🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23528

Re: [PATCH] neighbour: Move the netdev_put() out of RCU callback

#23528
From: "Zqiang"
Date: Fri, 27 Nov 2026 12:23
134 lines
12246 bytes
> 
> On Sat, 07 Nov 2026 19:34:07 +0000, Kuniyuki Iwashima wrote:
> 
> > 
> > On Sat, 07 Nov 2026 11:47:45 +0000, Zqiang wrote:
> >  > 
> >  > On Fri, Oct 9, 2026 at 2:19 AM Zqiang <qiang.zhang@linux.dev> wrote:
> >  > 
> >  > > 
> >  > > For builts with CONFIG_NET_DEV_REFCNT_TRACKER=y kernels, netdev_put()
> >  > > records the caller's stack trace via ref_tracker_free() for debugging
> >  > > reference leaks. however, the netdev_put() is within pneigh_destroy()
> >  > > RCU callback, this recorded stack is uninformative, it does not reveal
> >  > > which code path initiated the deletion.
> >  > > 
> >  > Have you seen pneigh double-free ? What motivates this change ?
> >  
> >  Firstly, Apologies for delayed reply.
> >  
> >  
> >  
> >  Actually, I didn't see any double-free happening, just wanted it to
> >  record a meaningful callstack which on release path. After all, if double-free
> >  really occurs, the callstack of the RCU callback execution path will not be helpful.
> >  
> >  
> >  > 
> >  > > 
> >  > > This commit therefore move netdev_put() from the RCU callback into the
> >  > > caller's process context, and replace call_rcu() with kfree_rcu().
> >  > > 
> >  > > Fixes: d539d8fbd8fc ("neighbour: Free pneigh_entry after RCU grace period.")
> >  > > 
> >  > Please elaborate why your change is safe in the commit message
> >  > and remove the tag.
> >  
> >  Does it refer to using kfree_rcu instead of call_rcu ensures safely ?
> >  
> >  I mean why dropping netdev refcnt waiting RCU gp is safe.

Hi Kuniyuki,

Do you mean that if we dropping netdev refcnt and this is the final
reference count of the netdev object, the netdev will be free when
it still be referenced in neigh RCU read critical section ?

But the synchronize_net() will be invoked before free netdev.

I am not an expert in netdev. if I missed something please correct me.

Thanks
Zqiang
 


> > 
> *without waiting
> 
> > 
> > Thanks
> >  Zqiang
> >  
> >  > 
> >  > > 
> >  > > Signed-off-by: Zqiang <qiang.zhang@linux.dev>
> >  > > 
> >  > nit: full name
> >  > 
> >  > > 
> >  > > ---
> >  > > net/core/neighbour.c | 14 ++++----------
> >  > > 1 file changed, 4 insertions(+), 10 deletions(-)
> >  > > 
> >  > > diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> >  > > index 6ed8eb075146..4263689fc415 100644
> >  > > --- a/net/core/neighbour.c
> >  > > +++ b/net/core/neighbour.c
> >  > > @@ -818,14 +818,6 @@ int pneigh_create(struct neigh_table *tbl,
> >  > > return err;
> >  > > }
> >  > > 
> >  > > -static void pneigh_destroy(struct rcu_head *rcu)
> >  > > -{
> >  > > - struct pneigh_entry *n = container_of(rcu, struct pneigh_entry, rcu);
> >  > > -
> >  > > - netdev_put(n->dev, &n->dev_tracker);
> >  > > - kfree(n);
> >  > > -}
> >  > > -
> >  > > int pneigh_delete(struct neigh_table *tbl, const void *pkey,
> >  > > struct net_device *dev)
> >  > > {
> >  > > @@ -849,7 +841,8 @@ int pneigh_delete(struct neigh_table *tbl, const void *pkey,
> >  > > if (tbl->pdestructor)
> >  > > tbl->pdestructor(n);
> >  > > 
> >  > > - call_rcu(&n->rcu, pneigh_destroy);
> >  > > + netdev_put(n->dev, &n->dev_tracker);
> >  > > + kfree_rcu(n, rcu);
> >  > > return 0;
> >  > > }
> >  > > }
> >  > > @@ -891,7 +884,8 @@ static void pneigh_ifdown(struct neigh_table *tbl, struct net_device *dev,
> >  > > if (tbl->pdestructor)
> >  > > tbl->pdestructor(n);
> >  > > 
> >  > > - call_rcu(&n->rcu, pneigh_destroy);
> >  > > + netdev_put(n->dev, &n->dev_tracker);
> >  > > + kfree_rcu(n, rcu);
> >  > > }
> >  > > }
> >  > > 
> >  > > --
> >  > > 2.17.1
> >  > >
> >  >
> >
>
Technical Details
Message-ID: <37ac3078817eb588433881217b273f0dfd301014@linux.dev>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372709-linux-kernel-netdev=dewy.ru
References: <20261009091941.5837-1-qiang.zhang@linux.dev> <CAAVpQUAeHP7M07uMweRePtuzPPUo-99dL6jOYUiVf7CSVUxNDQ@mail.gmail.com> <a951af6957fe4890d3eaaf5a661754fc259a4b79@linux.dev> <au99DNHQEsaaDqpJ@google.com> <au-AQ7OPf6QPyc3Q@google.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-372709-linux-kernel-netdev=dewy.ru
From: qiang.zhang@linux.dev ("Zqiang")
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH] neighbour: Move the netdev_put() out of RCU callback
Date: Fri, 27 Nov 2026 12:23:16 +0000
Organization: Usenet Network
Message-ID: <37ac3078817eb588433881217b273f0dfd301014@linux.dev>
References: <20261009091941.5837-1-qiang.zhang@linux.dev>
 <CAAVpQUAeHP7M07uMweRePtuzPPUo-99dL6jOYUiVf7CSVUxNDQ@mail.gmail.com>
 <a951af6957fe4890d3eaaf5a661754fc259a4b79@linux.dev>
 <au99DNHQEsaaDqpJ@google.com> <au-AQ7OPf6QPyc3Q@google.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="728648"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:Hul12Pyx4IHrRG9v/rhuZhItDXc= sha256:g3F+NRfVqSafMtDck0n8RgFc8btCXhyselm9DTxeuLI=
	sha1:7H0T0gDxXo4ytKpt5cqr78PPwZ4= sha256:lHZBMw4FzIUO90ACFfOHsoqgqGHIhUJHZnKeuc/fGlc=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 512D4125F53; Fri, 27 Nov 2026 15:23:43 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (1024-bit key)
	header.d=linux.dev
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id xTmfAZK8Nd96;
	Fri, 27 Nov 2026 15:23:39 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-372709-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=linux.dev
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 18A5A125F51; Fri, 27 Nov 2026 15:23:28 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 29A4E2BA3B; Fri, 27 Nov 2026 12:23:26 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795782205;
	b=tL/1lGly+8ELduK/pj99bxKHD1//l5QYyLMUEhMT8ultCwvuD2+F1PNSMFyzPa7XSrO6
	 36SsZecbF1672P3V5fEGkUWN0FtLVwaJx6IjxQMkQ4WS9yKobUsqV9HXESCfgI/gCBkXx
	 ptHNW39OrTHH2cCn2eqj2vBbotYQ3T5UGiqmR4NqedxPV8wxd4IvdWYu66ydAYvOKE4wB
	 VUqVem3EbCNA97uxOwiaFLB2HbUIXJsFwjcN9xigC5n6qR9uug9ef/ZpaGJ0hfC9RI1pI
	 e7OskBrxvUmKGM4DVr/mxiB+YFRqsLcwLAJ6cszD3gu89mJn33vFe+zTF2xv5aQ/RQA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795782205;
	h=X-Original-To:Received:DMARC-Filter:X-Envelope-To:DKIM-Signature:
	 X-Envelope-To:Received:X-Mizu-Trace-ID:X-Migadu-Flow:X-Mailing-List:
	 List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe:
	 List-Owner:Precedence:MIME-Version:Date:Content-Type:
	 Content-Transfer-Encoding:From:Message-ID:TLS-Required:Subject:To:Cc:
	 In-Reply-To:References;
	bh=we26npX57rKL+VL8xivi5E7EKRh5WKL6xyTPMHFncME=;
	b=u+uaJblBOZCv6QoQyBxPukNiUVxg2vaWKrdAoBpn+qXchClYAigVXoSbfgnChxDZeMKD
	 dkiSrRNTwKDDGnMvpTR3Q1RYDUzreHSNguSaIWINsMYM4WgaGs5PeUAGP6BUeKbFLaRpp
	 DHILQN9ey2gc5aMe+fOSJ0vu2pFHBjqmJq0STN5L5NY5BHuGvEWRDI3lLgEgGd92zYy8g
	 ecyN99ttkBg0hEd5qi1fqZUFYqwZzTjJCVFJ7sQ7aWrjlmfDun4JAEJ4BbjnhnbYIC6YT
	 Ta76Q1h0mNHZV0iyelxAgb2rcmOqK9WW1VsDtNq4JZycOGNBInWCv1vRfU9VFVlyD6w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZQ3enJyt;
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 71EA9606A326;
	Fri, 27 Nov 2026 12:23:25 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZQ3enJyt
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.53
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795782199;
	b=Nl2fc9Eub5vtBUFwUPrYrqioOJJZKpoIZh57Hc8AKpbYlns5RXN0rFEjKnr6PnOHqRF5
	 Vh98EbYNiNlEYHHF/WNqnhsgQ+YR5GsP+MsJ+efVIsfRmRbMX5BCLlMUmPnL/D9z7F7nh
	 kS0SYJ/T9hna+ewqJHYlfSkv+A6Y9UNnIkVGX5uzCxzftLnmPQPc6iYVW3fD6sYcOBItG
	 GPVFvJ7W7K9ly7fnxGXYWxTNKcSLI9HjWb3O1oA7yttHloLLyS7WMVnzwDKRXG5lFtn38
	 lcgHHWQCdXDqshLVz4FCiL3/5U/aJtz2V6FWPjvi1hlpU2kqbYpvv9L1WU90R3S6PLg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795782199;
	h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received:
	 X-Mizu-Trace-ID:X-Migadu-Flow:MIME-Version:Date:Content-Type:
	 Content-Transfer-Encoding:From:Message-ID:TLS-Required:Subject:To:Cc:
	 In-Reply-To:References;
	bh=we26npX57rKL+VL8xivi5E7EKRh5WKL6xyTPMHFncME=;
	b=fvwjVVTneA1xXkmmKZG2gMGGG2xEl+EwYJonZQlfzb9wey1e8/452LMskN2lmm2/REXL
	 iTSBzB4VU1K27RvaAoOOkO3WLplA0hOjb4xqRgxpR5Dv6WhIZG0AM2pkxd6Ax2x8AY0YF
	 31BoFmOqBwj5VgrS/hO4Ui+JhZs8udomT8EjdbNjS45FJFoV/M4pvBDTpFiYfNHK9iS98
	 jdqkd3dvi7hvv3LFjADCR5TggomVqwydtZlnANEnkukAPZlYoyhZkj0oTNPuFkK7nJ8HV
	 JaYEnXS9/VFqPkpGR8w/O3vUuqABKak6LvPZlZsq/SppH/eU6JihZazpnFljjZrmT/g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=linux.dev;
	spf=pass smtp.mailfrom=linux.dev;
	dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=ZQ3enJyt;
	arc=none smtp.remote-ip=91.218.175.53
