* [Patch v2 1/4] Drivers: hv: Allocate interrupt and monitor pages aligned to system page boundary [not found] <1746050758-6829-1-git-send-email-longli@linuxonhyperv.com> @ 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 2025-04-30 22:05 ` [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment longli 2 siblings, 1 reply; 7+ 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] 7+ 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; 7+ 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] 7+ 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; 7+ 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] 7+ messages in thread
* [Patch v2 2/4] uio_hv_generic: Use correct size for interrupt and monitor pages [not found] <1746050758-6829-1-git-send-email-longli@linuxonhyperv.com> 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 2 siblings, 1 reply; 7+ 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] 7+ 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; 7+ 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] 7+ messages in thread
* [Patch v2 3/4] uio_hv_generic: Adjust ring size according to system page alignment [not found] <1746050758-6829-1-git-send-email-longli@linuxonhyperv.com> 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 2 siblings, 1 reply; 7+ 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] 7+ 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; 7+ 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] 7+ messages in thread
end of thread, other threads:[~2025-05-06 0:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1746050758-6829-1-git-send-email-longli@linuxonhyperv.com>
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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox