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 DAEC04ED1AA 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-3964e7720afso2866029a91.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=BtQqmhhL9B/GIIcgW1rBcFxBpvH/e49hqk2bKnDEi16sQArChbxtaDkrt7r9eWFeFV K+5CGTB34+BDmjltx07JPVV54jdbG0bobcEv2aCNPVTvimNQCndNc3BOzS0WAlEKkYk1 N1Y085qDaKF4gs0bdyI2Cc3+RR1/vU1TIuNC2mJL4l3IYrOHN/PbvnZ69q2D1fRb910a wqu1lpngRxcqn0uNOV8lW70jrqd32hIbplMnHhiNsS4Qu/uHHOI74UUELA8o83d18JIV zH9zYioYyh9DGEogt3rgktieBfF7Obypk23vqBUhlo2Op7dspLeTfbjuiCB/CLLqapaK CiAQ== X-Gm-Message-State: AFq9FYLgLGL6eAkax/oRWb86TYHcnD/4XVtikDXv0z0ZfsGAcMDDTzp2 hEMvK8x2EF7MrhPA2qpS2G/ayrvRdiyQZRQTFa7+LR7qR3aGeleVvVf4 X-Gm-Gg: AYBFou0Lf8BuTItfwJwHKyXmxSpzRzxdKu6zZGzMOvTw59aZD5KGKTZOiOTUi73kciS +FaoRxlI8KFG6Lost4yVOoov/coPfYbSQ5dteVX/XCce2FH4QhTNTQ1CPD/W0Nl6RV1/DtPIew4 b9yq9LSJcttUxND7gxo56d0pX/FssjQVZymglTzYQaOV6kWDg1ZHPt+qEiYya7hxFeSWxytXoo9 YnVq/XRICs+hH4xcg9EHQuxsFes38yzro/vb3AWOJszX9rw9/DBZbtkJS8zI176p1QPBY05GU/Y 629szVyA5OrAUz0RJ2qlMn733KFg59HaKFMQ3bih3TiADmOZHSRs0xhBK3DTjtKtPHS7cdT/LFH 4Wdnb5lLIYmftP4wDTfWJhxt4LpotK79yJ8faNYKXXBpWsKdLAp0esysG7q0ngtZQEBuVsj7zmh LQZx/UK6ZUk7O7y/Zeo0gqs8okeqtN8flC93AdcFJbCCeXlVrZdsRZuOgsn0eoPBIC 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: netdev@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