linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes
@ 2020-03-23 13:09 ltykernel
  2020-03-23 13:09 ` [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback ltykernel
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, tglx, mingo, bp, hpa, x86,
	michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

This patchset fixes some issues in the Hyper-V panic code path.
Patch 1 resolves issue that panic system still responses network
packets.
Patch 2-3,5-6 resolves crash enlightenment issues.
Patch 4 is to set crash_kexec_post_notifiers to true for Hyper-V
VM in order to report crash data or kmsg to host before running
kdump kernel.

Tianyu Lan (6):
  x86/Hyper-V: Unload vmbus channel in hv panic callback
  x86/Hyper-V: Free hv_panic_page when fail to register kmsg dump
  x86/Hyper-V: Trigger crash enlightenment only once during  system
    crash.
  x86/Hyper-V: Report crash register data or ksmg before  running crash
    kernel
  x86/Hyper-V: Report crash register data when sysctl_record_panic_msg
    is not set
  x86/Hyper-V: Report crash data in die() when panic_on_oops is set

 arch/x86/kernel/cpu/mshyperv.c | 10 ++++++++
 drivers/hv/channel_mgmt.c      |  3 +++
 drivers/hv/vmbus_drv.c         | 55 ++++++++++++++++++++++++++++--------------
 3 files changed, 50 insertions(+), 18 deletions(-)

-- 
2.14.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback
  2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
@ 2020-03-23 13:09 ` ltykernel
  2020-03-23 17:11   ` Michael Kelley
  2020-03-23 13:09 ` [PATCH V2 2/6] x86/Hyper-V: Free hv_panic_page when fail to register kmsg dump ltykernel
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, tglx, mingo, bp, hpa, x86,
	michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

When kdump is not configured, a Hyper-V VM might still respond to
network traffic after a kernel panic when kernel parameter panic=0.
The panic CPU goes into an infinite loop with interrupts enabled,
and the VMbus driver interrupt handler still works because the
VMbus connection is unloaded only in the kdump path.  The network
responses make the other end of the connection think the VM is
still functional even though it has panic'ed, which could affect any
failover actions that should be taken.

Fix this by unloading the VMbus connection during the panic process.
vmbus_initiate_unload() could then be called twice (e.g., by
hyperv_panic_event() and hv_crash_handler(), so reset the connection
state in vmbus_initiate_unload() to ensure the unload is done only
once.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
Change since v1:
	- Update chnage log
	- Use xchg() to change vmbus connection status
---
 drivers/hv/channel_mgmt.c |  3 +++
 drivers/hv/vmbus_drv.c    | 17 +++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
index 0370364169c4..501c43c5851d 100644
--- a/drivers/hv/channel_mgmt.c
+++ b/drivers/hv/channel_mgmt.c
@@ -839,6 +839,9 @@ void vmbus_initiate_unload(bool crash)
 {
 	struct vmbus_channel_message_header hdr;
 
+	if (xchg(&vmbus_connection.conn_state, DISCONNECTED) == DISCONNECTED)
+		return;
+
 	/* Pre-Win2012R2 hosts don't support reconnect */
 	if (vmbus_proto_version < VERSION_WIN8_1)
 		return;
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 029378c27421..b56b9fb9bd90 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -53,9 +53,12 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
 {
 	struct pt_regs *regs;
 
-	regs = current_pt_regs();
+	vmbus_initiate_unload(true);
 
-	hyperv_report_panic(regs, val);
+	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
+		regs = current_pt_regs();
+		hyperv_report_panic(regs, val);
+	}
 	return NOTIFY_DONE;
 }
 
@@ -1391,10 +1394,12 @@ static int vmbus_bus_init(void)
 		}
 
 		register_die_notifier(&hyperv_die_block);
-		atomic_notifier_chain_register(&panic_notifier_list,
-					       &hyperv_panic_block);
 	}
 
