Skip to content

Commit 51e1368

Browse files
kuba-moodavem330
authored andcommitted
rtnetlink: RCU-annotate both dimensions of rtnl_msg_handlers
We use rcu_assign_pointer to assign both the table and the entries, but the entries are not marked as __rcu. This generates sparse warnings. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1d608d2 commit 51e1368

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

net/core/rtnetlink.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ bool lockdep_rtnl_is_held(void)
139139
EXPORT_SYMBOL(lockdep_rtnl_is_held);
140140
#endif /* #ifdef CONFIG_PROVE_LOCKING */
141141

142-
static struct rtnl_link *__rcu *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
142+
static struct rtnl_link __rcu *__rcu *rtnl_msg_handlers[RTNL_FAMILY_MAX + 1];
143143

144144
static inline int rtm_msgindex(int msgtype)
145145
{
@@ -157,7 +157,7 @@ static inline int rtm_msgindex(int msgtype)
157157

158158
static struct rtnl_link *rtnl_get_link(int protocol, int msgtype)
159159
{
160-
struct rtnl_link **tab;
160+
struct rtnl_link __rcu **tab;
161161

162162
if (protocol >= ARRAY_SIZE(rtnl_msg_handlers))
163163
protocol = PF_UNSPEC;
@@ -166,7 +166,7 @@ static struct rtnl_link *rtnl_get_link(int protocol, int msgtype)
166166
if (!tab)
167167
tab = rcu_dereference_rtnl(rtnl_msg_handlers[PF_UNSPEC]);
168168

169-
return tab[msgtype];
169+
return rcu_dereference_rtnl(tab[msgtype]);
170170
}
171171

172172
static int rtnl_register_internal(struct module *owner,
@@ -183,7 +183,7 @@ static int rtnl_register_internal(struct module *owner,
183183
msgindex = rtm_msgindex(msgtype);
184184

185185
rtnl_lock();
186-
tab = rtnl_msg_handlers[protocol];
186+
tab = rtnl_dereference(rtnl_msg_handlers[protocol]);
187187
if (tab == NULL) {
188188
tab = kcalloc(RTM_NR_MSGTYPES, sizeof(void *), GFP_KERNEL);
189189
if (!tab)
@@ -286,7 +286,8 @@ void rtnl_register(int protocol, int msgtype,
286286
*/
287287
int rtnl_unregister(int protocol, int msgtype)
288288
{
289-
struct rtnl_link **tab, *link;
289+
struct rtnl_link __rcu **tab;
290+
struct rtnl_link *link;
290291
int msgindex;
291292

292293
BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
@@ -299,7 +300,7 @@ int rtnl_unregister(int protocol, int msgtype)
299300
return -ENOENT;
300301
}
301302

302-
link = tab[msgindex];
303+
link = rtnl_dereference(tab[msgindex]);
303304
rcu_assign_pointer(tab[msgindex], NULL);
304305
rtnl_unlock();
305306

@@ -318,20 +319,21 @@ EXPORT_SYMBOL_GPL(rtnl_unregister);
318319
*/
319320
void rtnl_unregister_all(int protocol)
320321
{
321-
struct rtnl_link **tab, *link;
322+
struct rtnl_link __rcu **tab;
323+
struct rtnl_link *link;
322324
int msgindex;
323325

324326
BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX);
325327

326328
rtnl_lock();
327-
tab = rtnl_msg_handlers[protocol];
329+
tab = rtnl_dereference(rtnl_msg_handlers[protocol]);
328330
if (!tab) {
329331
rtnl_unlock();
330332
return;
331333
}
332334
RCU_INIT_POINTER(rtnl_msg_handlers[protocol], NULL);
333335
for (msgindex = 0; msgindex < RTM_NR_MSGTYPES; msgindex++) {
334-
link = tab[msgindex];
336+
link = rtnl_dereference(tab[msgindex]);
335337
if (!link)
336338
continue;
337339

@@ -3754,7 +3756,7 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
37543756
s_idx = 1;
37553757

37563758
for (idx = 1; idx <= RTNL_FAMILY_MAX; idx++) {
3757-
struct rtnl_link **tab;
3759+
struct rtnl_link __rcu **tab;
37583760
struct rtnl_link *link;
37593761
rtnl_dumpit_func dumpit;
37603762

@@ -3768,7 +3770,7 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
37683770
if (!tab)
37693771
continue;
37703772

3771-
link = tab[type];
3773+
link = rcu_dereference_rtnl(tab[type]);
37723774
if (!link)
37733775
continue;
37743776

0 commit comments

Comments
 (0)