virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "K. Y. Srinivasan" <kys@microsoft.com>
To: gregkh@suse.de, linux-kernel@vger.kernel.org,
	devel@linuxdriverproject.org, virtualization@lists.osdl.org
Cc: "K. Y. Srinivasan" <kys@microsoft.com>,
	Haiyang Zhang <haiyangz@microsoft.com>
Subject: [PATCH 34/46] Staging: hv: vmbus: Properly deal with de-registering channel callback
Date: Sat, 27 Aug 2011 11:31:33 -0700	[thread overview]
Message-ID: <1314469905-7058-34-git-send-email-kys@microsoft.com> (raw)
In-Reply-To: <1314469905-7058-1-git-send-email-kys@microsoft.com>

Ensure that we correctly handle racing invocations of the channel callback
when the channel is being closed. We do this using the channel's inbound_lock.
A side-effect of this strategy is that we avoid repeatedly picking up this lock
as we drain the inbound ring-buffer.

Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Haiyang Zhang <haiyangz@microsoft.com>
---
 drivers/staging/hv/channel.c     |   20 +++++---------------
 drivers/staging/hv/connection.c  |    3 +++
 drivers/staging/hv/netvsc.c      |    3 ---
 drivers/staging/hv/storvsc_drv.c |    3 ---
 4 files changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/staging/hv/channel.c b/drivers/staging/hv/channel.c
