Drivers: hv: Some miscellaneous fixes
cover Drivers: hv: Some miscellaneous fixes
Some miscellaneous fixes. All these patches are being resent.
Vitaly Kuznetsov (5):
Drivers: hv: kvp: fix IP Failover
Drivers: hv: vmbus: handle various crash scenarios
Drivers: hv: balloon: don't crash when memory is added in non-sorted
order
Drivers: hv: balloon: reset host_specified_ha_region
tools: hv: lsvmbus: add pci pass-through UUID
drivers/hv/channel_mgmt.c | 58 +++++++++++++++++++++++++++++++++----------- drivers/hv/hv_balloon.c | 5 ++- drivers/hv/hv_kvp.c | 31 ++++++++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 21 ++++++++++++++- drivers/hv/vmbus_drv.c | 7 +++-- tools/hv/lsvmbus | 1 + 6 files changed, 101 insertions(+), 22 deletions(-)
Signature · 1 line
1.7.4.1
PATCH RESEND 1/5 Drivers: hv: kvp: fix IP Failover
From: Vitaly Kuznetsov <[email protected]>
Hyper-V VMs can be replicated to another hosts and there is a feature to set different IP for replicas, it is called 'Failover TCP/IP'. When such guest starts Hyper-V host sends it KVP_OP_SET_IP_INFO message as soon as we finish negotiation procedure. The problem is that it can happen (and it actually happens) before userspace daemon connects and we reply with HV_E_FAIL to the message. As there are no repetitions we fail to set the requested IP.
Solve the issue by postponing our reply to the negotiation message till userspace daemon is connected. We can't wait too long as there is a host-side timeout (cca. 75 seconds) and if we fail to reply in this time frame the whole KVP service will become inactive. The solution is not ideal - if it takes userspace daemon more than 60 seconds to connect IP Failover will still fail but I don't see a solution with our current separation between kernel and userspace parts.
Other two modules (VSS and FCOPY) don't require such delay, leave them untouched.
--- drivers/hv/hv_kvp.c | 31 +++++++++++++++++++++++++++++++ drivers/hv/hyperv_vmbus.h | 5 +++++ 2 files changed, 36 insertions(+), 0 deletions(-)
drivers/hv/hv_kvp.c +31 -0
@@ -78,9 +78,11 @@ static void kvp_send_key(struct work_struct *dummy);static void kvp_respond_to_host (struct hv_kvp_msg *msg,int error);static void kvp_timeout_func (struct work_struct *dummy); +static void kvp_host_handshake_func (struct work_struct *dummy);static void kvp_register (int ); static DECLARE_DELAYED_WORK(kvp_timeout_work, kvp_timeout_func); +static DECLARE_DELAYED_WORK(kvp_host_handshake_work, kvp_host_handshake_func); static DECLARE_WORK(kvp_sendkey_work, kvp_send_key);static const char kvp_devname[] ="vmbus/hv_kvp" ;
@@ -130,6 +132,11 @@ static void kvp_timeout_func(struct work_struct *dummy)hv_poll_channel (kvp_transaction.recv_channel, kvp_poll_wrapper); } +static void kvp_host_handshake_func (struct work_struct *dummy) +{ +hv_poll_channel (kvp_transaction.recv_channel, hv_kvp_onchannelcallback); +} +static int kvp_handle_handshake (struct hv_kvp_msg *msg) {switch (msg->kvp_hdr.operation) {
@@ -154,6 +161,12 @@ static int kvp_handle_handshake(struct hv_kvp_msg *msg)pr_debug ("KVP: userspace daemon ver. %d registered\n" ,KVP_OP_REGISTER );kvp_register (dm_reg_value); + +/* +* If we're still negotiating with the host cancel the timeout +* work to not poll the channel twice. +*/ +cancel_delayed_work_sync (&kvp_host_handshake_work);hv_poll_channel (kvp_transaction.recv_channel, kvp_poll_wrapper);return 0 ;
@@ -594,7 +607,22 @@ void hv_kvp_onchannelcallback(void *context)struct icmsg_negotiate *negop =NULL ;int util_fw_version;int kvp_srv_version; +static enum {NEGO_NOT_STARTED , +NEGO_IN_PROGRESS , +NEGO_FINISHED } host_negotiatied =NEGO_NOT_STARTED ; +if (host_negotiatied ==NEGO_NOT_STARTED && + kvp_transaction.state <HVUTIL_READY ) { +/* +* If userspace daemon is not connected and host is asking +* us to negotiate we need to delay to not lose messages. +* This is important for Failover IP setting. +*/ + host_negotiatied =NEGO_IN_PROGRESS ; +schedule_delayed_work (&kvp_host_handshake_work, +HV_UTIL_NEGO_TIMEOUT *HZ ); +return ; + }if (kvp_transaction.state >HVUTIL_READY )return ;
@@ -672,6 +700,8 @@ void hv_kvp_onchannelcallback(void *context)vmbus_sendpacket (channel, recv_buffer, recvlen, requestid,VM_PKT_DATA_INBAND ,0 ); + + host_negotiatied =NEGO_FINISHED ; } }
@@ -708,6 +738,7 @@ hv_kvp_init(struct hv_util_service *srv)void hv_kvp_deinit (void ) { kvp_transaction.state =HVUTIL_DEVICE_DYING ; +cancel_delayed_work_sync (&kvp_host_handshake_work);cancel_delayed_work_sync (&kvp_timeout_work);cancel_work_sync (&kvp_sendkey_work);hvutil_transport_destroy (hvt);
drivers/hv/hyperv_vmbus.h +5 -0
@@ -36,6 +36,11 @@#define HV_UTIL_TIMEOUT 30/* +* Timeout for guest-host handshake for services. +*/ +#define HV_UTIL_NEGO_TIMEOUT 60 + +/* * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent * is set by CPUID(HVCPUID_VERSION_FEATURES). */
Signature · 1 line
1.7.4.1
PATCH RESEND 2/5 Drivers: hv: vmbus: handle various crash scenarios
From: Vitaly Kuznetsov <[email protected]>
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.
--- drivers/hv/channel_mgmt.c | 58 +++++++++++++++++++++++++++++++++----------- drivers/hv/hyperv_vmbus.h | 16 +++++++++++- drivers/hv/vmbus_drv.c | 7 +++-- 3 files changed, 61 insertions(+), 20 deletions(-)
drivers/hv/channel_mgmt.c +43 -15
@@ -597,27 +597,55 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type)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 ; +int cpu; +void *page_addr; +struct hv_message *msg;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 ) { -if (READ_ONCE (msg->header.message_type) ==HVMSG_NONE ) { -mdelay (10 ); -continue ; - } +if (completion_done (&vmbus_connection.unload_event)) +break ; - hdr = (struct vmbus_channel_message_header *)msg->u.payload; -if (hdr->msgtype ==CHANNELMSG_UNLOAD_RESPONSE ) - unloaded = true; +for_each_online_cpu (cpu) { + page_addr = hv_context.synic_message_page[cpu]; + msg = (struct hv_message *)page_addr + +VMBUS_MESSAGE_SINT ; -vmbus_signal_eom (msg); + message_type =READ_ONCE (msg->header.message_type); +if (message_type ==HVMSG_NONE ) +continue ; -if (unloaded) -break ; + hdr = (struct vmbus_channel_message_header *) + msg->u.payload; + +if (hdr->msgtype ==CHANNELMSG_UNLOAD_RESPONSE ) +complete (&vmbus_connection.unload_event); + +vmbus_signal_eom (msg, message_type); + } + +mdelay (10 ); + } + +/* +* 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 ; } }
drivers/hv/hyperv_vmbus.h +14 -2
@@ -625,9 +625,21 @@ extern struct vmbus_channel_message_table_entry channel_message_table[CHANNELMSG_COUNT ];/* 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
drivers/hv/vmbus_drv.c +4 -3
@@ -712,7 +712,7 @@ static void hv_process_timer_expiration(struct hv_message *msg, int cpu)if (dev->event_handler) dev->event_handler (dev); -vmbus_signal_eom (msg); +vmbus_signal_eom (msg,HVMSG_TIMER_EXPIRED ); }void vmbus_on_msg_dpc (unsigned long data)
@@ -724,8 +724,9 @@ void vmbus_on_msg_dpc(unsigned long data)struct vmbus_channel_message_header *hdr;struct vmbus_channel_message_table_entry *entry;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 */ return ;
@@ -750,7 +751,7 @@ void vmbus_on_msg_dpc(unsigned long data) entry->message_handler (hdr); msg_handled: -vmbus_signal_eom (msg); +vmbus_signal_eom (msg, message_type); }static void vmbus_isr (void )
Signature · 1 line
1.7.4.1
PATCH RESEND 3/5 Drivers: hv: balloon: don't crash when memory is added in non-sorted order
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
When we iterate through all HA regions in handle_pg_range() we have an assumption that all these regions are sorted in the list and the 'start_pfn >= has->end_pfn' check is enough to find the proper region. Unfortunately it's not the case with WS2016 where host can hot-add regions in a different order. We end up modifying the wrong HA region and crashing later on pages online. Modify the check to make sure we found the region we were searching for while iterating. Fix the same check in pfn_covered() as well.
--- drivers/hv/hv_balloon.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv_balloon.c +2 -2
@@ -714,7 +714,7 @@ static bool pfn_covered(unsigned long start_pfn, unsigned long pfn_cnt)* If the pfn range we are dealing with is not in the current * "hot add block", move on. */ -if ((start_pfn >= has->end_pfn)) +if (start_pfn < has->start_pfn || start_pfn >= has->end_pfn)continue ;/* * If the current hot add-request extends beyond
@@ -768,7 +768,7 @@ static unsigned long handle_pg_range(unsigned long pg_start,* If the pfn range we are dealing with is not in the current * "hot add block", move on. */ -if ((start_pfn >= has->end_pfn)) +if (start_pfn < has->start_pfn || start_pfn >= has->end_pfn)continue ; old_covered_state = has->covered_end_pfn;
Signature · 1 line
1.7.4.1
PATCH RESEND 4/5 Drivers: hv: balloon: reset host_specified_ha_region
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
We set host_specified_ha_region = true on certain request but this is a global state which stays 'true' forever. We need to reset it when we receive a request where ha_region is not specified. I did not see any real issues, the bug was found by code inspection.
--- drivers/hv/hv_balloon.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/hv/hv_balloon.c +1 -0
@@ -1400,6 +1400,7 @@ static void balloon_onchannelcallback(void *context)* This is a normal hot-add request specifying * hot-add memory. */ + dm->host_specified_ha_region = false; ha_pg_range = &ha_msg->range; dm->ha_wrk.ha_page_range = *ha_pg_range; dm->ha_wrk.ha_region_range.page_range =0 ;
Signature · 1 line
1.7.4.1
PATCH RESEND 5/5 tools: hv: lsvmbus: add pci pass-through UUID
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
lsvmbus keeps its own copy of all VMBus UUIDs, add PCIe pass-through device there to not report 'Unknown' for such devices.
--- tools/hv/lsvmbus | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tools/hv/lsvmbus +1 -0
@@ -35,6 +35,7 @@ vmbus_dev_dict = { '{ba6163d9-04a1-4d29-b605-72e2ffb1dc7f}' : 'Synthetic SCSI Controller', '{2f9bcc4a-0069-4af3-b76b-6fd0be528cda}' : 'Synthetic fiber channel adapter', '{8c2eaf3d-32a7-4b09-ab99-bd1f1c86b501}' : 'Synthetic RDMA adapter', + '{44c4f61d-4444-4400-9d52-802e27ede19f}' : 'PCI Express pass-through', '{276aacf4-ac15-426c-98dd-7521ad3f01fe}' : '[Reserved system device]', '{f8e65716-3cb3-4a06-9a60-1889c5cccab5}' : '[Reserved system device]', '{3375baf4-9e15-4b30-b765-67acb10d607b}' : '[Reserved system device]',
Signature · 1 line
1.7.4.1