+	/* Vmbus channel is unloaded in panic callback when panic happens.*/
+	atomic_notifier_chain_register(&panic_notifier_list,
+			       &hyperv_panic_block);
+
 	vmbus_request_offers();
 
 	return 0;
@@ -2204,8 +2209,6 @@ static int vmbus_bus_suspend(struct device *dev)
 
 	vmbus_initiate_unload(false);
 
-	vmbus_connection.conn_state = DISCONNECTED;
-
 	/* Reset the event for the next resume. */
 	reinit_completion(&vmbus_connection.ready_for_resume_event);
 
@@ -2289,7 +2292,6 @@ static void hv_kexec_handler(void)
 {
 	hv_stimer_global_cleanup();
 	vmbus_initiate_unload(false);
-	vmbus_connection.conn_state = DISCONNECTED;
 	/* Make sure conn_state is set as hv_synic_cleanup checks for it */
 	mb();
 	cpuhp_remove_state(hyperv_cpuhp_online);
@@ -2306,7 +2308,6 @@ static void hv_crash_handler(struct pt_regs *regs)
 	 * doing the cleanup for current CPU only. This should be sufficient
 	 * for kdump.
 	 */
-	vmbus_connection.conn_state = DISCONNECTED;
 	cpu = smp_processor_id();
 	hv_stimer_cleanup(cpu);
 	hv_synic_disable_regs(cpu);
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 2/6] x86/Hyper-V: Free hv_panic_page when fail to register kmsg dump
  2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
  2020-03-23 13:09 ` [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback ltykernel
@ 2020-03-23 13:09 ` ltykernel
  2020-03-23 13:09 ` [PATCH V2 3/6] x86/Hyper-V: Trigger crash enlightenment only once during system crash ltykernel
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, tglx, mingo, bp, hpa, x86,
	michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

If kmsg_dump_register() fails, hv_panic_page will not be used
anywhere.  So free and reset it.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
Change since v1:
	- Update commit log
	- Remove hv_free_hyperv_page() in the error path
---
 drivers/hv/vmbus_drv.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index b56b9fb9bd90..3a0472c8b7ae 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1385,9 +1385,13 @@ static int vmbus_bus_init(void)
 			hv_panic_page = (void *)hv_alloc_hyperv_zeroed_page();
 			if (hv_panic_page) {
 				ret = kmsg_dump_register(&hv_kmsg_dumper);
-				if (ret)
+				if (ret) {
 					pr_err("Hyper-V: kmsg dump register "
 						"error 0x%x\n", ret);
+					hv_free_hyperv_page(
+					    (unsigned long)hv_panic_page);
+					hv_panic_page = NULL;
+				}
 			} else
 				pr_err("Hyper-V: panic message page memory "
 					"allocation failed");
@@ -1412,7 +1416,6 @@ static int vmbus_bus_init(void)
 	hv_remove_vmbus_irq();
 
 	bus_unregister(&hv_bus);
-	hv_free_hyperv_page((unsigned long)hv_panic_page);
 	unregister_sysctl_table(hv_ctl_table_hdr);
 	hv_ctl_table_hdr = NULL;
 	return ret;
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 3/6] x86/Hyper-V: Trigger crash enlightenment only once during  system crash.
  2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
  2020-03-23 13:09 ` [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback ltykernel
  2020-03-23 13:09 ` [PATCH V2 2/6] x86/Hyper-V: Free hv_panic_page when fail to register kmsg dump ltykernel
@ 2020-03-23 13:09 ` ltykernel
  2020-03-23 17:15   ` Michael Kelley
  2020-03-23 13:09 ` [PATCH V2 4/6] x86/Hyper-V: Report crash register data or ksmg before running crash kernel ltykernel
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, tglx, mingo, bp, hpa, x86,
	michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

When a guest VM panics, Hyper-V should be notified only once via the
crash synthetic MSRs.  Current Linux code might write these crash MSRs
twice during a system panic:
1) hyperv_panic/die_event() calling hyperv_report_panic()
2) hv_kmsg_dump() calling hyperv_report_panic_msg()

