Skip to contentSkip to conversation

Drivers: hv: Specify buffer size using Hyper-V page size

PATCH Applied Himadri Pandya 3 participants 6 messages Jul 25, 2019 – Oct 4, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Drivers: hv: Specify buffer size using Hyper-V page size

recv_buffer and VMbus ring buffers are sized based on guest page size which Hyper-V assumes to be 4KB. It might not be the case for some architectures. Hence instead use the Hyper-V page size.

Himadri Pandya (2):
Drivers: hv: Specify receive buffer size using Hyper-V page size
Drivers: hv: util: Specify ring buffer size using Hyper-V page size

 drivers/hv/hv_fcopy.c    |  3 ++-
 drivers/hv/hv_kvp.c      |  3 ++-
 drivers/hv/hv_snapshot.c |  3 ++-
 drivers/hv/hv_util.c     | 13 +++++++------
 4 files changed, 13 insertions(+), 9 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 Drivers: hv: Specify receive buffer size using Hyper-V page size

The recv_buffer is used to retrieve data from the VMbus ring buffer. VMbus ring buffers are sized based on the guest page size which Hyper-V assumes to be 4KB. But it may be different on some architectures. So use the Hyper-V page size to allocate the recv_buffer and set the maximum size to receive.

---
 drivers/hv/hv_fcopy.c    | 3 ++-
 drivers/hv/hv_kvp.c      | 3 ++-
 drivers/hv/hv_snapshot.c | 3 ++-
 drivers/hv/hv_util.c     | 8 ++++----
 4 files changed, 10 insertions(+), 7 deletions(-)
drivers/hv/hv_fcopy.c +2 -1
index 7e30ae0635cc..08fa4a5de644 100644
@@ -13,6 +13,7 @@
 #include <linux/workqueue.h>
 #include <linux/hyperv.h>
 #include <linux/sched.h>
+#include <asm/hyperv-tlfs.h>
 
 #include "hyperv_vmbus.h"
 #include "hv_utils_transport.h"
@@ -234,7 +235,7 @@ void hv_fcopy_onchannelcallback(void *context)
 	if (fcopy_transaction.state > HVUTIL_READY)
 		return;
 
-	vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
+	vmbus_recvpacket(channel, recv_buffer, HV_HYP_PAGE_SIZE * 2, &recvlen,
 			 &requestid);
 	if (recvlen <= 0)
 		return;
drivers/hv/hv_kvp.c +2 -1
index 5054d1105236..ae7c028dc5a8 100644
@@ -27,6 +27,7 @@
 #include <linux/connector.h>
 #include <linux/workqueue.h>
 #include <linux/hyperv.h>
+#include <asm/hyperv-tlfs.h>
 
 #include "hyperv_vmbus.h"
 #include "hv_utils_transport.h"
@@ -661,7 +662,7 @@ void hv_kvp_onchannelcallback(void *context)
 	if (kvp_transaction.state > HVUTIL_READY)
 		return;
 
