Skip to contentSkip to conversation

Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

PATCH Superseded Vitaly Kuznetsov 4 participants 14 messages Nov 26, 2014 – Jan 26, 2015 Hyper-V/Azure core and drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
 drivers/hv/vmbus_drv.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/hv/vmbus_drv.c +19 -0
index 4d6b269..9a82249 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,13 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +719,12 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+#endif
+
 	vmbus_request_offers();
 
 	return 0;
@@ -964,6 +978,11 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = native_cpu_disable;
+#endif
 }
 
 
Signature · 1 line
1.9.3
#1 lore raw
Quoted 58 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
 drivers/hv/vmbus_drv.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/hv/vmbus_drv.c +14 -0
index 4d6b269..9a82249 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,13 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +719,12 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+#endif
+
 	vmbus_request_offers();
 
 	return 0;

drivers/hv/vmbus_drv.c static void __exit vmbus_exit(void) · line 986

Quoted 9 lines
drivers/hv/vmbus_drv.c +5 -0
@@ -964,6 +978,11 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = native_cpu_disable;
+#endif
 }

#ifdef in a .c file is not a good idea to do if at all possible, please only put this in one place, using a function call to "hide" the mess.

greg k-h

maintainer
#2 lore raw
Quoted 87 lines

-----Original Message-----
From: devel [mailto:[email protected]] On Behalf Of Greg Kroah-Hartman
Sent: Thursday, November 27, 2014 11:03 AM
To: Vitaly Kuznetsov
Cc: [email protected]; Haiyang Zhang; linux- [email protected]
Subject: Re: [PATCH] Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

Quoted 1 line · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and

secondary

Quoted 1 line

cpus are sent offline (with echo 0 >

/sys/devices/system/cpu/cpu$cpu/online)

Quoted 2 lines

the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are

distributed

Quoted 1 line

across all cpus (see init_vp_index() function in

drivers/hv/channel_mgmt.c)

Quoted 1 line

and on cpu offlining nobody reassigns them to CPU0. Prevent cpu

offlining

Quoted 52 lines

when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
 drivers/hv/vmbus_drv.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/hv/vmbus_drv.c +14 -0
index 4d6b269..9a82249 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,13 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +719,12 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+#endif
+
 	vmbus_request_offers();
 
 	return 0;

drivers/hv/vmbus_drv.c static void __exit vmbus_exit(void) · line 986

Quoted 9 lines
drivers/hv/vmbus_drv.c +5 -0
@@ -964,6 +978,11 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = native_cpu_disable;
+#endif
 }

#ifdef in a .c file is not a good idea to do if at all possible, please only put this in one place, using a function call to "hide" the mess.

Quoted 1 line

greg k-h

Hi Vitaly,
The idea of the patch is good to me.

I agree with Greg.
BTW, maybe hv_cpu_hotplug_quirk() is a better name?

Thanks,
-- Dexuan

#3 lore raw
Quoted 87 lines · Dexuan Cui
Quoted 87 lines

-----Original Message-----
From: devel [mailto:[email protected]] On Behalf Of Greg Kroah-Hartman
Sent: Thursday, November 27, 2014 11:03 AM
To: Vitaly Kuznetsov
Cc: [email protected]; Haiyang Zhang; linux- [email protected]
Subject: Re: [PATCH] Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

Quoted 1 line · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and

secondary

Quoted 1 line

cpus are sent offline (with echo 0 >

/sys/devices/system/cpu/cpu$cpu/online)

Quoted 2 lines

the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are

distributed

Quoted 1 line

across all cpus (see init_vp_index() function in

drivers/hv/channel_mgmt.c)

Quoted 1 line

and on cpu offlining nobody reassigns them to CPU0. Prevent cpu

offlining

Quoted 52 lines

when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
 drivers/hv/vmbus_drv.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/hv/vmbus_drv.c +14 -0
index 4d6b269..9a82249 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,13 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +719,12 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+#endif
+
 	vmbus_request_offers();
 
 	return 0;

drivers/hv/vmbus_drv.c static void __exit vmbus_exit(void) · line 986

Quoted 9 lines
drivers/hv/vmbus_drv.c +5 -0
@@ -964,6 +978,11 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+#ifdef CONFIG_HOTPLUG_CPU
+	if ((vmbus_proto_version != VERSION_WS2008) &&
+	    (vmbus_proto_version != VERSION_WIN7))
+		smp_ops.cpu_disable = native_cpu_disable;
+#endif
 }

