* [PATCH] x86/apic: Use the physical address for the local APIC resource
@ 2026-11-06 22:08 ` Ahmed Abdelfattah via B4 Relay
0 siblings, 0 replies; 4+ messages in thread
From: Ahmed Abdelfattah @ 2026-11-06 22:08 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Peter Zijlstra (Intel)
Cc: linux-kernel, Ahmed Abdelfattah
Since v6.6 the "Local APIC" entry is missing from /proc/iomem whenever
the kernel maps the xAPIC itself.
lapic_insert_resource() used to take the address from apic_phys. When
apic_phys went away it was switched to apic_mmio_base, but that holds
the fixmap virtual address, not the physical one:
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.
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: 78c32000848c ("x86/apic: Get rid of apic_phys")
Signed-off-by: Ahmed Abdelfattah <me@ahmedabdelfattah.dev>
---
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
as before 78c32000848c.
---
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@ahmedabdelfattah.dev>
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH] x86/apic: Use the physical address for the local APIC resource
@ 2026-11-06 22:08 ` Ahmed Abdelfattah via B4 Relay
0 siblings, 0 replies; 4+ messages in thread
From: Ahmed Abdelfattah via B4 Relay @ 2026-11-06 22:08 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Peter Zijlstra (Intel)
Cc: linux-kernel, Ahmed Abdelfattah
From: Ahmed Abdelfattah <me@ahmedabdelfattah.dev>
Since v6.6 the "Local APIC" entry is missing from /proc/iomem whenever
the kernel maps the xAPIC itself.
lapic_insert_resource() used to take the address from apic_phys. When
apic_phys went away it was switched to apic_mmio_base, but that holds
the fixmap virtual address, not the physical one:
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.
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: 78c32000848c ("x86/apic: Get rid of apic_phys")
Signed-off-by: Ahmed Abdelfattah <me@ahmedabdelfattah.dev>
---
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
as before 78c32000848c.
---
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@ahmedabdelfattah.dev>
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] x86/apic: Use the physical address for the local APIC resource
2026-11-06 22:08 ` Ahmed Abdelfattah via B4 Relay
(?)
@ 2026-11-20 8:37 ` Chao Gao
2026-11-20 10:44 ` Ahmed Abdelfattah
-1 siblings, 1 reply; 4+ messages in thread
From: Chao Gao @ 2026-11-20 8:37 UTC (permalink / raw)
To: Ahmed Abdelfattah
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Peter Zijlstra (Intel), linux-kernel
On Sat, Nov 07, 2026 at 12:08:07AM +0200, Ahmed Abdelfattah wrote:
>Since v6.6 the "Local APIC" entry is missing from /proc/iomem whenever
>the kernel maps the xAPIC itself.
What is the impact on end users if this isn't fixed? Please make it clear
in the changelog, even if it is minor.
No one else has noticed this since v6.6, so it looks to me that nothing
depends on this "Local APIC" entry.
>
>lapic_insert_resource() used to take the address from apic_phys. When
>apic_phys went away it was switched to apic_mmio_base, but that holds
>the fixmap virtual address, not the physical one:
>
> 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.
>
>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: 78c32000848c ("x86/apic: Get rid of apic_phys")
>Signed-off-by: Ahmed Abdelfattah <me@ahmedabdelfattah.dev>
Using the virtual address is clearly a mistake, so this fix looks good to
me. But the Fixes tag is wrong, as "apic_phys" already held the same
virtual address before that commit.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/apic: Use the physical address for the local APIC resource
2026-11-20 8:37 ` Chao Gao
@ 2026-11-20 10:44 ` Ahmed Abdelfattah
0 siblings, 0 replies; 4+ messages in thread
From: Ahmed Abdelfattah @ 2026-11-20 10:44 UTC (permalink / raw)
To: Chao Gao
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Peter Zijlstra (Intel), linux-kernel
On Fri, Nov 20, 2026 at 04:37:24PM +0800, Chao Gao wrote:
> What is the impact on end users if this isn't fixed? Please make it clear
> in the changelog, even if it is minor.
>
> No one else has noticed this since v6.6, so it looks to me that nothing
> depends on this "Local APIC" entry.
It is minor. Apart from the line missing in /proc/iomem, the page is no
longer a busy resource, so CONFIG_IO_STRICT_DEVMEM does not keep
/dev/mem away from it any more. I checked that on v7.4-rc3+ in a guest
booted with nox2apic: without the patch 0xfee00000 can be mapped
through /dev/mem, reads return the APIC registers and a write to the
TPR is accepted. With the patch the mmap() fails with EPERM, as it does
for the IOAPIC page.
I'll put that in the changelog.
> Using the virtual address is clearly a mistake, so this fix looks good to
> me. But the Fixes tag is wrong, as "apic_phys" already held the same
> virtual address before that commit.
You're right, thanks. It was 81287ad65da5 ("x86/apic: Sanitize APIC
address setup") that replaced
apic_phys = mp_lapic_addr;
with
apic_phys = apic_mmio_base = APIC_BASE;
and 78c32000848c only switched to the other variable. I'll fix the tag
and the description in v2.
Thanks for the review,
Ahmed
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 10:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-06 22:08 [PATCH] x86/apic: Use the physical address for the local APIC resource Ahmed Abdelfattah
2026-11-06 22:08 ` Ahmed Abdelfattah via B4 Relay
2026-11-20 8:37 ` Chao Gao
2026-11-20 10:44 ` Ahmed Abdelfattah
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.