hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/kernel/panic.c
....@@ -177,7 +177,6 @@
177177 void panic(const char *fmt, ...)
178178 {
179179 static char buf[1024];
180
- va_list args2;
181180 va_list args;
182181 long i, i_next = 0, len;
183182 int state = 0;
....@@ -192,21 +191,6 @@
192191 */
193192 local_irq_disable();
194193 preempt_disable_notrace();
195
-
196
- console_verbose();
197
- pr_emerg("Kernel panic - not syncing:\n");
198
- va_start(args2, fmt);
199
- va_copy(args, args2);
200
- vprintk(fmt, args2);
201
- va_end(args2);
202
-#ifdef CONFIG_DEBUG_BUGVERBOSE
203
- /*
204
- * Avoid nested stack-dumping if a panic occurs during oops processing
205
- */
206
- if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
207
- dump_stack();
208
-#endif
209
- pr_flush(1000, true);
210194
211195 /*
212196 * It's possible to come here directly from a panic-assertion and
....@@ -229,12 +213,23 @@
229213 if (old_cpu != PANIC_CPU_INVALID && old_cpu != this_cpu)
230214 panic_smp_self_stop();
231215
216
+ console_verbose();
232217 bust_spinlocks(1);
218
+ va_start(args, fmt);
233219 len = vscnprintf(buf, sizeof(buf), fmt, args);
234220 va_end(args);
235221
236222 if (len && buf[len - 1] == '\n')
237223 buf[len - 1] = '\0';
224
+
225
+ pr_emerg("Kernel panic - not syncing: %s\n", buf);
226
+#ifdef CONFIG_DEBUG_BUGVERBOSE
227
+ /*
228
+ * Avoid nested stack-dumping if a panic occurs during oops processing
229
+ */
230
+ if (!test_taint(TAINT_DIE) && oops_in_progress <= 1)
231
+ dump_stack();
232
+#endif
238233
239234 /*
240235 * If kgdb is enabled, give it a chance to run before we stop all
....@@ -252,6 +247,7 @@
252247 * Bypass the panic_cpu check and call __crash_kexec directly.
253248 */
254249 if (!_crash_kexec_post_notifiers) {
250
+ printk_safe_flush_on_panic();
255251 __crash_kexec(NULL);
256252
257253 /*
....@@ -275,6 +271,8 @@
275271 */
276272 atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
277273
274
+ /* Call flush even twice. It tries harder with a single online CPU */
275
+ printk_safe_flush_on_panic();
278276 kmsg_dump(KMSG_DUMP_PANIC);
279277
280278 /*
....@@ -544,11 +542,9 @@
544542
545543 static int init_oops_id(void)
546544 {
547
-#ifndef CONFIG_PREEMPT_RT
548545 if (!oops_id)
549546 get_random_bytes(&oops_id, sizeof(oops_id));
550547 else
551
-#endif
552548 oops_id++;
553549
554550 return 0;
....@@ -559,7 +555,6 @@
559555 {
560556 init_oops_id();
561557 pr_warn("---[ end trace %016llx ]---\n", (unsigned long long)oops_id);
562
- pr_flush(1000, true);
563558 }
564559
565560 /*