index ac92c1f..b6f3d38 100644
--- a/drivers/staging/hv/channel.c
+++ b/drivers/staging/hv/channel.c
@@ -513,9 +513,12 @@ void vmbus_close(struct vmbus_channel *channel)
 {
 	struct vmbus_channel_close_channel *msg;
 	int ret;
+	unsigned long flags;
 
 	/* Stop callback and cancel the timer asap */
+	spin_lock_irqsave(&channel->inbound_lock, flags);
 	channel->onchannel_callback = NULL;
+	spin_unlock_irqrestore(&channel->inbound_lock, flags);
 
 	/* Send a closing message */
 
@@ -735,19 +738,15 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
 	u32 packetlen;
 	u32 userlen;
 	int ret;
-	unsigned long flags;
 
 	*buffer_actual_len = 0;
 	*requestid = 0;
 
-	spin_lock_irqsave(&channel->inbound_lock, flags);
 
 	ret = hv_ringbuffer_peek(&channel->inbound, &desc,
 			     sizeof(struct vmpacket_descriptor));
-	if (ret != 0) {
-		spin_unlock_irqrestore(&channel->inbound_lock, flags);
+	if (ret != 0)
 		return 0;
-	}
 
 	packetlen = desc.len8 << 3;
 	userlen = packetlen - (desc.offset8 << 3);
@@ -755,7 +754,6 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
 	*buffer_actual_len = userlen;
 
 	if (userlen > bufferlen) {
-		spin_unlock_irqrestore(&channel->inbound_lock, flags);
 
 		pr_err("Buffer too small - got %d needs %d\n",
 			   bufferlen, userlen);
@@ -768,7 +766,6 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer,
 	ret = hv_ringbuffer_read(&channel->inbound, buffer, userlen,
 			     (desc.offset8 << 3));
 
-	spin_unlock_irqrestore(&channel->inbound_lock, flags);
 
 	return 0;
 }
@@ -785,19 +782,15 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
 	u32 packetlen;
 	u32 userlen;
 	int ret;
-	unsigned long flags;
 
 	*buffer_actual_len = 0;
 	*requestid = 0;
 
-	spin_lock_irqsave(&channel->inbound_lock, flags);
 
 	ret = hv_ringbuffer_peek(&channel->inbound, &desc,
 			     sizeof(struct vmpacket_descriptor));
-	if (ret != 0) {
-		spin_unlock_irqrestore(&channel->inbound_lock, flags);
+	if (ret != 0)
 		return 0;
-	}
 
 
 	packetlen = desc.len8 << 3;
@@ -806,8 +799,6 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
 	*buffer_actual_len = packetlen;
 
 	if (packetlen > bufferlen) {
-		spin_unlock_irqrestore(&channel->inbound_lock, flags);
-
 		pr_err("Buffer too small - needed %d bytes but "
 			"got space for only %d bytes\n",
 			packetlen, bufferlen);
@@ -819,7 +810,6 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer,
 	/* Copy over the entire packet to the user buffer */
 	ret = hv_ringbuffer_read(&channel->inbound, buffer, packetlen, 0);
 
-	spin_unlock_irqrestore(&channel->inbound_lock, flags);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(vmbus_recvpacket_raw);
diff --git a/drivers/staging/hv/connection.c b/drivers/staging/hv/connection.c
index 7a3ec75..6aab802 100644
--- a/drivers/staging/hv/connection.c
+++ b/drivers/staging/hv/connection.c
@@ -215,6 +215,7 @@ struct vmbus_channel *relid2channel(u32 relid)
 static void process_chn_event(u32 relid)
 {
 	struct vmbus_channel *channel;
+	unsigned long flags;
 
 	/*
 	 * Find the channel based on this relid and invokes the
@@ -222,11 +223,13 @@ static void process_chn_event(u32 relid)
 	 */
 	channel = relid2channel(relid);
 
+	spin_lock_irqsave(&channel->inbound_lock, flags);
 	if (channel && (channel->onchannel_callback != NULL)) {
 		channel->onchannel_callback(channel->channel_callback_context);
 	} else {
 		pr_err("channel not found for relid - %u\n", relid);
 	}
+	spin_unlock_irqrestore(&channel->inbound_lock, flags);
 }
 
 /*
diff --git a/drivers/staging/hv/netvsc.c b/drivers/staging/hv/netvsc.c
index 9828f0b..e4cc40a 100644
--- a/drivers/staging/hv/netvsc.c
+++ b/drivers/staging/hv/netvsc.c
@@ -62,9 +62,7 @@ static struct netvsc_device *get_outbound_net_device(struct hv_device *device)
 static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
 {
 	struct netvsc_device *net_device;
-	unsigned long flags;
 
-	spin_lock_irqsave(&device->channel->inbound_lock, flags);
 	net_device = device->ext;
 
 	if (!net_device)
@@ -75,7 +73,6 @@ static struct netvsc_device *get_inbound_net_device(struct hv_device *device)
 		net_device = NULL;
 
 get_in_err:
-	spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
 	return net_device;
 }
 
diff --git a/drivers/staging/hv/storvsc_drv.c b/drivers/staging/hv/storvsc_drv.c
index d575bc9..3686d10 100644
--- a/drivers/staging/hv/storvsc_drv.c
+++ b/drivers/staging/hv/storvsc_drv.c
@@ -352,9 +352,7 @@ static inline struct storvsc_device *get_in_stor_device(
 					struct hv_device *device)
 {
 	struct storvsc_device *stor_device;
-	unsigned long flags;
 
-	spin_lock_irqsave(&device->channel->inbound_lock, flags);
 	stor_device = (struct storvsc_device *)device->ext;
 
 	if (!stor_device)
@@ -370,7 +368,6 @@ static inline struct storvsc_device *get_in_stor_device(
 		stor_device = NULL;
 
 get_in_err:
-	spin_unlock_irqrestore(&device->channel->inbound_lock, flags);
 	return stor_device;
 
 }
-- 
1.7.4.1

  parent reply	other threads:[~2011-08-27 18:31 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-27 18:31 [PATCH 0000/0046] Staging: hv: Driver cleanup K. Y. Srinivasan
2011-08-27 18:31 ` [PATCH 01/46] Staging: hv: storvsc: Inline free_stor_device() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 02/46] Staging: hv: storvsc: Do not aquire an unnecessary reference on stor_device K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 03/46] Staging: hv: storvsc: Rename must_get_stor_device() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 04/46] Staging: hv: storvsc: Rename get_stor_device() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 05/46] Staging: hv: storvsc: Cleanup alloc_stor_device() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 06/46] Staging: hv: storvsc: Introduce state to manage the lifecycle of stor device K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 07/46] Staging: hv: storvsc: Prevent outgoing traffic when stor dev is being destroyed K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 08/46] Staging: hv: storvsc: Get rid of release_stor_device() by inlining the code K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 09/46] Staging: hv: storvsc: Get rid of final_release_stor_device() by inlining code K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 10/46] Staging: hv: storvsc: Get rid of the reference counting in struct storvsc_device K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 11/46] Staging: hv: netvsc: Inline the code for free_net_device() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 12/46] Staging: hv: netvsc: Cleanup alloc_net_device() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 13/46] Staging: hv: netvsc: Introduce state to manage the lifecycle of net device K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 14/46] Staging: hv: netvsc: Prevent outgoing traffic when netvsc dev is destroyed K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 15/46] Staging: hv: netvsc: Get rid of release_outbound_net_device() by inlining the code K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 16/46] Staging: hv: netvsc: Get rid of release_inbound_net_device() " K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 17/46] Staging: hv: netvsc: Get rid of the refcnt field in struct netvsc_device K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 18/46] Staging: hv: storvsc: Add code to handle IDE devices using the storvsc driver K. Y. Srinivasan
2011-08-30 11:07     ` Dan Carpenter
2011-08-27 18:31   ` [PATCH 19/46] Staging: hv: storvsc: Handle " K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 20/46] Staging: hv: blkvsc: Get rid of blkvsc_drv.c as this code is not used K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 21/46] Staging: hv: storvsc: Optimize bounce buffer handling for the "write" case K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 22/46] Staging: hv: storvsc: Optimize the bounce buffer handling in the "read" case K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 23/46] Staging: hv: storvsc: Include storvsc.c in storvsc_drv.c K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 24/46] Staging: hv: storvsc: Cleanup storvsc_drv.c after adding the contents of storvsc.c K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 25/46] Staging: hv: storvsc: Add the contents of hyperv_storage.h to storvsc_drv.c K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 26/46] Staging: hv: storvsc: Cleanup storvsc_drv.c after adding the contents of hyperv_storage.h K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 27/46] Staging: hv: storvsc: Fixup srb and scsi status for INQUIRY and MODE_SENSE K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 28/46] Staging: hv: storvsc: Fix a typo K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 29/46] Staging: hv: storvsc: In case of scsi errors offline the device K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 30/46] Staging: hv: storvsc: No need to copy from bounce buffer in case of a failure K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 31/46] Staging: hv: util: Forcefully shutdown when shutdown is requested K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 32/46] Staging: hv: util: Adjust guest time in a process context K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 33/46] Staging: hv: vmbus: Check before invoking the channel callback K. Y. Srinivasan
2011-08-27 18:31   ` K. Y. Srinivasan [this message]
2011-08-27 18:31   ` [PATCH 35/46] Staging: hv: Fix a bug in vmbus_match() K. Y. Srinivasan
2011-08-29 18:00     ` Greg KH
2011-08-27 18:31   ` [PATCH 36/46] Staging: hv: vmbus: Get rid of vmbus_on_isr() by inlining the code K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 37/46] Staging: hv: vmbus: Check for events before messages K. Y. Srinivasan
2011-08-29 18:05     ` Greg KH
2011-08-30 17:06       ` KY Srinivasan
2011-08-30 17:38         ` Greg KH
2011-08-31 14:22           ` KY Srinivasan
2011-08-27 18:31   ` [PATCH 38/46] Staging: hv: vmbus: Do not enable auto eoi K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 39/46] Staging: hv: vmbus: Fixup indentation in vmbus_acpi_add() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 40/46] Staging: hv: vmbus: Get rid of some dated/redundant comments K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 41/46] Staging: hv: vmbus: Fix a bug in error handling in vmbus_bus_init() K. Y. Srinivasan
2011-08-29 18:08     ` Greg KH
2011-08-30 10:29       ` Dan Carpenter
2011-08-30 14:07         ` Greg KH
2011-08-30 17:25           ` KY Srinivasan
2011-08-30 17:07       ` KY Srinivasan
2011-08-27 18:31   ` [PATCH 42/46] Staging: hv: vmbus: Get rid of an unnecessary check in vmbus_connect() K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 43/46] Staging: hv: vmbus: Fix a checkpatch warning in ring_buffer.c K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 44/46] Staging: hv: vmbus: Fix checkpatch warnings in connection.c K. Y. Srinivasan
2011-08-28  6:56     ` Joe Perches
2011-08-30 17:03       ` KY Srinivasan
2011-08-29 18:09     ` Greg KH
2011-08-30 17:11       ` KY Srinivasan
2011-08-30 17:41         ` Greg KH
2011-08-31 14:21           ` KY Srinivasan
2011-08-27 18:31   ` [PATCH 45/46] Staging: hv: mousevsc: Fix checkpatch errors and warnings K. Y. Srinivasan
2011-08-27 18:31   ` [PATCH 46/46] Staging: hv: Update the TODO file K. Y. Srinivasan
2011-08-29 18:12     ` Greg KH
2011-08-30 17:13       ` KY Srinivasan
2011-08-29 18:15 ` [PATCH 0000/0046] Staging: hv: Driver cleanup Greg KH
2011-08-30 17:27   ` KY Srinivasan
2011-08-30 12:48 ` Olaf Hering
2011-08-30 17:22   ` KY Srinivasan
2011-08-30 17:43     ` Greg KH
2011-08-30 18:04       ` Olaf Hering
2011-08-30 18:19         ` Greg KH
2011-08-31  9:11           ` Olaf Hering
2011-09-01 15:43             ` [PATCH RFC] ata_piix: ignore disks in a hyper-v guest Olaf Hering
2011-08-31 14:27         ` [PATCH 0000/0046] Staging: hv: Driver cleanup KY Srinivasan
2011-08-31 14:18       ` KY 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=1314469905-7058-34-git-send-email-kys@microsoft.com \
    --to=kys@microsoft.com \
    --cc=devel@linuxdriverproject.org \
    --cc=gregkh@suse.de \
    --cc=haiyangz@microsoft.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.osdl.org \
    /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).