hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ID3W9Y ------------------ In hrtimer_interrupt(), interrupts are disabled when acquiring a spinlock, which subsequently triggers an oops. During the oops call chain, blocking_notifier_call_chain() invokes _cond_resched, ultimately leading to a hard lockup. Call Stack: #0 [ffff8a317f6c3ac0] __cond_resched at ffffffffa10d29a6 #1 [ffff8a317f6c3ad8] _cond_resched at ffffffffa17292cf #2 [ffff8a317f6c3ae8] down_read at ffffffffa1728022 #3 [ffff8a317f6c3b00] __blocking_notifier_call_chain at ffffffffa10c5c37 #4 [ffff8a317f6c3b40] blocking_notifier_call_chain at ffffffffa10c5c86 #5 [ffff8a317f6c3b50] fb_notifier_call_chain at ffffffffa13c83eb #6 [ffff8a317f6c3b60] fb_blank at ffffffffa13c88eb #7 [ffff8a317f6c3ba0] fbcon_blank at ffffffffa13d4a4b #8 [ffff8a317f6c3ca0] do_unblank_screen at ffffffffa144cb30 #9 [ffff8a317f6c3cc0] unblank_screen at ffffffffa144cbf0 If the system is in an oops state, use down_read_trylock instead of a blocking lock acquisition. If the trylock fails, skip executing the notifier callbacks to avoid potential deadlocks or unsafe operations during the oops handling process. Fixes: fe9d4f576324 ("Add kernel/notifier.c") Signed-off-by: Yi Yang <yiyang13@huawei.com> --- kernel/notifier.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kernel/notifier.c b/kernel/notifier.c index d2aecd64b109..29e1f5d51f12 100644 --- a/kernel/notifier.c +++ b/kernel/notifier.c @@ -318,10 +318,20 @@ int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, * is, we re-check the list after having taken the lock anyway: */ if (rcu_access_pointer(nh->head)) { - down_read(&nh->rwsem); - ret = notifier_call_chain(&nh->head, val, v, nr_to_call, - nr_calls); - up_read(&nh->rwsem); + if (!oops_in_progress) { + down_read(&nh->rwsem); + ret = notifier_call_chain(&nh->head, val, v, + nr_to_call, nr_calls); + up_read(&nh->rwsem); + } else { + if (down_read_trylock(&nh->rwsem)) { + ret = notifier_call_chain(&nh->head, val, + v, nr_to_call, nr_calls); + up_read(&nh->rwsem); + } else { + ret = NOTIFY_BAD; + } + } } return ret; } -- 2.25.1