Skip to contentSkip to conversation

bonding: annotate data-races in sysfs and procfs

PATCH Applied Eric Dumazet 3 participants 3 messages Jun 2 – Jun 5

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bonding: annotate data-races in sysfs and procfs

bonding sysfs and procfs read parameters locklessly, while drivers/net/bonding/bond_options.c can write over them.

Add missing READ_ONCE()/WRITE_ONCE() annotations.

This came as a prereq to avoid RTNL in bond_fill_info().

---
Cc: Jay Vosburgh <[email protected]>
Cc: Andrew Lunn <[email protected]>

---
 drivers/net/bonding/bond_options.c | 65 ++++++++++----------
 drivers/net/bonding/bond_procfs.c  | 48 ++++++++-------
 drivers/net/bonding/bond_sysfs.c   | 98 +++++++++++++++++-------------
 3 files changed, 117 insertions(+), 94 deletions(-)
drivers/net/bonding/bond_options.c +33 -32
index 7380cc4ee75a9087dff45486dd199d2be790a036..5095ac3dad2cd924ff548343c7c1afe3e57e3065 100644
@@ -902,22 +902,22 @@ static int bond_option_mode_set(struct bonding *bond,
 			netdev_dbg(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n",
 				   newval->string);
 			/* disable arp monitoring */
-			bond->params.arp_interval = 0;
+			WRITE_ONCE(bond->params.arp_interval, 0);
 		}
 
 		if (!bond->params.miimon) {
 			/* set miimon to default value */
-			bond->params.miimon = BOND_DEFAULT_MIIMON;
+			WRITE_ONCE(bond->params.miimon, BOND_DEFAULT_MIIMON);
 			netdev_dbg(bond->dev, "Setting MII monitoring interval to %d\n",
 				   bond->params.miimon);
 		}
 	}
 
 	if (newval->value == BOND_MODE_ALB)
-		bond->params.tlb_dynamic_lb = 1;
+		WRITE_ONCE(bond->params.tlb_dynamic_lb, 1);
 
 	/* don't cache arp_validate between modes */
