linux-hyperv.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes
@ 2025-05-06  0:56 longli
  2025-05-06  0:56 ` [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
                   ` (5 more replies)
  0 siblings, 6 replies; 13+ messages in thread
From: longli @ 2025-05-06  0:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel
  Cc: Long Li

From: Long Li <longli@microsoft.com>

UIO framework requires the device memory aligned to page boundary.
Hyper-V may allocate some memory that is Hyper-V page aligned (4k)
but not system page aligned.

Fix this by having Hyper-V always allocate those pages on system page
boundary and expose them to user-mode.

Change in v2:
Added two more patches to the series:
"uio_hv_generic: Adjust ring size according to system page alignment"
"Drivers: hv: Remove hv_free/alloc_* helpers"

Added more details in the commit message of
"uio_hv_generic: Use correct size for interrupt and monitor pages"

Change in v3:
Rearranged the patch on removing hv_alloc/free* helpers
Added "Drivers: hv: Use kzalloc for panic page allocation"
Fixed typos.

Long Li (5):
  Drivers: hv: Allocate interrupt and monitor pages aligned to system
    page boundary
  uio_hv_generic: Use correct size for interrupt and monitor pages
  uio_hv_generic: Align ring size to system page
  Drivers: hv: Use kzalloc for panic page allocation
  Drivers: hv: Remove hv_alloc/free_* helpers

 drivers/hv/connection.c        | 23 ++++++++++++-----
 drivers/hv/hv_common.c         | 45 +++-------------------------------
 drivers/uio/uio_hv_generic.c   |  7 ++++--
 include/asm-generic/mshyperv.h |  4 ---
 4 files changed, 25 insertions(+), 54 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary
  2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
