target/arm/arch_dump: Add SVE notes
PATCH v2 1/1 target/arm/arch_dump: Add SVE notes
When dumping a guest with dump-guest-memory also dump the SVE registers if they are in use.
--- include/elf.h | 2 + target/arm/arch_dump.c | 135 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 2 deletions(-)
include/elf.h +2 -0
@@ -1650,6 +1650,8 @@ typedef struct elf64_shdr {#define NT_ARM_HW_BREAK 0x402/* ARM hardware breakpoint registers */ #define NT_ARM_HW_WATCH 0x403/* ARM hardware watchpoint registers */ #define NT_ARM_SYSTEM_CALL 0x404/* ARM system call number */ +#define NT_ARM_SVE 0x405/* ARM Scalable Vector Extension +registers */ /* * Physical entry point into the kernel.
target/arm/arch_dump.c +133 -2
175 lines not on this page · raw message
Signature · 1 line
2.20.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH v2] target/arm/arch_dump: Add SVE notes
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Switched to a new branch 'test'
9d21a9a target/arm/arch_dump: Add SVE notes
=== OUTPUT BEGIN ===
ERROR: code indent should never use tabs
#21: FILE: include/elf.h:1653:
+#define NT_ARM_SVE^I0x405^I^I/* ARM Scalable Vector Extension$
WARNING: Block comments use a leading /* on a separate line #21: FILE: include/elf.h:1653:
+#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension
ERROR: code indent should never use tabs
#22: FILE: include/elf.h:1654:
+^I^I^I^I^I registers */$
WARNING: Block comments use * on subsequent lines
#22: FILE: include/elf.h:1654:
+#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension
+ registers */
WARNING: Block comments use a trailing */ on a separate line #22: FILE: include/elf.h:1654:
+ registers */
total: 2 errors, 3 warnings, 183 lines checked
Commit 9d21a9a5cba2 (target/arm/arch_dump: Add SVE notes) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 23 lines · Andrew Jones
target/arm/arch_dump.c +23
-0+#ifdef TARGET_AARCH64 +static off_t sve_zreg_offset (uint32_t vq,int n) +{ +off_t off =sizeof (struct aarch64_user_sve_header ); +return ROUND_UP (off,16 ) + vq *16 * n; +} +static off_t sve_preg_offset (uint32_t vq,int n) +{ +return sve_zreg_offset (vq,32 ) + vq *16 /8 * n; +} +static off_t sve_fpsr_offset (uint32_t vq) +{ +off_t off =sve_preg_offset (vq,17 ) + offsetof(struct aarch64_note , sve); +return ROUND_UP (off,16 ) - offsetof(struct aarch64_note , sve); +} +static off_t sve_fpcr_offset (uint32_t vq) +{ +return sve_fpsr_offset (vq) +sizeof (uint32_t ); +} +static uint32_t sve_current_vq (CPUARMState *env) +{ +return sve_zcr_len_for_el (env,arm_current_el (env)) +1 ; +}
target/arm/arch_dump.c static int aarch64_write_elf64_prfpreg(WriteCoreDumpFunction f, · line 176
Quoted 10 lines
target/arm/arch_dump.c +10
-0+static size_t sve_size_vq (uint32_t vq) +{ +off_t off =sve_fpcr_offset (vq) +sizeof (uint32_t ) + + offsetof(struct aarch64_note , sve); +return ROUND_UP (off,16 ) - offsetof(struct aarch64_note , sve); +} +static size_t sve_size (CPUARMState *env) +{ +return sve_size_vq (sve_current_vq (env)); +}
Watch the missing spaces between functions.
target/arm/arch_dump.c static int aarch64_write_elf64_prfpreg(WriteCoreDumpFunction f, · line 212
Quoted 13 lines
target/arm/arch_dump.c +13
-0+for (i =0 ; i <32 ; ++i) { +#ifdef HOST_WORDS_BIGENDIAN +uint64_t d[vq *2 ]; +int j; + +for (j =0 ; j < vq *2 ; ++j) { + d[j] =bswap64 (env->vfp.zregs[i].d[j]); + } +#else +uint64_t *d = &env->vfp.zregs[i].d[0 ]; +#endif +memcpy (&buf[sve_zreg_offset (vq, i)], &d[0 ], vq *16 ); + }
We should avoid the variable sized array here.
It might be best to avoid the ifdef altogether:
for (i = 0; i < 32; ++i) {
uint64_t *d = (uint64_t *)&buf[sve_zreg_offset(vq, i)];
for (j = 0; j < vq * 2; ++j) {
d[j] = cpu_to_le64(env->vfp.zregs[i].d[j]);
}
}The compiler may well transform the inner loop to memcpy for little-endian host, but even if it doesn't core dumping is hardly performance sensitive.
r~
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Andrew Jones
target/arm/arch_dump.c +27
-0+#ifdef TARGET_AARCH64 +static off_t sve_zreg_offset (uint32_t vq,int n) +{ +off_t off =sizeof (struct aarch64_user_sve_header ); +return ROUND_UP (off,16 ) + vq *16 * n; +} +static off_t sve_preg_offset (uint32_t vq,int n) +{ +return sve_zreg_offset (vq,32 ) + vq *16 /8 * n; +} +static off_t sve_fpsr_offset (uint32_t vq) +{ +off_t off =sve_preg_offset (vq,17 ) + offsetof(struct aarch64_note , sve); +return ROUND_UP (off,16 ) - offsetof(struct aarch64_note , sve); +} +static off_t sve_fpcr_offset (uint32_t vq) +{ +return sve_fpsr_offset (vq) +sizeof (uint32_t ); +} +static uint32_t sve_current_vq (CPUARMState *env) +{ +return sve_zcr_len_for_el (env,arm_current_el (env)) +1 ; +} +static size_t sve_size_vq (uint32_t vq) +{ +off_t off =sve_fpcr_offset (vq) +sizeof (uint32_t ) + + offsetof(struct aarch64_note , sve);
Quoted 8 lines
target/arm/arch_dump.c static int aarch64_write_elf64_prfpreg(WriteCoreDumpFunction f, · line 176
Quoted 6 lines
target/arm/arch_dump.c +6
-0+return ROUND_UP (off,16 ) - offsetof(struct aarch64_note , sve); +} +static size_t sve_size (CPUARMState *env) +{ +return sve_size_vq (sve_current_vq (env)); +}Watch the missing spaces between functions.
I'll put in the blank lines
Quoted 26 lines
Quoted 4 lines
target/arm/arch_dump.c +3
-0+for (i =0 ; i <32 ; ++i) { +#ifdef HOST_WORDS_BIGENDIAN +uint64_t d[vq *2 ];target/arm/arch_dump.c static int aarch64_write_elf64_prfpreg(WriteCoreDumpFunction f, · line 212
Quoted 10 lines
target/arm/arch_dump.c +10
-0+int j; + +for (j =0 ; j < vq *2 ; ++j) { + d[j] =bswap64 (env->vfp.zregs[i].d[j]); + } +#else +uint64_t *d = &env->vfp.zregs[i].d[0 ]; +#endif +memcpy (&buf[sve_zreg_offset (vq, i)], &d[0 ], vq *16 ); + }We should avoid the variable sized array here.
It might be best to avoid the ifdef altogether:
for (i = 0; i < 32; ++i) { uint64_t *d = (uint64_t *)&buf[sve_zreg_offset(vq, i)]; for (j = 0; j < vq * 2; ++j) { d[j] = cpu_to_le64(env->vfp.zregs[i].d[j]); } }
Quoted 2 lines
The compiler may well transform the inner loop to memcpy for little-endian host, but even if it doesn't core dumping is hardly performance sensitive.
True. I even had something like the above at first, but then overcomplicated it with the #ifdef-ing.
Thanks,
drew
Quoted 9 lines · Andrew Jones
Quoted 9 lines
It might be best to avoid the ifdef altogether:
for (i = 0; i < 32; ++i) { uint64_t *d = (uint64_t *)&buf[sve_zreg_offset(vq, i)]; for (j = 0; j < vq * 2; ++j) { d[j] = cpu_to_le64(env->vfp.zregs[i].d[j]); } }
Quoted 5 lines
Quoted 2 lines
The compiler may well transform the inner loop to memcpy for little-endian host, but even if it doesn't core dumping is hardly performance sensitive.
True. I even had something like the above at first, but then overcomplicated it with the #ifdef-ing.
Ah, I wonder if you changed things around with the ifdefs due to the pregs. There's no trivial solution for those. It'd be nice to share the bswapping subroutine that you add in the SVE KVM patch set, and size the temporary array using ARM_MAX_VQ.
r~
Quoted 13 lines · Richard Henderson
Quoted 12 lines · Andrew Jones
Quoted 11 lines
It might be best to avoid the ifdef altogether:
for (i = 0; i < 32; ++i) { uint64_t *d = (uint64_t *)&buf[sve_zreg_offset(vq, i)]; for (j = 0; j < vq * 2; ++j) { d[j] = cpu_to_le64(env->vfp.zregs[i].d[j]); } }The compiler may well transform the inner loop to memcpy for little-endian host, but even if it doesn't core dumping is hardly performance sensitive.
Quoted 7 lines
Quoted 2 lines
True. I even had something like the above at first, but then overcomplicated it with the #ifdef-ing.
Ah, I wonder if you changed things around with the ifdefs due to the pregs. There's no trivial solution for those. It'd be nice to share the bswapping subroutine that you add in the SVE KVM patch set, and size the temporary array using
ARM_MAX_VQ.
How about something like this squashed in?
Thanks,
drew
target/arm/arch_dump.c +6 -22
@@ -182,6 +182,7 @@ static int aarch64_write_elf64_sve(WriteCoreDumpFunction f,struct aarch64_note *note;ARMCPU *cpu =env_archcpu (env);uint32_t vq =sve_current_vq (env); +uint64_t tmp[ARM_MAX_VQ *2 ], *r;uint32_t fpr;uint8_t *buf;int ret, i;
@@ -198,31 +199,14 @@ static int aarch64_write_elf64_sve(WriteCoreDumpFunction f, note->sve.flags =cpu_to_dump16 (s,1 );for (i =0 ; i <32 ; ++i) { -#ifdef HOST_WORDS_BIGENDIAN -uint64_t d[vq *2 ]; -int j; - -for (j =0 ; j < vq *2 ; ++j) { - d[j] =bswap64 (env->vfp.zregs[i].d[j]); - } -#else -uint64_t *d = &env->vfp.zregs[i].d[0 ]; -#endif -memcpy (&buf[sve_zreg_offset (vq, i)], &d[0 ], vq *16 ); + r =sve_bswap64 (tmp, &env->vfp.zregs[i].d[0 ], vq *2 ); +memcpy (&buf[sve_zreg_offset (vq, i)], r, vq *16 ); }for (i =0 ; i <17 ; ++i) { -#ifdef HOST_WORDS_BIGENDIAN -uint64_t d[DIV_ROUND_UP (vq *2 ,8 )]; -int j; - -for (j =0 ; j <DIV_ROUND_UP (vq *2 ,8 ); ++j) { - d[j] =bswap64 (env->vfp.pregs[i].p[j]); - } -#else -uint64_t *d = &env->vfp.pregs[i].p[0 ]; -#endif -memcpy (&buf[sve_preg_offset (vq, i)], &d[0 ], vq *16 /8 ); + r =sve_bswap64 (tmp, r = &env->vfp.pregs[i].p[0 ], +DIV_ROUND_UP (vq *2 ,8 )); +memcpy (&buf[sve_preg_offset (vq, i)], r, vq *16 /8 ); } fpr =cpu_to_dump32 (s,vfp_get_fpsr (env));
target/arm/cpu.h +25 -0
@@ -975,6 +975,31 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64);void aarch64_add_sve_properties (Object *obj); + +/* +* SVE registers are encoded in KVM's memory in an endianness-invariant format. +* The byte at offset i from the start of the in-memory representation contains +* the bits [(7 + 8 * i) : (8 * i)] of the register value. As this means the +* lowest offsets are stored in the lowest memory addresses, then that nearly +* matches QEMU's representation, which is to use an array of host-endian +* uint64_t's, where the lower offsets are at the lower indices. To complete +* the translation we just need to byte swap the uint64_t's on big-endian hosts. +*/ +static inline uint64_t *sve_bswap64 (uint64_t *dst,uint64_t *src,int nr) +{ +#ifdef HOST_WORDS_BIGENDIAN +int i; + +for (i =0 ; i < nr; ++i) { + dst[i] =bswap64 (src[i]); + } + +return dst; +#else +return src; +#endif +} +#else static inline void aarch64_sve_narrow_vq (CPUARMState *env,unsigned vq) { } static inline void aarch64_sve_change_el(CPUARMState *env, int o,
target/arm/kvm64.c +0 -24
@@ -876,30 +876,6 @@ static int kvm_arch_put_fpsimd(CPUState *cs)return 0 ; } -/* -* SVE registers are encoded in KVM's memory in an endianness-invariant format. -* The byte at offset i from the start of the in-memory representation contains -* the bits [(7 + 8 * i) : (8 * i)] of the register value. As this means the -* lowest offsets are stored in the lowest memory addresses, then that nearly -* matches QEMU's representation, which is to use an array of host-endian -* uint64_t's, where the lower offsets are at the lower indices. To complete -* the translation we just need to byte swap the uint64_t's on big-endian hosts. -*/ -static uint64_t *sve_bswap64 (uint64_t *dst,uint64_t *src,int nr) -{ -#ifdef HOST_WORDS_BIGENDIAN -int i; - -for (i =0 ; i < nr; ++i) { - dst[i] =bswap64 (src[i]); - } - -return dst; -#else -return src; -#endif -} -/* * KVM SVE registers come in slices where ZREGs have a slice size of 2048 bits * and PREGS and the FFR have a slice size of 256 bits. However we simply hard
Quoted 7 lines · Andrew Jones
Quoted 4 lines · Richard Henderson
Ah, I wonder if you changed things around with the ifdefs due to the pregs. There's no trivial solution for those. It'd be nice to share the bswapping subroutine that you add in the SVE KVM patch set, and size the temporary array using
ARM_MAX_VQ.How about something like this squashed in?
Looks good.
r~
Quoted 125 lines
Thanks,
drewtarget/arm/arch_dump.c +6
-22@@ -182,6 +182,7 @@ static int aarch64_write_elf64_sve(WriteCoreDumpFunction f,struct aarch64_note *note;ARMCPU *cpu =env_archcpu (env);uint32_t vq =sve_current_vq (env); +uint64_t tmp[ARM_MAX_VQ *2 ], *r;uint32_t fpr;uint8_t *buf;int ret, i;@@ -198,31 +199,14 @@ static int aarch64_write_elf64_sve(WriteCoreDumpFunction f, note->sve.flags =cpu_to_dump16 (s,1 );for (i =0 ; i <32 ; ++i) { -#ifdef HOST_WORDS_BIGENDIAN -uint64_t d[vq *2 ]; -int j; - -for (j =0 ; j < vq *2 ; ++j) { - d[j] =bswap64 (env->vfp.zregs[i].d[j]); - } -#else -uint64_t *d = &env->vfp.zregs[i].d[0 ]; -#endif -memcpy (&buf[sve_zreg_offset (vq, i)], &d[0 ], vq *16 ); + r =sve_bswap64 (tmp, &env->vfp.zregs[i].d[0 ], vq *2 ); +memcpy (&buf[sve_zreg_offset (vq, i)], r, vq *16 ); }for (i =0 ; i <17 ; ++i) { -#ifdef HOST_WORDS_BIGENDIAN -uint64_t d[DIV_ROUND_UP (vq *2 ,8 )]; -int j; - -for (j =0 ; j <DIV_ROUND_UP (vq *2 ,8 ); ++j) { - d[j] =bswap64 (env->vfp.pregs[i].p[j]); - } -#else -uint64_t *d = &env->vfp.pregs[i].p[0 ]; -#endif -memcpy (&buf[sve_preg_offset (vq, i)], &d[0 ], vq *16 /8 ); + r =sve_bswap64 (tmp, r = &env->vfp.pregs[i].p[0 ], +DIV_ROUND_UP (vq *2 ,8 )); +memcpy (&buf[sve_preg_offset (vq, i)], r, vq *16 /8 ); } fpr =cpu_to_dump32 (s,vfp_get_fpsr (env));target/arm/cpu.h +25
-0@@ -975,6 +975,31 @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq);void aarch64_sve_change_el (CPUARMState *env,int old_el,int new_el,bool el0_a64);void aarch64_add_sve_properties (Object *obj); + +/* +* SVE registers are encoded in KVM's memory in an endianness-invariant format. +* The byte at offset i from the start of the in-memory representation contains +* the bits [(7 + 8 * i) : (8 * i)] of the register value. As this means the +* lowest offsets are stored in the lowest memory addresses, then that nearly +* matches QEMU's representation, which is to use an array of host-endian +* uint64_t's, where the lower offsets are at the lower indices. To complete +* the translation we just need to byte swap the uint64_t's on big-endian hosts. +*/ +static inline uint64_t *sve_bswap64 (uint64_t *dst,uint64_t *src,int nr) +{ +#ifdef HOST_WORDS_BIGENDIAN +int i; + +for (i =0 ; i < nr; ++i) { + dst[i] =bswap64 (src[i]); + } + +return dst; +#else +return src; +#endif +} +#else static inline void aarch64_sve_narrow_vq (CPUARMState *env,unsigned vq) { } static inline void aarch64_sve_change_el(CPUARMState *env, int o,target/arm/kvm64.c +0
-24@@ -876,30 +876,6 @@ static int kvm_arch_put_fpsimd(CPUState *cs)return 0 ; } -/* -* SVE registers are encoded in KVM's memory in an endianness-invariant format. -* The byte at offset i from the start of the in-memory representation contains -* the bits [(7 + 8 * i) : (8 * i)] of the register value. As this means the -* lowest offsets are stored in the lowest memory addresses, then that nearly -* matches QEMU's representation, which is to use an array of host-endian -* uint64_t's, where the lower offsets are at the lower indices. To complete -* the translation we just need to byte swap the uint64_t's on big-endian hosts. -*/ -static uint64_t *sve_bswap64 (uint64_t *dst,uint64_t *src,int nr) -{ -#ifdef HOST_WORDS_BIGENDIAN -int i; - -for (i =0 ; i < nr; ++i) { - dst[i] =bswap64 (src[i]); - } - -return dst; -#else -return src; -#endif -} -/* * KVM SVE registers come in slices where ZREGs have a slice size of 2048 bits * and PREGS and the FFR have a slice size of 256 bits. However we simply hard