[PATCH 3/4] KVM: x86: Reject KVM_CREATE_IRQCHIP if APIC base is already mapped

From: Tim Wiederhake

Date: Mon Jul 06 2026 - 06:17:00 EST


User space must not map guest memory that covers the default APIC base
address (0xfee00000) when using an in-kernel irqchip. Currently,
KVM_CREATE_IRQCHIP does not check for this. The violation goes
unnoticed until vcpu creation, which fails with the misleading error
-EEXIST.

Add an explicit check to KVM_CREATE_IRQCHIP so the conflict is reported
at the point where the constraint takes effect.

Signed-off-by: Tim Wiederhake <twiederh@xxxxxxxxxx>
---
arch/x86/kvm/x86.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0550359ed798..07f348232a72 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -7336,6 +7336,10 @@ int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
if (kvm->created_vcpus)
goto create_irqchip_unlock;

+ r = -EEXIST;
+ if (gfn_to_memslot(kvm, gpa_to_gfn(APIC_DEFAULT_PHYS_BASE)))
+ goto create_irqchip_unlock;
+
r = kvm_pic_init(kvm);
if (r)
goto create_irqchip_unlock;
--
2.52.0