@ 2025-05-06  0:56 ` longli
  2025-05-07 15:47   ` Michael Kelley
  2025-05-06  0:56 ` [Patch v3 2/5] uio_hv_generic: Use correct size for interrupt and monitor pages longli
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: longli @ 2025-05-06  0:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel
  Cc: Long Li, stable

From: Long Li <longli@microsoft.com>

There are use cases that interrupt and monitor pages are mapped to
user-mode through UIO, so they need to be system page aligned. Some
Hyper-V allocation APIs introduced earlier broke those requirements.

Fix this by using page allocation functions directly for interrupt
and monitor pages.

Cc: stable@vger.kernel.org
Fixes: ca48739e59df ("Drivers: hv: vmbus: Move Hyper-V page allocator to arch neutral code")
Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/hv/connection.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 8351360bba16..be490c598785 100644
--- a/drivers/hv/connection.c
+++ b/drivers/hv/connection.c
@@ -206,11 +206,20 @@ int vmbus_connect(void)
 	INIT_LIST_HEAD(&vmbus_connection.chn_list);
 	mutex_init(&vmbus_connection.channel_mutex);
 
+	/*
+	 * The following Hyper-V interrupt and monitor pages can be used by
+	 * UIO for mapping to user-space, so they should always be allocated on
+	 * system page boundaries. The system page size must be >= the Hyper-V
+	 * page size.
+	 */
+	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
+
 	/*
 	 * Setup the vmbus event connection for channel interrupt
 	 * abstraction stuff
 	 */
-	vmbus_connection.int_page = hv_alloc_hyperv_zeroed_page();
+	vmbus_connection.int_page =
+		(void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
 	if (vmbus_connection.int_page == NULL) {
 		ret = -ENOMEM;
 		goto cleanup;
@@ -225,8 +234,8 @@ int vmbus_connect(void)
 	 * Setup the monitor notification facility. The 1st page for
 	 * parent->child and the 2nd page for child->parent
 	 */
-	vmbus_connection.monitor_pages[0] = hv_alloc_hyperv_page();
-	vmbus_connection.monitor_pages[1] = hv_alloc_hyperv_page();
+	vmbus_connection.monitor_pages[0] = (void *)__get_free_page(GFP_KERNEL);
+	vmbus_connection.monitor_pages[1] = (void *)__get_free_page(GFP_KERNEL);
 	if ((vmbus_connection.monitor_pages[0] == NULL) ||
 	    (vmbus_connection.monitor_pages[1] == NULL)) {
 		ret = -ENOMEM;
@@ -342,21 +351,23 @@ void vmbus_disconnect(void)
 		destroy_workqueue(vmbus_connection.work_queue);
 
 	if (vmbus_connection.int_page) {
-		hv_free_hyperv_page(vmbus_connection.int_page);
+		free_page((unsigned long)vmbus_connection.int_page);
 		vmbus_connection.int_page = NULL;
 	}
 
 	if (vmbus_connection.monitor_pages[0]) {
 		if (!set_memory_encrypted(
 			(unsigned long)vmbus_connection.monitor_pages[0], 1))
-			hv_free_hyperv_page(vmbus_connection.monitor_pages[0]);
+			free_page((unsigned long)
+				vmbus_connection.monitor_pages[0]);
 		vmbus_connection.monitor_pages[0] = NULL;
 	}
 
 	if (vmbus_connection.monitor_pages[1]) {
 		if (!set_memory_encrypted(
 			(unsigned long)vmbus_connection.monitor_pages[1], 1))
-			hv_free_hyperv_page(vmbus_connection.monitor_pages[1]);
+			free_page((unsigned long)
+				vmbus_connection.monitor_pages[1]);
 		vmbus_connection.monitor_pages[1] = NULL;
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Patch v3 2/5] uio_hv_generic: Use correct size for interrupt and monitor pages
  2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
  2025-05-06  0:56 ` [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
@ 2025-05-06  0:56 ` longli
  2025-05-07 15:47   ` Michael Kelley
  2025-05-06  0:56 ` [Patch v3 3/5] uio_hv_generic: Align ring size to system page longli
                   ` (3 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: longli @ 2025-05-06  0:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel
  Cc: Long Li, stable

From: Long Li <longli@microsoft.com>

Interrupt and monitor pages should be in Hyper-V page size (4k bytes).
This can be different from the system page size.

This size is read and used by the user-mode program to determine the
mapped data region. An example of such user-mode program is the VMBus
driver in DPDK.

Cc: stable@vger.kernel.org
Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/uio/uio_hv_generic.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index 1b19b5647495..08385b04c4ab 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -287,13 +287,13 @@ hv_uio_probe(struct hv_device *dev,
 	pdata->info.mem[INT_PAGE_MAP].name = "int_page";
 	pdata->info.mem[INT_PAGE_MAP].addr
 		= (uintptr_t)vmbus_connection.int_page;
-	pdata->info.mem[INT_PAGE_MAP].size = PAGE_SIZE;
+	pdata->info.mem[INT_PAGE_MAP].size = HV_HYP_PAGE_SIZE;
 	pdata->info.mem[INT_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
 
 	pdata->info.mem[MON_PAGE_MAP].name = "monitor_page";
 	pdata->info.mem[MON_PAGE_MAP].addr
 		= (uintptr_t)vmbus_connection.monitor_pages[1];
-	pdata->info.mem[MON_PAGE_MAP].size = PAGE_SIZE;
+	pdata->info.mem[MON_PAGE_MAP].size = HV_HYP_PAGE_SIZE;
 	pdata->info.mem[MON_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
 
 	if (channel->device_id == HV_NIC) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Patch v3 3/5] uio_hv_generic: Align ring size to system page
  2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
  2025-05-06  0:56 ` [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
  2025-05-06  0:56 ` [Patch v3 2/5] uio_hv_generic: Use correct size for interrupt and monitor pages longli
@ 2025-05-06  0:56 ` longli
  2025-05-07 15:48   ` Michael Kelley
  2025-05-06  0:56 ` [Patch v3 4/5] Drivers: hv: Use kzalloc for panic page allocation longli
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 13+ messages in thread
From: longli @ 2025-05-06  0:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel
  Cc: Long Li, stable

From: Long Li <longli@microsoft.com>

Following the ring header, the ring data should align to system page
boundary. Adjust the size if necessary.

Cc: stable@vger.kernel.org
Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/uio/uio_hv_generic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index 08385b04c4ab..cb2e7e0e1540 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -256,6 +256,9 @@ hv_uio_probe(struct hv_device *dev,
 	if (!ring_size)
 		ring_size = SZ_2M;
 
+	/* Adjust ring size if necessary to have it page aligned */
+	ring_size = VMBUS_RING_SIZE(ring_size);
+
 	pdata = devm_kzalloc(&dev->device, sizeof(*pdata), GFP_KERNEL);
 	if (!pdata)
 		return -ENOMEM;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Patch v3 4/5] Drivers: hv: Use kzalloc for panic page allocation
  2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
                   ` (2 preceding siblings ...)
  2025-05-06  0:56 ` [Patch v3 3/5] uio_hv_generic: Align ring size to system page longli
@ 2025-05-06  0:56 ` longli
  2025-05-07 15:48   ` Michael Kelley
  2025-05-06  0:56 ` [Patch v3 5/5] Drivers: hv: Remove hv_alloc/free_* helpers longli
  2025-05-08 18:48 ` [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes Wei Liu
  5 siblings, 1 reply; 13+ messages in thread
From: longli @ 2025-05-06  0:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel
  Cc: Long Li

From: Long Li <longli@microsoft.com>

To prepare for removal of hv_alloc_* and hv_free* functions, use
kzalloc/kfree directly for panic reporting page.

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/hv/hv_common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index a7d7494feaca..a5a6250b1a12 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -272,7 +272,7 @@ static void hv_kmsg_dump_unregister(void)
 	atomic_notifier_chain_unregister(&panic_notifier_list,
 					 &hyperv_panic_report_block);
 
-	hv_free_hyperv_page(hv_panic_page);
+	kfree(hv_panic_page);
 	hv_panic_page = NULL;
 }
 
@@ -280,7 +280,7 @@ static void hv_kmsg_dump_register(void)
 {
 	int ret;
 
-	hv_panic_page = hv_alloc_hyperv_zeroed_page();
+	hv_panic_page = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
 	if (!hv_panic_page) {
 		pr_err("Hyper-V: panic message page memory allocation failed\n");
 		return;
@@ -289,7 +289,7 @@ static void hv_kmsg_dump_register(void)
 	ret = kmsg_dump_register(&hv_kmsg_dumper);
 	if (ret) {
 		pr_err("Hyper-V: kmsg dump register error 0x%x\n", ret);
-		hv_free_hyperv_page(hv_panic_page);
+		kfree(hv_panic_page);
 		hv_panic_page = NULL;
 	}
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [Patch v3 5/5] Drivers: hv: Remove hv_alloc/free_* helpers
  2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
                   ` (3 preceding siblings ...)
  2025-05-06  0:56 ` [Patch v3 4/5] Drivers: hv: Use kzalloc for panic page allocation longli
@ 2025-05-06  0:56 ` longli
  2025-05-07 15:49   ` Michael Kelley
  2025-05-08 18:48 ` [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes Wei Liu
  5 siblings, 1 reply; 13+ messages in thread
From: longli @ 2025-05-06  0:56 UTC (permalink / raw)
  To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel
  Cc: Long Li

From: Long Li <longli@microsoft.com>

There are no users for those functions, remove them.

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/hv/hv_common.c         | 39 ----------------------------------
 include/asm-generic/mshyperv.h |  4 ----
 2 files changed, 43 deletions(-)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index a5a6250b1a12..421376cea17e 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -105,45 +105,6 @@ void __init hv_common_free(void)
 	hv_synic_eventring_tail = NULL;
 }
 
-/*
- * Functions for allocating and freeing memory with size and
- * alignment HV_HYP_PAGE_SIZE. These functions are needed because
- * the guest page size may not be the same as the Hyper-V page
- * size. We depend upon kmalloc() aligning power-of-two size
- * allocations to the allocation size boundary, so that the
- * allocated memory appears to Hyper-V as a page of the size
- * it expects.
- */
-
-void *hv_alloc_hyperv_page(void)
-{
-	BUILD_BUG_ON(PAGE_SIZE <  HV_HYP_PAGE_SIZE);
-
-	if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
-		return (void *)__get_free_page(GFP_KERNEL);
-	else
-		return kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
-}
-EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
-
-void *hv_alloc_hyperv_zeroed_page(void)
-{
-	if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
-		return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
-	else
-		return kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
-}
-EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
-
-void hv_free_hyperv_page(void *addr)
-{
-	if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
-		free_page((unsigned long)addr);
-	else
-		kfree(addr);
-}
-EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
-
 static void *hv_panic_page;
 
 /*
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index ccccb1cbf7df..4033508fbb11 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -236,10 +236,6 @@ int hv_common_cpu_init(unsigned int cpu);
 int hv_common_cpu_die(unsigned int cpu);
 void hv_identify_partition_type(void);
 
-void *hv_alloc_hyperv_page(void);
-void *hv_alloc_hyperv_zeroed_page(void);
-void hv_free_hyperv_page(void *addr);
-
 /**
  * hv_cpu_number_to_vp_number() - Map CPU to VP.
  * @cpu_number: CPU number in Linux terms
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* RE: [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary
  2025-05-06  0:56 ` [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
@ 2025-05-07 15:47   ` Michael Kelley
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Kelley @ 2025-05-07 15:47 UTC (permalink / raw)
  To: longli@linuxonhyperv.com, K. Y. Srinivasan, Haiyang Zhang,
	Wei Liu, Dexuan Cui, Greg Kroah-Hartman,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: Long Li, stable@vger.kernel.org

From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent: Monday, May 5, 2025 5:57 PM
> 
> There are use cases that interrupt and monitor pages are mapped to
> user-mode through UIO, so they need to be system page aligned. Some
> Hyper-V allocation APIs introduced earlier broke those requirements.
> 
> Fix this by using page allocation functions directly for interrupt
> and monitor pages.
> 
> Cc: stable@vger.kernel.org
> Fixes: ca48739e59df ("Drivers: hv: vmbus: Move Hyper-V page allocator to arch neutral code")
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/hv/connection.c | 23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
> index 8351360bba16..be490c598785 100644
> --- a/drivers/hv/connection.c
> +++ b/drivers/hv/connection.c
> @@ -206,11 +206,20 @@ int vmbus_connect(void)
>  	INIT_LIST_HEAD(&vmbus_connection.chn_list);
>  	mutex_init(&vmbus_connection.channel_mutex);
> 
> +	/*
> +	 * The following Hyper-V interrupt and monitor pages can be used by
> +	 * UIO for mapping to user-space, so they should always be allocated on
> +	 * system page boundaries. The system page size must be >= the Hyper-V
> +	 * page size.
> +	 */
> +	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
> +
>  	/*
>  	 * Setup the vmbus event connection for channel interrupt
>  	 * abstraction stuff
>  	 */
> -	vmbus_connection.int_page = hv_alloc_hyperv_zeroed_page();
> +	vmbus_connection.int_page =
> +		(void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
>  	if (vmbus_connection.int_page == NULL) {
>  		ret = -ENOMEM;
>  		goto cleanup;
> @@ -225,8 +234,8 @@ int vmbus_connect(void)
>  	 * Setup the monitor notification facility. The 1st page for
>  	 * parent->child and the 2nd page for child->parent
>  	 */
> -	vmbus_connection.monitor_pages[0] = hv_alloc_hyperv_page();
> -	vmbus_connection.monitor_pages[1] = hv_alloc_hyperv_page();
> +	vmbus_connection.monitor_pages[0] = (void *)__get_free_page(GFP_KERNEL);
> +	vmbus_connection.monitor_pages[1] = (void *)__get_free_page(GFP_KERNEL);
>  	if ((vmbus_connection.monitor_pages[0] == NULL) ||
>  	    (vmbus_connection.monitor_pages[1] == NULL)) {
>  		ret = -ENOMEM;
> @@ -342,21 +351,23 @@ void vmbus_disconnect(void)
>  		destroy_workqueue(vmbus_connection.work_queue);
> 
>  	if (vmbus_connection.int_page) {
> -		hv_free_hyperv_page(vmbus_connection.int_page);
> +		free_page((unsigned long)vmbus_connection.int_page);
>  		vmbus_connection.int_page = NULL;
>  	}
> 
>  	if (vmbus_connection.monitor_pages[0]) {
>  		if (!set_memory_encrypted(
>  			(unsigned long)vmbus_connection.monitor_pages[0], 1))
> -			hv_free_hyperv_page(vmbus_connection.monitor_pages[0]);
> +			free_page((unsigned long)
> +				vmbus_connection.monitor_pages[0]);
>  		vmbus_connection.monitor_pages[0] = NULL;
>  	}
> 
>  	if (vmbus_connection.monitor_pages[1]) {
>  		if (!set_memory_encrypted(
>  			(unsigned long)vmbus_connection.monitor_pages[1], 1))
> -			hv_free_hyperv_page(vmbus_connection.monitor_pages[1]);
> +			free_page((unsigned long)
> +				vmbus_connection.monitor_pages[1]);
>  		vmbus_connection.monitor_pages[1] = NULL;
>  	}
>  }
> --
> 2.34.1
> 

Reviewed-by: Michael Kelley <mhklinux@outlook.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [Patch v3 2/5] uio_hv_generic: Use correct size for interrupt and monitor pages
  2025-05-06  0:56 ` [Patch v3 2/5] uio_hv_generic: Use correct size for interrupt and monitor pages longli
@ 2025-05-07 15:47   ` Michael Kelley
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Kelley @ 2025-05-07 15:47 UTC (permalink / raw)
  To: longli@linuxonhyperv.com, K. Y. Srinivasan, Haiyang Zhang,
	Wei Liu, Dexuan Cui, Greg Kroah-Hartman,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: Long Li, stable@vger.kernel.org

From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent: Monday, May 5, 2025 5:57 PM
> 
> Interrupt and monitor pages should be in Hyper-V page size (4k bytes).
> This can be different from the system page size.
> 
> This size is read and used by the user-mode program to determine the
> mapped data region. An example of such user-mode program is the VMBus
> driver in DPDK.
> 
> Cc: stable@vger.kernel.org
> Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/uio/uio_hv_generic.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index 1b19b5647495..08385b04c4ab 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
> @@ -287,13 +287,13 @@ hv_uio_probe(struct hv_device *dev,
>  	pdata->info.mem[INT_PAGE_MAP].name = "int_page";
>  	pdata->info.mem[INT_PAGE_MAP].addr
>  		= (uintptr_t)vmbus_connection.int_page;
> -	pdata->info.mem[INT_PAGE_MAP].size = PAGE_SIZE;
> +	pdata->info.mem[INT_PAGE_MAP].size = HV_HYP_PAGE_SIZE;
>  	pdata->info.mem[INT_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
> 
>  	pdata->info.mem[MON_PAGE_MAP].name = "monitor_page";
>  	pdata->info.mem[MON_PAGE_MAP].addr
>  		= (uintptr_t)vmbus_connection.monitor_pages[1];
> -	pdata->info.mem[MON_PAGE_MAP].size = PAGE_SIZE;
> +	pdata->info.mem[MON_PAGE_MAP].size = HV_HYP_PAGE_SIZE;
>  	pdata->info.mem[MON_PAGE_MAP].memtype = UIO_MEM_LOGICAL;
> 
>  	if (channel->device_id == HV_NIC) {
> --
> 2.34.1
> 

Reviewed-by: Michael Kelley <mhklinux@outlook.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [Patch v3 3/5] uio_hv_generic: Align ring size to system page
  2025-05-06  0:56 ` [Patch v3 3/5] uio_hv_generic: Align ring size to system page longli
@ 2025-05-07 15:48   ` Michael Kelley
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Kelley @ 2025-05-07 15:48 UTC (permalink / raw)
  To: longli@linuxonhyperv.com, K. Y. Srinivasan, Haiyang Zhang,
	Wei Liu, Dexuan Cui, Greg Kroah-Hartman,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: Long Li, stable@vger.kernel.org

From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent: Monday, May 5, 2025 5:57 PM
> 
> Following the ring header, the ring data should align to system page
> boundary. Adjust the size if necessary.
> 
> Cc: stable@vger.kernel.org
> Fixes: 95096f2fbd10 ("uio-hv-generic: new userspace i/o driver for VMBus")
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/uio/uio_hv_generic.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index 08385b04c4ab..cb2e7e0e1540 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
> @@ -256,6 +256,9 @@ hv_uio_probe(struct hv_device *dev,
>  	if (!ring_size)
>  		ring_size = SZ_2M;
> 
> +	/* Adjust ring size if necessary to have it page aligned */
> +	ring_size = VMBUS_RING_SIZE(ring_size);
> +
>  	pdata = devm_kzalloc(&dev->device, sizeof(*pdata), GFP_KERNEL);
>  	if (!pdata)
>  		return -ENOMEM;
> --
> 2.34.1
> 

Reviewed-by: Michael Kelley <mhklinux@outlook.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [Patch v3 4/5] Drivers: hv: Use kzalloc for panic page allocation
  2025-05-06  0:56 ` [Patch v3 4/5] Drivers: hv: Use kzalloc for panic page allocation longli
@ 2025-05-07 15:48   ` Michael Kelley
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Kelley @ 2025-05-07 15:48 UTC (permalink / raw)
  To: longli@linuxonhyperv.com, K. Y. Srinivasan, Haiyang Zhang,
	Wei Liu, Dexuan Cui, Greg Kroah-Hartman,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: Long Li

From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent: Monday, May 5, 2025 5:57 PM
> 
> To prepare for removal of hv_alloc_* and hv_free* functions, use
> kzalloc/kfree directly for panic reporting page.
> 
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/hv/hv_common.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index a7d7494feaca..a5a6250b1a12 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -272,7 +272,7 @@ static void hv_kmsg_dump_unregister(void)
>  	atomic_notifier_chain_unregister(&panic_notifier_list,
>  					 &hyperv_panic_report_block);
> 
> -	hv_free_hyperv_page(hv_panic_page);
> +	kfree(hv_panic_page);
>  	hv_panic_page = NULL;
>  }
> 
> @@ -280,7 +280,7 @@ static void hv_kmsg_dump_register(void)
>  {
>  	int ret;
> 
> -	hv_panic_page = hv_alloc_hyperv_zeroed_page();
> +	hv_panic_page = kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
>  	if (!hv_panic_page) {
>  		pr_err("Hyper-V: panic message page memory allocation failed\n");
>  		return;
> @@ -289,7 +289,7 @@ static void hv_kmsg_dump_register(void)
>  	ret = kmsg_dump_register(&hv_kmsg_dumper);
>  	if (ret) {
>  		pr_err("Hyper-V: kmsg dump register error 0x%x\n", ret);
> -		hv_free_hyperv_page(hv_panic_page);
> +		kfree(hv_panic_page);
>  		hv_panic_page = NULL;
>  	}
>  }
> --
> 2.34.1
> 

Reviewed-by: Michael Kelley <mhklinux@outlook.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* RE: [Patch v3 5/5] Drivers: hv: Remove hv_alloc/free_* helpers
  2025-05-06  0:56 ` [Patch v3 5/5] Drivers: hv: Remove hv_alloc/free_* helpers longli
@ 2025-05-07 15:49   ` Michael Kelley
  0 siblings, 0 replies; 13+ messages in thread
From: Michael Kelley @ 2025-05-07 15:49 UTC (permalink / raw)
  To: longli@linuxonhyperv.com, K. Y. Srinivasan, Haiyang Zhang,
	Wei Liu, Dexuan Cui, Greg Kroah-Hartman,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
  Cc: Long Li

From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent: Monday, May 5, 2025 5:57 PM
> 
> There are no users for those functions, remove them.
> 
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/hv/hv_common.c         | 39 ----------------------------------
>  include/asm-generic/mshyperv.h |  4 ----
>  2 files changed, 43 deletions(-)
> 
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index a5a6250b1a12..421376cea17e 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -105,45 +105,6 @@ void __init hv_common_free(void)
>  	hv_synic_eventring_tail = NULL;
>  }
> 
> -/*
> - * Functions for allocating and freeing memory with size and
> - * alignment HV_HYP_PAGE_SIZE. These functions are needed because
> - * the guest page size may not be the same as the Hyper-V page
> - * size. We depend upon kmalloc() aligning power-of-two size
> - * allocations to the allocation size boundary, so that the
> - * allocated memory appears to Hyper-V as a page of the size
> - * it expects.
> - */
> -
> -void *hv_alloc_hyperv_page(void)
> -{
> -	BUILD_BUG_ON(PAGE_SIZE <  HV_HYP_PAGE_SIZE);
> -
> -	if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
> -		return (void *)__get_free_page(GFP_KERNEL);
> -	else
> -		return kmalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
> -}
> -EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
> -
> -void *hv_alloc_hyperv_zeroed_page(void)
> -{
> -	if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
> -		return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
> -	else
> -		return kzalloc(HV_HYP_PAGE_SIZE, GFP_KERNEL);
> -}
> -EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
> -
> -void hv_free_hyperv_page(void *addr)
> -{
> -	if (PAGE_SIZE == HV_HYP_PAGE_SIZE)
> -		free_page((unsigned long)addr);
> -	else
> -		kfree(addr);
> -}
> -EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
> -
>  static void *hv_panic_page;
> 
>  /*
> diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
> index ccccb1cbf7df..4033508fbb11 100644
> --- a/include/asm-generic/mshyperv.h
> +++ b/include/asm-generic/mshyperv.h
> @@ -236,10 +236,6 @@ int hv_common_cpu_init(unsigned int cpu);
>  int hv_common_cpu_die(unsigned int cpu);
>  void hv_identify_partition_type(void);
> 
> -void *hv_alloc_hyperv_page(void);
> -void *hv_alloc_hyperv_zeroed_page(void);
> -void hv_free_hyperv_page(void *addr);
> -
>  /**
>   * hv_cpu_number_to_vp_number() - Map CPU to VP.
>   * @cpu_number: CPU number in Linux terms
> --
> 2.34.1
> 

Reviewed-by: Michael Kelley <mhklinux@outlook.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes
  2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
                   ` (4 preceding siblings ...)
  2025-05-06  0:56 ` [Patch v3 5/5] Drivers: hv: Remove hv_alloc/free_* helpers longli
@ 2025-05-08 18:48 ` Wei Liu
  2025-05-13  4:49   ` Wei Liu
  5 siblings, 1 reply; 13+ messages in thread
From: Wei Liu @ 2025-05-08 18:48 UTC (permalink / raw)
  To: longli
  Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel, Long Li

On Mon, May 05, 2025 at 05:56:32PM -0700, longli@linuxonhyperv.com wrote:
> From: Long Li <longli@microsoft.com>
> 
> UIO framework requires the device memory aligned to page boundary.
> Hyper-V may allocate some memory that is Hyper-V page aligned (4k)
> but not system page aligned.
> 
> Fix this by having Hyper-V always allocate those pages on system page
> boundary and expose them to user-mode.
> 
> Change in v2:
> Added two more patches to the series:
> "uio_hv_generic: Adjust ring size according to system page alignment"
> "Drivers: hv: Remove hv_free/alloc_* helpers"
> 
> Added more details in the commit message of
> "uio_hv_generic: Use correct size for interrupt and monitor pages"
> 
> Change in v3:
> Rearranged the patch on removing hv_alloc/free* helpers
> Added "Drivers: hv: Use kzalloc for panic page allocation"
> Fixed typos.
> 
> Long Li (5):
>   Drivers: hv: Allocate interrupt and monitor pages aligned to system
>     page boundary
>   uio_hv_generic: Use correct size for interrupt and monitor pages
>   uio_hv_generic: Align ring size to system page

These patches to UIO look like small bug fixes to me.

Greg, let me know if you care enough to review them.

Given the patches surround these bug fixes, I propose to let me take
them via the Hyper-V tree.

Thanks,
Wei.

>   Drivers: hv: Use kzalloc for panic page allocation
>   Drivers: hv: Remove hv_alloc/free_* helpers
> 
>  drivers/hv/connection.c        | 23 ++++++++++++-----
>  drivers/hv/hv_common.c         | 45 +++-------------------------------
>  drivers/uio/uio_hv_generic.c   |  7 ++++--
>  include/asm-generic/mshyperv.h |  4 ---
>  4 files changed, 25 insertions(+), 54 deletions(-)
> 
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes
  2025-05-08 18:48 ` [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes Wei Liu
@ 2025-05-13  4:49   ` Wei Liu
  0 siblings, 0 replies; 13+ messages in thread
From: Wei Liu @ 2025-05-13  4:49 UTC (permalink / raw)
  To: longli
  Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Greg Kroah-Hartman, linux-hyperv, linux-kernel, Long Li

On Thu, May 08, 2025 at 06:48:28PM +0000, Wei Liu wrote:
> On Mon, May 05, 2025 at 05:56:32PM -0700, longli@linuxonhyperv.com wrote:
> > From: Long Li <longli@microsoft.com>
> > 
> > UIO framework requires the device memory aligned to page boundary.
> > Hyper-V may allocate some memory that is Hyper-V page aligned (4k)
> > but not system page aligned.
> > 
> > Fix this by having Hyper-V always allocate those pages on system page
> > boundary and expose them to user-mode.
> > 
> > Change in v2:
> > Added two more patches to the series:
> > "uio_hv_generic: Adjust ring size according to system page alignment"
> > "Drivers: hv: Remove hv_free/alloc_* helpers"
> > 
> > Added more details in the commit message of
> > "uio_hv_generic: Use correct size for interrupt and monitor pages"
> > 
> > Change in v3:
> > Rearranged the patch on removing hv_alloc/free* helpers
> > Added "Drivers: hv: Use kzalloc for panic page allocation"
> > Fixed typos.
> > 
> > Long Li (5):
> >   Drivers: hv: Allocate interrupt and monitor pages aligned to system
> >     page boundary
> >   uio_hv_generic: Use correct size for interrupt and monitor pages
> >   uio_hv_generic: Align ring size to system page
> 
> These patches to UIO look like small bug fixes to me.
> 
> Greg, let me know if you care enough to review them.
> 
> Given the patches surround these bug fixes, I propose to let me take
> them via the Hyper-V tree.

Series applied to hyperv-next-staging. Thanks.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-05-13  4:49 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-06  0:56 [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes longli
2025-05-06  0:56 ` [Patch v3 1/5] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
2025-05-07 15:47   ` Michael Kelley
2025-05-06  0:56 ` [Patch v3 2/5] uio_hv_generic: Use correct size for interrupt and monitor pages longli
2025-05-07 15:47   ` Michael Kelley
2025-05-06  0:56 ` [Patch v3 3/5] uio_hv_generic: Align ring size to system page longli
2025-05-07 15:48   ` Michael Kelley
2025-05-06  0:56 ` [Patch v3 4/5] Drivers: hv: Use kzalloc for panic page allocation longli
2025-05-07 15:48   ` Michael Kelley
2025-05-06  0:56 ` [Patch v3 5/5] Drivers: hv: Remove hv_alloc/free_* helpers longli
2025-05-07 15:49   ` Michael Kelley
2025-05-08 18:48 ` [Patch v3 0/5] Fix uio_hv_generic on systems with >4k page sizes Wei Liu
2025-05-13  4:49   ` Wei Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).