linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch v2 0/4] Fix uio_hv_generic on systems with >4k page sizes
@ 2025-04-30 22:05 longli
  2025-04-30 22:05 ` [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: longli @ 2025-04-30 22:05 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"

Long Li (4):
  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: Adjust ring size according to system page alignment
  Drivers: hv: Remove hv_free/alloc_* helpers

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

-- 
2.34.1


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

* [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary
  2025-04-30 22:05 [Patch v2 0/4] Fix uio_hv_generic on systems with >4k page sizes longli
@ 2025-04-30 22:05 ` longli
  2025-05-01  1:55   ` Michael Kelley
  2025-04-30 22:05 ` [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages longli
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: longli @ 2025-04-30 22:05 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, they need to be system page aligned. Some Hyper-V
allocation APIs introduced earlier broke those requirements.

Fix those APIs by always allocating Hyper-V page at system page boundaries.

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/hv_common.c | 35 ++++++++++-------------------------
 1 file changed, 10 insertions(+), 25 deletions(-)

diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index a7d7494feaca..297ccd7d4997 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -106,41 +106,26 @@ void __init hv_common_free(void)
 }
 
 /*
- * 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.
+ * A Hyper-V page can be used by UIO for mapping to user-space, it should
+ * always be allocated on system page boundaries.
  */
-
 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);
+	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
+	return (void *)__get_free_page(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);
+	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
+	return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
 }
 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);
+	free_page((unsigned long)addr);
 }
 EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
 
@@ -272,7 +257,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 +265,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 +274,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] 10+ messages in thread

