From: Nuno Das Neves <nunodasneves@linux.microsoft.com>
To: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>,
kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org,
decui@microsoft.com
Cc: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 3/7] Drivers: hv: Move region management to mshv_regions.c
Date: Wed, 3 Dec 2025 10:13:52 -0800 [thread overview]
Message-ID: <9c614ef4-6c97-4a9c-b33a-e989e3de2c85@linux.microsoft.com> (raw)
In-Reply-To: <176412294544.447063.14863746685758881018.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net>
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@linux.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@linux.microsoft.com>
next prev parent reply other threads:[~2025-12-03 18:13 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 2:08 [PATCH v7 0/7] Introduce movable pages for Hyper-V guests Stanislav Kinsburskii
2025-11-26 2:08 ` [PATCH v7 1/7] Drivers: hv: Refactor and rename memory region handling functions Stanislav Kinsburskii
2025-12-01 11:20 ` Anirudh Rayabharam
2025-11-26 2:08 ` [PATCH v7 2/7] Drivers: hv: Centralize guest memory region destruction Stanislav Kinsburskii
2025-12-01 11:12 ` Anirudh Rayabharam
2025-11-26 2:09 ` [PATCH v7 3/7] Drivers: hv: Move region management to mshv_regions.c Stanislav Kinsburskii
2025-12-01 11:06 ` Anirudh Rayabharam
2025-12-01 16:46 ` Stanislav Kinsburskii
2025-12-03 18:13 ` Nuno Das Neves [this message]
2025-12-03 18:20 ` Stanislav Kinsburskii
2025-11-26 2:09 ` [PATCH v7 4/7] Drivers: hv: Fix huge page handling in memory region traversal Stanislav Kinsburskii
2025-11-27 10:59 ` kernel test robot
2025-12-01 15:09 ` Anirudh Rayabharam
2025-12-01 18:26 ` Stanislav Kinsburskii
2025-12-03 18:50 ` Nuno Das Neves
2025-12-04 16:03 ` Michael Kelley
2025-12-04 21:08 ` Stanislav Kinsburskii
2025-12-11 17:37 ` Michael Kelley
2025-12-15 20:12 ` Stanislav Kinsburskii
2025-12-17 0:54 ` Stanislav Kinsburskii
2025-11-26 2:09 ` [PATCH v7 5/7] Drivers: hv: Improve region overlap detection in partition create Stanislav Kinsburskii
2025-12-01 15:06 ` Anirudh Rayabharam
2025-12-02 18:39 ` Michael Kelley
2025-12-03 17:46 ` Stanislav Kinsburskii
2025-12-03 18:58 ` Nuno Das Neves
2025-12-03 19:36 ` Nuno Das Neves
2025-11-26 2:09 ` [PATCH v7 6/7] Drivers: hv: Add refcount and locking to mem regions Stanislav Kinsburskii
2025-12-04 16:48 ` Michael Kelley
2025-12-04 21:23 ` Stanislav Kinsburskii
2025-11-26 2:09 ` [PATCH v7 7/7] Drivers: hv: Add support for movable memory regions Stanislav Kinsburskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9c614ef4-6c97-4a9c-b33a-e989e3de2c85@linux.microsoft.com \
--to=nunodasneves@linux.microsoft.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=skinsburskii@linux.microsoft.com \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox