[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID:
<SN6PR02MB41571611B46C233A6CFC86E4D4C3A@SN6PR02MB4157.namprd02.prod.outlook.com>
Date: Fri, 7 Nov 2025 15:25:12 +0000
From: Michael Kelley <mhklinux@...look.com>
To: Nuno Das Neves <nunodasneves@...ux.microsoft.com>,
"linux-hyperv@...r.kernel.org" <linux-hyperv@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"magnuskulke@...ux.microsoft.com" <magnuskulke@...ux.microsoft.com>
CC: "kys@...rosoft.com" <kys@...rosoft.com>, "haiyangz@...rosoft.com"
<haiyangz@...rosoft.com>, "wei.liu@...nel.org" <wei.liu@...nel.org>,
"decui@...rosoft.com" <decui@...rosoft.com>, "longli@...rosoft.com"
<longli@...rosoft.com>, "skinsburskii@...ux.microsoft.com"
<skinsburskii@...ux.microsoft.com>, "prapal@...ux.microsoft.com"
<prapal@...ux.microsoft.com>, "mrathor@...ux.microsoft.com"
<mrathor@...ux.microsoft.com>, "muislam@...rosoft.com"
<muislam@...rosoft.com>
Subject: RE: [PATCH v2 2/2] mshv: Allow mappings that overlap in uaddr
From: Nuno Das Neves <nunodasneves@...ux.microsoft.com> Sent: Thursday, November 6, 2025 2:14 PM
>
> From: Magnus Kulke <magnuskulke@...ux.microsoft.com>
>
> Currently the MSHV driver rejects mappings that would overlap in
> userspace.
>
> Some VMMs require the same memory to be mapped to different parts of
> the guest's address space, and so working around this restriction is
> difficult.
>
> The hypervisor itself doesn't prohibit mappings that overlap in uaddr,
> (really in SPA; system physical addresses), so supporting this in the
> driver doesn't require any extra work: only the checks need to be
> removed.
>
> Since no userspace code until now has been able to overlap regions in
> userspace, relaxing this constraint can't break any existing code.
>
> Signed-off-by: Magnus Kulke <magnuskulke@...ux.microsoft.com>
> Signed-off-by: Nuno Das Neves <nunodasneves@...ux.microsoft.com>
> ---
> drivers/hv/mshv_root_main.c | 8 ++------
> include/uapi/linux/mshv.h | 2 +-
> 2 files changed, 3 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
> index 25a68912a78d..b1821b18fa09 100644
> --- a/drivers/hv/mshv_root_main.c
> +++ b/drivers/hv/mshv_root_main.c
> @@ -1220,12 +1220,8 @@ static int mshv_partition_create_region(struct mshv_partition *partition,
>
> /* Reject overlapping regions */
> hlist_for_each_entry(rg, &partition->pt_mem_regions, hnode) {
> - u64 rg_size = rg->nr_pages << HV_HYP_PAGE_SHIFT;
> -
> - if ((mem->guest_pfn + nr_pages <= rg->start_gfn ||
> - rg->start_gfn + rg->nr_pages <= mem->guest_pfn) &&
> - (mem->userspace_addr + mem->size <= rg->start_uaddr ||
> - rg->start_uaddr + rg_size <= mem->userspace_addr))
> + if (mem->guest_pfn + nr_pages <= rg->start_gfn ||
> + rg->start_gfn + rg->nr_pages <= mem->guest_pfn)
> continue;
>
> return -EEXIST;
> diff --git a/include/uapi/linux/mshv.h b/include/uapi/linux/mshv.h
> index 9091946cba23..b10c8d1cb2ad 100644
> --- a/include/uapi/linux/mshv.h
> +++ b/include/uapi/linux/mshv.h
> @@ -123,7 +123,7 @@ enum {
> * @rsvd: MBZ
> *
> * Map or unmap a region of userspace memory to Guest Physical Addresses (GPA).
> - * Mappings can't overlap in GPA space or userspace.
> + * Mappings can't overlap in GPA space.
> * To unmap, these fields must match an existing mapping.
> */
> struct mshv_user_mem_region {
> --
> 2.34.1
Reviewed-by: Michael Kelley <mhklinux@...look.com>
Powered by blists - more mailing lists