#ifdef in a .c file is not a good idea to do if at all possible, please only put this in one place, using a function call to "hide" the mess.

Quoted 7 lines
Quoted 1 line

greg k-h

Hi Vitaly,
The idea of the patch is good to me.

I agree with Greg.
BTW, maybe hv_cpu_hotplug_quirk() is a better name?

My idea was that eventually this function will start doing something real (e.g. switching channels to cpu0 if it doesn't happen fully host-side) so I called it with a general name 'hyperv_cpu_disable'.

I'll try addressing our and Greg's comments in v2, thanks!

Quoted 3 lines

Thanks,
-- Dexuan

Signature · 1 line
  Vitaly
#4 lore raw

PATCH v2 1/1 Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

In reply to Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH]
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor"

---
 drivers/hv/vmbus_drv.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/hv/vmbus_drv.c +33 -0
index 4d6b269..2e6b38e 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,36 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+	/*
+	 * Offlining a CPU when running on newer hypervisors (WS2012R2, Win8,
+	 * ...) is not supported at this moment as channel interrupts are
+	 * distributed across all of them.
+	 */
+
+	if ((vmbus_proto_version == VERSION_WS2008) ||
+	    (vmbus_proto_version == VERSION_WIN7))
+		return;
+
+	if (vmbus_loaded) {
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+		pr_notice("CPU offlining is not supported by hypervisor");
+	} else
+		smp_ops.cpu_disable = native_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +742,7 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+	hv_cpu_hotplug_quirk(true);
 	vmbus_request_offers();
 
 	return 0;
@@ -964,6 +996,7 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+	hv_cpu_hotplug_quirk(false);
 }
 
 
Signature · 1 line
1.9.3
maintainer Acked-by on v2 1/1
#5 lore raw
Quoted 93 lines

-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Monday, December 1, 2014 18:53 PM
To: KY Srinivasan; Haiyang Zhang
Cc: [email protected]; Greg Kroah-Hartman; linux- [email protected]; Dexuan Cui
Subject: [PATCH v2] Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary
cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH]
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor"

---
 drivers/hv/vmbus_drv.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/hv/vmbus_drv.c +31 -0
index 4d6b269..2e6b38e 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,36 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+	/*
+	 * Offlining a CPU when running on newer hypervisors (WS2012R2,
 Win8,
+	 * ...) is not supported at this moment as channel interrupts are
+	 * distributed across all of them.
+	 */
+
+	if ((vmbus_proto_version == VERSION_WS2008) ||
+	    (vmbus_proto_version == VERSION_WIN7))
+		return;
+
+	if (vmbus_loaded) {
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+		pr_notice("CPU offlining is not supported by hypervisor");
+	} else
+		smp_ops.cpu_disable = native_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.

*

drivers/hv/vmbus_drv.c +1 -0
@@ -711,6 +742,7 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+	hv_cpu_hotplug_quirk(true);
 	vmbus_request_offers();
 
 	return 0;

drivers/hv/vmbus_drv.c static void __exit vmbus_exit(void) · line 1000

Quoted 5 lines
drivers/hv/vmbus_drv.c +1 -0
@@ -964,6 +996,7 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+	hv_cpu_hotplug_quirk(false);
 }
#6 lore raw
In reply to Vitaly Kuznetsov
Quoted 91 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH]
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor"

---
 drivers/hv/vmbus_drv.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/hv/vmbus_drv.c +33 -0
index 4d6b269..2e6b38e 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,36 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -1;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+	/*
+	 * Offlining a CPU when running on newer hypervisors (WS2012R2, Win8,
+	 * ...) is not supported at this moment as channel interrupts are
+	 * distributed across all of them.
+	 */
+
+	if ((vmbus_proto_version == VERSION_WS2008) ||
+	    (vmbus_proto_version == VERSION_WIN7))
+		return;
+
+	if (vmbus_loaded) {
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+		pr_notice("CPU offlining is not supported by hypervisor");
+	} else
+		smp_ops.cpu_disable = native_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +742,7 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+	hv_cpu_hotplug_quirk(true);
 	vmbus_request_offers();
 
 	return 0;
@@ -964,6 +996,7 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+	hv_cpu_hotplug_quirk(false);
 }
 
 
