Commit 39d44ef9 authored by Vitaly Kuznetsov's avatar Vitaly Kuznetsov Committed by Tim Gardner

Drivers: hv: vmbus: handle various crash scenarios

BugLink: http://bugs.launchpad.net/bugs/1616677

Kdump keeps biting. Turns out CHANNELMSG_UNLOAD_RESPONSE is always
delivered to the CPU which was used for initial contact or to CPU0
depending on host version. vmbus_wait_for_unload() doesn't account for
the fact that in case we're crashing on some other CPU we won't get the
CHANNELMSG_UNLOAD_RESPONSE message and our wait on the current CPU will
never end.

Do the following:
1) Check for completion_done() in the loop. In case interrupt handler is
   still alive we'll get the confirmation we need.

2) Read message pages for all CPUs message page as we're unsure where
   CHANNELMSG_UNLOAD_RESPONSE is going to be delivered to. We can race with
   still-alive interrupt handler doing the same, add cmpxchg() to
   vmbus_signal_eom() to not lose CHANNELMSG_UNLOAD_RESPONSE message.

3) Cleanup message pages on all CPUs. This is required (at least for the
   current CPU as we're clearing CPU0 messages now but we may want to bring
   up additional CPUs on crash) as new messages won't be delivered till we
   consume what's pending. On boot we'll place message pages somewhere else
   and we won't be able to read stale messages.
Signed-off-by: default avatarVitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: default avatarK. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit cd95aad5)
Signed-off-by: default avatarTim Gardner <tim.gardner@canonical.com>
Acked-by: default avatarBrad Figg <brad.figg@canonical.com>
Acked-by: default avatarKamal Mostafa <kamal@canonical.com>
parent ad8537af
...@@ -597,27 +597,55 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type) ...@@ -597,27 +597,55 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type)
static void vmbus_wait_for_unload(void) static void vmbus_wait_for_unload(void)
{ {
int cpu = smp_processor_id(); int cpu;
void *page_addr = hv_context.synic_message_page[cpu]; void *page_addr;
struct hv_message *msg = (struct hv_message *)page_addr + struct hv_message *msg;
VMBUS_MESSAGE_SINT;
struct vmbus_channel_message_header *hdr; struct vmbus_channel_message_header *hdr;
bool unloaded = false; u32 message_type;
/*
* CHANNELMSG_UNLOAD_RESPONSE is always delivered to the CPU which was
* used for initial contact or to CPU0 depending on host version. When
* we're crashing on a different CPU let's hope that IRQ handler on
* the cpu which receives CHANNELMSG_UNLOAD_RESPONSE is still
* functional and vmbus_unload_response() will complete
* vmbus_connection.unload_event. If not, the last thing we can do is
* read message pages for all CPUs directly.
*/
while (1) { while (1) {
if (READ_ONCE(msg->header.message_type) == HVMSG_NONE) { if (completion_done(&vmbus_connection.unload_event))
mdelay(10); break;
for_each_online_cpu(cpu) {
page_addr = hv_context.synic_message_page[cpu];
msg = (struct hv_message *)page_addr +
VMBUS_MESSAGE_SINT;
message_type = READ_ONCE(msg->header.message_type);
if (message_type == HVMSG_NONE)
continue; continue;
}
hdr = (struct vmbus_channel_message_header *)msg->u.payload; hdr = (struct vmbus_channel_message_header *)
msg->u.payload;
if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE) if (hdr->msgtype == CHANNELMSG_UNLOAD_RESPONSE)
unloaded = true; complete(&vmbus_connection.unload_event);
vmbus_signal_eom(msg); vmbus_signal_eom(msg, message_type);
}
if (unloaded) mdelay(10);
break; }
/*
* We're crashing and already got the UNLOAD_RESPONSE, cleanup all
* maybe-pending messages on all CPUs to be able to receive new
* messages after we reconnect.
*/
for_each_online_cpu(cpu) {
page_addr = hv_context.synic_message_page[cpu];
msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT;
msg->header.message_type = HVMSG_NONE;
} }
} }
......
...@@ -625,9 +625,21 @@ extern struct vmbus_channel_message_table_entry ...@@ -625,9 +625,21 @@ extern struct vmbus_channel_message_table_entry
channel_message_table[CHANNELMSG_COUNT]; channel_message_table[CHANNELMSG_COUNT];
/* Free the message slot and signal end-of-message if required */ /* Free the message slot and signal end-of-message if required */
static inline void vmbus_signal_eom(struct hv_message *msg) static inline void vmbus_signal_eom(struct hv_message *msg, u32 old_msg_type)
{ {
msg->header.message_type = HVMSG_NONE; /*
* On crash we're reading some other CPU's message page and we need
* to be careful: this other CPU may already had cleared the header
* and the host may already had delivered some other message there.
* In case we blindly write msg->header.message_type we're going
* to lose it. We can still lose a message of the same type but
* we count on the fact that there can only be one
* CHANNELMSG_UNLOAD_RESPONSE and we don't care about other messages
* on crash.
*/
if (cmpxchg(&msg->header.message_type, old_msg_type,
HVMSG_NONE) != old_msg_type)
return;
/* /*
* Make sure the write to MessageType (ie set to * Make sure the write to MessageType (ie set to
......
...@@ -713,7 +713,7 @@ static void hv_process_timer_expiration(struct hv_message *msg, int cpu) ...@@ -713,7 +713,7 @@ static void hv_process_timer_expiration(struct hv_message *msg, int cpu)
if (dev->event_handler) if (dev->event_handler)
dev->event_handler(dev); dev->event_handler(dev);
vmbus_signal_eom(msg); vmbus_signal_eom(msg, HVMSG_TIMER_EXPIRED);
} }
void vmbus_on_msg_dpc(unsigned long data) void vmbus_on_msg_dpc(unsigned long data)
...@@ -725,8 +725,9 @@ void vmbus_on_msg_dpc(unsigned long data) ...@@ -725,8 +725,9 @@ void vmbus_on_msg_dpc(unsigned long data)
struct vmbus_channel_message_header *hdr; struct vmbus_channel_message_header *hdr;
struct vmbus_channel_message_table_entry *entry; struct vmbus_channel_message_table_entry *entry;
struct onmessage_work_context *ctx; struct onmessage_work_context *ctx;
u32 message_type = msg->header.message_type;
if (msg->header.message_type == HVMSG_NONE) if (message_type == HVMSG_NONE)
/* no msg */ /* no msg */
return; return;
...@@ -751,7 +752,7 @@ void vmbus_on_msg_dpc(unsigned long data) ...@@ -751,7 +752,7 @@ void vmbus_on_msg_dpc(unsigned long data)
entry->message_handler(hdr); entry->message_handler(hdr);
msg_handled: msg_handled:
vmbus_signal_eom(msg); vmbus_signal_eom(msg, message_type);
} }
static void vmbus_isr(void) static void vmbus_isr(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment