Skip to contentSkip to conversation

Drivers: hv: Miscellaneous fixes.

PATCH RESEND In review K. Y. Srinivasan 3 participants 35 messages Dec 14, 2015 – Jan 6, 2016

Subsystems (3)

v1 of 2 In review Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Drivers: hv: Miscellaneous fixes.

Miscellaneous fixes and improvements.

Andrey Smetanin (2):
drivers/hv: cleanup synic msrs if vmbus connect failed drivers/hv: correct tsc page sequence invalid value

Dexuan Cui (6):
Drivers: hv: vmbus: serialize process_chn_event() and
vmbus_close_internal()
Drivers: hv: vmbus: do sanity check of channel state in
vmbus_close_internal()
Drivers: hv: vmbus: fix rescind-offer handling for device without a
driver
Drivers: hv: vmbus: release relid on error in vmbus_process_offer()
Drivers: hv: vmbus: channge vmbus_connection.channel_lock to mutex
tools: hv: vss: fix the write()'s argument: error -> vss_msg

Jake Oshins (4):
drivers:hv: Export a function that maps Linux CPU num onto Hyper-V
proc num
drivers:hv: Export the API to invoke a hypercall on Hyper-V drivers:hv: Define the channel type for Hyper-V PCI Express
pass-through
drivers:hv: Allow for MMIO claims that span ACPI _CRS records

K. Y. Srinivasan (8):
Drivers: hv: util: Increase the timeout for util services
Drivers: hv: vmbus: Use uuid_le type consistently
Drivers: hv: vmbus: Use uuid_le_cmp() for comparing GUIDs
Drivers: hv: vmbus: Get rid of the unused macro
Drivers: hv: vmbus: Get rid of the unused irq variable
Drivers: hv: vmbus: Fix a Host signaling bug
Drivers: hv: vmbus: Force all channel messages to be delivered on CPU

    0

Drivers: hv: utils: Invoke the poll function after handshake

Kamal Mostafa (1):
tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Olaf Hering (6):
Drivers: hv: utils: run polling callback always in interrupt context
tools: hv: report ENOSPC errors in hv_fcopy_daemon
tools: hv: remove repeated HV_FCOPY string
Drivers: hv: util: catch allocation errors
Drivers: hv: utils: use memdup_user in hvt_op_write
Drivers: hv: vss: run only on supported host versions

 drivers/hv/channel.c            |   57 +++++++++++++++---
 drivers/hv/channel_mgmt.c       |   45 +++++++++-----
 drivers/hv/connection.c         |   18 +++---
 drivers/hv/hv.c                 |   24 ++++----
 drivers/hv/hv_fcopy.c           |   37 +++++-------
 drivers/hv/hv_kvp.c             |   33 ++++------
 drivers/hv/hv_snapshot.c        |   36 +++++------
 drivers/hv/hv_utils_transport.c |   18 +++---
 drivers/hv/hyperv_vmbus.h       |   15 +++--
 drivers/hv/vmbus_drv.c          |   82 +++++++++++++++----------
 include/linux/hyperv.h          |  123 ++++++++++++++++++---------------------
 include/linux/mod_devicetable.h |    2 +-
 include/uapi/linux/hyperv.h     |    1 +
 scripts/mod/file2alias.c        |    2 +-
 tools/hv/Makefile               |    2 +
 tools/hv/hv_fcopy_daemon.c      |   24 ++++++--
 tools/hv/hv_vss_daemon.c        |    2 +-
 17 files changed, 292 insertions(+), 229 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH RESEND 1/27 Drivers: hv: util: Increase the timeout for util services

Util services such as KVP and FCOPY need assistance from daemon's running in user space. Increase the timeout so we don't prematurely terminate the transaction in the kernel. Host sets up a 60 second timeout for all util driver transactions. The host will retry the transaction if it times out. Set the guest timeout at 30 seconds.

---
 drivers/hv/hv_fcopy.c     |    3 ++-
 drivers/hv/hv_kvp.c       |    3 ++-
 drivers/hv/hyperv_vmbus.h |    5 +++++
 3 files changed, 9 insertions(+), 2 deletions(-)
drivers/hv/hv_fcopy.c +2 -1
index db4b887..bbdec50 100644
@@ -275,7 +275,8 @@ void hv_fcopy_onchannelcallback(void *context)
 		 * Send the information to the user-level daemon.
 		 */
 		schedule_work(&fcopy_send_work);
-		schedule_delayed_work(&fcopy_timeout_work, 5*HZ);
+		schedule_delayed_work(&fcopy_timeout_work,
+				      HV_UTIL_TIMEOUT * HZ);
 		return;
 	}
 	icmsghdr->icflags = ICMSGHDRFLAG_TRANSACTION | ICMSGHDRFLAG_RESPONSE;
drivers/hv/hv_kvp.c +2 -1
index 74c38a9..e6aa33a 100644
@@ -668,7 +668,8 @@ void hv_kvp_onchannelcallback(void *context)
 			 * user-mode not responding.
 			 */
 			schedule_work(&kvp_sendkey_work);
-			schedule_delayed_work(&kvp_timeout_work, 5*HZ);
+			schedule_delayed_work(&kvp_timeout_work,
+					      HV_UTIL_TIMEOUT * HZ);
 
 			return;
 
drivers/hv/hyperv_vmbus.h +5 -0
index 3782636..225b96b 100644
@@ -31,6 +31,11 @@
 #include <linux/hyperv.h>
 
 /*
+ * Timeout for services such as KVP and fcopy.
+ */
+#define HV_UTIL_TIMEOUT 30
+
+/*
  * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
  * is set by CPUID(HVCPUID_VERSION_FEATURES).
  */
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH RESEND 2/27 Drivers: hv: utils: run polling callback always in interrupt context

From: Olaf Hering <[email protected]>

All channel interrupts are bound to specific VCPUs in the guest at the point channel is created. While currently, we invoke the polling function on the correct CPU (the CPU to which the channel is bound to) in some cases we may run the polling function in a non-interrupt context. This potentially can cause an issue as the polling function can be interrupted by the channel callback function. Fix the issue by running the polling function on the appropriate CPU at interrupt level. Additional details of the issue being addressed by this patch are given below:

Currently hv_fcopy_onchannelcallback is called from interrupts and also via the ->write function of hv_utils. Since the used global variables to maintain state are not thread safe the state can get out of sync. This affects the variable state as well as the channel inbound buffer.

As suggested by KY adjust hv_poll_channel to always run the given callback on the cpu which the channel is bound to. This avoids the need for locking because all the util services are single threaded and only one transaction is active at any given point in time.

Additionally, remove the context variable, they will always be the same as recv_channel.

---
 drivers/hv/hv_fcopy.c     |   34 ++++++++++++----------------------
 drivers/hv/hv_kvp.c       |   28 ++++++++++------------------
 drivers/hv/hv_snapshot.c  |   29 +++++++++++------------------
 drivers/hv/hyperv_vmbus.h |    6 +-----
 4 files changed, 34 insertions(+), 63 deletions(-)
drivers/hv/hv_fcopy.c +12 -22
index bbdec50..c37a71e 100644
@@ -51,7 +51,6 @@ static struct {
 	struct hv_fcopy_hdr  *fcopy_msg; /* current message */
 	struct vmbus_channel *recv_channel; /* chn we got the request */
 	u64 recv_req_id; /* request ID. */
-	void *fcopy_context; /* for the channel callback */
 } fcopy_transaction;
 
 static void fcopy_respond_to_host(int error);
@@ -67,6 +66,13 @@ static struct hvutil_transport *hvt;
  */
 static int dm_reg_value;
 
+static void fcopy_poll_wrapper(void *channel)
+{
+	/* Transaction is finished, reset the state here to avoid races. */
+	fcopy_transaction.state = HVUTIL_READY;
+	hv_fcopy_onchannelcallback(channel);
+}
+
 static void fcopy_timeout_func(struct work_struct *dummy)
 {
 	/*
@@ -74,13 +80,7 @@ static void fcopy_timeout_func(struct work_struct *dummy)
 	 * process the pending transaction.
 	 */
 	fcopy_respond_to_host(HV_E_FAIL);
-
-	/* Transaction is finished, reset the state. */
-	if (fcopy_transaction.state > HVUTIL_READY)
-		fcopy_transaction.state = HVUTIL_READY;
-
-	hv_poll_channel(fcopy_transaction.fcopy_context,
-			hv_fcopy_onchannelcallback);
+	hv_poll_channel(fcopy_transaction.recv_channel, fcopy_poll_wrapper);
 }
 
 static int fcopy_handle_handshake(u32 version)
@@ -108,9 +108,7 @@ static int fcopy_handle_handshake(u32 version)
 		return -EINVAL;
 	}
 	pr_debug("FCP: userspace daemon ver. %d registered\n", version);
-	fcopy_transaction.state = HVUTIL_READY;
-	hv_poll_channel(fcopy_transaction.fcopy_context,
-			hv_fcopy_onchannelcallback);
+	hv_poll_channel(fcopy_transaction.recv_channel, fcopy_poll_wrapper);
 	return 0;
 }
 
@@ -227,15 +225,8 @@ void hv_fcopy_onchannelcallback(void *context)
 	int util_fw_version;
 	int fcopy_srv_version;
 
-	if (fcopy_transaction.state > HVUTIL_READY) {
-		/*
-		 * We will defer processing this callback once
-		 * the current transaction is complete.
-		 */
-		fcopy_transaction.fcopy_context = context;
+	if (fcopy_transaction.state > HVUTIL_READY)
 		return;
-	}
-	fcopy_transaction.fcopy_context = NULL;
 
 	vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
 			 &requestid);
