[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9c614ef4-6c97-4a9c-b33a-e989e3de2c85@linux.microsoft.com>
Date: Wed, 3 Dec 2025 10:13:52 -0800
From: Nuno Das Neves <nunodasneves@...ux.microsoft.com>
To: Stanislav Kinsburskii <skinsburskii@...ux.microsoft.com>,
kys@...rosoft.com, haiyangz@...rosoft.com, wei.liu@...nel.org,
decui@...rosoft.com
Cc: linux-hyperv@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v7 3/7] Drivers: hv: Move region management to
mshv_regions.c
On 11/25/2025 6:09 PM, Stanislav Kinsburskii wrote:
> Refactor memory region management functions from mshv_root_main.c into
> mshv_regions.c for better modularity and code organization.
>
> Adjust function calls and headers to use the new implementation. Improve
> maintainability and separation of concerns in the mshv_root module.
>
> Signed-off-by: Stanislav Kinsburskii <skinsburskii@...ux.microsoft.com>
> ---
> drivers/hv/Makefile | 2
> drivers/hv/mshv_regions.c | 175 +++++++++++++++++++++++++++++++++++++++++++
> drivers/hv/mshv_root.h | 10 ++
> drivers/hv/mshv_root_main.c | 176 +++----------------------------------------
> 4 files changed, 198 insertions(+), 165 deletions(-)
> create mode 100644 drivers/hv/mshv_regions.c
>
> diff --git a/drivers/hv/Makefile b/drivers/hv/Makefile
> index 58b8d07639f3..46d4f4f1b252 100644
> --- a/drivers/hv/Makefile
> +++ b/drivers/hv/Makefile
> @@ -14,7 +14,7 @@ hv_vmbus-y := vmbus_drv.o \
> hv_vmbus-$(CONFIG_HYPERV_TESTING) += hv_debugfs.o
> hv_utils-y := hv_util.o hv_kvp.o hv_snapshot.o hv_utils_transport.o
> mshv_root-y := mshv_root_main.o mshv_synic.o mshv_eventfd.o mshv_irq.o \
> - mshv_root_hv_call.o mshv_portid_table.o
> + mshv_root_hv_call.o mshv_portid_table.o mshv_regions.o
> mshv_vtl-y := mshv_vtl_main.o
>
> # Code that must be built-in
> diff --git a/drivers/hv/mshv_regions.c b/drivers/hv/mshv_regions.c
> new file mode 100644
> index 000000000000..35b866670840
> --- /dev/null
> +++ b/drivers/hv/mshv_regions.c
> @@ -0,0 +1,175 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2025, Microsoft Corporation.
> + *
> + * Memory region management for mshv_root module.
> + *
> + * Authors: Microsoft Linux virtualization team
> + */
> +
> +#include <linux/mm.h>
> +#include <linux/vmalloc.h>
> +
> +#include <asm/mshyperv.h>
> +
> +#include "mshv_root.h"
> +
> +struct mshv_mem_region *mshv_region_create(u64 guest_pfn, u64 nr_pages,
> + u64 uaddr, u32 flags,
nit: we use 'flags' here to mean MSHV_SET_MEM flags, but below in
mshv_region_share/unshare() we use it to mean HV_MAP_GPA flags.
Renaming 'flags' to 'mshv_flags' here could improve the clarity.
> + bool is_mmio)
> +{
> + struct mshv_mem_region *region;
> +
> + region = vzalloc(sizeof(*region) + sizeof(struct page *) * nr_pages);
> + if (!region)
> + return ERR_PTR(-ENOMEM);
> +
> + region->nr_pages = nr_pages;
> + region->start_gfn = guest_pfn;
> + region->start_uaddr = uaddr;
> + region->hv_map_flags = HV_MAP_GPA_READABLE | HV_MAP_GPA_ADJUSTABLE;
> + if (flags & BIT(MSHV_SET_MEM_BIT_WRITABLE))
> + region->hv_map_flags |= HV_MAP_GPA_WRITABLE;
> + if (flags & BIT(MSHV_SET_MEM_BIT_EXECUTABLE))
> + region->hv_map_flags |= HV_MAP_GPA_EXECUTABLE;
> +
> + /* Note: large_pages flag populated when we pin the pages */
> + if (!is_mmio)
> + region->flags.range_pinned = true;
> +
> + return region;
> +}
> +
> +int mshv_region_share(struct mshv_mem_region *region)
> +{
> + u32 flags = HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_SHARED;
> +
> + if (region->flags.large_pages)
> + flags |= HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE;
> +
> + return hv_call_modify_spa_host_access(region->partition->pt_id,
> + region->pages, region->nr_pages,
> + HV_MAP_GPA_READABLE | HV_MAP_GPA_WRITABLE,
> + flags, true);
> +}
> +
> +int mshv_region_unshare(struct mshv_mem_region *region)
> +{
> + u32 flags = HV_MODIFY_SPA_PAGE_HOST_ACCESS_MAKE_EXCLUSIVE;
> +
> + if (region->flags.large_pages)
> + flags |= HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE;
> +
> + return hv_call_modify_spa_host_access(region->partition->pt_id,
> + region->pages, region->nr_pages,
> + 0,
> + flags, false);
> +}<snip>
Looks fine to me. Fixing the nit is optional.
Reviewed-by: Nuno Das Neves <nunodasneves@...ux.microsoft.com>
Powered by blists - more mailing lists