Skip to contentSkip to conversation

team: call RCU read lock when walking the port_list

PATCH Superseded Hangbin Liu 3 participants 5 messages Oct 8, 2019 – Oct 10, 2019

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

PATCH 1/1 team: call RCU read lock when walking the port_list

Before reading the team port list, we need to acquire the RCU read lock. Also change list_for_each_entry() to list_for_each_entry_rcu().

Fixes 9ed68ca0d90b ("team: add ethtool get_link_ksettings")
---
 drivers/net/team/team.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/team/team.c +4 -1
index e8089def5a46..cb1d5fe60c31 100644
@@ -2066,7 +2066,8 @@ static int team_ethtool_get_link_ksettings(struct net_device *dev,
 	cmd->base.duplex = DUPLEX_UNKNOWN;
 	cmd->base.port = PORT_OTHER;
 
-	list_for_each_entry(port, &team->port_list, list) {
+	rcu_read_lock();
+	list_for_each_entry_rcu(port, &team->port_list, list) {
 		if (team_port_txable(port)) {
 			if (port->state.speed != SPEED_UNKNOWN)
 				speed += port->state.speed;
@@ -2075,6 +2076,8 @@ static int team_ethtool_get_link_ksettings(struct net_device *dev,
 				cmd->base.duplex = port->state.duplex;
 		}
 	}
+	rcu_read_unlock();
+
 	cmd->base.speed = speed ? : SPEED_UNKNOWN;
 
 	return 0;
Signature · 1 line
2.19.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Tue, Oct 08, 2019 at 03:56:14PM CEST, [email protected] wrote:

Before reading the team port list, we need to acquire the RCU read lock. Also change list_for_each_entry() to list_for_each_entry_rcu().

Fixes 9ed68ca0d90b ("team: add ethtool get_link_ksettings")

It is not strictly needed a since rtnl is taken, but similar list iteration in team is designed to work without rtnl dependency.

Thanks!

Quoted 30 lines

---
drivers/net/team/team.c | 5 ++++-

1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/team/team.c +4 -1
index e8089def5a46..cb1d5fe60c31 100644
@@ -2066,7 +2066,8 @@ static int team_ethtool_get_link_ksettings(struct net_device *dev,
 	cmd->base.duplex = DUPLEX_UNKNOWN;
 	cmd->base.port = PORT_OTHER;
 
-	list_for_each_entry(port, &team->port_list, list) {
+	rcu_read_lock();
+	list_for_each_entry_rcu(port, &team->port_list, list) {
 		if (team_port_txable(port)) {
 			if (port->state.speed != SPEED_UNKNOWN)
 				speed += port->state.speed;
@@ -2075,6 +2076,8 @@ static int team_ethtool_get_link_ksettings(struct net_device *dev,
 				cmd->base.duplex = port->state.duplex;
 		}
 	}
+	rcu_read_unlock();
+
 	cmd->base.speed = speed ? : SPEED_UNKNOWN;
 
 	return 0;
Signature · 1 line
2.19.2
#2 lore raw
Quoted 9 lines · Jiri Pirko
Quoted 7 lines · Tue, Oct 08, 2019 at 03:56:14PM CEST, [email protected] wrote:

Before reading the team port list, we need to acquire the RCU read lock. Also change list_for_each_entry() to list_for_each_entry_rcu().

Fixes 9ed68ca0d90b ("team: add ethtool get_link_ksettings")
Quoted 4 lines

It is not strictly needed a since rtnl is taken, but similar list iteration in team is designed to work without rtnl dependency.

IIUC this is a cosmetic change and non-RCU iteration seems to be used in a few places in team.c. Can we get this reposted for net-next, and without the Fixes tag? Please keep Jiri's Ack.

#3 lore raw

PATCH v2 1/1 team: call RCU read lock when walking the port_list

In reply to Hangbin Liu

Before reading the team port list, we need to acquire the RCU read lock. Also change list_for_each_entry() to list_for_each_entry_rcu().

v2:
repost the patch to net-next and remove fixes flag as this is a cosmetic change.

---
 drivers/net/team/team.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/team/team.c +4 -1
index e8089def5a46..cb1d5fe60c31 100644
@@ -2066,7 +2066,8 @@ static int team_ethtool_get_link_ksettings(struct net_device *dev,
 	cmd->base.duplex = DUPLEX_UNKNOWN;
 	cmd->base.port = PORT_OTHER;
 
-	list_for_each_entry(port, &team->port_list, list) {
+	rcu_read_lock();
+	list_for_each_entry_rcu(port, &team->port_list, list) {
 		if (team_port_txable(port)) {
 			if (port->state.speed != SPEED_UNKNOWN)
 				speed += port->state.speed;
@@ -2075,6 +2076,8 @@ static int team_ethtool_get_link_ksettings(struct net_device *dev,
 				cmd->base.duplex = port->state.duplex;
 		}
 	}
+	rcu_read_unlock();
+
 	cmd->base.speed = speed ? : SPEED_UNKNOWN;
 
 	return 0;
Signature · 1 line
2.19.2