Re: [PATCH v3 2/6] KVM: arm64: maintain per VM value for CTR_EL0

From: Sebastian Ott
Date: Wed May 29 2024 - 11:51:29 EST


Hej Eric,

On Wed, 29 May 2024, Eric Auger wrote:
static int set_clidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd,
u64 val)
{
- u64 ctr_el0 = read_sanitised_ftr_reg(SYS_CTR_EL0);
u64 idc = !CLIDR_LOC(val) || (!CLIDR_LOUIS(val) && !CLIDR_LOUU(val));
+ u64 ctr_el0 = vcpu->kvm->arch.ctr_el0;

if ((val & CLIDR_EL1_RES0) || (!(ctr_el0 & CTR_EL0_IDC) && idc))
return -EINVAL;
nit: you may update the function doc comment which the extra handling of
CTR_EL0.

Hm, there's no extra handling of CTR_EL0 it just uses the emulated value.

@@ -3557,6 +3557,13 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu)
struct kvm *kvm = vcpu->kvm;
unsigned long i;

+ if (!kvm_vcpu_initialized(vcpu))
at this stage of the reading, why is the above check needed?

To make sure that a later call to this function doesn't overwrite
the value provided by userspace. (See e016333745c "KVM: arm64: Only
reset vCPU-scoped feature ID regs once").

Sebastian