RE: [PATCH 2/3] KVM: arm64: nv: Don't request or attempt L1 VNCR mapping without vncr_tlb
From: Justin He
Date: Mon Nov 23 2026 - 20:43:28 EST
> -----Original Message-----
[...]
> On Mon, 23 Nov 2026 15:09:16 +0000,
> Jia He <justin.he@xxxxxxx> wrote:
> >
> > vcpu->arch.vncr_tlb is only allocated when ID_AA64MMFR4_EL1.NV_frac
> > advertises FEAT_NV2. When NV_frac is cleared to 0 (or E2H0 is selected),
> > vncr_tlb is NULL for the lifetime of the vCPU.
> >
> > Don't set KVM_REQ_MAP_L1_VNCR_EL2 in kvm_vcpu_load_hw_mmu()
> when
> > vncr_tlb is NULL. The only other place that sets this request is
> > kvm_translate_vncr(), which only runs on a FEAT_NV2 VNCR abort. Warn
> and
> > return early in kvm_map_l1_vncr() if vt is NULL before disabling
> > preemption and taking kvm->mmu_lock.
> >
> > Signed-off-by: Jia He <justin.he@xxxxxxx>
> > ---
> > arch/arm64/kvm/nested.c | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
> > index 4d83281a7a28..2f52c128f3a7 100644
> > --- a/arch/arm64/kvm/nested.c
> > +++ b/arch/arm64/kvm/nested.c
> > @@ -979,7 +979,8 @@ void kvm_vcpu_load_hw_mmu(struct kvm_vcpu
> *vcpu)
> > vcpu->arch.hw_mmu =
> get_s2_mmu_nested(vcpu);
> > }
> >
> > - if (__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_EL2_NV)
> > + if (vcpu->arch.vncr_tlb &&
> > + (__vcpu_sys_reg(vcpu, HCR_EL2) & HCR_EL2_NV))
> > kvm_make_request(KVM_REQ_MAP_L1_VNCR_EL2,
> vcpu);
>
> How do we even get here? Now that you have short-circuited the vcpu
> state loading, I can't see how this code is reachable before we've
> actually initialised the relevant state.
>
> What am I missing?
>
> > }
> > }
> > @@ -1761,6 +1762,9 @@ static void kvm_map_l1_vncr(struct kvm_vcpu
> *vcpu)
> > struct vncr_tlb *vt = vcpu->arch.vncr_tlb;
> > pgprot_t prot;
> >
> > + if (WARN_ON_ONCE(!vt))
> > + return;
> > +
>
> I don't think we want this. Either the code is rock solid, and the
> warning pointless, or we have terrible problems, and I really want to
> see the kernel exploding, specially given that NV is still an
> experimental feature.
>
Agreed. I'll drop this patch in v2. Patch 2/3 was only meant as a defensive check,
and patch 1/3 should be sufficient.
Thanks,
Jia He (Justin)