* [PATCH v4 3/3] hw/vfio: let read-only flag take effect for mmap'd regions
@ 2020-04-17 7:44 Yan Zhao
0 siblings, 0 replies; only message in thread
From: Yan Zhao @ 2020-04-17 7:44 UTC (permalink / raw)
To: pbonzini, alex.williamson; +Cc: Yan Zhao, xin.zeng, philmd, qemu-devel
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é <philmd@redhat.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
Signed-off-by: Xin Zeng <xin.zeng@intel.com>
---
hw/vfio/common.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index b6956a8098..0049e97c34 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -979,6 +979,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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2020-04-16 22:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-17 7:44 [PATCH v4 3/3] hw/vfio: let read-only flag take effect for mmap'd regions Yan Zhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).