net: xdp: don't call notifiers during driver init
Subsystems (4)
Jakub Kicinski
maintainerPATCH 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.
---
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
@@ -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
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 anASSERT_RTNL()insidecall_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")Signed-off-by Jakub Kicinski <[email protected]>---
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@@ -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
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 anASSERT_RTNL()insidecall_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")Signed-off-by Jakub Kicinski <[email protected]>---
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
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
-0call_netdevice_notifiers (NETDEV_XDP_FEAT_CHANGE , dev); }EXPORT_SYMBOL_GPL (xdp_set_features_flag);
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 anASSERT_RTNL()insidecall_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")Signed-off-by Jakub Kicinski <[email protected]>---
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
-0net/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_notifiersin cases >NETREG_REGISTERED.
Quoted 5 lines
Isn't it problematic to call it with
NETREG_UNREGISTERED?For comparison,
netif_set_real_num_tx_queueshas thisASSERT_RTNL()only underdev->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
-0call_netdevice_notifiers (NETDEV_XDP_FEAT_CHANGE , dev); }EXPORT_SYMBOL_GPL (xdp_set_features_flag);
Jakub Kicinski
maintainerQuoted 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_notifiersin cases >NETREG_REGISTERED.Isn't it problematic to call it with
NETREG_UNREGISTERED?For comparison,
netif_set_real_num_tx_queueshas thisASSERT_RTNL()only underdev->reg_state==NETREG_REGISTERED||dev->reg_state==NETREG_UNREGISTERING.does it make sense to run
call_netdevice_notifiers()inxdp_set_features_flag()just ifdev->reg_stateisNETREG_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_stateset toNETREG_UNREGISTEREDand without holding RTNL lock, right?
You mean - part of unregistration is done without rtnl lock held?
Jakub Kicinski
maintainerQuoted 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()inxdp_set_features_flag()just ifdev->reg_stateisNETREG_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_lockwon'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.