memory: Add memory_region_msync() & make NVMe emulated device generic
cover memory: Add memory_region_msync() & make NVMe emulated device generic
Let the NVMe emulated device be target-agnostic.
It is not clear if dccvap_writefn() really needs memory_region_writeback() or could use memory_region_msync().
Philippe Mathieu-Daudé (4):
memory: Rename memory_region_do_writeback -> memory_region_writeback
memory: Extract memory_region_msync() from memory_region_writeback() hw/block: Let the NVMe emulated device be target-agnostic
exec: Rename qemu_ram_writeback() as qemu_ram_msync()
include/exec/memory.h | 15 +++++++++++++-- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- hw/block/nvme.c | 6 ++---- memory.c | 12 +++++++++--- target/arm/helper.c | 2 +- hw/block/Makefile.objs | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-)
Signature · 1 line
2.21.3
PATCH 1/4 memory: Rename memory_region_do_writeback -> memory_region_writeback
We usually use '_do_' for internal functions. Rename memory_region_do_writeback() as memory_region_writeback().
--- include/exec/memory.h | 4 ++-- memory.c | 2 +- target/arm/helper.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/exec/memory.h +2 -2
@@ -1474,14 +1474,14 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr);void memory_region_ram_resize (MemoryRegion *mr,ram_addr_t newsize,Error **errp);/** -* memory_region_do_writeback: Trigger cache writeback or msync for +* memory_region_writeback: Trigger cache writeback or msync for * selected address range * * @mr: the memory region to be updated * @addr: the initial address of the range to be written back * @size: the size of the range to be written back */ -void memory_region_do_writeback (MemoryRegion *mr,hwaddr addr,hwaddr size); +void memory_region_writeback (MemoryRegion *mr,hwaddr addr,hwaddr size);/** * memory_region_set_log: Turn dirty logging on or off for a region.
memory.c +1 -1
@@ -2198,7 +2198,7 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errp } -void memory_region_do_writeback (MemoryRegion *mr,hwaddr addr,hwaddr size) +void memory_region_writeback (MemoryRegion *mr,hwaddr addr,hwaddr size) {/* * Might be extended case needed to cover
target/arm/helper.c +1 -1
@@ -6829,7 +6829,7 @@ static void dccvap_writefn(CPUARMState *env, const ARMCPRegInfo *opaque, mr =memory_region_from_host (haddr, &offset);if (mr) { -memory_region_do_writeback (mr, offset, dline_size); +memory_region_writeback (mr, offset, dline_size); } } }
Signature · 1 line
2.21.3
Re: [PATCH 1/4] memory: Rename memory_region_do_writeback -> memory_region_writeback
Quoted 9 lines · Philippe Mathieu-Daudé
We usually use '_do_' for internal functions. Rename
memory_region_do_writeback()asmemory_region_writeback().Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/exec/memory.h | 4 ++-- memory.c | 2 +- target/arm/helper.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
r~
PATCH 2/4 memory: Extract memory_region_msync() from memory_region_writeback()
In reply to Philippe Mathieu-Daudé--- include/exec/memory.h | 13 ++++++++++++- memory.c | 10 ++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-)
include/exec/memory.h +12 -1
@@ -1473,8 +1473,19 @@ void *memory_region_get_ram_ptr(MemoryRegion *mr);*/ void memory_region_ram_resize (MemoryRegion *mr,ram_addr_t newsize,Error **errp); +/** -* memory_region_writeback: Trigger cache writeback or msync for +* memory_region_msync: Synchronize selected address range of +* a memory mapped region +* +* @mr: the memory region to be msync +* @addr: the initial address of the range to be sync +* @size: the size of the range to be sync +*/ +void memory_region_msync (MemoryRegion *mr,hwaddr addr,hwaddr size); + +/** +* memory_region_writeback: Trigger cache writeback for * selected address range * * @mr: the memory region to be updated
memory.c +8 -2
@@ -2197,6 +2197,12 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errpqemu_ram_resize (mr->ram_block, newsize, errp); } +void memory_region_msync (MemoryRegion *mr,hwaddr addr,hwaddr size) +{ +if (mr->ram_block) { +qemu_ram_writeback (mr->ram_block, addr, size); + } +}void memory_region_writeback (MemoryRegion *mr,hwaddr addr,hwaddr size) {
@@ -2204,8 +2210,8 @@ void memory_region_writeback(MemoryRegion *mr, hwaddr addr, hwaddr size)* Might be extended case needed to cover * different types of memory regions */ -if (mr->ram_block && mr->dirty_log_mask) { -qemu_ram_writeback (mr->ram_block, addr, size); +if (mr->dirty_log_mask) { +memory_region_msync (mr, addr, size); } }
Signature · 1 line
2.21.3
PATCH 3/4 hw/block: Let the NVMe emulated device be target-agnostic
In reply to Philippe Mathieu-DaudéNow than the non-target specific memory_region_msync() function is available, use it to make this device target-agnostic.
--- hw/block/nvme.c | 6 ++---- hw/block/Makefile.objs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
hw/block/nvme.c +2 -4
@@ -46,8 +46,7 @@#include "qapi/visitor.h" #include "sysemu/hostmem.h" #include "sysemu/block-backend.h" -#include "exec/ram_addr.h" - +#include "exec/memory.h" #include "qemu/log.h" #include "qemu/module.h" #include "qemu/cutils.h"
@@ -1207,8 +1206,7 @@ static uint64_t nvme_mmio_read(void *opaque, hwaddr addr, unsigned size)*/ if (addr ==0xE08 && (NVME_PMRCAP_PMRWBM (n->bar.pmrcap) &0x02 )) { -qemu_ram_writeback (n->pmrdev->mr.ram_block, -0 , n->pmrdev->size); +memory_region_msync (&n->pmrdev->mr,0 , n->pmrdev->size); }memcpy (&val, ptr + addr, size); }else {
hw/block/Makefile.objs +1 -1
@@ -13,6 +13,6 @@ common-obj-$(CONFIG_SH4) += tc58128.o obj-$(CONFIG_VIRTIO_BLK) += virtio-blk.o obj-$(CONFIG_VHOST_USER_BLK) += vhost-user-blk.o -obj-$(CONFIG_NVME_PCI) += nvme.o +common-obj-$(CONFIG_NVME_PCI) += nvme.o obj-y += dataplane/
Signature · 1 line
2.21.3
Re: [PATCH 3/4] hw/block: Let the NVMe emulated device be target-agnostic
Quoted 8 lines · Philippe Mathieu-Daudé
Now than the non-target specific
memory_region_msync()function is available, use it to make this device target-agnostic.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/block/nvme.c | 6 ++---- hw/block/Makefile.objs | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-)
r~
PATCH 4/4 exec: Rename qemu_ram_writeback() as qemu_ram_msync()
In reply to Philippe Mathieu-DaudéRename qemu_ram_writeback() as qemu_ram_msync() to better match what it does.
--- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- memory.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/exec/ram_addr.h +2 -2
@@ -136,12 +136,12 @@ void qemu_ram_free(RAMBlock *block);int qemu_ram_resize (RAMBlock *block,ram_addr_t newsize,Error **errp); -void qemu_ram_writeback (RAMBlock *block,ram_addr_t start,ram_addr_t length); +void qemu_ram_msync (RAMBlock *block,ram_addr_t start,ram_addr_t length);/* Clear whole block of mem */ static inline void qemu_ram_block_writeback (RAMBlock *block) { -qemu_ram_writeback (block,0 , block->used_length); +qemu_ram_msync (block,0 , block->used_length); }#define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1)
exec.c +1 -1
@@ -2127,7 +2127,7 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)* Otherwise no-op. * @Note: this is supposed to be a synchronous op. */ -void qemu_ram_writeback (RAMBlock *block,ram_addr_t start,ram_addr_t length) +void qemu_ram_msync (RAMBlock *block,ram_addr_t start,ram_addr_t length) {/* The requested range should fit in within the block range */ g_assert ((start + length) <= block->used_length);
memory.c +1 -1
@@ -2200,7 +2200,7 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errpvoid memory_region_msync (MemoryRegion *mr,hwaddr addr,hwaddr size) {if (mr->ram_block) { -qemu_ram_writeback (mr->ram_block, addr, size); +qemu_ram_msync (mr->ram_block, addr, size); } }
Signature · 1 line
2.21.3
Re: [PATCH 4/4] exec: Rename qemu_ram_writeback() as qemu_ram_msync()
Quoted 10 lines · Philippe Mathieu-Daudé
Rename
qemu_ram_writeback()asqemu_ram_msync()to better match what it does.Suggested-by Stefan Hajnoczi <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- memory.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
r~
Quoted 2 lines · Philippe Mathieu-Daudé
It is not clear if
dccvap_writefn()really needsmemory_region_writeback()or could usememory_region_msync().
Indeed, I don't understand the code and why it matters that mr->dirty_log_mask is nonzero.
mr->dirty_log_mask tells if dirty tracking has been enabled, not if the page is dirty. It would always be true during live migration and when running on TCG, but otherwise it would always be false.
Beata, can you explain what you had in mind? :)
Paolo
Quoted 5 lines · Paolo Bonzini
Quoted 2 lines · Philippe Mathieu-Daudé
It is not clear if
dccvap_writefn()really needsmemory_region_writeback()or could usememory_region_msync().
Quoted 9 lines
Indeed, I don't understand the code and why it matters that
mr->dirty_log_maskis nonzero.
mr->dirty_log_masktells if dirty tracking has been enabled, not if the page is dirty. It would always be true during live migration and when running on TCG, but otherwise it would always be false.Beata, can you explain what you had in mind? :)
It has been a while ... , but the intention there was to skip the sync if there is nothing to be synced in the first place - so for performance reasons. I honestly do not recall why I went for the dirty_log_mask, as that seems not to be the right choice .
BR
Beata
Quoted 2 lines
Paolo
Quoted 11 lines · Beata Michalska
Quoted 7 lines
mr->dirty_log_masktells if dirty tracking has been enabled, not if the page is dirty. It would always be true during live migration and when running on TCG, but otherwise it would always be false.Beata, can you explain what you had in mind? :)
It has been a while ... , but the intention there was to skip the sync if there is nothing to be synced in the first place - so for performance reasons. I honestly do not recall why I went for the
dirty_log_mask, as that seems not to be the right choice .
You probably wanted to look at the dirty bitmap, but you would have to define a new bitmap rather than looking at dirty_log_mask.
But that's cool, because it means that we can just remove it! Thanks,
Paolo
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Beata Michalska
Quoted 7 lines
mr->dirty_log_masktells if dirty tracking has been enabled, not if the page is dirty. It would always be true during live migration and when running on TCG, but otherwise it would always be false.Beata, can you explain what you had in mind? :)
It has been a while ... , but the intention there was to skip the sync if there is nothing to be synced in the first place - so for performance reasons. I honestly do not recall why I went for the
dirty_log_mask, as that seems not to be the right choice .
Quoted 4 lines
You probably wanted to look at the dirty bitmap, but you would have to define a new bitmap rather than looking at
dirty_log_mask.But that's cool, because it means that we can just remove it! Thanks,
So I understand I can simply rename memory_region_writeback -> memory_region_msync in patch #2.
Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · Beata Michalska
Quoted 7 lines
mr->dirty_log_masktells if dirty tracking has been enabled, not if the page is dirty. It would always be true during live migration and when running on TCG, but otherwise it would always be false.Beata, can you explain what you had in mind? :)
It has been a while ... , but the intention there was to skip the sync if there is nothing to be synced in the first place - so for performance reasons. I honestly do not recall why I went for the
dirty_log_mask, as that seems not to be the right choice .
Quoted 7 lines
Quoted 4 lines
You probably wanted to look at the dirty bitmap, but you would have to define a new bitmap rather than looking at
dirty_log_mask.But that's cool, because it means that we can just remove it! Thanks,
So I understand I can simply rename
memory_region_writeback->memory_region_msyncin patch #2.
(removing the mr->dirty_log_mask).
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 2 lines
So I understand I can simply rename
memory_region_writeback->memory_region_msyncin patch #2.(removing the
mr->dirty_log_mask).
Yes.
Paolo
Quoted 11 lines · Philippe Mathieu-Daudé
Let the NVMe emulated device be target-agnostic.
It is not clear if
dccvap_writefn()really needsmemory_region_writeback()or could usememory_region_msync().Philippe Mathieu-Daudé (4):
memory: Renamememory_region_do_writeback->memory_region_writeback
memory: Extractmemory_region_msync()frommemory_region_writeback()hw/block: Let the NVMe emulated device be target-agnostic
exec: Renameqemu_ram_writeback()asqemu_ram_msync()
Quoted 13 lines
include/exec/memory.h | 15 +++++++++++++-- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- hw/block/nvme.c | 6 ++---- memory.c | 12 +++++++++--- target/arm/helper.c | 2 +- hw/block/Makefile.objs | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-)Signature · 1 line
2.21.3
Paolo Bonzini
Acked-byQuoted 21 lines · Stefan Hajnoczi
Quoted 20 lines · Philippe Mathieu-Daudé
Let the NVMe emulated device be target-agnostic.
It is not clear if
dccvap_writefn()really needsmemory_region_writeback()or could usememory_region_msync().Philippe Mathieu-Daudé (4):
memory: Renamememory_region_do_writeback->memory_region_writeback
memory: Extractmemory_region_msync()frommemory_region_writeback()hw/block: Let the NVMe emulated device be target-agnostic
exec: Renameqemu_ram_writeback()asqemu_ram_msync()include/exec/memory.h | 15 +++++++++++++-- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- hw/block/nvme.c | 6 ++---- memory.c | 12 +++++++++--- target/arm/helper.c | 2 +- hw/block/Makefile.objs | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-)
Quoted 7 lines
Quoted 4 lines
Signature · 1 line
2.21.3Reviewed-by Stefan Hajnoczi <[email protected]>
Quoted 27 lines · Paolo Bonzini
Quoted 26 lines · Stefan Hajnoczi
Quoted 24 lines · Philippe Mathieu-Daudé
Let the NVMe emulated device be target-agnostic.
It is not clear if
dccvap_writefn()really needsmemory_region_writeback()or could usememory_region_msync().Philippe Mathieu-Daudé (4):
memory: Renamememory_region_do_writeback->memory_region_writeback
memory: Extractmemory_region_msync()frommemory_region_writeback()hw/block: Let the NVMe emulated device be target-agnostic
exec: Renameqemu_ram_writeback()asqemu_ram_msync()include/exec/memory.h | 15 +++++++++++++-- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- hw/block/nvme.c | 6 ++---- memory.c | 12 +++++++++--- target/arm/helper.c | 2 +- hw/block/Makefile.objs | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-)Signature · 1 line
2.21.3
Quoted 5 lines
Quoted 2 lines
Reviewed-by Stefan Hajnoczi <[email protected]>Acked-by Paolo Bonzini <[email protected]>
Thanks both.
Stefan, do you mind taking the series via your block tree?
Thanks,
Phil.
Stefan Hajnoczi
AppliedQuoted 11 lines · Philippe Mathieu-Daudé
Let the NVMe emulated device be target-agnostic.
It is not clear if
dccvap_writefn()really needsmemory_region_writeback()or could usememory_region_msync().Philippe Mathieu-Daudé (4):
memory: Renamememory_region_do_writeback->memory_region_writeback
memory: Extractmemory_region_msync()frommemory_region_writeback()hw/block: Let the NVMe emulated device be target-agnostic
exec: Renameqemu_ram_writeback()asqemu_ram_msync()
Quoted 8 lines
include/exec/memory.h | 15 +++++++++++++-- include/exec/ram_addr.h | 4 ++-- exec.c | 2 +- hw/block/nvme.c | 6 ++---- memory.c | 12 +++++++++--- target/arm/helper.c | 2 +- hw/block/Makefile.objs | 2 +- 7 files changed, 29 insertions(+), 14 deletions(-)
Thanks, applied to my block tree with Paolo's Acked-by:
https://github.com/stefanha/qemu/commits/block
Stefan