diff mbox series

[net-next,1/2] net: rtnl: introduce rcu_replace_pointer_rtnl

Message ID 20231215175711.323784-2-pctammela@mojatatu.com (mailing list archive)
State Accepted
Commit 32da0f00ddcb101730cf242289b2b10ede0e1156
Delegated to: Netdev Maintainers
Headers show
Series net: rtnl: introduce rcu_replace_pointer_rtnl | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
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: 4577 this patch: 4577
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1329 this patch: 1329
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: 4829 this patch: 4829
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 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

Commit Message

Pedro Tammela Dec. 15, 2023, 5:57 p.m. UTC
From: Jamal Hadi Salim <jhs@mojatatu.com>

Introduce the rcu_replace_pointer_rtnl helper to lockdep check rtnl lock
rcu replacements, alongside the already existing helpers.

This is a quality of life helper so instead of using:
   rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
   .. or the open coded..
   rtnl_dereference() / rcu_assign_pointer()
   .. or the lazy check version ..
   rcu_replace_pointer(rp, p, 1)
Use:
   rcu_replace_pointer_rtnl(rp, p)

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Victor Nogueira <victor@mojatatu.com>
Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
---
 include/linux/rtnetlink.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Ido Schimmel Dec. 17, 2023, 12:17 p.m. UTC | #1
On Fri, Dec 15, 2023 at 02:57:10PM -0300, Pedro Tammela wrote:
> From: Jamal Hadi Salim <jhs@mojatatu.com>
> 
> Introduce the rcu_replace_pointer_rtnl helper to lockdep check rtnl lock
> rcu replacements, alongside the already existing helpers.
> 
> This is a quality of life helper so instead of using:
>    rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
>    .. or the open coded..
>    rtnl_dereference() / rcu_assign_pointer()
>    .. or the lazy check version ..
>    rcu_replace_pointer(rp, p, 1)
> Use:
>    rcu_replace_pointer_rtnl(rp, p)
> 
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Victor Nogueira <victor@mojatatu.com>
> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>

Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Nikolay Aleksandrov Dec. 17, 2023, 2:19 p.m. UTC | #2
On 15/12/2023 19:57, Pedro Tammela wrote:
> From: Jamal Hadi Salim <jhs@mojatatu.com>
> 
> Introduce the rcu_replace_pointer_rtnl helper to lockdep check rtnl lock
> rcu replacements, alongside the already existing helpers.
> 
> This is a quality of life helper so instead of using:
>    rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
>    .. or the open coded..
>    rtnl_dereference() / rcu_assign_pointer()
>    .. or the lazy check version ..
>    rcu_replace_pointer(rp, p, 1)
> Use:
>    rcu_replace_pointer_rtnl(rp, p)
> 
> Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Victor Nogueira <victor@mojatatu.com>
> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
> ---
>  include/linux/rtnetlink.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
> index 6a8543b34e2c..410529fca18b 100644
> --- a/include/linux/rtnetlink.h
> +++ b/include/linux/rtnetlink.h
> @@ -79,6 +79,18 @@ static inline bool lockdep_rtnl_is_held(void)
>  #define rtnl_dereference(p)					\
>  	rcu_dereference_protected(p, lockdep_rtnl_is_held())
>  
> +/**
> + * rcu_replace_pointer_rtnl - replace an RCU pointer under rtnl_lock, returning
> + * its old value
> + * @rp: RCU pointer, whose value is returned
> + * @p: regular pointer
> + *
> + * Perform a replacement under rtnl_lock, where @rp is an RCU-annotated
> + * pointer. The old value of @rp is returned, and @rp is set to @p
> + */
> +#define rcu_replace_pointer_rtnl(rp, p)			\
> +	rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
> +
>  static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
>  {
>  	return rtnl_dereference(dev->ingress_queue);

Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
diff mbox series

Patch

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 6a8543b34e2c..410529fca18b 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -79,6 +79,18 @@  static inline bool lockdep_rtnl_is_held(void)
 #define rtnl_dereference(p)					\
 	rcu_dereference_protected(p, lockdep_rtnl_is_held())
 
+/**
+ * rcu_replace_pointer_rtnl - replace an RCU pointer under rtnl_lock, returning
+ * its old value
+ * @rp: RCU pointer, whose value is returned
+ * @p: regular pointer
+ *
+ * Perform a replacement under rtnl_lock, where @rp is an RCU-annotated
+ * pointer. The old value of @rp is returned, and @rp is set to @p
+ */
+#define rcu_replace_pointer_rtnl(rp, p)			\
+	rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
+
 static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
 {
 	return rtnl_dereference(dev->ingress_queue);