]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: arm64: Return early from kvm_finalize_sys_regs() if guest has run
authorSascha Bischoff <Sascha.Bischoff@arm.com>
Thu, 19 Mar 2026 15:50:28 +0000 (15:50 +0000)
committerMarc Zyngier <maz@kernel.org>
Thu, 19 Mar 2026 16:25:55 +0000 (16:25 +0000)
If the guest has already run, we have no business finalizing the
system register state - it is too late. Therefore, check early and
bail if the VM has already run.

This change also stops kvm_init_nv_sysregs() from being called once
the RM has run once. Although this looks like a behavioural change,
the function returns early once it has been called the first time.

Signed-off-by: Sascha Bischoff <sascha.bischoff@arm.com>
Link: https://patch.msgid.link/20260319154937.3619520-4-sascha.bischoff@arm.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/sys_regs.c

index 0acd10e50aaba3e3e900dc6df42b747ddf9a0574..42c84b7900ff5041a93e24c633feac2b48911745 100644 (file)
@@ -5659,11 +5659,14 @@ int kvm_finalize_sys_regs(struct kvm_vcpu *vcpu)
 
        guard(mutex)(&kvm->arch.config_lock);
 
+       if (kvm_vm_has_ran_once(kvm))
+               return 0;
+
        /*
         * 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)) {
+       if (!irqchip_in_kernel(kvm)) {
                u64 val;
 
                val = kvm_read_vm_id_reg(kvm, SYS_ID_AA64PFR0_EL1) & ~ID_AA64PFR0_EL1_GIC;