Skip to contentSkip to conversation

Low speed Hyper-V devices support

PATCH Superseded Saurabh Sengar 3 participants 26 messages Feb 17, 2024 – Mar 13, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Low speed Hyper-V devices support

Hyper-V is adding multiple low speed "speciality" synthetic devices. Instead of writing a new kernel-level VMBus driver for each device, make the devices accessible to user space through UIO-based uio_hv_generic driver. Each device can then be supported by a user space driver. This approach optimizes the development process and provides flexibility to user space applications to control the key interactions with the VMBus ring buffer.

The new synthetic devices are low speed devices that don't support VMBus monitor bits, and so they must use vmbus_setevent() to notify the host of ring buffer updates. These new devices also have smaller ring buffer sizes which requires to add support for variable ring buffer sizes.

Moreover, this patch series adds a new implementation of the fcopy application that uses the new UIO driver. The older fcopy driver and application will be phased out gradually. Development of other similar userspace drivers is still underway.

Efforts have been made previously to implement this solution earlier. Here are the discussions related to those attempts:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

Saurabh Sengar (6):
Drivers: hv: vmbus: Add utility function for querying ring size
uio_hv_generic: Query the ringbuffer size for device
uio_hv_generic: Enable interrupt for low speed VMBus devices
tools: hv: Add vmbus_bufring
tools: hv: Add new fcopy application based on uio driver
Drivers: hv: Remove fcopy driver

 drivers/hv/Makefile            |   2 +-
 drivers/hv/channel_mgmt.c      |   7 +-
 drivers/hv/hv_fcopy.c          | 427 -----------------------------
 drivers/hv/hv_util.c           |  12 -
 drivers/hv/hyperv_vmbus.h      |   5 +
 drivers/uio/uio_hv_generic.c   |  14 +-
 include/linux/hyperv.h         |   1 +
 tools/hv/Build                 |   3 +-
 tools/hv/Makefile              |  10 +-
 tools/hv/hv_fcopy_daemon.c     | 266 ------------------
 tools/hv/hv_fcopy_uio_daemon.c | 488 +++++++++++++++++++++++++++++++++
 tools/hv/vmbus_bufring.c       | 316 +++++++++++++++++++++
 tools/hv/vmbus_bufring.h       | 158 +++++++++++
 13 files changed, 988 insertions(+), 721 deletions(-)
 delete mode 100644 drivers/hv/hv_fcopy.c
 delete mode 100644 tools/hv/hv_fcopy_daemon.c
 create mode 100644 tools/hv/hv_fcopy_uio_daemon.c
 create mode 100644 tools/hv/vmbus_bufring.c
 create mode 100644 tools/hv/vmbus_bufring.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/6 Drivers: hv: vmbus: Add utility function for querying ring size

Add a function to query for the preferred ring buffer size of VMBus device.

---
 drivers/hv/channel_mgmt.c | 7 +++++--
 drivers/hv/hyperv_vmbus.h | 5 +++++
 include/linux/hyperv.h    | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)
