Re: [PATCH v2 3/4] KVM: arm64: Reset TCR_EL2 according to guest's E2H mode

From: Joey Gouly

Date: Thu Oct 29 2026 - 07:36:41 EST


On Thu, Sep 17, 2026 at 10:42:13PM +0100, Wei-Lin Chang wrote:
> From: Marc Zyngier <maz@xxxxxxxxxx>
>
> Previously vCPU TCR_EL2's reset value didn't consider TCR_EL2's
> different formats based on the value of HCR_EL2.E2H. It always resets to
> the E2H == 0 version.
>
> This didn't cause any problem because the bits set in the E2H == 0
> version (TCR_EL2_RES1) all reset to UNKNOWN for E2H == 1 per the
> architecture.
>
> Still, it's better to fix it. Choose the correct reset value by checking
> KVM_ARM_VCPU_HAS_EL2_E2H0.
>
> Signed-off-by: Marc Zyngier <maz@xxxxxxxxxx>
> Signed-off-by: Wei-Lin Chang <weilin.chang@xxxxxxx>

Reviewed-by: Joey Gouly <joey.gouly@xxxxxxx>

> ---
> arch/arm64/kvm/sys_regs.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> index 44aae52c473d..62c059747fbb 100644
> --- a/arch/arm64/kvm/sys_regs.c
> +++ b/arch/arm64/kvm/sys_regs.c
> @@ -3275,6 +3275,14 @@ static u64 reset_mdcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
> return vcpu->kvm->arch.nr_pmu_counters;
> }
>
> +static u64 reset_tcr_el2(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r)
> +{
> + __vcpu_assign_sys_reg(vcpu, r->reg,
> + vcpu_has_feature(vcpu, KVM_ARM_VCPU_HAS_EL2_E2H0) ?
> + TCR_EL2_RES1 : VHE_TCR_EL2_RES1);
> + return __vcpu_sys_reg(vcpu, r->reg);
> +}
> +
> /*
> * Architected system registers.
> * Important: Must be sorted ascending by Op0, Op1, CRn, CRm, Op2
> @@ -3853,7 +3861,7 @@ static const struct sys_reg_desc sys_reg_descs[] = {
>
> EL2_REG(TTBR0_EL2, access_rw, reset_val, 0),
> EL2_REG(TTBR1_EL2, access_rw, reset_val, 0),
> - EL2_REG(TCR_EL2, access_rw, reset_val, TCR_EL2_RES1),
> + EL2_REG(TCR_EL2, access_rw, reset_tcr_el2, 0),
> EL2_REG_FILTERED(TCR2_EL2, access_rw, reset_val, TCR2_EL2_RES1,
> tcr2_el2_visibility),
> EL2_REG_VNCR(VTTBR_EL2, reset_val, 0),
> --
> 2.43.0
>