Skip to contentSkip to conversation

net: xdp: don't call notifiers during driver init

PATCH Superseded Jakub Kicinski 4 participants 6 messages Mar 16, 2023

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 net: xdp: don't call notifiers during driver init

Drivers will commonly perform feature setting during init, if they use the xdp_set_features_flag() helper they'll likely run into an ASSERT_RTNL() inside call_netdevice_notifiers_info().

Don't call the notifier until the device is actually registered. Nothing should be tracking the device until its registered.

Fixes 4d5ab0ad964d ("net/mlx5e: take into account device reconfiguration for xdp_features flag")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/core/xdp.c | 3 +++
 1 file changed, 3 insertions(+)
net/core/xdp.c +3 -0
index 87e654b7d06c..5722a1fc6e9e 100644
@@ -781,6 +781,9 @@ void xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
 		return;
 
 	dev->xdp_features = val;
+
+	if (dev->reg_state < NETREG_REGISTERED)
+		return;
 	call_netdevice_notifiers(NETDEV_XDP_FEAT_CHANGE, dev);
 }
 EXPORT_SYMBOL_GPL(xdp_set_features_flag);
Signature · 1 line
2.39.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 38 lines · Jakub Kicinski

Drivers will commonly perform feature setting during init, if they use the xdp_set_features_flag() helper they'll likely run into an ASSERT_RTNL() inside call_netdevice_notifiers_info().

Don't call the notifier until the device is actually registered. Nothing should be tracking the device until its registered.

Fixes 4d5ab0ad964d ("net/mlx5e: take into account device reconfiguration for xdp_features flag")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 net/core/xdp.c | 3 +++
 1 file changed, 3 insertions(+)
net/core/xdp.c +3 -0
index 87e654b7d06c..5722a1fc6e9e 100644
@@ -781,6 +781,9 @@ void xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
 		return;
 
 	dev->xdp_features = val;
+
+	if (dev->reg_state < NETREG_REGISTERED)
+		return;
 	call_netdevice_notifiers(NETDEV_XDP_FEAT_CHANGE, dev);
 }
 EXPORT_SYMBOL_GPL(xdp_set_features_flag);
Signature · 1 line
2.39.2

LGTM

#2 lore raw
In reply to Jakub Kicinski
Quoted 26 lines · Jakub Kicinski

Drivers will commonly perform feature setting during init, if they use the xdp_set_features_flag() helper they'll likely run into an ASSERT_RTNL() inside call_netdevice_notifiers_info().

Don't call the notifier until the device is actually registered. Nothing should be tracking the device until its registered.

Fixes 4d5ab0ad964d ("net/mlx5e: take into account device reconfiguration for xdp_features flag")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
  net/core/xdp.c | 3 +++
  1 file changed, 3 insertions(+)
net/core/xdp.c +0 -0
index 87e654b7d06c..5722a1fc6e9e 100644

net/core/xdp.c void xdp_set_features_flag(struct net_device *dev, xdp_features_t val) · line 786

Quoted 6 lines
net/core/xdp.c +3 -0
@@ -781,6 +781,9 @@ void xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
  		return;
 
  	dev->xdp_features = val;
+
+	if (dev->reg_state < NETREG_REGISTERED)
+		return;

I maybe need to dig deeper, but, it looks strange to still call_netdevice_notifiers in cases > NETREG_REGISTERED.

Isn't it problematic to call it with NETREG_UNREGISTERED ?

For comparison, netif_set_real_num_tx_queues has this ASSERT_RTNL() only under dev->reg_state == NETREG_REGISTERED || dev->reg_state == NETREG_UNREGISTERING.

Quoted 3 lines
net/core/xdp.c +0 -0
  	call_netdevice_notifiers(NETDEV_XDP_FEAT_CHANGE, dev);
  }
  EXPORT_SYMBOL_GPL(xdp_set_features_flag);
#3 lore raw
Quoted 38 lines · Jakub Kicinski
Quoted 26 lines

Drivers will commonly perform feature setting during init, if they use the xdp_set_features_flag() helper they'll likely run into an ASSERT_RTNL() inside call_netdevice_notifiers_info().

Don't call the notifier until the device is actually registered. Nothing should be tracking the device until its registered.

Fixes 4d5ab0ad964d ("net/mlx5e: take into account device reconfiguration for xdp_features flag")

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
  net/core/xdp.c | 3 +++
  1 file changed, 3 insertions(+)
net/core/xdp.c +0 -0
index 87e654b7d06c..5722a1fc6e9e 100644

net/core/xdp.c void xdp_set_features_flag(struct net_device *dev, xdp_features_t val) · line 785

Quoted 5 lines
net/core/xdp.c +3 -0
@@ -781,6 +781,9 @@ void xdp_set_features_flag(struct net_device *dev, xdp_features_t val)
  		return;
  	dev->xdp_features = val;
+
+	if (dev->reg_state < NETREG_REGISTERED)
+		return;

I maybe need to dig deeper, but, it looks strange to still call_netdevice_notifiers in cases > NETREG_REGISTERED.

Quoted 5 lines

Isn't it problematic to call it with NETREG_UNREGISTERED ?

For comparison, netif_set_real_num_tx_queues has this ASSERT_RTNL() only under dev->reg_state == NETREG_REGISTERED || dev->reg_state == NETREG_UNREGISTERING.

does it make sense to run call_netdevice_notifiers() in xdp_set_features_flag() just if dev->reg_state is NETREG_REGISTERED?
Moreover, looking at the code it seems netdev code can run with dev->reg_state set to NETREG_UNREGISTERED and without holding RTNL lock, right?

Regards,
Lorenzo

Quoted 4 lines
Quoted 4 lines
net/core/xdp.c +0 -0
  	call_netdevice_notifiers(NETDEV_XDP_FEAT_CHANGE, dev);
  }
  EXPORT_SYMBOL_GPL(xdp_set_features_flag);
author maintainer
#4 lore raw
Quoted 11 lines · On Thu, 16 Mar 2023 12:03:57 +0100 Lorenzo Bianconi wrote:
Quoted 8 lines

I maybe need to dig deeper, but, it looks strange to still call_netdevice_notifiers in cases > NETREG_REGISTERED.

Isn't it problematic to call it with NETREG_UNREGISTERED ?

For comparison, netif_set_real_num_tx_queues has this ASSERT_RTNL() only under dev->reg_state == NETREG_REGISTERED || dev->reg_state == NETREG_UNREGISTERING.

does it make sense to run call_netdevice_notifiers() in xdp_set_features_flag() just if dev->reg_state is NETREG_REGISTERED?

I was thinking - we'll adjust it if someone complains, but indeed the detection is somewhat weak, a call on a dead device but under rtnl_lock won't warn. Let me just copy what the queue helpers do, exactly, then.

Quoted 2 lines

Moreover, looking at the code it seems netdev code can run with dev->reg_state set to NETREG_UNREGISTERED and without holding RTNL lock, right?

You mean - part of unregistration is done without rtnl lock held?

author maintainer
#5 lore raw
Quoted 7 lines · On Thu, 16 Mar 2023 14:54:18 -0700 Jakub Kicinski wrote:
Quoted 2 lines

does it make sense to run call_netdevice_notifiers() in xdp_set_features_flag() just if dev->reg_state is NETREG_REGISTERED?

I was thinking - we'll adjust it if someone complains, but indeed the detection is somewhat weak, a call on a dead device but under rtnl_lock won't warn. Let me just copy what the queue helpers do, exactly, then.

It's just a notifier, I think I'll go with == REGISTERED. Let me send v2.