mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-01-21 12:53:20 -05:00
RISC-V: KVM: add vector registers and CSRs in KVM_GET_REG_LIST
Add all vector registers and CSRs (vstart, vl, vtype, vcsr, vlenb) in get-reg-list. Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
committed by
Anup Patel
parent
2fa290372d
commit
3975525e55
@@ -961,6 +961,55 @@ static unsigned long num_sbi_ext_regs(struct kvm_vcpu *vcpu)
|
||||
return copy_sbi_ext_reg_indices(vcpu, NULL);
|
||||
}
|
||||
|
||||
static inline unsigned long num_vector_regs(const struct kvm_vcpu *vcpu)
|
||||
{
|
||||
if (!riscv_isa_extension_available(vcpu->arch.isa, v))
|
||||
return 0;
|
||||
|
||||
/* vstart, vl, vtype, vcsr, vlenb and 32 vector regs */
|
||||
return 37;
|
||||
}
|
||||
|
||||
static int copy_vector_reg_indices(const struct kvm_vcpu *vcpu,
|
||||
u64 __user *uindices)
|
||||
{
|
||||
const struct kvm_cpu_context *cntx = &vcpu->arch.guest_context;
|
||||
int n = num_vector_regs(vcpu);
|
||||
u64 reg, size;
|
||||
int i;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
|
||||
/* copy vstart, vl, vtype, vcsr and vlenb */
|
||||
size = IS_ENABLED(CONFIG_32BIT) ? KVM_REG_SIZE_U32 : KVM_REG_SIZE_U64;
|
||||
for (i = 0; i < 5; i++) {
|
||||
reg = KVM_REG_RISCV | size | KVM_REG_RISCV_VECTOR | i;
|
||||
|
||||
if (uindices) {
|
||||
if (put_user(reg, uindices))
|
||||
return -EFAULT;
|
||||
uindices++;
|
||||
}
|
||||
}
|
||||
|
||||
/* vector_regs have a variable 'vlenb' size */
|
||||
size = __builtin_ctzl(cntx->vector.vlenb);
|
||||
size <<= KVM_REG_SIZE_SHIFT;
|
||||
for (i = 0; i < 32; i++) {
|
||||
reg = KVM_REG_RISCV | KVM_REG_RISCV_VECTOR | size |
|
||||
KVM_REG_RISCV_VECTOR_REG(i);
|
||||
|
||||
if (uindices) {
|
||||
if (put_user(reg, uindices))
|
||||
return -EFAULT;
|
||||
uindices++;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
/*
|
||||
* kvm_riscv_vcpu_num_regs - how many registers do we present via KVM_GET/SET_ONE_REG
|
||||
*
|
||||
@@ -976,6 +1025,7 @@ unsigned long kvm_riscv_vcpu_num_regs(struct kvm_vcpu *vcpu)
|
||||
res += num_timer_regs();
|
||||
res += num_fp_f_regs(vcpu);
|
||||
res += num_fp_d_regs(vcpu);
|
||||
res += num_vector_regs(vcpu);
|
||||
res += num_isa_ext_regs(vcpu);
|
||||
res += num_sbi_ext_regs(vcpu);
|
||||
|
||||
@@ -1020,6 +1070,11 @@ int kvm_riscv_vcpu_copy_reg_indices(struct kvm_vcpu *vcpu,
|
||||
return ret;
|
||||
uindices += ret;
|
||||
|
||||
ret = copy_vector_reg_indices(vcpu, uindices);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
uindices += ret;
|
||||
|
||||
ret = copy_isa_ext_reg_indices(vcpu, uindices);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user