@@ -305,9 +296,8 @@ static int fcopy_on_msg(void *msg, int len)
 	if (cancel_delayed_work_sync(&fcopy_timeout_work)) {
 		fcopy_transaction.state = HVUTIL_USERSPACE_RECV;
 		fcopy_respond_to_host(*val);
-		fcopy_transaction.state = HVUTIL_READY;
-		hv_poll_channel(fcopy_transaction.fcopy_context,
-				hv_fcopy_onchannelcallback);
+		hv_poll_channel(fcopy_transaction.recv_channel,
+				fcopy_poll_wrapper);
 	}
 
 	return 0;
drivers/hv/hv_kvp.c +10 -18
index e6aa33a..2a3420c 100644
@@ -66,7 +66,6 @@ static struct {
 	struct hv_kvp_msg  *kvp_msg; /* current message */
 	struct vmbus_channel *recv_channel; /* chn we got the request */
 	u64 recv_req_id; /* request ID. */
-	void *kvp_context; /* for the channel callback */
 } kvp_transaction;
 
 /*
@@ -94,6 +93,13 @@ static struct hvutil_transport *hvt;
  */
 #define HV_DRV_VERSION           "3.1"
 
+static void kvp_poll_wrapper(void *channel)
+{
+	/* Transaction is finished, reset the state here to avoid races. */
+	kvp_transaction.state = HVUTIL_READY;
+	hv_kvp_onchannelcallback(channel);
+}
+
 static void
 kvp_register(int reg_value)
 {
@@ -121,12 +127,7 @@ static void kvp_timeout_func(struct work_struct *dummy)
 	 */
 	kvp_respond_to_host(NULL, HV_E_FAIL);
 
-	/* Transaction is finished, reset the state. */
-	if (kvp_transaction.state > HVUTIL_READY)
-		kvp_transaction.state = HVUTIL_READY;
-
-	hv_poll_channel(kvp_transaction.kvp_context,
-			hv_kvp_onchannelcallback);
+	hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
 }
 
 static int kvp_handle_handshake(struct hv_kvp_msg *msg)
@@ -218,9 +219,7 @@ static int kvp_on_msg(void *msg, int len)
 	 */
 	if (cancel_delayed_work_sync(&kvp_timeout_work)) {
 		kvp_respond_to_host(message, error);
-		kvp_transaction.state = HVUTIL_READY;
-		hv_poll_channel(kvp_transaction.kvp_context,
-				hv_kvp_onchannelcallback);
+		hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
 	}
 
 	return 0;
@@ -596,15 +595,8 @@ void hv_kvp_onchannelcallback(void *context)
 	int util_fw_version;
 	int kvp_srv_version;
 
-	if (kvp_transaction.state > HVUTIL_READY) {
-		/*
-		 * We will defer processing this callback once
-		 * the current transaction is complete.
-		 */
-		kvp_transaction.kvp_context = context;
+	if (kvp_transaction.state > HVUTIL_READY)
 		return;
-	}
-	kvp_transaction.kvp_context = NULL;
 
 	vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 4, &recvlen,
 			 &requestid);
drivers/hv/hv_snapshot.c +11 -18
index 815405f..a548ae4 100644
@@ -53,7 +53,6 @@ static struct {
 	struct vmbus_channel *recv_channel; /* chn we got the request */
 	u64 recv_req_id; /* request ID. */
 	struct hv_vss_msg  *msg; /* current message */
-	void *vss_context; /* for the channel callback */
 } vss_transaction;
 
 
@@ -74,6 +73,13 @@ static void vss_timeout_func(struct work_struct *dummy);
 static DECLARE_DELAYED_WORK(vss_timeout_work, vss_timeout_func);
 static DECLARE_WORK(vss_send_op_work, vss_send_op);
 
+static void vss_poll_wrapper(void *channel)
+{
+	/* Transaction is finished, reset the state here to avoid races. */
+	vss_transaction.state = HVUTIL_READY;
+	hv_vss_onchannelcallback(channel);
+}
+
 /*
  * Callback when data is received from user mode.
  */
@@ -86,12 +92,7 @@ static void vss_timeout_func(struct work_struct *dummy)
 	pr_warn("VSS: timeout waiting for daemon to reply\n");
 	vss_respond_to_host(HV_E_FAIL);
 
-	/* Transaction is finished, reset the state. */
-	if (vss_transaction.state > HVUTIL_READY)
-		vss_transaction.state = HVUTIL_READY;
-
-	hv_poll_channel(vss_transaction.vss_context,
-			hv_vss_onchannelcallback);
+	hv_poll_channel(vss_transaction.recv_channel, vss_poll_wrapper);
 }
 
 static int vss_handle_handshake(struct hv_vss_msg *vss_msg)
@@ -138,9 +139,8 @@ static int vss_on_msg(void *msg, int len)
 		if (cancel_delayed_work_sync(&vss_timeout_work)) {
 			vss_respond_to_host(vss_msg->error);
 			/* Transaction is finished, reset the state. */
-			vss_transaction.state = HVUTIL_READY;
-			hv_poll_channel(vss_transaction.vss_context,
-					hv_vss_onchannelcallback);
+			hv_poll_channel(vss_transaction.recv_channel,
+					vss_poll_wrapper);
 		}
 	} else {
 		/* This is a spurious call! */
@@ -238,15 +238,8 @@ void hv_vss_onchannelcallback(void *context)
 	struct icmsg_hdr *icmsghdrp;
 	struct icmsg_negotiate *negop = NULL;
 
-	if (vss_transaction.state > HVUTIL_READY) {
-		/*
-		 * We will defer processing this callback once
-		 * the current transaction is complete.
-		 */
-		vss_transaction.vss_context = context;
+	if (vss_transaction.state > HVUTIL_READY)
 		return;
-	}
-	vss_transaction.vss_context = NULL;
 
 	vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
 			 &requestid);
drivers/hv/hyperv_vmbus.h +1 -5
index 225b96b..12156db 100644
@@ -764,11 +764,7 @@ static inline void hv_poll_channel(struct vmbus_channel *channel,
 	if (!channel)
 		return;
 
-	if (channel->target_cpu != smp_processor_id())
-		smp_call_function_single(channel->target_cpu,
-					 cb, channel, true);
-	else
-		cb(channel);
+	smp_call_function_single(channel->target_cpu, cb, channel, true);
 }
 
 enum hvutil_device_state {
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH RESEND 3/27 tools: hv: report ENOSPC errors in hv_fcopy_daemon

In reply to K. Y. Srinivasan

From: Olaf Hering <[email protected]>

Currently some "Unspecified error 0x80004005" is reported on the Windows side if something fails. Handle the ENOSPC case and return ERROR_DISK_FULL, which allows at least Copy-VMFile to report a meaning full error.

---
 include/uapi/linux/hyperv.h |    1 +
 tools/hv/hv_fcopy_daemon.c  |   20 +++++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
include/uapi/linux/hyperv.h +1 -0
index e4c0a35..e347b24 100644
@@ -313,6 +313,7 @@ enum hv_kvp_exchg_pool {
 #define HV_INVALIDARG			0x80070057
 #define HV_GUID_NOTFOUND		0x80041002
 #define HV_ERROR_ALREADY_EXISTS		0x80070050
+#define HV_ERROR_DISK_FULL		0x80070070
 
 #define ADDR_FAMILY_NONE	0x00
 #define ADDR_FAMILY_IPV4	0x01
tools/hv/hv_fcopy_daemon.c +17 -3
index 5480e4e..f1d7426 100644
@@ -37,12 +37,14 @@
 
 static int target_fd;
 static char target_fname[W_MAX_PATH];
+static unsigned long long filesize;
 
 static int hv_start_fcopy(struct hv_start_fcopy *smsg)
 {
 	int error = HV_E_FAIL;
 	char *q, *p;
 
+	filesize = 0;
 	p = (char *)smsg->path_name;
 	snprintf(target_fname, sizeof(target_fname), "%s/%s",
 		 (char *)smsg->path_name, (char *)smsg->file_name);
@@ -98,14 +100,26 @@ done:
 static int hv_copy_data(struct hv_do_fcopy *cpmsg)
 {
 	ssize_t bytes_written;
+	int ret = 0;
 
 	bytes_written = pwrite(target_fd, cpmsg->data, cpmsg->size,
 				cpmsg->offset);
 
-	if (bytes_written != cpmsg->size)
-		return HV_E_FAIL;
+	filesize += cpmsg->size;
+	if (bytes_written != cpmsg->size) {
+		switch (errno) {
+		case ENOSPC:
+			ret = HV_ERROR_DISK_FULL;
+			break;
+		default:
+			ret = HV_E_FAIL;
+			break;
+		}
+		syslog(LOG_ERR, "pwrite failed to write %llu bytes: %ld (%s)",
+		       filesize, (long)bytes_written, strerror(errno));
+	}
 
-	return 0;
+	return ret;
 }
 
 static int hv_copy_finished(void)
Signature · 1 line
1.7.4.1
#4 lore raw

PATCH RESEND 4/27 tools: hv: remove repeated HV_FCOPY string

In reply to K. Y. Srinivasan

From: Olaf Hering <[email protected]>

HV_FCOPY is already used as identifier in syslog.

---
 tools/hv/hv_fcopy_daemon.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
tools/hv/hv_fcopy_daemon.c +2 -2
index f1d7426..fdc9ca4 100644
@@ -179,7 +179,7 @@ int main(int argc, char *argv[])
 	}
 
 	openlog("HV_FCOPY", 0, LOG_USER);
-	syslog(LOG_INFO, "HV_FCOPY starting; pid is:%d", getpid());
+	syslog(LOG_INFO, "starting; pid is:%d", getpid());
 
 	fcopy_fd = open("/dev/vmbus/hv_fcopy", O_RDWR);
 
@@ -215,7 +215,7 @@ int main(int argc, char *argv[])
 			}
 			kernel_modver = *(__u32 *)buffer;
 			in_handshake = 0;
-			syslog(LOG_INFO, "HV_FCOPY: kernel module version: %d",
+			syslog(LOG_INFO, "kernel module version: %d",
 			       kernel_modver);
 			continue;
 		}
Signature · 1 line
1.7.4.1
#5 lore raw

PATCH RESEND 5/27 Drivers: hv: util: catch allocation errors

In reply to K. Y. Srinivasan

From: Olaf Hering <[email protected]>

Catch allocation errors in hvutil_transport_send.

Fixes 14b50f80c32d ('Drivers: hv: util: introduce hv_utils_transport abstraction')
---
 drivers/hv/hv_utils_transport.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
drivers/hv/hv_utils_transport.c +6 -3
index 6a9d80a..1505ee6 100644
@@ -204,9 +204,12 @@ int hvutil_transport_send(struct hvutil_transport *hvt, void *msg, int len)
 		goto out_unlock;
 	}
 	hvt->outmsg = kzalloc(len, GFP_KERNEL);
-	memcpy(hvt->outmsg, msg, len);
-	hvt->outmsg_len = len;
-	wake_up_interruptible(&hvt->outmsg_q);
+	if (hvt->outmsg) {
+		memcpy(hvt->outmsg, msg, len);
+		hvt->outmsg_len = len;
+		wake_up_interruptible(&hvt->outmsg_q);
+	} else
+		ret = -ENOMEM;
 out_unlock:
 	mutex_unlock(&hvt->outmsg_lock);
 	return ret;
Signature · 1 line
1.7.4.1
#6 lore raw

PATCH RESEND 6/27 Drivers: hv: utils: use memdup_user in hvt_op_write

In reply to K. Y. Srinivasan

From: Olaf Hering <[email protected]>

Use memdup_user to handle OOM.

Fixes 14b50f80c32d ('Drivers: hv: util: introduce hv_utils_transport abstraction')
---
 drivers/hv/hv_utils_transport.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)
drivers/hv/hv_utils_transport.c +4 -5
index 1505ee6..24b2766 100644
@@ -80,11 +80,10 @@ static ssize_t hvt_op_write(struct file *file, const char __user *buf,
 
 	hvt = container_of(file->f_op, struct hvutil_transport, fops);
 
-	inmsg = kzalloc(count, GFP_KERNEL);
-	if (copy_from_user(inmsg, buf, count)) {
-		kfree(inmsg);
-		return -EFAULT;
-	}
+	inmsg = memdup_user(buf, count);
+	if (IS_ERR(inmsg))
+		return PTR_ERR(inmsg);
+
 	if (hvt->on_msg(inmsg, count))
 		return -EFAULT;
 	kfree(inmsg);
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH RESEND 7/27 drivers/hv: cleanup synic msrs if vmbus connect failed

In reply to K. Y. Srinivasan

From: Andrey Smetanin <[email protected]>

Before vmbus_connect() synic is setup per vcpu - this means hypervisor receives writes at synic msr's and probably allocate hypervisor resources per synic setup.

If vmbus_connect() failed for some reason it's neccessary to cleanup synic setup by call hv_synic_cleanup() at each vcpu to get a chance to free allocated resources by hypervisor per synic.

This patch does appropriate cleanup in case of vmbus_connect() failure.

---
 drivers/hv/vmbus_drv.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/hv/vmbus_drv.c +3 -1
index f19b6f7..3297731 100644
@@ -867,7 +867,7 @@ static int vmbus_bus_init(int irq)
 	on_each_cpu(hv_synic_init, NULL, 1);
 	ret = vmbus_connect();
 	if (ret)
-		goto err_alloc;
+		goto err_connect;
 
 	if (vmbus_proto_version > VERSION_WIN7)
 		cpu_hotplug_disable();
@@ -885,6 +885,8 @@ static int vmbus_bus_init(int irq)
 
 	return 0;
 
+err_connect:
+	on_each_cpu(hv_synic_cleanup, NULL, 1);
 err_alloc:
 	hv_synic_free();
 	hv_remove_vmbus_irq();
Signature · 1 line
1.7.4.1
#8 lore raw

PATCH RESEND 8/27 drivers:hv: Export a function that maps Linux CPU num onto Hyper-V proc num

In reply to K. Y. Srinivasan

From: Jake Oshins <[email protected]>

This patch exposes the mapping between Linux CPU number and Hyper-V virtual processor number. This is necessary because the hypervisor needs to know which virtual processors to target when making a mapping in the Interrupt Redirection Table in the I/O MMU.

---
 drivers/hv/vmbus_drv.c |   17 +++++++++++++++++
 include/linux/hyperv.h |    2 ++
 2 files changed, 19 insertions(+), 0 deletions(-)
drivers/hv/vmbus_drv.c +17 -0
index 3297731..c01b689 100644
@@ -1193,6 +1193,23 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
 }
 EXPORT_SYMBOL_GPL(vmbus_allocate_mmio);
 
+/**
+ * vmbus_cpu_number_to_vp_number() - Map CPU to VP.
+ * @cpu_number: CPU number in Linux terms
+ *
+ * This function returns the mapping between the Linux processor
+ * number and the hypervisor's virtual processor number, useful
+ * in making hypercalls and such that talk about specific
+ * processors.
+ *
+ * Return: Virtual processor number in Hyper-V terms
+ */
+int vmbus_cpu_number_to_vp_number(int cpu_number)
+{
+	return hv_context.vp_index[cpu_number];
+}
+EXPORT_SYMBOL_GPL(vmbus_cpu_number_to_vp_number);
+
 static int vmbus_acpi_add(struct acpi_device *device)
 {
 	acpi_status result;
include/linux/hyperv.h +2 -0
index 8fdc17b..fddb3e0 100644
@@ -983,6 +983,8 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
 			resource_size_t size, resource_size_t align,
 			bool fb_overlap_ok);
 
+int vmbus_cpu_number_to_vp_number(int cpu_number);
+
 /**
  * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
  *
Signature · 1 line
1.7.4.1
#9 lore raw

PATCH RESEND 9/27 drivers:hv: Export the API to invoke a hypercall on Hyper-V

In reply to K. Y. Srinivasan

From: Jake Oshins <[email protected]>

This patch exposes the function that hv_vmbus.ko uses to make hypercalls. This is necessary for retargeting an interrupt when it is given a new affinity.

Since we are exporting this API, rename the API as it will be visible outside the hv.c file.

---
 drivers/hv/hv.c           |   20 ++++++++++----------
 drivers/hv/hyperv_vmbus.h |    2 +-
 include/linux/hyperv.h    |    1 +
 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/hv/hv.c +10 -10
index 6341be8..7a06933 100644
@@ -89,9 +89,9 @@ static int query_hypervisor_info(void)
 }
 
 /*
- * do_hypercall- Invoke the specified hypercall
+ * hv_do_hypercall- Invoke the specified hypercall
  */
-static u64 do_hypercall(u64 control, void *input, void *output)
+u64 hv_do_hypercall(u64 control, void *input, void *output)
 {
 	u64 input_address = (input) ? virt_to_phys(input) : 0;
 	u64 output_address = (output) ? virt_to_phys(output) : 0;
@@ -132,6 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
 	return hv_status_lo | ((u64)hv_status_hi << 32);
 #endif /* !x86_64 */
 }
+EXPORT_SYMBOL_GPL(hv_do_hypercall);
 
 #ifdef CONFIG_X86_64
 static cycle_t read_hv_clock_tsc(struct clocksource *arg)
@@ -315,7 +316,7 @@ int hv_post_message(union hv_connection_id connection_id,
 {
 
 	struct hv_input_post_message *aligned_msg;
-	u16 status;
+	u64 status;
 
 	if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
 		return -EMSGSIZE;
@@ -329,11 +330,10 @@ int hv_post_message(union hv_connection_id connection_id,
 	aligned_msg->payload_size = payload_size;
 	memcpy((void *)aligned_msg->payload, payload, payload_size);
 
-	status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL)
-		& 0xFFFF;
+	status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL);
 
 	put_cpu();
-	return status;
+	return status & 0xFFFF;
 }
 
 
@@ -343,13 +343,13 @@ int hv_post_message(union hv_connection_id connection_id,
  *
  * This involves a hypercall.
  */
-u16 hv_signal_event(void *con_id)
+int hv_signal_event(void *con_id)
 {
-	u16 status;
+	u64 status;
 
-	status = (do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL) & 0xFFFF);
+	status = hv_do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL);
 
-	return status;
+	return status & 0xFFFF;
 }
 
 static int hv_ce_set_next_event(unsigned long delta,
drivers/hv/hyperv_vmbus.h +1 -1
index 12156db..9beeb14 100644
@@ -587,7 +587,7 @@ extern int hv_post_message(union hv_connection_id connection_id,
 			 enum hv_message_type message_type,
 			 void *payload, size_t payload_size);
 
-extern u16 hv_signal_event(void *con_id);
+extern int hv_signal_event(void *con_id);
 
 extern int hv_synic_alloc(void);
 
include/linux/hyperv.h +1 -0
index fddb3e0..24d0b65 100644
@@ -984,6 +984,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
 			bool fb_overlap_ok);
 
 int vmbus_cpu_number_to_vp_number(int cpu_number);
