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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 6AE80C07E96 for ; Thu, 15 Jul 2021 14:45:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4225B613C0 for ; Thu, 15 Jul 2021 14:45:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237548AbhGOOsl (ORCPT ); Thu, 15 Jul 2021 10:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234745AbhGOOsl (ORCPT ); Thu, 15 Jul 2021 10:48:41 -0400 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5F92C06175F for ; Thu, 15 Jul 2021 07:45:47 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id v1so8491935edt.6 for ; Thu, 15 Jul 2021 07:45:47 -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=7uqDZzHKVpsINWHrg5JOJTdJvh6PSIO/q3/0nSNsYII=; b=wphbDc7+rLxFhMs3a2acJoIwxbDAMRsUtFVZEj58rxiSfdbeuDshwMt79HHJ23/g3G 5Qw65nVbjEra99I3wVw26Hiwz4GYv3Dr0foBGti1e/kupVmcqKtH+dwwm+OND3eZ3i/G KPXwkQ9ORGeAyhdXdX2/aOV94neCkKybOgbe5X36ENPLB5vXbDbSPk6Pb7QLbboL3Ezn RTCPwd1/FzQW8Cuf8XPQFRiqZ2Yy1JUDNJuxo8DiRwRTZhwaZuelnhb3XSEr/Q1XnU2p 1ZvAN0YZ+8PVPOVjCyatVKpFdqAhTgWqI2ISOAt17axncq+xH5GsHAa7gqaCINpoa5Mu a23w== 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=7uqDZzHKVpsINWHrg5JOJTdJvh6PSIO/q3/0nSNsYII=; b=K7lkuCDReBMOBG+lG+qrDBG/cblATgi+blkR2DR+KJ2NerTMDzA2lD/M1OnIHgJQY2 IkPSt0SFMFcPS6/OR3gSTIXOs+Q+rY2UGNAGwDCra6rKLE+VAPbzp4FW3205WE8ybmo7 j3V3S5DxlPqEhYbgxo107nSNlLEzSpT4++pQbaKG98kArZzrD1uOSA62cyMGrWYH51+F HH6GedCj2XaoOL5n17J7COIwQf/rGd6fad7KoaG6mjC3mQxTYIpdKqaPRd1tsCyD52+T h+4DcR1BJs3BgSJ+EDVR4GOAAT2TY7Fk6ALSXi3LNUDIR15DQylKVFzeLORs6wIn5PYU iOvg== X-Gm-Message-State: AOAM531fIdrlzCpZatsEbiy6hjNeoJliB5V6begHdM/lGkF4NEA69ueT /1WwGFjZeYf4SLCy0rjwwpeisg== X-Google-Smtp-Source: ABdhPJx7QpTydQ7DmTb1eoicKoERov8gYCGMOTruJKutI8Y9z3nmdc68jbxUJf3CdUq9F11UiGUxIA== X-Received: by 2002:a05:6402:31bb:: with SMTP id dj27mr7266889edb.375.1626360346401; Thu, 15 Jul 2021 07:45:46 -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 l20sm2472131edb.47.2021.07.15.07.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 07:45:46 -0700 (PDT) Date: Thu, 15 Jul 2021 17:45:41 +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 > > > 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) > > > > > > > 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; > > Note the path here. We don't clear skb->pp_recycle for the last buffer > where "dataref == 0" until *AFTER* the head has been freed, and all > clones will have skb->pp_recycle = 1 as long as they are a clone of > the original skb that had it set.