From: Auger Eric <eric.auger@redhat.com>
To: Andrew Jones <drjones@redhat.com>,
qemu-devel@nongnu.org, qemu-arm@nongnu.org
Cc: peter.maydell@linaro.org, richard.henderson@linaro.org,
armbru@redhat.com, imammedo@redhat.com, alex.bennee@linaro.org,
Dave.Martin@arm.com
Subject: Re: [PATCH v4 5/9] target/arm/kvm64: Add kvm_arch_get/put_sve
Date: Wed, 25 Sep 2019 15:58:12 +0200 [thread overview]
Message-ID: <fc9ad988-d909-de1f-b29d-5d6a239f5da3@redhat.com> (raw)
In-Reply-To: <20190924113105.19076-6-drjones@redhat.com>
Hi Drew,
On 9/24/19 1:31 PM, Andrew Jones wrote:
> These are the SVE equivalents to kvm_arch_get/put_fpsimd. Note, the
> swabbing is different than it is for fpsmid because the vector format
> is a little-endian stream of words.
>
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Eric
> ---
> target/arm/kvm64.c | 137 +++++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 133 insertions(+), 4 deletions(-)
>
> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
> index 28f6db57d5ee..ea454c613919 100644
> --- a/target/arm/kvm64.c
> +++ b/target/arm/kvm64.c
> @@ -671,11 +671,12 @@ int kvm_arch_destroy_vcpu(CPUState *cs)
> bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx)
> {
> /* Return true if the regidx is a register we should synchronize
> - * via the cpreg_tuples array (ie is not a core reg we sync by
> - * hand in kvm_arch_get/put_registers())
> + * via the cpreg_tuples array (ie is not a core or sve reg that
> + * we sync by hand in kvm_arch_get/put_registers())
> */
> switch (regidx & KVM_REG_ARM_COPROC_MASK) {
> case KVM_REG_ARM_CORE:
> + case KVM_REG_ARM64_SVE:
> return false;
> default:
> return true;
> @@ -761,6 +762,78 @@ 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
> + * code the slice index to zero for now as it's unlikely we'll need more than
> + * one slice for quite some time.
> + */
> +static int kvm_arch_put_sve(CPUState *cs)
> +{
> + ARMCPU *cpu = ARM_CPU(cs);
> + CPUARMState *env = &cpu->env;
> + uint64_t tmp[ARM_MAX_VQ * 2];
> + uint64_t *r;
> + struct kvm_one_reg reg;
> + int n, ret;
> +
> + for (n = 0; n < KVM_ARM64_SVE_NUM_ZREGS; ++n) {
> + r = sve_bswap64(tmp, &env->vfp.zregs[n].d[0], cpu->sve_max_vq * 2);
> + reg.addr = (uintptr_t)r;
> + reg.id = KVM_REG_ARM64_SVE_ZREG(n, 0);
> + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
> + if (ret) {
> + return ret;
> + }
> + }
> +
> + for (n = 0; n < KVM_ARM64_SVE_NUM_PREGS; ++n) {
> + r = sve_bswap64(tmp, r = &env->vfp.pregs[n].p[0],
> + DIV_ROUND_UP(cpu->sve_max_vq, 8));
> + reg.addr = (uintptr_t)r;
> + reg.id = KVM_REG_ARM64_SVE_PREG(n, 0);
> + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
> + if (ret) {
> + return ret;
> + }
> + }
> +
> + r = sve_bswap64(tmp, &env->vfp.pregs[FFR_PRED_NUM].p[0],
> + DIV_ROUND_UP(cpu->sve_max_vq, 8));
> + reg.addr = (uintptr_t)r;
> + reg.id = KVM_REG_ARM64_SVE_FFR(0);
> + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®);
> + if (ret) {
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> int kvm_arch_put_registers(CPUState *cs, int level)
> {
> struct kvm_one_reg reg;
> @@ -855,7 +928,11 @@ int kvm_arch_put_registers(CPUState *cs, int level)
> }
> }
>
> - ret = kvm_arch_put_fpsimd(cs);
> + if (cpu_isar_feature(aa64_sve, cpu)) {
> + ret = kvm_arch_put_sve(cs);
> + } else {
> + ret = kvm_arch_put_fpsimd(cs);
> + }
> if (ret) {
> return ret;
> }
> @@ -918,6 +995,54 @@ static int kvm_arch_get_fpsimd(CPUState *cs)
> return 0;
> }
>
> +/*
> + * 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
> + * code the slice index to zero for now as it's unlikely we'll need more than
> + * one slice for quite some time.
> + */
> +static int kvm_arch_get_sve(CPUState *cs)
> +{
> + ARMCPU *cpu = ARM_CPU(cs);
> + CPUARMState *env = &cpu->env;
> + struct kvm_one_reg reg;
> + uint64_t *r;
> + int n, ret;
> +
> + for (n = 0; n < KVM_ARM64_SVE_NUM_ZREGS; ++n) {
> + r = &env->vfp.zregs[n].d[0];
> + reg.addr = (uintptr_t)r;
> + reg.id = KVM_REG_ARM64_SVE_ZREG(n, 0);
> + ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
> + if (ret) {
> + return ret;
> + }
> + sve_bswap64(r, r, cpu->sve_max_vq * 2);
> + }
> +
> + for (n = 0; n < KVM_ARM64_SVE_NUM_PREGS; ++n) {
> + r = &env->vfp.pregs[n].p[0];
> + reg.addr = (uintptr_t)r;
> + reg.id = KVM_REG_ARM64_SVE_PREG(n, 0);
> + ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
> + if (ret) {
> + return ret;
> + }
> + sve_bswap64(r, r, DIV_ROUND_UP(cpu->sve_max_vq, 8));
> + }
> +
> + r = &env->vfp.pregs[FFR_PRED_NUM].p[0];
> + reg.addr = (uintptr_t)r;
> + reg.id = KVM_REG_ARM64_SVE_FFR(0);
> + ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®);
> + if (ret) {
> + return ret;
> + }
> + sve_bswap64(r, r, DIV_ROUND_UP(cpu->sve_max_vq, 8));
> +
> + return 0;
> +}
> +
> int kvm_arch_get_registers(CPUState *cs)
> {
> struct kvm_one_reg reg;
> @@ -1012,7 +1137,11 @@ int kvm_arch_get_registers(CPUState *cs)
> env->spsr = env->banked_spsr[i];
> }
>
> - ret = kvm_arch_get_fpsimd(cs);
> + if (cpu_isar_feature(aa64_sve, cpu)) {
> + ret = kvm_arch_get_sve(cs);
> + } else {
> + ret = kvm_arch_get_fpsimd(cs);
> + }
> if (ret) {
> return ret;
> }
>
next prev parent reply other threads:[~2019-09-25 13:59 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-24 11:30 [PATCH v4 0/9] target/arm/kvm: enable SVE in guests Andrew Jones
2019-09-24 11:30 ` [PATCH v4 1/9] target/arm/monitor: Introduce qmp_query_cpu_model_expansion Andrew Jones
2019-09-24 15:06 ` Auger Eric
2019-09-24 11:30 ` [PATCH v4 2/9] tests: arm: Introduce cpu feature tests Andrew Jones
2019-09-24 11:30 ` [PATCH v4 3/9] target/arm: Allow SVE to be disabled via a CPU property Andrew Jones
2019-09-24 15:06 ` Auger Eric
2019-09-24 11:31 ` [PATCH v4 4/9] target/arm/cpu64: max cpu: Introduce sve<N> properties Andrew Jones
2019-09-24 13:55 ` Andrew Jones
2019-09-25 13:53 ` Auger Eric
2019-09-26 8:21 ` Andrew Jones
2019-09-26 9:34 ` Auger Eric
2019-09-26 11:14 ` Andrew Jones
2019-09-26 19:07 ` Richard Henderson
2019-09-26 23:50 ` Alex Bennée
2019-09-27 6:51 ` Andrew Jones
2019-09-27 6:45 ` Andrew Jones
2019-09-24 11:31 ` [PATCH v4 5/9] target/arm/kvm64: Add kvm_arch_get/put_sve Andrew Jones
2019-09-25 13:58 ` Auger Eric [this message]
2019-09-27 13:00 ` Andrew Jones
2019-10-01 6:53 ` Andrew Jones
2019-09-24 11:31 ` [PATCH v4 6/9] target/arm/kvm64: max cpu: Enable SVE when available Andrew Jones
2019-09-26 6:53 ` Auger Eric
2019-09-24 11:31 ` [PATCH v4 7/9] target/arm/kvm: scratch vcpu: Preserve input kvm_vcpu_init features Andrew Jones
2019-09-24 11:31 ` [PATCH v4 8/9] target/arm/cpu64: max cpu: Support sve properties with KVM Andrew Jones
2019-09-26 6:52 ` Auger Eric
2019-09-26 8:41 ` Andrew Jones
2019-09-26 10:01 ` Auger Eric
2019-09-26 11:40 ` Andrew Jones
2019-09-26 11:50 ` Auger Eric
2019-09-24 11:31 ` [PATCH v4 9/9] target/arm/kvm: host cpu: Add support for sve<N> properties Andrew Jones
2019-09-26 7:07 ` Auger Eric
2019-09-26 8:53 ` Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fc9ad988-d909-de1f-b29d-5d6a239f5da3@redhat.com \
--to=eric.auger@redhat.com \
--cc=Dave.Martin@arm.com \
--cc=alex.bennee@linaro.org \
--cc=armbru@redhat.com \
--cc=drjones@redhat.com \
--cc=imammedo@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).