Fix this by not calling hyperv_report_panic() if a kmsg dump has been
successfully registered.  The notification will happen later via
hyperv_report_panic_msg().

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
Change since v1:
	- Update commit log
---
 drivers/hv/vmbus_drv.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 3a0472c8b7ae..d73fa8aa00a3 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -55,7 +55,12 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
 
 	vmbus_initiate_unload(true);
 
-	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
+	/*
+	 * Crash notify only can be triggered once. If crash notify
+	 * message is available, just report kmsg to crash buffer.
+	 */
+	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE
+	    && !hv_panic_page) {
 		regs = current_pt_regs();
 		hyperv_report_panic(regs, val);
 	}
@@ -68,7 +73,12 @@ static int hyperv_die_event(struct notifier_block *nb, unsigned long val,
 	struct die_args *die = (struct die_args *)args;
 	struct pt_regs *regs = die->regs;
 
-	hyperv_report_panic(regs, val);
+	/*
+	 * Crash notify only can be triggered once. If crash notify
+	 * message is available, just report kmsg to crash buffer.
+	 */
+	if (!hv_panic_page)
+		hyperv_report_panic(regs, val);
 	return NOTIFY_DONE;
 }
 
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 4/6] x86/Hyper-V: Report crash register data or ksmg before running crash kernel
  2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
                   ` (2 preceding siblings ...)
  2020-03-23 13:09 ` [PATCH V2 3/6] x86/Hyper-V: Trigger crash enlightenment only once during system crash ltykernel
@ 2020-03-23 13:09 ` ltykernel
  2020-03-23 17:16   ` Michael Kelley
  2020-03-23 13:09 ` [PATCH V2 5/6] x86/Hyper-V: Report crash register data when sysctl_record_panic_msg is not set ltykernel
  2020-03-23 13:09 ` [PATCH V2 6/6] x86/Hyper-V: Report crash data in die() when panic_on_oops is set ltykernel
  5 siblings, 1 reply; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, tglx, mingo, bp, hpa, x86,
	michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

When a guest VM panics, Hyper-V should be notified only once via the
crash synthetic MSRs.  Current Linux code might write these crash MSRs
twice during a system panic:
1) hyperv_panic/die_event() calling hyperv_report_panic()
2) hv_kmsg_dump() calling hyperv_report_panic_msg()

Fix this by not calling hyperv_report_panic() if a kmsg dump has been
successfully registered.  The notification will happen later via
hyperv_report_panic_msg().

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
Change since v1:
       Update commit log
---
 arch/x86/kernel/cpu/mshyperv.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index caa032ce3fe3..5e296a7e6036 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -263,6 +263,16 @@ static void __init ms_hyperv_init_platform(void)
 			cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
 	}
 
+	/*
+	 * Hyper-V expects to get crash register data or kmsg when
+	 * crash enlightment is available and system crashes. Set
+	 * crash_kexec_post_notifiers to be true to make sure that
+	 * calling crash enlightment interface before running kdump
+	 * kernel.
+	 */
+	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
+		crash_kexec_post_notifiers = true;
+
 #ifdef CONFIG_X86_LOCAL_APIC
 	if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS &&
 	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 5/6] x86/Hyper-V: Report crash register data when sysctl_record_panic_msg is not set
  2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
                   ` (3 preceding siblings ...)
  2020-03-23 13:09 ` [PATCH V2 4/6] x86/Hyper-V: Report crash register data or ksmg before running crash kernel ltykernel
