From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj2-f6.google.com (mail-pj2-f6.google.com [74.125.227.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DD7B94F85B8 for ; Thu, 15 Oct 2026 21:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.227.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792100213; cv=none; b=MvLKgF9WiJAWCtSK7+UfyxEuw6CB99gpAuTNjeV4W0FU5yQCqmayqJWqnQUSdw/MxA8sUOpVMjU4ohUzbNcbaeiyo1b4G0UeqvcUt7Jtwbr+XivsSmzI9RyAcGTHOGSJ1+02q7XYwy2rxVL0Sv6hoswt9kEN4jaAQOgWGcIDVg8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792100213; c=relaxed/simple; bh=/mThlAxqOQ/illGXXCKqwpofgrrCmo0z6UJR5iZDmek=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VhpTln6h3IZFagBmZZuNCd6oHIRposx82B7A3VQb2QkxqPR3yWxsm97/+HGO4GmkBXWTV5+Z7SGISUmUIZ1VvPU6bgILc5BOa6RjdCnJjMLKFlMwYZ1v7o2aWU9gp3fv4ajqVp9hm4qeAoVMx9AchzWdKJJv2yugbbgJF8Nl8tA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=L5Gw+2rH; arc=none smtp.client-ip=74.125.227.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="L5Gw+2rH" Received: by mail-pj2-f6.google.com with SMTP id 98e67ed59e1d1-3964e7720afso2866020a91.1 for ; Thu, 15 Oct 2026 14:36:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1792100210; x=1792705010; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=TFWHGN7cklsMWKCyO/CrNxAqmD+l+5aS8n56/ZuYuKE=; b=L5Gw+2rHfKE35YiYPy1ol+Mo3zNmcIrTcm+mx5+BQacp1HSFNELcpJ6qmDp0QHOg3n eSTwG/f5uRWvuhiLEoPNh2WZHfLDYhdc00wODroEGA2Jc0PUIZSOtUVfQ3SU5Dd+N1b3 HfocrloFYZ3lGJ7lihdL3QuZoGxvCIZUeYtCKnnitqPWwkoC3y9LMKNscFi4lcdLoARf dICo26do3vBcP09lvRkDSgOyDefSdm2vtCqzdztqSCrp4FhXpYa7AuOEDh/TM4RQHd2X DWgUOL8szfRsiHPSZtukg6KSbYtG8pwMW6DMaZLbQdoHydZz3/N8YgC0ahh0Q0IejlQs 25Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1792100210; x=1792705010; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TFWHGN7cklsMWKCyO/CrNxAqmD+l+5aS8n56/ZuYuKE=; b=ZeTwLh7OvGzg8hA/Emsw+EfujhhHT4zCL+y2KIqFBSVH1/qs4xdwzVQzCWlgbhwArT U4BGfZ+0p9OR/mUx1lPfqUhBtLlazm2pYlQaH31gImpk3+MRMqxt1zx/qNbhjcxUBbyJ gUg5xTkAsIpWlruECI0qBMG1hMrJ7FhxZbqCcBWYZtmW3rJf7UGxn48pXp5qhL7IKMnV oZWZ/9ftfqCrmGFGSnFs9dtzIdjr8RtzDIijQPHTTxQlwUjJAN8t/GYYY8xDBesoU6+l GoBP+sy1D7hjpWjrAa/4qt2sCfe6kWWAvGbH1f8yVD1KZHK3T7QZaohLrJcs13Kgevcw RI7w== X-Forwarded-Encrypted: i=1; AKwUvBzcJyc5nN6SncgRp5VHnWx3/sE0bzdf25R6gs9UZ2EI7+N/a3MRkb/1Krg9BWC73XvUL0E=@vger.kernel.org X-Gm-Message-State: AFq9FYIkGRxItusdbUnRiIhIWYxUSkZhvCFMuAN9uozgeKa0L2SWtmeD K7V1+ylE+/XiQcnryKZdvQlA16nuQO+rpI8k4f0WO65e1LFJYbTW5JB9 X-Gm-Gg: AYBFou0lEzTmIuiGQw1X+12W7sgT8/cVg8KBBH3KZtkzGDzjZo7qJhTVm7Cm+7qhght Gdx4JHF6QmrD+rZz34hzszdg0cOZM4UPYuAgENiaCNYMWCsf0t1ixiEtwb4mqgETjW0KCX6gaZM iu6fUayoBSSMcnTWlPAQVUdTB/8pHzKXJuGGKIvdUYwl0NmBSx0DRAqVfJA9gDj7ik4rd+nFY1u KQqRWikgE6eJZdze4bvPx3HQUjjTRI0udpMu2ErHy6wPjko4Z3PphFhDUF3R/1RWy2sqVMhxj4J /sUsB6lHrKYrCQfWllk1N1PJY/pLJpyXXbh/wx4eFdpMi90qDKTcgwDOm//A056c9jx+/OIEewi 4dDdO8+y7V8LdouQI/Da0YYIxU4vPC6+uURwBTjJTkXpd9heBSlAWCGsNng9o9gqBaBSo5usED8 jX5bv+nOusKW/KkDF9lLi2okXE4wFE1gakQub67ooVg7FnsrIu6Aggez0mHMVp0yyN X-Received: by 2002:a17:90b:48c5:b0:3a4:b418:94cf with SMTP id 98e67ed59e1d1-3ab3a7366bfmr18636143a91.14.1792100210060; Thu, 15 Oct 2026 14:36:50 -0700 (PDT) Received: from localhost ([2a03:2880:2ff:46::]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3acd05fb680sm23372a91.2.2026.10.15.14.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Oct 2026 14:36:49 -0700 (PDT) Date: Thu, 15 Oct 2026 14:36:38 -0700 From: Stanislav Fomichev To: Mina Almasry Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, bpf@vger.kernel.org, Ayush Sawal , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Tariq Toukan , Simon Horman , Steffen Klassert , Herbert Xu , Neal Cardwell , Kuniyuki Iwashima , John Fastabend , Sabrina Dubroca , Eric Biggers , Kees Cook , Aleksandr Loktionov , Petr Machata , Uwe =?utf-8?Q?Kleine-K=C3=B6nig_=28The_Capable_Hub=29?= , Jakub Raczynski , Wang Zhan , Willem de Bruijn Subject: Re: [PATCH net-next v3 0/6] net: unify symmetric netmem and page_pool refcounting Message-ID: References: <20261014173945.373295-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20261014173945.373295-1-almasrymina@google.com> On 10/14, Mina Almasry wrote: > netmems (pages and net_iovs) have two independent refcounts: a non-pp > refcount (page._refcount or binding->ref) governing backing memory > lifetime, and pp_ref_count governing recycling within a page_pool while > page_pool holds a single backing non-pp reference. SKBs with > pp_recycle=1 own pp_ref_count references on page_pool fragments; SKBs > with pp_recycle=0 own non-pp references. > > Core helpers currently mix these two refcounts asymmetrically: > skb_frag_ref() always increments the non-pp refcount via get_netmem(), > whereas skb_frag_unref() decrements pp_ref_count when skb->pp_recycle > is set. Any path that refs a fragment on a pp_recycle=1 SKB (or unrefs > with a hardcoded recycle=false) increments one counter and decrements > the other, leaking the backing memory while underflowing pp_ref_count > (e.g., IP-TFS [1], skb_split(), skb_shift(), and cloned SKB uncloning). > Unclear core APIs also led drivers and ULPs to open-code pp_ref_count > manipulations or add one-off helpers like skb_pp_frag_ref(). > > Unify fragment refcounting into symmetric pairs where each layer clearly > specifies which refcount it touches: > > - Non-PP refcount: get/put_page(), get/put_net_iov(), get/put_netmem() > - PP refcount: napi_pp_get/put_page() > - SKB netmem: skb_netmem_ref/unref(netmem, recycle) > - SKB fragment: skb_frag_ref/unref(skb, f) > > Found by code inspection while reviewing [1] and confirmed with the KUnit > tests in patch 6; not observed in production. Driver and ULP call-site > changes are compile-tested only. > > Link: https://lore.kernel.org/netdev/xfrm-iptfs-pp_ref_count-underflow-v4-1-912fa72106f0@secunet.com/ [1] > > --- > v3: > - Linearize straddling output segments in skb_segment() when frag_list > SKBs mix pp_recycle flags instead of clearing NETIF_F_SG, and add a > KUnit regression test (Sashiko). > - Link to v2: https://lore.kernel.org/netdev/20261012082148.1698596-1-almasrymina@google.com/ Acked-by: Stanislav Fomichev