Skip to contentSkip to conversation

vmbus: hvsock: add proper sync for vmbus_hvsock_device_unregister()

PATCH Superseded [email protected] 3 participants 3 messages Oct 11, 2017 Hyper-V/Azure core and drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmbus: hvsock: add proper sync for vmbus_hvsock_device_unregister()

From: Dexuan Cui <[email protected]>

Without the patch, vmbus_hvsock_device_unregister() can destroy the device prematurely when close() is called, and can cause NULl dereferencing or potential data loss (the last portion of the data stream may be dropped prematurely).

Please consider this for 4.14.

Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
---
 drivers/hv/channel_mgmt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/hv/channel_mgmt.c +4 -1
index 018d2e0f8ec5..379b0df123be 100644
@@ -937,7 +937,10 @@ void vmbus_hvsock_device_unregister(struct vmbus_channel *channel)
 {
 	BUG_ON(!is_hvsock_channel(channel));
 
-	channel->rescind = true;
+	/* We always get a rescind msg when a connection is closed. */
+	while (!READ_ONCE(channel->probe_done) || !READ_ONCE(channel->rescind))
+		msleep(1);
+
 	vmbus_device_unregister(channel->device_obj);
 }
 EXPORT_SYMBOL_GPL(vmbus_hvsock_device_unregister);
Signature · 1 line
2.14.1
#1 lore raw
Quoted 8 lines · On Tue, Oct 10, 2017 at 10:38:51PM -0700, [email protected] wrote:

From: Dexuan Cui <[email protected]>

Without the patch, vmbus_hvsock_device_unregister() can destroy the device prematurely when close() is called, and can cause NULl dereferencing or potential data loss (the last portion of the data stream may be dropped prematurely).

Please consider this for 4.14.

Put these meta comments under the --- cut off line. They don't add any value to the final upstream git log.

Quoted 8 lines
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
---
 drivers/hv/channel_mgmt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

regards,
dan carpenter

#2 lore raw

Thanks Dan. Will do.

K. Y

Quoted 40 lines

-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Wednesday, October 11, 2017 2:42 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Stephen Hemminger <[email protected]>; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 1/1] vmbus: hvsock: add proper sync for vmbus_hvsock_device_unregister()

Quoted 3 lines · On Tue, Oct 10, 2017 at 10:38:51PM -0700, [email protected] wrote:

From: Dexuan Cui <[email protected]>

Without the patch, vmbus_hvsock_device_unregister() can destroy the

device

Quoted 5 lines

prematurely when close() is called, and can cause NULl dereferencing or potential data loss (the last portion of the data stream may be dropped prematurely).

Please consider this for 4.14.

Put these meta comments under the --- cut off line. They don't add any value to the final upstream git log.

Quoted 8 lines
Cc Haiyang Zhang <[email protected]>
Cc Stephen Hemminger <[email protected]>
---
 drivers/hv/channel_mgmt.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

regards,
dan carpenter