Drivers: hv: vmbus: Miscellaneous fixes and enhancements
Subsystems (2)
v2 cover Drivers: hv: vmbus: Miscellaneous fixes and enhancements
Miscellaneous fixes and enhancements.
V2: Fixed a merge error in Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister()
Dexuan Cui (7):
Drivers: hv: vmbus: add a helper function to set a channel's pending
send size
Drivers: hv: vmbus: define the new offer type for Hyper-V socket
(hvsock)
Drivers: hv: vmbus: vmbus_sendpacket_ctl: hvsock: avoid unnecessary
signaling
Drivers: hv: vmbus: define a new VMBus message type for hvsock
Drivers: hv: vmbus: add a hvsock flag in struct hv_driver
Drivers: hv: vmbus: add a per-channel rescind callback
Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister()
K. Y. Srinivasan (2):
Drivers: hv: vmbus: Eliminate the spin lock on the read path
Drivers: hv: vmbus: Give control over how the ring access is
serialized
Kamal Mostafa (1):
tools/hv: Use include/uapi with __EXPORTED_HEADERS__
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.c | 36 ++++++++++++++-- drivers/hv/channel_mgmt.c | 102 ++++++++++++++++++++++++++++++++++++++++++-- drivers/hv/connection.c | 4 +- drivers/hv/hv.c | 10 ++++- drivers/hv/hyperv_vmbus.h | 2 +- drivers/hv/ring_buffer.c | 31 ++++++-------- drivers/hv/vmbus_drv.c | 4 ++ include/linux/hyperv.h | 67 +++++++++++++++++++++++++++++ tools/hv/Makefile | 2 + 9 files changed, 225 insertions(+), 33 deletions(-)
Signature · 1 line
1.7.4.1
PATCH v2 1/13 tools/hv: Use include/uapi with __EXPORTED_HEADERS__
From: Kamal Mostafa <[email protected]>
Use the local uapi headers to keep in sync with "recently" added #define's (e.g. VSS_OP_REGISTER1).
--- tools/hv/Makefile | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
tools/hv/Makefile +2 -0
@@ -5,6 +5,8 @@ PTHREAD_LIBS = -lpthread WARNINGS = -Wall -Wextra CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) $(shell getconf LFS_CFLAGS) +CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include + all: hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon %: %.c $(CC) $(CFLAGS) -o $@ $^
Signature · 1 line
1.7.4.1
PATCH v2 2/13 Drivers: hv: vmbus: avoid infinite loop in init_vp_index()
From: Vitaly Kuznetsov <[email protected]>
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 files changed, 11 insertions(+), 0 deletions(-)
drivers/hv/channel_mgmt.c +11 -0
@@ -549,6 +549,17 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type) 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
1.7.4.1
PATCH v2 3/13 Drivers: hv: vmbus: avoid scheduling in interrupt context in vmbus_initiate_unload()
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
We 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 files changed, 43 insertions(+), 1 deletions(-)
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"
@@ -589,6 +590,40 @@ static void init_vp_index(struct vmbus_channel *channel, u16 dev_type) 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. */
@@ -614,7 +649,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
1.7.4.1
PATCH v2 4/13 Drivers: hv: vmbus: don't manipulate with clocksources on crash
In reply to K. Y. SrinivasanFrom: Vitaly Kuznetsov <[email protected]>
clocksource_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 files 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
1.7.4.1
PATCH v2 5/13 Drivers: hv: vmbus: add a helper function to set a channel's pending send size
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
This will be used by the coming net/hvsock driver.
--- include/linux/hyperv.h | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/hyperv.h +6 -0
@@ -816,6 +816,12 @@ static inline void *get_per_channel_state(struct vmbus_channel *c)return c->per_channel_state; } +static inline void set_channel_pending_send_size (struct vmbus_channel *c, +u32 size) +{ + c->outbound.ring_buffer->pending_send_sz = size; +} +void vmbus_onmessage (void *context);int vmbus_request_offers (void );
Signature · 1 line
1.7.4.1
PATCH v2 6/13 Drivers: hv: vmbus: define the new offer type for Hyper-V socket (hvsock)
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
A helper function is also added.
--- include/linux/hyperv.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
include/linux/hyperv.h +7 -0
@@ -235,6 +235,7 @@ struct vmbus_channel_offer {#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100#define VMBUS_CHANNEL_PARENT_OFFER 0x200#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400 +#define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000struct vmpacket_descriptor {u16 type;
@@ -795,6 +796,12 @@ struct vmbus_channel {enum hv_signal_policy signal_policy; }; +static inline bool is_hvsock_channel (const struct vmbus_channel *c) +{ +return !!(c->offermsg.offer.chn_flags & +VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER ); +} +static inline void set_channel_signal_state (struct vmbus_channel *c,enum hv_signal_policy policy) {
Signature · 1 line
1.7.4.1
Greg KH
maintainerRe: [PATCH V2 06/13] Drivers: hv: vmbus: define the new offer type for Hyper-V socket (hvsock)
Quoted 15 lines · K. Y. Srinivasan
From: Dexuan Cui <[email protected]>
A helper function is also added.
Signed-off-by Dexuan Cui <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- include/linux/hyperv.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)include/linux/hyperv.h +0
-0
include/linux/hyperv.h struct vmbus_channel_offer { · line 238
Quoted 4 lines
include/linux/hyperv.h +1
-0@@ -235,6 +235,7 @@ struct vmbus_channel_offer {#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100#define VMBUS_CHANNEL_PARENT_OFFER 0x200#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400 +#define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000
In the future the BIT() macro might be good here...
Dexuan Cui
maintainerRE: [PATCH V2 06/13] Drivers: hv: vmbus: define the new offer type for Hyper-V socket (hvsock)
Quoted 20 lines
From: Greg KH [mailto:[email protected]]
Sent: Monday, February 8, 2016 13:34
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Dexuan Cui <[email protected]>
Subject: Re: [PATCH V2 06/13] Drivers: hv: vmbus: define the new offer type for Hyper-V socket (hvsock)Quoted 10 lines · K. Y. Srinivasan
From: Dexuan Cui <[email protected]>
A helper function is also added.
Signed-off-by Dexuan Cui <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- include/linux/hyperv.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
Quoted 11 lines
include/linux/hyperv.h struct vmbus_channel_offer { · line 238
Quoted 9 lines
include/linux/hyperv.h +1
-0@@ -235,6 +235,7 @@ struct vmbus_channel_offer {#define VMBUS_CHANNEL_LOOPBACK_OFFER 0x100#define VMBUS_CHANNEL_PARENT_OFFER 0x200#define VMBUS_CHANNEL_REQUEST_MONITORED_NOTIFICATION 0x400 +#define VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER 0x2000In the future the
BIT()macro might be good here...
Hi Greg,
Thanks for the reminder!
In the future, before introducing a new flag, we'll remember to make a clean-up patch to make these replaced with BIT(). :-)
Thanks,
-- Dexuan
PATCH v2 7/13 Drivers: hv: vmbus: vmbus_sendpacket_ctl: hvsock: avoid unnecessary signaling
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
When the hvsock channel's outbound ringbuffer is full (i.e., hv_ringbuffer_write() returns -EAGAIN), we should avoid the unnecessary signaling the host.
--- drivers/hv/channel.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/hv/channel.c +5 -1
@@ -659,6 +659,9 @@ int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer,* If we cannot write to the ring-buffer; signal the host * even if we may not have written anything. This is a rare * enough condition that it should not matter. +* NOTE: in this case, the hvsock channel is an exception, because +* it looks the host side's hvsock implementation has a throttling +* mechanism which can hurt the performance otherwise. */ if (channel->signal_policy)
@@ -666,7 +669,8 @@ int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer,else kick_q = true; -if (((ret ==0 ) && kick_q && signal) || (ret)) +if (((ret ==0 ) && kick_q && signal) || + (ret && !is_hvsock_channel (channel)))vmbus_setevent (channel);return ret;
Signature · 1 line
1.7.4.1
PATCH v2 8/13 Drivers: hv: vmbus: define a new VMBus message type for hvsock
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
A function to send the type of message is also added.
The coming net/hvsock driver will use this function to proactively request the host to offer a VMBus channel for a new hvsock connection.
--- drivers/hv/channel.c | 15 +++++++++++++++ drivers/hv/channel_mgmt.c | 4 ++++ include/linux/hyperv.h | 13 +++++++++++++ 3 files changed, 32 insertions(+), 0 deletions(-)
drivers/hv/channel.c +15 -0
@@ -219,6 +219,21 @@ error0: }EXPORT_SYMBOL_GPL (vmbus_open); +/* Used for Hyper-V Socket: a guest client's connect() to the host */ +int vmbus_send_tl_connect_request (const uuid_le *shv_guest_servie_id, +const uuid_le *shv_host_servie_id) +{ +struct vmbus_channel_tl_connect_request conn_msg; + +memset (&conn_msg,0 ,sizeof (conn_msg)); + conn_msg.header.msgtype =CHANNELMSG_TL_CONNECT_REQUEST ; + conn_msg.guest_endpoint_id = *shv_guest_servie_id; + conn_msg.host_service_id = *shv_host_servie_id; + +return vmbus_post_msg (&conn_msg,sizeof (conn_msg)); +} +EXPORT_SYMBOL_GPL (vmbus_send_tl_connect_request); +/* * create_gpadl_header - Creates a gpadl for the specified buffer */
drivers/hv/channel_mgmt.c +4 -0
@@ -958,6 +958,10 @@ struct vmbus_channel_message_table_entry {CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response}, {CHANNELMSG_UNLOAD, 0, NULL}, {CHANNELMSG_UNLOAD_RESPONSE, 1, vmbus_unload_response}, + {CHANNELMSG_18, 0, NULL}, + {CHANNELMSG_19, 0, NULL}, + {CHANNELMSG_20, 0, NULL}, + {CHANNELMSG_TL_CONNECT_REQUEST, 0, NULL}, };/*
include/linux/hyperv.h +13 -0
@@ -392,6 +392,10 @@ enum vmbus_channel_message_type {CHANNELMSG_VERSION_RESPONSE =15 ,CHANNELMSG_UNLOAD =16 ,CHANNELMSG_UNLOAD_RESPONSE =17 , +CHANNELMSG_18 =18 , +CHANNELMSG_19 =19 , +CHANNELMSG_20 =20 , +CHANNELMSG_TL_CONNECT_REQUEST =21 , CHANNELMSG_COUNT };
@@ -562,6 +566,13 @@ struct vmbus_channel_initiate_contact {u64 monitor_page2; } __packed; +/* Hyper-V socket: guest's connect()-ing to host */ +struct vmbus_channel_tl_connect_request { +struct vmbus_channel_message_header header; +uuid_le guest_endpoint_id; +uuid_le host_service_id; +} __packed; +struct vmbus_channel_version_response {struct vmbus_channel_message_header header;u8 version_supported;
@@ -1283,4 +1294,6 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid);extern __u32 vmbus_proto_version; +int vmbus_send_tl_connect_request (const uuid_le *shv_guest_servie_id, +const uuid_le *shv_host_servie_id);#endif /* _HYPERV_H */
Signature · 1 line
1.7.4.1
PATCH v2 9/13 Drivers: hv: vmbus: add a hvsock flag in struct hv_driver
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
Only the coming hv_sock driver has a "true" value for this flag.
We treat the hvsock offers/channels as special VMBus devices. Since the hv_sock driver handles all the hvsock offers/channels, we need to tweak vmbus_match() for hv_sock driver, so we introduce this flag.
--- drivers/hv/vmbus_drv.c | 4 ++++ include/linux/hyperv.h | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/hv/vmbus_drv.c +4 -0
@@ -582,6 +582,10 @@ static int vmbus_match(struct device *device, struct device_driver *driver)struct hv_driver *drv =drv_to_hv_drv (driver);struct hv_device *hv_dev =device_to_hv_device (device); +/* The hv_sock driver handles all hv_sock offers. */ +if (is_hvsock_channel (hv_dev->channel)) +return drv->hvsock; +if (hv_vmbus_get_id (drv->id_table, &hv_dev->dev_type))return 1 ;
include/linux/hyperv.h +14 -0
@@ -990,6 +990,20 @@ extern void vmbus_ontimer(unsigned long data);struct hv_driver {const char *name; +/* +* A hvsock offer, which has a VMBUS_CHANNEL_TLNPI_PROVIDER_OFFER +* channel flag, actually doesn't mean a synthetic device because the +* offer's if_type/if_instance can change for every new hvsock +* connection. +* +* However, to facilitate the notification of new-offer/rescind-offer +* from vmbus driver to hvsock driver, we can handle hvsock offer as +* a special vmbus device, and hence we need the below flag to +* indicate if the driver is the hvsock driver or not: we need to +* specially treat the hvosck offer & driver in vmbus_match(). +*/ +bool hvsock; +/* the device type supported by this driver */ uuid_le dev_type;const struct hv_vmbus_device_id *id_table;
Signature · 1 line
1.7.4.1
PATCH v2 10/13 Drivers: hv: vmbus: add a per-channel rescind callback
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
This will be used by the coming hv_sock driver.
--- drivers/hv/channel_mgmt.c | 11 +++++++++++ include/linux/hyperv.h | 9 +++++++++ 2 files changed, 20 insertions(+), 0 deletions(-)
drivers/hv/channel_mgmt.c +11 -0
@@ -741,6 +741,10 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)spin_unlock_irqrestore (&channel->lock, flags);if (channel->device_obj) { +if (channel->chn_rescind_callback) { + channel->chn_rescind_callback (channel); +return ; + }/* * We will have to unregister this device from the * driver core.
@@ -1110,3 +1114,10 @@ bool vmbus_are_subchannels_present(struct vmbus_channel *primary)return ret; }EXPORT_SYMBOL_GPL (vmbus_are_subchannels_present); + +void vmbus_set_chn_rescind_callback (struct vmbus_channel *channel, +void (*chn_rescind_cb)(struct vmbus_channel *)) +{ + channel->chn_rescind_callback = chn_rescind_cb; +} +EXPORT_SYMBOL_GPL (vmbus_set_chn_rescind_callback);
include/linux/hyperv.h +9 -0
@@ -766,6 +766,12 @@ struct vmbus_channel {void (*sc_creation_callback)(struct vmbus_channel *new_sc);/* +* Channel rescind callback. Some channels (the hvsock ones), need to +* register a callback which is invoked in vmbus_onoffer_rescind(). +*/ +void (*chn_rescind_callback)(struct vmbus_channel *channel); + +/* * The spinlock to protect the structure. It is being used to protect * test-and-set access to various attributes of the structure as well * as all sc_list operations.
@@ -851,6 +857,9 @@ int vmbus_request_offers(void);void vmbus_set_sc_create_callback (struct vmbus_channel *primary_channel,void (*sc_cr_cb)(struct vmbus_channel *new_sc)); +void vmbus_set_chn_rescind_callback (struct vmbus_channel *channel, +void (*chn_rescind_cb)(struct vmbus_channel *)); +/* * Retrieve the (sub) channel on which to send an outgoing request. * When a primary channel has multiple sub-channels, we choose a
Signature · 1 line
1.7.4.1
PATCH v2 11/13 Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister()
In reply to K. Y. SrinivasanFrom: Dexuan Cui <[email protected]>
The hvsock driver needs this API to release all the resources related to the channel.
--- drivers/hv/channel_mgmt.c | 33 ++++++++++++++++++++++++++++----- drivers/hv/connection.c | 4 ++-- include/linux/hyperv.h | 2 ++ 3 files changed, 32 insertions(+), 7 deletions(-)
drivers/hv/channel_mgmt.c +28 -5
@@ -310,6 +310,7 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)vmbus_release_relid (relid);BUG_ON (!channel->rescind); +BUG_ON (!mutex_is_locked (&vmbus_connection.channel_mutex));if (channel->target_cpu !=get_cpu ()) {put_cpu ();
@@ -321,9 +322,7 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid) }if (channel->primary_channel ==NULL ) { -mutex_lock (&vmbus_connection.channel_mutex);list_del (&channel->listentry); -mutex_unlock (&vmbus_connection.channel_mutex); primary_channel = channel; }else {
@@ -367,6 +366,7 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)bool fnew = true;unsigned long flags;u16 dev_type; +int ret;/* Make sure this is a new offer */ mutex_lock (&vmbus_connection.channel_mutex);
@@ -449,7 +449,11 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)* binding which eventually invokes the device driver's AddDevice() * method. */ -if (vmbus_device_register (newchannel->device_obj) !=0 ) { +mutex_lock (&vmbus_connection.channel_mutex); + ret =vmbus_device_register (newchannel->device_obj); +mutex_unlock (&vmbus_connection.channel_mutex); + +if (ret !=0 ) {pr_err ("unable to add child device object (relid %d)\n" , newchannel->offermsg.child_relid);kfree (newchannel->device_obj);
@@ -725,6 +729,8 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)struct device *dev; rescind = (struct vmbus_channel_rescind_offer *)hdr; + +mutex_lock (&vmbus_connection.channel_mutex); channel =relid2channel (rescind->child_relid);if (channel ==NULL ) {
@@ -733,7 +739,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)* vmbus_process_offer(), we have already invoked * vmbus_release_relid() on error. */ -return ; + goto out; }spin_lock_irqsave (&channel->lock, flags);
@@ -743,7 +749,7 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)if (channel->device_obj) {if (channel->chn_rescind_callback) { channel->chn_rescind_callback (channel); -return ; + goto out; }/* * We will have to unregister this device from the
@@ -758,8 +764,25 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)hv_process_channel_removal (channel, channel->offermsg.child_relid); } + +out: +mutex_unlock (&vmbus_connection.channel_mutex); } +void vmbus_hvsock_device_unregister (struct vmbus_channel *channel) +{ +mutex_lock (&vmbus_connection.channel_mutex); + +BUG_ON (!is_hvsock_channel (channel)); + + channel->rescind = true; +vmbus_device_unregister (channel->device_obj); + +mutex_unlock (&vmbus_connection.channel_mutex); +} +EXPORT_SYMBOL_GPL (vmbus_hvsock_device_unregister); + +/* * vmbus_onoffers_delivered - * This is invoked when all offers have been delivered.
drivers/hv/connection.c +2 -2
@@ -288,7 +288,8 @@ struct vmbus_channel *relid2channel(u32 relid)struct list_head *cur, *tmp;struct vmbus_channel *cur_sc; -mutex_lock (&vmbus_connection.channel_mutex); +BUG_ON (!mutex_is_locked (&vmbus_connection.channel_mutex)); +list_for_each_entry (channel, &vmbus_connection.chn_list, listentry) {if (channel->offermsg.child_relid == relid) { found_channel = channel;
@@ -307,7 +308,6 @@ struct vmbus_channel *relid2channel(u32 relid) } } } -mutex_unlock (&vmbus_connection.channel_mutex);return found_channel; }
include/linux/hyperv.h +2 -0
@@ -1069,6 +1069,8 @@ int __must_check __vmbus_driver_register(struct hv_driver *hv_driver, const char *mod_name);void vmbus_driver_unregister (struct hv_driver *hv_driver); +void vmbus_hvsock_device_unregister (struct vmbus_channel *channel); + int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj, resource_size_t min, resource_size_t max, resource_size_t size, resource_size_t align,
Signature · 1 line
1.7.4.1
PATCH v2 12/13 Drivers: hv: vmbus: Eliminate the spin lock on the read path
In reply to K. Y. SrinivasanThe function hv_ringbuffer_read() is called always on a pre-assigned CPU. Each chnnel is bound to a specific CPU and this function is always called on the CPU the channel is bound. There is no need to acquire the spin lock; get rid of this overhead.
--- drivers/hv/ring_buffer.c | 18 +++++------------- 1 files changed, 5 insertions(+), 13 deletions(-)
drivers/hv/ring_buffer.c +5 -13
@@ -388,7 +388,6 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,u32 bytes_avail_toread;u32 next_read_location =0 ;u64 prev_indices =0 ; -unsigned long flags;struct vmpacket_descriptor desc;u32 offset;u32 packetlen;
@@ -397,7 +396,6 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,if (buflen <=0 )return -EINVAL ; -spin_lock_irqsave (&inring_info->ring_lock, flags); *buffer_actual_len =0 ; *requestid =0 ;
@@ -412,7 +410,7 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info,* No error is set when there is even no header, drivers are * supposed to analyze buffer_actual_len. */ - goto out_unlock; +return ret; } next_read_location =hv_get_next_read_location (inring_info);
@@ -425,15 +423,11 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, *buffer_actual_len = packetlen; *requestid = desc.trans_id; -if (bytes_avail_toread < packetlen + offset) { - ret = -EAGAIN ; - goto out_unlock; - } +if (bytes_avail_toread < packetlen + offset) +return -EAGAIN ; -if (packetlen > buflen) { - ret = -ENOBUFS ; - goto out_unlock; - } +if (packetlen > buflen) +return -ENOBUFS ; next_read_location =hv_get_next_readlocation_withoffset (inring_info, offset);
@@ -460,7 +454,5 @@ int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, *signal =hv_need_to_signal_on_read (bytes_avail_towrite, inring_info); -out_unlock: -spin_unlock_irqrestore (&inring_info->ring_lock, flags);return ret; }
Signature · 1 line
1.7.4.1
PATCH v2 13/13 Drivers: hv: vmbus: Give control over how the ring access is serialized
In reply to K. Y. SrinivasanOn the channel send side, many of the VMBUS device drivers explicity serialize access to the outgoing ring buffer. Give more control to the VMBUS device drivers in terms how to serialize accesss to the outgoing ring buffer.
The default behavior will be to aquire the ring lock to preserve the current behavior.
--- drivers/hv/channel.c | 15 +++++++++++---- drivers/hv/channel_mgmt.c | 1 + drivers/hv/hyperv_vmbus.h | 2 +- drivers/hv/ring_buffer.c | 13 ++++++++----- include/linux/hyperv.h | 16 ++++++++++++++++ 5 files changed, 37 insertions(+), 10 deletions(-)
drivers/hv/channel.c +11 -4
@@ -639,6 +639,7 @@ int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer,u64 aligned_data =0 ;int ret;bool signal = false; +bool lock = channel->acquire_ring_lock;int num_vecs = ((bufferlen !=0 ) ?3 :1 );
@@ -658,7 +659,7 @@ int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer, bufferlist[2 ].iov_len = (packetlen_aligned - packetlen); ret =hv_ringbuffer_write (&channel->outbound, bufferlist, num_vecs, - &signal); + &signal, lock);/* * Signalling the host is conditional on many factors:
@@ -738,6 +739,7 @@ int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel,struct kvec bufferlist[3 ];u64 aligned_data =0 ;bool signal = false; +bool lock = channel->acquire_ring_lock;if (pagecount >MAX_PAGE_BUFFER_COUNT )return -EINVAL ;
@@ -774,7 +776,8 @@ int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel, bufferlist[2 ].iov_base = &aligned_data; bufferlist[2 ].iov_len = (packetlen_aligned - packetlen); - ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , &signal); + ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , + &signal, lock);/* * Signalling the host is conditional on many factors:
@@ -837,6 +840,7 @@ int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel,struct kvec bufferlist[3 ];u64 aligned_data =0 ;bool signal = false; +bool lock = channel->acquire_ring_lock; packetlen = desc_size + bufferlen; packetlen_aligned =ALIGN (packetlen,sizeof (u64));
@@ -856,7 +860,8 @@ int vmbus_sendpacket_mpb_desc(struct vmbus_channel *channel, bufferlist[2 ].iov_base = &aligned_data; bufferlist[2 ].iov_len = (packetlen_aligned - packetlen); - ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , &signal); + ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , + &signal, lock);if (ret ==0 && signal)vmbus_setevent (channel);
@@ -881,6 +886,7 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel,struct kvec bufferlist[3 ];u64 aligned_data =0 ;bool signal = false; +bool lock = channel->acquire_ring_lock;u32 pfncount =NUM_PAGES_SPANNED (multi_pagebuffer->offset, multi_pagebuffer->len);
@@ -919,7 +925,8 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, bufferlist[2 ].iov_base = &aligned_data; bufferlist[2 ].iov_len = (packetlen_aligned - packetlen); - ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , &signal); + ret =hv_ringbuffer_write (&channel->outbound, bufferlist,3 , + &signal, lock);if (ret ==0 && signal)vmbus_setevent (channel);
drivers/hv/channel_mgmt.c +1 -0
@@ -259,6 +259,7 @@ static struct vmbus_channel *alloc_channel(void)return NULL ; channel->id =atomic_inc_return (&chan_num); + channel->acquire_ring_lock = true;spin_lock_init (&channel->inbound_lock);spin_lock_init (&channel->lock);
drivers/hv/hyperv_vmbus.h +1 -1
@@ -531,7 +531,7 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info);int hv_ringbuffer_write (struct hv_ring_buffer_info *ring_info,struct kvec *kv_list, -u32 kv_count,bool *signal); +u32 kv_count,bool *signal,bool lock); int hv_ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer, u32 buflen, u32 *buffer_actual_len,
drivers/hv/ring_buffer.c +8 -5
@@ -314,7 +314,7 @@ void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info)/* Write to the ring buffer. */ int hv_ringbuffer_write (struct hv_ring_buffer_info *outring_info, -struct kvec *kv_list,u32 kv_count,bool *signal) +struct kvec *kv_list,u32 kv_count,bool *signal,bool lock) {int i =0 ;u32 bytes_avail_towrite;
@@ -324,14 +324,15 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info,u32 next_write_location;u32 old_write;u64 prev_indices =0 ; -unsigned long flags; +unsigned long flags =0 ;for (i =0 ; i < kv_count; i++) totalbytes_towrite += kv_list[i].iov_len; totalbytes_towrite +=sizeof (u64); -spin_lock_irqsave (&outring_info->ring_lock, flags); +if (lock) +spin_lock_irqsave (&outring_info->ring_lock, flags); hv_get_ringbuffer_availbytes(outring_info, &bytes_avail_toread,
@@ -343,7 +344,8 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info,* is empty since the read index == write index. */ if (bytes_avail_towrite <= totalbytes_towrite) { -spin_unlock_irqrestore (&outring_info->ring_lock, flags); +if (lock) +spin_unlock_irqrestore (&outring_info->ring_lock, flags);return -EAGAIN ; }
@@ -374,7 +376,8 @@ int hv_ringbuffer_write(struct hv_ring_buffer_info *outring_info,hv_set_next_write_location (outring_info, next_write_location); -spin_unlock_irqrestore (&outring_info->ring_lock, flags); +if (lock) +spin_unlock_irqrestore (&outring_info->ring_lock, flags); *signal =hv_need_to_signal (old_write, outring_info);return 0 ;
include/linux/hyperv.h +16 -0
@@ -811,8 +811,24 @@ struct vmbus_channel {* signaling control. */ enum hv_signal_policy signal_policy; +/* +* On the channel send side, many of the VMBUS +* device drivers explicity serialize access to the +* outgoing ring buffer. Give more control to the +* VMBUS device drivers in terms how to serialize +* accesss to the outgoing ring buffer. +* The default behavior will be to aquire the +* ring lock to preserve the current behavior. +*/ +bool acquire_ring_lock; + }; +static inline void set_channel_lock_state (struct vmbus_channel *c,bool state) +{ + c->acquire_ring_lock = state; +} +static inline bool is_hvsock_channel (const struct vmbus_channel *c) { return !!(c->offermsg.offer.chn_flags &
Signature · 1 line
1.7.4.1