All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dexuan Cui <decui@microsoft.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: "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>,
	KY Srinivasan <kys@microsoft.com>
Subject: RE: [PATCH V2 10/12] Drivers: hv: vmbus: channge vmbus_connection.channel_lock to mutex
Date: Thu, 12 Nov 2015 13:10:51 +0000	[thread overview]
Message-ID: <c186f6b8dd6047d19e5471e97cf6b805@HKXPR30MB0039.064d.mgd.msft.net> (raw)
In-Reply-To: <87vb97ijot.fsf@vitty.brq.redhat.com>

> From: Vitaly Kuznetsov [mailto:vkuznets@redhat.com]
> Sent: Thursday, November 12, 2015 18:41
> To: Dexuan Cui <decui@microsoft.com>
> Cc: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; olaf@aepfle.de; apw@canonical.com;
> jasowang@redhat.com; KY Srinivasan <kys@microsoft.com>
> Subject: Re: [PATCH V2 10/12] Drivers: hv: vmbus: channge
> vmbus_connection.channel_lock to mutex
>
> "K. Y. Srinivasan" <kys@microsoft.com> writes:
>
> > From: Dexuan Cui <decui@microsoft.com>
> >
> > spinlock is unnecessary here.
> > mutex is enough.
>
> Hm, mutex is usually required when we need to sleep and a spinlock is
> enough otherwise :-)

Sorry, I should have written a better changelog. :-)

 > Or are you trying to say we don't need to disable interrupts here? In

Yes.
Here we try to protect vmbus_connection.chn_list and the related
channel pointer (see relid2channel()) from being updated in parallel.

The parallel paths, e.g., vmbus_process_offer() and
vmbus_onoffer_rescind(), are in process context and no irq context is
involved, so we don't need disable interrupts at all.

> that can maybe we can just switch to spin_lock()/spin_unlock()?

Switching to mutex actually makes preparation for a later patch (which
will be posted to LKML once this pachset is accepted):

Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister()
https://github.com/dcui/linux/commit/185afe8394a9bdae2be11ee1ea2a38d05e373025
(on branch decui/vmsock_1020)

For a vmsock socket connection, the host and the guest can be closing
the connection at the same time.

When the host tries to close the connection, a rescind offer is received
in the VM.

When the guest tries to close the connection, a new vmbus API
vmbus_hvsock_device_unregister(channel) is invoked, so
vmbus_hvsock_device_unregister() -> vmbus_device_unregister() is
invoked and this can be running in parallel with
vmbus_onoffer_rescind() -> vmbus_device_unregister().

The issue of "vmbus_onoffer_rescind () -> relid2channel()" is:
it returns a channel pointer without the spinlock held, so actually
there is no real protection for the channel pointer.

So IMO we need to serialize vmbus_onoffer_rescind() and
vmbus_hvsock_device_unregister().
Here I use mutex (rather than spinlock) because the critical section
can sleep, due to vmbus_device_unregister().

Thanks,
-- Dexuan

  reply	other threads:[~2015-11-12 13:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-12  2:25 [PATCH V2 00/12] Drivers: hv: vmbus: Miscellaneous fixes and cleanup K. Y. Srinivasan
2015-11-12  2:26 ` [PATCH V2 01/12] Drivers: hv: vss: run only on supported host versions K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 02/12] Drivers: hv: vmbus: Use uuid_le type consistently K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 03/12] Drivers: hv: vmbus: Use uuid_le_cmp() for comparing GUIDs K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 04/12] Drivers: hv: vmbus: Get rid of the unused macro K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 05/12] Drivers: hv: vmbus: Get rid of the unused irq variable K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 06/12] Drivers: hv: vmbus: serialize process_chn_event() and vmbus_close_internal() K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 07/12] Drivers: hv: vmbus: do sanity check of channel state in vmbus_close_internal() K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 08/12] Drivers: hv: vmbus: fix rescind-offer handling for device without a driver K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 09/12] Drivers: hv: vmbus: release relid on error in vmbus_process_offer() K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH V2 10/12] Drivers: hv: vmbus: channge vmbus_connection.channel_lock to mutex K. Y. Srinivasan
2015-11-12 10:41     ` Vitaly Kuznetsov
2015-11-12 13:10       ` Dexuan Cui [this message]
2015-11-12  2:26   ` [PATCH V2 11/12] drivers:hv: Allow for MMIO claims that span ACPI _CRS records K. Y. Srinivasan
2015-11-12  2:26   ` [PATCH 12/12] tools/hv: Use include/uapi with __EXPORTED_HEADERS__ K. Y. Srinivasan

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=c186f6b8dd6047d19e5471e97cf6b805@HKXPR30MB0039.064d.mgd.msft.net \
    --to=decui@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=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.