-	vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 4, &recvlen,
+	vmbus_recvpacket(channel, recv_buffer, HV_HYP_PAGE_SIZE * 4, &recvlen,
 			 &requestid);
 
 	if (recvlen > 0) {
drivers/hv/hv_snapshot.c +2 -1
index 20ba95b75a94..03b6454268b3 100644
@@ -12,6 +12,7 @@
 #include <linux/connector.h>
 #include <linux/workqueue.h>
 #include <linux/hyperv.h>
+#include <asm/hyperv-tlfs.h>
 
 #include "hyperv_vmbus.h"
 #include "hv_utils_transport.h"
@@ -297,7 +298,7 @@ void hv_vss_onchannelcallback(void *context)
 	if (vss_transaction.state > HVUTIL_READY)
 		return;
 
-	vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE * 2, &recvlen,
+	vmbus_recvpacket(channel, recv_buffer, HV_HYP_PAGE_SIZE * 2, &recvlen,
 			 &requestid);
 
 	if (recvlen > 0) {
drivers/hv/hv_util.c +4 -4
index e32681ee7b9f..c2c08f26bd5f 100644
@@ -136,7 +136,7 @@ static void shutdown_onchannelcallback(void *context)
 	struct icmsg_hdr *icmsghdrp;
 
 	vmbus_recvpacket(channel, shut_txf_buf,
-			 PAGE_SIZE, &recvlen, &requestid);
+			 HV_HYP_PAGE_SIZE, &recvlen, &requestid);
 
 	if (recvlen > 0) {
 		icmsghdrp = (struct icmsg_hdr *)&shut_txf_buf[
@@ -284,7 +284,7 @@ static void timesync_onchannelcallback(void *context)
 	u8 *time_txf_buf = util_timesynch.recv_buffer;
 
 	vmbus_recvpacket(channel, time_txf_buf,
-			 PAGE_SIZE, &recvlen, &requestid);
+			 HV_HYP_PAGE_SIZE, &recvlen, &requestid);
 
 	if (recvlen > 0) {
 		icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[
@@ -346,7 +346,7 @@ static void heartbeat_onchannelcallback(void *context)
 	while (1) {
 
 		vmbus_recvpacket(channel, hbeat_txf_buf,
-				 PAGE_SIZE, &recvlen, &requestid);
+				 HV_HYP_PAGE_SIZE, &recvlen, &requestid);
 
 		if (!recvlen)
 			break;
@@ -390,7 +390,7 @@ static int util_probe(struct hv_device *dev,
 		(struct hv_util_service *)dev_id->driver_data;
 	int ret;
 
-	srv->recv_buffer = kmalloc(PAGE_SIZE * 4, GFP_KERNEL);
+	srv->recv_buffer = kmalloc(HV_HYP_PAGE_SIZE * 4, GFP_KERNEL);
 	if (!srv->recv_buffer)
 		return -ENOMEM;
 	srv->channel = dev->channel;
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/2] Drivers: hv: Specify receive buffer size using Hyper-V page size

Quoted 7 lines · On Wed, 24 Jul 2019 22:03:14 -0700 "Himadri Pandya" <[email protected]>…

The recv_buffer is used to retrieve data from the VMbus ring buffer. VMbus ring buffers are sized based on the guest page size which Hyper-V assumes to be 4KB. But it may be different on some architectures. So use the Hyper-V page size to allocate the recv_buffer and set the maximum size to receive.

If pagesize is 64K, then doing it this way will waste lots of memory.

#3 lore raw

PATCH 2/2 Drivers: hv: util: Specify ring buffer size using Hyper-V page size

In reply to Himadri Pandya

VMbus ring buffers are sized based on the 4K page size used by Hyper-V. The Linux guest page size may not be 4K on all architectures so use the Hyper-V page size to specify the ring buffer size.

---
 drivers/hv/hv_util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hv/hv_util.c +3 -2
index c2c08f26bd5f..766bd8457346 100644
@@ -413,8 +413,9 @@ static int util_probe(struct hv_device *dev,
 
 	hv_set_drvdata(dev, srv);
 
-	ret = vmbus_open(dev->channel, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL, 0,
-			srv->util_cb, dev->channel);
+	ret = vmbus_open(dev->channel, 4 * HV_HYP_PAGE_SIZE,
+			 4 * HV_HYP_PAGE_SIZE, NULL, 0, srv->util_cb,
+			 dev->channel);
 	if (ret)
 		goto error;
 
Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH 2/2] Drivers: hv: util: Specify ring buffer size using Hyper-V page size

Quoted 16 lines · On Wed, 24 Jul 2019 22:03:15 -0700 "Himadri Pandya" <[email protected]>…

VMbus ring buffers are sized based on the 4K page size used by Hyper-V. The Linux guest page size may not be 4K on all architectures so use the Hyper-V page size to specify the ring buffer size.

---
 drivers/hv/hv_util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/hv/hv_util.c +0 -0
index c2c08f26bd5f..766bd8457346 100644
@@ -413,8 +413,9 @@ static int util_probe(struct hv_device *dev,
 

drivers/hv/hv_util.c static int util_probe(struct hv_device *dev, · line 421

Quoted 10 lines
drivers/hv/hv_util.c +3 -2
 	hv_set_drvdata(dev, srv);
 
-	ret = vmbus_open(dev->channel, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL,
 0,
-			srv->util_cb, dev->channel);
+	ret = vmbus_open(dev->channel, 4 * HV_HYP_PAGE_SIZE,
+			 4 * HV_HYP_PAGE_SIZE, NULL, 0, srv->util_cb,
+			 dev->channel);
 	if (ret)
 		goto error;

hv_util doesn't need lots of buffering. Why not define a fixed value across all architectures. Maybe with some roundup to HV_HYP_PAGE_SIZE.

A message that is not in the archive (sent off-list or not yet received): DM5PR21MB01377E1E6DE541E902A12EEFD7B80@DM5PR21MB0137.namprd21.prod.outlook.com

Applied
#6 lore raw
Quoted 16 lines · Michael Kelley

From: Himadri Pandya <[email protected]> Sent: Wednesday, July 24, 2019 10:03 PM

Quoted 15 lines

recv_buffer and VMbus ring buffers are sized based on guest page size which Hyper-V assumes to be 4KB. It might not be the case for some architectures. Hence instead use the Hyper-V page size.

Himadri Pandya (2):
Drivers: hv: Specify receive buffer size using Hyper-V page size
Drivers: hv: util: Specify ring buffer size using Hyper-V page size

 drivers/hv/hv_fcopy.c    |  3 ++-
 drivers/hv/hv_kvp.c      |  3 ++-
 drivers/hv/hv_snapshot.c |  3 ++-
 drivers/hv/hv_util.c     | 13 +++++++------
 4 files changed, 13 insertions(+), 9 deletions(-)
Quoted 6 lines
Quoted 2 lines

--
2.17.1

Thomas -- can you pick up this patch set in the x86/hyperv branch of your tip tree along with the other patches to fix wrong page size assumptions?

I've queued these two for hyperv-next, thanks!

Signature · 2 lines
Thanks,
Sasha