@@ -1907,17 +1907,36 @@ struct console *early_console;
asmlinkage __visible void early_printk(const char *fmt, ...)
{
va_list ap;
+ static int print_cpu = -1;
char buf[512];
- int n;
+ int n, cpu;
if (!early_console)
return;
+ preempt_disable();
+ cpu = raw_smp_processor_id();
+ for (;;) {
+ if (READ_ONCE(print_cpu) == cpu)
+ break;
+
+ if (READ_ONCE(print_cpu) == -1 &&
+ cmpxchg(&print_cpu, -1, cpu) == -1) {
+ cpu = -1;
+ break;
+ }
+
+ cpu_relax();
+ }
+
va_start(ap, fmt);
n = vscnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
early_console->write(early_console, buf, n);
+
+ smp_store_release(&print_cpu, cpu);
+ preempt_enable();
}
#endif