Allow a memory region to be marked as 'no_vhost' and exclude that region from vhost's list build.
Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com> Signed-off-by: Wang Xin <wangxinxin.w...@huawei.com> --- hw/virtio/vhost.c | 5 ++++- include/exec/memory.h | 21 +++++++++++++++++++++ softmmu/memory.c | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 1a1384e7a6..bd50532a30 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -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; diff --git a/include/exec/memory.h b/include/exec/memory.h index 0cfe987ab4..7258fd6996 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -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 * diff --git a/softmmu/memory.c b/softmmu/memory.c index 70b93104e8..5debe22978 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -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) { -- 2.26.0.windows.1