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

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/printk/printk.c+10−36
@@ -269,7 +269,6 @@ static struct console *exclusive_console; · 268 unmodified lines
269269 #define MAX_CMDLINECONSOLES 8
270270
271271 static struct console_cmdline console_cmdline[MAX_CMDLINECONSOLES];
272−static int console_cmdline_cnt;
273272
274273 static int preferred_console = -1;
275274 int console_set_on_cmdline;
@@ -1906,25 +1905,12 @@ static int __add_preferred_console(char *name, int idx, char *options, · 1630 unmodified lines
19061905 * See if this tty is not yet registered, and
19071906 * if we have a slot free.
19081907 */
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++) {
19101911 if (strcmp(c->name, name) == 0 && c->index == idx) {
1911− if (brl_options)
1912− return 0;
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−
1912+ if (!brl_options)
1913+ preferred_console = i;
19281914 return 0;
19291915 }
19301916 }
@@ -1937,7 +1923,6 @@ static int __add_preferred_console(char *name, int idx, char *options, · 6 unmodified lines
19371923 braille_set_options(c, brl_options);
19381924
19391925 c->index = idx;
1940− console_cmdline_cnt++;
19411926 return 0;
19421927 }
19431928 /*
@@ -2477,23 +2462,12 @@ void register_console(struct console *newcon) · 533 unmodified lines
24772462 }
24782463
24792464 /*
2480− * See if this console matches one we selected on the command line.
2481− *
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().
2465+ * See if this console matches one we selected on
2466+ * the command line.
24932467 */
2494− for (i = console_cmdline_cnt - 1; i >= 0; i--) {
2495− c = console_cmdline + i;
2496−
2468+ for (i = 0, c = console_cmdline;
2469+ i < MAX_CMDLINECONSOLES && c->name[0];
2470+ i++, c++) {
24972471 if (!newcon->match ||
24982472 newcon->match(newcon, c->name, c->index, c->options) != 0) {
24992473 /* default matching */