+u64 hv_do_hypercall(u64 control, void *input, void *output);
 
 /**
  * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
Signature · 1 line
1.7.4.1
maintainer
#10 lore raw

Re: [PATCH RESEND 09/27] drivers:hv: Export the API to invoke a hypercall on Hyper-V

Quoted 68 lines · K. Y. Srinivasan

From: Jake Oshins <[email protected]>

This patch exposes the function that hv_vmbus.ko uses to make hypercalls. This is necessary for retargeting an interrupt when it is given a new affinity.

Since we are exporting this API, rename the API as it will be visible outside the hv.c file.

---
 drivers/hv/hv.c           |   20 ++++++++++----------
 drivers/hv/hyperv_vmbus.h |    2 +-
 include/linux/hyperv.h    |    1 +
 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/hv/hv.c +6 -7
index 6341be8..7a06933 100644
@@ -89,9 +89,9 @@ static int query_hypervisor_info(void)
 }
 
 /*
- * do_hypercall- Invoke the specified hypercall
+ * hv_do_hypercall- Invoke the specified hypercall
  */
-static u64 do_hypercall(u64 control, void *input, void *output)
+u64 hv_do_hypercall(u64 control, void *input, void *output)
 {
 	u64 input_address = (input) ? virt_to_phys(input) : 0;
 	u64 output_address = (output) ? virt_to_phys(output) : 0;
@@ -132,6 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
 	return hv_status_lo | ((u64)hv_status_hi << 32);
 #endif /* !x86_64 */
 }
+EXPORT_SYMBOL_GPL(hv_do_hypercall);
 
 #ifdef CONFIG_X86_64
 static cycle_t read_hv_clock_tsc(struct clocksource *arg)
@@ -315,7 +316,7 @@ int hv_post_message(union hv_connection_id connection_id,
 {
 
 	struct hv_input_post_message *aligned_msg;
-	u16 status;
+	u64 status;
 
 	if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
 		return -EMSGSIZE;
@@ -329,11 +330,10 @@ int hv_post_message(union hv_connection_id connection_id,
 	aligned_msg->payload_size = payload_size;
 	memcpy((void *)aligned_msg->payload, payload, payload_size);
 
-	status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL)
-		& 0xFFFF;
+	status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL);
 
 	put_cpu();
-	return status;
+	return status & 0xFFFF;
 }
 
 
