target/arm: Support for Data Cache Clean up to PoP
v3 cover target/arm: Support for Data Cache Clean up to PoP
ARMv8.2 introduced support for Data Cache Clean instructions to PoP (point-of-persistence) and PoDP (point-of-deep-persistence):
ARMv8.2-DCCVAP & ARMv8.2-DCCVADP respectively.
This patch set adds support for emulating both, though there is no distinction between the two points: the PoDP is assumed to represent the same point of persistence as PoP. Case there is no such point specified for the considered memory system both will fall back to the DV CVAC inst (clean up to the point of coherency).
The changes introduced include adding probe_read for validating read memory access to allow verification for mandatory read access for both cache clean instructions, along with support for writeback for requested memory regions through msync, if one is available, based otherwise on fsyncdata.
As currently the virt platform is missing support for NVDIMM, the changes have been tested with [1] & [2]
[1] https://patchwork.kernel.org/cover/10830237/
[2] https://patchwork.kernel.org/project/qemu-devel/list/?series=159441
v3:
- Assert on invalid sync range for ram block
- Drop alignment handling from qemu_msync
v2:
- Moved the msync into a qemu wrapper with CONFIG_POSIX switch + additional comments
- Fixed length alignment
- Dropped treating the DC CVAP/CVADP as special case and moved those to conditional registration
- Dropped needless locking for grabbing mem region
Beata Michalska (4):
tcg: cputlb: Add probe_read
Memory: Enable writeback for given memory region
migration: ram: Switch to ram block writeback target/arm: Add support for DC CVAP & DC CVADP ins
exec.c | 36 +++++++++++++++++++++++++++++++ include/exec/exec-all.h | 6 ++++++ include/exec/memory.h | 6 ++++++ include/exec/ram_addr.h | 8 +++++++ include/qemu/cutils.h | 1 + linux-user/elfload.c | 2 ++ memory.c | 12 +++++++++++ migration/ram.c | 5 +---- target/arm/cpu.h | 10 +++++++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ util/cutils.c | 38 +++++++++++++++++++++++++++++++++ 12 files changed, 177 insertions(+), 4 deletions(-)
Signature · 1 line
2.7.4
PATCH v3 1/4 tcg: cputlb: Add probe_read
Add probe_read alongside the write probing equivalent.
--- include/exec/exec-all.h | 6 ++++++ 1 file changed, 6 insertions(+)
include/exec/exec-all.h +6 -0
@@ -339,6 +339,12 @@ static inline void *probe_write(CPUArchState *env, target_ulong addr, int size,return probe_access (env, addr, size,MMU_DATA_STORE , mmu_idx, retaddr); } +static inline void *probe_read (CPUArchState *env,target_ulong addr,int size, +int mmu_idx,uintptr_t retaddr) +{ +return probe_access (env, addr, size,MMU_DATA_LOAD , mmu_idx, retaddr); +} +#define CODE_GEN_ALIGN 16/* must be >= of the size of a icache line */ /* Estimated block size for TB allocation. */
Signature · 1 line
2.7.4
Re: [PATCH v3 1/4] tcg: cputlb: Add probe_read
Quoted 7 lines · Beata Michalska
Add
probe_readalongside the write probing equivalent.Signed-off-by Beata Michalska <[email protected]>Reviewed-by Alex Bennée <[email protected]>--- include/exec/exec-all.h | 6 ++++++ 1 file changed, 6 insertions(+)
r~
PATCH v3 2/4 Memory: Enable writeback for given memory region
In reply to Beata MichalskaAdd an option to trigger memory writeback to sync given memory region with the corresponding backing store, case one is available. This extends the support for persistent memory, allowing syncing on-demand.
--- exec.c | 36 ++++++++++++++++++++++++++++++++++++ include/exec/memory.h | 6 ++++++ include/exec/ram_addr.h | 8 ++++++++ include/qemu/cutils.h | 1 + memory.c | 12 ++++++++++++ util/cutils.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 101 insertions(+)
exec.c +36 -0
@@ -65,6 +65,8 @@#include "exec/ram_addr.h" #include "exec/log.h" +#include "qemu/pmem.h" +#include "migration/vmstate.h" #include "qemu/range.h"
@@ -2156,6 +2158,40 @@ int qemu_ram_resize(RAMBlock *block, ram_addr_t newsize, Error **errp)return 0 ; } +/* +* Trigger sync on the given ram block for range [start, start + length] +* with the backing store if one is available. +* 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 *addr =ramblock_ptr (block, start); + +/* The requested range should fit in within the block range */ +g_assert ((start + length) <= block->used_length); + +#ifdef CONFIG_LIBPMEM +/* The lack of support for pmem should not block the sync */ +if (ramblock_is_pmem (block)) { +pmem_persist (addr, length); +return ; + } +#endif +if (block->fd >=0 ) { +/** +* Case there is no support for PMEM or the memory has not been +* specified as persistent (or is not one) - use the msync. +* Less optimal but still achieves the same goal +*/ +if (qemu_msync (addr, length, block->fd)) { +warn_report ("%s: failed to sync memory range: start: " +RAM_ADDR_FMT " length: " RAM_ADDR_FMT , + __func__, start, length); + } + } +} +/* Called with ram_list.mutex held */ static void dirty_memory_extend (ram_addr_t old_ram_size,ram_addr_t new_ram_size)
include/exec/memory.h +6 -0
@@ -1265,6 +1265,12 @@ 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 writeback for selected address range +* [addr, addr + size] +* +*/ +void memory_region_do_writeback (MemoryRegion *mr,hwaddr addr,hwaddr size);/** * memory_region_set_log: Turn dirty logging on or off for a region.
include/exec/ram_addr.h +8 -0
@@ -174,6 +174,14 @@ 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); + +/* Clear whole block of mem */ +static inline void qemu_ram_block_writeback (RAMBlock *block) +{ +qemu_ram_writeback (block,0 , block->used_length); +} +#define DIRTY_CLIENTS_ALL ((1 << DIRTY_MEMORY_NUM) - 1)#define DIRTY_CLIENTS_NOCODE (DIRTY_CLIENTS_ALL & ~(1 << DIRTY_MEMORY_CODE))
include/qemu/cutils.h +1 -0
@@ -130,6 +130,7 @@ const char *qemu_strchrnul(const char *s, int c);#endif time_t mktimegm (struct tm *tm);int qemu_fdatasync (int fd); +int qemu_msync (void *addr,size_t length,int fd);int fcntl_setfl (int fd,int flag);int qemu_parse_fd (const char *param); int qemu_strtoi(const char *nptr, const char **endptr, int base,
memory.c +12 -0
@@ -2207,6 +2207,18 @@ void memory_region_ram_resize(MemoryRegion *mr, ram_addr_t newsize, Error **errpqemu_ram_resize (mr->ram_block, newsize, errp); } + +void memory_region_do_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); + } +} +/* * Call proper memory listeners about the change on the newly * added/removed CoalescedMemoryRange.
util/cutils.c +38 -0
@@ -164,6 +164,44 @@ int qemu_fdatasync(int fd)#endif } +/** +* Sync changes made to the memory mapped file back to the backing +* storage. For POSIX compliant systems this will fallback +* to regular msync call. Otherwise it will trigger whole file sync +* (including the metadata case there is no support to skip that otherwise) +* +* @addr - start of the memory area to be synced +* @length - length of the are to be synced +* @fd - file descriptor for the file to be synced +* (mandatory only for POSIX non-compliant systems) +*/ +int qemu_msync (void *addr,size_t length,int fd) +{ +#ifdef CONFIG_POSIX +size_t align_mask = ~(qemu_real_host_page_size -1 ); + +/** +* There are no strict reqs as per the length of mapping +* to be synced. Still the length needs to follow the address +* alignment changes. Additionally - round the size to the multiple +* of PAGE_SIZE +*/ + length += ((uintptr_t )addr & (qemu_real_host_page_size -1 )); + length = (length + ~align_mask) & align_mask; + + addr = (void *)((uintptr_t )addr & align_mask); + +return msync (addr, length,MS_SYNC ); +#else /* CONFIG_POSIX */ +/** +* Perform the sync based on the file descriptor +* The sync range will most probably be wider than the one +* requested - but it will still get the job done +*/ +return qemu_fdatasync (fd); +#endif /* CONFIG_POSIX */ +} +#ifndef _WIN32/* Sets a specific flag */ int fcntl_setfl (int fd,int flag)
Signature · 1 line
2.7.4
Re: [PATCH v3 2/4] Memory: Enable writeback for given memory region
Quoted 5 lines · Beata Michalska
Add an option to trigger memory writeback to sync given memory region with the corresponding backing store, case one is available. This extends the support for persistent memory, allowing syncing on-demand.
Signed-off-by Beata Michalska <[email protected]>
Quoted 8 lines
--- exec.c | 36 ++++++++++++++++++++++++++++++++++++ include/exec/memory.h | 6 ++++++ include/exec/ram_addr.h | 8 ++++++++ include/qemu/cutils.h | 1 + memory.c | 12 ++++++++++++ util/cutils.c | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 101 insertions(+)
r~
PATCH v3 3/4 migration: ram: Switch to ram block writeback
In reply to Beata MichalskaSwitch to ram block writeback for pmem migration.
--- migration/ram.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
migration/ram.c +1 -4
@@ -33,7 +33,6 @@#include "qemu/bitops.h" #include "qemu/bitmap.h" #include "qemu/main-loop.h" -#include "qemu/pmem.h" #include "xbzrle.h" #include "ram.h" #include "migration.h"
@@ -3981,9 +3980,7 @@ static int ram_load_cleanup(void *opaque)RAMBlock *rb;RAMBLOCK_FOREACH_NOT_IGNORED (rb) { -if (ramblock_is_pmem (rb)) { -pmem_persist (rb->host, rb->used_length); - } +qemu_ram_block_writeback (rb); }xbzrle_load_cleanup ();
Signature · 1 line
2.7.4
PATCH v3 4/4 target/arm: Add support for DC CVAP & DC CVADP ins
In reply to Beata MichalskaARMv8.2 introduced support for Data Cache Clean instructions
to PoP (point-of-persistence) - DC CVAP and PoDP (point-of-deep-persistence)
- DV CVADP. Both specify conceptual points in a memory system where all writes that are to reach them are considered persistent.
The support provided considers both to be actually the same so there is no distinction between the two. If none is available (there is no backing store for given memory) both will result in Data Cache Clean up to the point of coherency. Otherwise sync for the specified range shall be performed.
--- linux-user/elfload.c | 2 ++ target/arm/cpu.h | 10 ++++++++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 69 insertions(+)
linux-user/elfload.c +2 -0
@@ -656,6 +656,7 @@ static uint32_t get_elf_hwcap(void)GET_FEATURE_ID (aa64_jscvt,ARM_HWCAP_A64_JSCVT );GET_FEATURE_ID (aa64_sb,ARM_HWCAP_A64_SB );GET_FEATURE_ID (aa64_condm_4,ARM_HWCAP_A64_FLAGM ); +GET_FEATURE_ID (aa64_dcpop,ARM_HWCAP_A64_DCPOP );return hwcaps; }
@@ -665,6 +666,7 @@ static uint32_t get_elf_hwcap2(void)ARMCPU *cpu =ARM_CPU (thread_cpu);uint32_t hwcaps =0 ; +GET_FEATURE_ID (aa64_dcpodp,ARM_HWCAP2_A64_DCPODP );GET_FEATURE_ID (aa64_condm_5,ARM_HWCAP2_A64_FLAGM2 );GET_FEATURE_ID (aa64_frint,ARM_HWCAP2_A64_FRINT );
target/arm/cpu.h +10 -0
@@ -3616,6 +3616,16 @@ static inline bool isar_feature_aa64_frint(const ARMISARegisters *id)return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,FRINTTS ) !=0 ; } +static inline bool isar_feature_aa64_dcpop (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,DPB ) !=0 ; +} + +static inline bool isar_feature_aa64_dcpodp (const ARMISARegisters *id) +{ +return FIELD_EX64 (id->id_aa64isar1,ID_AA64ISAR1 ,DPB ) >=2 ; +} +static inline bool isar_feature_aa64_fp16 (const ARMISARegisters *id) {/* We always set the AdvSIMD and FP fields identically wrt FP16. */
target/arm/cpu64.c +1 -0
@@ -646,6 +646,7 @@ static void aarch64_max_initfn(Object *obj) cpu->isar.id_aa64isar0 = t; t = cpu->isar.id_aa64isar1; + t =FIELD_DP64 (t,ID_AA64ISAR1 ,DPB ,2 ); t =FIELD_DP64 (t,ID_AA64ISAR1 ,JSCVT ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR1 ,FCMA ,1 ); t =FIELD_DP64 (t,ID_AA64ISAR1 ,APA ,1 );/* PAuth, architected only */
target/arm/helper.c +56 -0
68 lines not on this page · raw message
Signature · 1 line
2.7.4
Peter Maydell
AppliedQuoted 13 lines · Beata Michalska
ARMv8.2 introduced support for Data Cache Clean instructions to PoP (point-of-persistence) and PoDP (point-of-deep-persistence):
ARMv8.2-DCCVAP & ARMv8.2-DCCVADP respectively.
This patch set adds support for emulating both, though there is no distinction between the two points: the PoDP is assumed to represent the same point of persistence as PoP. Case there is no such point specified for the considered memory system both will fall back to the DV CVAC inst (clean up to the point of coherency).
The changes introduced include addingprobe_readfor validating read memory access to allow verification for mandatory read access for both cache clean instructions, along with support for writeback for requested memory regions through msync, if one is available, based otherwise on fsyncdata.
Applied to target-arm.next for 5.0, thanks.
-- PMM