@ 2020-03-23 13:09 ` ltykernel
  2020-03-23 17:20   ` Michael Kelley
  2020-03-23 13:09 ` [PATCH V2 6/6] x86/Hyper-V: Report crash data in die() when panic_on_oops is set ltykernel
  5 siblings, 1 reply; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

When sysctl_record_panic_msg is not set, kmsg will
not be reported to Hyper-V. Crash register data should
be reported via hyperv_report_panic() in such case.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 drivers/hv/vmbus_drv.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index d73fa8aa00a3..00447175c040 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -48,6 +48,18 @@ static int hyperv_cpuhp_online;
 
 static void *hv_panic_page;
 
+/*
+ * Boolean to control whether to report panic messages over Hyper-V.
+ *
+ * It can be set via /proc/sys/kernel/hyperv/record_panic_msg
+ */
+static int sysctl_record_panic_msg = 1;
+
+static int hyperv_report_reg(void)
+{
+	return !sysctl_record_panic_msg || !hv_panic_page;
+}
+
 static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
 			      void *args)
 {
@@ -60,7 +72,7 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
 	 * message is available, just report kmsg to crash buffer.
 	 */
 	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE
-	    && !hv_panic_page) {
+	    && hyperv_report_reg()) {
 		regs = current_pt_regs();
 		hyperv_report_panic(regs, val);
 	}
@@ -77,7 +89,7 @@ static int hyperv_die_event(struct notifier_block *nb, unsigned long val,
 	 * Crash notify only can be triggered once. If crash notify
 	 * message is available, just report kmsg to crash buffer.
 	 */
-	if (!hv_panic_page)
+	if (hyperv_report_reg())
 		hyperv_report_panic(regs, val);
 	return NOTIFY_DONE;
 }
@@ -1265,13 +1277,6 @@ static void vmbus_isr(void)
 	add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0);
 }
 
-/*
- * Boolean to control whether to report panic messages over Hyper-V.
- *
- * It can be set via /proc/sys/kernel/hyperv/record_panic_msg
- */
-static int sysctl_record_panic_msg = 1;
-
 /*
  * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg
  * buffer and call into Hyper-V to transfer the data.
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 6/6] x86/Hyper-V: Report crash data in die() when panic_on_oops is set
  2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
                   ` (4 preceding siblings ...)
  2020-03-23 13:09 ` [PATCH V2 5/6] x86/Hyper-V: Report crash register data when sysctl_record_panic_msg is not set ltykernel
@ 2020-03-23 13:09 ` ltykernel
  5 siblings, 0 replies; 11+ messages in thread
From: ltykernel @ 2020-03-23 13:09 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, liuwe, michael.h.kelley
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com>