drivers/hv/channel_mgmt.c +5 -2
index 2f4d09ce027a..7ea444d72f9f 100644
@@ -120,7 +120,8 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* File copy */
-	{ .dev_type = HV_FCOPY,
+	{ .pref_ring_size = 0x4000,
+	  .dev_type = HV_FCOPY,
 	  HV_FCOPY_GUID,
 	  .perf_device = false,
 	  .allowed_in_isolated = false,
@@ -141,11 +142,13 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* Unknown GUID */
-	{ .dev_type = HV_UNKNOWN,
+	{ .pref_ring_size = 0x11000,
+	  .dev_type = HV_UNKNOWN,
 	  .perf_device = false,
 	  .allowed_in_isolated = false,
 	},
 };
+EXPORT_SYMBOL_GPL(vmbus_devs);
 
 static const struct {
 	guid_t guid;
drivers/hv/hyperv_vmbus.h +5 -0
index f6b1e710f805..76ac5185a01a 100644
@@ -417,6 +417,11 @@ static inline bool hv_is_perf_channel(struct vmbus_channel *channel)
 	return vmbus_devs[channel->device_id].perf_device;
 }
 
+static inline size_t hv_dev_ring_size(struct vmbus_channel *channel)
+{
+	return vmbus_devs[channel->device_id].pref_ring_size;
+}
+
 static inline bool hv_is_allocated_cpu(unsigned int cpu)
 {
 	struct vmbus_channel *channel, *sc;
include/linux/hyperv.h +1 -0
index 2b00faf98017..5951c7bb5712 100644
@@ -800,6 +800,7 @@ struct vmbus_requestor {
 #define VMBUS_RQST_RESET (U64_MAX - 3)
 
 struct vmbus_device {
+	size_t pref_ring_size;
 	u16  dev_type;
 	guid_t guid;
 	bool perf_device;
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 1/6] Drivers: hv: vmbus: Add utility function for querying ring size

Quoted 2 lines · Saurabh Sengar

Add a function to query for the preferred ring buffer size of VMBus device.

That says what you did, but not why you did it.

Quoted 23 lines
---
 drivers/hv/channel_mgmt.c | 7 +++++--
 drivers/hv/hyperv_vmbus.h | 5 +++++
 include/linux/hyperv.h    | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)
drivers/hv/channel_mgmt.c +2 -1
index 2f4d09ce027a..7ea444d72f9f 100644
@@ -120,7 +120,8 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* File copy */
-	{ .dev_type = HV_FCOPY,
+	{ .pref_ring_size = 0x4000,
+	  .dev_type = HV_FCOPY,
 	  HV_FCOPY_GUID,
 	  .perf_device = false,
 	  .allowed_in_isolated = false,

drivers/hv/channel_mgmt.c const struct vmbus_device vmbus_devs[] = { · line 146

Quoted 6 lines
drivers/hv/channel_mgmt.c +2 -1
@@ -141,11 +142,13 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* Unknown GUID */
-	{ .dev_type = HV_UNKNOWN,
+	{ .pref_ring_size = 0x11000,
+	  .dev_type = HV_UNKNOWN,

Where do these magic numbers for the size come from?

Quoted 29 lines
drivers/hv/channel_mgmt.c +1 -0
 	  .perf_device = false,
 	  .allowed_in_isolated = false,
 	},
 };
+EXPORT_SYMBOL_GPL(vmbus_devs);
 
 static const struct {
 	guid_t guid;
drivers/hv/hyperv_vmbus.h +5 -0
index f6b1e710f805..76ac5185a01a 100644
@@ -417,6 +417,11 @@ static inline bool hv_is_perf_channel(struct vmbus_channel *channel)
 	return vmbus_devs[channel->device_id].perf_device;
 }
 
+static inline size_t hv_dev_ring_size(struct vmbus_channel *channel)
+{
+	return vmbus_devs[channel->device_id].pref_ring_size;
+}
+
 static inline bool hv_is_allocated_cpu(unsigned int cpu)
 {
 	struct vmbus_channel *channel, *sc;
include/linux/hyperv.h +0 -0
index 2b00faf98017..5951c7bb5712 100644

include/linux/hyperv.h struct vmbus_requestor { · line 803

Quoted 4 lines
include/linux/hyperv.h +1 -0
@@ -800,6 +800,7 @@ struct vmbus_requestor {
 #define VMBUS_RQST_RESET (U64_MAX - 3)
 
 struct vmbus_device {
+	size_t pref_ring_size;

No documentation for this? What is the size in units of?

thanks,

greg k-h

#3 lore raw

Re: [PATCH 1/6] Drivers: hv: vmbus: Add utility function for querying ring size

Quoted 5 lines · Greg KH
Quoted 2 lines · Saurabh Sengar

Add a function to query for the preferred ring buffer size of VMBus device.

That says what you did, but not why you did it.

I thought subsequent patch will make it clear, but I can add more info in cover letter. I will enhance this commit as well.

Quoted 26 lines
Quoted 26 lines
---
 drivers/hv/channel_mgmt.c | 7 +++++--
 drivers/hv/hyperv_vmbus.h | 5 +++++
 include/linux/hyperv.h    | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)
drivers/hv/channel_mgmt.c +2 -1
index 2f4d09ce027a..7ea444d72f9f 100644
@@ -120,7 +120,8 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* File copy */
-	{ .dev_type = HV_FCOPY,
+	{ .pref_ring_size = 0x4000,
+	  .dev_type = HV_FCOPY,
 	  HV_FCOPY_GUID,
 	  .perf_device = false,
 	  .allowed_in_isolated = false,
@@ -141,11 +142,13 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
Quoted 6 lines

drivers/hv/channel_mgmt.c const struct vmbus_device vmbus_devs[] = { · line 146

Quoted 4 lines
drivers/hv/channel_mgmt.c +2 -1
 	/* Unknown GUID */
-	{ .dev_type = HV_UNKNOWN,
+	{ .pref_ring_size = 0x11000,
+	  .dev_type = HV_UNKNOWN,

Where do these magic numbers for the size come from?

This value is (16 + 1) page_size, which is found sufficient for most of the slow devices. 16 page_size is for the ringbuffer and 1 page_size for the headre. This is the approximation for default case, to avoid using fall back case of 512 page_size as used by uio_hv_generic.

Quoted 31 lines
Quoted 31 lines
drivers/hv/channel_mgmt.c +1 -0
 	  .perf_device = false,
 	  .allowed_in_isolated = false,> >  	},
 };
+EXPORT_SYMBOL_GPL(vmbus_devs);
 
 static const struct {
 	guid_t guid;
drivers/hv/hyperv_vmbus.h +5 -0
index f6b1e710f805..76ac5185a01a 100644
@@ -417,6 +417,11 @@ static inline bool hv_is_perf_channel(struct vmbus_channel *channel)
 	return vmbus_devs[channel->device_id].perf_device;
 }
 
+static inline size_t hv_dev_ring_size(struct vmbus_channel *channel)
+{
+	return vmbus_devs[channel->device_id].pref_ring_size;
+}
+
 static inline bool hv_is_allocated_cpu(unsigned int cpu)
 {
 	struct vmbus_channel *channel, *sc;
include/linux/hyperv.h +0 -0
index 2b00faf98017..5951c7bb5712 100644
@@ -800,6 +800,7 @@ struct vmbus_requestor {
 #define VMBUS_RQST_RESET (U64_MAX - 3)
 
Quoted 4 lines

include/linux/hyperv.h struct vmbus_requestor { · line 803

Quoted 2 lines
include/linux/hyperv.h +1 -0
 struct vmbus_device {
+	size_t pref_ring_size;

No documentation for this? What is the size in units of?

I can add a comment here like below:

/*
* Total memory in bytes allocated for the one complete ring buffer,
* which includes the ring buffer header, of size PAGE_SIZE. This value
* should be aligned to page_size.
*/

- Saurabh

Quoted 4 lines

thanks,

greg k-h

maintainer
#4 lore raw

Re: [PATCH 1/6] Drivers: hv: vmbus: Add utility function for querying ring size

Quoted 9 lines · Saurabh Singh Sengar
Quoted 5 lines · Greg KH
Quoted 2 lines · Saurabh Sengar

Add a function to query for the preferred ring buffer size of VMBus device.

That says what you did, but not why you did it.

I thought subsequent patch will make it clear, but I can add more info in cover letter. I will enhance this commit as well.

Each patch should stand on its own, as it will be on its own when committed, right?

I don't know anything is happening "next", nor what any of this means here, which is required.

Again, what would _you_ want to see if you had to review this?

Along those lines, why not get some internal review, and signed-off-by first, before asking us to review this for you? You all know this area the best, and have lots of experience with reviews, right?

thanks,

greg k-h

#5 lore raw

RE: [PATCH 1/6] Drivers: hv: vmbus: Add utility function for querying ring size

In reply to Saurabh Sengar
Quoted 3 lines

Subject: [PATCH 1/6] Drivers: hv: vmbus: Add utility function for querying ring size

Add a function to query for the preferred ring buffer size of VMBus device.

Patch looks good to me. It will be helpful if you can document the ring sizes for each device and put it in the comment. (e.g use a new ring size, or keep using an existing ring size)

Quoted 67 lines
---
 drivers/hv/channel_mgmt.c | 7 +++++--
 drivers/hv/hyperv_vmbus.h | 5 +++++
 include/linux/hyperv.h    | 1 +
 3 files changed, 11 insertions(+), 2 deletions(-)
drivers/hv/channel_mgmt.c index renamed from drivers/hv/channel_mgmt.c +0 -0

2f4d09ce027a..7ea444d72f9f 100644

drivers/hv/channel_mgmt.c +5 -2
@@ -120,7 +120,8 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* File copy */
-	{ .dev_type = HV_FCOPY,
+	{ .pref_ring_size = 0x4000,
+	  .dev_type = HV_FCOPY,
 	  HV_FCOPY_GUID,
 	  .perf_device = false,
 	  .allowed_in_isolated = false,
@@ -141,11 +142,13 @@ const struct vmbus_device vmbus_devs[] = {
 	},
 
 	/* Unknown GUID */
-	{ .dev_type = HV_UNKNOWN,
+	{ .pref_ring_size = 0x11000,
+	  .dev_type = HV_UNKNOWN,
 	  .perf_device = false,
 	  .allowed_in_isolated = false,
 	},
 };
+EXPORT_SYMBOL_GPL(vmbus_devs);
 
 static const struct {
 	guid_t guid;
drivers/hv/hyperv_vmbus.h index renamed from drivers/hv/hyperv_vmbus.h +0 -0

f6b1e710f805..76ac5185a01a 100644

drivers/hv/hyperv_vmbus.h +4 -0
@@ -417,6 +417,11 @@ static inline bool hv_is_perf_channel(struct
 vmbus_channel *channel)
 	return vmbus_devs[channel->device_id].perf_device;
 }
 
+static inline size_t hv_dev_ring_size(struct vmbus_channel *channel) {
+	return vmbus_devs[channel->device_id].pref_ring_size;
+}
+
 static inline bool hv_is_allocated_cpu(unsigned int cpu)  {
 	struct vmbus_channel *channel, *sc;
include/linux/hyperv.h index renamed from include/linux/hyperv.h +0 -0

2b00faf98017..5951c7bb5712 100644

include/linux/hyperv.h +1 -1
@@ -800,6 +800,7 @@ struct vmbus_requestor {  #define VMBUS_RQST_RESET
 (U64_MAX - 3)
 
 struct vmbus_device {
+	size_t pref_ring_size;
 	u16  dev_type;
 	guid_t guid;
 	bool perf_device;
--

2.34.1

#6 lore raw

PATCH 2/6 uio_hv_generic: Query the ringbuffer size for device

In reply to Saurabh Sengar

Query the ring buffer size from pre defined table per device. Keep the size as is if the device doesn't have any preferred ring size.

---
 drivers/uio/uio_hv_generic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/uio/uio_hv_generic.c +5 -2
index 20d9762331bd..4bda6b52e49e 100644
@@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
 	struct hv_uio_private_data *pdata;
 	void *ring_buffer;
 	int ret;
+	size_t ring_size = hv_dev_ring_size(channel);
 
 	/* Communicating with host has to be via shared memory not hypercall */
 	if (!channel->offermsg.monitor_allocated) {
@@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
 		return -ENOTSUPP;
 	}
 
+	if (!ring_size)
+		ring_size = HV_RING_SIZE * PAGE_SIZE;
+
 	pdata = devm_kzalloc(&dev->device, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return -ENOMEM;
 
-	ret = vmbus_alloc_ring(channel, HV_RING_SIZE * PAGE_SIZE,
-			       HV_RING_SIZE * PAGE_SIZE);
+	ret = vmbus_alloc_ring(channel, ring_size, ring_size);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.34.1
maintainer
#7 lore raw

Re: [PATCH 2/6] uio_hv_generic: Query the ringbuffer size for device

Quoted 3 lines · Saurabh Sengar

Query the ring buffer size from pre defined table per device. Keep the size as is if the device doesn't have any preferred ring size.

What is the "as is" size?

Quoted 19 lines
---
 drivers/uio/uio_hv_generic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/uio/uio_hv_generic.c +1 -0
index 20d9762331bd..4bda6b52e49e 100644
@@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
 	struct hv_uio_private_data *pdata;
 	void *ring_buffer;
 	int ret;
+	size_t ring_size = hv_dev_ring_size(channel);
 
 	/* Communicating with host has to be via shared memory not hypercall */
 	if (!channel->offermsg.monitor_allocated) {

drivers/uio/uio_hv_generic.c hv_uio_probe(struct hv_device *dev, · line 250

Quoted 5 lines
drivers/uio/uio_hv_generic.c +2 -0
@@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
 		return -ENOTSUPP;
 	}
 
+	if (!ring_size)
+		ring_size = HV_RING_SIZE * PAGE_SIZE;

Why the magic * PAGE_SIZE here?

Where is it documented that ring_size is in pages?

And what happens when PAGE_SIZE is changed? Why are you relying on that arbritrary value to dictate your buffer sizes to a device that has no relationship with PAGE_SIZE?

Yes, I know you are copying what was there today, but you have the chance to rethink and most importantly, DOCUMENT this decision properly now.

thanks,

greg k-h

#8 lore raw

Re: [PATCH 2/6] uio_hv_generic: Query the ringbuffer size for device

Quoted 6 lines · Greg KH
Quoted 3 lines · Saurabh Sengar

Query the ring buffer size from pre defined table per device. Keep the size as is if the device doesn't have any preferred ring size.

What is the "as is" size?

I will elaborate more here.

Quoted 30 lines
Quoted 20 lines
---
 drivers/uio/uio_hv_generic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/uio/uio_hv_generic.c +1 -0
index 20d9762331bd..4bda6b52e49e 100644
@@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
 	struct hv_uio_private_data *pdata;
 	void *ring_buffer;
 	int ret;
+	size_t ring_size = hv_dev_ring_size(channel);
 
 	/* Communicating with host has to be via shared memory not hypercall */
 	if (!channel->offermsg.monitor_allocated) {

drivers/uio/uio_hv_generic.c hv_uio_probe(struct hv_device *dev, · line 250

Quoted 5 lines
drivers/uio/uio_hv_generic.c +2 -0
@@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
 		return -ENOTSUPP;
 	}
 
+	if (!ring_size)
+		ring_size = HV_RING_SIZE * PAGE_SIZE;

Why the magic * PAGE_SIZE here?

Where is it documented that ring_size is in pages?

Quoted 7 lines

And what happens when PAGE_SIZE is changed? Why are you relying on that arbritrary value to dictate your buffer sizes to a device that has no relationship with PAGE_SIZE?

Yes, I know you are copying what was there today, but you have the chance to rethink and most importantly, DOCUMENT this decision properly now.

I agree PAGE_SIZE is not accurate here and we should use HV_HYP_PAGE_SIZE. This can be further improved by using VMBUS_RING_SIZE macro.

However, I propose addressing this improvement in a separate patch, given the are significant changes already present in this series.

- Saurabh

Quoted 4 lines

thanks,

greg k-h

maintainer
#9 lore raw

Re: [PATCH 2/6] uio_hv_generic: Query the ringbuffer size for device

Quoted 48 lines · Saurabh Singh Sengar
Quoted 6 lines · Greg KH
Quoted 3 lines · Saurabh Sengar

Query the ring buffer size from pre defined table per device. Keep the size as is if the device doesn't have any preferred ring size.

What is the "as is" size?

I will elaborate more here.

Quoted 30 lines
Quoted 20 lines
---
 drivers/uio/uio_hv_generic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/uio/uio_hv_generic.c +1 -0
index 20d9762331bd..4bda6b52e49e 100644
@@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
 	struct hv_uio_private_data *pdata;
 	void *ring_buffer;
 	int ret;
+	size_t ring_size = hv_dev_ring_size(channel);
 
 	/* Communicating with host has to be via shared memory not hypercall */
 	if (!channel->offermsg.monitor_allocated) {

drivers/uio/uio_hv_generic.c hv_uio_probe(struct hv_device *dev, · line 250

Quoted 5 lines
drivers/uio/uio_hv_generic.c +2 -0
@@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
 		return -ENOTSUPP;
 	}
 
+	if (!ring_size)
+		ring_size = HV_RING_SIZE * PAGE_SIZE;

Why the magic * PAGE_SIZE here?

Where is it documented that ring_size is in pages?

Quoted 7 lines

And what happens when PAGE_SIZE is changed? Why are you relying on that arbritrary value to dictate your buffer sizes to a device that has no relationship with PAGE_SIZE?

Yes, I know you are copying what was there today, but you have the chance to rethink and most importantly, DOCUMENT this decision properly now.

Quoted 5 lines

I agree PAGE_SIZE is not accurate here and we should use HV_HYP_PAGE_SIZE. This can be further improved by using VMBUS_RING_SIZE macro.

However, I propose addressing this improvement in a separate patch, given the are significant changes already present in this series.

Add it as a new patch to the series makes sense, thanks!

greg k-h

#10 lore raw

Re: [PATCH 2/6] uio_hv_generic: Query the ringbuffer size for device

Quoted 49 lines · Greg KH
Quoted 48 lines · Saurabh Singh Sengar
Quoted 6 lines · Greg KH
Quoted 3 lines · Saurabh Sengar

Query the ring buffer size from pre defined table per device. Keep the size as is if the device doesn't have any preferred ring size.

What is the "as is" size?

I will elaborate more here.

Quoted 37 lines
Quoted 20 lines
---
 drivers/uio/uio_hv_generic.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/uio/uio_hv_generic.c +1 -0
index 20d9762331bd..4bda6b52e49e 100644
@@ -238,6 +238,7 @@ hv_uio_probe(struct hv_device *dev,
 	struct hv_uio_private_data *pdata;
 	void *ring_buffer;
 	int ret;
+	size_t ring_size = hv_dev_ring_size(channel);
 
 	/* Communicating with host has to be via shared memory not hypercall */
 	if (!channel->offermsg.monitor_allocated) {

drivers/uio/uio_hv_generic.c hv_uio_probe(struct hv_device *dev, · line 250

Quoted 5 lines
drivers/uio/uio_hv_generic.c +2 -0
@@ -245,12 +246,14 @@ hv_uio_probe(struct hv_device *dev,
 		return -ENOTSUPP;
 	}
 
+	if (!ring_size)
+		ring_size = HV_RING_SIZE * PAGE_SIZE;

Why the magic * PAGE_SIZE here?

Where is it documented that ring_size is in pages?

And what happens when PAGE_SIZE is changed? Why are you relying on that arbritrary value to dictate your buffer sizes to a device that has no relationship with PAGE_SIZE?

Yes, I know you are copying what was there today, but you have the chance to rethink and most importantly, DOCUMENT this decision properly now.

Quoted 7 lines
Quoted 5 lines

I agree PAGE_SIZE is not accurate here and we should use HV_HYP_PAGE_SIZE. This can be further improved by using VMBUS_RING_SIZE macro.

However, I propose addressing this improvement in a separate patch, given the are significant changes already present in this series.

Add it as a new patch to the series makes sense, thanks!

Sure, will add in V2.

- Saurabh

Quoted 2 lines

greg k-h

#11 lore raw

PATCH 3/6 uio_hv_generic: Enable interrupt for low speed VMBus devices

In reply to Saurabh Sengar

Hyper-V is adding some "specialty" synthetic devices. Instead of writing new kernel-level VMBus drivers for these devices, the devices will be presented to user space via this existing Hyper-V generic UIO driver, so that a user space driver can handle the device. Since these new synthetic devices are low speed devices, they don't support monitor bits and we must use vmbus_setevent() to enable interrupts from the host.

---
 drivers/uio/uio_hv_generic.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/uio/uio_hv_generic.c +3 -6
index 4bda6b52e49e..289611c7dfd7 100644
@@ -84,6 +84,9 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state)
 	dev->channel->inbound.ring_buffer->interrupt_mask = !irq_state;
 	virt_mb();
 
+	if (!dev->channel->offermsg.monitor_allocated && irq_state)
+		vmbus_setevent(dev->channel);
+
 	return 0;
 }
 
@@ -240,12 +243,6 @@ hv_uio_probe(struct hv_device *dev,
 	int ret;
 	size_t ring_size = hv_dev_ring_size(channel);
 
-	/* Communicating with host has to be via shared memory not hypercall */
-	if (!channel->offermsg.monitor_allocated) {
-		dev_err(&dev->device, "vmbus channel requires hypercall\n");
-		return -ENOTSUPP;
-	}
-
 	if (!ring_size)
 		ring_size = HV_RING_SIZE * PAGE_SIZE;
 
Signature · 1 line
2.34.1
Reviewed-by on v1 3/6
#12 lore raw

RE: [PATCH 3/6] uio_hv_generic: Enable interrupt for low speed VMBus devices

Quoted 11 lines

Subject: [PATCH 3/6] uio_hv_generic: Enable interrupt for low speed VMBus devices

Hyper-V is adding some "specialty" synthetic devices. Instead of writing new kernel-level VMBus drivers for these devices, the devices will be presented to user space via this existing Hyper-V generic UIO driver, so that a user space driver can handle the device. Since these new synthetic devices are low speed devices, they don't support monitor bits and we must use vmbus_setevent() to enable interrupts from the host.

Quoted 35 lines
---
 drivers/uio/uio_hv_generic.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/uio/uio_hv_generic.c index renamed from drivers/uio/uio_hv_generic.c +0 -0

4bda6b52e49e..289611c7dfd7 100644

drivers/uio/uio_hv_generic.c +3 -7
@@ -84,6 +84,9 @@ hv_uio_irqcontrol(struct uio_info *info, s32 irq_state)
 	dev->channel->inbound.ring_buffer->interrupt_mask = !irq_state;
 	virt_mb();
 
+	if (!dev->channel->offermsg.monitor_allocated && irq_state)
+		vmbus_setevent(dev->channel);
+
 	return 0;
 }
 
@@ -240,12 +243,6 @@ hv_uio_probe(struct hv_device *dev,
 	int ret;
 	size_t ring_size = hv_dev_ring_size(channel);
 
-	/* Communicating with host has to be via shared memory not hypercall
 */
-	if (!channel->offermsg.monitor_allocated) {
-		dev_err(&dev->device, "vmbus channel requires hypercall\n");
-		return -ENOTSUPP;
-	}
-
 	if (!ring_size)
 		ring_size = HV_RING_SIZE * PAGE_SIZE;
 
--

2.34.1

#13 lore raw

PATCH 4/6 tools: hv: Add vmbus_bufring

In reply to Saurabh Sengar

Common userspace interface for read/write from VMBus ringbuffer. This implementation is open for use by any userspace driver or application seeking direct control over VMBus ring buffers. A significant part of this code is borrowed from DPDK.

---
 tools/hv/vmbus_bufring.c | 316 +++++++++++++++++++++++++++++++++++++++
 tools/hv/vmbus_bufring.h | 158 ++++++++++++++++++++
 2 files changed, 474 insertions(+)
 create mode 100644 tools/hv/vmbus_bufring.c
 create mode 100644 tools/hv/vmbus_bufring.h
tools/hv/vmbus_bufring.c new file +316 -0
new file mode 100644
index 000000000000..b74b56283bc5
@@ -0,0 +1,316 @@
+// SPDX-License-Identifier: BSD-3-Clause
+/*
+ * Copyright (c) 2009-2012,2016,2023 Microsoft Corp.
+ * Copyright (c) 2012 NetApp Inc.
+ * Copyright (c) 2012 Citrix Inc.
+ * All rights reserved.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <emmintrin.h>
+#include <linux/limits.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include "vmbus_bufring.h"
+
+#define	rte_compiler_barrier()	({ asm volatile ("" : : : "memory"); })
+
+#define	rte_smp_rwmb()		({ asm volatile ("" : : : "memory"); })
+
+#define VMBUS_RQST_ERROR	0xFFFFFFFFFFFFFFFF
+#define ALIGN(val, align)	((typeof(val))((val) & (~((typeof(val))((align) - 1)))))
+
+void *vmbus_uio_map(int *fd, int size)
+{
+	void *map;
+
+	map = mmap(NULL, 2 * size, PROT_READ | PROT_WRITE, MAP_SHARED, *fd, 0);
+	if (map == MAP_FAILED)
+		return NULL;
+
+	return map;
+}
+
+/* Increase bufring index by inc with wraparound */
+static inline uint32_t vmbus_br_idxinc(uint32_t idx, uint32_t inc, uint32_t sz)
+{
+	idx += inc;
+	if (idx >= sz)
+		idx -= sz;
+
+	return idx;
+}
+
+void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen)
+{
+	br->vbr = buf;
+	br->windex = br->vbr->windex;
+	br->dsize = blen - sizeof(struct vmbus_bufring);
+}
+
+static inline __always_inline void
+rte_smp_mb(void)
+{
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory");
+}
+
+static inline int
+rte_atomic32_cmpset(volatile uint32_t *dst, uint32_t exp, uint32_t src)
+{
+	uint8_t res;
+
+	asm volatile("lock ; "
+		     "cmpxchgl %[src], %[dst];"
+		     "sete %[res];"
+		     : [res] "=a" (res),     /* output */
+		     [dst] "=m" (*dst)
+		     : [src] "r" (src),      /* input */
+		     "a" (exp),
+		     "m" (*dst)
+		     : "memory");            /* no-clobber list */
+	return res;
+}
+
+static inline uint32_t
+vmbus_txbr_copyto(const struct vmbus_br *tbr, uint32_t windex,
+		  const void *src0, uint32_t cplen)
+{
+	uint8_t *br_data = tbr->vbr->data;
+	uint32_t br_dsize = tbr->dsize;
+	const uint8_t *src = src0;
+
+	/* XXX use double mapping like Linux kernel? */
+	if (cplen > br_dsize - windex) {
+		uint32_t fraglen = br_dsize - windex;
+
+		/* Wrap-around detected */
+		memcpy(br_data + windex, src, fraglen);
+		memcpy(br_data, src + fraglen, cplen - fraglen);
+	} else {
+		memcpy(br_data + windex, src, cplen);
+	}
+
+	return vmbus_br_idxinc(windex, cplen, br_dsize);
+}
+
+/*
+ * Write scattered channel packet to TX bufring.
+ *
+ * The offset of this channel packet is written as a 64bits value
+ * immediately after this channel packet.
+ *
+ * The write goes through three stages:
+ *  1. Reserve space in ring buffer for the new data.
+ *     Writer atomically moves priv_write_index.
+ *  2. Copy the new data into the ring.
+ *  3. Update the tail of the ring (visible to host) that indicates
+ *     next read location. Writer updates write_index
+ */
+static int
+vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
+		 bool *need_sig)
+{
+	struct vmbus_bufring *vbr = tbr->vbr;
+	uint32_t ring_size = tbr->dsize;
+	uint32_t old_windex, next_windex, windex, total;
+	uint64_t save_windex;
+	int i;
+
+	total = 0;
+	for (i = 0; i < iovlen; i++)
+		total += iov[i].iov_len;
+	total += sizeof(save_windex);
+
+	/* Reserve space in ring */
+	do {
+		uint32_t avail;
+
+		/* Get current free location */
+		old_windex = tbr->windex;
+
+		/* Prevent compiler reordering this with calculation */
+		rte_compiler_barrier();
+
+		avail = vmbus_br_availwrite(tbr, old_windex);
+
+		/* If not enough space in ring, then tell caller. */
+		if (avail <= total)
+			return -EAGAIN;
+
+		next_windex = vmbus_br_idxinc(old_windex, total, ring_size);
+
+		/* Atomic update of next write_index for other threads */
+	} while (!rte_atomic32_cmpset(&tbr->windex, old_windex, next_windex));
+
+	/* Space from old..new is now reserved */
+	windex = old_windex;
+	for (i = 0; i < iovlen; i++)
+		windex = vmbus_txbr_copyto(tbr, windex, iov[i].iov_base, iov[i].iov_len);
+
+	/* Set the offset of the current channel packet. */
+	save_windex = ((uint64_t)old_windex) << 32;
+	windex = vmbus_txbr_copyto(tbr, windex, &save_windex,
+				   sizeof(save_windex));
+
+	/* The region reserved should match region used */
+	if (windex != next_windex)
+		return -EINVAL;
+
+	/* Ensure that data is available before updating host index */
+	rte_smp_rwmb();
+
+	/* Checkin for our reservation. wait for our turn to update host */
+	while (!rte_atomic32_cmpset(&vbr->windex, old_windex, next_windex))
+		_mm_pause();
+
+	return 0;
+}
+
+int rte_vmbus_chan_send(struct vmbus_br *txbr, uint16_t type, void *data,
+			uint32_t dlen, uint32_t flags)
+{
+	struct vmbus_chanpkt pkt;
+	unsigned int pktlen, pad_pktlen;
+	const uint32_t hlen = sizeof(pkt);
+	bool send_evt = false;
+	uint64_t pad = 0;
+	struct iovec iov[3];
+	int error;
+
+	pktlen = hlen + dlen;
+	pad_pktlen = ALIGN(pktlen, sizeof(uint64_t));
+
+	pkt.hdr.type = type;
+	pkt.hdr.flags = flags;
+	pkt.hdr.hlen = hlen >> VMBUS_CHANPKT_SIZE_SHIFT;
+	pkt.hdr.tlen = pad_pktlen >> VMBUS_CHANPKT_SIZE_SHIFT;
+	pkt.hdr.xactid = VMBUS_RQST_ERROR;
+
+	iov[0].iov_base = &pkt;
+	iov[0].iov_len = hlen;
+	iov[1].iov_base = data;
+	iov[1].iov_len = dlen;
+	iov[2].iov_base = &pad;
+	iov[2].iov_len = pad_pktlen - pktlen;
+
+	error = vmbus_txbr_write(txbr, iov, 3, &send_evt);
+
+	return error;
+}
+
+static inline uint32_t
+vmbus_rxbr_copyfrom(const struct vmbus_br *rbr, uint32_t rindex,
+		    void *dst0, size_t cplen)
+{
+	const uint8_t *br_data = rbr->vbr->data;
+	uint32_t br_dsize = rbr->dsize;
+	uint8_t *dst = dst0;
+
+	if (cplen > br_dsize - rindex) {
+		uint32_t fraglen = br_dsize - rindex;
+
+		/* Wrap-around detected. */
+		memcpy(dst, br_data + rindex, fraglen);
+		memcpy(dst + fraglen, br_data, cplen - fraglen);
+	} else {
+		memcpy(dst, br_data + rindex, cplen);
+	}
+
+	return vmbus_br_idxinc(rindex, cplen, br_dsize);
+}
+
+/* Copy data from receive ring but don't change index */
+static int
+vmbus_rxbr_peek(const struct vmbus_br *rbr, void *data, size_t dlen)
+{
+	uint32_t avail;
+
+	/*
+	 * The requested data and the 64bits channel packet
+	 * offset should be there at least.
+	 */
+	avail = vmbus_br_availread(rbr);
+	if (avail < dlen + sizeof(uint64_t))
+		return -EAGAIN;
+
+	vmbus_rxbr_copyfrom(rbr, rbr->vbr->rindex, data, dlen);
+	return 0;
+}
+
+/*
+ * Copy data from receive ring and change index
+ * NOTE:
+ * We assume (dlen + skip) == sizeof(channel packet).
+ */
+static int
+vmbus_rxbr_read(struct vmbus_br *rbr, void *data, size_t dlen, size_t skip)
+{
+	struct vmbus_bufring *vbr = rbr->vbr;
+	uint32_t br_dsize = rbr->dsize;
+	uint32_t rindex;
+
+	if (vmbus_br_availread(rbr) < dlen + skip + sizeof(uint64_t))
+		return -EAGAIN;
+
+	/* Record where host was when we started read (for debug) */
+	rbr->windex = rbr->vbr->windex;
+
+	/*
+	 * Copy channel packet from RX bufring.
+	 */
+	rindex = vmbus_br_idxinc(rbr->vbr->rindex, skip, br_dsize);
+	rindex = vmbus_rxbr_copyfrom(rbr, rindex, data, dlen);
+
+	/*
+	 * Discard this channel packet's 64bits offset, which is useless to us.
+	 */
+	rindex = vmbus_br_idxinc(rindex, sizeof(uint64_t), br_dsize);
+
+	/* Update the read index _after_ the channel packet is fetched.	 */
+	rte_compiler_barrier();
+
+	vbr->rindex = rindex;
+
+	return 0;
+}
+
+int rte_vmbus_chan_recv_raw(struct vmbus_br *rxbr,
+			    void *data, uint32_t *len)
+{
+	struct vmbus_chanpkt_hdr pkt;
+	uint32_t dlen, bufferlen = *len;
+	int error;
+
+	error = vmbus_rxbr_peek(rxbr, &pkt, sizeof(pkt));
+	if (error)
+		return error;
+
+	if (unlikely(pkt.hlen < VMBUS_CHANPKT_HLEN_MIN))
+		/* XXX this channel is dead actually. */
+		return -EIO;
+
+	if (unlikely(pkt.hlen > pkt.tlen))
+		return -EIO;
+
+	/* Length are in quad words */
+	dlen = pkt.tlen << VMBUS_CHANPKT_SIZE_SHIFT;
+	*len = dlen;
+
+	/* If caller buffer is not large enough */
+	if (unlikely(dlen > bufferlen))
+		return -ENOBUFS;
+
+	/* Read data and skip packet header */
+	error = vmbus_rxbr_read(rxbr, data, dlen, 0);
+	if (error)
+		return error;
+
+	/* Return the number of bytes read */
+	return dlen + sizeof(uint64_t);
+}
tools/hv/vmbus_bufring.h new file +158 -0

158 lines not on this page · raw message

Signature · 1 line
2.34.1
#14 lore raw

RE: [PATCH 4/6] tools: hv: Add vmbus_bufring

Quoted 48 lines
tools/hv/vmbus_bufring.c new file +4 -0
+
+#define	rte_compiler_barrier()	({ asm volatile ("" : : : "memory"); })
+
+#define	rte_smp_rwmb()		({ asm volatile ("" : : :

"memory"); })

tools/hv/vmbus_bufring.c new file +3 -0
+
+#define VMBUS_RQST_ERROR	0xFFFFFFFFFFFFFFFF
+#define ALIGN(val, align)	((typeof(val))((val) & (~((typeof(val))((align) -

1)))))

tools/hv/vmbus_bufring.c new file +6 -0
+
+void *vmbus_uio_map(int *fd, int size)
+{
+	void *map;
+
+	map = mmap(NULL, 2 * size, PROT_READ | PROT_WRITE, MAP_SHARED,

*fd, 0);

tools/hv/vmbus_bufring.c new file +32 -0
+	if (map == MAP_FAILED)
+		return NULL;
+
+	return map;
+}
+
+/* Increase bufring index by inc with wraparound */ static inline
+uint32_t vmbus_br_idxinc(uint32_t idx, uint32_t inc, uint32_t sz) {
+	idx += inc;
+	if (idx >= sz)
+		idx -= sz;
+
+	return idx;
+}
+
+void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen)
+{
+	br->vbr = buf;
+	br->windex = br->vbr->windex;
+	br->dsize = blen - sizeof(struct vmbus_bufring); }
+
+static inline __always_inline void
+rte_smp_mb(void)
+{
+	asm volatile("lock addl $0, -128(%%rsp); " ::: "memory"); }
+
+static inline int
+rte_atomic32_cmpset(volatile uint32_t *dst, uint32_t exp, uint32_t src)
+{
+	uint8_t res;
+
+	asm volatile("lock ; "

tools/hv/vmbus_bufring.c line 78

Quoted 10 lines
tools/hv/vmbus_bufring.c new file +10 -0
+		     "cmpxchgl %[src], %[dst];"
+		     "sete %[res];"
+		     : [res] "=a" (res),     /* output */
+		     [dst] "=m" (*dst)
+		     : [src] "r" (src),      /* input */
+		     "a" (exp),
+		     "m" (*dst)
+		     : "memory");            /* no-clobber list */
+	return res;
+}

Those helper functions (rte_*) are difficult to read for someone without DPDK background. Can you add comments to those helper functions? Maybe just copy the comments over from DPDK.

Quoted 28 lines
tools/hv/vmbus_bufring.c new file +28 -0
+
+static inline uint32_t
+vmbus_txbr_copyto(const struct vmbus_br *tbr, uint32_t windex,
+		  const void *src0, uint32_t cplen)
+{
+	uint8_t *br_data = tbr->vbr->data;
+	uint32_t br_dsize = tbr->dsize;
+	const uint8_t *src = src0;
+
+	/* XXX use double mapping like Linux kernel? */
+	if (cplen > br_dsize - windex) {
+		uint32_t fraglen = br_dsize - windex;
+
+		/* Wrap-around detected */
+		memcpy(br_data + windex, src, fraglen);
+		memcpy(br_data, src + fraglen, cplen - fraglen);
+	} else {
+		memcpy(br_data + windex, src, cplen);
+	}
+
+	return vmbus_br_idxinc(windex, cplen, br_dsize); }
+
+/*
+ * Write scattered channel packet to TX bufring.
+ *
+ * The offset of this channel packet is written as a 64bits value
+ * immediately after this channel packet.
+ *

tools/hv/vmbus_bufring.c line 117

Quoted 10 lines
tools/hv/vmbus_bufring.c new file +10 -0
+ * The write goes through three stages:
+ *  1. Reserve space in ring buffer for the new data.
+ *     Writer atomically moves priv_write_index.
+ *  2. Copy the new data into the ring.
+ *  3. Update the tail of the ring (visible to host) that indicates
+ *     next read location. Writer updates write_index
+ */
+static int
+vmbus_txbr_write(struct vmbus_br *tbr, const struct iovec iov[], int iovlen,
+		 bool *need_sig)

Do you need "need_sig"? It's probably not for non-network/storage devices.

#15 lore raw

PATCH 5/6 tools: hv: Add new fcopy application based on uio driver

In reply to Saurabh Sengar

New fcopy application which utilizes uio_hv_vmbus_client driver

---
 tools/hv/Build                 |   3 +-
 tools/hv/Makefile              |  10 +-
 tools/hv/hv_fcopy_uio_daemon.c | 488 +++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+), 6 deletions(-)
 create mode 100644 tools/hv/hv_fcopy_uio_daemon.c
tools/hv/Build +2 -1
index 6cf51fa4b306..7d1f1698069b 100644
@@ -1,3 +1,4 @@
 hv_kvp_daemon-y += hv_kvp_daemon.o
 hv_vss_daemon-y += hv_vss_daemon.o
-hv_fcopy_daemon-y += hv_fcopy_daemon.o
+hv_fcopy_uio_daemon-y += hv_fcopy_uio_daemon.o
+hv_fcopy_uio_daemon-y += vmbus_bufring.o
tools/hv/Makefile +5 -5
index fe770e679ae8..944180cf916e 100644
@@ -17,7 +17,7 @@ MAKEFLAGS += -r
 
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
-ALL_TARGETS := hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
+ALL_TARGETS := hv_kvp_daemon hv_vss_daemon hv_fcopy_uio_daemon
 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
 ALL_SCRIPTS := hv_get_dhcp_info.sh hv_get_dns_info.sh hv_set_ifconfig.sh
@@ -39,10 +39,10 @@ $(HV_VSS_DAEMON_IN): FORCE
 $(OUTPUT)hv_vss_daemon: $(HV_VSS_DAEMON_IN)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
-HV_FCOPY_DAEMON_IN := $(OUTPUT)hv_fcopy_daemon-in.o
-$(HV_FCOPY_DAEMON_IN): FORCE
-	$(Q)$(MAKE) $(build)=hv_fcopy_daemon
-$(OUTPUT)hv_fcopy_daemon: $(HV_FCOPY_DAEMON_IN)
+HV_FCOPY_UIO_DAEMON_IN := $(OUTPUT)hv_fcopy_uio_daemon-in.o
+$(HV_FCOPY_UIO_DAEMON_IN): FORCE
+	$(Q)$(MAKE) $(build)=hv_fcopy_uio_daemon
+$(OUTPUT)hv_fcopy_uio_daemon: $(HV_FCOPY_UIO_DAEMON_IN)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
 clean:
tools/hv/hv_fcopy_uio_daemon.c new file +488 -0

488 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#16 lore raw

Re: [PATCH 5/6] tools: hv: Add new fcopy application based on uio driver

Quoted 1 line · Saurabh Sengar

New fcopy application which utilizes uio_hv_vmbus_client driver

What does this "application" do?

Quoted 53 lines
---
 tools/hv/Build                 |   3 +-
 tools/hv/Makefile              |  10 +-
 tools/hv/hv_fcopy_uio_daemon.c | 488 +++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+), 6 deletions(-)
 create mode 100644 tools/hv/hv_fcopy_uio_daemon.c
tools/hv/Build +2 -1
index 6cf51fa4b306..7d1f1698069b 100644
@@ -1,3 +1,4 @@
 hv_kvp_daemon-y += hv_kvp_daemon.o
 hv_vss_daemon-y += hv_vss_daemon.o
-hv_fcopy_daemon-y += hv_fcopy_daemon.o
+hv_fcopy_uio_daemon-y += hv_fcopy_uio_daemon.o
+hv_fcopy_uio_daemon-y += vmbus_bufring.o
tools/hv/Makefile +5 -5
index fe770e679ae8..944180cf916e 100644
@@ -17,7 +17,7 @@ MAKEFLAGS += -r
 
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
-ALL_TARGETS := hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
+ALL_TARGETS := hv_kvp_daemon hv_vss_daemon hv_fcopy_uio_daemon
 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
 ALL_SCRIPTS := hv_get_dhcp_info.sh hv_get_dns_info.sh hv_set_ifconfig.sh
@@ -39,10 +39,10 @@ $(HV_VSS_DAEMON_IN): FORCE
 $(OUTPUT)hv_vss_daemon: $(HV_VSS_DAEMON_IN)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
-HV_FCOPY_DAEMON_IN := $(OUTPUT)hv_fcopy_daemon-in.o
-$(HV_FCOPY_DAEMON_IN): FORCE
-	$(Q)$(MAKE) $(build)=hv_fcopy_daemon
-$(OUTPUT)hv_fcopy_daemon: $(HV_FCOPY_DAEMON_IN)
+HV_FCOPY_UIO_DAEMON_IN := $(OUTPUT)hv_fcopy_uio_daemon-in.o
+$(HV_FCOPY_UIO_DAEMON_IN): FORCE
+	$(Q)$(MAKE) $(build)=hv_fcopy_uio_daemon
+$(OUTPUT)hv_fcopy_uio_daemon: $(HV_FCOPY_UIO_DAEMON_IN)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
 clean:
tools/hv/hv_fcopy_uio_daemon.c new file +0 -0
new file mode 100644
index 000000000000..f72c899328fc

tools/hv/hv_fcopy_uio_daemon.c line 3

Quoted 3 lines
tools/hv/hv_fcopy_uio_daemon.c new file +3 -0
@@ -0,0 +1,488 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * An implementation of host to guest copy functionality for Linux.

host to guest of what? I think it's a specific type of host and guest, right?

Quoted 39 lines
tools/hv/hv_fcopy_uio_daemon.c new file +39 -0
+ *
+ * Copyright (C) 2023, Microsoft, Inc.
+ *
+ * Author : K. Y. Srinivasan <[email protected]>
+ * Author : Saurabh Sengar <[email protected]>
+ *
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <locale.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <wchar.h>
+#include <sys/stat.h>
+#include <linux/hyperv.h>
+#include <linux/limits.h>
+#include "vmbus_bufring.h"
+
+#define ICMSGTYPE_NEGOTIATE	0
+#define ICMSGTYPE_FCOPY		7
+
+#define WIN8_SRV_MAJOR		1
+#define WIN8_SRV_MINOR		1
+#define WIN8_SRV_VERSION	(WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
+
+#define MAX_FOLDER_NAME		15
+#define MAX_PATH_LEN		15
+#define FCOPY_UIO		"/sys/bus/vmbus/devices/eb765408-105f-49b6-b4aa-c123b64d17d4/uio"
+
+#define FCOPY_VER_COUNT		1

tools/hv/hv_fcopy_uio_daemon.c line 52

Quoted 10 lines
tools/hv/hv_fcopy_uio_daemon.c new file +10 -0
+static const int fcopy_versions[] = {
+	WIN8_SRV_VERSION
+};
+
+#define FW_VER_COUNT		1
+static const int fw_versions[] = {
+	UTIL_FW_VERSION
+};
+
+#define HV_RING_SIZE		(4 * 4096)

Hey, that doesn't match the kernel driver! Why these values?

Quoted 4 lines
tools/hv/hv_fcopy_uio_daemon.c new file +4 -0
+
+unsigned char desc[HV_RING_SIZE];
+
+static int target_fd;

tools/hv/hv_fcopy_uio_daemon.c line 66

Quoted 10 lines
tools/hv/hv_fcopy_uio_daemon.c new file +10 -0
+static char target_fname[PATH_MAX];
+static unsigned long long filesize;
+
+static int hv_fcopy_create_file(char *file_name, char *path_name, __u32 flags)
+{
+	int error = HV_E_FAIL;
+	char *q, *p;
+
+	filesize = 0;
+	p = (char *)path_name;

Why the unneeded cast?

tools/hv/hv_fcopy_uio_daemon.c line 68

Quoted 2 lines
tools/hv/hv_fcopy_uio_daemon.c new file +2 -0
+	snprintf(target_fname, sizeof(target_fname), "%s/%s",
+		 (char *)path_name, (char *)file_name);

Again, why all of the unneeded casts? This feels very odd, so I've stopped reading here, perhaps get an internal review first before sending this out again?

thanks,

greg k-h

#17 lore raw

Re: [PATCH 5/6] tools: hv: Add new fcopy application based on uio driver

Quoted 4 lines · Greg KH
Quoted 1 line · Saurabh Sengar

New fcopy application which utilizes uio_hv_vmbus_client driver

What does this "application" do?

I will improve the commit message with more information.

Quoted 47 lines
Quoted 47 lines
---
 tools/hv/Build                 |   3 +-
 tools/hv/Makefile              |  10 +-
 tools/hv/hv_fcopy_uio_daemon.c | 488 +++++++++++++++++++++++++++++++++
 3 files changed, 495 insertions(+), 6 deletions(-)
 create mode 100644 tools/hv/hv_fcopy_uio_daemon.c
tools/hv/Build +2 -1
index 6cf51fa4b306..7d1f1698069b 100644
@@ -1,3 +1,4 @@
 hv_kvp_daemon-y += hv_kvp_daemon.o
 hv_vss_daemon-y += hv_vss_daemon.o
-hv_fcopy_daemon-y += hv_fcopy_daemon.o
+hv_fcopy_uio_daemon-y += hv_fcopy_uio_daemon.o
+hv_fcopy_uio_daemon-y += vmbus_bufring.o
tools/hv/Makefile +5 -5
index fe770e679ae8..944180cf916e 100644
@@ -17,7 +17,7 @@ MAKEFLAGS += -r
 
 override CFLAGS += -O2 -Wall -g -D_GNU_SOURCE -I$(OUTPUT)include
 
-ALL_TARGETS := hv_kvp_daemon hv_vss_daemon hv_fcopy_daemon
+ALL_TARGETS := hv_kvp_daemon hv_vss_daemon hv_fcopy_uio_daemon
 ALL_PROGRAMS := $(patsubst %,$(OUTPUT)%,$(ALL_TARGETS))
 
 ALL_SCRIPTS := hv_get_dhcp_info.sh hv_get_dns_info.sh hv_set_ifconfig.sh
@@ -39,10 +39,10 @@ $(HV_VSS_DAEMON_IN): FORCE
 $(OUTPUT)hv_vss_daemon: $(HV_VSS_DAEMON_IN)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
-HV_FCOPY_DAEMON_IN := $(OUTPUT)hv_fcopy_daemon-in.o
-$(HV_FCOPY_DAEMON_IN): FORCE
-	$(Q)$(MAKE) $(build)=hv_fcopy_daemon
-$(OUTPUT)hv_fcopy_daemon: $(HV_FCOPY_DAEMON_IN)
+HV_FCOPY_UIO_DAEMON_IN := $(OUTPUT)hv_fcopy_uio_daemon-in.o
+$(HV_FCOPY_UIO_DAEMON_IN): FORCE
+	$(Q)$(MAKE) $(build)=hv_fcopy_uio_daemon
+$(OUTPUT)hv_fcopy_uio_daemon: $(HV_FCOPY_UIO_DAEMON_IN)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $< -o $@
 
Quoted 13 lines

tools/hv/hv_fcopy_uio_daemon.c line 3

Quoted 10 lines
tools/hv/Makefile +0 -0
 clean:
tools/hv/hv_fcopy_uio_daemon.c new file +3 -0
new file mode 100644
index 000000000000..f72c899328fc
@@ -0,0 +1,488 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * An implementation of host to guest copy functionality for Linux.

host to guest of what? I think it's a specific type of host and guest, right?

This application is replacement of hv_fcopy_daemon, so copied the exact comment here. This is specific to Hyper-V host, I can add these details.

Quoted 44 lines
Quoted 44 lines
tools/hv/hv_fcopy_uio_daemon.c new file +43 -0
+ *
+ * Copyright (C) 2023, Microsoft, Inc.
+ *
+ * Author : K. Y. Srinivasan <[email protected]>
+ * Author : Saurabh Sengar <[email protected]>
+ *
+ */
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <locale.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <syslog.h>
+#include <unistd.h>
+#include <wchar.h>
+#include <sys/stat.h>
+#include <linux/hyperv.h>
+#include <linux/limits.h>
+#include "vmbus_bufring.h"
+
+#define ICMSGTYPE_NEGOTIATE	0
+#define ICMSGTYPE_FCOPY		7
+
+#define WIN8_SRV_MAJOR		1
+#define WIN8_SRV_MINOR		1
+#define WIN8_SRV_VERSION	(WIN8_SRV_MAJOR << 16 | WIN8_SRV_MINOR)
+
+#define MAX_FOLDER_NAME		15
+#define MAX_PATH_LEN		15
+#define FCOPY_UIO		"/sys/bus/vmbus/devices/eb765408-105f-49b6-b4aa-c123b64d17d4/uio"
+
+#define FCOPY_VER_COUNT		1
+static const int fcopy_versions[] = {
+	WIN8_SRV_VERSION
+};
+
Quoted 8 lines

tools/hv/hv_fcopy_uio_daemon.c line 52

Quoted 6 lines
tools/hv/hv_fcopy_uio_daemon.c new file +6 -0
+#define FW_VER_COUNT		1
+static const int fw_versions[] = {
+	UTIL_FW_VERSION
+};
+
+#define HV_RING_SIZE		(4 * 4096)

Hey, that doesn't match the kernel driver! Why these values?

This application talks to device which is recognize as HV_FCOPY is kernel. In the first patch of current patch series I have mentioned .pref_ring_size = 0x4000 for HV_FCOPY which matches this.

This code is well tested.

Quoted 18 lines
Quoted 6 lines
tools/hv/hv_fcopy_uio_daemon.c new file +4 -0
+
+unsigned char desc[HV_RING_SIZE];
+
+static int target_fd;

tools/hv/hv_fcopy_uio_daemon.c line 66

Quoted 10 lines
tools/hv/hv_fcopy_uio_daemon.c new file +10 -0
+static char target_fname[PATH_MAX];
+static unsigned long long filesize;
+
+static int hv_fcopy_create_file(char *file_name, char *path_name, __u32 flags)
+{
+	int error = HV_E_FAIL;
+	char *q, *p;
+
+	filesize = 0;
+	p = (char *)path_name;

Why the unneeded cast?

This code is existing today as form of hv_fcopy_daemon. As this new application is replacing hv_fcopy_daemon I reused the same code and casting.

But, I agree I can improve these.

Quoted 7 lines

tools/hv/hv_fcopy_uio_daemon.c line 68

Quoted 3 lines
tools/hv/hv_fcopy_uio_daemon.c new file +2 -0
+	snprintf(target_fname, sizeof(target_fname), "%s/%s",
+		 (char *)path_name, (char *)file_name);

Again, why all of the unneeded casts? This feels very odd, so I've stopped reading here, perhaps get an internal review first before sending this out again?

This patch has gone through extensive review in past, here is the reference to the history:

https://lore.kernel.org/lkml/[email protected]/

I will look for some more internal review and reviewed-by.

- Saurabh

Quoted 4 lines

thanks,

greg k-h

maintainer
#18 lore raw

Re: [PATCH 5/6] tools: hv: Add new fcopy application based on uio driver

Quoted 9 lines · Saurabh Singh Sengar
Quoted 3 lines
Quoted 1 line

+#define HV_RING_SIZE (4 * 4096)

Hey, that doesn't match the kernel driver! Why these values?

This application talks to device which is recognize as HV_FCOPY is kernel. In the first patch of current patch series I have mentioned .pref_ring_size = 0x4000 for HV_FCOPY which matches this.

This code is well tested.

I'm commenting on the fact the 4096 is sometimes PAGE_SIZE and sometimes not, and you have a default of using PAGE_SIZE values in the kernel driver, and as such, this will not match up. So be careful here.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
tools/hv/hv_fcopy_uio_daemon.c new file +8 -0
+
+unsigned char desc[HV_RING_SIZE];
+
+static int target_fd;
+static char target_fname[PATH_MAX];
+static unsigned long long filesize;
+
+static int hv_fcopy_create_file(char *file_name, char *path_name, __u32 flags)
Quoted 8 lines

tools/hv/hv_fcopy_uio_daemon.c line 66

Quoted 6 lines
tools/hv/hv_fcopy_uio_daemon.c new file +6 -0
+{
+	int error = HV_E_FAIL;
+	char *q, *p;
+
+	filesize = 0;
+	p = (char *)path_name;

Why the unneeded cast?

Quoted 3 lines

This code is existing today as form of hv_fcopy_daemon. As this new application is replacing hv_fcopy_daemon I reused the same code and casting.

That wasn't obvious that this was copied code, please be explicit about that.

thanks,

greg k-h

#19 lore raw

Re: [PATCH 5/6] tools: hv: Add new fcopy application based on uio driver

Quoted 9 lines · Greg KH
Quoted 8 lines · Saurabh Singh Sengar
Quoted 3 lines
Quoted 1 line

+#define HV_RING_SIZE (4 * 4096)

Hey, that doesn't match the kernel driver! Why these values?

This application talks to device which is recognize as HV_FCOPY is kernel. In the first patch of current patch series I have mentioned .pref_ring_size = 0x4000 for HV_FCOPY which matches this.

Quoted 5 lines
Quoted 1 line

This code is well tested.

I'm commenting on the fact the 4096 is sometimes PAGE_SIZE and sometimes not, and you have a default of using PAGE_SIZE values in the kernel driver, and as such, this will not match up. So be careful here.

Thanks for clarification, I will add some note for it in V2.

Quoted 28 lines
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
tools/hv/hv_fcopy_uio_daemon.c new file +4 -0
+
+unsigned char desc[HV_RING_SIZE];
+
+static int target_fd;

tools/hv/hv_fcopy_uio_daemon.c line 66

Quoted 10 lines
tools/hv/hv_fcopy_uio_daemon.c new file +10 -0
+static char target_fname[PATH_MAX];
+static unsigned long long filesize;
+
+static int hv_fcopy_create_file(char *file_name, char *path_name, __u32 flags)
+{
+	int error = HV_E_FAIL;
+	char *q, *p;
+
+	filesize = 0;
+	p = (char *)path_name;

Why the unneeded cast?

Quoted 3 lines

This code is existing today as form of hv_fcopy_daemon. As this new application is replacing hv_fcopy_daemon I reused the same code and casting.

That wasn't obvious that this was copied code, please be explicit about that.

thanks,

greg k-h

#20 lore raw

RE: [PATCH 5/6] tools: hv: Add new fcopy application based on uio driver

In reply to Saurabh Sengar
Quoted 5 lines
tools/hv/hv_fcopy_uio_daemon.c new file +4 -0
+			/* Signal host */
+			if ((write(fcopy_fd, &tmp, sizeof(int))) != sizeof(int)) {
+				ret = errno;
+				syslog(LOG_ERR, "Registration failed: %s\n",

strerror(ret));

"Signaling failed" is a better word?

#21 lore raw

PATCH 6/6 Drivers: hv: Remove fcopy driver

In reply to Saurabh Sengar

As the new fcopy driver using uio is introduced, remove obsolete driver and application.

---
 drivers/hv/Makefile        |   2 +-
 drivers/hv/hv_fcopy.c      | 427 -------------------------------------
 drivers/hv/hv_util.c       |  12 --
 tools/hv/hv_fcopy_daemon.c | 266 -----------------------
 4 files changed, 1 insertion(+), 706 deletions(-)
 delete mode 100644 drivers/hv/hv_fcopy.c
 delete mode 100644 tools/hv/hv_fcopy_daemon.c
drivers/hv/Makefile +1 -1
index d76df5c8c2a9..b992c0ed182b 100644
@@ -10,7 +10,7 @@ hv_vmbus-y := vmbus_drv.o \
 		 hv.o connection.o channel.o \
 		 channel_mgmt.o ring_buffer.o hv_trace.o
 hv_vmbus-$(CONFIG_HYPERV_TESTING)	+= hv_debugfs.o
-hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_fcopy.o hv_utils_transport.o
+hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o
 
 # Code that must be built-in
 obj-$(subst m,y,$(CONFIG_HYPERV)) += hv_common.o
drivers/hv/hv_fcopy.c deleted +0 -427

427 lines not on this page · raw message

drivers/hv/hv_util.c +0 -12
index 9c97c4065fe7..c4f525325790 100644
@@ -154,14 +154,6 @@ static struct hv_util_service util_vss = {
 	.util_deinit = hv_vss_deinit,
 };
 
-static struct hv_util_service util_fcopy = {
-	.util_cb = hv_fcopy_onchannelcallback,
-	.util_init = hv_fcopy_init,
-	.util_pre_suspend = hv_fcopy_pre_suspend,
-	.util_pre_resume = hv_fcopy_pre_resume,
-	.util_deinit = hv_fcopy_deinit,
-};
-
 static void perform_shutdown(struct work_struct *dummy)
 {
 	orderly_poweroff(true);
@@ -700,10 +692,6 @@ static const struct hv_vmbus_device_id id_table[] = {
 	{ HV_VSS_GUID,
 	  .driver_data = (unsigned long)&util_vss
 	},
-	/* File copy GUID */
-	{ HV_FCOPY_GUID,
-	  .driver_data = (unsigned long)&util_fcopy
-	},
 	{ },
 };
 
tools/hv/hv_fcopy_daemon.c deleted +0 -266

266 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#23 lore raw
In reply to Saurabh Sengar
Quoted 20 lines · Saurabh Sengar

Hyper-V is adding multiple low speed "speciality" synthetic devices. Instead of writing a new kernel-level VMBus driver for each device, make the devices accessible to user space through UIO-based uio_hv_generic driver. Each device can then be supported by a user space driver. This approach optimizes the development process and provides flexibility to user space applications to control the key interactions with the VMBus ring buffer.

The new synthetic devices are low speed devices that don't support VMBus monitor bits, and so they must use vmbus_setevent() to notify the host of ring buffer updates. These new devices also have smaller ring buffer sizes which requires to add support for variable ring buffer sizes.

Moreover, this patch series adds a new implementation of the fcopy application that uses the new UIO driver. The older fcopy driver and application will be phased out gradually. Development of other similar userspace drivers is still underway.

Quoted 5 lines

Efforts have been made previously to implement this solution earlier. Here are the discussions related to those attempts:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

So is this a v4 of the patch series? What has changed from those previous submissions?

thanks,

greg k-h

#24 lore raw
Quoted 21 lines · Greg KH
Quoted 20 lines · Saurabh Sengar

Hyper-V is adding multiple low speed "speciality" synthetic devices. Instead of writing a new kernel-level VMBus driver for each device, make the devices accessible to user space through UIO-based uio_hv_generic driver. Each device can then be supported by a user space driver. This approach optimizes the development process and provides flexibility to user space applications to control the key interactions with the VMBus ring buffer.

The new synthetic devices are low speed devices that don't support VMBus monitor bits, and so they must use vmbus_setevent() to notify the host of ring buffer updates. These new devices also have smaller ring buffer sizes which requires to add support for variable ring buffer sizes.

Moreover, this patch series adds a new implementation of the fcopy application that uses the new UIO driver. The older fcopy driver and application will be phased out gradually. Development of other similar userspace drivers is still underway.

Quoted 8 lines
Quoted 5 lines

Efforts have been made previously to implement this solution earlier. Here are the discussions related to those attempts:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

So is this a v4 of the patch series? What has changed from those previous submissions?

In the most recent attempt we introduced a new driver uio_hv_vmbus_client for slow devices, where as in this new approach we are making use of existing uio_hv_generic driver.

We also introduced the function to query ring buffer sizes, this is an attempt to address your comment on earlier series to avoid kernel params. Comment ref: https://lore.kernel.org/lkml/[email protected]/

We later tried to have ring buffer sizes via sysfs for which we wrote a new driver uio_hv_vmbus_client as explained above.

This is the next approach in an attempt to address all of the concerns with all the previous series.

- Saurabh

Quoted 4 lines

thanks,

greg k-h

maintainer
#25 lore raw
Quoted 39 lines · Saurabh Singh Sengar
Quoted 21 lines · Greg KH
Quoted 20 lines · Saurabh Sengar

Hyper-V is adding multiple low speed "speciality" synthetic devices. Instead of writing a new kernel-level VMBus driver for each device, make the devices accessible to user space through UIO-based uio_hv_generic driver. Each device can then be supported by a user space driver. This approach optimizes the development process and provides flexibility to user space applications to control the key interactions with the VMBus ring buffer.

The new synthetic devices are low speed devices that don't support VMBus monitor bits, and so they must use vmbus_setevent() to notify the host of ring buffer updates. These new devices also have smaller ring buffer sizes which requires to add support for variable ring buffer sizes.

Moreover, this patch series adds a new implementation of the fcopy application that uses the new UIO driver. The older fcopy driver and application will be phased out gradually. Development of other similar userspace drivers is still underway.

Quoted 8 lines
Quoted 5 lines

Efforts have been made previously to implement this solution earlier. Here are the discussions related to those attempts:
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/
https://lore.kernel.org/lkml/[email protected]/

So is this a v4 of the patch series? What has changed from those previous submissions?

In the most recent attempt we introduced a new driver uio_hv_vmbus_client for slow devices, where as in this new approach we are making use of existing uio_hv_generic driver.

We also introduced the function to query ring buffer sizes, this is an attempt to address your comment on earlier series to avoid kernel params. Comment ref: https://lore.kernel.org/lkml/[email protected]/

Quoted 5 lines

We later tried to have ring buffer sizes via sysfs for which we wrote a new driver uio_hv_vmbus_client as explained above.

This is the next approach in an attempt to address all of the concerns with all the previous series.

Then you need to say that somewhere, what differs from the previous submissions and why this is better. Remember, some of us get 1000+ emails a day to do something with, and trying to remember a review comment from last week, let alone months ago, is impossible.

Make this easy for us please...

And as this is a "next approach", it should be versioned properly. What would you want to see if you had to review this?

thanks,

greg k-h