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.

fib: rules: use READ_ONCE()/WRITE_ONCE() on ops->fib_rules_seq

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

Writes are protected by RTNL.
We can use READ_ONCE() on readers.

Constify 'struct net' argument of fib_rules_seq_read()
and lookup_rules_ops().

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-2-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Eric Dumazet and committed by
Jakub Kicinski
a716ff52 d677aebd

+9 -7
+1 -1
include/net/fib_rules.h
··· 176 176 bool fib_rule_matchall(const struct fib_rule *rule); 177 177 int fib_rules_dump(struct net *net, struct notifier_block *nb, int family, 178 178 struct netlink_ext_ack *extack); 179 - unsigned int fib_rules_seq_read(struct net *net, int family); 179 + unsigned int fib_rules_seq_read(const struct net *net, int family); 180 180 181 181 int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, 182 182 struct netlink_ext_ack *extack);
+8 -6
net/core/fib_rules.c
··· 101 101 struct fib_rules_ops *ops, struct nlmsghdr *nlh, 102 102 u32 pid); 103 103 104 - static struct fib_rules_ops *lookup_rules_ops(struct net *net, int family) 104 + static struct fib_rules_ops *lookup_rules_ops(const struct net *net, 105 + int family) 105 106 { 106 107 struct fib_rules_ops *ops; 107 108 ··· 371 370 .rule = rule, 372 371 }; 373 372 374 - ops->fib_rules_seq++; 373 + ASSERT_RTNL(); 374 + /* Paired with READ_ONCE() in fib_rules_seq() */ 375 + WRITE_ONCE(ops->fib_rules_seq, ops->fib_rules_seq + 1); 375 376 return call_fib_notifiers(net, event_type, &info.info); 376 377 } 377 378 ··· 400 397 } 401 398 EXPORT_SYMBOL_GPL(fib_rules_dump); 402 399 403 - unsigned int fib_rules_seq_read(struct net *net, int family) 400 + unsigned int fib_rules_seq_read(const struct net *net, int family) 404 401 { 405 402 unsigned int fib_rules_seq; 406 403 struct fib_rules_ops *ops; 407 404 408 - ASSERT_RTNL(); 409 - 410 405 ops = lookup_rules_ops(net, family); 411 406 if (!ops) 412 407 return 0; 413 - fib_rules_seq = ops->fib_rules_seq; 408 + /* Paired with WRITE_ONCE() in call_fib_rule_notifiers() */ 409 + fib_rules_seq = READ_ONCE(ops->fib_rules_seq); 414 410 rules_ops_put(ops); 415 411 416 412 return fib_rules_seq;