linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Cody Schuffelen <schuffelen@google.com>
Cc: Kalle Valo <kvalo@codeaurora.org>,
	"David S . Miller" <davem@davemloft.net>,
	linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org,
	netdev@vger.kernel.org, kernel-team@android.com
Subject: Re: [PATCH net-next v3] wireless-drivers: rtnetlink wifi simulation device
Date: Tue, 09 Oct 2018 10:25:40 +0200	[thread overview]
Message-ID: <1539073540.3687.99.camel@sipsolutions.net> (raw)
In-Reply-To: <20181004195906.201895-1-schuffelen@google.com> (sfid-20181004_220026_241767_96C715D6)

On Thu, 2018-10-04 at 12:59 -0700, Cody Schuffelen wrote:
> 
> I wasn't completely clear on whether I should change the title (net-next
> to mac80211-next) so I left it as is for v3 to try to keep the patchwork
> series together.

You can/should change it - patchwork doesn't really track this at all
anyway.

> The driver is also now a bool instead of a tristate to use __ro_after_init.

Hmm? Why would that be required? __ro_after_init works fine in modules?

> +static struct ieee80211_rate bitrates_2ghz[] = {
> +	{ .bitrate = 10 },
> +	{ .bitrate = 20 },
> +	{ .bitrate = 55 },
> +	{ .bitrate = 60 },
> +	{ .bitrate = 110 },
> +	{ .bitrate = 120 },
> +	{ .bitrate = 240 },
> +};

Come to think of it, the typical order here would be 1,2,5.5,11,6,12,24
(6<->11), due to the ordering in the probe request frame I guess.

I'm not sure it matters though.

> +static struct ieee80211_supported_band band_2ghz = {

These can be const, I think?

> +/** Assigned at module init. Guaranteed locally-administered and unicast. */

I think you should avoid ** - it's the kernel-doc marker.

> +static u8 fake_router_bssid[ETH_ALEN] __ro_after_init = {};

If this is the reason for not allowing it to be a module then you don't
need  to disallow the module case.

> +static int virt_wifi_scan(struct wiphy *wiphy,
> +			  struct cfg80211_scan_request *request)
> +{
> +	struct virt_wifi_priv *priv = wiphy_priv(wiphy);
> +
> +	wiphy_debug(wiphy, "scan\n");
> +
> +	if (priv->scan_request || priv->being_deleted)
> +		return -EBUSY;
> +
> +	priv->scan_request = request;
> +	schedule_delayed_work(&priv->scan_result, HZ * 2);
> +
> +	return 0;
> +}
> +
> +static void virt_wifi_scan_result(struct work_struct *work)
> +{
> +	const union {
> +		struct {
> +			u8 tag;
> +			u8 len;
> +			u8 ssid[8];
> +		} __packed parts;
> +		u8 data[10];
> +	} ssid = { .parts = {
> +		.tag = WLAN_EID_SSID, .len = 8, .ssid = "VirtWifi" }
> +	};

Not sure I see much value in the union, but I don't think it matters
much.
(You could just cast below - (void *)&ssid, sizeof(ssid))

> +	rtnl_lock();
> +	if (priv->scan_request) {
> +		cfg80211_scan_done(priv->scan_request, &scan_info);
> +		priv->scan_request = NULL;
> +	}
> +	rtnl_unlock();

Do you need the rtnl for the priv->scan_request locking?

> +static int virt_wifi_get_station(struct wiphy *wiphy,
> +				 struct net_device *dev,
> +				 const u8 *mac,
> +				 struct station_info *sinfo)
> +{
> [...]
> +	sinfo->tx_packets = 1;
> +	sinfo->tx_failed = 0;
> +	sinfo->signal = -60;

I think Sergey pointed out the -60 elsewhere - need to check here too,
and maybe set in some place that you actually report dBm/mBm.

Also, I think you should only report something here if actually
connected - Sergey pointed this out on the dump station but it applies
here too.

> +static void free_netdev_and_wiphy(struct net_device *dev)
> +{
> +	struct virt_wifi_netdev_priv *priv = netdev_priv(dev);
> +	struct virt_wifi_priv *w_priv;
> +
> +	flush_work(&priv->register_wiphy_work);
> +	if (dev->ieee80211_ptr && !IS_ERR(dev->ieee80211_ptr)) {
> +		w_priv = wiphy_priv(dev->ieee80211_ptr->wiphy);
> +		w_priv->being_deleted = true;
> +		flush_delayed_work(&w_priv->scan_result);
> +		flush_delayed_work(&w_priv->connect);
> +		flush_delayed_work(&w_priv->disconnect);

this is called from

> +static void virt_wifi_setup(struct net_device *dev)
> +{
> +	ether_setup(dev);
> +	dev->netdev_ops = &virt_wifi_ops;
> +	dev->priv_destructor = free_netdev_and_wiphy;
> +}

the destructor, but I believe the destructor is invoked with the RTNL
held. As such, this will deadlock (and lockdep should complain - at
least in current kernel versions) when it's actually running when you
flush it, since you flush something that's (potentially) waiting to
acquire the RTNL, but you are holding the RTNL here and so neither side
can make progress.

> +	/* The newlink callback is invoked while holding the rtnl lock, but
> +	 * register_wiphy wants to claim the rtnl lock itself.
> +	 */
> +	schedule_work(&priv->register_wiphy_work);

Maybe we should fix/change that?

johannes

  parent reply	other threads:[~2018-10-09  8:25 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-04 19:59 [PATCH net-next v3] wireless-drivers: rtnetlink wifi simulation device Cody Schuffelen
2018-10-05 14:33 ` Sergey Matyukevich
2018-10-05 21:05   ` Joel Fernandes
2018-10-05 21:08     ` Joel Fernandes
     [not found]       ` <CAAELVAGAZ-UM77P=JqzHjUGja9oJcN5y9+YvxZWKBmOXAu=zNQ@mail.gmail.com>
2018-10-06 12:01         ` Kalle Valo
2018-11-21  3:20           ` Cody Schuffelen
2018-10-08 13:56     ` Sergey Matyukevich
2018-11-21  3:20   ` Cody Schuffelen
2018-10-06 11:52 ` Kalle Valo
2018-11-21  3:20   ` Cody Schuffelen
2018-10-09  8:25 ` Johannes Berg [this message]
2018-11-21  3:20   ` Cody Schuffelen

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=1539073540.3687.99.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=davem@davemloft.net \
    --cc=kernel-team@android.com \
    --cc=kvalo@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=schuffelen@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).