X-Received: from mta0.migadu.com (out-53.mta0.migadu.com [91.218.175.53])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2287606A32C
	for <netdev@vger.kernel.org>; Fri, 27 Nov 2026 12:23:18 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D2287606A32C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev
X-Envelope-To: netdev@vger.kernel.org
X-DKIM-Signature: a=rsa-sha256; bh=BA10GbeixydBlnD7l7DBKlHSr5quCNW2fqkr45XbMcM=;
 c=simple/simple; d=linux.dev;
 h=from:to:subject:date:message-id:mime-version:content-type; s=key1;
 t=1795782197; v=1; x=1796386997;
 b=ZQ3enJyt7KEbqECNYjUWqm9CuJMuvWzmGYMGsfNCLdt6we75CVwrz88wsqwYH4BzicNPOUlp
 DVcwjo0Zvgc/I8ZiepVHJzl29fcYGBVAqHA0LBlqBciM/hFOzl1UbA6FPnxzLGGcQ3Qi+I3C1++
 3Lua1XtiUG61PRAuZ3RmFtAw=
X-Envelope-To: netdev@vger.kernel.org
X-Received: by smtp.migadu.com with ESMTPS id adf3816c4789e0e7;
	Fri, 27 Nov 2026 12:23:16 +0000
X-Mizu-Trace-ID: adf3816c4789e0e7
X-Migadu-Flow: FLOW_OUT
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-TLS-Required: No
X-Cc: davem@davemloft.net, edumazet@kernel.org, kuba@kernel.org,
 pabeni@redhat.com, horms@kernel.org, netdev@vger.kernel.org,
 linux-kernel@vger.kernel.org
X-In-Reply-To: <au-AQ7OPf6QPyc3Q@google.com>