Re: [PATCH v4 4/5] Drivers: hv: Ensure large page GPA mapping is PMD-aligned
From: Nuno Das Neves
Date: Fri Oct 10 2025 - 19:07:54 EST
On 10/6/2025 8:06 AM, Stanislav Kinsburskii wrote:
> With the upcoming introduction of movable pages, a region doesn't guarantee
> always having large pages mapped. Both mapping on fault and unmapping
> during PTE invalidation may not be 2M-aligned, while the hypervisor
> requires both the GFN and page count to be 2M-aligned to use the large page
> flag.
>
> Update the logic for large page mapping in mshv_region_remap_pages() to
> require both page_offset and page_count to be PMD-aligned.
>
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@xxxxxxxxxxxxxxxxxxx>
> ---
> drivers/hv/mshv_root_main.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index b61bef6b9c132..cb462495f34b5 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -34,6 +34,8 @@
> #include "mshv.h"
> #include "mshv_root.h"
>
> +#define VALUE_PMD_ALIGNED(c) (!((c) & (PTRS_PER_PMD - 1)))
> +
> MODULE_AUTHOR("Microsoft");
> MODULE_LICENSE("GPL");
> MODULE_DESCRIPTION("Microsoft Hyper-V root partition VMM interface /dev/mshv");
> @@ -1100,7 +1102,9 @@ mshv_region_remap_pages(struct mshv_mem_region *region, u32 map_flags,
> if (page_offset + page_count > region->nr_pages)
> return -EINVAL;
>
> - if (region->flags.large_pages)
> + if (region->flags.large_pages &&
> + VALUE_PMD_ALIGNED(page_offset) &&
> + VALUE_PMD_ALIGNED(page_count))
> map_flags |= HV_MAP_GPA_LARGE_PAGE;
>
> /* ask the hypervisor to map guest ram */
>
>
Reviewed-by: Nuno Das Neves <nunodasneves@xxxxxxxxxxxxxxxxxxx>