Signature · 1 line
1.9.3

This breaks the build:
ERROR: "native_cpu_disable" [drivers/hv/hv_vmbus.ko] undefined!

Please test better.

greg k-h

#7 lore raw

PATCH v3 1/1 Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

In reply to Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by saving current cpu_disable pointer to previous_cpu_disable and restoring it on unload;
- return -ENOSYS (same as native_cpu_disable when !CONFIG_HOTPLUG_CPU) instead of -1 in hyperv_cpu_disable().

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/hv/vmbus_drv.c +36 -0
index 4d6b269..233da0b 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,39 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -ENOSYS;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+	static void *previous_cpu_disable;
+
+	/*
+	 * Offlining a CPU when running on newer hypervisors (WS2012R2, Win8,
+	 * ...) is not supported at this moment as channel interrupts are
+	 * distributed across all of them.
+	 */
+
+	if ((vmbus_proto_version == VERSION_WS2008) ||
+	    (vmbus_proto_version == VERSION_WIN7))
+		return;
+
+	if (vmbus_loaded) {
+		previous_cpu_disable = smp_ops.cpu_disable;
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+		pr_notice("CPU offlining is not supported by hypervisor\n");
+	} else if (previous_cpu_disable)
+		smp_ops.cpu_disable = previous_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -711,6 +745,7 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+	hv_cpu_hotplug_quirk(true);
 	vmbus_request_offers();
 
 	return 0;
@@ -964,6 +999,7 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+	hv_cpu_hotplug_quirk(false);
 }
 
 
Signature · 1 line
1.9.3
#8 lore raw
Quoted 21 lines

-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Monday, January 12, 2015 8:50 AM
To: KY Srinivasan; [email protected]
Cc: Haiyang Zhang; Greg Kroah-Hartman; [email protected]; Dexuan Cui
Subject: [PATCH v3] Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary
cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online)
the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

Quoted 6 lines

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

Thank you.

Quoted 89 lines

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by saving current cpu_disable pointer to previous_cpu_disable and restoring it on unload;
- return -ENOSYS (same as native_cpu_disable when !CONFIG_HOTPLUG_CPU) instead
of -1 in hyperv_cpu_disable().

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/hv/vmbus_drv.c +34 -0
index 4d6b269..233da0b 100644
@@ -32,6 +32,7 @@
 #include <linux/completion.h>
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -671,6 +672,39 @@ static void vmbus_isr(void)
 		tasklet_schedule(&msg_dpc);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -ENOSYS;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+	static void *previous_cpu_disable;
+
+	/*
+	 * Offlining a CPU when running on newer hypervisors (WS2012R2,
 Win8,
+	 * ...) is not supported at this moment as channel interrupts are
+	 * distributed across all of them.
+	 */
+
+	if ((vmbus_proto_version == VERSION_WS2008) ||
+	    (vmbus_proto_version == VERSION_WIN7))
+		return;
+
+	if (vmbus_loaded) {
+		previous_cpu_disable = smp_ops.cpu_disable;
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+		pr_notice("CPU offlining is not supported by hypervisor\n");
+	} else if (previous_cpu_disable)
+		smp_ops.cpu_disable = previous_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.

*

drivers/hv/vmbus_drv.c +2 -1
@@ -711,6 +745,7 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+	hv_cpu_hotplug_quirk(true);
 	vmbus_request_offers();
 
 	return 0;
@@ -964,6 +999,7 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+	hv_cpu_hotplug_quirk(false);
 }
 
 
--

1.9.3

#9 lore raw
In reply to Vitaly Kuznetsov
Quoted 23 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by saving current cpu_disable pointer to previous_cpu_disable and restoring it on unload;
- return -ENOSYS (same as native_cpu_disable when !CONFIG_HOTPLUG_CPU) instead of -1 in hyperv_cpu_disable().

Quoted 7 lines

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

Doesn't apply to my char-misc-test branch at all :(

#10 lore raw
Quoted 32 lines · Greg Kroah-Hartman
Quoted 23 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by saving current cpu_disable pointer to previous_cpu_disable and restoring it on unload;
- return -ENOSYS (same as native_cpu_disable when !CONFIG_HOTPLUG_CPU) instead of -1 in hyperv_cpu_disable().

Quoted 7 lines

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
Quoted 1 line

Doesn't apply to my char-misc-test branch at all :(

Another mid-air collision with K.Y's "Drivers: hv: vmbus: Implement a clockevent device", please use the attached version. No functional changes are required, I just fixed the merge conflict (includes).

Othere than that (and sorry for meddling), would it it be better if you switch to 'pull requests' workflow with K.Y? There is a lot of ongoing work in hyperv nowdays and such collisions seem otherwise inevitable ...

Signature · 1 line
  Vitaly
Quoted 1 line

From 95f9b0ff3f73c3bbe8aa9c525414097c2c26a3ef Mon Sep 17 00:00:00 2001

From: Vitaly Kuznetsov <[email protected]>
Date: Mon, 12 Jan 2015 17:50:11 +0100
Subject: [PATCH] Drivers: hv: vmbus: prevent cpu offlining on newer
hypervisors

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
 drivers/hv/vmbus_drv.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
drivers/hv/vmbus_drv.c +36 -0
index 35e3f42..90c3400 100644
@@ -33,6 +33,7 @@
 #include <linux/hyperv.h>
 #include <linux/kernel_stat.h>
 #include <linux/clockchips.h>
+#include <linux/cpu.h>
 #include <asm/hyperv.h>
 #include <asm/hypervisor.h>
 #include <asm/mshyperv.h>
