* [PATCH 0/2] x86/apic: Make noapictimer work with the TSC deadline timer
@ 2026-11-22 10:29 Jiaming Fan
2026-11-22 10:30 ` [PATCH 1/2] x86/timer: Don't skip PIT setup on UP when the local APIC timer is disabled Jiaming Fan
2026-11-22 10:30 ` [RFC PATCH 2/2] x86/apic: Honor noapictimer on SMP with the TSC deadline timer Jiaming Fan
0 siblings, 2 replies; 3+ messages in thread
From: Jiaming Fan @ 2026-11-22 10:29 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: x86, H. Peter Anvin, linux-kernel
I hit this while writing a small VMM as a learning project: a
single-vCPU guest booted with "noapictimer" and no HPET hangs during
boot. It reproduces with QEMU on a host with TSC deadline and ARAT:
qemu-system-x86_64 -enable-kvm -cpu host -smp 1 -machine q35,hpet=off \
-nographic -kernel bzImage -append "console=ttyS0 noapictimer"
Patch 1 fixes that. While testing it I noticed that with -smp 2 the
option is silently ignored on TSC deadline CPUs, which patch 2 changes.
Patch 2 is an RFC: it can make machines that boot today panic or hang
when there is no working PIT or HPET, so feel free to drop it. Patch 1
does not depend on it.
Tested with QEMU/KVM on an AMD host and with my VMM: 1 and 2 vCPUs,
with HPET, without HPET, and without HPET and PIT. Not tested on Intel
or bare metal.
Jiaming Fan (2):
x86/timer: Don't skip PIT setup on UP when the local APIC timer is
disabled
x86/apic: Honor noapictimer on SMP with the TSC deadline timer
arch/x86/kernel/apic/apic.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
base-commit: c44104f3642da720164042623e4832836aefdd8e
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH 1/2] x86/timer: Don't skip PIT setup on UP when the local APIC timer is disabled
2026-11-22 10:29 [PATCH 0/2] x86/apic: Make noapictimer work with the TSC deadline timer Jiaming Fan
@ 2026-11-22 10:30 ` Jiaming Fan
2026-11-22 10:30 ` [RFC PATCH 2/2] x86/apic: Honor noapictimer on SMP with the TSC deadline timer Jiaming Fan
1 sibling, 0 replies; 3+ messages in thread
From: Jiaming Fan @ 2026-11-22 10:30 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: x86, H. Peter Anvin, linux-kernel
apic_needs_pit() returns false on CPUs with the TSC deadline timer before
it checks disable_apic_timer. With "noapictimer" and only one possible
CPU, setup_boot_APIC_clock() registers no local APIC clockevent either,
so without an HPET no clockevent device is left and the boot hangs.
Ask for the PIT in that case. Leave SMP alone: there the option is
currently ignored and the local APIC timer is used, and setting up the
PIT would make check_timer() panic on machines without an HPET whose PIT
doesn't tick.
Fixes: c8c4076723da ("x86/timer: Skip PIT initialization on modern chipsets")
Signed-off-by: Jiaming Fan <fan.jiaming@hotmail.com>
---
Notes:
I first tried simply moving the disable_apic_timer check above the TSC
deadline check. That breaks SMP as described above; I reproduced the
check_timer() panic with QEMU -smp 2 -machine q35,hpet=off,pit=off
-cpu host,kvm=off and tsc_early_khz=3193914 (the guest's TSC frequency
on my host; use your own, or tsc_khz stays unknown early and the PIT is
required before the changed check is reached).
arch/x86/kernel/apic/apic.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 90025451ace2f..6b2e61ae7e240 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -782,6 +782,9 @@ bool __init apic_needs_pit(void)
if (!boot_cpu_has(X86_FEATURE_ARAT))
return true;
+ if (disable_apic_timer && num_possible_cpus() == 1)
+ return true;
+
/* Deadline timer is based on TSC so no further PIT action required */
if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER))
return false;
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [RFC PATCH 2/2] x86/apic: Honor noapictimer on SMP with the TSC deadline timer
2026-11-22 10:29 [PATCH 0/2] x86/apic: Make noapictimer work with the TSC deadline timer Jiaming Fan
2026-11-22 10:30 ` [PATCH 1/2] x86/timer: Don't skip PIT setup on UP when the local APIC timer is disabled Jiaming Fan
@ 2026-11-22 10:30 ` Jiaming Fan
1 sibling, 0 replies; 3+ messages in thread
From: Jiaming Fan @ 2026-11-22 10:30 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen
Cc: x86, H. Peter Anvin, linux-kernel
On SMP with "noapictimer", setup_boot_APIC_clock() leaves
CLOCK_EVT_FEAT_DUMMY set so that the local APIC clockevents become dummy
devices driven by the broadcast device. But the TSC deadline branch of
setup_APIC_timer() clears that flag unconditionally, so the option has no
effect on TSC deadline CPUs.
When the local APIC timer is in use and the boot CPU has the TSC deadline
timer, setup_boot_APIC_clock() has already cleared the flag, so clearing
it again there is redundant. Stop doing that, and ask for the PIT on SMP
too so that it can provide the broadcast tick when available.
This changes behaviour for SMP systems booted with "noapictimer": with a
working HPET or PIT the tick moves there, but without one a boot that
works today panics in check_timer() or hangs. Is that acceptable, or
should the option keep being ignored here?
Fixes: 279f1461432c ("x86: apic: Use tsc deadline for oneshot when available")
Signed-off-by: Jiaming Fan <fan.jiaming@hotmail.com>
---
arch/x86/kernel/apic/apic.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 6b2e61ae7e240..b25353fe88892 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -592,7 +592,7 @@ static void setup_APIC_timer(void)
if (this_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER)) {
levt->name = "lapic-deadline";
- levt->features &= ~(CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_DUMMY);
+ levt->features &= ~CLOCK_EVT_FEAT_PERIODIC;
levt->features |= CLOCK_EVT_FEAT_CLOCKSOURCE_COUPLED;
levt->cs_id = CSID_X86_TSC;
levt->set_next_event = lapic_next_deadline;
@@ -782,16 +782,14 @@ bool __init apic_needs_pit(void)
if (!boot_cpu_has(X86_FEATURE_ARAT))
return true;
- if (disable_apic_timer && num_possible_cpus() == 1)
+ /* APIC timer disabled? */
+ if (disable_apic_timer)
return true;
/* Deadline timer is based on TSC so no further PIT action required */
if (boot_cpu_has(X86_FEATURE_TSC_DEADLINE_TIMER))
return false;
- /* APIC timer disabled? */
- if (disable_apic_timer)
- return true;
/*
* The APIC timer frequency is known already, no PIT calibration
* required. If unknown, let the PIT be initialized.
--
2.56.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-22 10:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22 10:29 [PATCH 0/2] x86/apic: Make noapictimer work with the TSC deadline timer Jiaming Fan
2026-11-22 10:30 ` [PATCH 1/2] x86/timer: Don't skip PIT setup on UP when the local APIC timer is disabled Jiaming Fan
2026-11-22 10:30 ` [RFC PATCH 2/2] x86/apic: Honor noapictimer on SMP with the TSC deadline timer Jiaming Fan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®