Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp441122pxv; Thu, 15 Jul 2021 07:47:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGwiyTTpdC8Vt2b/d8iovWVf5T7W5KndNgtxkcPFQA4Wy0pPpv4GvrOTlCs+k/m9DVjp1N X-Received: by 2002:a50:cb8b:: with SMTP id k11mr7585838edi.55.1626360426696; Thu, 15 Jul 2021 07:47:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626360426; cv=none; d=google.com; s=arc-20160816; b=o31DCYhQEYGy38GzQE1Vn7JrB/gTdvWk2t1sb0JwHap2/Mc5s74wQxjRNjfpvvIHhU DxN7bITdovz8ZLVoabqCegec80f3ds9Eq6lV/yWYNUsLWEReqxLCnpHYVKXPE1d/+7Y2 vXVdD77Je5SkuV5vZRoF2A3nykEW6mtc3kZTfLlMl7Fx0zHyOziHzqhE/T7dyqZNJ1A7 qNIX5U3qIEnUNg+FeKqZDidgLFeU6R+1PEMr3oFoDUVi5+Rtf23BahXiMIaut1NLzppu XRoijWiUxgbeGi4U4hSuN3kdstSK+iWfoABwvBJ6oZoBcJSK7AhQm/ihgy9RawqFvOAy WSdw== 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=7uqDZzHKVpsINWHrg5JOJTdJvh6PSIO/q3/0nSNsYII=; b=AfFieURmd4C8MLKaHh/y6Z5G+e1yRyWnxfODL8X1FCxUDd0f9VBJtOCYiNSCuqKYsa hEeYn3dSzA6yN0E8DkdNteKpoytcKjiksWP+ev8Yz8hbNaCwwPmHmTOtynYbIBX7d9oz v1LgNvXsNxOvj9k698GL++qA51IRGX52hlN1VHHI0o9ZauucGSh7PuBjXCu2dKRJnqEp 50TvVmGp5PpnYJhwBrfabf28ZZeOf3kcwp1r2ik8zLAAprYiKvAtSx89ubBWrc1rbKpp u/rj13UVn4lDkqN/fn+S1GaGtvdme3+LEs1CUy27apo68qHNm13TJCGdLQkIDEXf0KN+ 2T0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wphbDc7+; 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 et5si6254927ejc.582.2021.07.15.07.46.42; Thu, 15 Jul 2021 07:47:06 -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=wphbDc7+; 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 S236981AbhGOOsl (ORCPT + 99 others); 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-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.