Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipv4: use READ_ONCE()/WRITE_ONCE() on net->ipv4.fib_seq

Using RTNL to protect ops->fib_rules_seq reads seems a big hammer.

Writes are protected by RTNL.
We can use READ_ONCE() when reading it.

Constify 'struct net' argument of fib4_rules_seq_read()

Signed-off-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20241009184405.3752829-3-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
16207384 a716ff52

+8 -8
+2 -2
include/net/ip_fib.h
··· 347 347 return 0; 348 348 } 349 349 350 - static inline unsigned int fib4_rules_seq_read(struct net *net) 350 + static inline unsigned int fib4_rules_seq_read(const struct net *net) 351 351 { 352 352 return 0; 353 353 } ··· 411 411 bool fib4_rule_default(const struct fib_rule *rule); 412 412 int fib4_rules_dump(struct net *net, struct notifier_block *nb, 413 413 struct netlink_ext_ack *extack); 414 - unsigned int fib4_rules_seq_read(struct net *net); 414 + unsigned int fib4_rules_seq_read(const struct net *net); 415 415 416 416 static inline bool fib4_rules_early_flow_dissect(struct net *net, 417 417 struct sk_buff *skb,
+1 -1
include/net/netns/ipv4.h
··· 262 262 #endif 263 263 264 264 struct fib_notifier_ops *notifier_ops; 265 - unsigned int fib_seq; /* protected by rtnl_mutex */ 265 + unsigned int fib_seq; /* writes protected by rtnl_mutex */ 266 266 267 267 struct fib_notifier_ops *ipmr_notifier_ops; 268 268 unsigned int ipmr_seq; /* protected by rtnl_mutex */
+4 -4
net/ipv4/fib_notifier.c
··· 22 22 ASSERT_RTNL(); 23 23 24 24 info->family = AF_INET; 25 - net->ipv4.fib_seq++; 25 + /* Paired with READ_ONCE() in fib4_seq_read() */ 26 + WRITE_ONCE(net->ipv4.fib_seq, net->ipv4.fib_seq + 1); 26 27 return call_fib_notifiers(net, event_type, info); 27 28 } 28 29 29 30 static unsigned int fib4_seq_read(struct net *net) 30 31 { 31 - ASSERT_RTNL(); 32 - 33 - return net->ipv4.fib_seq + fib4_rules_seq_read(net); 32 + /* Paired with WRITE_ONCE() in call_fib4_notifiers() */ 33 + return READ_ONCE(net->ipv4.fib_seq) + fib4_rules_seq_read(net); 34 34 } 35 35 36 36 static int fib4_dump(struct net *net, struct notifier_block *nb,
+1 -1
net/ipv4/fib_rules.c
··· 74 74 return fib_rules_dump(net, nb, AF_INET, extack); 75 75 } 76 76 77 - unsigned int fib4_rules_seq_read(struct net *net) 77 + unsigned int fib4_rules_seq_read(const struct net *net) 78 78 { 79 79 return fib_rules_seq_read(net, AF_INET); 80 80 }