History

Revert "printk: fix double printing with earlycon"

This reverts commit cf39bf58afdaabc0b86f141630fb3fd18190294e. The commit regression to users that define both console=ttyS1 and console=ttyS0 on the command line, see https://lkml.kernel.org/r/20170509082915.GA13236@bistromath.localdomain The kernel log messages always appeared only on one serial port. It is even documented in Documentation/admin-guide/serial-console.rst: "Note that you can only define one console per device type (serial, video)." The above mentioned commit changed the order in which the command line parameters are searched. As a result, the kernel log messages go to the last mentioned ttyS* instead of the first one. We long thought that using two console=ttyS* on the command line did not make sense. But then we realized that console= parameters were handled also by systemd, see http://0pointer.de/blog/projects/serial-console.html "By default systemd will instantiate one serial-getty@.service on the main kernel console, if it is not a virtual terminal." where "[4] If multiple kernel consoles are used simultaneously, the main console is the one listed first in /sys/class/tty/console/active, which is the last one listed on the kernel command line." This puts the original report into another light. The system is running in qemu. The first serial port is used to store the messages into a file. The second one is used to login to the system via a socket. It depends on systemd and the historic kernel behavior. By other words, systemd causes that it makes sense to define both console=ttyS1 console=ttyS0 on the command line. The kernel fix caused regression related to userspace (systemd) and need to be reverted. In addition, it went out that the fix helped only partially. The messages still were duplicated when the boot console was removed early by late_initcall(printk_late_init). Then the entire log was replayed when the same console was registered as a normal one.

Petr Mladek committed 9 years ago

Commit dac8bbb1 parent 9c35baf1 file · +10 −36Browse files

Unified · Split

kernel/printk/printk.c+10−36
@@ -269,7 +269,6 @@ static struct console *exclusive_console; · 268 unmodified lines
269#define MAX_CMDLINECONSOLES 8269#define MAX_CMDLINECONSOLES 8
270 270
271static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];271static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
272static int console_cmdline_cnt;
273 272
274static int preferred_console = -1;273static int preferred_console = -1;
275int console_set_on_cmdline;274int console_set_on_cmdline;
@@ -1906,25 +1905,12 @@ static int __add_preferred_console(char *name, int idx, char *options, · 1630 unmodified lines
1906 * See if this tty is not yet registered, and1905 * See if this tty is not yet registered, and
1907 * if we have a slot free.1906 * if we have a slot free.
1908 */1907 */
1909 for (i = 0, c = console_cmdline; i < console_cmdline_cnt; i++, c++) {1908 for (i = 0, c = console_cmdline;
1909 i < MAX_CMDLINECONSOLES && c->name[0];
1910 i++, c++) {
1910 if (strcmp(c->name, name) == 0 && c->index == idx) {1911 if (strcmp(c->name, name) == 0 && c->index == idx) {
1911 if (brl_options)1912 if (!brl_options)
1912 return 0;1913 preferred_console = i;
1913
1914 /*
1915 * Maintain an invariant that will help to find if
1916 * the matching console is preferred, see
1917 * register_console():
1918 *
1919 * The last non-braille console is always
1920 * the preferred one.
1921 */
1922 if (i != console_cmdline_cnt - 1)
1923 swap(console_cmdline[i],
1924 console_cmdline[console_cmdline_cnt - 1]);
1925
1926 preferred_console = console_cmdline_cnt - 1;
1927
1928 return 0;1914 return 0;
1929 }1915 }
1930 }1916 }
@@ -1937,7 +1923,6 @@ static int __add_preferred_console(char *name, int idx, char *options, · 6 unmodified lines
1937 braille_set_options(c, brl_options);1923 braille_set_options(c, brl_options);
1938 1924
1939 c->index = idx;1925 c->index = idx;
1940 console_cmdline_cnt++;
1941 return 0;1926 return 0;
1942}1927}
1943/*1928/*
@@ -2477,23 +2462,12 @@ void register_console(struct console *newcon) · 533 unmodified lines
2477 }2462 }
2478 2463
2479 /*2464 /*
2480 * See if this console matches one we selected on the command line.2465 * See if this console matches one we selected on
2481 *2466 * the command line.
2482 * There may be several entries in the console_cmdline array matching
2483 * with the same console, one with newcon->match(), another by
2484 * name/index:
2485 *
2486 * pl011,mmio,0x87e024000000,115200 -- added from SPCR
2487 * ttyAMA0 -- added from command line
2488 *
2489 * Traverse the console_cmdline array in reverse order to be
2490 * sure that if this console is preferred then it will be the first
2491 * matching entry. We use the invariant that is maintained in
2492 * __add_preferred_console().
2493 */2467 */
2494 for (i = console_cmdline_cnt - 1; i >= 0; i--) {2468 for (i = 0, c = console_cmdline;
2495 c = console_cmdline + i;2469 i < MAX_CMDLINECONSOLES && c->name[0];
2496 2470 i++, c++) {
2497 if (!newcon->match ||2471 if (!newcon->match ||
2498 newcon->match(newcon, c->name, c->index, c->options) != 0) {2472 newcon->match(newcon, c->name, c->index, c->options) != 0) {
2499 /* default matching */2473 /* default matching */