[PATCH v2] x86/apic: Use the physical address for the local APIC resource
From: Ahmed Abdelfattah via B4 Relay
Date: Mon Nov 23 2026 - 06:05:21 EST
From: Ahmed Abdelfattah <me@xxxxxxxxxxxxxxxxxxxx>
Since v6.6 the "Local APIC" entry is missing from /proc/iomem whenever
the kernel maps the xAPIC itself.
lapic_insert_resource() takes the start of the resource from apic_phys,
which used to hold mp_lapic_addr. Commit 81287ad65da5 ("x86/apic:
Sanitize APIC address setup") moved that assignment to
apic_set_fixmap(), where it became the fixmap virtual address:
apic_phys = apic_mmio_base = APIC_BASE;
Commit 78c32000848c ("x86/apic: Get rid of apic_phys") then replaced
apic_phys with apic_mmio_base, which holds the same value:
APIC: Mapped APIC to ffffffffff5fc000 ( fee00000)
insert_resource() rejects that range because it lies outside
iomem_resource, and as the return value is not checked, the failure
goes unnoticed.
Without the resource the local APIC page is no longer marked busy. So
apart from the line missing in /proc/iomem, CONFIG_IO_STRICT_DEVMEM
does not stop /dev/mem from mapping the page any more, and in xAPIC
mode the APIC registers can be read and written through it.
Use mp_lapic_addr, which is the address apic_set_fixmap() maps. Keep
the apic_mmio_base check, so the resource is still only added when the
APIC was actually mapped.
Fixes: 81287ad65da5 ("x86/apic: Sanitize APIC address setup")
Signed-off-by: Ahmed Abdelfattah <me@xxxxxxxxxxxxxxxxxxxx>
---
This showed up while comparing /proc/iomem with the memory map of a
QEMU guest.
Tested on QEMU q35 with KVM (x86_64_defconfig + kvm_guest.config),
booting with and without nox2apic. Without the patch there is no
"Local APIC" entry in either case; with it both show
fee00000-fee00fff : Local APIC
For the /dev/mem part I used v7.4-rc3+ (4405c18c95d2) with a
distribution config that has CONFIG_IO_STRICT_DEVMEM=y, and a small
program that maps one page of /dev/mem. Without the patch the page at
0xfee00000 can be mapped. Booted with nox2apic, the APIC version
register reads 0x00050014 through it and a write to the task priority
register is accepted. With the patch the mmap() fails with EPERM in
both boots, as it does for the IOAPIC page.
---
Changes in v2:
- Fixes: now names the commit that made apic_phys a virtual address
(Chao Gao)
- Say what the missing resource changes for users (Chao Gao)
- Link to v1: https://patch.msgid.link/20261107-x86-apic-lapic-resource-v1-1-28de4cb3fb1e@xxxxxxxxxxxxxxxxxxxx
---
arch/x86/kernel/apic/apic.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 90025451ace2..17525b5daa0d 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -2667,7 +2667,7 @@ static int __init lapic_insert_resource(void)
return -1;
/* Put local APIC into the resource map. */
- lapic_resource.start = apic_mmio_base;
+ lapic_resource.start = mp_lapic_addr;
lapic_resource.end = lapic_resource.start + PAGE_SIZE - 1;
insert_resource(&iomem_resource, &lapic_resource);
---
base-commit: d48723711bae9b8cdc56719c448ba42fef28cbee
change-id: 20261107-x86-apic-lapic-resource-e2f88ada8677
Best regards,
--
Ahmed Abdelfattah <me@xxxxxxxxxxxxxxxxxxxx>