]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
mshv: Allow mappings that overlap in uaddr
authorMagnus Kulke <magnuskulke@linux.microsoft.com>
Thu, 6 Nov 2025 22:13:31 +0000 (14:13 -0800)
committerWei Liu <wei.liu@kernel.org>
Sat, 15 Nov 2025 06:18:17 +0000 (06:18 +0000)
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@linux.microsoft.com>
Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
Reviewed-by: Michael Kelley <mhklinux@outlook.com>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
drivers/hv/mshv_root_main.c
include/uapi/linux/mshv.h

index a8f3c5f3ce3471779ac1256994bfd9e04773cf0a..3f73c468e9759b9335182a3df64f90b51df8bcc7 100644 (file)
@@ -1188,12 +1188,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;
index 876bfe4e42276e3c359842df0b1a37e872a5aac8..374f75e198bc1e48246a05b1ce445ec5b03c9c88 100644 (file)
@@ -89,7 +89,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 {