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 |
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>
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 --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);