public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Johannes Berg <johannes-cdvu00un1VgdHxzADdlk8Q@public•gmane.org>
To: Martin Willi <martin-jzJueiEJWxp8fCCB1iTX4w@public•gmane.org>
Cc: linux-wireless-u79uwXL29TY76Z2rM5mHXA@public•gmane.org,
	netdev-u79uwXL29TY76Z2rM5mHXA@public•gmane.org
Subject: Re: [PATCH 2/2] mac80211_hwsim: Allow managing radios from non-initial namespaces
Date: Tue, 03 May 2016 21:16:32 +0200	[thread overview]
Message-ID: <1462302992.10444.11.camel@sipsolutions.net> (raw)
In-Reply-To: <1462258398-6749-3-git-send-email-martin-jzJueiEJWxp8fCCB1iTX4w@public.gmane.org>

On Tue, 2016-05-03 at 08:53 +0200, Martin Willi wrote:
> 
> +static __net_init int hwsim_init_net(struct net *net)
> +{
> +	struct mac80211_hwsim_data *data;
> +	bool exists = true;
> +	int netgroup = 0;
> +
> +	spin_lock_bh(&hwsim_radio_lock);
> +	while (exists) {
> +		exists = false;
> +		list_for_each_entry(data, &hwsim_radios, list) {
> +			if (netgroup == data->netgroup) {
> +				exists = true;
> +				netgroup++;
> +				break;
> +			}
> +		}
> +	}
> +	spin_unlock_bh(&hwsim_radio_lock);
> +
> +	*(int *)net_generic(net, hwsim_net_id) = netgroup;


This seems somewhat awkward. Why not just take the maximum of all the
netgroup IDs + 1? We'd run out of memory and radio IDs long before
netgroup IDs even that way, and they're not actually visible anywhere
so it doesn't matter.

Actually though, *both* your approach and my suggestion don't seem
safe: consider a new netns that doesn't have any hwsim radios yet. Now
you create *another* one, but it would get the same netgroup.

IOW, you should simply use a global counter. Surprising (net)
namespaces don't have an index like that already, but I don't see one.

> +static void __net_exit hwsim_exit_net(struct net *net)
> +{
> +	struct mac80211_hwsim_data *entry, *tmp;
> +
> +	spin_lock_bh(&hwsim_radio_lock);
> +	list_for_each_entry_safe(entry, tmp, &hwsim_radios, list) {
> +		if (net_eq(wiphy_net(entry->hw->wiphy), net)) {
> +			list_del(&entry->list);
> +			INIT_WORK(&entry->destroy_work,
> destroy_radio);
> +			schedule_work(&entry->destroy_work);
> +		}
> +	}
> +	spin_unlock_bh(&hwsim_radio_lock);
> +}

This changes today's default behaviour of moving the wiphys to the
default namespace. Did you intend to destroy them based on the
netgroup, i.e. based on the namespace that created them? Actually,
maybe they should move back to the namespace that created them, if the
namespace they are in is destroyed? But that's difficult, I don't mind
this behaviour, but I'm not sure it's what we want by default for
radios created in the init_net.

johannes
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public•gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2016-05-03 19:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-03  6:53 [PATCH 0/2] wireless: Allow wiphy/hwsim management from user namespaces Martin Willi
2016-05-03  6:53 ` [PATCH 1/2] nl80211: Allow privileged operations " Martin Willi
2016-05-03  6:53 ` [PATCH 2/2] mac80211_hwsim: Allow managing radios from non-initial namespaces Martin Willi
2016-05-03  6:56   ` Johannes Berg
     [not found]   ` <1462258398-6749-3-git-send-email-martin-jzJueiEJWxp8fCCB1iTX4w@public.gmane.org>
2016-05-03 19:16     ` Johannes Berg [this message]
     [not found]       ` <1462302992.10444.11.camel-cdvu00un1VgdHxzADdlk8Q@public.gmane.org>
2016-05-04  8:33         ` Martin Willi
2016-05-09  7:30           ` Johannes Berg
     [not found]             ` <1462779045.30690.2.camel-cdvu00un1VgdHxzADdlk8Q@public.gmane.org>
2016-05-09 16:33               ` Martin Willi
2016-05-05 10:16   ` David Laight
     [not found]     ` <063D6719AE5E284EB5DD2968C1650D6D5F4B5302-VkEWCZq2GCInGFn1LkZF6NBPR1lH4CV8@public.gmane.org>
2016-05-09  7:31       ` Johannes Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462302992.10444.11.camel@sipsolutions.net \
    --to=johannes-cdvu00un1vgdhxzaddlk8q@public$(echo .)gmane.org \
    --cc=linux-wireless-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
    --cc=martin-jzJueiEJWxp8fCCB1iTX4w@public$(echo .)gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public$(echo .)gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox