Drivers: hv: vmbus: Enable kexec and other misc cleanup
Subsystems (3)
cover Drivers: hv: vmbus: Enable kexec and other misc cleanup
In addition to enabling kexec, this patch-set has a bunch of miscellaneous fixes.
Alex Ng (1):
Drivers: hv: balloon: Enable dynamic memory protocol negotiation with
Windows 10 hosts
K. Y. Srinivasan (1):
Drivers: hv: vmbus: Permit sending of packets without payload
Vitaly Kuznetsov (8):
Drivers: hv: vmbus: remove hv_synic_free_cpu() call from
hv_synic_cleanup()
kexec: define kexec_in_progress in !CONFIG_KEXEC case
Drivers: hv: vmbus: add special kexec handler
Drivers: hv: don't do hypercalls when hypercall_page is NULL
Drivers: hv: vmbus: add special crash handler
Drivers: hv: vmbus: prefer 'die' notification chain to 'panic'
Drivers: hv: kvp: check kzalloc return value
Drivers: hv: fcopy: dynamically allocate smsg_out in
fcopy_send_data()
arch/x86/include/asm/mshyperv.h | 4 ++ arch/x86/kernel/cpu/mshyperv.c | 46 ++++++++++++++++++++++++++ drivers/hv/channel.c | 4 ++- drivers/hv/hv.c | 15 ++++---- drivers/hv/hv_balloon.c | 26 +++++++++++--- drivers/hv/hv_fcopy.c | 21 +++++++---- drivers/hv/hv_kvp.c | 3 ++ drivers/hv/vmbus_drv.c | 69 ++++++++++++++++++++++++++++++++++++-- include/linux/kexec.h | 1 + 9 files changed, 163 insertions(+), 26 deletions(-)
Signature · 1 line
1.7.4.1
PATCH 1/10 Drivers: hv: vmbus: remove hv_synic_free_cpu() call from hv_synic_cleanup()
From: Vitaly Kuznetsov <[email protected]>
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.
--- drivers/hv/hv.c | 2 -- drivers/hv/vmbus_drv.c | 1 + 2 files changed, 1 insertions(+), 2 deletions(-)
drivers/hv/hv.c +0 -2
@@ -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); }
drivers/hv/vmbus_drv.c +1 -0
@@ -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); }
Signature · 1 line
1.7.4.1
PATCH 2/10 kexec: define kexec_in_progress in !CONFIG_KEXEC case
From: Vitaly Kuznetsov <[email protected]>
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.
--- include/linux/kexec.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/kexec.h +1 -0
@@ -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__) */
Signature · 1 line
1.7.4.1
PATCH 3/10 Drivers: hv: vmbus: add special kexec handler
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
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.
--- 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(+), 0 deletions(-)
arch/x86/include/asm/mshyperv.h +2 -0
@@ -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
arch/x86/kernel/cpu/mshyperv.c +24 -0
@@ -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 = {
drivers/hv/vmbus_drv.c +14 -0
@@ -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 ();
Signature · 1 line
1.7.4.1