linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael Kelley (EOSG)" <Michael.H.Kelley@microsoft.com>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: KY Srinivasan <kys@microsoft.com>,
	"gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"devel@linuxdriverproject.org" <devel@linuxdriverproject.org>,
	"olaf@aepfle.de" <olaf@aepfle.de>,
	"apw@canonical.com" <apw@canonical.com>,
	"jasowang@redhat.com" <jasowang@redhat.com>,
	Stephen Hemminger <sthemmin@microsoft.com>,
	vkuznets <vkuznets@redhat.com>
Subject: RE: [PATCH 2/5] vmbus: add driver_override support
Date: Tue, 14 Aug 2018 19:13:13 +0000	[thread overview]
Message-ID: <CY4PR21MB0773F0CF5B7E3B4ED0F2BBF3DC380@CY4PR21MB0773.namprd21.prod.outlook.com> (raw)
In-Reply-To: <20180814093514.7febc8d5@xeon-e3>

From: Stephen Hemminger <stephen@networkplumber.org>  Sent: Tuesday, August 14, 2018 9:35 AM

> On Mon, 13 Aug 2018 19:30:50 +0000
> "Michael Kelley (EOSG)" <Michael.H.Kelley@microsoft.com> wrote:
> 
> > > +/*
> > > + * Return a matching hv_vmbus_device_id pointer.
> > > + * If there is no match, return NULL.
> > > + */
> > > +static const struct hv_vmbus_device_id *hv_vmbus_get_id(struct hv_driver *drv,
> > > +							struct hv_device *dev)
> > > +{
> > > +	const uuid_le *guid = &dev->dev_type;
> > > +	const struct hv_vmbus_device_id *id;
> > >
> > > -	return NULL;
> > > +	/* When driver_override is set, only bind to the matching driver */
> > > +	if (dev->driver_override && strcmp(dev->driver_override, drv->name))
> > > +		return NULL;
> >
> > This function needs to be covered by the device lock, so that
> > dev->driver_override can't be set to NULL and the memory freed
> > during the above 'if' statement.  When called from vmbus_probe(),
> > the device lock is held, so it's good. But when called from
> > vmbus_match(), the device lock may not be held: consider the path
> > __driver_attach() -> driver_match_device() -> vmbus_match().
> 
> The function hv_vmbus_get_id is called from that path.
> i.e. __device_attach -> driver-match_device -> vmbus_match.
> and __device_attach always does:
> 	device_lock(dev);

Agreed.  The __device_attach() path holds the device lock and all is good.
But the __driver_attach() path does not hold the device lock when the
match function is called, leaving the code open to a potential race.  Same
problem could happen in the pci subsystem, so the issue is more generic
and probably should be evaluated and dealt with separately.

Michael

> 
> The code in driver _override_store uses the same device_lock
> when storing the new value.
> 
> This is same locking as is done in pci-sysfs.c


  reply	other threads:[~2018-08-14 19:13 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-10 23:05 [PATCH 0/5] Miscellaneous fixes/enhancements kys
2018-08-10 23:06 ` [PATCH 1/5] Tools: hv: Fix a bug in the key delete code kys
2018-08-10 23:06   ` [PATCH 2/5] vmbus: add driver_override support kys
2018-08-13 19:30     ` Michael Kelley (EOSG)
2018-08-13 19:40       ` gregkh
2018-08-13 19:56       ` Stephen Hemminger
2018-08-14 16:35       ` Stephen Hemminger
2018-08-14 19:13         ` Michael Kelley (EOSG) [this message]
2018-08-10 23:06   ` [PATCH 3/5] uio_hv_generic: increase size of receive and send buffers kys
2018-08-10 23:06   ` [PATCH 4/5] uio_hv_generic: drop #ifdef DEBUG kys
2018-08-10 23:06   ` [PATCH 5/5] Drivers: hv: vmbus: Fix synic per-cpu context initialization kys
2018-08-13 16:41   ` [PATCH 1/5] Tools: hv: Fix a bug in the key delete code Michael Kelley (EOSG)

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=CY4PR21MB0773F0CF5B7E3B4ED0F2BBF3DC380@CY4PR21MB0773.namprd21.prod.outlook.com \
    --to=michael.h.kelley@microsoft.com \
    --cc=apw@canonical.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jasowang@redhat.com \
    --cc=kys@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=olaf@aepfle.de \
    --cc=stephen@networkplumber.org \
    --cc=sthemmin@microsoft.com \
    --cc=vkuznets@redhat.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).