exclude ivshmem mr from vhost sections
cover exclude ivshmem mr from vhost sections
The ivshmem me now mapped to vhost memory regions, and it reduces the number of available memslots of vhost backend, which may causes vhost backend memory slots limit check failure in vhost dev init.
Since ivshmem_bar2 not normal RAM in Guest, and it shouldn't have vhost DMAing into them, exclude it from the vhost sections.
The 1st patch re-spin Dave's patch, see link
https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02370.html
However, I'm not sure is there any side effects, or maybe it's better to add a new device property like 'novhost/nodma'?
Thanks,
Xin
Wang Xin (2):
memory: Allow a MemoryRegion to be marked no_vhost misc/ivshmem: Mark shared memory regions as no vhost
hw/misc/ivshmem.c | 2 ++ hw/virtio/vhost.c | 5 ++++- include/exec/memory.h | 21 +++++++++++++++++++++ softmmu/memory.c | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)
Signature · 1 line
2.26.0.windows.1
PATCH 1/2 memory: Allow a MemoryRegion to be marked no_vhost
Allow a memory region to be marked as 'no_vhost' and exclude that region from vhost's list build.
--- hw/virtio/vhost.c | 5 ++++- include/exec/memory.h | 21 +++++++++++++++++++++ softmmu/memory.c | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-)
hw/virtio/vhost.c +4 -1
@@ -415,7 +415,10 @@ static bool vhost_section(struct vhost_dev *dev, MemoryRegionSection *section) {MemoryRegion *mr = section->mr; -if (memory_region_is_ram (mr) && !memory_region_is_rom (mr)) { +if (memory_region_is_ram (mr) && + !memory_region_is_rom (mr) && + !memory_region_is_no_vhost (mr)) { +uint8_t dirty_mask =memory_region_get_dirty_log_mask (mr);uint8_t handled_dirty;
include/exec/memory.h +21 -0
@@ -380,6 +380,7 @@ struct MemoryRegion {bool global_locking;uint8_t dirty_log_mask;bool is_iommu; +bool no_vhost;RAMBlock *ram_block;Object *owner;
@@ -1205,6 +1206,26 @@ static inline bool memory_region_is_romd(MemoryRegion *mr)return mr->rom_device && mr->romd_mode; } +/** +* memory_region_set_no_vhost: Make vhost ignore a memory region +* +* Makes vhost ignore a memory region, useful if it isn't real +* DMAble memory and is at inconvenient addresses +* +* @mr: the region being updated. +* @no_vhost: true to ignore +*/ +void memory_region_set_no_vhost (MemoryRegion *mr,bool no_vhost); + +/** +* memory_region_is_no_vhost: Test if memory region is marked no vhost +* +* Test if the no_vhost flag is set on the memory region +* +* @mr: the region being tested. +*/ +bool memory_region_is_no_vhost (const MemoryRegion *mr); +/** * memory_region_get_iommu: check whether a memory region is an iommu *
softmmu/memory.c +15 -0
@@ -2125,6 +2125,21 @@ void memory_region_rom_device_set_romd(MemoryRegion *mr, bool romd_mode) } } +void memory_region_set_no_vhost (MemoryRegion *mr,bool no_vhost) +{ +if (mr->no_vhost != no_vhost) { +memory_region_transaction_begin (); + mr->no_vhost = no_vhost; + memory_region_update_pending |= mr->enabled; +memory_region_transaction_commit (); + } +} + +bool memory_region_is_no_vhost (const MemoryRegion *mr) +{ +return mr->no_vhost; +} +void memory_region_reset_dirty (MemoryRegion *mr,hwaddr addr,hwaddr size,unsigned client) {
Signature · 1 line
2.26.0.windows.1
PATCH 2/2 misc/ivshmem: Mark shared memory regions as no vhost
In reply to Wang XinSince ivshmem_bar2 not normal RAM in Guest, and it shouldn't have vhost DMAing into them, exclude it from the vhost sections, mark the shared memory regions as novhost.
--- hw/misc/ivshmem.c | 2 ++ 1 file changed, 2 insertions(+)
hw/misc/ivshmem.c +2 -0
@@ -499,6 +499,7 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp) } s->ivshmem_bar2 = &s->server_bar2; +memory_region_set_no_vhost (s->ivshmem_bar2, true); } static void process_msg_disconnect(IVShmemState *s, uint16_t posn,
@@ -855,6 +856,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 =host_memory_backend_get_memory (s->hostmem);host_memory_backend_set_mapped (s->hostmem, true); +memory_region_set_no_vhost (s->ivshmem_bar2, true); }else {Chardev *chr =qemu_chr_fe_get_driver (&s->server_chr);assert (chr);
Signature · 1 line
2.26.0.windows.1
Ping.
Quoted 31 lines
The ivshmem me now mapped to vhost memory regions, and it reduces the number of available memslots of vhost backend, which may causes vhost backend memory slots limit check failure in vhost dev init.
Since
ivshmem_bar2not normal RAM in Guest, and it shouldn't have vhost DMAing into them, exclude it from the vhost sections.The 1st patch re-spin Dave's patch, see link
https://lists.nongnu.org/archive/html/qemu-devel/2020-01/msg02370.htmlHowever, I'm not sure is there any side effects, or maybe it's better to add a new device property like 'novhost/nodma'?
Thanks,
XinWang Xin (2):
memory: Allow a MemoryRegion to be markedno_vhostmisc/ivshmem: Mark shared memory regions as no vhosthw/misc/ivshmem.c | 2 ++ hw/virtio/vhost.c | 5 ++++- include/exec/memory.h | 21 +++++++++++++++++++++ softmmu/memory.c | 15 +++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-)--
2.26.0.windows.1