When oops happens with panic_on_oops unset, the oops
thread is killed by die() and system continues to run.
In such case, guest should not report crash register
data to host since system still runs. Fix it.

Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
---
 drivers/hv/vmbus_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 00447175c040..ecdb64db0e4a 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -89,7 +89,7 @@ static int hyperv_die_event(struct notifier_block *nb, unsigned long val,
 	 * Crash notify only can be triggered once. If crash notify
 	 * message is available, just report kmsg to crash buffer.
 	 */
-	if (hyperv_report_reg())
+	if (hyperv_report_reg() && panic_on_oops)
 		hyperv_report_panic(regs, val);
 	return NOTIFY_DONE;
 }
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* RE: [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback
  2020-03-23 13:09 ` [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback ltykernel
@ 2020-03-23 17:11   ` Michael Kelley
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Kelley @ 2020-03-23 17:11 UTC (permalink / raw)
  To: ltykernel, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, tglx, mingo, bp, hpa, x86
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com> Sent: Monday, March 23, 2020 6:09 AM
> 
> When kdump is not configured, a Hyper-V VM might still respond to
> network traffic after a kernel panic when kernel parameter panic=0.
> The panic CPU goes into an infinite loop with interrupts enabled,
> and the VMbus driver interrupt handler still works because the
> VMbus connection is unloaded only in the kdump path.  The network
> responses make the other end of the connection think the VM is
> still functional even though it has panic'ed, which could affect any
> failover actions that should be taken.
> 
> Fix this by unloading the VMbus connection during the panic process.
> vmbus_initiate_unload() could then be called twice (e.g., by
> hyperv_panic_event() and hv_crash_handler(), so reset the connection
> state in vmbus_initiate_unload() to ensure the unload is done only
> once.
> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
> Change since v1:
> 	- Update chnage log
> 	- Use xchg() to change vmbus connection status
> ---
>  drivers/hv/channel_mgmt.c |  3 +++
>  drivers/hv/vmbus_drv.c    | 17 +++++++++--------
>  2 files changed, 12 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c
> index 0370364169c4..501c43c5851d 100644
> --- a/drivers/hv/channel_mgmt.c
> +++ b/drivers/hv/channel_mgmt.c
> @@ -839,6 +839,9 @@ void vmbus_initiate_unload(bool crash)
>  {
>  	struct vmbus_channel_message_header hdr;
> 
> +	if (xchg(&vmbus_connection.conn_state, DISCONNECTED) == DISCONNECTED)
> +		return;
> +
>  	/* Pre-Win2012R2 hosts don't support reconnect */
>  	if (vmbus_proto_version < VERSION_WIN8_1)
>  		return;
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index 029378c27421..b56b9fb9bd90 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -53,9 +53,12 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned
> long val,
>  {
>  	struct pt_regs *regs;
> 
> -	regs = current_pt_regs();
> +	vmbus_initiate_unload(true);
> 
> -	hyperv_report_panic(regs, val);
> +	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
> +		regs = current_pt_regs();
> +		hyperv_report_panic(regs, val);
> +	}
>  	return NOTIFY_DONE;
>  }
> 
> @@ -1391,10 +1394,12 @@ static int vmbus_bus_init(void)
>  		}
> 
>  		register_die_notifier(&hyperv_die_block);
> -		atomic_notifier_chain_register(&panic_notifier_list,
> -					       &hyperv_panic_block);
>  	}
> 
> +	/* Vmbus channel is unloaded in panic callback when panic happens.*/

Let me suggest a tweak to the above comment so it is super clear:

	/*
	 * Always register the panic notifier because we need to unload
	 * the VMbus channel connection to prevent any VMbus
	 * activity after the VM panics.
	 */

> +	atomic_notifier_chain_register(&panic_notifier_list,
> +			       &hyperv_panic_block);
> +
>  	vmbus_request_offers();
> 
>  	return 0;

