[PATCH 3/3] KVM: arm64: Drop open-coded GIC idreg sanitisation

Marc Zyngier maz at kernel.org
Tue Nov 24 02:50:11 PST 2026


On Tue, 24 Nov 2026 09:38:00 +0000,
Fuad Tabba <fuad.tabba at linux.dev> wrote:
> 
> Hi Marc,
> 
> On Mon, 23 Nov 2026 19:24:57 +0000, Marc Zyngier <maz at kernel.org> wrote:
> [...]
> > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c
> [...]
> > @@ -5874,51 +5874,6 @@ static int kvm_vm_finalize_sys_regs(struct kvm *kvm)
> [...]
> > -                 * On GICv5 hardware that supports FEAT_GCIE_LEGACY we can run
> > -                 * both GICv3- and GICv5-based guests. Therefore, we initially
> > -                 * present both ID_AA64PFR0.GIC and ID_AA64PFR2.GCIE as IMP to
> > -                 * reflect that userspace can create EITHER a vGICv3 or a
> > -                 * vGICv5. This is an architecturally invalid combination, of
> > -                 * course. Once an in-kernel GIC is created, the sysreg state is
> > -                 * updated to reflect the actual, valid configuration.
> 
> nit: This comment is the only place that explains why, on a
> FEAT_GCIE_LEGACY host, a VM's ID registers can show both GIC and GCIE
> as IMP before the VM first runs. sanitise_id_aa64pfr0_el1() and
> sanitise_id_aa64pfr2_el1() still set both at reset. Is it worth having
> a short version of it next to the tables patch 2 adds?

I don't think that's the correct place. If anything, such comment
should be in the reset code, not in the sanitisation code, which
actually generates the architecturally compliant view.

> 
> [...]
> > diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c
> [...]
> > @@ -180,7 +180,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
> >           * We've now created the GIC. Update the system register state
> >           * to accurately reflect what we've created.
> >           */
> > -        kvm_vgic_finalize_idregs(kvm);
> > +        kvm_idregs_enforce_dependencies(kvm);
> 
> This now also applies the S1P[IO]E dependencies when the vGIC is
> created, at a point where userspace can still write the ID registers.
> Was that intended? If this clears S1PIE or S1POE, the first KVM_RUN
> doesn't restore it, so the final ID_AA64MMFR3_EL1 can change with the
> order in which userspace writes the ID registers and creates the vGIC.
> If that's the intent, should it say so in the commit message?

The commit message has no influence on the behaviour of the kernel.
However, I want to know whether this change is an acceptable behaviour
or not *from an ABI perspective*. We have several options:

(1) delay all idreg enforcement to the same (late) point

(2) keep things as currently done, meaning that the GIC fields are
    special and sanitised at a different time

(3) say that idregs can change at any point if you change the
    configuration of the system, such as creating a GIC

I'd be tempted to go with either (1) or (3). (2) feels like a total
bodge.

	M.

-- 
Without deviation from the norm, progress is not possible.



More information about the linux-arm-kernel mailing list