Skip to contentSkip to conversation

KVM: arm64: Finalize ID registers only once per VM

PATCH Applied Marc Zyngier 2 participants 3 messages Nov 10, 2025 – Nov 11, 2025

Subsystems (3)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH 1/1 KVM: arm64: Finalize ID registers only once per VM

Owing to the ID registers being global to the VM, there is no point in computing them more than once. However, recent changes making use of kvm_set_vm_id_reg() outlined that we repeatedly hammer the ID registers when we shouldn't.

Gate the ID reg update on the VM having never run.

Fixes 50e7cce81b9b2 ("KVM: arm64: Limit clearing of ID_{AA64PFR0,PFR1}_EL1.GIC to userspace irqchip")
Fixes 5cb57a1aff755 ("KVM: arm64: Zero ID_AA64PFR0_EL1.GIC when no GICv3 is presented to the guest")
---
 arch/arm64/kvm/sys_regs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +5 -1
index 3bf7005258f07..19afcd833d6fa 100644
@@ -5624,7 +5624,11 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
 
 	guard(mutex)(&kvm->arch.config_lock);
 
-	if (!irqchip_in_kernel(kvm)) {
+	/*
+	 * This hacks into the ID registers, so only perform it when the
+	 * first vcpu runs, or the kvm_set_vm_id_reg() helper will scream.
+	 */
+	if (!irqchip_in_kernel(kvm) && !kvm_vm_has_ran_once(kvm)) {
 		u64 val;
 
 		val = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1) & ~ID_AA64PFR0_EL1_GIC;
Signature · 1 line
2.47.3
Tested-by on v1 1/1
#1 lore raw
Quoted 6 lines · Marc Zyngier

Owing to the ID registers being global to the VM, there is no point in computing them more than once. However, recent changes making use of kvm_set_vm_id_reg() outlined that we repeatedly hammer the ID registers when we shouldn't.

Gate the ID reg update on the VM having never run.

This resolves all the test issues I was seeing:

author maintainer Applied
#2 lore raw
In reply to Marc Zyngier
Quoted 8 lines · Marc Zyngier

Owing to the ID registers being global to the VM, there is no point in computing them more than once. However, recent changes making use of kvm_set_vm_id_reg() outlined that we repeatedly hammer the ID registers when we shouldn't.

Gate the ID reg update on the VM having never run.

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: Finalize ID registers only once per VM

      commit: 0f559cd91e37b7978e4198ca2fbf7eb95df11361

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.