]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: x86: Check irqchip mode before create PIT
authorTengfei Yu <moehanabichan@gmail.com>
Thu, 25 Jan 2024 05:08:23 +0000 (13:08 +0800)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 31 Jan 2024 21:21:00 +0000 (16:21 -0500)
As the kvm api(https://docs.kernel.org/virt/kvm/api.html) reads,
KVM_CREATE_PIT2 call is only valid after enabling in-kernel irqchip
support via KVM_CREATE_IRQCHIP.

Without this check, I can create PIT first and enable irqchip-split
then, which may cause the PIT invalid because of lacking of in-kernel
PIC to inject the interrupt.

Signed-off-by: Tengfei Yu <moehanabichan@gmail.com>
Message-Id: <20240125050823.4893-1-moehanabichan@gmail.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/x86.c

index 363b1c08020578b090b53d74482d9c8912629ec9..9a89471a613cdbef9f74d64c605e0885f4404395 100644 (file)
@@ -7016,6 +7016,9 @@ set_identity_unlock:
                r = -EEXIST;
                if (kvm->arch.vpit)
                        goto create_pit_unlock;
+               r = -ENOENT;
+               if (!pic_in_kernel(kvm))
+                       goto create_pit_unlock;
                r = -ENOMEM;
                kvm->arch.vpit = kvm_create_pit(kvm, u.pit_config.flags);
                if (kvm->arch.vpit)