Mark non-volatile memory regions
cover Mark non-volatile memory regions
Hi,
As discussed in the "[PATCH v10 6/6] tpm: add ACPI memory clear interface" thread, and proposed in the "[PATCH] RFC: mark non-volatile memory region", here is a small series to mark non-volvatile memory regions and skip them on dump. Upcoming TCG "Platform Reset Attack Mitigation" will also use this information to eventually skip non-volatile memory.
Thanks
Marc-André Lureau (3):
memory: learn about non-volatile memory region
nvdimm: set non-volatile on the memory region
memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
include/exec/memory.h | 25 ++++++++++++++++++++++ hw/mem/nvdimm.c | 1 + memory.c | 45 +++++++++++++++++++++++++++++++--------- memory_mapping.c | 3 ++- docs/devel/migration.rst | 1 + 5 files changed, 64 insertions(+), 11 deletions(-)
Signature · 1 line
2.19.0.271.gfe8321ec05
PATCH 1/3 memory: learn about non-volatile memory region
Add a new flag to mark memory region that are used as non-volatile, by NVDIMM for example. That bit is propagated down to the flat view, and reflected in HMP info mtree with a "nv-" prefix on the memory type.
This way, guest_phys_blocks_region_add() can skip the NV memory regions for dumps and TCG memory clear in a following patch.
--- include/exec/memory.h | 25 ++++++++++++++++++++++ memory.c | 45 +++++++++++++++++++++++++++++++--------- docs/devel/migration.rst | 1 + 3 files changed, 61 insertions(+), 10 deletions(-)
include/exec/memory.h +25 -0
@@ -355,6 +355,7 @@ struct MemoryRegion {bool ram;bool subpage;bool readonly;/* For RAM regions */ +bool nonvolatile;bool rom_device;bool flush_coalesced_mmio;bool global_locking;
@@ -480,6 +481,7 @@ static inline FlatView *address_space_to_flatview(AddressSpace *as)* @offset_within_address_space: the address of the first byte of the section * relative to the region's address space * @readonly: writes to this section are ignored +* @nonvolatile: this section is non-volatile */ struct MemoryRegionSection {MemoryRegion *mr;
@@ -488,6 +490,7 @@ struct MemoryRegionSection {Int128 size;hwaddr offset_within_address_space;bool readonly; +bool nonvolatile; };/**
@@ -1170,6 +1173,17 @@ static inline bool memory_region_is_rom(MemoryRegion *mr)return mr->ram && mr->readonly; } +/** +* memory_region_is_nonvolatile: check whether a memory region is non-volatile +* +* Returns %true is a memory region is non-volatile memory. +* +* @mr: the memory region being queried +*/ +static inline bool memory_region_is_nonvolatile (MemoryRegion *mr) +{ +return mr->nonvolatile; +}/** * memory_region_get_fd: Get a file descriptor backing a RAM memory region.
@@ -1341,6 +1355,17 @@ void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr,*/ void memory_region_set_readonly (MemoryRegion *mr,bool readonly); +/** +* memory_region_set_nonvolatile: Turn a memory region non-volatile +* +* Allows a memory region to be marked as non-volatile. +* only useful on RAM regions. +* +* @mr: the region being updated. +* @nonvolatile: whether rhe region is to be non-volatile. +*/ +void memory_region_set_nonvolatile (MemoryRegion *mr,bool nonvolatile); +/** * memory_region_rom_device_set_romd: enable/disable ROMD mode *
memory.c +35 -10
150 lines not on this page · raw message
docs/devel/migration.rst +1 -0
@@ -435,6 +435,7 @@ Examples of such memory API functions are: - memory_region_add_subregion() - memory_region_del_subregion() - memory_region_set_readonly() + - memory_region_set_nonvolatile() - memory_region_set_enabled() - memory_region_set_address() - memory_region_set_alias_offset()
Signature · 1 line
2.19.0.271.gfe8321ec05
PATCH 2/3 nvdimm: set non-volatile on the memory region
In reply to Marc-André Lureauqemu-system-x86_64 -machine pc,nvdimm -m 2G,slots=4,maxmem=16G -enable-kvm -monitor stdio -object memory-backend-file,id=mem1,share=on,mem-path=/tmp/foo,size=1G -device nvdimm,id=nvdimm1,memdev=mem1
HMP info mtree command reflects the flag with "nv-" prefix on memory type:
(qemu) info mtree
0000000100000000-000000013fffffff (prio 0, nv-i/o): alias nvdimm-memory @/objects/mem1 0000000000000000-000000003fffffff
(qemu) info mtree -f
0000000100000000-000000013fffffff (prio 0, nv-ram): /objects/mem1
--- hw/mem/nvdimm.c | 1 + 1 file changed, 1 insertion(+)
hw/mem/nvdimm.c +1 -0
@@ -115,6 +115,7 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice *nvdimm, Error **errp) nvdimm->nvdimm_mr =g_new (MemoryRegion,1 );memory_region_init_alias (nvdimm->nvdimm_mr,OBJECT (dimm),"nvdimm-memory" , mr,0 , pmem_size); +memory_region_set_nonvolatile (nvdimm->nvdimm_mr, true); nvdimm->nvdimm_mr->align = align; }
Signature · 1 line
2.19.0.271.gfe8321ec05
PATCH 3/3 memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
In reply to Marc-André LureauGuestPhysBlockList is currently used to produce dumps. Given the size and the typical usage of NVDIMM for storage, they are not a good idea to have in the dumps. We may want to have an extra dump option to include them. For now, skip non-volatile regions.
The TCG memory clear function is going to use the GuestPhysBlockList as well, and will thus skip NVDIMM for similar reasons.
--- memory_mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
memory_mapping.c +2 -1
@@ -206,7 +206,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,/* we only care about RAM */ if (!memory_region_is_ram (section->mr) || -memory_region_is_ram_device (section->mr)) { +memory_region_is_ram_device (section->mr) || +memory_region_is_nonvolatile (section->mr)) {return ; }
Signature · 1 line
2.19.0.271.gfe8321ec05
Re: [Qemu-devel] [PATCH 3/3] memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
Quoted 20 lines · Marc-André Lureau
GuestPhysBlockList is currently used to produce dumps. Given the size and the typical usage of NVDIMM for storage, they are not a good idea to have in the dumps. We may want to have an extra dump option to include them. For now, skip non-volatile regions.
The TCG memory clear function is going to use the GuestPhysBlockList as well, and will thus skip NVDIMM for similar reasons.
Signed-off-by Marc-André Lureau <[email protected]>--- memory_mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)memory_mapping.c +0
-0
memory_mapping.c static void guest_phys_blocks_region_add(MemoryListener *listener, · line 213
Quoted 9 lines
memory_mapping.c +2
-1@@ -206,7 +206,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,/* we only care about RAM */ if (!memory_region_is_ram (section->mr) || -memory_region_is_ram_device (section->mr)) { +memory_region_is_ram_device (section->mr) || +memory_region_is_nonvolatile (section->mr)) {return ; }
I've peeked at the first two patches as well. Seems OK to me. (Famous last words?)
Re: [Qemu-devel] [PATCH 3/3] memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
Quoted 34 lines · * Laszlo Ersek ([email protected]) wrote:
Quoted 20 lines · Marc-André Lureau
GuestPhysBlockList is currently used to produce dumps. Given the size and the typical usage of NVDIMM for storage, they are not a good idea to have in the dumps. We may want to have an extra dump option to include them. For now, skip non-volatile regions.
The TCG memory clear function is going to use the GuestPhysBlockList as well, and will thus skip NVDIMM for similar reasons.
Signed-off-by Marc-André Lureau <[email protected]>--- memory_mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)memory_mapping.c +0
-0memory_mapping.c static void guest_phys_blocks_region_add(MemoryListener *listener, · line 213
Quoted 9 lines
memory_mapping.c +2
-1@@ -206,7 +206,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,/* we only care about RAM */ if (!memory_region_is_ram (section->mr) || -memory_region_is_ram_device (section->mr)) { +memory_region_is_ram_device (section->mr) || +memory_region_is_nonvolatile (section->mr)) {return ; }I've peeked at the first two patches as well. Seems OK to me. (Famous last words?)
Quoted 1 line
Reviewed-by Laszlo Ersek <[email protected]>
This also looks good to me; just cc'ing in David H as well though.
Dave
--
Dr. David Alan Gilbert / [email protected] / Manchester, UK
David Hildenbrand
Reviewed-byRe: [Qemu-devel] [PATCH 3/3] memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
Quoted 35 lines · Dr. David Alan Gilbert
Quoted 34 lines · * Laszlo Ersek ([email protected]) wrote:
Quoted 20 lines · Marc-André Lureau
GuestPhysBlockList is currently used to produce dumps. Given the size and the typical usage of NVDIMM for storage, they are not a good idea to have in the dumps. We may want to have an extra dump option to include them. For now, skip non-volatile regions.
The TCG memory clear function is going to use the GuestPhysBlockList as well, and will thus skip NVDIMM for similar reasons.
Signed-off-by Marc-André Lureau <[email protected]>--- memory_mapping.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)memory_mapping.c +0
-0memory_mapping.c static void guest_phys_blocks_region_add(MemoryListener *listener, · line 213
Quoted 9 lines
memory_mapping.c +2
-1@@ -206,7 +206,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,/* we only care about RAM */ if (!memory_region_is_ram (section->mr) || -memory_region_is_ram_device (section->mr)) { +memory_region_is_ram_device (section->mr) || +memory_region_is_nonvolatile (section->mr)) {return ; }I've peeked at the first two patches as well. Seems OK to me. (Famous last words?)
Quoted 4 lines
Quoted 1 line
Reviewed-by Laszlo Ersek <[email protected]>This also looks good to me; just cc'ing in David H as well though.
Thanks Dave. Yes, just like the guest will exclude NVDIMMs from dumps, so should we. (if somebody ever want to have this e.g. because the NVDIMM is based on RAM in the host, we can introduce what you describe - extra dump option).
Signature · 3 lines
Thanks, David / dhildenb
Re: [Qemu-devel] [PATCH 3/3] memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
In reply to Marc-André LureauQuoted 5 lines · Marc-André Lureau
memory_mapping.c +0
-0
memory_mapping.c static void guest_phys_blocks_region_add(MemoryListener *listener, · line 213
Quoted 9 lines
memory_mapping.c +2
-1@@ -206,7 +206,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,/* we only care about RAM */ if (!memory_region_is_ram (section->mr) || -memory_region_is_ram_device (section->mr)) { +memory_region_is_ram_device (section->mr) || +memory_region_is_nonvolatile (section->mr)) {return ; }
We should also have
scripts/dump-guest-memory.py +3 -1
@@ -417,7 +417,9 @@ def get_guest_phys_blocks(): memory_region = flat_range["mr"].dereference() # we only care about RAM - if not memory_region["ram"]: + if not memory_region["ram"] \ + or memory_region["ram_device"] \ + or memory_region["nonvolatile"]: continue section_size = int128_get64(flat_range["addr"]["size"])
here. I queued the patches and will post this soon as a separate patch.
Paolo
Re: [Qemu-devel] [PATCH 3/3] memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
Quoted 34 lines · Paolo Bonzini
Quoted 5 lines · Marc-André Lureau
memory_mapping.c +0
-0memory_mapping.c static void guest_phys_blocks_region_add(MemoryListener *listener, · line 213
Quoted 9 lines
memory_mapping.c +2
-1@@ -206,7 +206,8 @@ static void guest_phys_blocks_region_add(MemoryListener *listener,/* we only care about RAM */ if (!memory_region_is_ram (section->mr) || -memory_region_is_ram_device (section->mr)) { +memory_region_is_ram_device (section->mr) || +memory_region_is_nonvolatile (section->mr)) {return ; }We should also have
scripts/dump-guest-memory.py +3
-1@@ -417,7 +417,9 @@ def get_guest_phys_blocks(): memory_region = flat_range["mr"].dereference() # we only care about RAM - if not memory_region["ram"]: + if not memory_region["ram"] \ + or memory_region["ram_device"] \ + or memory_region["nonvolatile"]: continue section_size = int128_get64(flat_range["addr"]["size"])
Quoted 1 line
here. I queued the patches and will post this soon as a separate patch.
Thanks. I keep forgetting that this logic is duplicated.
Laszlo
Hi
Quoted 10 lines · Marc-André Lureau
Hi,
As discussed in the "[PATCH v10 6/6] tpm: add ACPI memory clear interface" thread, and proposed in the "[PATCH] RFC: mark non-volatile memory region", here is a small series to mark non-volvatile memory regions and skip them on dump. Upcoming TCG "Platform Reset Attack Mitigation" will also use this information to eventually skip non-volatile memory.
Quoted 6 lines
Thanks
Marc-André Lureau (3):
memory: learn about non-volatile memory region
nvdimm: set non-volatile on the memory region
memory-mapping: skip non-volatile memory regions in GuestPhysBlockList
Only last patch got reviews, but that means the first are probably ok as well. Is anybody reviewing & picking the series?
thanks
Quoted 12 lines
include/exec/memory.h | 25 ++++++++++++++++++++++ hw/mem/nvdimm.c | 1 + memory.c | 45 +++++++++++++++++++++++++++++++--------- memory_mapping.c | 3 ++- docs/devel/migration.rst | 1 + 5 files changed, 64 insertions(+), 11 deletions(-)--
2.19.0.271.gfe8321ec05
Signature · 1 line
Marc-André Lureau