[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 3/3] hw/vfio: let read-only flag take effect for mmap'd region
From: |
Yan Zhao |
Subject: |
[PATCH v6 3/3] hw/vfio: let read-only flag take effect for mmap'd regions |
Date: |
Thu, 30 Apr 2020 04:13:53 -0400 |
along side setting host page table to be read-only, the memory regions
are also required to be read-only, so that when guest writes to the
read-only & mmap'd regions, vmexits would happen and region write handlers
are called.
Reviewed-by: Philippe Mathieu-Daudé <address@hidden>
Signed-off-by: Yan Zhao <address@hidden>
Signed-off-by: Xin Zeng <address@hidden>
---
hw/vfio/common.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 2a4fedfeaa..bf510e66c0 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -980,6 +980,10 @@ int vfio_region_mmap(VFIORegion *region)
name, region->mmaps[i].size,
region->mmaps[i].mmap);
g_free(name);
+
+ if (!(region->flags & VFIO_REGION_INFO_FLAG_WRITE)) {
+ memory_region_set_readonly(®ion->mmaps[i].mem, true);
+ }
memory_region_add_subregion(region->mem, region->mmaps[i].offset,
®ion->mmaps[i].mem);
--
2.17.1