public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hpet: Read HPET directly if panic in progress
@ 2024-05-28  6:38 Tony W Wang-oc
  2024-05-28 14:18 ` Dave Hansen
  0 siblings, 1 reply; 19+ messages in thread
From: Tony W Wang-oc @ 2024-05-28  6:38 UTC (permalink / raw)
  To: tglx, mingo, bp, dave.hansen, x86, hpa, keescook, tony.luck,
	gpiccoli, mat.jonczyk, rdunlap, alexandre.belloni,
	mario.limonciello, TonyWWang-oc, yaolu, bhelgaas, justinstitt,
	linux-kernel, linux-hardening
  Cc: CobeChen, TimGuo, LeoLiu-oc

When the clocksource of the system is HPET,a CPU executing read_hpet
might be interrupted by exceptions to executing the panic,this may
lead to read_hpet dead loops:

CPU x				    CPU x
----                                ----
read_hpet()
  arch_spin_trylock(&hpet.lock)
  [CPU x got the hpet.lock]         #MCE happened
				    do_machine_check()
				      mce_panic()
				        panic()
					  kmsg_dump()
					    pstore_dump()
					      pstore_record_init()
						ktime_get_real_fast_ns()
						  read_hpet()
						  [dead loops]

To avoid this dead loops, read HPET directly if panic in progress.

Signed-off-by: Tony W Wang-oc <TonyWWang-oc@zhaoxin.com>
---
 arch/x86/kernel/hpet.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index c96ae8fee95e..ecadd0698d6a 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -804,6 +804,12 @@ static u64 read_hpet(struct clocksource *cs)
 	if (in_nmi())
 		return (u64)hpet_readl(HPET_COUNTER);
 
+	/*
+	 * Read HPET directly if panic in progress.
+	 */
+	if (unlikely(atomic_read(&panic_cpu) != PANIC_CPU_INVALID))
+		return (u64)hpet_readl(HPET_COUNTER);
+
 	/*
 	 * Read the current state of the lock and HPET value atomically.
 	 */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2024-07-01 11:09 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-28  6:38 [PATCH] x86/hpet: Read HPET directly if panic in progress Tony W Wang-oc
2024-05-28 14:18 ` Dave Hansen
2024-05-28 22:12   ` Thomas Gleixner
2024-05-28 23:22     ` Linus Torvalds
2024-05-29  7:42       ` Thomas Gleixner
2024-06-05  6:23         ` Tony W Wang-oc
2024-06-05  9:36           ` Borislav Petkov
2024-06-05 10:10             ` Tony W Wang-oc
2024-06-05 11:33               ` Borislav Petkov
2024-06-05 12:02                 ` Tony W Wang-oc
2024-06-05 15:51                   ` Luck, Tony
2024-06-06  8:44                     ` Tony W Wang-oc
2024-06-06 17:00                       ` Luck, Tony
2024-05-29  4:39     ` Tony W Wang-oc
2024-05-29  6:44       ` Tony W Wang-oc
2024-05-29  7:45         ` Thomas Gleixner
2024-05-29  8:15           ` Tony W Wang-oc
2024-05-29  7:44       ` Thomas Gleixner
2024-07-01 11:09     ` Tony W Wang-oc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox