drop writes to read-only ram device & vfio regions
v2 cover drop writes to read-only ram device & vfio regions
patch 1 modifies handler of ram device memory regions to drop guest writes to read-only ram device memory regions
patch 2 modifies handler of non-mmap'd read-only vfio regions to drop guest writes to those regions
patch 3 let mmap'd read-only vfio regions be able to generate vmexit for guest write. so, without patch 1, host qemu would crash on guest write to this read-only region. with patch 1, host qemu would drop the writes.
Yan Zhao (3):
memory: drop guest writes to read-only ram device regions hw/vfio: drop guest writes to ro regions hw/vfio: let read-only flag take effect for mmap'd regions
hw/vfio/common.c | 12 +++++++++++- hw/vfio/trace-events | 2 +- memory.c | 6 +++++- trace-events | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
PATCH v2 1/3 memory: drop guest writes to read-only ram device regions
for ram device regions, drop guest writes if the regions is read-only.
--- memory.c | 6 +++++- trace-events | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-)
memory.c +5 -1
@@ -1312,7 +1312,11 @@ static void memory_region_ram_device_write(void *opaque, hwaddr addr, {MemoryRegion *mr = opaque; -trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, size); +trace_memory_region_ram_device_write (get_cpu_index (), mr, addr, data, + size, mr->readonly); +if (mr->readonly) { +return ; + }switch (size) {case 1 :
trace-events +1 -1
@@ -61,7 +61,7 @@ memory_region_ops_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64" size %u" memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" -memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" +memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uint64_t value, unsigned size, bool readonly) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64" size %u" " is_readonly_region=%d" flatview_new(void *view, void *root) "%p (root %p)" flatview_destroy(void *view, void *root) "%p (root %p)" flatview_destroy_rcu(void *view, void *root) "%p (root %p)"
Signature · 1 line
2.17.1
PATCH v2 2/3 hw/vfio: drop guest writes to ro regions
In reply to Yan Zhaofor vfio regions that are without write permission, drop guest writes to those regions.
--- hw/vfio/common.c | 8 +++++++- hw/vfio/trace-events | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-)
hw/vfio/common.c +7 -1
@@ -190,6 +190,11 @@ void vfio_region_write(void *opaque, hwaddr addr,uint64_t qword; } buf; +if (!(region->flags &VFIO_REGION_INFO_FLAG_WRITE )) { +trace_vfio_region_write (vbasedev->name, region->nr, + addr, data, size, true); +return ; + }switch (size) {case 1 : buf.byte = data;
@@ -215,7 +220,8 @@ void vfio_region_write(void *opaque, hwaddr addr, addr, data, size); } -trace_vfio_region_write (vbasedev->name, region->nr, addr, data, size); +trace_vfio_region_write (vbasedev->name, region->nr, addr, data, size, + false);/* * A read or write to a BAR always signals an INTx EOI. This will
hw/vfio/trace-events +1 -1
@@ -91,7 +91,7 @@ vfio_pci_nvlink2_setup_quirk_ssatgt(const char *name, uint64_t tgt, uint64_t siz vfio_pci_nvlink2_setup_quirk_lnkspd(const char *name, uint32_t link_speed) "%s link_speed=0x%x" # common.c -vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" +vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size, bool readonly) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" " is_readonly_region=%d." vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64 vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_end) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64 vfio_listener_region_add_skip(uint64_t start, uint64_t end) "SKIPPING region_add 0x%"PRIx64" - 0x%"PRIx64
Signature · 1 line
2.17.1
PATCH v2 3/3 hw/vfio: let read-only flag take effect for mmap'd regions
In reply to Yan Zhaoalong 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.
--- hw/vfio/common.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/vfio/common.c +4 -0
@@ -977,6 +977,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);
Signature · 1 line
2.17.1
v2 cover drop writes to read-only ram device & vfio regions
In reply to Yan Zhaopatch 1 modifies handler of ram device memory regions to drop guest writes to read-only ram device memory regions
patch 2 modifies handler of non-mmap'd read-only vfio regions to drop guest writes to those regions
patch 3 let mmap'd read-only vfio regions be able to generate vmexit for guest write. so, without patch 1, host qemu would crash on guest write to this read-only region. with patch 1, host qemu would drop the writes.
Changelog:
v2:
-split one big patches into smaller ones (Philippe)
-modify existing trace to record guest writes to read-only memory (Alex) -modify vfio_region_write() to drop guest writes to non-mmap'd read-only
region (Alex)
Yan Zhao (3):
memory: drop guest writes to read-only ram device regions hw/vfio: drop guest writes to ro regions hw/vfio: let read-only flag take effect for mmap'd regions
hw/vfio/common.c | 12 +++++++++++- hw/vfio/trace-events | 2 +- memory.c | 6 +++++- trace-events | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-)
Signature · 1 line
2.17.1
Forgot the changelog, so sent this patch 0/3 again. sorry about that.
Quoted 31 lines · Yan Y
patch 1 modifies handler of ram device memory regions to drop guest writes to read-only ram device memory regions
patch 2 modifies handler of non-mmap'd read-only vfio regions to drop guest writes to those regions
patch 3 let mmap'd read-only vfio regions be able to generate vmexit for guest write. so, without patch 1, host qemu would crash on guest write to this read-only region. with patch 1, host qemu would drop the writes.
Changelog:
v2:(quoted diff) +0
-3-split one big patches into smaller ones (Philippe) -modify existing trace to record guest writes to read-only memory (Alex) -modify vfio_region_write() to drop guest writes to non-mmap'd read-only region (Alex)Yan Zhao (3):
memory: drop guest writes to read-only ram device regions hw/vfio: drop guest writes to ro regions hw/vfio: let read-only flag take effect for mmap'd regionshw/vfio/common.c | 12 +++++++++++- hw/vfio/trace-events | 2 +- memory.c | 6 +++++- trace-events | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-)Signature · 1 line
2.17.1
Quoted 10 lines · Yan Zhao
patch 1 modifies handler of ram device memory regions to drop guest writes to read-only ram device memory regions
patch 2 modifies handler of non-mmap'd read-only vfio regions to drop guest writes to those regions
patch 3 let mmap'd read-only vfio regions be able to generate vmexit for guest write. so, without patch 1, host qemu would crash on guest write to this read-only region. with patch 1, host qemu would drop the writes.
Just FYI, there seems to be a minor clock or timezone issue with however you're sending these emails: the Date header you sent reads "Date: Fri, 3 Apr 2020 16:56:57 +0000" but that time in the UTC +0000 timezone is (as I write this) still several hours in the future. This isn't a big deal but you probably want to look into fixing it.
(Noticed because the wrong-date makes your patches stick to the top of the https://patchew.org/QEMU/ list even after other patches arrive after them.)
thanks
-- PMM
Quoted 19 lines · Peter Maydell
Quoted 10 lines · Yan Zhao
patch 1 modifies handler of ram device memory regions to drop guest writes to read-only ram device memory regions
patch 2 modifies handler of non-mmap'd read-only vfio regions to drop guest writes to those regions
patch 3 let mmap'd read-only vfio regions be able to generate vmexit for guest write. so, without patch 1, host qemu would crash on guest write to this read-only region. with patch 1, host qemu would drop the writes.
Just FYI, there seems to be a minor clock or timezone issue with however you're sending these emails: the Date header you sent reads "Date: Fri, 3 Apr 2020 16:56:57 +0000" but that time in the UTC +0000 timezone is (as I write this) still several hours in the future. This isn't a big deal but you probably want to look into fixing it.
Quoted 4 lines
(Noticed because the wrong-date makes your patches stick to the top of the https://patchew.org/QEMU/ list even after other patches arrive after them.)
thanks for informing of it! will pay attention to it. Thanks
Yan