Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp539358pxv; Thu, 15 Jul 2021 09:47:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhmQjxmpT3wp+EqyKAU9rfiqVquhNLVTAKp+gZ8YzfEaysujrgWyvHDwHxsQAFhK2xJDgm X-Received: by 2002:a17:906:2bc6:: with SMTP id n6mr6583057ejg.256.1626367654241; Thu, 15 Jul 2021 09:47:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626367654; cv=none; d=google.com; s=arc-20160816; b=caVYGdE7fT6R5nLtigpJuzXC5hkdT5ncuPHZrGaeeOp0SwETCwbxdV5OkWpM2Jzevy 4xw6A9HYWhKwiKxpJHNtOCBVOy7GJt94OK1sl6WAg7hZvJYaVZwZe6Cgeb3wYUGoo8+X iBSxK/ZiRuYlPg8h6oR3ruzT8dY9A2CAidXxYQ1sjsNhBthGhbkTzPiXjj3PROdQ/hno tccMRL0pljNH92+0RDO8jBY+kwdgPpifCc5NB1z2Kl18DSoWkFfELgett1QCPJzR0aZ6 ojv0/5qRggjykRtNVJWS/bTWInvtt2xocHADh51zG0yWOWEqBhEILqrK0MUaZ7fmR2uZ TM+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Yluq3beMV5fv9/Nk87EzEa1ZxTYd3mzcMJaKDO7x4Vg=; b=vIsyfOYki06l/l4OXvr1W6p/6XBj7vqQKpSY80i/lA2t/akgdANlt8zHT4dzjiT/CW DiPp0ilzw7vzY+9EZT7J2ezI+XlUJxGdUpaWubJIs8x9ufM6bPrWywdA2xfWDLE3EyXF IXRFDGSHIqCqu84guXI6w8vjnFh2DnxnirC1pqtSiHirEiu4lxCiVlAWXyD8aIXOSLZ2 henb/EnVk/dapnGGqlyNH6RI27mB7n+2wnCIg1tGswMspr8sdPEYHCAULB6ZiihCZsr9 1LdC52WkPvn18aUISYxuoQ+f1XWpteLnFtsOa4Tgc6kMpQMwfX+bsFqp5nhXXZ8BylOR JWqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="tmIomh/M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw15si7723042ejc.604.2021.07.15.09.47.11; Thu, 15 Jul 2021 09:47:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="tmIomh/M"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231548AbhGOPFx (ORCPT + 99 others); Thu, 15 Jul 2021 11:05:53 -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-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