Skip to content

Commit b33eab0

Browse files
Eric Dumazetdavem330
authored andcommitted
tunnels: add __rcu annotations
Add __rcu annotations to : (struct ip_tunnel)->prl (struct ip_tunnel_prl_entry)->next (struct xfrm_tunnel)->next struct xfrm_tunnel *tunnel4_handlers struct xfrm_tunnel *tunnel64_handlers And use appropriate rcu primitives to reduce sparse warnings if CONFIG_SPARSE_RCU_POINTER=y Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e0ad61e commit b33eab0

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

‎include/net/ipip.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ struct ip_tunnel {
3434
#ifdef CONFIG_IPV6_SIT_6RD
3535
struct ip_tunnel_6rd_parm ip6rd;
3636
#endif
37-
struct ip_tunnel_prl_entry *prl; /* potential router list */
37+
struct ip_tunnel_prl_entry __rcu *prl; /* potential router list */
3838
unsigned int prl_count; /* # of entries in PRL */
3939
};
4040

4141
struct ip_tunnel_prl_entry {
42-
struct ip_tunnel_prl_entry *next;
42+
struct ip_tunnel_prl_entry __rcu *next;
4343
__be32 addr;
4444
u16 flags;
4545
struct rcu_head rcu_head;

‎include/net/xfrm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ struct xfrm_tunnel {
12641264
int (*handler)(struct sk_buff *skb);
12651265
int (*err_handler)(struct sk_buff *skb, u32 info);
12661266

1267-
struct xfrm_tunnel *next;
1267+
struct xfrm_tunnel __rcu *next;
12681268
int priority;
12691269
};
12701270

‎net/ipv4/tunnel4.c‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,32 @@
1414
#include <net/protocol.h>
1515
#include <net/xfrm.h>
1616

17-
static struct xfrm_tunnel *tunnel4_handlers __read_mostly;
18-
static struct xfrm_tunnel *tunnel64_handlers __read_mostly;
17+
static struct xfrm_tunnel __rcu *tunnel4_handlers __read_mostly;
18+
static struct xfrm_tunnel __rcu *tunnel64_handlers __read_mostly;
1919
static DEFINE_MUTEX(tunnel4_mutex);
2020

21-
static inline struct xfrm_tunnel **fam_handlers(unsigned short family)
21+
static inline struct xfrm_tunnel __rcu **fam_handlers(unsigned short family)
2222
{
2323
return (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers;
2424
}
2525

2626
int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family)
2727
{
28-
struct xfrm_tunnel **pprev;
28+
struct xfrm_tunnel __rcu **pprev;
29+
struct xfrm_tunnel *t;
30+
2931
int ret = -EEXIST;
3032
int priority = handler->priority;
3133

3234
mutex_lock(&tunnel4_mutex);
3335

34-
for (pprev = fam_handlers(family); *pprev; pprev = &(*pprev)->next) {
35-
if ((*pprev)->priority > priority)
36+
for (pprev = fam_handlers(family);
37+
(t = rcu_dereference_protected(*pprev,
38+
lockdep_is_held(&tunnel4_mutex))) != NULL;
39+
pprev = &t->next) {
40+
if (t->priority > priority)
3641
break;
37-
if ((*pprev)->priority == priority)
42+
if (t->priority == priority)
3843
goto err;
3944
}
4045

@@ -52,13 +57,17 @@ EXPORT_SYMBOL(xfrm4_tunnel_register);
5257

5358
int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family)
5459
{
55-
struct xfrm_tunnel **pprev;
60+
struct xfrm_tunnel __rcu **pprev;
61+
struct xfrm_tunnel *t;
5662
int ret = -ENOENT;
5763

5864
mutex_lock(&tunnel4_mutex);
5965

60-
for (pprev = fam_handlers(family); *pprev; pprev = &(*pprev)->next) {
61-
if (*pprev == handler) {
66+
for (pprev = fam_handlers(family);
67+
(t = rcu_dereference_protected(*pprev,
68+
lockdep_is_held(&tunnel4_mutex))) != NULL;
69+
pprev = &t->next) {
70+
if (t == handler) {
6271
*pprev = handler->next;
6372
ret = 0;
6473
break;

0 commit comments

Comments
 (0)