Skip to content

Commit 610a689

Browse files
committed
Merge branch 'rtnl-rcu'
Pedro Tammela says: ==================== net: rtnl: introduce rcu_replace_pointer_rtnl Introduce the rcu_replace_pointer_rtnl helper to lockdep check rtnl lock rcu replacements, alongside the already existing helpers. Patch 2 uses the new helper in the rtnl_unregister_* functions. Originally this change was part of the P4TC series, as it's a recurrent pattern there, but since it has a use case in mainline we are pushing it separately. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 54f4c25 + 1745234 commit 610a689

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

include/linux/rtnetlink.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ static inline bool lockdep_rtnl_is_held(void)
7979
#define rtnl_dereference(p) \
8080
rcu_dereference_protected(p, lockdep_rtnl_is_held())
8181

82+
/**
83+
* rcu_replace_pointer_rtnl - replace an RCU pointer under rtnl_lock, returning
84+
* its old value
85+
* @rp: RCU pointer, whose value is returned
86+
* @p: regular pointer
87+
*
88+
* Perform a replacement under rtnl_lock, where @rp is an RCU-annotated
89+
* pointer. The old value of @rp is returned, and @rp is set to @p
90+
*/
91+
#define rcu_replace_pointer_rtnl(rp, p) \
92+
rcu_replace_pointer(rp, p, lockdep_rtnl_is_held())
93+
8294
static inline struct netdev_queue *dev_ingress_queue(struct net_device *dev)
8395
{
8496
return rtnl_dereference(dev->ingress_queue);

net/core/rtnetlink.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,7 @@ int rtnl_unregister(int protocol, int msgtype)
342342
return -ENOENT;
343343
}
344344

345-
link = rtnl_dereference(tab[msgindex]);
346-
RCU_INIT_POINTER(tab[msgindex], NULL);
345+
link = rcu_replace_pointer_rtnl(tab[msgindex], NULL);
347346
rtnl_unlock();
348347

349348
kfree_rcu(link, rcu);
@@ -368,18 +367,13 @@ void rtnl_unregister_all(int protocol)
368367
BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
369368

370369
rtnl_lock();
371-
tab = rtnl_dereference(rtnl_msg_handlers[protocol]);
370+
tab = rcu_replace_pointer_rtnl(rtnl_msg_handlers[protocol], NULL);
372371
if (!tab) {
373372
rtnl_unlock();
374373
return;
375374
}
376-
RCU_INIT_POINTER(rtnl_msg_handlers[protocol], NULL);
377375
for (msgindex = 0; msgindex < RTM_NR_MSGTYPES; msgindex++) {
378-
link = rtnl_dereference(tab[msgindex]);
379-
if (!link)
380-
continue;
381-
382-
RCU_INIT_POINTER(tab[msgindex], NULL);
376+
link = rcu_replace_pointer_rtnl(tab[msgindex], NULL);
383377
kfree_rcu(link, rcu);
384378
}
385379
rtnl_unlock();

0 commit comments

Comments
 (0)