@@ -704,6 +705,39 @@ static void vmbus_isr(void)
 	}
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static int hyperv_cpu_disable(void)
+{
+	return -ENOSYS;
+}
+
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+	static void *previous_cpu_disable;
+
+	/*
+	 * Offlining a CPU when running on newer hypervisors (WS2012R2, Win8,
+	 * ...) is not supported at this moment as channel interrupts are
+	 * distributed across all of them.
+	 */
+
+	if ((vmbus_proto_version == VERSION_WS2008) ||
+	    (vmbus_proto_version == VERSION_WIN7))
+		return;
+
+	if (vmbus_loaded) {
+		previous_cpu_disable = smp_ops.cpu_disable;
+		smp_ops.cpu_disable = hyperv_cpu_disable;
+		pr_notice("CPU offlining is not supported by hypervisor\n");
+	} else if (previous_cpu_disable)
+		smp_ops.cpu_disable = previous_cpu_disable;
+}
+#else
+static void hv_cpu_hotplug_quirk(bool vmbus_loaded)
+{
+}
+#endif
+
 /*
  * vmbus_bus_init -Main vmbus driver initialization routine.
  *
@@ -744,6 +778,7 @@ static int vmbus_bus_init(int irq)
 	if (ret)
 		goto err_alloc;
 
+	hv_cpu_hotplug_quirk(true);
 	vmbus_request_offers();
 
 	return 0;
@@ -997,6 +1032,7 @@ static void __exit vmbus_exit(void)
 	bus_unregister(&hv_bus);
 	hv_cleanup();
 	acpi_bus_unregister_driver(&vmbus_acpi_driver);
+	hv_cpu_hotplug_quirk(false);
 }
 
 
Signature · 1 line
1.9.3
#11 lore raw
Quoted 52 lines

-----Original Message-----
From: Vitaly Kuznetsov [mailto:[email protected]]
Sent: Monday, January 26, 2015 2:39 AM
To: Greg Kroah-Hartman
Cc: KY Srinivasan; [email protected]; Haiyang Zhang; linux- [email protected]; Dexuan Cui
Subject: Re: [PATCH v3] Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online)
the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is

fixed host-side.

Quoted 6 lines
Quoted 6 lines

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

Quoted 8 lines
Quoted 8 lines

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by saving current cpu_disable pointer to previous_cpu_disable and restoring it on unload;
- return -ENOSYS (same as native_cpu_disable when

!CONFIG_HOTPLUG_CPU) instead

Quoted 9 lines
Quoted 9 lines

of -1 in hyperv_cpu_disable().

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36

++++++++++++++++++++++++++++++++++++

Quoted 3 lines
Quoted 1 line
 1 file changed, 36 insertions(+)

Doesn't apply to my char-misc-test branch at all :(

Quoted 7 lines

Another mid-air collision with K.Y's "Drivers: hv: vmbus: Implement a clockevent device", please use the attached version. No functional changes are required, I just fixed the merge conflict (includes).

Othere than that (and sorry for meddling), would it it be better if you switch to 'pull requests' workflow with K.Y? There is a lot of ongoing work in hyperv nowdays and such collisions seem otherwise inevitable ...

I will co-ordinate and forward Hyper-V patches to Greg.

K. Y

Quoted 3 lines

--
Vitaly

#12 lore raw
In reply to Vitaly Kuznetsov
Quoted 36 lines · Vitaly Kuznetsov
Quoted 32 lines · Greg Kroah-Hartman
Quoted 23 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online) the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the issue is fixed host-side.

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by saving current cpu_disable pointer to previous_cpu_disable and restoring it on unload;
- return -ENOSYS (same as native_cpu_disable when !CONFIG_HOTPLUG_CPU) instead of -1 in hyperv_cpu_disable().

Quoted 7 lines

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
Quoted 1 line

Doesn't apply to my char-misc-test branch at all :(

Quoted 8 lines

Another mid-air collision with K.Y's "Drivers: hv: vmbus: Implement a clockevent device", please use the attached version. No functional changes are required, I just fixed the merge conflict (includes).

Othere than that (and sorry for meddling), would it it be better if you switch to 'pull requests' workflow with K.Y? There is a lot of ongoing work in hyperv nowdays and such collisions seem otherwise inevitable ...

This is a trivial number of patches for this subsystem, so no, a git workflow isn't needed. But if KY would collect the patches up and send them to me for all hyperv patches from now on, that would make these types of issues go away, KY, can you do that from now on?

thanks,

greg k-h

#13 lore raw
Quoted 64 lines

-----Original Message-----
From: Greg Kroah-Hartman [mailto:[email protected]]
Sent: Monday, January 26, 2015 2:54 PM
To: Vitaly Kuznetsov
Cc: KY Srinivasan; [email protected]; Haiyang Zhang; linux- [email protected]; Dexuan Cui
Subject: Re: [PATCH v3] Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors

Quoted 11 lines · Vitaly Kuznetsov
Quoted 9 lines · Greg Kroah-Hartman
Quoted 8 lines · Vitaly Kuznetsov

When an SMP Hyper-V guest is running on top of 2012R2 Server and secondary cpus are sent offline (with echo 0 > /sys/devices/system/cpu/cpu$cpu/online)
the system freeze is observed. This happens due to the fact that on newer hypervisors (Win8, WS2012R2, ...) vmbus channel handlers are distributed across all cpus (see init_vp_index() function in drivers/hv/channel_mgmt.c) and on cpu offlining nobody reassigns them to CPU0. Prevent cpu offlining when vmbus is loaded until the

issue is fixed host-side.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

This patch also disables hibernation but it is OK as it is also broken (MCE error is hit on resume). Suspend still works.

Tested with WS2008R2 and WS2012R2.

---
Changes since v2:
- repair the build when vmbus is builded as a module [Greg KH] by

saving

Quoted 1 line
Quoted 1 line
Quoted 1 line

current cpu_disable pointer to previous_cpu_disable and restoring it

on

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

unload;
- return -ENOSYS (same as native_cpu_disable when

!CONFIG_HOTPLUG_CPU) instead

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

of -1 in hyperv_cpu_disable().

Changes since v1:
- introduce hv_cpu_hotplug_quirk() function to not spread #ifdefs [Greg KH];
- add pr_notice() message "hv_vmbus: CPU offlining is not supported by hypervisor".

---
 drivers/hv/vmbus_drv.c | 36

++++++++++++++++++++++++++++++++++++

Quoted 4 lines
Quoted 3 lines
Quoted 1 line
 1 file changed, 36 insertions(+)

Doesn't apply to my char-misc-test branch at all :(

Quoted 8 lines

Another mid-air collision with K.Y's "Drivers: hv: vmbus: Implement a clockevent device", please use the attached version. No functional changes are required, I just fixed the merge conflict (includes).

Othere than that (and sorry for meddling), would it it be better if you switch to 'pull requests' workflow with K.Y? There is a lot of ongoing work in hyperv nowdays and such collisions seem otherwise inevitable ...

Quoted 4 lines

This is a trivial number of patches for this subsystem, so no, a git workflow isn't needed. But if KY would collect the patches up and send them to me for all hyperv patches from now on, that would make these types of issues go away, KY, can you do that from now on?

Will do.

Thanks,

K. Y

Quoted 4 lines

thanks,

greg k-h