Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34c6801e authored by Dexuan Cui's avatar Dexuan Cui Committed by Greg Kroah-Hartman
Browse files

Drivers: hv: vmbus: fix rescind-offer handling for device without a driver



In the path vmbus_onoffer_rescind() -> vmbus_device_unregister()  ->
device_unregister() -> ... -> __device_release_driver(), we can see for a
device without a driver loaded: dev->driver is NULL, so
dev->bus->remove(dev), namely vmbus_remove(), isn't invoked.

As a result, vmbus_remove() -> hv_process_channel_removal() isn't invoked
and some cleanups(like sending a CHANNELMSG_RELID_RELEASED message to the
host) aren't done.

We can demo the issue this way:
1. rmmod hv_utils;
2. disable the Heartbeat Integration Service in Hyper-V Manager and lsvmbus
shows the device disappears.
3. re-enable the Heartbeat in Hyper-V Manager and modprobe hv_utils, but
lsvmbus shows the device can't appear again.
This is because, the host thinks the VM hasn't released the relid, so can't
re-offer the device to the VM.

We can fix the issue by moving hv_process_channel_removal()
from vmbus_close_internal() to vmbus_device_release(), since the latter is
always invoked on device_unregister(), whether or not the dev has a driver
loaded.

Signed-off-by: default avatarDexuan Cui <decui@microsoft.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 64b7faf9
Loading
Loading
Loading
Loading
+0 −6
Original line number Original line Diff line number Diff line
@@ -575,12 +575,6 @@ static int vmbus_close_internal(struct vmbus_channel *channel)
	free_pages((unsigned long)channel->ringbuffer_pages,
	free_pages((unsigned long)channel->ringbuffer_pages,
		get_order(channel->ringbuffer_pagecount * PAGE_SIZE));
		get_order(channel->ringbuffer_pagecount * PAGE_SIZE));


	/*
	 * If the channel has been rescinded; process device removal.
	 */
	if (channel->rescind)
		hv_process_channel_removal(channel,
					   channel->offermsg.child_relid);
out:
out:
	tasklet_enable(tasklet);
	tasklet_enable(tasklet);


+3 −3
Original line number Original line Diff line number Diff line
@@ -191,6 +191,8 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)
	if (channel == NULL)
	if (channel == NULL)
		return;
		return;


	BUG_ON(!channel->rescind);

	if (channel->target_cpu != get_cpu()) {
	if (channel->target_cpu != get_cpu()) {
		put_cpu();
		put_cpu();
		smp_call_function_single(channel->target_cpu,
		smp_call_function_single(channel->target_cpu,
@@ -230,9 +232,7 @@ void vmbus_free_channels(void)


	list_for_each_entry_safe(channel, tmp, &vmbus_connection.chn_list,
	list_for_each_entry_safe(channel, tmp, &vmbus_connection.chn_list,
		listentry) {
		listentry) {
		/* if we don't set rescind to true, vmbus_close_internal()
		/* hv_process_channel_removal() needs this */
		 * won't invoke hv_process_channel_removal().
		 */
		channel->rescind = true;
		channel->rescind = true;


		vmbus_device_unregister(channel->device_obj);
		vmbus_device_unregister(channel->device_obj);
+3 −12
Original line number Original line Diff line number Diff line
@@ -601,23 +601,11 @@ static int vmbus_remove(struct device *child_device)
{
{
	struct hv_driver *drv;
	struct hv_driver *drv;
	struct hv_device *dev = device_to_hv_device(child_device);
	struct hv_device *dev = device_to_hv_device(child_device);
	u32 relid = dev->channel->offermsg.child_relid;


	if (child_device->driver) {
	if (child_device->driver) {
		drv = drv_to_hv_drv(child_device->driver);
		drv = drv_to_hv_drv(child_device->driver);
		if (drv->remove)
		if (drv->remove)
			drv->remove(dev);
			drv->remove(dev);
		else {
			hv_process_channel_removal(dev->channel, relid);
			pr_err("remove not set for driver %s\n",
				dev_name(child_device));
		}
	} else {
		/*
		 * We don't have a driver for this device; deal with the
		 * rescind message by removing the channel.
		 */
		hv_process_channel_removal(dev->channel, relid);
	}
	}


	return 0;
	return 0;
@@ -652,7 +640,10 @@ static void vmbus_shutdown(struct device *child_device)
static void vmbus_device_release(struct device *device)
static void vmbus_device_release(struct device *device)
{
{
	struct hv_device *hv_dev = device_to_hv_device(device);
	struct hv_device *hv_dev = device_to_hv_device(device);
	struct vmbus_channel *channel = hv_dev->channel;


	hv_process_channel_removal(channel,
				   channel->offermsg.child_relid);
	kfree(hv_dev);
	kfree(hv_dev);


}
}