* [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages
  2025-04-30 22:05 [Patch v2 0/4] Fix uio_hv_generic on systems with >4k page sizes longli
  2025-04-30 22:05 ` [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
@ 2025-04-30 22:05 ` longli
  2025-05-01  1:55   ` Michael Kelley
  2025-04-30 22:05 ` [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment longli
  2025-04-30 22:05 ` [Patch v2 4/4] Drivers: hv: Remove hv_free/alloc_* helpers longli
  3 siblings, 1 reply; 10+ messages in thread
From: longli @ 2025-04-30 22:05 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 to 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] 10+ messages in thread

* [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment
  2025-04-30 22:05 [Patch v2 0/4] Fix uio_hv_generic on systems with >4k page sizes longli
  2025-04-30 22:05 ` [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
  2025-04-30 22:05 ` [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages longli
@ 2025-04-30 22:05 ` longli
  2025-05-01  1:56   ` Michael Kelley
  2025-04-30 22:05 ` [Patch v2 4/4] Drivers: hv: Remove hv_free/alloc_* helpers longli
  3 siblings, 1 reply; 10+ messages in thread
From: longli @ 2025-04-30 22:05 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 | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
index 08385b04c4ab..dfc5f0e1a254 100644
--- a/drivers/uio/uio_hv_generic.c
+++ b/drivers/uio/uio_hv_generic.c
@@ -256,6 +256,12 @@ hv_uio_probe(struct hv_device *dev,
 	if (!ring_size)
 		ring_size = SZ_2M;
 
+	/*
+	 * Adjust ring size if necessary to have the ring data region 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] 10+ messages in thread

* [Patch v2 4/4] Drivers: hv: Remove hv_free/alloc_* helpers
  2025-04-30 22:05 [Patch v2 0/4] Fix uio_hv_generic on systems with >4k page sizes longli
                   ` (2 preceding siblings ...)
  2025-04-30 22:05 ` [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment longli
@ 2025-04-30 22:05 ` longli
  2025-05-01  1:56   ` Michael Kelley
  3 siblings, 1 reply; 10+ messages in thread
From: longli @ 2025-04-30 22:05 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>

Those helpers are simply wrappers for page allocations.

Signed-off-by: Long Li <longli@microsoft.com>
---
 drivers/hv/connection.c        | 23 +++++++++++++++++------
 drivers/hv/hv_common.c         | 24 ------------------------
 include/asm-generic/mshyperv.h |  4 ----
 3 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
index 8351360bba16..a0160b73b593 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, it should always be allocated on
+	 * system page boundaries. We use page allocation functions to allocate
+	 * those pages. We assume system page be bigger than Hyper-v page.
+	 */
+	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;
 	}
 }
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 297ccd7d4997..421376cea17e 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -105,30 +105,6 @@ void __init hv_common_free(void)
 	hv_synic_eventring_tail = NULL;
 }
 
-/*
- * A Hyper-V page can be used by UIO for mapping to user-space, it should
- * always be allocated on system page boundaries.
- */
-void *hv_alloc_hyperv_page(void)
-{
-	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
-	return (void *)__get_free_page(GFP_KERNEL);
-}
-EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
-
-void *hv_alloc_hyperv_zeroed_page(void)
-{
-	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
-	return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
-}
-EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
-
-void hv_free_hyperv_page(void *addr)
-{
-	free_page((unsigned long)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] 10+ messages in thread

* RE: [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary
  2025-04-30 22:05 ` [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
@ 2025-05-01  1:55   ` Michael Kelley
  2025-05-06  0:58     ` Long Li
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Kelley @ 2025-05-01  1:55 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: Wednesday, April 30, 2025 3:06 PM
> 
> There are use cases that interrupt and monitor pages are mapped to
> user-mode through UIO, they need to be system page aligned. Some Hyper-V

s/UIO, they/UIO, so they/

> allocation APIs introduced earlier broke those requirements.
> 
> Fix those APIs by always allocating Hyper-V page at system page boundaries.

This patch modifies hv_alloc_hyperv_page() and friends. Then Patch 4 of the
series deletes them, including the modifications. It would be less code motion
to do the first part of Patch 4 (i.e., the use of __get_free_page directly in
connection.c) here in Patch 1, and leave hv_alloc_hyperv_page() and friends
unmodified. Continue to make the change to hv_kmsg_dump_register() here
in Patch 1 as well.

Then have Patch 2 simply delete hv_alloc_hyperv_page() and friends
because they are no longer used. The modifications to hv_alloc_hyperv_page()
and friends would not be needed.

Patch 3 and 4 would be the additional changes in uio_hv_generic.c.

Michael

> 
> 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/hv_common.c | 35 ++++++++++-------------------------
>  1 file changed, 10 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index a7d7494feaca..297ccd7d4997 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -106,41 +106,26 @@ void __init hv_common_free(void)
>  }
> 
>  /*
> - * 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.
> + * A Hyper-V page can be used by UIO for mapping to user-space, it should
> + * always be allocated on system page boundaries.
>   */
> -
>  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);
> +	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
> +	return (void *)__get_free_page(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);
> +	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
> +	return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
>  }
>  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);
> +	free_page((unsigned long)addr);
>  }
>  EXPORT_SYMBOL_GPL(hv_free_hyperv_page);
> 
> @@ -272,7 +257,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 +265,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 +274,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	[flat|nested] 10+ messages in thread

* RE: [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages
  2025-04-30 22:05 ` [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages longli
@ 2025-05-01  1:55   ` Michael Kelley
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Kelley @ 2025-05-01  1:55 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: Wednesday, April 30, 2025 3:06 PM
> 
> Interrupt and monitor pages should be in Hyper-V page size (4k bytes).
> This can be different to the system page size.

s/different to/different from/

> 
> 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

s/VMBUS/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	[flat|nested] 10+ messages in thread

* RE: [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment
  2025-04-30 22:05 ` [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment longli
@ 2025-05-01  1:56   ` Michael Kelley
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Kelley @ 2025-05-01  1:56 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: Wednesday, April 30, 2025 3:06 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 | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/uio/uio_hv_generic.c b/drivers/uio/uio_hv_generic.c
> index 08385b04c4ab..dfc5f0e1a254 100644
> --- a/drivers/uio/uio_hv_generic.c
> +++ b/drivers/uio/uio_hv_generic.c
> @@ -256,6 +256,12 @@ hv_uio_probe(struct hv_device *dev,
>  	if (!ring_size)
>  		ring_size = SZ_2M;
> 
> +	/*
> +	 * Adjust ring size if necessary to have the ring data region 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] 10+ messages in thread

* RE: [Patch v2 4/4] Drivers: hv: Remove hv_free/alloc_* helpers
  2025-04-30 22:05 ` [Patch v2 4/4] Drivers: hv: Remove hv_free/alloc_* helpers longli
@ 2025-05-01  1:56   ` Michael Kelley
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Kelley @ 2025-05-01  1:56 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: Wednesday, April 30, 2025 3:06 PM
> 
> Those helpers are simply wrappers for page allocations.
> 
> Signed-off-by: Long Li <longli@microsoft.com>
> ---
>  drivers/hv/connection.c        | 23 +++++++++++++++++------
>  drivers/hv/hv_common.c         | 24 ------------------------
>  include/asm-generic/mshyperv.h |  4 ----
>  3 files changed, 17 insertions(+), 34 deletions(-)
> 
> diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c
> index 8351360bba16..a0160b73b593 100644
> --- a/drivers/hv/connection.c
> +++ b/drivers/hv/connection.c

See my comment in Patch 1 of the series, suggesting that these
changes to connection.c move into Patch 1.

> @@ -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, it should always be allocated on

s/it should/so should/

> +	 * system page boundaries. We use page allocation functions to allocate
> +	 * those pages. We assume system page be bigger than Hyper-v page.

Instead of your last sentence above, say:

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;
>  	}
>  }
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index 297ccd7d4997..421376cea17e 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -105,30 +105,6 @@ void __init hv_common_free(void)
>  	hv_synic_eventring_tail = NULL;
>  }
> 
> -/*
> - * A Hyper-V page can be used by UIO for mapping to user-space, it should
> - * always be allocated on system page boundaries.
> - */
> -void *hv_alloc_hyperv_page(void)
> -{
> -	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
> -	return (void *)__get_free_page(GFP_KERNEL);
> -}
> -EXPORT_SYMBOL_GPL(hv_alloc_hyperv_page);
> -
> -void *hv_alloc_hyperv_zeroed_page(void)
> -{
> -	BUILD_BUG_ON(PAGE_SIZE < HV_HYP_PAGE_SIZE);
> -	return (void *)__get_free_page(GFP_KERNEL | __GFP_ZERO);
> -}
> -EXPORT_SYMBOL_GPL(hv_alloc_hyperv_zeroed_page);
> -
> -void hv_free_hyperv_page(void *addr)
> -{
> -	free_page((unsigned long)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	[flat|nested] 10+ messages in thread

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



> -----Original Message-----
> From: Michael Kelley <mhklinux@outlook.com>
> Sent: Wednesday, April 30, 2025 6:56 PM
> To: longli@linuxonhyperv.com; KY Srinivasan <kys@microsoft.com>; Haiyang
> Zhang <haiyangz@microsoft.com>; Wei Liu <wei.liu@kernel.org>; Dexuan Cui
> <decui@microsoft.com>; Greg Kroah-Hartman
> <gregkh@linuxfoundation.org>; linux-hyperv@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Cc: Long Li <longli@microsoft.com>; stable@vger.kernel.org
> Subject: [EXTERNAL] RE: [Patch v2 1/4] Drivers: hv: Allocate interrupt and
> monitor pages aligned to system page boundary
> 
> From: longli@linuxonhyperv.com <longli@linuxonhyperv.com> Sent:
> Wednesday, April 30, 2025 3:06 PM
> >
> > There are use cases that interrupt and monitor pages are mapped to
> > user-mode through UIO, they need to be system page aligned. Some
> > Hyper-V
> 
> s/UIO, they/UIO, so they/
> 
> > allocation APIs introduced earlier broke those requirements.
> >
> > Fix those APIs by always allocating Hyper-V page at system page boundaries.
> 
> This patch modifies hv_alloc_hyperv_page() and friends. Then Patch 4 of the
> series deletes them, including the modifications. It would be less code motion
> to do the first part of Patch 4 (i.e., the use of __get_free_page directly in
> connection.c) here in Patch 1, and leave hv_alloc_hyperv_page() and friends
> unmodified. Continue to make the change to hv_kmsg_dump_register() here
> in Patch 1 as well.
> 
> Then have Patch 2 simply delete hv_alloc_hyperv_page() and friends because
> they are no longer used. The modifications to hv_alloc_hyperv_page() and
> friends would not be needed.
> 
> Patch 3 and 4 would be the additional changes in uio_hv_generic.c.
> 
> Michael

I have sent v3 of the patch series.

Long

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

end of thread, other threads:[~2025-05-06  0:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 22:05 [Patch v2 0/4] Fix uio_hv_generic on systems with >4k page sizes longli
2025-04-30 22:05 ` [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary longli
2025-05-01  1:55   ` Michael Kelley
2025-05-06  0:58     ` Long Li
2025-04-30 22:05 ` [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages longli
2025-05-01  1:55   ` Michael Kelley
2025-04-30 22:05 ` [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment longli
2025-05-01  1:56   ` Michael Kelley
2025-04-30 22:05 ` [Patch v2 4/4] Drivers: hv: Remove hv_free/alloc_* helpers longli
2025-05-01  1:56   ` Michael Kelley

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).