@@ -343,13 +343,13 @@ int hv_post_message(union hv_connection_id connection_id,
  *
  * This involves a hypercall.
  */
-u16 hv_signal_event(void *con_id)

drivers/hv/hv.c int hv_post_message(union hv_connection_id connection_id, · line 352

Quoted 10 lines
drivers/hv/hv.c +4 -3
+int hv_signal_event(void *con_id)
 {
-	u16 status;
+	u64 status;
 
-	status = (do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL) & 0xFFFF);
+	status = hv_do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL);
 
-	return status;
+	return status & 0xFFFF;

This "feels" odd, as the return value isn't the traditional 0 or -ERROR, right? Why are you masking off the top bits?

And, no one ever does anything with the return value of hv_signal_event(), so why have it return anything anyway?

I'll take this, but please fix up the area, it's messy...

greg k-h

#11 lore raw

RE: [PATCH RESEND 09/27] drivers:hv: Export the API to invoke a hypercall on Hyper-V

Quoted 102 lines

-----Original Message-----
From: Greg KH [mailto:[email protected]]
Sent: Monday, December 14, 2015 7:08 PM
To: KY Srinivasan <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jake Oshins <[email protected]>
Subject: Re: [PATCH RESEND 09/27] drivers:hv: Export the API to invoke a hypercall on Hyper-V

Quoted 3 lines · K. Y. Srinivasan

From: Jake Oshins <[email protected]>

This patch exposes the function that hv_vmbus.ko uses to make hypercalls.

This

drivers/hv/hv.c static u64 do_hypercall(u64 control, void *input,

Quoted 30 lines

is necessary for retargeting an interrupt when it is given a new affinity.

Since we are exporting this API, rename the API as it will be visible outside the hv.c file.

---
 drivers/hv/hv.c           |   20 ++++++++++----------
 drivers/hv/hyperv_vmbus.h |    2 +-
 include/linux/hyperv.h    |    1 +
 3 files changed, 12 insertions(+), 11 deletions(-)
drivers/hv/hv.c +2 -2
index 6341be8..7a06933 100644
@@ -89,9 +89,9 @@ static int query_hypervisor_info(void)
 }
 
 /*
- * do_hypercall- Invoke the specified hypercall
+ * hv_do_hypercall- Invoke the specified hypercall
  */
-static u64 do_hypercall(u64 control, void *input, void *output)
+u64 hv_do_hypercall(u64 control, void *input, void *output)
 {
 	u64 input_address = (input) ? virt_to_phys(input) : 0;
 	u64 output_address = (output) ? virt_to_phys(output) : 0;
@@ -132,6 +132,7 @@ static u64 do_hypercall(u64 control, void *input,

void *output)

drivers/hv/hv.c int hv_post_message(union hv_connection_id

Quoted 8 lines
drivers/hv/hv.c +1 -0
 	return hv_status_lo | ((u64)hv_status_hi << 32);
 #endif /* !x86_64 */
 }
+EXPORT_SYMBOL_GPL(hv_do_hypercall);
 
 #ifdef CONFIG_X86_64
 static cycle_t read_hv_clock_tsc(struct clocksource *arg)
@@ -315,7 +316,7 @@ int hv_post_message(union hv_connection_id

connection_id,

drivers/hv/hv.c int hv_post_message(union hv_connection_id

Quoted 9 lines
drivers/hv/hv.c +1 -1
 {
 
 	struct hv_input_post_message *aligned_msg;
-	u16 status;
+	u64 status;
 
 	if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT)
 		return -EMSGSIZE;
@@ -329,11 +330,10 @@ int hv_post_message(union hv_connection_id

connection_id,

drivers/hv/hv.c int hv_post_message(union hv_connection_id connection_id,

Quoted 6 lines
drivers/hv/hv.c +1 -2
 	aligned_msg->payload_size = payload_size;
 	memcpy((void *)aligned_msg->payload, payload, payload_size);
 
-	status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL)
-		& 0xFFFF;
+	status = hv_do_hypercall(HVCALL_POST_MESSAGE, aligned_msg,

NULL);

drivers/hv/hv.c int hv_post_message(union hv_connection_id

Quoted 8 lines
drivers/hv/hv.c +1 -1
 	put_cpu();
-	return status;
+	return status & 0xFFFF;
 }
 
 
@@ -343,13 +343,13 @@ int hv_post_message(union hv_connection_id

connection_id,

drivers/hv/hv.c int hv_post_message(union hv_connection_id connection_id,

Quoted 10 lines
drivers/hv/hv.c +2 -3
  *
  * This involves a hypercall.
  */
-u16 hv_signal_event(void *con_id)
+int hv_signal_event(void *con_id)
 {
-	u16 status;
+	u64 status;
 
-	status = (do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL) &

0xFFFF);

drivers/hv/hv.c int hv_post_message(union hv_connection_id connection_id, · line 352

Quoted 4 lines
drivers/hv/hv.c +2 -1
+	status = hv_do_hypercall(HVCALL_SIGNAL_EVENT, con_id, NULL);
 
-	return status;
+	return status & 0xFFFF;

This "feels" odd, as the return value isn't the traditional 0 or -ERROR, right? Why are you masking off the top bits?

Quoted 4 lines

And, no one ever does anything with the return value of hv_signal_event(), so why have it return anything anyway?

I'll take this, but please fix up the area, it's messy...

Thanks Greg. Will do.

K. Y

Quoted 2 lines

greg k-h

#12 lore raw

PATCH RESEND 10/27 drivers:hv: Define the channel type for Hyper-V PCI Express pass-through

In reply to K. Y. Srinivasan

From: Jake Oshins <[email protected]>

This defines the channel type for PCI front-ends in Hyper-V VMs.

---
 drivers/hv/channel_mgmt.c |    3 +++
 include/linux/hyperv.h    |   11 +++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)
drivers/hv/channel_mgmt.c +3 -0
index 652afd1..a77646b 100644
@@ -358,6 +358,7 @@ enum {
 	SCSI,
 	NIC,
 	ND_NIC,
+	PCIE,
 	MAX_PERF_CHN,
 };
 
@@ -375,6 +376,8 @@ static const struct hv_vmbus_device_id hp_devs[] = {
 	{ HV_NIC_GUID, },
 	/* NetworkDirect Guest RDMA */
 	{ HV_ND_GUID, },
+	/* PCI Express Pass Through */
+	{ HV_PCIE_GUID, },
 };
 
 
include/linux/hyperv.h +11 -0
index 24d0b65..c9a9eed 100644
@@ -1141,6 +1141,17 @@ u64 hv_do_hypercall(u64 control, void *input, void *output);
 		}
 
 /*
+ * PCI Express Pass Through
+ * {44C4F61D-4444-4400-9D52-802E27EDE19F}
+ */
+
+#define HV_PCIE_GUID \
+	.guid = { \
+			0x1D, 0xF6, 0xC4, 0x44, 0x44, 0x44, 0x00, 0x44, \
+			0x9D, 0x52, 0x80, 0x2E, 0x27, 0xED, 0xE1, 0x9F \
+		}
+
+/*
  * Common header for Hyper-V ICs
  */
 
Signature · 1 line
1.7.4.1
#13 lore raw

PATCH RESEND 11/27 Drivers: hv: vss: run only on supported host versions

In reply to K. Y. Srinivasan

From: Olaf Hering <[email protected]>

The Backup integration service on WS2012 has appearently trouble to negotiate with a guest which does not support the provided util version. Currently the VSS driver supports only version 5/0. A WS2012 offers only version 1/x and 3/x, and vmbus_prep_negotiate_resp correctly returns an empty icframe_vercnt/icmsg_vercnt. But the host ignores that and continues to send ICMSGTYPE_NEGOTIATE messages. The result are weird errors during boot and general misbehaviour.

Check the Windows version to work around the host bug, skip hv_vss_init on WS2012 and older.

---
 drivers/hv/hv_snapshot.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
drivers/hv/hv_snapshot.c +5 -0
index a548ae4..81882d4 100644
@@ -331,6 +331,11 @@ static void vss_on_reset(void)
 int
 hv_vss_init(struct hv_util_service *srv)
 {
+	if (vmbus_proto_version < VERSION_WIN8_1) {
+		pr_warn("Integration service 'Backup (volume snapshot)'"
+			" not supported on this host version.\n");
+		return -ENOTSUPP;
+	}
 	recv_buffer = srv->recv_buffer;
 
 	/*
Signature · 1 line
1.7.4.1
#14 lore raw

PATCH RESEND 12/27 Drivers: hv: vmbus: Use uuid_le type consistently

In reply to K. Y. Srinivasan

Consistently use uuid_le type in the Hyper-V driver code.

---
 drivers/hv/channel_mgmt.c       |    2 +-
 drivers/hv/vmbus_drv.c          |   10 ++--
 include/linux/hyperv.h          |   92 +++++++++++++-------------------------
 include/linux/mod_devicetable.h |    2 +-
 scripts/mod/file2alias.c        |    2 +-
 5 files changed, 40 insertions(+), 68 deletions(-)
drivers/hv/channel_mgmt.c +1 -1
index a77646b..38470aa 100644
@@ -408,7 +408,7 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui
 	struct cpumask *alloced_mask;
 
 	for (i = IDE; i < MAX_PERF_CHN; i++) {
-		if (!memcmp(type_guid->b, hp_devs[i].guid,
+		if (!memcmp(type_guid->b, &hp_devs[i].guid,
 				 sizeof(uuid_le))) {
 			perf_chn = true;
 			break;
drivers/hv/vmbus_drv.c +5 -5
index c01b689..7078b5f 100644
@@ -531,7 +531,7 @@ static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env)
 
 static const uuid_le null_guid;
 
-static inline bool is_null_guid(const __u8 *guid)
+static inline bool is_null_guid(const uuid_le *guid)
 {
 	if (memcmp(guid, &null_guid, sizeof(uuid_le)))
 		return false;
@@ -544,9 +544,9 @@ static inline bool is_null_guid(const __u8 *guid)
  */
 static const struct hv_vmbus_device_id *hv_vmbus_get_id(
 					const struct hv_vmbus_device_id *id,
-					const __u8 *guid)
+					const uuid_le *guid)
 {
-	for (; !is_null_guid(id->guid); id++)
+	for (; !is_null_guid(&id->guid); id++)
 		if (!memcmp(&id->guid, guid, sizeof(uuid_le)))
 			return id;
 
@@ -563,7 +563,7 @@ 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);
 
-	if (hv_vmbus_get_id(drv->id_table, hv_dev->dev_type.b))
+	if (hv_vmbus_get_id(drv->id_table, &hv_dev->dev_type))
 		return 1;
 
 	return 0;
@@ -580,7 +580,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.b);
+	dev_id = hv_vmbus_get_id(drv->id_table, &dev->dev_type);
 	if (drv->probe) {
 		ret = drv->probe(dev, dev_id);
 		if (ret != 0)
include/linux/hyperv.h +32 -60

186 lines not on this page · raw message

include/linux/mod_devicetable.h +1 -1
index 64f36e0..6e4c645 100644
@@ -404,7 +404,7 @@ struct virtio_device_id {
  * For Hyper-V devices we use the device guid as the id.
  */
 struct hv_vmbus_device_id {
-	__u8 guid[16];
+	uuid_le guid;
 	kernel_ulong_t driver_data;	/* Data private to the driver */
 };
 
scripts/mod/file2alias.c +1 -1
index 5b96206..8adca44 100644
@@ -917,7 +917,7 @@ static int do_vmbus_entry(const char *filename, void *symval,
 	char guid_name[(sizeof(*guid) + 1) * 2];
 
 	for (i = 0; i < (sizeof(*guid) * 2); i += 2)
-		sprintf(&guid_name[i], "%02x", TO_NATIVE((*guid)[i/2]));
+		sprintf(&guid_name[i], "%02x", TO_NATIVE((guid->b)[i/2]));
 
 	strcpy(alias, "vmbus:");
 	strcat(alias, guid_name);
Signature · 1 line
1.7.4.1
#15 lore raw

PATCH RESEND 13/27 Drivers: hv: vmbus: Use uuid_le_cmp() for comparing GUIDs

In reply to K. Y. Srinivasan

Use uuid_le_cmp() for comparing GUIDs.

---
 drivers/hv/channel_mgmt.c |    3 +--
 drivers/hv/vmbus_drv.c    |    4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/hv/channel_mgmt.c +1 -2
index 38470aa..dc4fb0b 100644
@@ -408,8 +408,7 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui
 	struct cpumask *alloced_mask;
 
 	for (i = IDE; i < MAX_PERF_CHN; i++) {
-		if (!memcmp(type_guid->b, &hp_devs[i].guid,
-				 sizeof(uuid_le))) {
+		if (!uuid_le_cmp(*type_guid, hp_devs[i].guid)) {
 			perf_chn = true;
 			break;
 		}
drivers/hv/vmbus_drv.c +2 -2
index 7078b5f..9e0e25c 100644
@@ -533,7 +533,7 @@ static const uuid_le null_guid;
 
 static inline bool is_null_guid(const uuid_le *guid)
 {
-	if (memcmp(guid, &null_guid, sizeof(uuid_le)))
+	if (uuid_le_cmp(*guid, null_guid))
 		return false;
 	return true;
 }
@@ -547,7 +547,7 @@ static const struct hv_vmbus_device_id *hv_vmbus_get_id(
 					const uuid_le *guid)
 {
 	for (; !is_null_guid(&id->guid); id++)
-		if (!memcmp(&id->guid, guid, sizeof(uuid_le)))
+		if (!uuid_le_cmp(id->guid, *guid))
 			return id;
 
 	return NULL;
Signature · 1 line
1.7.4.1
#16 lore raw

PATCH RESEND 14/27 Drivers: hv: vmbus: Get rid of the unused macro

In reply to K. Y. Srinivasan

The macro VMBUS_DEVICE() is unused; get rid of it.

---
 include/linux/hyperv.h |   13 -------------
 1 files changed, 0 insertions(+), 13 deletions(-)
include/linux/hyperv.h +0 -13
index b9f3bb2..f773a68 100644
@@ -986,19 +986,6 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
 int vmbus_cpu_number_to_vp_number(int cpu_number);
 u64 hv_do_hypercall(u64 control, void *input, void *output);
 
-/**
- * VMBUS_DEVICE - macro used to describe a specific hyperv vmbus device
- *
- * This macro is used to create a struct hv_vmbus_device_id that matches a
- * specific device.
- */
-#define VMBUS_DEVICE(g0, g1, g2, g3, g4, g5, g6, g7,	\
-		     g8, g9, ga, gb, gc, gd, ge, gf)	\
-	.guid = { g0, g1, g2, g3, g4, g5, g6, g7,	\
-		  g8, g9, ga, gb, gc, gd, ge, gf },
-
-
-
 /*
  * GUID definitions of various offer types - services offered to the guest.
  */
Signature · 1 line
1.7.4.1
#17 lore raw

PATCH RESEND 15/27 Drivers: hv: vmbus: Get rid of the unused irq variable

In reply to K. Y. Srinivasan

The irq we extract from ACPI is not used - we deliver hypervisor interrupts on a special vector. Make the necessary adjustments.

---
 drivers/hv/vmbus_drv.c |   16 +++-------------
 1 files changed, 3 insertions(+), 13 deletions(-)
drivers/hv/vmbus_drv.c +3 -13
index 9e0e25c..ab888a1 100644
@@ -47,7 +47,6 @@ static struct acpi_device  *hv_acpi_dev;
 
 static struct tasklet_struct msg_dpc;
 static struct completion probe_event;
-static int irq;
 
 
 static void hyperv_report_panic(struct pt_regs *regs)
@@ -835,10 +834,9 @@ static void vmbus_isr(void)
  * Here, we
  *	- initialize the vmbus driver context
  *	- invoke the vmbus hv main init routine
- *	- get the irq resource
  *	- retrieve the channel offers
  */
-static int vmbus_bus_init(int irq)
+static int vmbus_bus_init(void)
 {
 	int ret;
 
@@ -1033,9 +1031,6 @@ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx)
 	struct resource **prev_res = NULL;
 
 	switch (res->type) {
-	case ACPI_RESOURCE_TYPE_IRQ:
-		irq = res->data.irq.interrupts[0];
-		return AE_OK;
 
 	/*
 	 * "Address" descriptors are for bus windows. Ignore
@@ -1294,7 +1289,7 @@ static int __init hv_acpi_init(void)
 	init_completion(&probe_event);
 
 	/*
-	 * Get irq resources first.
+	 * Get ACPI resources first.
 	 */
 	ret = acpi_bus_register_driver(&vmbus_acpi_driver);
 
@@ -1307,12 +1302,7 @@ static int __init hv_acpi_init(void)
 		goto cleanup;
 	}
 
-	if (irq <= 0) {
-		ret = -ENODEV;
-		goto cleanup;
-	}
-
-	ret = vmbus_bus_init(irq);
+	ret = vmbus_bus_init();
 	if (ret)
 		goto cleanup;
 
Signature · 1 line
1.7.4.1
#18 lore raw

PATCH RESEND 16/27 Drivers: hv: vmbus: serialize process_chn_event() and vmbus_close_internal()

In reply to K. Y. Srinivasan

From: Dexuan Cui <[email protected]>

process_chn_event(), running in the tasklet, can race with vmbus_close_internal() in the case of SMP guest, e.g., when the former is accessing channel->inbound.ring_buffer, the latter could be freeing the ring_buffer pages.

To resolve the race, we can serialize them by disabling the tasklet when the latter is running here.

---
 drivers/hv/channel.c |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)
drivers/hv/channel.c +19 -2
index c4dcab0..f7f3d5c 100644
@@ -28,6 +28,7 @@
 #include <linux/module.h>
 #include <linux/hyperv.h>
 #include <linux/uio.h>
+#include <linux/interrupt.h>
 
 #include "hyperv_vmbus.h"
 
@@ -496,8 +497,21 @@ static void reset_channel_cb(void *arg)
 static int vmbus_close_internal(struct vmbus_channel *channel)
 {
 	struct vmbus_channel_close_channel *msg;
+	struct tasklet_struct *tasklet;
 	int ret;
 
+	/*
+	 * process_chn_event(), running in the tasklet, can race
+	 * with vmbus_close_internal() in the case of SMP guest, e.g., when
+	 * the former is accessing channel->inbound.ring_buffer, the latter
+	 * could be freeing the ring_buffer pages.
+	 *
+	 * To resolve the race, we can serialize them by disabling the
+	 * tasklet when the latter is running here.
+	 */
+	tasklet = hv_context.event_dpc[channel->target_cpu];
+	tasklet_disable(tasklet);
+
 	channel->state = CHANNEL_OPEN_STATE;
 	channel->sc_creation_callback = NULL;
 	/* Stop callback and cancel the timer asap */
@@ -525,7 +539,7 @@ static int vmbus_close_internal(struct vmbus_channel *channel)
 		 * If we failed to post the close msg,
 		 * it is perhaps better to leak memory.
 		 */
-		return ret;
+		goto out;
 	}
 
 	/* Tear down the gpadl for the channel's ring buffer */
@@ -538,7 +552,7 @@ static int vmbus_close_internal(struct vmbus_channel *channel)
 			 * If we failed to teardown gpadl,
 			 * it is perhaps better to leak memory.
 			 */
-			return ret;
+			goto out;
 		}
 	}
 
@@ -555,6 +569,9 @@ static int vmbus_close_internal(struct vmbus_channel *channel)
 	if (channel->rescind)
 		hv_process_channel_removal(channel,
 					   channel->offermsg.child_relid);
+out:
+	tasklet_enable(tasklet);
+
 	return ret;
 }
 
Signature · 1 line
1.7.4.1
#19 lore raw

PATCH RESEND 17/27 Drivers: hv: vmbus: do sanity check of channel state in vmbus_close_internal()

In reply to K. Y. Srinivasan

From: Dexuan Cui <[email protected]>

This fixes an incorrect assumption of channel state in the function.

---
 drivers/hv/channel.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
drivers/hv/channel.c +12 -0
index f7f3d5c..00e1be7 100644
@@ -512,6 +512,18 @@ static int vmbus_close_internal(struct vmbus_channel *channel)
 	tasklet = hv_context.event_dpc[channel->target_cpu];
 	tasklet_disable(tasklet);
 
+	/*
+	 * In case a device driver's probe() fails (e.g.,
+	 * util_probe() -> vmbus_open() returns -ENOMEM) and the device is
+	 * rescinded later (e.g., we dynamically disble an Integrated Service
+	 * in Hyper-V Manager), the driver's remove() invokes vmbus_close():
+	 * here we should skip most of the below cleanup work.
+	 */
+	if (channel->state != CHANNEL_OPENED_STATE) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	channel->state = CHANNEL_OPEN_STATE;
 	channel->sc_creation_callback = NULL;
 	/* Stop callback and cancel the timer asap */
Signature · 1 line
1.7.4.1
#20 lore raw

PATCH RESEND 18/27 Drivers: hv: vmbus: fix rescind-offer handling for device without a driver

In reply to K. Y. Srinivasan

From: Dexuan Cui <[email protected]>

In the path vmbus_onoffer_rescind() -> vmbus_device_unregister() -> device_unregister() -> ... -> __device_release_driver(), we can see for a device without a driver loaded: dev->driver is NULL, so dev->bus->remove(dev), namely vmbus_remove(), isn't invoked.

As a result, vmbus_remove() -> hv_process_channel_removal() isn't invoked and some cleanups(like sending a CHANNELMSG_RELID_RELEASED message to the host) aren't done.

We can demo the issue this way:
1. rmmod hv_utils;
2. disable the Heartbeat Integration Service in Hyper-V Manager and lsvmbus shows the device disappears.
3. re-enable the Heartbeat in Hyper-V Manager and modprobe hv_utils, but lsvmbus shows the device can't appear again.
This is because, the host thinks the VM hasn't released the relid, so can't re-offer the device to the VM.

We can fix the issue by moving hv_process_channel_removal() from vmbus_close_internal() to vmbus_device_release(), since the latter is always invoked on device_unregister(), whether or not the dev has a driver loaded.

---
 drivers/hv/channel.c      |    6 ------
 drivers/hv/channel_mgmt.c |    6 +++---
 drivers/hv/vmbus_drv.c    |   15 +++------------
 3 files changed, 6 insertions(+), 21 deletions(-)
drivers/hv/channel.c +0 -6
index 00e1be7..77d2579 100644
@@ -575,12 +575,6 @@ static int vmbus_close_internal(struct vmbus_channel *channel)
 	free_pages((unsigned long)channel->ringbuffer_pages,
 		get_order(channel->ringbuffer_pagecount * PAGE_SIZE));
 
-	/*
-	 * If the channel has been rescinded; process device removal.
-	 */
-	if (channel->rescind)
-		hv_process_channel_removal(channel,
-					   channel->offermsg.child_relid);
 out:
 	tasklet_enable(tasklet);
 
drivers/hv/channel_mgmt.c +3 -3
index dc4fb0b..7903acc 100644
@@ -191,6 +191,8 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)
 	if (channel == NULL)
 		return;
 
+	BUG_ON(!channel->rescind);
+
 	if (channel->target_cpu != get_cpu()) {
 		put_cpu();
 		smp_call_function_single(channel->target_cpu,
@@ -230,9 +232,7 @@ void vmbus_free_channels(void)
 
 	list_for_each_entry_safe(channel, tmp, &vmbus_connection.chn_list,
 		listentry) {
-		/* if we don't set rescind to true, vmbus_close_internal()
-		 * won't invoke hv_process_channel_removal().
-		 */
+		/* hv_process_channel_removal() needs this */
 		channel->rescind = true;
 
 		vmbus_device_unregister(channel->device_obj);
drivers/hv/vmbus_drv.c +3 -12
index ab888a1..f123bca 100644
@@ -601,23 +601,11 @@ static int vmbus_remove(struct device *child_device)
 {
 	struct hv_driver *drv;
 	struct hv_device *dev = device_to_hv_device(child_device);
-	u32 relid = dev->channel->offermsg.child_relid;
 
 	if (child_device->driver) {
 		drv = drv_to_hv_drv(child_device->driver);
 		if (drv->remove)
 			drv->remove(dev);
-		else {
-			hv_process_channel_removal(dev->channel, relid);
-			pr_err("remove not set for driver %s\n",
-				dev_name(child_device));
-		}
-	} else {
-		/*
-		 * We don't have a driver for this device; deal with the
-		 * rescind message by removing the channel.
-		 */
-		hv_process_channel_removal(dev->channel, relid);
 	}
 
 	return 0;
@@ -652,7 +640,10 @@ static void vmbus_shutdown(struct device *child_device)
 static void vmbus_device_release(struct device *device)
 {
 	struct hv_device *hv_dev = device_to_hv_device(device);
+	struct vmbus_channel *channel = hv_dev->channel;
 
+	hv_process_channel_removal(channel,
+				   channel->offermsg.child_relid);
 	kfree(hv_dev);
 
 }
Signature · 1 line
1.7.4.1
#21 lore raw

PATCH RESEND 19/27 Drivers: hv: vmbus: release relid on error in vmbus_process_offer()

In reply to K. Y. Srinivasan

From: Dexuan Cui <[email protected]>

We want to simplify vmbus_onoffer_rescind() by not invoking hv_process_channel_removal(NULL, ...).

---
 drivers/hv/channel_mgmt.c |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 deletions(-)
drivers/hv/channel_mgmt.c +15 -6
index 7903acc..9c9da3a 100644
@@ -177,19 +177,22 @@ static void percpu_channel_deq(void *arg)
 }
 
 
-void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)
+static void vmbus_release_relid(u32 relid)
 {
 	struct vmbus_channel_relid_released msg;
-	unsigned long flags;
-	struct vmbus_channel *primary_channel;
 
 	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));
+}
 
-	if (channel == NULL)
-		return;
+void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)
+{
+	unsigned long flags;
+	struct vmbus_channel *primary_channel;
+
+	vmbus_release_relid(relid);
 
 	BUG_ON(!channel->rescind);
 
@@ -336,6 +339,8 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
 	return;
 
 err_deq_chan:
+	vmbus_release_relid(newchannel->offermsg.child_relid);
+
 	spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
 	list_del(&newchannel->listentry);
 	spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
@@ -587,7 +592,11 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr)
 	channel = relid2channel(rescind->child_relid);
 
 	if (channel == NULL) {
-		hv_process_channel_removal(NULL, rescind->child_relid);
+		/*
+		 * This is very impossible, because in
+		 * vmbus_process_offer(), we have already invoked
+		 * vmbus_release_relid() on error.
+		 */
 		return;
 	}
 
Signature · 1 line
1.7.4.1
#22 lore raw

PATCH RESEND 20/27 Drivers: hv: vmbus: channge vmbus_connection.channel_lock to mutex

In reply to K. Y. Srinivasan

From: Dexuan Cui <[email protected]>

spinlock is unnecessary here.
mutex is enough.

---
 drivers/hv/channel_mgmt.c |   12 ++++++------
 drivers/hv/connection.c   |    7 +++----
 drivers/hv/hyperv_vmbus.h |    2 +-
 3 files changed, 10 insertions(+), 11 deletions(-)
drivers/hv/channel_mgmt.c +6 -6
index 9c9da3a..d013171 100644
@@ -206,9 +206,9 @@ void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid)
 	}
 
 	if (channel->primary_channel == NULL) {
-		spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
+		mutex_lock(&vmbus_connection.channel_mutex);
 		list_del(&channel->listentry);
-		spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
+		mutex_unlock(&vmbus_connection.channel_mutex);
 
 		primary_channel = channel;
 	} else {
@@ -253,7 +253,7 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
 	unsigned long flags;
 
 	/* Make sure this is a new offer */
-	spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
+	mutex_lock(&vmbus_connection.channel_mutex);
 
 	list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
 		if (!uuid_le_cmp(channel->offermsg.offer.if_type,
@@ -269,7 +269,7 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
 		list_add_tail(&newchannel->listentry,
 			      &vmbus_connection.chn_list);
 
-	spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
+	mutex_unlock(&vmbus_connection.channel_mutex);
 
 	if (!fnew) {
 		/*
@@ -341,9 +341,9 @@ static void vmbus_process_offer(struct vmbus_channel *newchannel)
 err_deq_chan:
 	vmbus_release_relid(newchannel->offermsg.child_relid);
 
-	spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
+	mutex_lock(&vmbus_connection.channel_mutex);
 	list_del(&newchannel->listentry);
-	spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
+	mutex_unlock(&vmbus_connection.channel_mutex);
 
 	if (newchannel->target_cpu != get_cpu()) {
 		put_cpu();
drivers/hv/connection.c +3 -4
index 4fc2e88..521f48e 100644
@@ -146,7 +146,7 @@ int vmbus_connect(void)
 	spin_lock_init(&vmbus_connection.channelmsg_lock);
 
 	INIT_LIST_HEAD(&vmbus_connection.chn_list);
-	spin_lock_init(&vmbus_connection.channel_lock);
+	mutex_init(&vmbus_connection.channel_mutex);
 
 	/*
 	 * Setup the vmbus event connection for channel interrupt
@@ -282,11 +282,10 @@ struct vmbus_channel *relid2channel(u32 relid)
 {
 	struct vmbus_channel *channel;
 	struct vmbus_channel *found_channel  = NULL;
-	unsigned long flags;
 	struct list_head *cur, *tmp;
 	struct vmbus_channel *cur_sc;
 
-	spin_lock_irqsave(&vmbus_connection.channel_lock, flags);
+	mutex_lock(&vmbus_connection.channel_mutex);
 	list_for_each_entry(channel, &vmbus_connection.chn_list, listentry) {
 		if (channel->offermsg.child_relid == relid) {
 			found_channel = channel;
@@ -305,7 +304,7 @@ struct vmbus_channel *relid2channel(u32 relid)
 			}
 		}
 	}
-	spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags);
+	mutex_unlock(&vmbus_connection.channel_mutex);
 
 	return found_channel;
 }
drivers/hv/hyperv_vmbus.h +1 -1
index 9beeb14..4d67e98 100644
@@ -683,7 +683,7 @@ struct vmbus_connection {
 
 	/* List of channels */
 	struct list_head chn_list;
-	spinlock_t channel_lock;
+	struct mutex channel_mutex;
 
 	struct workqueue_struct *work_queue;
 };
Signature · 1 line
1.7.4.1
#23 lore raw

PATCH RESEND 21/27 drivers:hv: Allow for MMIO claims that span ACPI _CRS records

In reply to K. Y. Srinivasan

From: Jake Oshins <[email protected]>

This patch makes 16GB GPUs work in Hyper-V VMs, since, for compatibility reasons, the Hyper-V BIOS lists MMIO ranges in 2GB chunks in its root bus's _CRS object.

---
 drivers/hv/vmbus_drv.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
drivers/hv/vmbus_drv.c +16 -0
index f123bca..328e4c3 100644
@@ -1063,12 +1063,28 @@ static acpi_status vmbus_walk_resources(struct acpi_resource *res, void *ctx)
 	new_res->start = start;
 	new_res->end = end;
 
+	/*
+	 * Stick ranges from higher in address space at the front of the list.
+	 * If two ranges are adjacent, merge them.
+	 */
 	do {
 		if (!*old_res) {
 			*old_res = new_res;
 			break;
 		}
 
+		if (((*old_res)->end + 1) == new_res->start) {
+			(*old_res)->end = new_res->end;
+			kfree(new_res);
+			break;
+		}
+
+		if ((*old_res)->start == new_res->end + 1) {
+			(*old_res)->start = new_res->start;
+			kfree(new_res);
+			break;
+		}
+
 		if ((*old_res)->end < new_res->start) {
 			new_res->sibling = *old_res;
 			if (prev_res)
Signature · 1 line
1.7.4.1
#24 lore raw

PATCH RESEND 22/27 tools/hv: Use include/uapi with __EXPORTED_HEADERS__

In reply to K. Y. Srinivasan

From: Kamal Mostafa <[email protected]>

Use the local uapi headers to keep in sync with "recently" added #define's (e.g. VSS_OP_REGISTER1).

Fixes 3eb2094c59e89db2bedd401e23c7a870081c9edb
---
 tools/hv/Makefile |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/hv/Makefile +2 -0
index a8ab795..a8c4644 100644
@@ -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
maintainer
#25 lore raw

Re: [PATCH RESEND 22/27] tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Quoted 6 lines · K. Y. Srinivasan

From: Kamal Mostafa <[email protected]>

Use the local uapi headers to keep in sync with "recently" added #define's (e.g. VSS_OP_REGISTER1).

Fixes 3eb2094c59e89db2bedd401e23c7a870081c9edb

Please use the "correct" way of listing this:

	3eb2094c59e8 ("Adding makefile for tools/hv")

And as this is an old kernel, shouldn't it go into stable releases? Or does that mean that no one really ever runs into this issue?

Quoted 11 lines
---
 tools/hv/Makefile |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/hv/Makefile +0 -0
index a8ab795..a8c4644 100644

tools/hv/Makefile PTHREAD_LIBS = -lpthread · line 8

Quoted 4 lines
tools/hv/Makefile +1 -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

Why do you need ../../include also?

thanks,

greg k-h

#26 lore raw

Re: [PATCH RESEND 22/27] tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Quoted 6 lines · Greg KH
Quoted 5 lines · K. Y. Srinivasan

From: Kamal Mostafa <[email protected]>

Use the local uapi headers to keep in sync with "recently" added #define's (e.g. VSS_OP_REGISTER1).

Quoted 6 lines
Quoted 1 line
Fixes 3eb2094c59e89db2bedd401e23c7a870081c9edb

Please use the "correct" way of listing this:

	3eb2094c59e8 ("Adding makefile for tools/hv")

And as this is an old kernel, shouldn't it go into stable releases?

Yes it should. I'll resubmit with Cc: stable and correct the Fixes line.

Quoted 17 lines

Or
does that mean that no one really ever runs into this issue?

Quoted 14 lines
---
 tools/hv/Makefile |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
tools/hv/Makefile +0 -0
index a8ab795..a8c4644 100644
@@ -5,6 +5,8 @@ PTHREAD_LIBS = -lpthread
 WARNINGS = -Wall -Wextra
 CFLAGS = $(WARNINGS) -g $(PTHREAD_LIBS) $(shell getconf LFS_CFLAGS)
 
Quoted 3 lines

tools/hv/Makefile PTHREAD_LIBS = -lpthread · line 8

Quoted 1 line
tools/hv/Makefile +1 -0
+CFLAGS += -D__EXPORTED_HEADERS__ -I../../include/uapi -I../../include

Why do you need ../../include also?

Because include/uapi/linux/stddef.h includes linux/compiler.h, so omitting ../../include yields:

gcc -Wall -Wextra -g -lpthread -D__EXPORTED_HEADERS__ -I../../include/uapi -o hv_kvp_daemon hv_kvp_daemon.c In file included from ../../include/uapi/linux/posix_types.h:4:0,

                 from ../../include/uapi/linux/types.h:13,
                 from ../../include/uapi/linux/uuid.h:24,
                 from ../../include/uapi/linux/hyperv.h:28,
                 from hv_kvp_daemon.c:36:
../../include/uapi/linux/stddef.h:1:28: fatal error: linux/compiler.h: No such file or directory
 #include <linux/compiler.h>
                            ^

-Kamal

#27 lore raw

PATCH v2 1/1 tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Quoted 1 line

From f424410bf4a6a0dd6ff88bec808798016f4161a0 Mon Sep 17 00:00:00 2001

From: Kamal Mostafa <[email protected]>
Date: Wed, 11 Nov 2015 19:16:59 +0000
Subject: tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Use the local uapi headers to keep in sync with "recently" added #define's (e.g. VSS_OP_REGISTER1).

Fixes 3eb2094c59e8 ("Adding makefile for tools/hv")
---
 tools/hv/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/hv/Makefile +2 -0
index a8ab795..a8c4644 100644
@@ -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.9.1
maintainer
#28 lore raw

Re: [PATCH v2] tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Quoted 4 lines · Kamal Mostafa
Quoted 1 line

From f424410bf4a6a0dd6ff88bec808798016f4161a0 Mon Sep 17 00:00:00 2001

From: Kamal Mostafa <[email protected]>
Date: Wed, 11 Nov 2015 19:16:59 +0000
Subject: tools/hv: Use include/uapi with __EXPORTED_HEADERS__

Why is all of this mess here?

Please don't do that...

#29 lore raw

PATCH RESEND v2 1/1 tools/hv: Use include/uapi with __EXPORTED_HEADERS__

In reply to Kamal Mostafa

Use the local uapi headers to keep in sync with "recently" added #define's (e.g. VSS_OP_REGISTER1).

Fixes 3eb2094c59e8 ("Adding makefile for tools/hv")
---
 tools/hv/Makefile | 2 ++
 1 file changed, 2 insertions(+)
tools/hv/Makefile +2 -0
index a8ab795..a8c4644 100644
@@ -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.9.1
#30 lore raw

PATCH RESEND 23/27 Drivers: hv: vmbus: Fix a Host signaling bug

In reply to K. Y. Srinivasan

Currently we have two policies for deciding when to signal the host:
One based on the ring buffer state and the other based on what the VMBUS client driver wants to do. Consider the case when the client wants to explicitly control when to signal the host. In this case, if the client were to defer signaling, we will not be able to signal the host subsequently when the client does want to signal since the ring buffer state will prevent the signaling. Implement logic to have only one signaling policy in force for a given channel.

---
 drivers/hv/channel.c   |   18 ++++++++++++++++++
 include/linux/hyperv.h |   18 ++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
drivers/hv/channel.c +18 -0
index 77d2579..2889d97 100644
@@ -653,10 +653,19 @@ int vmbus_sendpacket_ctl(struct vmbus_channel *channel, void *buffer,
 	 *    on the ring. We will not signal if more data is
 	 *    to be placed.
 	 *
+	 * Based on the channel signal state, we will decide
+	 * which signaling policy will be applied.
+	 *
 	 * 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.
 	 */
+
+	if (channel->signal_policy)
+		signal = true;
+	else
+		kick_q = true;
+
 	if (((ret == 0) && kick_q && signal) || (ret))
 		vmbus_setevent(channel);
 
@@ -756,10 +765,19 @@ int vmbus_sendpacket_pagebuffer_ctl(struct vmbus_channel *channel,
 	 *    on the ring. We will not signal if more data is
 	 *    to be placed.
 	 *
+	 * Based on the channel signal state, we will decide
+	 * which signaling policy will be applied.
+	 *
 	 * 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.
 	 */
+
+	if (channel->signal_policy)
+		signal = true;
+	else
+		kick_q = true;
+
 	if (((ret == 0) && kick_q && signal) || (ret))
 		vmbus_setevent(channel);
 
include/linux/hyperv.h +18 -0
index f773a68..acd995b 100644
@@ -630,6 +630,11 @@ struct hv_input_signal_event_buffer {
 	struct hv_input_signal_event event;
 };
 
+enum hv_signal_policy {
+	HV_SIGNAL_POLICY_DEFAULT = 0,
+	HV_SIGNAL_POLICY_EXPLICIT,
+};
+
 struct vmbus_channel {
 	/* Unique channel id */
 	int id;
@@ -757,8 +762,21 @@ struct vmbus_channel {
 	 * link up channels based on their CPU affinity.
 	 */
 	struct list_head percpu_list;
+	/*
+	 * Host signaling policy: The default policy will be
+	 * based on the ring buffer state. We will also support
+	 * a policy where the client driver can have explicit
+	 * signaling control.
+	 */
+	enum hv_signal_policy  signal_policy;
 };
 
+static inline void set_channel_signal_state(struct vmbus_channel *c,
+					    enum hv_signal_policy policy)
+{
+	c->signal_policy = policy;
+}
+
 static inline void set_channel_read_state(struct vmbus_channel *c, bool state)
 {
 	c->batched_reading = state;
Signature · 1 line
1.7.4.1
#31 lore raw

PATCH RESEND 24/27 drivers/hv: correct tsc page sequence invalid value

In reply to K. Y. Srinivasan

From: Andrey Smetanin <[email protected]>

Hypervisor Top Level Functional Specification v3/4 says that TSC page sequence value = -1(0xFFFFFFFF) is used to indicate that TSC page no longer reliable source of reference timer. Unfortunately, we found that Windows Hyper-V guest side implementation uses sequence value = 0 to indicate that Tsc page no longer valid. This is clearly visible inside Windows 2012R2 ntoskrnl.exe HvlGetReferenceTime() function dissassembly:

HvlGetReferenceTime proc near
xchg ax, ax
loc_1401C3132:

                 mov     rax, cs:HvlpReferenceTscPage
                 mov     r9d, [rax]
                 test    r9d, r9d
                 jz      short loc_1401C3176

rdtsc
mov rcx, cs:HvlpReferenceTscPage
shl rdx, 20h
or rdx, rax
mov rax, [rcx+8]
mov rcx, cs:HvlpReferenceTscPage
mov r8, [rcx+10h]
mul rdx
mov rax, cs:HvlpReferenceTscPage
add rdx, r8
mov ecx, [rax]
cmp ecx, r9d
jnz short loc_1401C3132
jmp short loc_1401C3184
loc_1401C3176:
mov ecx, 40000020h
rdmsr
shl rdx, 20h
or rdx, rax
loc_1401C3184:
mov rax, rdx
retn
HvlGetReferenceTime endp

This patch aligns Tsc page invalid sequence value with Windows Hyper-V guest implementation which is more compatible with both Hyper-V hypervisor and KVM hypervisor.

CC "K. Y. Srinivasan" <[email protected]>
CC Haiyang Zhang <[email protected]>
CC Vitaly Kuznetsov <[email protected]>
---
 drivers/hv/hv.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv.c +2 -2
index 7a06933..1db9556 100644
@@ -140,7 +140,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource *arg)
 	cycle_t current_tick;
 	struct ms_hyperv_tsc_page *tsc_pg = hv_context.tsc_page;
 
-	if (tsc_pg->tsc_sequence != -1) {
+	if (tsc_pg->tsc_sequence != 0) {
 		/*
 		 * Use the tsc page to compute the value.
 		 */
@@ -162,7 +162,7 @@ static cycle_t read_hv_clock_tsc(struct clocksource *arg)
 			if (tsc_pg->tsc_sequence == sequence)
 				return current_tick;
 
-			if (tsc_pg->tsc_sequence != -1)
+			if (tsc_pg->tsc_sequence != 0)
 				continue;
 			/*
 			 * Fallback using MSR method.
Signature · 1 line
1.7.4.1
#32 lore raw

PATCH RESEND 25/27 Drivers: hv: vmbus: Force all channel messages to be delivered on CPU 0

In reply to K. Y. Srinivasan

Force all channel messages to be delivered on CPU0. These messages are not performance critical and are used during the setup and teardown of the channel.

---
 drivers/hv/connection.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
drivers/hv/connection.c +7 -4
index 521f48e..3dc5a9c 100644
@@ -83,10 +83,13 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo,
 	msg->interrupt_page = virt_to_phys(vmbus_connection.int_page);
 	msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]);
 	msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]);
-	if (version >= VERSION_WIN8_1) {
-		msg->target_vcpu = hv_context.vp_index[get_cpu()];
-		put_cpu();
-	}
+	/*
+	 * We want all channel messages to be delivered on CPU 0.
+	 * This has been the behavior pre-win8. This is not
+	 * perf issue and having all channel messages delivered on CPU 0
+	 * would be ok.
+	 */
+	msg->target_vcpu = 0;
 
 	/*
 	 * Add to list before we send the request since we may
Signature · 1 line
1.7.4.1
#33 lore raw

PATCH RESEND 26/27 Drivers: hv: utils: Invoke the poll function after handshake

In reply to K. Y. Srinivasan

When the handshake with daemon is complete, we should poll the channel since during the handshake, we will not be processing any messages. This is a potential bug if the host is waiting for a response from the guest. I would like to thank Dexuan for pointing this out.

---
 drivers/hv/hv_kvp.c      |    2 +-
 drivers/hv/hv_snapshot.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/hv/hv_kvp.c +1 -1
index 2a3420c..d4ab81b 100644
@@ -154,7 +154,7 @@ 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);
-	kvp_transaction.state = HVUTIL_READY;
+	hv_poll_channel(kvp_transaction.recv_channel, kvp_poll_wrapper);
 
 	return 0;
 }
drivers/hv/hv_snapshot.c +1 -1
index 81882d4..67def4a 100644
@@ -113,7 +113,7 @@ static int vss_handle_handshake(struct hv_vss_msg *vss_msg)
 	default:
 		return -EINVAL;
 	}
-	vss_transaction.state = HVUTIL_READY;
+	hv_poll_channel(vss_transaction.recv_channel, vss_poll_wrapper);
 	pr_debug("VSS: userspace daemon ver. %d registered\n", dm_reg_value);
 	return 0;
 }
Signature · 1 line
1.7.4.1
#34 lore raw

PATCH RESEND 27/27 tools: hv: vss: fix the write()'s argument: error -> vss_msg

In reply to K. Y. Srinivasan

From: Dexuan Cui <[email protected]>

Fix the write()'s argument in the daemon code.

---
 tools/hv/hv_vss_daemon.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/hv/hv_vss_daemon.c +1 -1
index 96234b6..5d51d6f 100644
@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
 			syslog(LOG_ERR, "Illegal op:%d\n", op);
 		}
 		vss_msg->error = error;
-		len = write(vss_fd, &error, sizeof(struct hv_vss_msg));
+		len = write(vss_fd, vss_msg, sizeof(struct hv_vss_msg));
 		if (len != sizeof(struct hv_vss_msg)) {
 			syslog(LOG_ERR, "write failed; error: %d %s", errno,
 			       strerror(errno));
Signature · 1 line
1.7.4.1