netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtnl: Add guard support
@ 2025-11-28  8:34 Fushuai Wang
  2025-11-29  3:45 ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Fushuai Wang @ 2025-11-28  8:34 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni, horms
  Cc: netdev, linux-kernel, wangfushuai, Fushuai Wang

Introduce guard support to simplify the usage of the
lock about rtnl.

Signed-off-by: Fushuai Wang <wangfushuai@baidu.com>
---
 include/linux/rtnetlink.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index ea39dd23a197..61e727c35927 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -7,6 +7,7 @@
 #include <linux/netdevice.h>
 #include <linux/wait.h>
 #include <linux/refcount.h>
+#include <linux/cleanup.h>
 #include <uapi/linux/rtnetlink.h>
 
 extern int rtnetlink_send(struct sk_buff *skb, struct net *net, u32 pid, u32 group, int echo);
@@ -158,6 +159,16 @@ static inline void ASSERT_RTNL_NET(struct net *net)
 	rcu_replace_pointer_rtnl(rp, p)
 #endif
 
+DEFINE_LOCK_GUARD_0(rtnl, rtnl_lock(), rtnl_unlock())
+
+DEFINE_GUARD(__rtnl_net, struct net *, __rtnl_net_lock(_T),
+	     __rtnl_net_unlock(_T))
+
+DEFINE_GUARD(rtnl_net, struct net *, rtnl_net_lock(_T),
+	     rtnl_net_unlock(_T))
+DEFINE_GUARD_COND(rtnl_net, _try, rtnl_net_trylock(_T))
+DEFINE_GUARD_COND(rtnl_net, _kill, rtnl_net_lock_killable(_T), _RET == 0)
+
 static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
 {
 	return rtnl_dereference(dev->ingress_queue);
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtnl: Add guard support
  2025-11-28  8:34 [PATCH] rtnl: Add guard support Fushuai Wang
@ 2025-11-29  3:45 ` Jakub Kicinski
  2025-11-29  8:35   ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Jakub Kicinski @ 2025-11-29  3:45 UTC (permalink / raw)
  To: Fushuai Wang
  Cc: davem, edumazet, pabeni, horms, netdev, linux-kernel, wangfushuai

On Fri, 28 Nov 2025 16:34:55 +0800 Fushuai Wang wrote:
> Introduce guard support to simplify the usage of the
> lock about rtnl.

We don't accept APIs without a user.

Also in this case please read:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#using-device-managed-and-cleanup-h-constructs
-- 
pw-bot: reject

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rtnl: Add guard support
  2025-11-29  3:45 ` Jakub Kicinski
@ 2025-11-29  8:35   ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2025-11-29  8:35 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Fushuai Wang, davem, pabeni, horms, netdev, linux-kernel,
	wangfushuai

On Fri, Nov 28, 2025 at 7:45 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Fri, 28 Nov 2025 16:34:55 +0800 Fushuai Wang wrote:
> > Introduce guard support to simplify the usage of the
> > lock about rtnl.
>
> We don't accept APIs without a user.
>
> Also in this case please read:
> https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#using-device-managed-and-cleanup-h-constructs

Another argument is that we are working hard to _remove_ RTNL these days.
This is a multi-years huge effort.

Adding such helpers are spreading a wrong signal : "Look how it is
easy to add more RTNL sections in the kernel"

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-29  8:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-28  8:34 [PATCH] rtnl: Add guard support Fushuai Wang
2025-11-29  3:45 ` Jakub Kicinski
2025-11-29  8:35   ` Eric Dumazet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).