Skip to contentSkip to conversation

wext: allow wext users without rtnl

PATCH In review Johannes Berg 3 participants 8 messages Apr 18, 2007 – Apr 20, 2007 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore

Johannes Berg

author maintainer
#0 lore raw

PATCH 1/1 wext: allow wext users without rtnl

This patch modifies wext adding a flag that allows drivers to specify that they do not wish their wext calls made under rtnl. The default is to still acquire the rtnl.

Warning: a device reference is held for the new no_locking API, therefore it is not safe to call unregister_netdev on the passed device!

---
 include/net/iw_handler.h   |    3 +
 net/wireless/wext-common.c |    6 --
 net/wireless/wext-old.c    |  127 ++++++++++++++++++++++++---------------------
 3 files changed, 72 insertions(+), 64 deletions(-)
include/net/iw_handler.h +3 -0
@@ -349,6 +349,9 @@ struct iw_handler_def
 	 * The old pointer in struct net_device will be gradually phased
 	 * out, and drivers are encouraged to use this one... */
 	struct iw_statistics*	(*get_wireless_stats)(struct net_device *dev);
+
+	/* can live without rtnl locking? */
+	int no_locking;
 };
 
 /* ---------------------- IOCTL DESCRIPTION ---------------------- */
net/wireless/wext-common.c +0 -6
@@ -631,15 +631,9 @@ int wext_ioctl(unsigned int cmd, struct 
 #ifdef CONFIG_WIRELESS_EXT
 	dev_load(ifr->ifr_name);
 
-	/* we could change the code to not hold the rtnl but
-	 * some callees might require it held */
-	rtnl_lock();
-
 	/* Follow me in wext-old.c */
 	ret = wireless_process_ioctl(ifr, cmd);
 
-	rtnl_unlock();
-
 	/* haha, I cheat here by allowing a driver or stack to have both WE and
 	 * CFG80211-WE for a little while during conversion... wext returns
 	 * -EOPNOTSUPP if a handler is not assigned, so we can in that case try
net/wireless/wext-old.c +69 -58

143 lines not on this page · raw message

#1 lore raw
Quoted 10 lines · On Tue, 17 Apr 2007 17:50:10 +0200 Johannes Berg <[email protected]>…

This patch modifies wext adding a flag that allows drivers to specify that they do not wish their wext calls made under rtnl. The default is to still acquire the rtnl.

Warning: a device reference is held for the new no_locking API, therefore it is not safe to call unregister_netdev on the passed device!

NACK Conditional locking is bad design.
Either lock or not, make up your mind and fix the devices.

Signature · 1 line
Stephen Hemminger <[email protected]>
#2 lore raw

From: Stephen Hemminger <[email protected]>
Date: Wed, 18 Apr 2007 14:04:51 -0700

Quoted 10 lines
Quoted 7 lines · On Tue, 17 Apr 2007 17:50:10 +0200 Johannes Berg <[email protected]>…

This patch modifies wext adding a flag that allows drivers to specify that they do not wish their wext calls made under rtnl. The default is to still acquire the rtnl.

Warning: a device reference is held for the new no_locking API, therefore it is not safe to call unregister_netdev on the passed device!

Quoted 6 lines
Quoted 3 lines

NACK Conditional locking is bad design.
Either lock or not, make up your mind and fix the devices.

It is also wrong because all entities in the kernel assume that network configuration changes all occur under the RTNL therefore it must be held consistently everywhere.

I don't know what kind of deadlock or other issues are being worked around here, but you'll have to find another way.

author maintainer
#3 lore raw
Quoted 2 lines · David Miller
Quoted 2 lines

NACK Conditional locking is bad design.
Either lock or not, make up your mind and fix the devices.

That was because I don't think we can go fixing all current wext users which might even be out of tree.

Quoted 3 lines

It is also wrong because all entities in the kernel assume that network configuration changes all occur under the RTNL therefore it must be held consistently everywhere.

So you're saying that cfg80211 should hold rtnl too? I don't see any point in holding rtnl (for example) for setting the SSID of a wireless device.

johannes

author maintainer
#4 lore raw
In reply to Stephen Hemminger
Quoted 2 lines · Stephen Hemminger

NACK Conditional locking is bad design.
Either lock or not, make up your mind and fix the devices.

Ok looking at this again.

We essentially have the problem that all wext users assume that the rtnl is held during wext calls, which is mostly required right now because they are being passed a netdev pointer and no reference is taken. Also, there shouldn't be multiple wext calls in progress at the same time.

In cfg80211, I decided that holding the rtnl would be mostly pointless since configuration of a wireless device can't race against the other config ioctls that could be done. I'd have to look at the details to see if changing the interface mac address and setting a BSSID on it could clash.

Hence, since cfg80211 doesn't hold rtnl, to avoid ABBA style deadlocks wext entry points to the code need to be changed to not hold rtnl either. Or cfg80211 needs to be changed to hold rtnl.

I'm not entirely opposed to making cfg80211 hold rtnl for configuration, it just seems pointless to block configuration of different devices against each other when even a for a single item it shouldn't matter. Then again, holding rtnl in cfg80211 would simplify some things because we could pass in a netdev pointer instead of the ifindex for example.

If you think I can justify holding rtnl in cfg80211 I'm certainly willing to change that. Global locks are just too suspicious to me ;)

johannes

#5 lore raw

From: Johannes Berg <[email protected]>
Date: Fri, 20 Apr 2007 21:48:41 +0200

Quoted 8 lines

I'm not entirely opposed to making cfg80211 hold rtnl for configuration, it just seems pointless to block configuration of different devices against each other when even a for a single item it shouldn't matter. Then again, holding rtnl in cfg80211 would simplify some things because we could pass in a netdev pointer instead of the ifindex for example.

If you think I can justify holding rtnl in cfg80211 I'm certainly willing to change that. Global locks are just too suspicious to me ;)

It is true that things like IPSEC configuration via xfrm_user.c uses it's own mutex, so there is precedence for splitting up the locking where things are truly seperate.

But changing things like MAC addresse changes, which you mention, do fall into the existing scope of the RTNL semaphore.

If it simplifies things, all the reason more to use it for cfg80211.

author maintainer
#6 lore raw
Quoted 9 lines · David Miller
Quoted 5 lines

Then again, holding rtnl in cfg80211 would simplify some things because we could pass in a netdev pointer instead of the ifindex for example.

If you think I can justify holding rtnl in cfg80211 I'm certainly willing to change that. Global locks are just too suspicious to me ;)

It is true that things like IPSEC configuration via xfrm_user.c uses it's own mutex, so there is precedence for splitting up the locking where things are truly seperate.

:)

Quoted 2 lines

But changing things like MAC addresse changes, which you mention, do fall into the existing scope of the RTNL semaphore.

Actually, just thought about mac address change again, it is only permitted when devices are down anyway and at that point nothing can race since wireless devices that are down just store configuration for when they're up (or ignore it)

Quoted 1 line

If it simplifies things, all the reason more to use it for cfg80211.

A few places could use a netdev pointer instead of ifindex but I don't feel it's much of a simplification for callees. This is only an issue for two or three calls that cannot hold a netdev reference because the device will be removed by the driver/stack.

Since the discussion came up due to dropping the rtnl from wext I think that it may be beneficial if we added rtnl locking to cfg80211 now to simplify migration away from wext which holds rtnl and then revisit the locking when we can drop wext completely from the mac80211 code. That would allow us to revisit rtnl locking for wext when we have completely migrated to cfg80211 and wext is only handled through cfg80211.

Does that sound like an acceptable way forward?

johannes

#7 lore raw

From: Johannes Berg <[email protected]>
Date: Fri, 20 Apr 2007 22:53:42 +0200

Quoted 8 lines

Since the discussion came up due to dropping the rtnl from wext I think that it may be beneficial if we added rtnl locking to cfg80211 now to simplify migration away from wext which holds rtnl and then revisit the locking when we can drop wext completely from the mac80211 code. That would allow us to revisit rtnl locking for wext when we have completely migrated to cfg80211 and wext is only handled through cfg80211.

Does that sound like an acceptable way forward?

Sure.