Skip to content

Commit f91bc8f

Browse files
mkulkeliuw
authored andcommitted
mshv: Allow mappings that overlap in uaddr
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>
1 parent ba9eb9b commit f91bc8f

2 files changed

Lines changed: 3 additions & 7 deletions

File tree

drivers/hv/mshv_root_main.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,12 +1188,8 @@ static int mshv_partition_create_region(struct mshv_partition *partition,
11881188

11891189
/* Reject overlapping regions */
11901190
hlist_for_each_entry(rg, &partition->pt_mem_regions, hnode) {
1191-
u64 rg_size = rg->nr_pages << HV_HYP_PAGE_SHIFT;
1192-
1193-
if ((mem->guest_pfn + nr_pages <= rg->start_gfn ||
1194-
rg->start_gfn + rg->nr_pages <= mem->guest_pfn) &&
1195-
(mem->userspace_addr + mem->size <= rg->start_uaddr ||
1196-
rg->start_uaddr + rg_size <= mem->userspace_addr))
1191+
if (mem->guest_pfn + nr_pages <= rg->start_gfn ||
1192+
rg->start_gfn + rg->nr_pages <= mem->guest_pfn)
11971193
continue;
11981194

11991195
return -EEXIST;

include/uapi/linux/mshv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum {
8989
* @rsvd: MBZ
9090
*
9191
* Map or unmap a region of userspace memory to Guest Physical Addresses (GPA).
92-
* Mappings can't overlap in GPA space or userspace.
92+
* Mappings can't overlap in GPA space.
9393
* To unmap, these fields must match an existing mapping.
9494
*/
9595
struct mshv_user_mem_region {

0 commit comments

Comments
 (0)