Skip to content

Commit

Permalink
x86/hpet: Read HPET directly if panic in progress
Browse files Browse the repository at this point in the history
zhaoxin inclusion
category: other

-------------------

When the clocksource of the system is HPET,a CPU executing read_hpet might
be interrupted by #GP/#PF 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]         #GP/#PF happened
                                    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: leoliu-oc <[email protected]>
  • Loading branch information
leoliu-oc authored and Avenger-285714 committed Aug 17, 2024
1 parent ac1ff20 commit 2c69b5f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/x86/kernel/hpet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 2c69b5f

Please sign in to comment.