Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp1043404pxv; Thu, 15 Jul 2021 23:45:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKdPGJ3TLWAqsdSxxyHlEnzVmDxxS/Dgt09AueGQO/Q49jAd+QkWcpobmUAl27fRT/dOaO X-Received: by 2002:aa7:ca04:: with SMTP id y4mr12197249eds.83.1626417957176; Thu, 15 Jul 2021 23:45:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626417957; cv=none; d=google.com; s=arc-20160816; b=SFbMuKEliA0srip/OLfFJ1xsFFx+hZPYOVLd/nXdtGVv/A2XbpaawcMrFZ7Zy4H+Fb Oc0KXVOqLICD8HFijkc1xL1SZ3pGXcb4Pwpj9QWL0JM2f4fQjOc6njlZ5fwplcmy9c6A i1ZOYpxDO8L57HeoWtIIC5B6S/4V3rHRzFnaIC4XwnhS8H6c652mGaiuv9zP+MenY9Fb fsSG8o2/5IpsgJmtQGlI2jmXNd6EstxSc2UpsF2G+OYfAC3soSuzEIDqwSnc6O1sJYJ4 QFNBr3a9zhK6LRJ1NIFB0UdqoaW6Zge1qYjSYeQoxmUjBAugiYGCOsTZSRIu7YFQeyHE vpog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mwYXIr6ik9gRFyyihXOmtA5qXVO6HHeD+uU+nCHmsq0=; b=tOPmEPbNgkSkwoTRkXxA7l8fq0oBq9nvMpDYRp9dMmSUpqV2+Im26cWA505Bp2d93Y Vyitn5yAISkOglApJfvEvse1ctSeMlpQNRXFz11D2yQWlCT8YWPeMjUDGADM1NW6M9EV PMSQrm4t9XNfDS5p71UPh9TSR7V5dr4o0C14Sc30IciPeGvBy4qCTcZHOM93CgzZ17s6 Yh6SeIzPt0QXosotbwCou8ImRUSeYpjbXAeEdcDDiSgm8x7kmbn6YE7OK30bO67JQuLY W3//7gtxd3KEeqnkL7/qXix7o0VR31aJHMs/bSKp41dU74rTs+OzIcTUeT7TDhdHKhKE a97w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YZ52dA33; 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 kl25si9929912ejc.370.2021.07.15.23.45.33; Thu, 15 Jul 2021 23:45:57 -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=YZ52dA33; 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 S234855AbhGPGr0 (ORCPT + 99 others); Fri, 16 Jul 2021 02:47:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235246AbhGPGrY (ORCPT ); Fri, 16 Jul 2021 02:47:24 -0400 Received: from mail-yb1-xb2a.google.com (mail-yb1-xb2a.google.com [IPv6:2607:f8b0:4864:20::b2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0CEFC06175F for ; Thu, 15 Jul 2021 23:44:29 -0700 (PDT) Received: by mail-yb1-xb2a.google.com with SMTP id a16so13197647ybt.8 for ; Thu, 15 Jul 2021 23:44:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mwYXIr6ik9gRFyyihXOmtA5qXVO6HHeD+uU+nCHmsq0=; b=YZ52dA33UBIanGFBEMesnLQgILFUGfuI/dFj6cpjXYYJLxefZsLaVB9mys2X2kl2aT y98CmtNdAqXIhkeAHE9ZPrlTCVA6DoE8hgxSjVINFYy01TOc3ZztkHt1OwDb8jgsNt+g hJGctN5hI0TzrlwYbSjIqug84KTwTIiMfv5k0hP4TSgSJ+/YkE04zBJS3760u2hKZbz2 rJf36PkwKxrR+b2/AFC6J3SYWRSsSzJ4yjN/Hp0BAMzeLmqvKwwtfI3KmKtHVYpgnAfJ y3dDJEF8MzRSVxR7Z9aEHWbQd4iCR2Xu4LB8j/fzKiliChdFrRU0UvYlSo/tZPDVaK9e zMPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mwYXIr6ik9gRFyyihXOmtA5qXVO6HHeD+uU+nCHmsq0=; b=Mbf0wP5jGBNkoMIhtwBEe6q7crAhzNxdLbKX5i+T8WxyZhamMAAcAYgV895zEqpyEF zesWZM6H7ZzkSFXiehVJRHgfGzOxR9P8pkQvr1d4oTeqHC6JFd8n+9HrQPU3jZ9B86ie AZzqxNdyIdJlrGhx27edbCRaLqvWGOHdPJg5xqSTO1mw84Sm/z6sWIyoYc7Py/TTM3uG LGahQOm+IXpBjYPGSm21EmGPftsQfYEtHySEiowPSVk/Qhvj75wmuAYWmmcfbCKHsULy 0jjTEH9+CqeycJy6utnEJSke+6nw14HjDTU2nTOv580RohDkdLXNt7sJ4eemg5IpDRN+ yBOw== X-Gm-Message-State: AOAM533AdWhnTjaydMpzd2IQjT73vcHaBD1lODA4wtNj6M6Ha/KgNlIM j9d12vXSyApTvphgMvCIe8SXZ7rVugaHQwNqS/4l8A== X-Received: by 2002:a25:8b91:: with SMTP id j17mr10365880ybl.228.1626417869290; Thu, 15 Jul 2021 23:44:29 -0700 (PDT) MIME-Version: 1.0 References: <20210709062943.101532-1-ilias.apalodimas@linaro.org> <57b08af5-8be2-56c7-981c-27ab7187fbdf@huawei.com> In-Reply-To: <57b08af5-8be2-56c7-981c-27ab7187fbdf@huawei.com> From: Ilias Apalodimas Date: Fri, 16 Jul 2021 09:43:53 +0300 Message-ID: Subject: Re: [PATCH 1/1 v2] skbuff: Fix a potential race while recycling page_pool packets To: Yunsheng Lin Cc: Alexander Duyck , 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 16 Jul 2021 at 05:30, Yunsheng Lin wrote: > > On 2021/7/15 23:02, Ilias Apalodimas wrote: > > 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 > > Ok, I suppose the fraglist skb is handled similar as the regular skb, right? > Yes, even in the fragments case your cloned/expanded SBK will still have the recycle bit set, so it will try to recycle them or unmap them > Also, this patch might need respinning as the state of this patch is "Changes > Requested" in patchwork. Thanks, I'll respin it and add a comment explaining why > > > > > Thanks > > /Ilias > > . > >