^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH V2 3/6] x86/Hyper-V: Trigger crash enlightenment only once during  system crash.
  2020-03-23 13:09 ` [PATCH V2 3/6] x86/Hyper-V: Trigger crash enlightenment only once during system crash ltykernel
@ 2020-03-23 17:15   ` Michael Kelley
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Kelley @ 2020-03-23 17:15 UTC (permalink / raw)
  To: ltykernel, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, tglx, mingo, bp, hpa, x86
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com> Sent: Monday, March 23, 2020 6:09 AM
> 
> When a guest VM panics, Hyper-V should be notified only once via the
> crash synthetic MSRs.  Current Linux code might write these crash MSRs
> twice during a system panic:
> 1) hyperv_panic/die_event() calling hyperv_report_panic()
> 2) hv_kmsg_dump() calling hyperv_report_panic_msg()
> 
> Fix this by not calling hyperv_report_panic() if a kmsg dump has been
> successfully registered.  The notification will happen later via
> hyperv_report_panic_msg().
> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
> Change since v1:
> 	- Update commit log
> ---
>  drivers/hv/vmbus_drv.c | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index 3a0472c8b7ae..d73fa8aa00a3 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -55,7 +55,12 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned
> long val,
> 
>  	vmbus_initiate_unload(true);
> 
> -	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) {
> +	/*
> +	 * Crash notify only can be triggered once. If crash notify
> +	 * message is available, just report kmsg to crash buffer.
> +	 */

Just to clarify the above comment, let me suggest:

	/*
	 * Hyper-V should be notified only once about a panic.  If we will be
	 * doing hyperv_report_panic_msg() later with kmsg data, don't do
	 * the notification here.
	 */

> +	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE
> +	    && !hv_panic_page) {
>  		regs = current_pt_regs();
>  		hyperv_report_panic(regs, val);
>  	}
> @@ -68,7 +73,12 @@ static int hyperv_die_event(struct notifier_block *nb, unsigned long
> val,
>  	struct die_args *die = (struct die_args *)args;
>  	struct pt_regs *regs = die->regs;
> 
> -	hyperv_report_panic(regs, val);
> +	/*
> +	 * Crash notify only can be triggered once. If crash notify
> +	 * message is available, just report kmsg to crash buffer.
> +	 */

Same suggested clarification to the comment applies here.

> +	if (!hv_panic_page)
> +		hyperv_report_panic(regs, val);
>  	return NOTIFY_DONE;
>  }
> 
> --
> 2.14.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH V2 4/6] x86/Hyper-V: Report crash register data or ksmg before running crash kernel
  2020-03-23 13:09 ` [PATCH V2 4/6] x86/Hyper-V: Report crash register data or ksmg before running crash kernel ltykernel
@ 2020-03-23 17:16   ` Michael Kelley
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Kelley @ 2020-03-23 17:16 UTC (permalink / raw)
  To: ltykernel, KY Srinivasan, Haiyang Zhang, Stephen Hemminger,
	Wei Liu, tglx, mingo, bp, hpa, x86
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com> Sent: Monday, March 23, 2020 6:09 AM
> 
> When a guest VM panics, Hyper-V should be notified only once via the
> crash synthetic MSRs.  Current Linux code might write these crash MSRs
> twice during a system panic:
> 1) hyperv_panic/die_event() calling hyperv_report_panic()
> 2) hv_kmsg_dump() calling hyperv_report_panic_msg()
> 
> Fix this by not calling hyperv_report_panic() if a kmsg dump has been
> successfully registered.  The notification will happen later via
> hyperv_report_panic_msg().

I think this patch got the wrong commit message.  This message is the same
as in patch 3 of the series.

> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
> Change since v1:
>        Update commit log
> ---
>  arch/x86/kernel/cpu/mshyperv.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index caa032ce3fe3..5e296a7e6036 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -263,6 +263,16 @@ static void __init ms_hyperv_init_platform(void)
>  			cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
>  	}
> 
> +	/*
> +	 * Hyper-V expects to get crash register data or kmsg when
> +	 * crash enlightment is available and system crashes. Set
> +	 * crash_kexec_post_notifiers to be true to make sure that
> +	 * calling crash enlightment interface before running kdump
> +	 * kernel.
> +	 */
> +	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
> +		crash_kexec_post_notifiers = true;
> +
>  #ifdef CONFIG_X86_LOCAL_APIC
>  	if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS &&
>  	    ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
> --
> 2.14.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

* RE: [PATCH V2 5/6] x86/Hyper-V: Report crash register data when sysctl_record_panic_msg is not set
  2020-03-23 13:09 ` [PATCH V2 5/6] x86/Hyper-V: Report crash register data when sysctl_record_panic_msg is not set ltykernel
@ 2020-03-23 17:20   ` Michael Kelley
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Kelley @ 2020-03-23 17:20 UTC (permalink / raw)
  To: ltykernel, KY Srinivasan, Haiyang Zhang, Stephen Hemminger, Wei Liu
  Cc: Tianyu Lan, linux-hyperv, linux-kernel, vkuznets

From: Tianyu Lan <Tianyu.Lan@microsoft.com> Sent: Monday, March 23, 2020 6:09 AM
> 
> When sysctl_record_panic_msg is not set, kmsg will
> not be reported to Hyper-V. Crash register data should
> be reported via hyperv_report_panic() in such case.

