File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -2597,6 +2597,25 @@ static int have_callable_console(void)
2597
2597
return 0 ;
2598
2598
}
2599
2599
2600
+ /*
2601
+ * Return true when this CPU should unlock console_sem without pushing all
2602
+ * messages to the console. This reduces the chance that the console is
2603
+ * locked when the panic CPU tries to use it.
2604
+ */
2605
+ static bool abandon_console_lock_in_panic (void )
2606
+ {
2607
+ if (!panic_in_progress ())
2608
+ return false;
2609
+
2610
+ /*
2611
+ * We can use raw_smp_processor_id() here because it is impossible for
2612
+ * the task to be migrated to the panic_cpu, or away from it. If
2613
+ * panic_cpu has already been set, and we're not currently executing on
2614
+ * that CPU, then we never will be.
2615
+ */
2616
+ return atomic_read (& panic_cpu ) != raw_smp_processor_id ();
2617
+ }
2618
+
2600
2619
/*
2601
2620
* Can we actually use the console at this time on this cpu?
2602
2621
*
@@ -2745,6 +2764,10 @@ void console_unlock(void)
2745
2764
if (handover )
2746
2765
return ;
2747
2766
2767
+ /* Allow panic_cpu to take over the consoles safely */
2768
+ if (abandon_console_lock_in_panic ())
2769
+ break ;
2770
+
2748
2771
if (do_cond_resched )
2749
2772
cond_resched ();
2750
2773
}
@@ -2762,7 +2785,7 @@ void console_unlock(void)
2762
2785
* flush, no worries.
2763
2786
*/
2764
2787
retry = prb_read_valid (prb , next_seq , NULL );
2765
- if (retry && console_trylock ())
2788
+ if (retry && ! abandon_console_lock_in_panic () && console_trylock ())
2766
2789
goto again ;
2767
2790
}
2768
2791
EXPORT_SYMBOL (console_unlock );
You can’t perform that action at this time.
0 commit comments