Drivers: hv: fix kdump (again) and more
cover Drivers: hv: fix kdump (again) and more
Kdump on crash is reportedly broken for Hyper-V guests and I was able to find two reasons:
1) Inability to boot with nr_cpus=1 (PATCH 1)
2) Sleeping in interrupt context on crash (PATCH 2 and 3)
Vitaly Kuznetsov (3):
Drivers: hv: vmbus: avoid infinite loop in init_vp_index()
Drivers: hv: vmbus: avoid scheduling in interrupt context in
vmbus_initiate_unload()
Drivers: hv: vmbus: don't manipulate with clocksources on crash
drivers/hv/channel_mgmt.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++- drivers/hv/hv.c | 10 +++++++-- 2 files changed, 62 insertions(+), 3 deletions(-)
Signature · 1 line
2.5.0
PATCH 1/3 Drivers: hv: vmbus: avoid infinite loop in init_vp_index()
When we pick a CPU to use for a new subchannel we try find a non-used one on the appropriate NUMA node, we keep track of them with the primary->alloced_cpus_in_node mask. Under normal circumstances we don't run out of available CPUs but it is possible when we we don't initialize some cpus in Linux, e.g. when we boot with 'nr_cpus=' limitation.
Avoid the infinite loop in init_vp_index() by checking that we still have non-used CPUs in the alloced_cpus_in_node mask and resetting it in case we don't.
--- drivers/hv/channel_mgmt.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/hv/channel_mgmt.c +11 -0
@@ -469,6 +469,17 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui cpumask_of_node(primary->numa_node)); cur_cpu =-1 ; + +/* +* Normally Hyper-V host doesn't create more subchannels than there +* are VCPUs on the node but it is possible when not all present VCPUs +* on the node are initialized by guest. Clear the alloced_cpus_in_node +* to start over. +*/ +if (cpumask_equal (&primary->alloced_cpus_in_node, +cpumask_of_node (primary->numa_node))) +cpumask_clear (&primary->alloced_cpus_in_node); +while (true) { cur_cpu =cpumask_next (cur_cpu, &available_mask);if (cur_cpu >= nr_cpu_ids) {
Signature · 1 line
2.5.0
PATCH 3/3 Drivers: hv: vmbus: don't manipulate with clocksources on crash
In reply to Vitaly Kuznetsovclocksource_change_rating() involves mutex usage and can't be called in interrupt context. It also makes sense to avoid doing redundant work on crash.
--- drivers/hv/hv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/hv/hv.c +8 -2
@@ -295,8 +295,14 @@ void hv_cleanup(void)* Cleanup the TSC page based CS. */ if (ms_hyperv.features &HV_X64_MSR_REFERENCE_TSC_AVAILABLE ) { -clocksource_change_rating (&hyperv_cs_tsc,10 ); -clocksource_unregister (&hyperv_cs_tsc); +/* +* Crash can happen in an interrupt context and unregistering +* a clocksource is impossible and redundant in this case. +*/ +if (!oops_in_progress) { +clocksource_change_rating (&hyperv_cs_tsc,10 ); +clocksource_unregister (&hyperv_cs_tsc); + } hypercall_msr.as_uint64 =0 ;wrmsrl (HV_X64_MSR_REFERENCE_TSC , hypercall_msr.as_uint64);
Signature · 1 line
2.5.0
PATCH 2/3 Drivers: hv: vmbus: avoid scheduling in interrupt context in vmbus_initiate_unload()
In reply to Vitaly KuznetsovWe have to call vmbus_initiate_unload() on crash to make kdump work but the crash can also be happening in interrupt (e.g. Sysrq + c results in such) where we can't schedule or the following will happen:
[ 314.905786] bad: scheduling from the idle thread!
Just skipping the wait (and even adding some random wait here) won't help:
to make host-side magic working we're supposed to receive CHANNELMSG_UNLOAD (and actually confirm the fact that we received it) but we can't use interrupt-base path (vmbus_isr()-> vmbus_on_msg_dpc()). Implement a simple busy wait ignoring all the other messages and use it if we're in an interrupt context.
--- drivers/hv/channel_mgmt.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-)
drivers/hv/channel_mgmt.c +43 -1
@@ -28,6 +28,7 @@#include <linux/list.h> #include <linux/module.h> #include <linux/completion.h> +#include <linux/delay.h> #include <linux/hyperv.h> #include "hyperv_vmbus.h"
@@ -509,6 +510,40 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui channel->target_vp = hv_context.vp_index[cur_cpu]; } +static void vmbus_wait_for_unload (void ) +{ +int cpu =smp_processor_id (); +void *page_addr = hv_context.synic_message_page[cpu]; +struct hv_message *msg = (struct hv_message *)page_addr + +VMBUS_MESSAGE_SINT ; +struct vmbus_channel_message_header *hdr; +bool unloaded = false; + +while (1 ) { +if (msg->header.message_type ==HVMSG_NONE ) { +mdelay (10 ); +continue ; + } + + hdr = (struct vmbus_channel_message_header *)msg->u.payload; +if (hdr->msgtype ==CHANNELMSG_UNLOAD_RESPONSE ) + unloaded = true; + + msg->header.message_type =HVMSG_NONE ; +/* +* header.message_type needs to be written before we do +* wrmsrl() below. +*/ +mb (); + +if (msg->header.message_flags.msg_pending) +wrmsrl (HV_X64_MSR_EOM ,0 ); + +if (unloaded) +break ; + } +} +/* * vmbus_unload_response - Handler for the unload response. */
@@ -534,7 +569,14 @@ void vmbus_initiate_unload(void) hdr.msgtype =CHANNELMSG_UNLOAD ;vmbus_post_msg (&hdr,sizeof (struct vmbus_channel_message_header )); -wait_for_completion (&vmbus_connection.unload_event); +/* +* vmbus_initiate_unload() is also called on crash and the crash can be +* happening in an interrupt context, where scheduling is impossible. +*/ +if (!in_interrupt ()) +wait_for_completion (&vmbus_connection.unload_event); +else +vmbus_wait_for_unload (); }/*
Signature · 1 line
2.5.0