Tweaking the wording:

When sysctl_record_panic_msg is not set, the panic will
not be reported to Hyper-V via hyperv_report_panic_msg().
So the crash should be reported via hyperv_report_panic().

> 
> Signed-off-by: Tianyu Lan <Tianyu.Lan@microsoft.com>
> ---
>  drivers/hv/vmbus_drv.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
> index d73fa8aa00a3..00447175c040 100644
> --- a/drivers/hv/vmbus_drv.c
> +++ b/drivers/hv/vmbus_drv.c
> @@ -48,6 +48,18 @@ static int hyperv_cpuhp_online;
> 
>  static void *hv_panic_page;
> 
> +/*
> + * Boolean to control whether to report panic messages over Hyper-V.
> + *
> + * It can be set via /proc/sys/kernel/hyperv/record_panic_msg
> + */
> +static int sysctl_record_panic_msg = 1;
> +
> +static int hyperv_report_reg(void)
> +{
> +	return !sysctl_record_panic_msg || !hv_panic_page;
> +}
> +
>  static int hyperv_panic_event(struct notifier_block *nb, unsigned long val,
>  			      void *args)
>  {
> @@ -60,7 +72,7 @@ static int hyperv_panic_event(struct notifier_block *nb, unsigned long
> val,
>  	 * message is available, just report kmsg to crash buffer.
>  	 */
>  	if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE
> -	    && !hv_panic_page) {
> +	    && hyperv_report_reg()) {
>  		regs = current_pt_regs();
>  		hyperv_report_panic(regs, val);
>  	}
> @@ -77,7 +89,7 @@ static int hyperv_die_event(struct notifier_block *nb, unsigned long
> val,
>  	 * Crash notify only can be triggered once. If crash notify
>  	 * message is available, just report kmsg to crash buffer.
>  	 */
> -	if (!hv_panic_page)
> +	if (hyperv_report_reg())
>  		hyperv_report_panic(regs, val);
>  	return NOTIFY_DONE;
>  }
> @@ -1265,13 +1277,6 @@ static void vmbus_isr(void)
>  	add_interrupt_randomness(HYPERVISOR_CALLBACK_VECTOR, 0);
>  }
> 
> -/*
> - * Boolean to control whether to report panic messages over Hyper-V.
> - *
> - * It can be set via /proc/sys/kernel/hyperv/record_panic_msg
> - */
> -static int sysctl_record_panic_msg = 1;
> -
>  /*
>   * Callback from kmsg_dump. Grab as much as possible from the end of the kmsg
>   * buffer and call into Hyper-V to transfer the data.
> --
> 2.14.5


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-03-23 17:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-23 13:09 [PATCH V2 0/6] x86/Hyper-V: Panic code path fixes ltykernel
2020-03-23 13:09 ` [PATCH V2 1/6] x86/Hyper-V: Unload vmbus channel in hv panic callback ltykernel
2020-03-23 17:11   ` Michael Kelley
2020-03-23 13:09 ` [PATCH V2 2/6] x86/Hyper-V: Free hv_panic_page when fail to register kmsg dump ltykernel
2020-03-23 13:09 ` [PATCH V2 3/6] x86/Hyper-V: Trigger crash enlightenment only once during system crash ltykernel
2020-03-23 17:15   ` Michael Kelley
2020-03-23 13:09 ` [PATCH V2 4/6] x86/Hyper-V: Report crash register data or ksmg before running crash kernel ltykernel
2020-03-23 17:16   ` Michael Kelley
2020-03-23 13:09 ` [PATCH V2 5/6] x86/Hyper-V: Report crash register data when sysctl_record_panic_msg is not set ltykernel
2020-03-23 17:20   ` Michael Kelley
2020-03-23 13:09 ` [PATCH V2 6/6] x86/Hyper-V: Report crash data in die() when panic_on_oops is set ltykernel

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).