[RHEL7,COMMIT] mac80211_hwsim: Make hwsim_netgroup IDA

Submitted by Konstantin Khorenko on May 27, 2020, 6:35 p.m.

Details

Message ID 202005271835.04RIZ0wl015191@finist-ce7.sw.ru
State New
Series "Parallel per-net init/exit"
Headers show

Commit Message

Konstantin Khorenko May 27, 2020, 6:35 p.m.
The commit is pushed to "branch-rh7-3.10.0-1127.8.2.vz7.161.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.8.2.vz7.161.3
------>
commit 3e4eadef02a756ad4d60c6006b504392dda83785
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Wed May 27 21:34:59 2020 +0300

    mac80211_hwsim: Make hwsim_netgroup IDA
    
    ms commit 03695549aa76
    
    hwsim_netgroup counter is declarated as int, and it is incremented
    every time a new net is created. After sizeof(int) net are created,
    it will overflow, and different net namespaces will have the same
    identifier. This patch fixes the problem by introducing IDA instead
    of int counter. IDA guarantees, all the net namespaces have the uniq
    identifier.
    
    Note, that after we do ida_simple_remove() in hwsim_exit_net(),
    and we destroy the ID, later there may be executed destroy_radio()
    from the workqueue. But destroy_radio() does not use the ID, so it's OK.
    
    Out of bounds of this patch, just as a report to wireless subsystem
    maintainer, destroy_radio() increaments hwsim_radios_generation
    without hwsim_radio_lock, so this may need one more patch to fix.
    
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    
    Signed-off-by: Johannes Berg <johannes.berg@intel.com>
    
    =====================
    Patchset description:
    
    Parallel per-net init/exit
    
    https://jira.sw.ru/browse/PSBM-104158
---
 drivers/net/wireless/mac80211_hwsim.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 877261887d708..b7024f6fb4e5b 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -33,6 +33,7 @@ 
 #include <net/net_namespace.h>
 #include <net/netns/generic.h>
 #include <linux/nospec.h>
+#include <linux/idr.h>
 #include "mac80211_hwsim.h"
 
 #define WARN_QUEUE 100
@@ -253,7 +254,7 @@  static inline void hwsim_clear_chanctx_magic(struct ieee80211_chanctx_conf *c)
 
 static unsigned int hwsim_net_id;
 
-static int hwsim_netgroup;
+static DEFINE_IDA(hwsim_netgroup_ida);
 
 struct hwsim_net {
 	int netgroup;
@@ -267,11 +268,13 @@  static inline int hwsim_net_get_netgroup(struct net *net)
 	return hwsim_net->netgroup;
 }
 
-static inline void hwsim_net_set_netgroup(struct net *net)
+static inline int hwsim_net_set_netgroup(struct net *net)
 {
 	struct hwsim_net *hwsim_net = net_generic(net, hwsim_net_id);
 
-	hwsim_net->netgroup = hwsim_netgroup++;
+	hwsim_net->netgroup = ida_simple_get(&hwsim_netgroup_ida,
+					     0, 0, GFP_KERNEL);
+	return hwsim_net->netgroup >= 0 ? 0 : -ENOMEM;
 }
 
 static inline u32 hwsim_net_get_wmediumd(struct net *net)
@@ -3402,9 +3405,7 @@  static int __init hwsim_init_netlink(void)
 
 static __net_init int hwsim_init_net(struct net *net)
 {
-	hwsim_net_set_netgroup(net);
-
-	return 0;
+	return hwsim_net_set_netgroup(net);
 }
 
 static void __net_exit hwsim_exit_net(struct net *net)
@@ -3425,6 +3426,8 @@  static void __net_exit hwsim_exit_net(struct net *net)
 		schedule_work(&data->destroy_work);
 	}
 	spin_unlock_bh(&hwsim_radio_lock);
+
+	ida_simple_remove(&hwsim_netgroup_ida, hwsim_net_get_netgroup(net));
 }
 
 static struct pernet_operations hwsim_net_ops = {