From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50C27C1B08C for ; Thu, 15 Jul 2021 15:03:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 35E1C61167 for ; Thu, 15 Jul 2021 15:03:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbhGOPFz (ORCPT ); Thu, 15 Jul 2021 11:05:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbhGOPFx (ORCPT ); Thu, 15 Jul 2021 11:05:53 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF609C061760 for ; Thu, 15 Jul 2021 08:02:58 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id l1so8522820edr.11 for ; Thu, 15 Jul 2021 08:02:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Yluq3beMV5fv9/Nk87EzEa1ZxTYd3mzcMJaKDO7x4Vg=; b=tmIomh/MEK5Au1dRya+387VrIb++sWNgScG7/F2JXr+zc9TZILAd+oJqCU7TlojXFw y/IlFFftKD5HYw2kc2WQMAm7hl1zAc6lhGw3jclsj1gJPxa3x0rOFr/RoueciggSV2W+ vN7agWZDf6nMMO6BNLUmUx25LXWlNugY/uPU5PXQNM6ER2VRbVKxDXvyOpB117l5PTw9 w2hN2cgwohw9pEV3k7kzV5gLEMLrzTbKmvb3y2CFWYiPDELw/c80UluYZhH3YgKtsyKU YSjeDhngy+rvMbT87ErftTQp3/b9gRTcpLyckw01D/NxOxXwCJ/VgCxHZvfmb8O0qvCW 1EPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Yluq3beMV5fv9/Nk87EzEa1ZxTYd3mzcMJaKDO7x4Vg=; b=gsHUQ86W6B5uNc888dkyQ1aA2Bay4n7jd6xzRXVGOE4ofeP6VY0fG2Zu+MyxW+KiCu PJ32BUxUhvzmQz2hE+Ciy2YBFrYFL9C5yLSm51ztSiFS6V+VpDELQ0D8cOaBjvzMekZc qVFyE5dvv1p23eidfValVGFeWjgdSJMql1qyLiW8moih3dcmgPmt2saJ63KX/F/8GhEy DDHL1+rVANiBHDxQJ5cafXaTSWFaG/71fUrVQiYbYW3LcwBGRpHSDaPcQ90U1RnDg+G7 t/nG/4xwqSKBlqpkLDlyyHWs4ZT6LlACi7gW0eIon5TAa4BbSOW+1GGak2wOXA7wqIQl LmBQ== X-Gm-Message-State: AOAM532x8vl+42r/Xx738OcJGNlhpYzxxYsdqKXiFoosi1FPt5OIVQiw L/hQD7b4j6mQevl+DP1vAkUIPQ== X-Google-Smtp-Source: ABdhPJxPZoQhKVPrlfkBexsehYqwhichiPmzBkfipmfJwsofsg05PAyw7/fAr4FoIvAgJdvqn2HXUQ== X-Received: by 2002:a05:6402:4cb:: with SMTP id n11mr7624597edw.292.1626361377200; Thu, 15 Jul 2021 08:02:57 -0700 (PDT) Received: from Iliass-MBP (ppp-94-66-243-35.home.otenet.gr. [94.66.243.35]) by smtp.gmail.com with ESMTPSA id m26sm462685edf.4.2021.07.15.08.02.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 08:02:56 -0700 (PDT) Date: Thu, 15 Jul 2021 18:02:53 +0300 From: Ilias Apalodimas To: Alexander Duyck Cc: Yunsheng Lin , Netdev , Alexander Duyck , "David S. Miller" , Jakub Kicinski , Alexander Lobakin , Jonathan Lemon , Willem de Bruijn , Miaohe Lin , Guillaume Nault , Cong Wang , Jesper Dangaard Brouer , Matteo Croce , LKML Subject: Re: [PATCH 1/1 v2] skbuff: Fix a potential race while recycling page_pool packets Message-ID: References: <20210709062943.101532-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 15, 2021 at 07:57:57AM -0700, Alexander Duyck wrote: > On Thu, Jul 15, 2021 at 7:45 AM Ilias Apalodimas > wrote: > > > > > > > atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1, > > > > [...] > > > > > > > &shinfo->dataref)) > > > > > - return; > > > > > + goto exit; > > > > > > > > Is it possible this patch may break the head frag page for the original skb, > > > > supposing it's head frag page is from the page pool and below change clears > > > > the pp_recycle for original skb, causing a page leaking for the page pool? > > > > > > I don't see how. The assumption here is that when atomic_sub_return > > > gets down to 0 we will still have an skb with skb->pp_recycle set and > > > it will flow down and encounter skb_free_head below. All we are doing > > > is skipping those steps and clearing skb->pp_recycle for all but the > > > last buffer and the last one to free it will trigger the recycling. > > > > I think the assumption here is that > > 1. We clone an skb > > 2. The original skb goes into pskb_expand_head() > > 3. skb_release_data() will be called for the original skb > > > > But with the dataref bumped, we'll skip the recycling for it but we'll also > > skip recycling or unmapping the current head (which is a page_pool mapped > > buffer) > > Right, but in that case it is the clone that is left holding the > original head and the skb->pp_recycle flag is set on the clone as it > was copied from the original when we cloned it. Ah yes, that's what I missed > What we have > essentially done is transferred the responsibility for freeing it from > the original to the clone. > > If you think about it the result is the same as if step 2 was to go > into kfree_skb. We would still be calling skb_release_data and the > dataref would be decremented without the original freeing the page. We > have to wait until all the clones are freed and dataref reaches 0 > before the head can be recycled. Yep sounds correct Thanks /Ilias