Received: by 2002:adf:e804:0:0:0:0:0 with SMTP id o4csp3464368wrm; Mon, 7 Oct 2019 00:22:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDmit9cMyfL3imxLWXptN9GngjKp0Wl2r6rjtF2twqCjA7LyjyHd8bJ1nRYR4JS71zt/We X-Received: by 2002:a92:2c0c:: with SMTP id t12mr26708988ile.67.1570432956795; Mon, 07 Oct 2019 00:22:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570432956; cv=none; d=google.com; s=arc-20160816; b=mjLkB0vJdhxh8PZ2VGQI5sDPR5qNRjNzIUlNEqLg95TaLrqe+8ozPUbAkQWZjmzqiI d3V6WdBl3l5ZzyuCK4dyGEo3ErpuwWTZXQVc4fkXEfAqnV0PNJA3svWQdALzqd8cfYhn FqXLxjPzFXIfSmEtlDzTJeK6R+m+WqS+u53MbhEU5Hg/DE99js79f7sa2EVaNWeJOni/ utAt8WUCTunEEl2TZ+wEeJ3ve5mfI5xwfU9zC4muydqc0cI+K2M6Q8+e/M6qYZAyeVNj 9oNb6UPq80xxaqazujCVkNFZfhRfqGrHcojfBPJQecwkUob6r5C7DblHoObFufNfKNWf uUTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject; bh=rJNIvEYtTTkjSEUmuUvhW+q9cnRDPdGibM9ThryBeEk=; b=SfC8A9Pg0bDi+XCCgjgFupdq4BT7rybvpLgB6AKDT7z4mgqq61RnJK4+qPFYrukavn u7xxh5C/RV20rGOFWfQ3sJVvSAY6XtDSWPmynZPYQFVYSGsg2CtViTpjCUMtpLhQjcs/ gktmM1xegfZlYDxQqTeuBcV/frI24rQP7k+jdVsuR0vD3q/ISGalwMQN8CWyxP0AL4M2 okRpXHsB2CEm48r0dDAX5EIJFjNetUCv+HSGZASvXJmzfkClucCoisEXLcJ3zt6uZOez XwqT4oGqSS1mSaRQ904oqwZy2XooLoeRfVRC83x0idfLOD7wwpxBgRExHjddo09hhacQ y4EQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of eric.auger@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=eric.auger@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id p16si16906820ilc.124.2019.10.07.00.22.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Oct 2019 00:22:36 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=eric.auger@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F2D018C4272; Mon, 7 Oct 2019 07:22:36 +0000 (UTC) Received: from [10.36.116.56] (ovpn-116-56.ams2.redhat.com [10.36.116.56]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B8E565D6D0; Mon, 7 Oct 2019 07:22:29 +0000 (UTC) Subject: Re: [PATCH v5 5/9] target/arm/kvm64: Add kvm_arch_get/put_sve To: Andrew Jones , qemu-devel@nongnu.org, qemu-arm@nongnu.org Cc: peter.maydell@linaro.org, richard.henderson@linaro.org, alex.bennee@linaro.org, armbru@redhat.com, eblake@redhat.com, Dave.Martin@arm.com, imammedo@redhat.com References: <20191001125845.8793-1-drjones@redhat.com> <20191001125845.8793-6-drjones@redhat.com> From: Auger Eric Message-ID: Date: Mon, 7 Oct 2019 09:22:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20191001125845.8793-6-drjones@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Mon, 07 Oct 2019 07:22:36 +0000 (UTC) X-TUID: SRmoKTJWPEHj Hi Drew, On 10/1/19 2:58 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 Reviewed-by: Eric Auger Eric > --- > target/arm/kvm64.c | 183 ++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 155 insertions(+), 28 deletions(-) > > diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c > index 28f6db57d5ee..4c0b11d105a4 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; > @@ -721,10 +722,8 @@ int kvm_arm_cpreg_level(uint64_t regidx) > > static int kvm_arch_put_fpsimd(CPUState *cs) > { > - ARMCPU *cpu = ARM_CPU(cs); > - CPUARMState *env = &cpu->env; > + CPUARMState *env = &ARM_CPU(cs)->env; > struct kvm_one_reg reg; > - uint32_t fpr; > int i, ret; > > for (i = 0; i < 32; i++) { > @@ -742,17 +741,73 @@ static int kvm_arch_put_fpsimd(CPUState *cs) > } > } > > - reg.addr = (uintptr_t)(&fpr); > - fpr = vfp_get_fpsr(env); > - reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpsr); > - ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); > - if (ret) { > - return ret; > + 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]); > } > > - reg.addr = (uintptr_t)(&fpr); > - fpr = vfp_get_fpcr(env); > - reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpcr); > + 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 * 2, 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 * 2, 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; > @@ -765,6 +820,7 @@ int kvm_arch_put_registers(CPUState *cs, int level) > { > struct kvm_one_reg reg; > uint64_t val; > + uint32_t fpr; > int i, ret; > unsigned int el; > > @@ -855,7 +911,27 @@ 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; > + } > + > + reg.addr = (uintptr_t)(&fpr); > + fpr = vfp_get_fpsr(env); > + reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpsr); > + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); > + if (ret) { > + return ret; > + } > + > + reg.addr = (uintptr_t)(&fpr); > + fpr = vfp_get_fpcr(env); > + reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpcr); > + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); > if (ret) { > return ret; > } > @@ -878,10 +954,8 @@ int kvm_arch_put_registers(CPUState *cs, int level) > > static int kvm_arch_get_fpsimd(CPUState *cs) > { > - ARMCPU *cpu = ARM_CPU(cs); > - CPUARMState *env = &cpu->env; > + CPUARMState *env = &ARM_CPU(cs)->env; > struct kvm_one_reg reg; > - uint32_t fpr; > int i, ret; > > for (i = 0; i < 32; i++) { > @@ -899,21 +973,53 @@ static int kvm_arch_get_fpsimd(CPUState *cs) > } > } > > - reg.addr = (uintptr_t)(&fpr); > - reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpsr); > - ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); > - if (ret) { > - return ret; > + 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); > } > - vfp_set_fpsr(env, fpr); > > - reg.addr = (uintptr_t)(&fpr); > - reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpcr); > + 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 * 2, 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; > } > - vfp_set_fpcr(env, fpr); > + sve_bswap64(r, r, DIV_ROUND_UP(cpu->sve_max_vq * 2, 8)); > > return 0; > } > @@ -923,6 +1029,7 @@ int kvm_arch_get_registers(CPUState *cs) > struct kvm_one_reg reg; > uint64_t val; > unsigned int el; > + uint32_t fpr; > int i, ret; > > ARMCPU *cpu = ARM_CPU(cs); > @@ -1012,10 +1119,30 @@ 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; > + } > + > + reg.addr = (uintptr_t)(&fpr); > + reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpsr); > + ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); > + if (ret) { > + return ret; > + } > + vfp_set_fpsr(env, fpr); > + > + reg.addr = (uintptr_t)(&fpr); > + reg.id = AARCH64_SIMD_CTRL_REG(fp_regs.fpcr); > + ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); > if (ret) { > return ret; > } > + vfp_set_fpcr(env, fpr); > > ret = kvm_get_vcpu_events(cpu); > if (ret) { >