Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp854421pxv; Fri, 9 Jul 2021 10:31:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjEFPuwW6CUP7ccWoKx7+ZHjUPVdnangNh1MWE8sWut4PY6rqjzLXeJdNuTZSSlk9+g/rL X-Received: by 2002:a17:906:2bd4:: with SMTP id n20mr34223198ejg.390.1625851891813; Fri, 09 Jul 2021 10:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625851891; cv=none; d=google.com; s=arc-20160816; b=CUTc0I0aHe4DwzeNvQj38LShDnyOo6W0UwISuWNEEdxtR+r9Ou5ZFssz+j8X2YSlXy ocvLh5u7RbjLJ/NTuCs3I0zB6ftKxCVLf9HvPpMYo248uV4en349WITQCGM7RzDvPvTl nOI0FNf+jyfuRdrZ+PXf6WNBgAarFSTjtp5oYznSI37Nc6R/K+m/m/9vk9JYIQN5lU79 T7II0zjBIiGQnl3Hzu30Ouwa0FBzJrIneObiOc70OQcaApL4uFMtyk/0a53OJo29A/M2 haK4+F1cknufL9dU78AGng/8lyU8p4irQxntXrlyfU2iIV5WNID3XDg73fJrFkMoOCmE 88kg== 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=/16PvS0+2CUKH8u7VJDHoAVMZui3Hk9OZqyyxl42huQ=; b=DdmHAOf2WpKObVbS+RDF/oTIxV5hztEKQykUVNBZmc6BVAgEaZPtIG814PyQjIvUXP Z3ATCrHwZ3Ql6xsNMQ5jJoZdApp2N5s9dDlCQA6EtEouhmi9jJ1p4u4rwoctQoCZauWX XW6wLsAMDVBT7mhi2Mm6iDFcdQO6uEu/kt7tK1QqNTp5gehYj/W6iQAKB429zxSqjgET uoWp+JPJh0F+qU966Moj+g9k3MJAhexH6NdzxL+CmuhzCfZC95P5RALQS5tcBw4w20HQ mnFG6zkRaBfxma6mpKogfOlt7QYw6XqEB4912VX3p4FkQaESJYZYsvRf0ybqSQtPx/kk mj4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GAx44Mmr; 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 am1si8444281ejc.41.2021.07.09.10.31.09; Fri, 09 Jul 2021 10:31:31 -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=GAx44Mmr; 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 S229819AbhGIRcf (ORCPT + 99 others); Fri, 9 Jul 2021 13:32:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229499AbhGIRce (ORCPT ); Fri, 9 Jul 2021 13:32:34 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE2C4C0613E5 for ; Fri, 9 Jul 2021 10:29:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id q18-20020a1ce9120000b02901f259f3a250so6750955wmc.2 for ; Fri, 09 Jul 2021 10:29:49 -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=/16PvS0+2CUKH8u7VJDHoAVMZui3Hk9OZqyyxl42huQ=; b=GAx44MmrmNnReE+9YFn5w2r22huzdUEmMwN1BJ3SqLdVCktaDWJg7nii/srUK3K4Cv 7oSxU3HM/DbPnMLZrIqh80NQoQalRjwlPWfp2hsXhH09C+2/KbmSb3rkpy4XE2I9JLRQ 0rlMvAU1oHUKaOqBGg95Whv9chxzz5mViiat25L9NrFGWpcbK1RKQkAOBwPaaE2Ydh5e vJrJE7nINrrgbSet/VxUWxAWk707zClxDKKJiwIJIXvsbO6qO6ZAPiOJYUPiHJlpBoKS OXU6dIsd9v8f0cWFVP8/El75DOHttXIgZYS0L11ACfevhbI14gVBJFty4YaLf0iHu13N XKYw== 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=/16PvS0+2CUKH8u7VJDHoAVMZui3Hk9OZqyyxl42huQ=; b=kFVY3mtvNbOrFB8sVDQR9kqtDRDA76Y/QX6JmXIW7Mx7dZfbLHPsxBNLW3yVXTvXoI lTjX/W/iAdo3NHq9ZJUkIIWjaSQuDJtILO7V2hAeh8+S/o/azo5bcAt5d1tA/e6zEjXm x4eyAASqSJQ871SAO+ueSzLbFpTcmSfbI54U/UNasUXcfM0LrSHTFQ42kn4ZAH7Y1ryK EYFDYpADIVg/T4kXNuXl//mZMIs3gUoTS/WBOxocqXvKEnQe57cEUqP43UPGyABADWHr juuKw18O3Y7BuFtW3f1i9PLVgLHNRKcfYbh9LQyeb3v3glgwSQ4PHDkb4Dhf/vKvSj82 FwPA== X-Gm-Message-State: AOAM531NCMUch/W4cGVE9ou0UXtixdX0FF49SF+Qn3z6ePxMffaM0i9m rQD53RD38TAQkt9pI6dEh8KTxg== X-Received: by 2002:a7b:c751:: with SMTP id w17mr11351014wmk.117.1625851788472; Fri, 09 Jul 2021 10:29:48 -0700 (PDT) Received: from enceladus (athedsl-417902.home.otenet.gr. [79.131.184.108]) by smtp.gmail.com with ESMTPSA id l17sm12217084wmq.3.2021.07.09.10.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jul 2021 10:29:47 -0700 (PDT) Date: Fri, 9 Jul 2021 20:29:44 +0300 From: Ilias Apalodimas To: Alexander Duyck Cc: 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 Fri, Jul 09, 2021 at 07:34:38AM -0700, Alexander Duyck wrote: > On Thu, Jul 8, 2021 at 11:30 PM Ilias Apalodimas > wrote: > > > > As Alexander points out, when we are trying to recycle a cloned/expanded > > SKB we might trigger a race. The recycling code relies on the > > pp_recycle bit to trigger, which we carry over to cloned SKBs. > > If that cloned SKB gets expanded or if we get references to the frags, > > call skbb_release_data() and overwrite skb->head, we are creating separate > > instances accessing the same page frags. Since the skb_release_data() > > will first try to recycle the frags, there's a potential race between > > the original and cloned SKB, since both will have the pp_recycle bit set. > > > > Fix this by explicitly those SKBs not recyclable. > > The atomic_sub_return effectively limits us to a single release case, > > and when we are calling skb_release_data we are also releasing the > > option to perform the recycling, or releasing the pages from the page pool. > > > > Fixes: 6a5bcd84e886 ("page_pool: Allow drivers to hint on SKB recycling") > > Reported-by: Alexander Duyck > > Suggested-by: Alexander Duyck > > Signed-off-by: Ilias Apalodimas > > --- > > Changes since v1: > > - Set the recycle bit to 0 during skb_release_data instead of the > > individual fucntions triggering the issue, in order to catch all > > cases > > net/core/skbuff.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > > index 12aabcda6db2..f91f09a824be 100644 > > --- a/net/core/skbuff.c > > +++ b/net/core/skbuff.c > > @@ -663,7 +663,7 @@ static void skb_release_data(struct sk_buff *skb) > > if (skb->cloned && > > atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1, > > &shinfo->dataref)) > > - return; > > + goto exit; > > > > skb_zcopy_clear(skb, true); > > > > @@ -674,6 +674,8 @@ static void skb_release_data(struct sk_buff *skb) > > kfree_skb_list(shinfo->frag_list); > > > > skb_free_head(skb); > > +exit: > > + skb->pp_recycle = 0; > > } > > > > /* > > -- > > 2.32.0.rc0 > > > > This is probably the cleanest approach with the least amount of > change, but one thing I am concerned with in this approach is that we > end up having to dirty a cacheline that I am not sure is otherwise > touched during skb cleanup. I am not sure if that will be an issue or > not. If it is then an alternative or follow-on patch could move the > pp_recycle flag into the skb_shared_info flags itself and then make > certain that we clear it around the same time we are setting > shinfo->dataref to 1. > Yep that's a viable alternative. Let's see if there's any measurable impact. > Otherwise this looks good to me. > > Reviewed-by: Alexander Duyck Thanks Alexander!