Drivers: hv: CPU management fixes and a new uio driver
Subsystems (2)
cover Drivers: hv: CPU management fixes and a new uio driver
From: K. Y. Srinivasan <[email protected]>
Fixes to handle CPU online/offline. Also included is a new uio driver for Hyper-V.
Alex Fluter (1):
Tools: hv: kvp: configurable external scripts path
Haiyang Zhang (2):
hyperv: Add a function to detect hv_device
hyperv: Fix spelling of HV_UNKOWN
K. Y. Srinivasan (2):
Drivers: hv: vmbus: Prevent sending data on a rescinded channel
Drivers: hv: vmbus: Enhance the rescind callback functionality
Stephen Hemminger (2):
vmbus: add support for dynamic device id's
uio-hv-generic: new userspace i/o driver for VMBus
Vitaly Kuznetsov (8):
Drivers: hv: vmbus: Raise retry/wait limits in vmbus_post_msg()
hv: acquire vmbus_connection.channel_mutex in vmbus_free_channels()
hv: allocate synic pages for all present CPUs
hv: init percpu_list in hv_synic_alloc()
hv: change clockevents unbind tactics
hv: switch to cpuhp state machine for synic init/cleanup
hv: make CPU offlining prevention fine-grained
hv: don't reset hv_context.tsc_page on crash
MAINTAINERS | 1 + drivers/hv/channel.c | 17 ++-- drivers/hv/channel_mgmt.c | 29 ++++-- drivers/hv/connection.c | 18 +++- drivers/hv/hv.c | 65 ++++++++++--- drivers/hv/hyperv_vmbus.h | 6 +- drivers/hv/ring_buffer.c | 3 + drivers/hv/vmbus_drv.c | 208 ++++++++++++++++++++++++++++++++++++---- drivers/uio/Kconfig | 9 ++ drivers/uio/Makefile | 1 + drivers/uio/uio_hv_generic.c | 218 ++++++++++++++++++++++++++++++++++++++++++ include/linux/hyperv.h | 17 +++- tools/hv/hv_kvp_daemon.c | 11 ++- 13 files changed, 532 insertions(+), 71 deletions(-) create mode 100644 drivers/uio/uio_hv_generic.c
Signature · 1 line
1.7.4.1
PATCH 1/15 Drivers: hv: vmbus: Raise retry/wait limits in vmbus_post_msg()
From: Vitaly Kuznetsov <[email protected]>
DoS protection conditions were altered in WS2016 and now it's easy to get -EAGAIN returned from vmbus_post_msg() (e.g. when we try changing MTU on a netvsc device in a loop). All vmbus_post_msg() callers don't retry the operation and we usually end up with a non-functional device or crash.
While host's DoS protection conditions are unknown to me my tests show that it can take up to 10 seconds before the message is sent so doing udelay() is not an option, we really need to sleep. Almost all vmbus_post_msg() callers are ready to sleep but there is one special case:vmbus_initiate_unload() which can be called from interrupt/NMI context and we can't sleep there. I'm also not sure about the lonely vmbus_send_tl_connect_request() which has no in-tree users but its external users are most likely waiting for the host to reply so sleeping there is also appropriate.
--- drivers/hv/channel.c | 17 +++++++++-------- drivers/hv/channel_mgmt.c | 10 ++++++---- drivers/hv/connection.c | 17 ++++++++++++----- drivers/hv/hyperv_vmbus.h | 2 +- 4 files changed, 28 insertions(+), 18 deletions(-)
drivers/hv/channel.c +9 -8
@@ -181,7 +181,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size,spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags); ret =vmbus_post_msg (open_msg, -sizeof (struct vmbus_channel_open_channel )); +sizeof (struct vmbus_channel_open_channel ), true);if (ret !=0 ) { err = ret;
@@ -233,7 +233,7 @@ int vmbus_send_tl_connect_request(const uuid_le *shv_guest_servie_id, 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)); +return vmbus_post_msg (&conn_msg,sizeof (conn_msg), true); }EXPORT_SYMBOL_GPL (vmbus_send_tl_connect_request);
@@ -419,7 +419,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags); ret =vmbus_post_msg (gpadlmsg, msginfo->msgsize - -sizeof (*msginfo)); +sizeof (*msginfo), true);if (ret !=0 ) goto cleanup;
@@ -433,8 +433,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, gpadl_body->gpadl = next_gpadl_handle; ret =vmbus_post_msg (gpadl_body, - submsginfo->msgsize - -sizeof (*submsginfo)); + submsginfo->msgsize -sizeof (*submsginfo), + true);if (ret !=0 ) goto cleanup;
@@ -485,8 +485,8 @@ int vmbus_teardown_gpadl(struct vmbus_channel *channel, u32 gpadl_handle)list_add_tail (&info->msglistentry, &vmbus_connection.chn_msg_list);spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags); - ret =vmbus_post_msg (msg, -sizeof (struct vmbus_channel_gpadl_teardown )); + ret =vmbus_post_msg (msg,sizeof (struct vmbus_channel_gpadl_teardown ), + true);if (ret) goto post_msg_err;
@@ -557,7 +557,8 @@ static int vmbus_close_internal(struct vmbus_channel *channel) msg->header.msgtype =CHANNELMSG_CLOSECHANNEL ; msg->child_relid = channel->offermsg.child_relid; - ret =vmbus_post_msg (msg,sizeof (struct vmbus_channel_close_channel )); + ret =vmbus_post_msg (msg,sizeof (struct vmbus_channel_close_channel ), + true);if (ret) {pr_err ("Close failed: close post msg return is %d\n" , ret);
drivers/hv/channel_mgmt.c +6 -4
@@ -321,7 +321,8 @@ static void vmbus_release_relid(u32 relid)memset (&msg,0 ,sizeof (struct vmbus_channel_relid_released )); msg.child_relid = relid; msg.header.msgtype =CHANNELMSG_RELID_RELEASED ; -vmbus_post_msg (&msg,sizeof (struct vmbus_channel_relid_released )); +vmbus_post_msg (&msg,sizeof (struct vmbus_channel_relid_released ), + true); }void hv_event_tasklet_disable (struct vmbus_channel *channel)
@@ -726,7 +727,8 @@ void vmbus_initiate_unload(bool crash)init_completion (&vmbus_connection.unload_event);memset (&hdr,0 ,sizeof (struct vmbus_channel_message_header )); hdr.msgtype =CHANNELMSG_UNLOAD ; -vmbus_post_msg (&hdr,sizeof (struct vmbus_channel_message_header )); +vmbus_post_msg (&hdr,sizeof (struct vmbus_channel_message_header ), + !crash);/* * vmbus_initiate_unload() is also called on crash and the crash can be
@@ -1114,8 +1116,8 @@ int vmbus_request_offers(void) msg->msgtype =CHANNELMSG_REQUESTOFFERS ; - ret =vmbus_post_msg (msg, -sizeof (struct vmbus_channel_message_header )); + ret =vmbus_post_msg (msg,sizeof (struct vmbus_channel_message_header ), + true);if (ret !=0 ) {pr_err ("Unable to request offers - %d\n" , ret);
drivers/hv/connection.c +12 -5
@@ -110,7 +110,8 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,spin_unlock_irqrestore (&vmbus_connection.channelmsg_lock, flags); ret =vmbus_post_msg (msg, -sizeof (struct vmbus_channel_initiate_contact )); +sizeof (struct vmbus_channel_initiate_contact ), + true);if (ret !=0 ) {spin_lock_irqsave (&vmbus_connection.channelmsg_lock, flags);list_del (&msginfo->msglistentry);
@@ -434,7 +435,7 @@ void vmbus_on_event(unsigned long data)/* * vmbus_post_msg - Send a msg on the vmbus's message connection */ -int vmbus_post_msg (void *buffer,size_t buflen) +int vmbus_post_msg (void *buffer,size_t buflen,bool can_sleep) {union hv_connection_id conn_id;int ret =0 ;
@@ -449,7 +450,7 @@ int vmbus_post_msg(void *buffer, size_t buflen)* insufficient resources. Retry the operation a couple of * times before giving up. */ -while (retries <20 ) { +while (retries <100 ) { ret =hv_post_message (conn_id,1 , buffer, buflen);switch (ret) {
@@ -472,8 +473,14 @@ int vmbus_post_msg(void *buffer, size_t buflen) } retries++; -udelay (usec); -if (usec <2048 ) +if (can_sleep && usec >1000 ) +msleep (usec /1000 ); +else if (usec <MAX_UDELAY_MS *1000 ) +udelay (usec); +else +mdelay (usec /1000 ); + +if (usec <256000 ) usec *=2 ; }return ret;
drivers/hv/hyperv_vmbus.h +1 -1
@@ -683,7 +683,7 @@ struct hv_device *vmbus_device_create(const uuid_le *type,int vmbus_connect (void );void vmbus_disconnect (void ); -int vmbus_post_msg (void *buffer,size_t buflen); +int vmbus_post_msg (void *buffer,size_t buflen,bool can_sleep);void vmbus_on_event (unsigned long data);void vmbus_on_msg_dpc (unsigned long data);
Signature · 1 line
1.7.4.1
PATCH 2/15 hyperv: Add a function to detect hv_device
From: Haiyang Zhang <[email protected]>
--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)
drivers/hv/vmbus_drv.c +6 -0
@@ -692,6 +692,12 @@ struct onmessage_work_context {struct hv_message msg; }; +bool device_is_hyperv (struct device *dev) +{ +return dev->release == vmbus_device_release; +} +EXPORT_SYMBOL_GPL (device_is_hyperv); +static void vmbus_onmessage_work (struct work_struct *work) {struct onmessage_work_context *ctx;
include/linux/hyperv.h +2 -0
@@ -946,6 +946,8 @@ static inline void clear_low_latency_mode(struct vmbus_channel *c) c->low_latency = false; } +bool device_is_hyperv (struct device *dev); +void vmbus_onmessage (void *context);int vmbus_request_offers (void );
Signature · 1 line
1.7.4.1
Greg KH
maintainerRe: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 8 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)
I can't, and you shouldn't, take patches with no changelog comments at all.
sorry.
greg k-h
RE: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 23 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 12:34 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 8 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)
Quoted 4 lines
I can't, and you shouldn't, take patches with no changelog comments at all.
sorry.
Sorry about this; this will be fixed.
K. Y
Quoted 2 lines
greg k-h
Greg KH
maintainerRe: [PATCH 02/15] hyperv: Add a function to detect hv_device
In reply to [email protected]Quoted 14 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)drivers/hv/vmbus_drv.c +0
-0
drivers/hv/vmbus_drv.c struct onmessage_work_context { · line 699
Quoted 8 lines
drivers/hv/vmbus_drv.c +5
-0@@ -692,6 +692,12 @@ struct onmessage_work_context {struct hv_message msg; }; +bool device_is_hyperv (struct device *dev) +{ +return dev->release == vmbus_device_release; +} +EXPORT_SYMBOL_GPL (device_is_hyperv);
Wait, eek, no! That's NOT how you determine a device type, if you really even ever need to do that.
Why are you needing this? You should always "just know" what type of device a struct device * is, that's what we rely on in the driver model. Otherwise things get messy very very quickly.
Sorry, I can't take this without a ton of justification, and even then, you need to do this correctly (and no, I'm not going to tell you how to do that as I don't like it being done...)
greg k-h
Greg KH
maintainerRe: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 27 lines · Greg KH
Quoted 14 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)drivers/hv/vmbus_drv.c +0
-0drivers/hv/vmbus_drv.c struct onmessage_work_context { · line 699
Quoted 8 lines
drivers/hv/vmbus_drv.c +5
-0@@ -692,6 +692,12 @@ struct onmessage_work_context {struct hv_message msg; }; +bool device_is_hyperv (struct device *dev) +{ +return dev->release == vmbus_device_release; +} +EXPORT_SYMBOL_GPL (device_is_hyperv);Wait, eek, no! That's NOT how you determine a device type, if you really even ever need to do that.
Quoted 7 lines
Why are you needing this? You should always "just know" what type of device a struct device * is, that's what we rely on in the driver model. Otherwise things get messy very very quickly.
Sorry, I can't take this without a ton of justification, and even then, you need to do this correctly (and no, I'm not going to tell you how to do that as I don't like it being done...)
And, to make this even worse, you never use this function in this series, making this something that no one even needs!!!
ugh.
I'm dropping this whole series, sorry, get it together, this was a mess...
greg k-h
RE: [PATCH 02/15] hyperv: Add a function to detect hv_device
In reply to Greg KHQuoted 40 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 12:36 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 14 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)drivers/hv/vmbus_drv.c +0
-0drivers/hv/vmbus_drv.c struct onmessage_work_context { · line 699
Quoted 8 lines
drivers/hv/vmbus_drv.c +5
-0@@ -692,6 +692,12 @@ struct onmessage_work_context {struct hv_message msg; }; +bool device_is_hyperv (struct device *dev) +{ +return dev->release == vmbus_device_release; +} +EXPORT_SYMBOL_GPL (device_is_hyperv);Wait, eek, no! That's NOT how you determine a device type, if you really even ever need to do that.
Quoted 8 lines
Why are you needing this? You should always "just know" what type of device a struct device * is, that's what we rely on in the driver model. Otherwise things get messy very very quickly.
Sorry, I can't take this without a ton of justification, and even then, you need to do this correctly (and no, I'm not going to tell you how to do that as I don't like it being done...)
Greg,
To support SR-IOV, netvsc registers for all netdev events. For netdev events related to the VF interface, we need to do some special processing. And so, we need to determine if the device that is generating the netdev event is Hyper-V device or not (passed through the PCI pass through driver). Is this justification sufficient. As you have observed, currently there is no user of this API and that is because netvsc will be the user. To avoid cross-tree dependency, we wanted to get this functionality in first before submitting the netvsc patch.
Regards,
K. Y
Quoted 1 line
greg k-h
Greg KH
maintainerRe: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 11 lines · KY Srinivasan
Quoted 11 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 12:36 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_device
Ugh, please fix your email client...
Quoted 39 lines
Quoted 29 lines
Quoted 14 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)drivers/hv/vmbus_drv.c +0
-0drivers/hv/vmbus_drv.c struct onmessage_work_context { · line 699
Quoted 8 lines
drivers/hv/vmbus_drv.c +5
-0@@ -692,6 +692,12 @@ struct onmessage_work_context {struct hv_message msg; }; +bool device_is_hyperv (struct device *dev) +{ +return dev->release == vmbus_device_release; +} +EXPORT_SYMBOL_GPL (device_is_hyperv);Wait, eek, no! That's NOT how you determine a device type, if you really even ever need to do that.
Quoted 8 lines
Why are you needing this? You should always "just know" what type of device a struct device * is, that's what we rely on in the driver model. Otherwise things get messy very very quickly.
Sorry, I can't take this without a ton of justification, and even then, you need to do this correctly (and no, I'm not going to tell you how to do that as I don't like it being done...)
Greg,
Quoted 7 lines
To support SR-IOV, netvsc registers for all netdev events. For netdev events related to the VF interface, we need to do some special processing. And so, we need to determine if the device that is generating the netdev event is Hyper-V device or not (passed through the PCI pass through driver). Is this justification sufficient. As you have observed, currently there is no user of this API and that is because netvsc will be the user. To avoid cross-tree dependency, we wanted to get this functionality in first before submitting the netvsc patch.
See, you do have some text for a changelog!
{grumble...}
No, I don't think this is a good justification, where are you going to put this "check" into the networking stack? Your driver should only be binding to devices of this "type" anyway, so by that logic, it already "knows" that the device is of this type.
In other words, why do you need this and PCI or USB doesn't? Why is hyperv "special"?
greg k-h
RE: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 82 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 10:48 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 11 lines · KY Srinivasan
Quoted 11 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 12:36 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceUgh, please fix your email client...
Quoted 33 lines
Quoted 33 lines
Quoted 14 lines · On Thu, Dec 01, 2016 at 09:28:39AM -0800, [email protected] wrote:
From: Haiyang Zhang <[email protected]>
Signed-off-by Haiyang Zhang <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/vmbus_drv.c | 6 ++++++ include/linux/hyperv.h | 2 ++ 2 files changed, 8 insertions(+), 0 deletions(-)drivers/hv/vmbus_drv.c +0
-0drivers/hv/vmbus_drv.c struct onmessage_work_context { · line 699
Quoted 8 lines
drivers/hv/vmbus_drv.c +5
-0@@ -692,6 +692,12 @@ struct onmessage_work_context {struct hv_message msg; }; +bool device_is_hyperv (struct device *dev) +{ +return dev->release == vmbus_device_release; +} +EXPORT_SYMBOL_GPL (device_is_hyperv);Wait, eek, no! That's NOT how you determine a device type, if you really even ever need to do that.
Why are you needing this? You should always "just know" what type of device a struct device * is, that's what we rely on in the driver model. Otherwise things get messy very very quickly.
Quoted 7 lines
Quoted 4 lines
Sorry, I can't take this without a ton of justification, and even then, you need to do this correctly (and no, I'm not going to tell you how to do that as I don't like it being done...)
Greg,
To support SR-IOV, netvsc registers for all netdev events. For netdev
events related to the
Quoted 1 line
VF interface, we need to do some special processing. And so, we need to
determine
Quoted 3 lines
if the device that is generating the netdev event is Hyper-V device or not (passed through the PCI pass through driver). Is this justification sufficient. As you have observed, currently there is no user of this API and that is
because netvsc
Quoted 1 line
will be the user. To avoid cross-tree dependency, we wanted to get this
functionality in first
Quoted 1 line
before submitting the netvsc patch.
See, you do have some text for a changelog!
{grumble...}
Quoted 7 lines
No, I don't think this is a good justification, where are you going to put this "check" into the networking stack? Your driver should only be binding to devices of this "type" anyway, so by that logic, it already "knows" that the device is of this type.
In other words, why do you need this and PCI or USB doesn't? Why is hyperv "special"?
On Hyper-V, each VF interface (SR-IOV interface) is paired with an instance of the synthetic interface that is managed by netvsc. When the VF interface comes up, we
need to associate the VF instance with
the corresponding netvsc instance. To do this without modifying the VF drivers, netvsc registers for netdev events. In the netdev
event handler (in netvsc) currently I am doing the association based on the MAC address - this code is currently committed upstream (see drivers/net/hyperv/netvsc_drv.c netvsc_register_vf()). Going forward, we want to base this association based on a sequence number that the host publishes both for the VF as well as the corresponding
synthetic (netvsc) instance.
You are right, netvsc already knows that the devices it is managing belong to vmbus.
Since we are registering for netdev events,
we will get notified for devices that may not
be vmbus devices and that is where this new
API will be used. If the device is a vmbus device we can extract the sequence number to implement the match.
Regards,
K. Y
Greg KH
maintainerRe: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 11 lines · KY Srinivasan
Quoted 2 lines
In other words, why do you need this and PCI or USB doesn't? Why is hyperv "special"?
On Hyper-V, each VF interface (SR-IOV interface) is paired with an instance of the synthetic interface that is managed by netvsc. When the VF interface comes up, we
need to associate the VF instance with
the corresponding netvsc instance. To do this without modifying the VF drivers, netvsc registers for netdev events.
Why not modify the VF drivers? You have the full source to them...
RE: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 25 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 11:36 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 11 lines · KY Srinivasan
Quoted 2 lines
In other words, why do you need this and PCI or USB doesn't? Why is hyperv "special"?
On Hyper-V, each VF interface (SR-IOV interface) is paired with an instance of the synthetic interface that is managed by netvsc. When the VF interface comes up, we
need to associate the VF instance with
the corresponding netvsc instance. To do this without modifying the VF drivers, netvsc registers for netdev events.
Quoted 1 line
Why not modify the VF drivers? You have the full source to them...
Greg,
This is even worse. On Linux, VF drivers are hypervisor agnostic and I want to keep it that way.
Regards,
K. Y
Greg KH
maintainerRe: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 25 lines · KY Srinivasan
Quoted 25 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 11:36 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 11 lines · KY Srinivasan
Quoted 2 lines
In other words, why do you need this and PCI or USB doesn't? Why is hyperv "special"?
On Hyper-V, each VF interface (SR-IOV interface) is paired with an instance of the synthetic interface that is managed by netvsc. When the VF interface comes up, we
need to associate the VF instance with
the corresponding netvsc instance. To do this without modifying the VF drivers, netvsc registers for netdev events.
Quoted 5 lines
Quoted 1 line
Why not modify the VF drivers? You have the full source to them...
Greg,
This is even worse. On Linux, VF drivers are hypervisor agnostic and I want to keep it that way.
Ok, I really don't know what to suggest, other than this is probably not the way to do this as no other bus has to. As I don't see the code that actually uses this anywhere, it's really impossible to have this conversation at all :(
greg k-h
RE: [PATCH 02/15] hyperv: Add a function to detect hv_device
Quoted 41 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Friday, December 2, 2016 8:03 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; Haiyang Zhang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 28 lines · KY Srinivasan
Quoted 25 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 11:36 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Haiyang Zhang <[email protected]>
Subject: Re: [PATCH 02/15] hyperv: Add a function to detecthv_deviceQuoted 11 lines · KY Srinivasan
Quoted 2 lines
In other words, why do you need this and PCI or USB doesn't? Why is hyperv "special"?
On Hyper-V, each VF interface (SR-IOV interface) is paired with an instance of the synthetic interface that is managed by netvsc. When the VF interface comes up, we
need to associate the VF instance with
the corresponding netvsc instance. To do this without modifying the VF drivers, netvsc registers for netdev events.Quoted 1 line
Why not modify the VF drivers? You have the full source to them...
Greg,
Quoted 7 lines
Quoted 2 lines
This is even worse. On Linux, VF drivers are hypervisor agnostic and I want to keep it that way.
Ok, I really don't know what to suggest, other than this is probably not the way to do this as no other bus has to. As I don't see the code that actually uses this anywhere, it's really impossible to have this conversation at all :(
I agree it is difficult to discuss this without
having the code that uses this.
That said, there is currently code in
the tree that disambiguates the netdev
events that netvsc sees - look at the function get_netvsc_bymac(). This function allows us to
associate the VF interface that maybe coming up with the associated netvsc interface using MAC address. What I want to do is to not use the MAC address but to use a serial number that the host publishes. I could send the netvsc patches that use this if that would help here. In any case once we have this functionality, we will be submitting the patches that use this.
What I am trying to do here is to implement the equivalent of dev_is_pci() for vmbus.
You also had concerns about how we were implementing this functionality. We could certainly use the same mechanism used in dev_is_pci(). Perhaps I could also use the same naming convention - dev_is_hv()?
Regards,
K. Y
Quoted 2 lines
greg k-h
PATCH 3/15 hyperv: Fix spelling of HV_UNKOWN
In reply to [email protected]From: Haiyang Zhang <[email protected]>
Changed it to HV_UNKNOWN
--- drivers/hv/channel_mgmt.c | 6 +++--- include/linux/hyperv.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/hv/channel_mgmt.c +3 -3
@@ -134,7 +134,7 @@ },/* Unknown GUID */ - { .dev_type = HV_UNKOWN, + { .dev_type = HV_UNKNOWN, .perf_device = false, }, };
@@ -163,9 +163,9 @@ static u16 hv_get_dev_type(const struct vmbus_channel *channel)u16 i;if (is_hvsock_channel (channel) ||is_unsupported_vmbus_devs (guid)) -return HV_UNKOWN ; +return HV_UNKNOWN ; -for (i =HV_IDE ; i <HV_UNKOWN ; i++) { +for (i =HV_IDE ; i <HV_UNKNOWN ; i++) {if (!uuid_le_cmp (*guid, vmbus_devs[i].guid))return i; }
include/linux/hyperv.h +1 -1
@@ -696,7 +696,7 @@ enum vmbus_device_type {HV_FCOPY ,HV_BACKUP ,HV_DM , - HV_UNKOWN, + HV_UNKNOWN, }; struct vmbus_device {
Signature · 1 line
1.7.4.1
PATCH 4/15 Drivers: hv: vmbus: Prevent sending data on a rescinded channel
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
After the channel is rescinded, the host does not read from the rescinded channel. Fail writes to a channel that has already been rescinded
--- drivers/hv/ring_buffer.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
drivers/hv/ring_buffer.c +3 -0
@@ -298,6 +298,9 @@ int hv_ringbuffer_write(struct vmbus_channel *channel,unsigned long flags =0 ;struct hv_ring_buffer_info *outring_info = &channel->outbound; +if (channel->rescind) +return -ENODEV ; +for (i =0 ; i < kv_count; i++) totalbytes_towrite += kv_list[i].iov_len;
Signature · 1 line
1.7.4.1
Greg KH
maintainerRe: [PATCH 04/15] Drivers: hv: vmbus: Prevent sending data on a rescinded channel
Quoted 5 lines · On Thu, Dec 01, 2016 at 09:28:41AM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
After the channel is rescinded, the host does not read from the rescinded channel. Fail writes to a channel that has already been rescinded
Signed-off-by K. Y. Srinivasan <[email protected]>
{sigh}
What's wrong with this picture...
Re: [PATCH 04/15] Drivers: hv: vmbus: Prevent sending data on a rescinded channel
In reply to [email protected]Quoted 4 lines · On Thu, Dec 01, 2016 at 09:28:41AM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
After the channel is rescinded, the host does not read from the rescinded channel. Fail writes to a channel that has already been rescinded
What are the user visible effects of this bug? Presumably none right since it doesn't need to be back ported.
But it's absolutely impossible to tell from the commit message.
regards,
dan carpenter
RE: [PATCH 04/15] Drivers: hv: vmbus: Prevent sending data on a rescinded channel
Quoted 17 lines
-----Original Message-----
From: Dan Carpenter [mailto:[email protected]]
Sent: Monday, December 5, 2016 2:01 AM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 04/15] Drivers: hv: vmbus: Prevent sending data on a rescinded channelQuoted 2 lines · On Thu, Dec 01, 2016 at 09:28:41AM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
Quoted 8 lines
Quoted 1 line
After the channel is rescinded, the host does not read from the rescinded
channel.
Quoted 1 line
Fail writes to a channel that has already been rescinded
What are the user visible effects of this bug? Presumably none right since it doesn't need to be back ported.
But it's absolutely impossible to tell from the commit message.
Thanks Dan. I will update the commit log and resend.
K. Y
Quoted 3 lines
regards,
dan carpenter
PATCH 5/15 Drivers: hv: vmbus: Enhance the rescind callback functionality
In reply to [email protected]From: K. Y. Srinivasan <[email protected]>
--- drivers/hv/channel_mgmt.c | 11 +++++++---- include/linux/hyperv.h | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-)
drivers/hv/channel_mgmt.c +7 -4
@@ -825,8 +825,10 @@ 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); - goto out; + channel->chn_rescind_callback (channel, + channel->rescind_arg); +if (is_hvsock_channel (channel)) + goto out; }/* * We will have to unregister this device from the
@@ -1215,9 +1217,10 @@ bool vmbus_are_subchannels_present(struct vmbus_channel *primary) }EXPORT_SYMBOL_GPL (vmbus_are_subchannels_present); -void vmbus_set_chn_rescind_callback (struct vmbus_channel *channel, -void (*chn_rescind_cb)(struct vmbus_channel *)) +void vmbus_set_chn_rescind_callback (struct vmbus_channel *channel,void *arg, +void (*chn_rescind_cb)(struct vmbus_channel *,void *)) { channel->chn_rescind_callback = chn_rescind_cb; + channel->rescind_arg = arg; }EXPORT_SYMBOL_GPL (vmbus_set_chn_rescind_callback);
include/linux/hyperv.h +4 -3
@@ -800,7 +800,8 @@ struct vmbus_channel {* 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); +void (*chn_rescind_callback)(struct vmbus_channel *channel,void *arg); +void *rescind_arg;/* * The spinlock to protect the structure. It is being used to protect
@@ -959,8 +960,8 @@ static inline void clear_low_latency_mode(struct vmbus_channel *c)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 *)); +void vmbus_set_chn_rescind_callback (struct vmbus_channel *channel,void *arg, +void (*chn_rescind_cb)(struct vmbus_channel *,void *));/* * Retrieve the (sub) channel on which to send an outgoing request.
Signature · 1 line
1.7.4.1
Greg KH
maintainerRe: [PATCH 05/15] Drivers: hv: vmbus: Enhance the rescind callback functionality
Quoted 7 lines · On Thu, Dec 01, 2016 at 09:28:42AM -0800, [email protected] wrote:
From: K. Y. Srinivasan <[email protected]>
Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/channel_mgmt.c | 11 +++++++---- include/linux/hyperv.h | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-)
no commit log == will not be committed
PATCH 6/15 hv: acquire vmbus_connection.channel_mutex in vmbus_free_channels()
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
"kernel BUG at drivers/hv/channel_mgmt.c:350!" is observed when hv_vmbus module is unloaded. BUG_ON() was introduced in commit 85d9aa705184 ("Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister()") as vmbus_free_channels() codepath was apparently forgotten.
--- drivers/hv/channel_mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
drivers/hv/channel_mgmt.c +2 -0
@@ -390,6 +390,7 @@ void vmbus_free_channels(void) {struct vmbus_channel *channel, *tmp; +mutex_lock (&vmbus_connection.channel_mutex);list_for_each_entry_safe (channel, tmp, &vmbus_connection.chn_list, listentry) {/* hv_process_channel_removal() needs this */
@@ -397,6 +398,7 @@ void vmbus_free_channels(void)vmbus_device_unregister (channel->device_obj); } +mutex_unlock (&vmbus_connection.channel_mutex); }/*
Signature · 1 line
1.7.4.1
Greg KH
maintainerRe: [PATCH 06/15] hv: acquire vmbus_connection.channel_mutex in vmbus_free_channels()
Quoted 7 lines · On Thu, Dec 01, 2016 at 09:28:43AM -0800, [email protected] wrote:
From: Vitaly Kuznetsov <[email protected]>
"kernel BUG at
drivers/hv/channel_mgmt.c:350!" is observed whenhv_vmbusmodule is unloaded.BUG_ON()was introduced in commit85d9aa705184("Drivers: hv: vmbus: add an APIvmbus_hvsock_device_unregister()") asvmbus_free_channels()codepath was apparently forgotten.
Quoted 6 lines
Fixes 85d9aa705184 ("Drivers: hv: vmbus: add an API vmbus_hvsock_device_unregister()")Signed-off-by Vitaly Kuznetsov <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/channel_mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
Shouldn't this go to stable kernels?
RE: [PATCH 06/15] hv: acquire vmbus_connection.channel_mutex in vmbus_free_channels()
Quoted 23 lines
-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Thursday, December 1, 2016 12:37 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 06/15] hv: acquire vmbus_connection.channel_mutex invmbus_free_channels()Quoted 3 lines · On Thu, Dec 01, 2016 at 09:28:43AM -0800, [email protected] wrote:
From: Vitaly Kuznetsov <[email protected]>
"kernel BUG at
drivers/hv/channel_mgmt.c:350!" is observed when
hv_vmbusQuoted 5 lines
module is unloaded.
BUG_ON()was introduced in commit85d9aa705184("Drivers: hv: vmbus: add an APIvmbus_hvsock_device_unregister()") asvmbus_free_channels()codepath was apparently forgotten.Fixes 85d9aa705184 ("Drivers: hv: vmbus: add an API
Quoted 8 lines
vmbus_hvsock_device_unregister()")Quoted 5 lines
Signed-off-by Vitaly Kuznetsov <[email protected]>Signed-off-by K. Y. Srinivasan <[email protected]>--- drivers/hv/channel_mgmt.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)Shouldn't this go to stable kernels?
Yes; I will resubmit.
Regards,
K. Y
PATCH 7/15 hv: allocate synic pages for all present CPUs
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
It may happen that not all CPUs are online when we do hv_synic_alloc() and in case more CPUs come online later we may try accessing these allocated structures.
--- drivers/hv/hv.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv.c +2 -2
@@ -411,7 +411,7 @@ int hv_synic_alloc(void) goto err; } -for_each_online_cpu (cpu) { +for_each_present_cpu (cpu) { hv_context.event_dpc[cpu] =kmalloc (size,GFP_ATOMIC );if (hv_context.event_dpc[cpu] ==NULL ) {pr_err ("Unable to allocate event dpc\n" );
@@ -482,7 +482,7 @@ void hv_synic_free(void)int cpu;kfree (hv_context.hv_numa_map); -for_each_online_cpu (cpu) +for_each_present_cpu (cpu)hv_synic_free_cpu (cpu); }
Signature · 1 line
1.7.4.1
PATCH 8/15 hv: init percpu_list in hv_synic_alloc()
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
Initializing hv_context.percpu_list in hv_synic_alloc() helps to prevent a crash in percpu_channel_enq() when not all CPUs were online during initialization and it naturally belongs there.
--- drivers/hv/hv.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv.c +2 -2
@@ -457,6 +457,8 @@ int hv_synic_alloc(void)pr_err ("Unable to allocate post msg page\n" ); goto err; } + +INIT_LIST_HEAD (&hv_context.percpu_list[cpu]); }return 0 ;
@@ -552,8 +554,6 @@ void hv_synic_init(void *arg)rdmsrl (HV_X64_MSR_VP_INDEX , vp_index); hv_context.vp_index[cpu] = (u32 )vp_index; -INIT_LIST_HEAD (&hv_context.percpu_list[cpu]); -/* * Register the per-cpu clockevent source. */
Signature · 1 line
1.7.4.1
PATCH 9/15 hv: change clockevents unbind tactics
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
To get prepared to CPU offlining support we need co change the way how we unbind clockevent devices. As one CPU may go online/offline multiple times we need to bind it in hv_synic_init() and unbind it in hv_synic_cleanup(). There is an additional corner case: when we unload the module completely we need to switch to some other clockevent mechanism before stopping VMBus or we will hang. We can't call hv_synic_cleanup() before unloading VMBus as we won't be able to send UNLOAD request and get a response so hv_synic_clockevents_cleanup() has to live. Luckily, we can always call clockevents_unbind_device(), even if it wasn't bound before and there is no issue if we call it twice.
--- drivers/hv/hv.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
drivers/hv/hv.c +4 -2
@@ -575,7 +575,7 @@ void hv_synic_clockevents_cleanup(void)if (!(ms_hyperv.features &HV_X64_MSR_SYNTIMER_AVAILABLE ))return ; -for_each_online_cpu (cpu) +for_each_present_cpu (cpu)clockevents_unbind_device (hv_context.clk_evt[cpu], cpu); }
@@ -594,8 +594,10 @@ void hv_synic_cleanup(void *arg)return ;/* Turn off clockevent device */ -if (ms_hyperv.features &HV_X64_MSR_SYNTIMER_AVAILABLE ) +if (ms_hyperv.features &HV_X64_MSR_SYNTIMER_AVAILABLE ) { +clockevents_unbind_device (hv_context.clk_evt[cpu], cpu);hv_ce_shutdown (hv_context.clk_evt[cpu]); + }rdmsrl (HV_X64_MSR_SINT0 +VMBUS_MESSAGE_SINT , shared_sint.as_uint64);
Signature · 1 line
1.7.4.1
PATCH 10/15 hv: switch to cpuhp state machine for synic init/cleanup
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
To make it possible to online/offline CPUs switch to cpuhp infrastructure for doing hv_synic_init()/hv_synic_cleanup().
--- drivers/hv/hv.c | 15 +++++++-------- drivers/hv/hyperv_vmbus.h | 4 ++-- drivers/hv/vmbus_drv.c | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 18 deletions(-)
drivers/hv/hv.c +7 -8
@@ -495,7 +495,7 @@ void hv_synic_free(void)* retrieve the initialized message and event pages. Otherwise, we create and * initialize the message and event pages. */ -void hv_synic_init (void *arg) +int hv_synic_init (unsigned int cpu) {u64 version;union hv_synic_simp simp;
@@ -504,10 +504,8 @@ void hv_synic_init(void *arg)union hv_synic_scontrol sctrl;u64 vp_index; -int cpu =smp_processor_id (); -if (!hv_context.hypercall_page) -return ; +return -EFAULT ;/* Check the version */ rdmsrl (HV_X64_MSR_SVERSION , version);
@@ -562,7 +560,7 @@ void hv_synic_init(void *arg)HV_TIMER_FREQUENCY ,HV_MIN_DELTA_TICKS , HV_MAX_MAX_DELTA_TICKS); -return ; +return 0 ; }/*
@@ -582,16 +580,15 @@ void hv_synic_clockevents_cleanup(void)/* * hv_synic_cleanup - Cleanup routine for hv_synic_init(). */ -void hv_synic_cleanup (void *arg) +int hv_synic_cleanup (unsigned int cpu) {union hv_synic_sint shared_sint;union hv_synic_simp simp;union hv_synic_siefp siefp;union hv_synic_scontrol sctrl; -int cpu =smp_processor_id ();if (!hv_context.synic_initialized) -return ; +return -EFAULT ;/* Turn off clockevent device */ if (ms_hyperv.features &HV_X64_MSR_SYNTIMER_AVAILABLE ) {
@@ -623,4 +620,6 @@ 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); + +return 0 ; }
drivers/hv/hyperv_vmbus.h +2 -2
@@ -505,9 +505,9 @@ extern int hv_post_message(union hv_connection_id connection_id,extern void hv_synic_free (void ); -extern void hv_synic_init (void *irqarg); +extern int hv_synic_init (unsigned int cpu); -extern void hv_synic_cleanup (void *arg); +extern int hv_synic_cleanup (unsigned int cpu);extern void hv_synic_clockevents_cleanup (void );
drivers/hv/vmbus_drv.c +11 -8
@@ -49,6 +49,7 @@static struct completion probe_event; +static int hyperv_cpuhp_online;static void hyperv_report_panic (struct pt_regs *regs) {
@@ -850,7 +851,12 @@ static int vmbus_bus_init(void)* Initialize the per-cpu interrupt state and * connect to the host. */ -on_each_cpu (hv_synic_init,NULL ,1 ); + ret =cpuhp_setup_state (CPUHP_AP_ONLINE_DYN ,"x86/hyperv:online" , + hv_synic_init, hv_synic_cleanup); +if (ret <0 ) + goto err_alloc; + hyperv_cpuhp_online = ret; + ret =vmbus_connect ();if (ret) goto err_connect;
@@ -872,7 +878,7 @@ static int vmbus_bus_init(void)return 0 ; err_connect: -on_each_cpu (hv_synic_cleanup,NULL ,1 ); +cpuhp_remove_state (hyperv_cpuhp_online); err_alloc:hv_synic_free ();hv_remove_vmbus_irq ();
@@ -1326,12 +1332,9 @@ static int vmbus_acpi_add(struct acpi_device *device)static void hv_kexec_handler (void ) { -int cpu; -hv_synic_clockevents_cleanup ();vmbus_initiate_unload (false); -for_each_online_cpu (cpu) -smp_call_function_single (cpu, hv_synic_cleanup,NULL ,1 ); +cpuhp_remove_state (hyperv_cpuhp_online);hv_cleanup (false); };
@@ -1343,7 +1346,7 @@ static void hv_crash_handler(struct pt_regs *regs)* doing the cleanup for current CPU only. This should be sufficient * for kdump. */ -hv_synic_cleanup (NULL ); +hv_synic_cleanup (smp_processor_id ());hv_cleanup (true); };
@@ -1407,8 +1410,8 @@ static void __exit vmbus_exit(void)hv_cleanup (false);for_each_online_cpu (cpu) {tasklet_kill (hv_context.event_dpc[cpu]); -smp_call_function_single (cpu, hv_synic_cleanup,NULL ,1 ); } +cpuhp_remove_state (hyperv_cpuhp_online);hv_synic_free ();acpi_bus_unregister_driver (&vmbus_acpi_driver);if (vmbus_proto_version >VERSION_WIN7 )
Signature · 1 line
1.7.4.1
PATCH 11/15 hv: make CPU offlining prevention fine-grained
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
Since commit e513229b4c38 ("Drivers: hv: vmbus: prevent cpu offlining on newer hypervisors") cpu offlining was disabled. It is still true that we can't offline CPUs which have VMBus channels bound to them but we may have 'free' CPUs (e.v. we booted with maxcpus= parameter and onlined CPUs after VMBus was initialized), these CPUs may be disabled without issues.
In future, we may even allow closing CPUs which have only sub-channels assinged to them by closing these sub-channels. All devices will continue to work.
--- drivers/hv/hv.c | 31 +++++++++++++++++++++++++++++++ drivers/hv/vmbus_drv.c | 9 ++++----- 2 files changed, 35 insertions(+), 5 deletions(-)
drivers/hv/hv.c +31 -0
@@ -586,10 +586,41 @@ int hv_synic_cleanup(unsigned int cpu)union hv_synic_simp simp;union hv_synic_siefp siefp;union hv_synic_scontrol sctrl; +struct vmbus_channel *channel, *sc; +bool channel_found = false; +unsigned long flags;if (!hv_context.synic_initialized)return -EFAULT ; +/* +* Search for channels which are bound to the CPU we're about to +* cleanup. In case we find one and vmbus is still connected we need to +* fail, this will effectively prevent CPU offlining. There is no way +* we can re-bind channels to different CPUs for now. +*/ +mutex_lock (&vmbus_connection.channel_mutex); +list_for_each_entry (channel, &vmbus_connection.chn_list, listentry) { +if (channel->target_cpu == cpu) { + channel_found = true; +break ; + } +spin_lock_irqsave (&channel->lock, flags); +list_for_each_entry (sc, &channel->sc_list, sc_list) { +if (sc->target_cpu == cpu) { + channel_found = true; +break ; + } + } +spin_unlock_irqrestore (&channel->lock, flags); +if (channel_found) +break ; + } +mutex_unlock (&vmbus_connection.channel_mutex); + +if (channel_found && vmbus_connection.conn_state ==CONNECTED ) +return -EBUSY ; +/* Turn off clockevent device */ if (ms_hyperv.features &HV_X64_MSR_SYNTIMER_AVAILABLE ) {clockevents_unbind_device (hv_context.clk_evt[cpu], cpu);
drivers/hv/vmbus_drv.c +4 -5
@@ -861,9 +861,6 @@ static int vmbus_bus_init(void)if (ret) goto err_connect; -if (vmbus_proto_version >VERSION_WIN7 ) -cpu_hotplug_disable (); -/* * Only register if the crash MSRs are available */
@@ -1334,6 +1331,9 @@ static void hv_kexec_handler(void) {hv_synic_clockevents_cleanup ();vmbus_initiate_unload (false); + vmbus_connection.conn_state =DISCONNECTED ; +/* Make sure conn_state is set as hv_synic_cleanup checks for it */ +mb ();cpuhp_remove_state (hyperv_cpuhp_online);hv_cleanup (false); };
@@ -1346,6 +1346,7 @@ static void hv_crash_handler(struct pt_regs *regs)* doing the cleanup for current CPU only. This should be sufficient * for kdump. */ + vmbus_connection.conn_state =DISCONNECTED ;hv_synic_cleanup (smp_processor_id ());hv_cleanup (true); };
@@ -1414,8 +1415,6 @@ static void __exit vmbus_exit(void)cpuhp_remove_state (hyperv_cpuhp_online);hv_synic_free ();acpi_bus_unregister_driver (&vmbus_acpi_driver); -if (vmbus_proto_version >VERSION_WIN7 ) -cpu_hotplug_enable (); }
Signature · 1 line
1.7.4.1
PATCH 12/15 hv: don't reset hv_context.tsc_page on crash
In reply to [email protected]From: Vitaly Kuznetsov <[email protected]>
It may happen that secondary CPUs are still alive and resetting hv_context.tsc_page will cause a consequent crash in read_hv_clock_tsc() as we don't check for it being not NULL there. It is safe as we're not freeing this page anyways.
--- drivers/hv/hv.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/hv/hv.c +3 -2
@@ -309,9 +309,10 @@ void hv_cleanup(bool crash) hypercall_msr.as_uint64 =0 ;wrmsrl (HV_X64_MSR_REFERENCE_TSC , hypercall_msr.as_uint64); -if (!crash) +if (!crash) {vfree (hv_context.tsc_page); - hv_context.tsc_page = NULL; + hv_context.tsc_page =NULL ; + } }#endif }
Signature · 1 line
1.7.4.1
PATCH 13/15 vmbus: add support for dynamic device id's
In reply to [email protected]From: Stephen Hemminger <[email protected]>
This patch adds sysfs interface to dynamically bind new UUID values to existing VMBus device. This is useful for generic UIO driver to act similar to uio_pci_generic.
--- drivers/hv/vmbus_drv.c | 174 +++++++++++++++++++++++++++++++++++++++++++++-- include/linux/hyperv.h | 6 ++ 2 files changed, 172 insertions(+), 8 deletions(-)
drivers/hv/vmbus_drv.c +166 -8
@@ -45,6 +45,11 @@#include <linux/random.h> #include "hyperv_vmbus.h" +struct vmbus_dynid { +struct list_head node; +struct hv_vmbus_device_id id; +}; +static struct acpi_device *hv_acpi_dev;static struct completion probe_event;
@@ -501,7 +506,7 @@ static ssize_t device_show(struct device *dev,static DEVICE_ATTR_RO (device);/* Set up per device attributes in /sys/bus/vmbus/devices/<bus device> */ -static struct attribute *vmbus_attrs[] = { +static struct attribute *vmbus_dev_attrs[] = { &dev_attr_id.attr, &dev_attr_state.attr, &dev_attr_monitor_id.attr,
@@ -529,7 +534,7 @@ static ssize_t device_show(struct device *dev, &dev_attr_device.attr,NULL , }; -ATTRIBUTE_GROUPS (vmbus); +ATTRIBUTE_GROUPS (vmbus_dev);/* * vmbus_uevent - add uevent for our device
@@ -566,10 +571,29 @@ static inline bool is_null_guid(const uuid_le *guid)* Return a matching hv_vmbus_device_id pointer. * If there is no match, return NULL. */ -static const struct hv_vmbus_device_id *hv_vmbus_get_id ( -const struct hv_vmbus_device_id *id, +static const struct hv_vmbus_device_id *hv_vmbus_get_id (struct hv_driver *drv,const uuid_le *guid) { +const struct hv_vmbus_device_id *id =NULL ; +struct vmbus_dynid *dynid; + +/* Look at the dynamic ids first, before the static ones */ +spin_lock (&drv->dynids.lock); +list_for_each_entry (dynid, &drv->dynids.list, node) { +if (!uuid_le_cmp (dynid->id.guid, *guid)) { + id = &dynid->id; +break ; + } + } +spin_unlock (&drv->dynids.lock); + +if (id) +return id; + + id = drv->id_table; +if (id ==NULL ) +return NULL ;/* empty device table */ +for (; !is_null_guid (&id->guid); id++)if (!uuid_le_cmp (id->guid, *guid))return id;
@@ -577,6 +601,134 @@ static inline bool is_null_guid(const uuid_le *guid)return NULL ; } +/* vmbus_add_dynid - add a new device ID to this driver and re-probe devices */ +static int vmbus_add_dynid (struct hv_driver *drv,uuid_le *guid) +{ +struct vmbus_dynid *dynid; + + dynid =kzalloc (sizeof (*dynid),GFP_KERNEL ); +if (!dynid) +return -ENOMEM ; + + dynid->id.guid = *guid; + +spin_lock (&drv->dynids.lock); +list_add_tail (&dynid->node, &drv->dynids.list); +spin_unlock (&drv->dynids.lock); + +return driver_attach (&drv->driver); +} + +static void vmbus_free_dynids (struct hv_driver *drv) +{ +struct vmbus_dynid *dynid, *n; + +spin_lock (&drv->dynids.lock); +list_for_each_entry_safe (dynid, n, &drv->dynids.list, node) { +list_del (&dynid->node); +kfree (dynid); + } +spin_unlock (&drv->dynids.lock); +} + +/* Parse string of form: 1b4e28ba-2fa1-11d2-883f-b9a761bde3f */ +static int get_uuid_le (const char *str,uuid_le *uu) +{ +unsigned int b[16 ]; +int i; + +if (strlen (str) <37 ) +return -1 ; + +for (i =0 ; i <36 ; i++) { +switch (i) { +case 8 :case 13 :case 18 :case 23 : +if (str[i] !='-' ) +return -1 ; +break ; +default : +if (!isxdigit (str[i])) +return -1 ; + } + } + +/* unparse little endian output byte order */ +if (sscanf (str, +"%2x%2x%2x%2x-%2x%2x-%2x%2x-%2x%2x-%2x%2x%2x%2x%2x%2x" , + &b[3 ], &b[2 ], &b[1 ], &b[0 ], + &b[5 ], &b[4 ], &b[7 ], &b[6 ], &b[8 ], &b[9 ], + &b[10 ], &b[11 ], &b[12 ], &b[13 ], &b[14 ], &b[15 ]) !=16 ) +return -1 ; + +for (i =0 ; i <16 ; i++) + uu->b[i] = b[i]; +return 0 ; +} + +/* +* store_new_id - sysfs frontend to vmbus_add_dynid() +* +* Allow GUIDs to be added to an existing driver via sysfs. +*/ +static ssize_t new_id_store (struct device_driver *driver,const char *buf, +size_t count) +{ +struct hv_driver *drv =drv_to_hv_drv (driver); +uuid_le guid =NULL_UUID_LE ; +ssize_t retval; + +if (get_uuid_le (buf, &guid) !=0 ) +return -EINVAL ; + +if (hv_vmbus_get_id (drv, &guid)) +return -EEXIST ; + + retval =vmbus_add_dynid (drv, &guid); +if (retval) +return retval; +return count; +} +static DRIVER_ATTR_WO (new_id); + +/* +* store_remove_id - remove a PCI device ID from this driver +* +* Removes a dynamic pci device ID to this driver. +*/ +static ssize_t remove_id_store (struct device_driver *driver,const char *buf, +size_t count) +{ +struct hv_driver *drv =drv_to_hv_drv (driver); +struct vmbus_dynid *dynid, *n; +uuid_le guid =NULL_UUID_LE ; +size_t retval = -ENODEV ; + +if (get_uuid_le (buf, &guid)) +return -EINVAL ; + +spin_lock (&drv->dynids.lock); +list_for_each_entry_safe (dynid, n, &drv->dynids.list, node) { +struct hv_vmbus_device_id *id = &dynid->id; + +if (!uuid_le_cmp (id->guid, guid)) { +list_del (&dynid->node); +kfree (dynid); + retval = count; +break ; + } + } +spin_unlock (&drv->dynids.lock); + +return retval; +} +static DRIVER_ATTR_WO (remove_id); + +static struct attribute *vmbus_drv_attrs[] = { + &driver_attr_new_id.attr, + &driver_attr_remove_id.attr, +NULL , +}; +ATTRIBUTE_GROUPS (vmbus_drv);/*
@@ -591,7 +743,7 @@ static int vmbus_match(struct device *device, struct device_driver *driver)if (is_hvsock_channel (hv_dev->channel))return drv->hvsock; -if (hv_vmbus_get_id (drv->id_table, &hv_dev->dev_type)) +if (hv_vmbus_get_id (drv, &hv_dev->dev_type))return 1 ;return 0 ;
@@ -608,7 +760,7 @@ static int vmbus_probe(struct device *child_device)struct hv_device *dev =device_to_hv_device (child_device);const struct hv_vmbus_device_id *dev_id; - dev_id =hv_vmbus_get_id (drv->id_table, &dev->dev_type); + dev_id =hv_vmbus_get_id (drv, &dev->dev_type);if (drv->probe) { ret = drv->probe (dev, dev_id);if (ret !=0 )
@@ -685,7 +837,8 @@ static void vmbus_device_release(struct device *device) .remove = vmbus_remove, .probe = vmbus_probe, .uevent = vmbus_uevent, - .dev_groups = vmbus_groups, + .dev_groups = vmbus_dev_groups, + .drv_groups = vmbus_drv_groups, };struct onmessage_work_context {
@@ -914,6 +1067,9 @@ int __vmbus_driver_register(struct hv_driver *hv_driver, struct module *owner, c hv_driver->driver.mod_name = mod_name; hv_driver->driver.bus = &hv_bus; +spin_lock_init (&hv_driver->dynids.lock); +INIT_LIST_HEAD (&hv_driver->dynids.list); + ret =driver_register (&hv_driver->driver);return ret;
@@ -932,8 +1088,10 @@ void vmbus_driver_unregister(struct hv_driver *hv_driver) {pr_info ("unregistering driver %s\n" , hv_driver->name); -if (!vmbus_exists ()) +if (!vmbus_exists ()) {driver_unregister (&hv_driver->driver); +vmbus_free_dynids (hv_driver); + } }EXPORT_SYMBOL_GPL (vmbus_driver_unregister);
include/linux/hyperv.h +6 -0
@@ -1122,6 +1122,12 @@ struct hv_driver {struct device_driver driver; +/* dynamic device GUID's */ +struct { +spinlock_t lock; +struct list_head list; + } dynids; +int (*probe)(struct hv_device *,const struct hv_vmbus_device_id *);int (*remove)(struct hv_device *);void (*shutdown)(struct hv_device *);
Signature · 1 line
1.7.4.1
PATCH 14/15 uio-hv-generic: new userspace i/o driver for VMBus
In reply to [email protected]From: Stephen Hemminger <[email protected]>
This is a new driver to enable userspace networking on VMBus. It is based largely on the similar driver that already exists for PCI, and earlier work done by Brocade to support DPDK.
--- MAINTAINERS | 1 + drivers/hv/connection.c | 1 + drivers/uio/Kconfig | 9 ++ drivers/uio/Makefile | 1 + drivers/uio/uio_hv_generic.c | 218 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+), 0 deletions(-) create mode 100644 drivers/uio/uio_hv_generic.c
MAINTAINERS +1 -0
@@ -5851,6 +5851,7 @@ F: drivers/input/serio/hyperv-keyboard.c F: drivers/pci/host/pci-hyperv.c F: drivers/net/hyperv/ F: drivers/scsi/storvsc_drv.c +F: drivers/uio/uio_hv_generic.c F: drivers/video/fbdev/hyperv_fb.c F: include/linux/hyperv.h F: tools/hv/
drivers/hv/connection.c +1 -0
@@ -39,6 +39,7 @@ struct vmbus_connection vmbus_connection = { .conn_state = DISCONNECTED, .next_gpadl_handle = ATOMIC_INIT(0xE1E10), }; +EXPORT_SYMBOL_GPL (vmbus_connection);/* * Negotiated protocol version with the host.
drivers/uio/Kconfig +9 -0
@@ -155,4 +155,13 @@ config UIO_MF624 If you compile this as a module, it will be called uio_mf624. +config UIO_HV_GENERIC + tristate "Generic driver for Hyper-V VMBus" + depends on HYPERV + help + Generic driver that you can bind, dynamically, to any + Hyper-V VMBus device. It is useful to provide direct access + to network and storage devices from userspace. + + If you compile this as a module, it will be called uio_hv_generic. endif
drivers/uio/Makefile +1 -0
@@ -9,3 +9,4 @@ obj-$(CONFIG_UIO_NETX) += uio_netx.o obj-$(CONFIG_UIO_PRUSS) += uio_pruss.o obj-$(CONFIG_UIO_MF624) += uio_mf624.o obj-$(CONFIG_UIO_FSL_ELBC_GPCM) += uio_fsl_elbc_gpcm.o +obj-$(CONFIG_UIO_HV_GENERIC) += uio_hv_generic.o
drivers/uio/uio_hv_generic.c new file +218 -0
218 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH 15/15 Tools: hv: kvp: configurable external scripts path
In reply to [email protected]From: Alex Fluter <[email protected]>
error when running hypervkvpd:
$ sudo ./hv_kvp_daemon -n
sh: hv_get_dns_info: command not found
sh: hv_get_dhcp_info: command not found
sh: hv_get_dns_info: command not found
sh: hv_get_dhcp_info: command not found
The external scripts are not installed in system path, adding a configurable macro.
--- tools/hv/hv_kvp_daemon.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
tools/hv/hv_kvp_daemon.c +8 -3
@@ -93,6 +93,10 @@ enum {#define KVP_CONFIG_LOC "/var/lib/hyperv" +#ifndef KVP_SCRIPTS_PATH +#define KVP_SCRIPTS_PATH "/usr/libexec/hypervkvpd/" +#endif +#define MAX_FILE_NAME 100#define ENTRIES_PER_BLOCK 50
@@ -818,7 +822,7 @@ static void kvp_get_ipconfig_info(char *if_name,* . */ -sprintf (cmd,"%s" ,"hv_get_dns_info" ); +sprintf (cmd,KVP_SCRIPTS_PATH "%s" ,"hv_get_dns_info" );/* * Execute the command to gather DNS info.
@@ -835,7 +839,7 @@ static void kvp_get_ipconfig_info(char *if_name,* Enabled: DHCP enabled. */ -sprintf (cmd,"%s %s" ,"hv_get_dhcp_info" , if_name); +sprintf (cmd,KVP_SCRIPTS_PATH "%s %s" ,"hv_get_dhcp_info" , if_name); file =popen (cmd,"r" );if (file ==NULL )
@@ -1341,7 +1345,8 @@ static int kvp_set_ip_info(char *if_name, struct hv_kvp_ipaddr_value *new_val)* invoke the external script to do its magic. */ -snprintf (cmd,sizeof (cmd),"%s %s" ,"hv_set_ifconfig" , if_file); +snprintf (cmd,sizeof (cmd),KVP_SCRIPTS_PATH "%s %s" , +"hv_set_ifconfig" , if_file);if (system (cmd)) {syslog (LOG_ERR ,"Failed to execute cmd '%s'; error: %d %s" , cmd, errno,strerror (errno));
Signature · 1 line
1.7.4.1