netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 1/2] net: bonding: correctly annotate RCU in bond_should_notify_peers()
@ 2024-07-18 19:20 Johannes Berg
  2024-07-18 19:20 ` [RFC PATCH 2/2] net: bonding: don't call ethtool methods under RCU Johannes Berg
  2024-07-19  9:42 ` [RFC PATCH 1/2] net: bonding: correctly annotate RCU in bond_should_notify_peers() Jiri Pirko
  0 siblings, 2 replies; 10+ messages in thread
From: Johannes Berg @ 2024-07-18 19:20 UTC (permalink / raw)
  To: netdev; +Cc: Eric Dumazet, Johannes Berg

From: Johannes Berg <johannes.berg@intel.com>

RCU use in bond_should_notify_peers() looks wrong, since it does
rcu_dereference(), leaves the critical section, and uses the
pointer after that.

Luckily, it's called either inside a nested RCU critical section
or with the RTNL held.

Annotate it with rcu_dereference_rtnl() instead, and remove the
inner RCU critical section.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
---
 drivers/net/bonding/bond_main.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index d19aabf5d4fb..2ed0da068490 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1121,13 +1121,10 @@ static struct slave *bond_find_best_slave(struct bonding *bond)
 	return bestslave;
 }
 
+/* must be called in RCU critical section or with RTNL held */
 static bool bond_should_notify_peers(struct bonding *bond)
 {
-	struct slave *slave;
-
-	rcu_read_lock();
-	slave = rcu_dereference(bond->curr_active_slave);
-	rcu_read_unlock();
+	struct slave *slave = rcu_dereference_rtnl(bond->curr_active_slave);
 
 	if (!slave || !bond->send_peer_notif ||
 	    bond->send_peer_notif %
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-07-23 14:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-18 19:20 [RFC PATCH 1/2] net: bonding: correctly annotate RCU in bond_should_notify_peers() Johannes Berg
2024-07-18 19:20 ` [RFC PATCH 2/2] net: bonding: don't call ethtool methods under RCU Johannes Berg
2024-07-18 21:12   ` Jay Vosburgh
2024-07-19 16:37     ` Johannes Berg
2024-07-19  9:50   ` Jiri Pirko
2024-07-19 16:31     ` Johannes Berg
2024-07-19  9:42 ` [RFC PATCH 1/2] net: bonding: correctly annotate RCU in bond_should_notify_peers() Jiri Pirko
2024-07-19 16:31   ` Johannes Berg
2024-07-23 14:22     ` Jiri Pirko
2024-07-23 14:27       ` Johannes Berg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).