[PATCH] hw/intc: apic: stop register accesses for invalid situations

Mohamed Mediouni posted 1 patch 2 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260411131806.94653-1-mohamed@unpredictable.fr
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>
hw/intc/apic.c | 9 +++++++++
1 file changed, 9 insertions(+)
[PATCH] hw/intc: apic: stop register accesses for invalid situations
Posted by Mohamed Mediouni 2 hours ago
kvm-unit-tests's apic.c tests for:

!APICBASE_ENABLE + attempting to read xAPIC registers is not an allowed
 combination.

And neither is x2APIC enabled + attempting to read xAPIC registers

This was tested on WHPX with kernel-irqchip=off with x2APIC emulation
enabled (in a posted series) and TCG.

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
---
 hw/intc/apic.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 8766ed00b9..c09dddef39 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -875,6 +875,15 @@ static uint64_t apic_mem_read(void *opaque, hwaddr addr, unsigned size)
         return -1;
     }
 
+    /* if the xAPIC is disabled, return early. */
+    if (!(s->apicbase & MSR_IA32_APICBASE_ENABLE)) {
+        return 0xffffffff;
+    }
+
+    if (s->apicbase & MSR_IA32_APICBASE_EXTD) {
+        return 0xffffffff;
+    }
+
     index = (addr >> 4) & 0xff;
     apic_register_read(s, index, &val);
 
-- 
2.50.1 (Apple Git-155)