ipv6: use READ_ONCE()/WRITE_ONCE() on fib6_table->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 fib6_tables_seq_read() and
fib6_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-4-edumazet@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Dumazet 2024-10-09 18:44:03 +00:00 committed by Jakub Kicinski
parent 16207384d2
commit e60ea45447
3 changed files with 12 additions and 12 deletions

View File

@ -394,7 +394,7 @@ struct fib6_table {
struct fib6_node tb6_root; struct fib6_node tb6_root;
struct inet_peer_base tb6_peers; struct inet_peer_base tb6_peers;
unsigned int flags; unsigned int flags;
unsigned int fib_seq; unsigned int fib_seq; /* writes protected by rtnl_mutex */
struct hlist_head tb6_gc_hlist; /* GC candidates */ struct hlist_head tb6_gc_hlist; /* GC candidates */
#define RT6_TABLE_HAS_DFLT_ROUTER BIT(0) #define RT6_TABLE_HAS_DFLT_ROUTER BIT(0)
}; };
@ -563,7 +563,7 @@ int call_fib6_notifiers(struct net *net, enum fib_event_type event_type,
int __net_init fib6_notifier_init(struct net *net); int __net_init fib6_notifier_init(struct net *net);
void __net_exit fib6_notifier_exit(struct net *net); void __net_exit fib6_notifier_exit(struct net *net);
unsigned int fib6_tables_seq_read(struct net *net); unsigned int fib6_tables_seq_read(const struct net *net);
int fib6_tables_dump(struct net *net, struct notifier_block *nb, int fib6_tables_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
@ -632,7 +632,7 @@ void fib6_rules_cleanup(void);
bool fib6_rule_default(const struct fib_rule *rule); bool fib6_rule_default(const struct fib_rule *rule);
int fib6_rules_dump(struct net *net, struct notifier_block *nb, int fib6_rules_dump(struct net *net, struct notifier_block *nb,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
unsigned int fib6_rules_seq_read(struct net *net); unsigned int fib6_rules_seq_read(const struct net *net);
static inline bool fib6_rules_early_flow_dissect(struct net *net, static inline bool fib6_rules_early_flow_dissect(struct net *net,
struct sk_buff *skb, struct sk_buff *skb,
@ -676,7 +676,7 @@ static inline int fib6_rules_dump(struct net *net, struct notifier_block *nb,
{ {
return 0; return 0;
} }
static inline unsigned int fib6_rules_seq_read(struct net *net) static inline unsigned int fib6_rules_seq_read(const struct net *net)
{ {
return 0; return 0;
} }

View File

@ -56,7 +56,7 @@ int fib6_rules_dump(struct net *net, struct notifier_block *nb,
return fib_rules_dump(net, nb, AF_INET6, extack); return fib_rules_dump(net, nb, AF_INET6, extack);
} }
unsigned int fib6_rules_seq_read(struct net *net) unsigned int fib6_rules_seq_read(const struct net *net)
{ {
return fib_rules_seq_read(net, AF_INET6); return fib_rules_seq_read(net, AF_INET6);
} }

View File

@ -345,17 +345,17 @@ static void __net_init fib6_tables_init(struct net *net)
#endif #endif
unsigned int fib6_tables_seq_read(struct net *net) unsigned int fib6_tables_seq_read(const struct net *net)
{ {
unsigned int h, fib_seq = 0; unsigned int h, fib_seq = 0;
rcu_read_lock(); rcu_read_lock();
for (h = 0; h < FIB6_TABLE_HASHSZ; h++) { for (h = 0; h < FIB6_TABLE_HASHSZ; h++) {
struct hlist_head *head = &net->ipv6.fib_table_hash[h]; const struct hlist_head *head = &net->ipv6.fib_table_hash[h];
struct fib6_table *tb; const struct fib6_table *tb;
hlist_for_each_entry_rcu(tb, head, tb6_hlist) hlist_for_each_entry_rcu(tb, head, tb6_hlist)
fib_seq += tb->fib_seq; fib_seq += READ_ONCE(tb->fib_seq);
} }
rcu_read_unlock(); rcu_read_unlock();
@ -400,7 +400,7 @@ int call_fib6_entry_notifiers(struct net *net,
.rt = rt, .rt = rt,
}; };
rt->fib6_table->fib_seq++; WRITE_ONCE(rt->fib6_table->fib_seq, rt->fib6_table->fib_seq + 1);
return call_fib6_notifiers(net, event_type, &info.info); return call_fib6_notifiers(net, event_type, &info.info);
} }
@ -416,7 +416,7 @@ int call_fib6_multipath_entry_notifiers(struct net *net,
.nsiblings = nsiblings, .nsiblings = nsiblings,
}; };
rt->fib6_table->fib_seq++; WRITE_ONCE(rt->fib6_table->fib_seq, rt->fib6_table->fib_seq + 1);
return call_fib6_notifiers(net, event_type, &info.info); return call_fib6_notifiers(net, event_type, &info.info);
} }
@ -427,7 +427,7 @@ int call_fib6_entry_notifiers_replace(struct net *net, struct fib6_info *rt)
.nsiblings = rt->fib6_nsiblings, .nsiblings = rt->fib6_nsiblings,
}; };
rt->fib6_table->fib_seq++; WRITE_ONCE(rt->fib6_table->fib_seq, rt->fib6_table->fib_seq + 1);
return call_fib6_notifiers(net, FIB_EVENT_ENTRY_REPLACE, &info.info); return call_fib6_notifiers(net, FIB_EVENT_ENTRY_REPLACE, &info.info);
} }