* [PATCH v3 1/5] Drivers: hv: vmbus: remove hv_synic_free_cpu() call from hv_synic_cleanup()
2015-06-25 9:58 [PATCH v3 0/5] Drivers: hv: add kexec support (and fix kdump) Vitaly Kuznetsov
@ 2015-06-25 9:58 ` Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 2/5] kexec: define kexec_in_progress in !CONFIG_KEXEC case Vitaly Kuznetsov
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-25 9:58 UTC (permalink / raw)
To: devel
Cc: linux-kernel, kexec, Eric Biederman, x86, H. Peter Anvin,
Ingo Molnar, Thomas Gleixner, Haiyang Zhang, K. Y. Srinivasan,
Olaf Hering, Greg KH
We already have hv_synic_free() which frees all per-cpu pages for all
CPUs, let's remove the hv_synic_free_cpu() call from hv_synic_cleanup()
so it will be possible to do separate cleanup (writing to MSRs) and final
freeing. This is going to be used to assist kexec.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
drivers/hv/hv.c | 2 --
drivers/hv/vmbus_drv.c | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index d3943bc..5b87042 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -530,6 +530,4 @@ void hv_synic_cleanup(void *arg)
rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
sctrl.enable = 0;
wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64);
-
- hv_synic_free_cpu(cpu);
}
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index cf20400..00d5158 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1120,6 +1120,7 @@ static void __exit vmbus_exit(void)
tasklet_kill(hv_context.event_dpc[cpu]);
smp_call_function_single(cpu, hv_synic_cleanup, NULL, 1);
}
+ hv_synic_free();
acpi_bus_unregister_driver(&vmbus_acpi_driver);
hv_cpu_hotplug_quirk(false);
}
--
2.4.2
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3 2/5] kexec: define kexec_in_progress in !CONFIG_KEXEC case
2015-06-25 9:58 [PATCH v3 0/5] Drivers: hv: add kexec support (and fix kdump) Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 1/5] Drivers: hv: vmbus: remove hv_synic_free_cpu() call from hv_synic_cleanup() Vitaly Kuznetsov
@ 2015-06-25 9:58 ` Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 3/5] Drivers: hv: vmbus: add special kexec handler Vitaly Kuznetsov
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-25 9:58 UTC (permalink / raw)
To: devel
Cc: linux-kernel, kexec, Eric Biederman, x86, H. Peter Anvin,
Ingo Molnar, Thomas Gleixner, Haiyang Zhang, K. Y. Srinivasan,
Olaf Hering, Greg KH
If some piece of code wants to check kexec_in_progress it has to be put
in #ifdef CONFIG_KEXEC block to not break the build in !CONFIG_KEXEC
case. Overcome this limitation by defining kexec_in_progress to false.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
include/linux/kexec.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/include/linux/kexec.h b/include/linux/kexec.h
index e804306..b63218f 100644
--- a/include/linux/kexec.h
+++ b/include/linux/kexec.h
@@ -323,6 +323,7 @@ struct pt_regs;
struct task_struct;
static inline void crash_kexec(struct pt_regs *regs) { }
static inline int kexec_should_crash(struct task_struct *p) { return 0; }
+#define kexec_in_progress false
#endif /* CONFIG_KEXEC */
#endif /* !defined(__ASSEBMLY__) */
--
2.4.2
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3 3/5] Drivers: hv: vmbus: add special kexec handler
2015-06-25 9:58 [PATCH v3 0/5] Drivers: hv: add kexec support (and fix kdump) Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 1/5] Drivers: hv: vmbus: remove hv_synic_free_cpu() call from hv_synic_cleanup() Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 2/5] kexec: define kexec_in_progress in !CONFIG_KEXEC case Vitaly Kuznetsov
@ 2015-06-25 9:58 ` Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 4/5] Drivers: hv: don't do hypercalls when hypercall_page is NULL Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 5/5] Drivers: hv: vmbus: add special crash handler Vitaly Kuznetsov
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-25 9:58 UTC (permalink / raw)
To: devel
Cc: linux-kernel, kexec, Eric Biederman, x86, H. Peter Anvin,
Ingo Molnar, Thomas Gleixner, Haiyang Zhang, K. Y. Srinivasan,
Olaf Hering, Greg KH
When general-purpose kexec (not kdump) is being performed in Hyper-V guest
the newly booted kernel fails with an MCE error coming from the host. It
is the same error which was fixed in the "Drivers: hv: vmbus: Implement
the protocol for tearing down vmbus state" commit - monitor pages remain
special and when they're being written to (as the new kernel doesn't know
these pages are special) bad things happen. We need to perform some
minimalistic cleanup before booting a new kernel on kexec. To do so we
need to register a special machine_ops.shutdown handler to be executed
before the native_machine_shutdown(). Registering a shutdown notification
handler via the register_reboot_notifier() call is not sufficient as it
happens to early for our purposes. machine_ops is not being exported to
modules (and I don't think we want to export it) so let's do this in
mshyperv.c
The minimalistic cleanup consists of cleaning up clockevents, synic MSRs,
guest os id MSR, and hypercall MSR.
Kdump doesn't require all this stuff as it lives in a separate memory
space.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
arch/x86/include/asm/mshyperv.h | 2 ++
arch/x86/kernel/cpu/mshyperv.c | 24 ++++++++++++++++++++++++
drivers/hv/vmbus_drv.c | 14 ++++++++++++++
3 files changed, 40 insertions(+)
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index c163215..d3db910 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -20,4 +20,6 @@ void hyperv_vector_handler(struct pt_regs *regs);
void hv_setup_vmbus_irq(void (*handler)(void));
void hv_remove_vmbus_irq(void);
+void hv_setup_kexec_handler(void (*handler)(void));
+void hv_remove_kexec_handler(void);
#endif
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 939155f..09911aa 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -18,6 +18,7 @@
#include <linux/efi.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
+#include <linux/kexec.h>
#include <asm/processor.h>
#include <asm/hypervisor.h>
#include <asm/hyperv.h>
@@ -28,10 +29,13 @@
#include <asm/i8259.h>
#include <asm/apic.h>
#include <asm/timer.h>
+#include <asm/reboot.h>
struct ms_hyperv_info ms_hyperv;
EXPORT_SYMBOL_GPL(ms_hyperv);
+static void (*hv_kexec_handler)(void);
+
#if IS_ENABLED(CONFIG_HYPERV)
static void (*vmbus_handler)(void);
@@ -69,8 +73,27 @@ void hv_remove_vmbus_irq(void)
}
EXPORT_SYMBOL_GPL(hv_setup_vmbus_irq);
EXPORT_SYMBOL_GPL(hv_remove_vmbus_irq);
+
+void hv_setup_kexec_handler(void (*handler)(void))
+{
+ hv_kexec_handler = handler;
+}
+EXPORT_SYMBOL_GPL(hv_setup_kexec_handler);
+
+void hv_remove_kexec_handler(void)
+{
+ hv_kexec_handler = NULL;
+}
+EXPORT_SYMBOL_GPL(hv_remove_kexec_handler);
#endif
+static void hv_machine_shutdown(void)
+{
+ if (kexec_in_progress && hv_kexec_handler)
+ hv_kexec_handler();
+ native_machine_shutdown();
+}
+
static uint32_t __init ms_hyperv_platform(void)
{
u32 eax;
@@ -143,6 +166,7 @@ static void __init ms_hyperv_init_platform(void)
no_timer_check = 1;
#endif
+ machine_ops.shutdown = hv_machine_shutdown;
}
const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 00d5158..31748a2 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1060,6 +1060,17 @@ static struct acpi_driver vmbus_acpi_driver = {
},
};
+static void hv_kexec_handler(void)
+{
+ int cpu;
+
+ hv_synic_clockevents_cleanup();
+ vmbus_initiate_unload();
+ for_each_online_cpu(cpu)
+ smp_call_function_single(cpu, hv_synic_cleanup, NULL, 1);
+ hv_cleanup();
+};
+
static int __init hv_acpi_init(void)
{
int ret, t;
@@ -1092,6 +1103,8 @@ static int __init hv_acpi_init(void)
if (ret)
goto cleanup;
+ hv_setup_kexec_handler(hv_kexec_handler);
+
return 0;
cleanup:
@@ -1104,6 +1117,7 @@ static void __exit vmbus_exit(void)
{
int cpu;
+ hv_remove_kexec_handler();
vmbus_connection.conn_state = DISCONNECTED;
hv_synic_clockevents_cleanup();
vmbus_disconnect();
--
2.4.2
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3 4/5] Drivers: hv: don't do hypercalls when hypercall_page is NULL
2015-06-25 9:58 [PATCH v3 0/5] Drivers: hv: add kexec support (and fix kdump) Vitaly Kuznetsov
` (2 preceding siblings ...)
2015-06-25 9:58 ` [PATCH v3 3/5] Drivers: hv: vmbus: add special kexec handler Vitaly Kuznetsov
@ 2015-06-25 9:58 ` Vitaly Kuznetsov
2015-06-25 9:58 ` [PATCH v3 5/5] Drivers: hv: vmbus: add special crash handler Vitaly Kuznetsov
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-25 9:58 UTC (permalink / raw)
To: devel
Cc: linux-kernel, kexec, Eric Biederman, x86, H. Peter Anvin,
Ingo Molnar, Thomas Gleixner, Haiyang Zhang, K. Y. Srinivasan,
Olaf Hering, Greg KH
At the very late stage of kexec a driver (which are not being unloaded) can
try to post a message or signal an event. This will crash the kernel as we
already did hv_cleanup() and the hypercall page is NULL.
Move all common (between 32 and 64 bit code) declarations to the beginning
of the do_hypercall() function. Unfortunately we have to write the
!hypercall_page check twice to not mix declarations and code.
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
drivers/hv/hv.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
index 5b87042..41d8072 100644
--- a/drivers/hv/hv.c
+++ b/drivers/hv/hv.c
@@ -93,11 +93,14 @@ static int query_hypervisor_info(void)
*/
static u64 do_hypercall(u64 control, void *input, void *output)
{
-#ifdef CONFIG_X86_64
- u64 hv_status = 0;
u64 input_address = (input) ? virt_to_phys(input) : 0;
u64 output_address = (output) ? virt_to_phys(output) : 0;
void *hypercall_page = hv_context.hypercall_page;
+#ifdef CONFIG_X86_64
+ u64 hv_status = 0;
+
+ if (!hypercall_page)
+ return (u64)ULLONG_MAX;
__asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8");
__asm__ __volatile__("call *%3" : "=a" (hv_status) :
@@ -112,13 +115,13 @@ static u64 do_hypercall(u64 control, void *input, void *output)
u32 control_lo = control & 0xFFFFFFFF;
u32 hv_status_hi = 1;
u32 hv_status_lo = 1;
- u64 input_address = (input) ? virt_to_phys(input) : 0;
u32 input_address_hi = input_address >> 32;
u32 input_address_lo = input_address & 0xFFFFFFFF;
- u64 output_address = (output) ? virt_to_phys(output) : 0;
u32 output_address_hi = output_address >> 32;
u32 output_address_lo = output_address & 0xFFFFFFFF;
- void *hypercall_page = hv_context.hypercall_page;
+
+ if (!hypercall_page)
+ return (u64)ULLONG_MAX;
__asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
"=a"(hv_status_lo) : "d" (control_hi),
--
2.4.2
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH v3 5/5] Drivers: hv: vmbus: add special crash handler
2015-06-25 9:58 [PATCH v3 0/5] Drivers: hv: add kexec support (and fix kdump) Vitaly Kuznetsov
` (3 preceding siblings ...)
2015-06-25 9:58 ` [PATCH v3 4/5] Drivers: hv: don't do hypercalls when hypercall_page is NULL Vitaly Kuznetsov
@ 2015-06-25 9:58 ` Vitaly Kuznetsov
4 siblings, 0 replies; 6+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-25 9:58 UTC (permalink / raw)
To: devel
Cc: linux-kernel, kexec, Eric Biederman, x86, H. Peter Anvin,
Ingo Molnar, Thomas Gleixner, Haiyang Zhang, K. Y. Srinivasan,
Olaf Hering, Greg KH
Full kernel hang is observed when kdump kernel starts after a crash. This
hang happens in vmbus_negotiate_version() function on
wait_for_completion() as Hyper-V host (Win2012R2 in my testing) never
responds to CHANNELMSG_INITIATE_CONTACT as it thinks the connection is
already established. We need to perform some mandatory minimalistic
cleanup before we start new kernel.
Reported-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
arch/x86/include/asm/mshyperv.h | 2 ++
arch/x86/kernel/cpu/mshyperv.c | 22 ++++++++++++++++++++++
drivers/hv/vmbus_drv.c | 14 ++++++++++++++
3 files changed, 38 insertions(+)
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index d3db910..d02f9c9 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -22,4 +22,6 @@ void hv_remove_vmbus_irq(void);
void hv_setup_kexec_handler(void (*handler)(void));
void hv_remove_kexec_handler(void);
+void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs));
+void hv_remove_crash_handler(void);
#endif
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 09911aa..1a6e742 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -35,6 +35,7 @@ struct ms_hyperv_info ms_hyperv;
EXPORT_SYMBOL_GPL(ms_hyperv);
static void (*hv_kexec_handler)(void);
+static void (*hv_crash_handler)(struct pt_regs *regs);
#if IS_ENABLED(CONFIG_HYPERV)
static void (*vmbus_handler)(void);
@@ -85,6 +86,18 @@ void hv_remove_kexec_handler(void)
hv_kexec_handler = NULL;
}
EXPORT_SYMBOL_GPL(hv_remove_kexec_handler);
+
+void hv_setup_crash_handler(void (*handler)(struct pt_regs *regs))
+{
+ hv_crash_handler = handler;
+}
+EXPORT_SYMBOL_GPL(hv_setup_crash_handler);
+
+void hv_remove_crash_handler(void)
+{
+ hv_crash_handler = NULL;
+}
+EXPORT_SYMBOL_GPL(hv_remove_crash_handler);
#endif
static void hv_machine_shutdown(void)
@@ -94,6 +107,14 @@ static void hv_machine_shutdown(void)
native_machine_shutdown();
}
+static void hv_machine_crash_shutdown(struct pt_regs *regs)
+{
+ if (hv_crash_handler)
+ hv_crash_handler(regs);
+ native_machine_crash_shutdown(regs);
+}
+
+
static uint32_t __init ms_hyperv_platform(void)
{
u32 eax;
@@ -167,6 +188,7 @@ static void __init ms_hyperv_init_platform(void)
#endif
machine_ops.shutdown = hv_machine_shutdown;
+ machine_ops.crash_shutdown = hv_machine_crash_shutdown;
}
const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
index 31748a2..1ed9b32 100644
--- a/drivers/hv/vmbus_drv.c
+++ b/drivers/hv/vmbus_drv.c
@@ -1071,6 +1071,18 @@ static void hv_kexec_handler(void)
hv_cleanup();
};
+static void hv_crash_handler(struct pt_regs *regs)
+{
+ vmbus_initiate_unload();
+ /*
+ * In crash handler we can't schedule synic cleanup for all CPUs,
+ * doing the cleanup for current CPU only. This should be sufficient
+ * for kdump.
+ */
+ hv_synic_cleanup(NULL);
+ hv_cleanup();
+};
+
static int __init hv_acpi_init(void)
{
int ret, t;
@@ -1104,6 +1116,7 @@ static int __init hv_acpi_init(void)
goto cleanup;
hv_setup_kexec_handler(hv_kexec_handler);
+ hv_setup_crash_handler(hv_crash_handler);
return 0;
@@ -1118,6 +1131,7 @@ static void __exit vmbus_exit(void)
int cpu;
hv_remove_kexec_handler();
+ hv_remove_crash_handler();
vmbus_connection.conn_state = DISCONNECTED;
hv_synic_clockevents_cleanup();
vmbus_disconnect();
--
2.4.2
^ permalink raw reply [flat|nested] 6+ messages in thread