diff mbox series

[net-next,v2,1/2] rtnetlink: add guard for RTNL

Message ID 20240328082748.b6003379b15b.I9da87266ad39fff647828b5822e6ac8898857b71@changeid (mailing list archive)
State Accepted
Commit 464eb03c4a7cfb32cb3324249193cf6bb5b35152
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2,1/2] rtnetlink: add guard for RTNL | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 4342 this patch: 4342
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1035 this patch: 1035
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4546 this patch: 4546
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 15 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-31--03-00 (tests: 953)

Commit Message

Johannes Berg March 28, 2024, 7:27 a.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

The new guard/scoped_gard can be useful for the RTNL as well,
so add a guard definition for it. It gets used like

 {
   guard(rtnl)();
   // RTNL held until end of block
 }

or

  scoped_guard(rtnl) {
    // RTNL held in this block
  }

as with any other guard/scoped_guard.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
v2: resend
---
 include/linux/rtnetlink.h | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Horman April 2, 2024, 8:27 a.m. UTC | #1
On Thu, Mar 28, 2024 at 08:27:49AM +0100, Johannes Berg wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> The new guard/scoped_gard can be useful for the RTNL as well,
> so add a guard definition for it. It gets used like
> 
>  {
>    guard(rtnl)();
>    // RTNL held until end of block
>  }
> 
> or
> 
>   scoped_guard(rtnl) {
>     // RTNL held in this block
>   }
> 
> as with any other guard/scoped_guard.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>

Reviewed-by: Simon Horman <horms@kernel.org>
Jiri Pirko April 2, 2024, 12:31 p.m. UTC | #2
Thu, Mar 28, 2024 at 08:27:49AM CET, johannes@sipsolutions.net wrote:
>From: Johannes Berg <johannes.berg@intel.com>
>
>The new guard/scoped_gard can be useful for the RTNL as well,
>so add a guard definition for it. It gets used like
>
> {
>   guard(rtnl)();
>   // RTNL held until end of block
> }
>
>or
>
>  scoped_guard(rtnl) {
>    // RTNL held in this block
>  }
>
>as with any other guard/scoped_guard.
>
>Signed-off-by: Johannes Berg <johannes.berg@intel.com>

Since you add couple of helpers, I believe it is a nice custom to add a
couple of patches that actually uses them. Would that make sense?


>---
>v2: resend
>---
> include/linux/rtnetlink.h | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
>index cdfc897f1e3c..a7da7dfc06a2 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);
>@@ -46,6 +47,8 @@ extern int rtnl_is_locked(void);
> extern int rtnl_lock_killable(void);
> extern bool refcount_dec_and_rtnl_lock(refcount_t *r);
> 
>+DEFINE_LOCK_GUARD_0(rtnl, rtnl_lock(), rtnl_unlock())
>+
> extern wait_queue_head_t netdev_unregistering_wq;
> extern atomic_t dev_unreg_count;
> extern struct rw_semaphore pernet_ops_rwsem;
>-- 
>2.44.0
>
Jakub Kicinski April 2, 2024, 3:04 p.m. UTC | #3
On Tue, 2 Apr 2024 14:31:31 +0200 Jiri Pirko wrote:
> >Signed-off-by: Johannes Berg <johannes.berg@intel.com>  
> 
> Since you add couple of helpers, I believe it is a nice custom to add a
> couple of patches that actually uses them. Would that make sense?

We discussed on v1, we want to open up the use in new code but
I don't see any benefit in rewriting existing, well tested code.
The first users are likely to be in wireless.
patchwork-bot+netdevbpf@kernel.org April 3, 2024, 9 a.m. UTC | #4
Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 28 Mar 2024 08:27:49 +0100 you wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> The new guard/scoped_gard can be useful for the RTNL as well,
> so add a guard definition for it. It gets used like
> 
>  {
>    guard(rtnl)();
>    // RTNL held until end of block
>  }
> 
> [...]

Here is the summary with links:
  - [net-next,v2,1/2] rtnetlink: add guard for RTNL
    https://git.kernel.org/netdev/net-next/c/464eb03c4a7c
  - [net-next,v2,2/2] netdevice: add DEFINE_FREE() for dev_put
    https://git.kernel.org/netdev/net-next/c/b1f81b9a535b

You are awesome, thank you!
diff mbox series

Patch

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index cdfc897f1e3c..a7da7dfc06a2 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);
@@ -46,6 +47,8 @@  extern int rtnl_is_locked(void);
 extern int rtnl_lock_killable(void);
 extern bool refcount_dec_and_rtnl_lock(refcount_t *r);
 
+DEFINE_LOCK_GUARD_0(rtnl, rtnl_lock(), rtnl_unlock())
+
 extern wait_queue_head_t netdev_unregistering_wq;
 extern atomic_t dev_unreg_count;
 extern struct rw_semaphore pernet_ops_rwsem;