-	bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
+	WRITE_ONCE(bond->params.arp_validate, BOND_ARP_VALIDATE_NONE);
 	bond->params.mode = newval->value;
 
 	/* When changing mode, the bond device is down, we may reduce
@@ -1010,7 +1010,7 @@ static int bond_option_miimon_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting MII monitoring interval to %llu\n",
 		   newval->value);
-	bond->params.miimon = newval->value;
+	WRITE_ONCE(bond->params.miimon, newval->value);
 	if (bond->params.updelay)
 		netdev_dbg(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n",
 			   bond->params.updelay * bond->params.miimon);
@@ -1022,9 +1022,10 @@ static int bond_option_miimon_set(struct bonding *bond,
 			   bond->params.peer_notif_delay * bond->params.miimon);
 	if (newval->value && bond->params.arp_interval) {
 		netdev_dbg(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n");
-		bond->params.arp_interval = 0;
+		WRITE_ONCE(bond->params.arp_interval, 0);
 		if (bond->params.arp_validate)
-			bond->params.arp_validate = BOND_ARP_VALIDATE_NONE;
+			WRITE_ONCE(bond->params.arp_validate,
+				   BOND_ARP_VALIDATE_NONE);
 	}
 	if (bond->dev->flags & IFF_UP) {
 		/* If the interface is up, we may need to fire off
@@ -1067,7 +1068,7 @@ static int _bond_option_delay_set(struct bonding *bond,
 			    (value / bond->params.miimon) *
 			    bond->params.miimon);
 	}
-	*target = value / bond->params.miimon;
+	WRITE_ONCE(*target, value / bond->params.miimon);
 	netdev_dbg(bond->dev, "Setting %s to %d\n",
 		   name,
 		   *target * bond->params.miimon);
@@ -1113,11 +1114,11 @@ static int bond_option_arp_interval_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting ARP monitoring interval to %llu\n",
 		   newval->value);
-	bond->params.arp_interval = newval->value;
+	WRITE_ONCE(bond->params.arp_interval, newval->value);
 	if (newval->value) {
 		if (bond->params.miimon) {
 			netdev_dbg(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring\n");
-			bond->params.miimon = 0;
+			WRITE_ONCE(bond->params.miimon, 0);
 		}
 		if (!bond->params.arp_targets[0])
 			netdev_dbg(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n");
@@ -1154,7 +1155,7 @@ static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot,
 	if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) {
 		bond_for_each_slave(bond, slave, iter)
 			WRITE_ONCE(slave->target_last_arp_rx[slot], last_rx);
-		targets[slot] = target;
+		WRITE_ONCE(targets[slot], target);
 	}
 }
 
@@ -1226,8 +1227,8 @@ static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target)
 		WRITE_ONCE(targets_rx[i], 0);
 	}
 	for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++)
-		targets[i] = targets[i+1];
-	targets[i] = 0;
+		WRITE_ONCE(targets[i], targets[i+1]);
+	WRITE_ONCE(targets[i], 0);
 
 	return 0;
 }
@@ -1449,7 +1450,7 @@ static int bond_option_arp_validate_set(struct bonding *bond,
 
 	netdev_dbg(bond->dev, "Setting arp_validate to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.arp_validate = newval->value;
+	WRITE_ONCE(bond->params.arp_validate, newval->value);
 
 	if (changed) {
 		bond_for_each_slave(bond, slave, iter)
@@ -1464,7 +1465,7 @@ static int bond_option_arp_all_targets_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting arp_all_targets to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.arp_all_targets = newval->value;
+	WRITE_ONCE(bond->params.arp_all_targets, newval->value);
 
 	return 0;
 }
@@ -1474,7 +1475,7 @@ static int bond_option_missed_max_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting missed max to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.missed_max = newval->value;
+	WRITE_ONCE(bond->params.missed_max, newval->value);
 
 	return 0;
 }
@@ -1553,7 +1554,7 @@ static int bond_option_primary_reselect_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting primary_reselect to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.primary_reselect = newval->value;
+	WRITE_ONCE(bond->params.primary_reselect, newval->value);
 
 	block_netpoll_tx();
 	bond_select_active_slave(bond);
@@ -1567,7 +1568,7 @@ static int bond_option_fail_over_mac_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting fail_over_mac to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.fail_over_mac = newval->value;
+	WRITE_ONCE(bond->params.fail_over_mac, newval->value);
 
 	return 0;
 }
@@ -1579,7 +1580,7 @@ static int bond_option_xmit_hash_policy_set(struct bonding *bond,
 		return -EOPNOTSUPP;
 	netdev_dbg(bond->dev, "Setting xmit hash policy to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.xmit_policy = newval->value;
+	WRITE_ONCE(bond->params.xmit_policy, newval->value);
 
 	return 0;
 }
@@ -1589,7 +1590,7 @@ static int bond_option_resend_igmp_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting resend_igmp to %llu\n",
 		   newval->value);
-	bond->params.resend_igmp = newval->value;
+	WRITE_ONCE(bond->params.resend_igmp, newval->value);
 
 	return 0;
 }
@@ -1597,7 +1598,7 @@ static int bond_option_resend_igmp_set(struct bonding *bond,
 static int bond_option_num_peer_notif_set(struct bonding *bond,
 				   const struct bond_opt_value *newval)
 {
-	bond->params.num_peer_notif = newval->value;
+	WRITE_ONCE(bond->params.num_peer_notif, newval->value);
 
 	return 0;
 }
@@ -1610,7 +1611,7 @@ static int bond_option_all_slaves_active_set(struct bonding *bond,
 
 	if (newval->value == bond->params.all_slaves_active)
 		return 0;
-	bond->params.all_slaves_active = newval->value;
+	WRITE_ONCE(bond->params.all_slaves_active, newval->value);
 	bond_for_each_slave(bond, slave, iter) {
 		if (!bond_is_active_slave(slave)) {
 			if (newval->value)
@@ -1628,7 +1629,7 @@ static int bond_option_min_links_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting min links value to %llu\n",
 		   newval->value);
-	bond->params.min_links = newval->value;
+	WRITE_ONCE(bond->params.min_links, newval->value);
 	bond_set_carrier(bond);
 
 	return 0;
@@ -1637,7 +1638,7 @@ static int bond_option_min_links_set(struct bonding *bond,
 static int bond_option_lp_interval_set(struct bonding *bond,
 				       const struct bond_opt_value *newval)
 {
-	bond->params.lp_interval = newval->value;
+	WRITE_ONCE(bond->params.lp_interval, newval->value);
 
 	return 0;
 }
@@ -1647,7 +1648,7 @@ static int bond_option_pps_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting packets per slave to %llu\n",
 		   newval->value);
-	bond->params.packets_per_slave = newval->value;
+	WRITE_ONCE(bond->params.packets_per_slave, newval->value);
 	if (newval->value > 0) {
 		bond->params.reciprocal_packets_per_slave =
 			reciprocal_value(newval->value);
@@ -1667,7 +1668,7 @@ static int bond_option_lacp_active_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting LACP active to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.lacp_active = newval->value;
+	WRITE_ONCE(bond->params.lacp_active, newval->value);
 	bond_3ad_update_lacp_active(bond);
 
 	return 0;
@@ -1678,7 +1679,7 @@ static int bond_option_lacp_rate_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting LACP rate to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.lacp_fast = newval->value;
+	WRITE_ONCE(bond->params.lacp_fast, newval->value);
 	bond_3ad_update_lacp_rate(bond);
 
 	return 0;
@@ -1689,7 +1690,7 @@ static int bond_option_ad_select_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting ad_select to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.ad_select = newval->value;
+	WRITE_ONCE(bond->params.ad_select, newval->value);
 
 	return 0;
 }
@@ -1808,7 +1809,7 @@ static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
 {
 	netdev_dbg(bond->dev, "Setting dynamic-lb to %s (%llu)\n",
 		   newval->string, newval->value);
-	bond->params.tlb_dynamic_lb = newval->value;
+	WRITE_ONCE(bond->params.tlb_dynamic_lb, newval->value);
 
 	return 0;
 }
@@ -1819,7 +1820,7 @@ static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
 	netdev_dbg(bond->dev, "Setting ad_actor_sys_prio to %llu\n",
 		   newval->value);
 
-	bond->params.ad_actor_sys_prio = newval->value;
+	WRITE_ONCE(bond->params.ad_actor_sys_prio, newval->value);
 	bond_3ad_update_ad_actor_settings(bond);
 
 	return 0;
@@ -1879,7 +1880,7 @@ static int bond_option_ad_user_port_key_set(struct bonding *bond,
 	netdev_dbg(bond->dev, "Setting ad_user_port_key to %llu\n",
 		   newval->value);
 
-	bond->params.ad_user_port_key = newval->value;
+	WRITE_ONCE(bond->params.ad_user_port_key, newval->value);
 	return 0;
 }
 
@@ -1889,7 +1890,7 @@ static int bond_option_coupled_control_set(struct bonding *bond,
 	netdev_info(bond->dev, "Setting coupled_control to %s (%llu)\n",
 		    newval->string, newval->value);
 
-	bond->params.coupled_control = newval->value;
+	WRITE_ONCE(bond->params.coupled_control, newval->value);
 	return 0;
 }
 
drivers/net/bonding/bond_procfs.c +27 -21

105 lines not on this page · raw message

drivers/net/bonding/bond_sysfs.c +57 -41

258 lines not on this page · raw message

Signature · 1 line
2.54.0.929.g9b7fa37559-goog
#2 lore raw
In reply to Eric Dumazet
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:

Quoted 8 lines · On Tue, 2 Jun 2026 15:27:48 +0000 you wrote:

bonding sysfs and procfs read parameters locklessly, while drivers/net/bonding/bond_options.c can write over them.

Add missing READ_ONCE()/WRITE_ONCE() annotations.

This came as a prereq to avoid RTNL in bond_fill_info().

[...]

Here is the summary with links:
- [net-next] bonding: annotate data-races in sysfs and procfs

    https://git.kernel.org/netdev/net-next/c/4dc5a40b3bc9

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html