2016-10-16 18:07:28

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH v2] console: Don't prefer first registered if DT specifies stdout-path

On Aug 09 2016, Paul Burton <[email protected]> wrote:

> Fix this by not automatically preferring the first registered console if
> one is specified by the device tree. This allows consoles to be
> registered but not enabled, and once the driver for the console selected
> by stdout-path calls of_console_check() the driver will be added to the
> list of preferred consoles before any other console has been enabled.
> When that console is then registered via register_console() it will be
> enabled as expected.

This breaks the console on PowerMac. There is no output and it panics
eventually.

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."


2016-10-17 10:34:13

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v2] console: Don't prefer first registered if DT specifies stdout-path

On Sunday, 16 October 2016 20:07:18 BST Andreas Schwab wrote:
> On Aug 09 2016, Paul Burton <[email protected]> wrote:
> > Fix this by not automatically preferring the first registered console if
> > one is specified by the device tree. This allows consoles to be
> > registered but not enabled, and once the driver for the console selected
> > by stdout-path calls of_console_check() the driver will be added to the
> > list of preferred consoles before any other console has been enabled.
> > When that console is then registered via register_console() it will be
> > enabled as expected.
>
> This breaks the console on PowerMac. There is no output and it panics
> eventually.
>
> Andreas.

Hi Andreas,

Could you share the device tree from your system?

Thanks,
Paul


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-10-17 17:40:12

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH v2] console: Don't prefer first registered if DT specifies stdout-path

On Okt 17 2016, Paul Burton <[email protected]> wrote:

> Could you share the device tree from your system?

This is the contents of chosen/linux,stdout-path on the systems I have:

chosen/linux,stdout-path
"/pci@f0000000/ATY,SnowyParent@10/ATY,Snowy_A@0"

chosen/linux,stdout-path
"/pci@0,f0000000/NVDA,Parent@10/NVDA,Display-B@1"

Is that what you need? There is also chosen/stdout, but no
aliases/stdout.

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2016-10-18 09:19:25

by Paul Burton

[permalink] [raw]
Subject: [PATCH] console: use first console if stdout-path device doesn't appear

If a device tree specified a preferred device for kernel console output
via the stdout-path or linux,stdout-path chosen node properties there's
no guarantee that it will have specified a device for which we have a
driver. It may also be the case that we do have a driver but it doesn't
call of_console_check() to register as a preferred console (eg. offb
driver as used on powermac systems). In these cases try to ensure that
we provide some console output by enabling the first console in the
console_drivers list.

As I don't have access to an affected system this has only been build
tested - testing would be most appreciated.

Signed-off-by: Paul Burton <[email protected]>
Fixes: 05fd007e4629 ("console: don't prefer first registered if DT specifies stdout-path")
Reported-by: Andreas Schwab <[email protected]>
Cc: Andreas Schwab <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: [email protected]
Cc: [email protected]
---
A potential alternative to this might be to have the affected offb
driver call of_check_console(), and perhaps that should happen anyway,
but doing so seems non-trivial since the offb driver doesn't know the
index of the framebuffer console device it may be about to register &
the fbdev core doesn't know the associated device tree node. This also
wouldn't catch the case of us not having a driver for the device
specified by stdout-path, so this fallback seems worthwhile anyway.
---
kernel/printk/printk.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index d5e3973..7091e2f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2835,10 +2835,45 @@ EXPORT_SYMBOL(unregister_console);
* intersects with the init section. Note that code exists elsewhere to get
* rid of the boot console as soon as the proper console shows up, so there
* won't be side-effects from postponing the removal.
+ *
+ * Additionally we may be using a device tree which specifies valid
+ * stdout-path referencing a device for which we don't have a driver, or for
+ * which we have a driver that doesn't register itself as preferred console
+ * using of_console_check(). In these cases we attempt here to enable the
+ * first registered console.
*/
static int __init printk_late_init(void)
{
- struct console *con;
+ struct console *con, *enabled;
+
+ if (of_specified_console) {
+ console_lock();
+
+ /* Find the enabled console, if there is one */
+ enabled = NULL;
+ for_each_console(con) {
+ if (!(con->flags & CON_ENABLED))
+ continue;
+
+ enabled = con;
+ break;
+ }
+
+ /* Enable the first console if none were already enabled */
+ con = console_drivers;
+ if (!enabled && con) {
+ if (con->index < 0)
+ con->index = 0;
+ if (con->setup == NULL ||
+ con->setup(con, NULL) == 0) {
+ con->flags |= CON_ENABLED;
+ if (con->device)
+ con->flags |= CON_CONSDEV;
+ }
+ }
+
+ console_unlock();
+ }

for_each_console(con) {
if (!keep_bootcon && con->flags & CON_BOOT) {
--
2.10.0

2016-10-18 09:21:50

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v2] console: Don't prefer first registered if DT specifies stdout-path

On Monday, 17 October 2016 19:39:57 BST Andreas Schwab wrote:
> On Okt 17 2016, Paul Burton <[email protected]> wrote:
> > Could you share the device tree from your system?
>
> This is the contents of chosen/linux,stdout-path on the systems I have:
>
> chosen/linux,stdout-path
> "/pci@f0000000/ATY,SnowyParent@10/ATY,Snowy_A@0"
>
> chosen/linux,stdout-path
> "/pci@0,f0000000/NVDA,Parent@10/NVDA,Display-B@1"
>
> Is that what you need? There is also chosen/stdout, but no
> aliases/stdout.
>
> Andreas.

Hi Andreas,

I think I see the problem & I'm hoping this patch will fix it:

https://lkml.org/lkml/2016/10/18/142

Could you give it a try & let me know?

Thanks,
Paul


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-10-18 18:58:59

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] console: use first console if stdout-path device doesn't appear

On Okt 18 2016, Paul Burton <[email protected]> wrote:

> If a device tree specified a preferred device for kernel console output
> via the stdout-path or linux,stdout-path chosen node properties there's
> no guarantee that it will have specified a device for which we have a
> driver. It may also be the case that we do have a driver but it doesn't
> call of_console_check() to register as a preferred console (eg. offb
> driver as used on powermac systems). In these cases try to ensure that
> we provide some console output by enabling the first console in the
> console_drivers list.
>
> As I don't have access to an affected system this has only been build
> tested - testing would be most appreciated.

Unfortunately that doesn't work. The initial console still cannot be
opened.

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2016-10-30 09:47:00

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH] console: use first console if stdout-path device doesn't appear

Any news?

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2016-10-31 05:29:06

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH] console: use first console if stdout-path device doesn't appear

Andreas Schwab <[email protected]> writes:

> Any news?

We discovered it also breaks VGA on qemu, which presumably is not the
type of news you were hoping for.


To reproduce you just need to build a ppc64le kernel:

$ apt-get install gcc-powerpc64le-linux-gnu
$ make ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu- pseries_le_defconfig
$ make ARCH=powerpc CROSS_COMPILE=powerpc64le-linux-gnu-

And then run qemu:

$ qemu-system-ppc64 -M pseries -m 1G -kernel vmlinux


Which will display the Tux logo but then nothing else and then reboot
after 10 seconds or so.

If you revert 05fd007e4629 on top of rc3 it boots fine.


Paul I tried your "console: use first console if stdout-path device
doesn't appear" patch, but it didn't help. I'll try and work out why,
but it's a bit hard with no output :)


If we can't come up with a fix soon I'm inclined to ask for a revert.

cheers

2016-10-31 12:15:26

by Paul Burton

[permalink] [raw]
Subject: [PATCH v2] console: use first console if stdout-path device doesn't appear

If a device tree specified a preferred device for kernel console output
via the stdout-path or linux,stdout-path chosen node properties there's
no guarantee that it will have specified a device for which we have a
driver. It may also be the case that we do have a driver but it doesn't
call of_console_check() to register as a preferred console (eg. offb
driver as used on powermac systems). In these cases try to ensure that
we provide some console output by enabling the first usable registered
console, which we keep track of with the of_fallback_console variable.

Tested in QEMU with a PowerPC pseries_defconfig kernel.

Signed-off-by: Paul Burton <[email protected]>
Fixes: 05fd007e4629 ("console: don't prefer first registered if DT specifies stdout-path")
Reported-by: Andreas Schwab <[email protected]>
Reported-by: Larry Finger <[email protected]>
Reported-by: Michael Ellerman <[email protected]>
Cc: Andreas Schwab <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Larry Finger <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: [email protected]
Cc: [email protected]

---

Changes in v2:
- Split enable_console() out of register_console() & call in the fallback case.
- Track the console we would have enabled as of_fallback_console.

kernel/printk/printk.c | 60 +++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index de08fc9..b02c00a 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -264,6 +264,13 @@ void console_set_by_of(void)
# define of_specified_console false
#endif

+/*
+ * The first usable console, which we'll fall back to using if the system
+ * uses a device tree which indicates a stdout-path device for which we
+ * have no driver, or for which our driver doesn't call of_console_check().
+ */
+static struct console *of_fallback_console;
+
/* Flag: console code may call schedule() */
static int console_may_schedule;

@@ -2598,6 +2605,8 @@ static int __init keep_bootcon_setup(char *str)

early_param("keep_bootcon", keep_bootcon_setup);

+static void enable_console(struct console *newcon);
+
/*
* The console driver calls this routine during kernel initialization
* to register the console printing procedure with printk() and to
@@ -2620,7 +2629,6 @@ early_param("keep_bootcon", keep_bootcon_setup);
void register_console(struct console *newcon)
{
int i;
- unsigned long flags;
struct console *bcon = NULL;
struct console_cmdline *c;

@@ -2657,7 +2665,9 @@ void register_console(struct console *newcon)
* didn't select a console we take the first one
* that registers here.
*/
- if (preferred_console < 0 && !of_specified_console) {
+ if (preferred_console < 0 && of_specified_console) {
+ of_fallback_console = of_fallback_console ?: newcon;
+ } else if (preferred_console < 0) {
if (newcon->index < 0)
newcon->index = 0;
if (newcon->setup == NULL ||
@@ -2705,8 +2715,18 @@ void register_console(struct console *newcon)
break;
}

- if (!(newcon->flags & CON_ENABLED))
- return;
+ if (newcon->flags & CON_ENABLED)
+ enable_console(newcon);
+}
+EXPORT_SYMBOL(register_console);
+
+static void enable_console(struct console *newcon)
+{
+ struct console *bcon = NULL;
+ unsigned long flags;
+
+ if (console_drivers && console_drivers->flags & CON_BOOT)
+ bcon = console_drivers;

/*
* If we have a bootconsole, and are switching to a real console,
@@ -2777,7 +2797,6 @@ void register_console(struct console *newcon)
unregister_console(bcon);
}
}
-EXPORT_SYMBOL(register_console);

int unregister_console(struct console *console)
{
@@ -2839,10 +2858,41 @@ EXPORT_SYMBOL(unregister_console);
* intersects with the init section. Note that code exists elsewhere to get
* rid of the boot console as soon as the proper console shows up, so there
* won't be side-effects from postponing the removal.
+ *
+ * Additionally we may be using a device tree which specifies valid
+ * stdout-path referencing a device for which we don't have a driver, or for
+ * which we have a driver that doesn't register itself as preferred console
+ * using of_console_check(). In these cases we attempt here to enable the
+ * first usable registered console, which we assigned to of_fallback_console.
*/
static int __init printk_late_init(void)
{
struct console *con;
+ bool any_enabled = false;
+
+ for_each_console(con) {
+ if (!(con->flags & CON_ENABLED))
+ continue;
+
+ any_enabled = true;
+ break;
+ }
+
+ if (!any_enabled && of_fallback_console) {
+ if (of_fallback_console->index < 0)
+ of_fallback_console->index = 0;
+
+ if (!of_fallback_console->setup ||
+ !of_fallback_console->setup(of_fallback_console, NULL)) {
+ of_fallback_console->flags |= CON_ENABLED;
+ if (of_fallback_console->device) {
+ of_fallback_console->flags |= CON_CONSDEV;
+ preferred_console = 0;
+ }
+ }
+
+ enable_console(of_fallback_console);
+ }

for_each_console(con) {
if (!keep_bootcon && con->flags & CON_BOOT) {
--
2.10.1

2016-10-31 12:23:36

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH] console: use first console if stdout-path device doesn't appear

Hi Michael et al,

On Monday, 31 October 2016 16:28:59 GMT Michael Ellerman wrote:
> Andreas Schwab <[email protected]> writes:
> > Any news?
>
> We discovered it also breaks VGA on qemu, which presumably is not the
> type of news you were hoping for.

On the contrary, that's wonderful news - I can test that! Huzzah for
brokenness!

Thanks for your steps to reproduce the issue. Could you try my v2 patch? It
works for me in QEMU, at least as far as seeing the kernel console output for
a panic due to not having a rootfs. Hopefully it works for you (& Andreas &
Larry) too:

https://patchwork.kernel.org/patch/9405415/

Thanks,
Paul


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-10-31 15:51:07

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

On Monday, 31 October 2016 12:14:55 GMT Paul Burton wrote:
> If a device tree specified a preferred device for kernel console output
> via the stdout-path or linux,stdout-path chosen node properties there's
> no guarantee that it will have specified a device for which we have a
> driver. It may also be the case that we do have a driver but it doesn't
> call of_console_check() to register as a preferred console (eg. offb
> driver as used on powermac systems). In these cases try to ensure that
> we provide some console output by enabling the first usable registered
> console, which we keep track of with the of_fallback_console variable.
>
> Tested in QEMU with a PowerPC pseries_defconfig kernel.

Actually whilst this fixes the output in QEMU it has other problems. I'm still
digging...

Thanks,
Paul

>
> Signed-off-by: Paul Burton <[email protected]>
> Fixes: 05fd007e4629 ("console: don't prefer first registered if DT specifies
> stdout-path") Reported-by: Andreas Schwab <[email protected]>
> Reported-by: Larry Finger <[email protected]>
> Reported-by: Michael Ellerman <[email protected]>
> Cc: Andreas Schwab <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Borislav Petkov <[email protected]>
> Cc: Larry Finger <[email protected]>
> Cc: Michael Ellerman <[email protected]>
> Cc: Petr Mladek <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Tejun Heo <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
>
> ---
>
> Changes in v2:
> - Split enable_console() out of register_console() & call in the fallback
> case. - Track the console we would have enabled as of_fallback_console.
>
> kernel/printk/printk.c | 60
> +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 55
> insertions(+), 5 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index de08fc9..b02c00a 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -264,6 +264,13 @@ void console_set_by_of(void)
> # define of_specified_console false
> #endif
>
> +/*
> + * The first usable console, which we'll fall back to using if the system
> + * uses a device tree which indicates a stdout-path device for which we
> + * have no driver, or for which our driver doesn't call of_console_check().
> + */
> +static struct console *of_fallback_console;
> +
> /* Flag: console code may call schedule() */
> static int console_may_schedule;
>
> @@ -2598,6 +2605,8 @@ static int __init keep_bootcon_setup(char *str)
>
> early_param("keep_bootcon", keep_bootcon_setup);
>
> +static void enable_console(struct console *newcon);
> +
> /*
> * The console driver calls this routine during kernel initialization
> * to register the console printing procedure with printk() and to
> @@ -2620,7 +2629,6 @@ early_param("keep_bootcon", keep_bootcon_setup);
> void register_console(struct console *newcon)
> {
> int i;
> - unsigned long flags;
> struct console *bcon = NULL;
> struct console_cmdline *c;
>
> @@ -2657,7 +2665,9 @@ void register_console(struct console *newcon)
> * didn't select a console we take the first one
> * that registers here.
> */
> - if (preferred_console < 0 && !of_specified_console) {
> + if (preferred_console < 0 && of_specified_console) {
> + of_fallback_console = of_fallback_console ?: newcon;
> + } else if (preferred_console < 0) {
> if (newcon->index < 0)
> newcon->index = 0;
> if (newcon->setup == NULL ||
> @@ -2705,8 +2715,18 @@ void register_console(struct console *newcon)
> break;
> }
>
> - if (!(newcon->flags & CON_ENABLED))
> - return;
> + if (newcon->flags & CON_ENABLED)
> + enable_console(newcon);
> +}
> +EXPORT_SYMBOL(register_console);
> +
> +static void enable_console(struct console *newcon)
> +{
> + struct console *bcon = NULL;
> + unsigned long flags;
> +
> + if (console_drivers && console_drivers->flags & CON_BOOT)
> + bcon = console_drivers;
>
> /*
> * If we have a bootconsole, and are switching to a real console,
> @@ -2777,7 +2797,6 @@ void register_console(struct console *newcon)
> unregister_console(bcon);
> }
> }
> -EXPORT_SYMBOL(register_console);
>
> int unregister_console(struct console *console)
> {
> @@ -2839,10 +2858,41 @@ EXPORT_SYMBOL(unregister_console);
> * intersects with the init section. Note that code exists elsewhere to get
> * rid of the boot console as soon as the proper console shows up, so there
> * won't be side-effects from postponing the removal.
> + *
> + * Additionally we may be using a device tree which specifies valid
> + * stdout-path referencing a device for which we don't have a driver, or
> for + * which we have a driver that doesn't register itself as preferred
> console + * using of_console_check(). In these cases we attempt here to
> enable the + * first usable registered console, which we assigned to
> of_fallback_console. */
> static int __init printk_late_init(void)
> {
> struct console *con;
> + bool any_enabled = false;
> +
> + for_each_console(con) {
> + if (!(con->flags & CON_ENABLED))
> + continue;
> +
> + any_enabled = true;
> + break;
> + }
> +
> + if (!any_enabled && of_fallback_console) {
> + if (of_fallback_console->index < 0)
> + of_fallback_console->index = 0;
> +
> + if (!of_fallback_console->setup ||
> + !of_fallback_console->setup(of_fallback_console, NULL)) {
> + of_fallback_console->flags |= CON_ENABLED;
> + if (of_fallback_console->device) {
> + of_fallback_console->flags |= CON_CONSDEV;
> + preferred_console = 0;
> + }
> + }
> +
> + enable_console(of_fallback_console);
> + }
>
> for_each_console(con) {
> if (!keep_bootcon && con->flags & CON_BOOT) {


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-10-31 15:58:21

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

On 10/31/2016 07:14 AM, Paul Burton wrote:
> If a device tree specified a preferred device for kernel console output
> via the stdout-path or linux,stdout-path chosen node properties there's
> no guarantee that it will have specified a device for which we have a
> driver. It may also be the case that we do have a driver but it doesn't
> call of_console_check() to register as a preferred console (eg. offb
> driver as used on powermac systems). In these cases try to ensure that
> we provide some console output by enabling the first usable registered
> console, which we keep track of with the of_fallback_console variable.
>
> Tested in QEMU with a PowerPC pseries_defconfig kernel.

The patch fails to fix my real PowerPC. I still get a kernel panic for an
attempt to kill init. This first test was done with 4.9-rc2. I am in the process
of updating to -rc3 to see if that changes anything. Later today when that build
finishes, I will report those results.

Larry

2016-10-31 19:21:35

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

On 10/31/2016 10:50 AM, Paul Burton wrote:
> On Monday, 31 October 2016 12:14:55 GMT Paul Burton wrote:
>> If a device tree specified a preferred device for kernel console output
>> via the stdout-path or linux,stdout-path chosen node properties there's
>> no guarantee that it will have specified a device for which we have a
>> driver. It may also be the case that we do have a driver but it doesn't
>> call of_console_check() to register as a preferred console (eg. offb
>> driver as used on powermac systems). In these cases try to ensure that
>> we provide some console output by enabling the first usable registered
>> console, which we keep track of with the of_fallback_console variable.
>>
>> Tested in QEMU with a PowerPC pseries_defconfig kernel.
>
> Actually whilst this fixes the output in QEMU it has other problems. I'm still
> digging...

As expected, it does n ot work with 4.9-rc3 on the real PowerPC.

Larry


2016-10-31 23:11:02

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

Hi,

On (10/31/16 15:50), Paul Burton wrote:
[..]
> Actually whilst this fixes the output in QEMU it has other problems. I'm still
> digging...

I propose a revert of '05fd007e46296', so you guys can find the
problem and fix it, not being under 'rc3' pressure.

-ss

2016-10-31 23:31:48

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

On 10/31/2016 06:09 PM, Sergey Senozhatsky wrote:
> Hi,
>
> On (10/31/16 15:50), Paul Burton wrote:
> [..]
>> Actually whilst this fixes the output in QEMU it has other problems. I'm still
>> digging...
>
> I propose a revert of '05fd007e46296', so you guys can find the
> problem and fix it, not being under 'rc3' pressure.

If we were at -rc4 or -rc5, then I would agree; however, I think there is still
time to fix the problem.

Larry


2016-11-01 04:39:14

by Michael Ellerman

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

Sergey Senozhatsky <[email protected]> writes:
> On (10/31/16 15:50), Paul Burton wrote:
> [..]
>> Actually whilst this fixes the output in QEMU it has other problems. I'm still
>> digging...
>
> I propose a revert of '05fd007e46296', so you guys can find the
> problem and fix it, not being under 'rc3' pressure.

Yeah I agree. The v2 fix doesn't work for me either.

Paul are you OK with that? And if so are you happy to send a revert to
Linus?

cheers

2016-11-03 13:00:00

by Paul Burton

[permalink] [raw]
Subject: [PATCH v3] console: use first console if stdout-path device doesn't appear

If a device tree specified a preferred device for kernel console output
via the stdout-path or linux,stdout-path chosen node properties there's
no guarantee that it will have specified a device for which we have a
driver. It may also be the case that we do have a driver but it doesn't
call of_console_check() to register as a preferred console (eg. offb
driver as used on powermac systems).

In these cases try to ensure that we provide some console output by
enabling the first usable registered console, which we keep track of
with the of_fallback_console variable. Affected systems will enable
their console later than they did prior to commit 05fd007e4629
("console: don't prefer first registered if DT specifies stdout-path")
but should otherwise produce the same output.

Tested in QEMU with a PowerPC pseries_defconfig kernel.

Signed-off-by: Paul Burton <[email protected]>
Fixes: 05fd007e4629 ("console: don't prefer first registered if DT specifies stdout-path")
Reported-by: Andreas Schwab <[email protected]>
Reported-by: Larry Finger <[email protected]>
Reported-by: Michael Ellerman <[email protected]>
Cc: Andreas Schwab <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Larry Finger <[email protected]>
Cc: Michael Ellerman <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: Sergey Senozhatsky <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: [email protected]
Cc: [email protected]

---

Changes in v3:
- Be less invasive by simply calling register_console() again rather than splitting it.
- Check for CON_CONSDEV on the first console driver rather than for CON_ENABLED on any.
- Clean up the tracking of the fallback console.

Changes in v2:
- Split enable_console() out of register_console() & call in the fallback case.
- Track the console we would have enabled as of_fallback_console.

kernel/printk/printk.c | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 42 insertions(+), 2 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index de08fc9..c86e6d0 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -260,10 +260,18 @@ void console_set_by_of(void)
{
of_specified_console = true;
}
+
+static void clear_of_specified_console(void)
+{
+ of_specified_console = false;
+}
#else
# define of_specified_console false
+static void clear_of_specified_console(void) { }
#endif

+struct console *of_fallback_console;
+
/* Flag: console code may call schedule() */
static int console_may_schedule;

@@ -2657,10 +2665,26 @@ void register_console(struct console *newcon)
* didn't select a console we take the first one
* that registers here.
*/
- if (preferred_console < 0 && !of_specified_console) {
+ if (preferred_console < 0) {
if (newcon->index < 0)
newcon->index = 0;
- if (newcon->setup == NULL ||
+ if (of_specified_console) {
+ /*
+ * The device tree stdout-path chosen node property was
+ * specified so we don't want to enable the first
+ * registered console just now in order to give the
+ * device indicated by stdout-path a chance to be
+ * registered first. Do however keep track of the
+ * first console we see so that we can fall back to
+ * using it if we don't see the desired device, either
+ * because stdout-path isn't valid, or because we have
+ * no driver for the device or our driver doesn't call
+ * of_console_check(). See printk_late_init() for this
+ * fallback.
+ */
+ if (!of_fallback_console)
+ of_fallback_console = newcon;
+ } else if (newcon->setup == NULL ||
newcon->setup(newcon, NULL) == 0) {
newcon->flags |= CON_ENABLED;
if (newcon->device) {
@@ -2844,6 +2868,22 @@ static int __init printk_late_init(void)
{
struct console *con;

+ if (of_specified_console && of_fallback_console &&
+ (!console_drivers || !(console_drivers->flags & CON_CONSDEV))) {
+ /*
+ * The system has a device tree which specified stdout-path,
+ * but we haven't seen a console associated with the device
+ * specified by the stdout-path chosen node property.
+ *
+ * We do however know which console would have been used
+ * if stdout-path weren't specified at all, so in an attempt
+ * to provide some output we'll re-register that console
+ * pretending that we never saw stdout-path.
+ */
+ clear_of_specified_console();
+ register_console(of_fallback_console);
+ }
+
for_each_console(con) {
if (!keep_bootcon && con->flags & CON_BOOT) {
/*
--
2.10.2

2016-11-03 13:04:25

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v2] console: use first console if stdout-path device doesn't appear

On Monday, 31 October 2016 18:31:43 GMT Larry Finger wrote:
> On 10/31/2016 06:09 PM, Sergey Senozhatsky wrote:
> > Hi,
> >
> > On (10/31/16 15:50), Paul Burton wrote:
> > [..]
> >
> >> Actually whilst this fixes the output in QEMU it has other problems. I'm
> >> still digging...
> >
> > I propose a revert of '05fd007e46296', so you guys can find the
> > problem and fix it, not being under 'rc3' pressure.
>
> If we were at -rc4 or -rc5, then I would agree; however, I think there is
> still time to fix the problem.
>
> Larry

Hi Larry et al,

If you could give the v3 I just submitted a try that would be great:

https://patchwork.kernel.org/patch/9410849/

If it still doesn't work for you then we're back to a place where I can't test
an affected system, since QEMU pseries now works fine with my patch. Would you
perhaps be able to get some console output by specifying console=<whatever> on
the kernel command line? Doing that ought to be unaffected by 05fd007e4629
("console: don't prefer first registered if DT specifies stdout-path") and
could be a way to get us some debug output.

Thanks,
Paul


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-11-03 17:41:50

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

On (11/03/16 12:57), Paul Burton wrote:
> If a device tree specified a preferred device for kernel console output
> via the stdout-path or linux,stdout-path chosen node properties there's
> no guarantee that it will have specified a device for which we have a
> driver. It may also be the case that we do have a driver but it doesn't
> call of_console_check() to register as a preferred console (eg. offb
> driver as used on powermac systems).

so why that driver doesn't call of_console_check() then? if there is a
misconfiguration then why do we want to fix it/fallback in printk code?

[..]
> @@ -260,10 +260,18 @@ void console_set_by_of(void)
> {
> of_specified_console = true;
> }
> +
> +static void clear_of_specified_console(void)
> +{
> + of_specified_console = false;
> +}
> #else
> # define of_specified_console false
> +static void clear_of_specified_console(void) { }
> #endif
>
> +struct console *of_fallback_console;
> +
> /* Flag: console code may call schedule() */
> static int console_may_schedule;
>
> @@ -2657,10 +2665,26 @@ void register_console(struct console *newcon)
> * didn't select a console we take the first one
> * that registers here.
> */
> - if (preferred_console < 0 && !of_specified_console) {
> + if (preferred_console < 0) {
> if (newcon->index < 0)
> newcon->index = 0;
> - if (newcon->setup == NULL ||
> + if (of_specified_console) {
> + /*
> + * The device tree stdout-path chosen node property was
> + * specified so we don't want to enable the first
> + * registered console just now in order to give the
> + * device indicated by stdout-path a chance to be
> + * registered first. Do however keep track of the
> + * first console we see so that we can fall back to
> + * using it if we don't see the desired device, either
> + * because stdout-path isn't valid, or because we have
> + * no driver for the device or our driver doesn't call
> + * of_console_check(). See printk_late_init() for this
> + * fallback.

if the path is not valid then correct the path. no?

> + */
> + if (!of_fallback_console)
> + of_fallback_console = newcon;
> + } else if (newcon->setup == NULL ||
> newcon->setup(newcon, NULL) == 0) {
> newcon->flags |= CON_ENABLED;
> if (newcon->device) {
> @@ -2844,6 +2868,22 @@ static int __init printk_late_init(void)
> {
> struct console *con;
>
> + if (of_specified_console && of_fallback_console &&
> + (!console_drivers || !(console_drivers->flags & CON_CONSDEV))) {
> + /*
> + * The system has a device tree which specified stdout-path,
> + * but we haven't seen a console associated with the device
> + * specified by the stdout-path chosen node property.
> + *
> + * We do however know which console would have been used
> + * if stdout-path weren't specified at all, so in an attempt
> + * to provide some output we'll re-register that console
> + * pretending that we never saw stdout-path.
> + */

DT screwed up, so why would printk() care? does any other
sub-system/driver fixes up a DT misconfiguration?

-ss

> + clear_of_specified_console();
> + register_console(of_fallback_console);
> + }
> +
> for_each_console(con) {
> if (!keep_bootcon && con->flags & CON_BOOT) {
> /*
> --
> 2.10.2
>

2016-11-03 21:18:08

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

Hi Sergey,

On Friday, 4 November 2016 02:40:40 GMT Sergey Senozhatsky wrote:
> On (11/03/16 12:57), Paul Burton wrote:
> > If a device tree specified a preferred device for kernel console output
> > via the stdout-path or linux,stdout-path chosen node properties there's
> > no guarantee that it will have specified a device for which we have a
> > driver. It may also be the case that we do have a driver but it doesn't
> > call of_console_check() to register as a preferred console (eg. offb
> > driver as used on powermac systems).
>
> so why that driver doesn't call of_console_check() then? if there is a
> misconfiguration then why do we want to fix it/fallback in printk code?

Ideally I think the driver (or perhaps fbdev/fbcon) ought to call
of_console_check() which would allow the console to be enabled earlier again.
However there isn't any single place I can see that currently has all the
information required to do so - the device tree node, the name & index of the
console.

Even if we change that in the future & do call of_console_check(), I can't
guarantee that offb is the only driver that would encounter this case, and it
still wouldn't cover the case of us not having any driver for the specified
stdout-path device. The fallback thus seems like a sensible thing to do.

>
> [..]
>
> > @@ -260,10 +260,18 @@ void console_set_by_of(void)
> >
> > {
> >
> > of_specified_console = true;
> >
> > }
> >
> > +
> > +static void clear_of_specified_console(void)
> > +{
> > + of_specified_console = false;
> > +}
> >
> > #else
> > # define of_specified_console false
> >
> > +static void clear_of_specified_console(void) { }
> >
> > #endif
> >
> > +struct console *of_fallback_console;
> > +
> >
> > /* Flag: console code may call schedule() */
> > static int console_may_schedule;
> >
> > @@ -2657,10 +2665,26 @@ void register_console(struct console *newcon)
> >
> > * didn't select a console we take the first one
> > * that registers here.
> > */
> >
> > - if (preferred_console < 0 && !of_specified_console) {
> > + if (preferred_console < 0) {
> >
> > if (newcon->index < 0)
> >
> > newcon->index = 0;
> >
> > - if (newcon->setup == NULL ||
> > + if (of_specified_console) {
> > + /*
> > + * The device tree stdout-path chosen node property was
> > + * specified so we don't want to enable the first
> > + * registered console just now in order to give the
> > + * device indicated by stdout-path a chance to be
> > + * registered first. Do however keep track of the
> > + * first console we see so that we can fall back to
> > + * using it if we don't see the desired device, either
> > + * because stdout-path isn't valid, or because we have
> > + * no driver for the device or our driver doesn't call
> > + * of_console_check(). See printk_late_init() for this
> > + * fallback.
>
> if the path is not valid then correct the path. no?

...but what if the path is valid and we simply don't have a driver for the
device it references? As I said in that comment we may not have a driver at
all.

>
> > + */
> > + if (!of_fallback_console)
> > + of_fallback_console = newcon;
> > + } else if (newcon->setup == NULL ||
> >
> > newcon->setup(newcon, NULL) == 0) {
> >
> > newcon->flags |= CON_ENABLED;
> > if (newcon->device) {
> >
> > @@ -2844,6 +2868,22 @@ static int __init printk_late_init(void)
> >
> > {
> >
> > struct console *con;
> >
> > + if (of_specified_console && of_fallback_console &&
> > + (!console_drivers || !(console_drivers->flags & CON_CONSDEV))) {
> > + /*
> > + * The system has a device tree which specified stdout-path,
> > + * but we haven't seen a console associated with the device
> > + * specified by the stdout-path chosen node property.
> > + *
> > + * We do however know which console would have been used
> > + * if stdout-path weren't specified at all, so in an attempt
> > + * to provide some output we'll re-register that console
> > + * pretending that we never saw stdout-path.
> > + */
>
> DT screwed up, so why would printk() care? does any other
> sub-system/driver fixes up a DT misconfiguration?
>
> -ss

...and again, it may not be a misconfiguration - that's one possibility of a
few that I mentioned. Even if the DT is misconfigured & stdout-path is
completely bonkers it's still arguable that falling back to the first console
registered (ie. our previous behaviour) is the sensible thing to do. Perhaps
we ought to warn in such cases, but even then we can't distinguish between the
3 cases I mentioned (invalid stdout-path, driver which doesn't call
of_console_check() or no driver at all) so we'd certainly end up warning on
systems like these affected PowerPC systems, which makes me think that may be
a better warning to introduce once we expect systems to not hit it.

Thanks,
Paul

>
> > + clear_of_specified_console();
> > + register_console(of_fallback_console);
> > + }
> > +
> >
> > for_each_console(con) {
> >
> > if (!keep_bootcon && con->flags & CON_BOOT) {
> >
> > /*


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-11-04 08:05:57

by Andreas Schwab

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

On Nov 03 2016, Paul Burton <[email protected]> wrote:

> If a device tree specified a preferred device for kernel console output
> via the stdout-path or linux,stdout-path chosen node properties there's
> no guarantee that it will have specified a device for which we have a
> driver. It may also be the case that we do have a driver but it doesn't
> call of_console_check() to register as a preferred console (eg. offb
> driver as used on powermac systems).
>
> In these cases try to ensure that we provide some console output by
> enabling the first usable registered console, which we keep track of
> with the of_fallback_console variable. Affected systems will enable
> their console later than they did prior to commit 05fd007e4629
> ("console: don't prefer first registered if DT specifies stdout-path")
> but should otherwise produce the same output.
>
> Tested in QEMU with a PowerPC pseries_defconfig kernel.

Unfortunately, that still doesn't work on PowerMac.

Andreas.

--
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."

2016-11-04 15:46:02

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

Hi Paul,

On (11/03/16 21:17), Paul Burton wrote:
> > [..]
> > > + * The device tree stdout-path chosen node property was
> > > + * specified so we don't want to enable the first
> > > + * registered console just now in order to give the
> > > + * device indicated by stdout-path a chance to be
> > > + * registered first. Do however keep track of the
> > > + * first console we see so that we can fall back to
> > > + * using it if we don't see the desired device, either
> > > + * because stdout-path isn't valid, or because we have
> > > + * no driver for the device or our driver doesn't call
> > > + * of_console_check(). See printk_late_init() for this
> > > + * fallback.
> >
> > if the path is not valid then correct the path. no?
>
> ...but what if the path is valid and we simply don't have a driver for the
> device it references? As I said in that comment we may not have a driver at
> all.

well, I suppose, in this case normally one would go and enable the
missing .config option. no?

-ss

2016-11-07 09:18:16

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

On Monday, 7 November 2016 19:27:32 GMT Michael Ellerman wrote:
> Paul Burton <[email protected]> writes:
> > If a device tree specified a preferred device for kernel console output
> > via the stdout-path or linux,stdout-path chosen node properties there's
> > no guarantee that it will have specified a device for which we have a
> > driver. It may also be the case that we do have a driver but it doesn't
> > call of_console_check() to register as a preferred console (eg. offb
> > driver as used on powermac systems).
> >
> > In these cases try to ensure that we provide some console output by
> > enabling the first usable registered console, which we keep track of
> > with the of_fallback_console variable. Affected systems will enable
> > their console later than they did prior to commit 05fd007e4629
> > ("console: don't prefer first registered if DT specifies stdout-path")
> > but should otherwise produce the same output.
> >
> > Tested in QEMU with a PowerPC pseries_defconfig kernel.
>
> Hi Paul,
>
> This does "work", as in it boots and I get a console. But the delay in
> getting output on the VGA is not workable. I get pretty much no output
> until the machine is booted entirely to userspace, meaning any crash
> prior to that will be undebuggable.
>
> I also note Andreas reports it doesn't work at all on PowerMac.
>
> Please send a revert and we can try again next cycle.
>
> cheers

Hi Michael,

A revert was already submitted by Hans de Goede & is being discussed over
here:

https://marc.info/?l=linux-kernel&m=147826151427455&w=2

Thanks,
Paul


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-11-07 15:26:42

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

On 11/07/2016 03:18 AM, Paul Burton wrote:
> On Monday, 7 November 2016 19:27:32 GMT Michael Ellerman wrote:
>> Paul Burton <[email protected]> writes:
>>> If a device tree specified a preferred device for kernel console output
>>> via the stdout-path or linux,stdout-path chosen node properties there's
>>> no guarantee that it will have specified a device for which we have a
>>> driver. It may also be the case that we do have a driver but it doesn't
>>> call of_console_check() to register as a preferred console (eg. offb
>>> driver as used on powermac systems).
>>>
>>> In these cases try to ensure that we provide some console output by
>>> enabling the first usable registered console, which we keep track of
>>> with the of_fallback_console variable. Affected systems will enable
>>> their console later than they did prior to commit 05fd007e4629
>>> ("console: don't prefer first registered if DT specifies stdout-path")
>>> but should otherwise produce the same output.
>>>
>>> Tested in QEMU with a PowerPC pseries_defconfig kernel.
>>
>> Hi Paul,
>>
>> This does "work", as in it boots and I get a console. But the delay in
>> getting output on the VGA is not workable. I get pretty much no output
>> until the machine is booted entirely to userspace, meaning any crash
>> prior to that will be undebuggable.
>>
>> I also note Andreas reports it doesn't work at all on PowerMac.
>>
>> Please send a revert and we can try again next cycle.
>>
>> cheers
>
> Hi Michael,
>
> A revert was already submitted by Hans de Goede & is being discussed over
> here:
>
> https://marc.info/?l=linux-kernel&m=147826151427455&w=2

I am a little surprised that I was not CCd on that thread. To reiterate, my
PowerBook G4 with a PPC32 processor CRASHES on boot. That is a lot more serious
than the console output disappearing.

As it seems unlikely that this regression will be fixed in the current cycle, I
recommend that the reversion of commit 05fd007e4629 until a proper fix is available.

Larry


2016-11-07 17:21:54

by Paul Burton

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

Hi Larry,

On Monday, 7 November 2016 09:26:37 GMT Larry Finger wrote:
> > A revert was already submitted by Hans de Goede & is being discussed over
> > here:
> >
> > https://marc.info/?l=linux-kernel&m=147826151427455&w=2
>
> I am a little surprised that I was not CCd on that thread.

Hans started that thread without copying you just as you started your thread
without copying Andreas, who reported issues first.

> To reiterate, my
> PowerBook G4 with a PPC32 processor CRASHES on boot. That is a lot more
> serious than the console output disappearing.

Crashes as in init dies due to lack of a console, right?

> As it seems unlikely that this regression will be fixed in the current
> cycle, I recommend that the reversion of commit 05fd007e4629 until a proper
> fix is available.

I agree that reverting is probably the best option for now, and have replied
with that in the other thread too.

Thanks,
Paul


Attachments:
signature.asc (801.00 B)
This is a digitally signed message part.

2016-11-07 18:27:51

by Larry Finger

[permalink] [raw]
Subject: Re: [PATCH v3] console: use first console if stdout-path device doesn't appear

On 11/07/2016 11:21 AM, Paul Burton wrote:
> Hi Larry,
>
> On Monday, 7 November 2016 09:26:37 GMT Larry Finger wrote:
>>> A revert was already submitted by Hans de Goede & is being discussed over
>>> here:
>>>
>>> https://marc.info/?l=linux-kernel&m=147826151427455&w=2
>>
>> I am a little surprised that I was not CCd on that thread.
>
> Hans started that thread without copying you just as you started your thread
> without copying Andreas, who reported issues first.

My searching had failed to find his report.

>> To reiterate, my
>> PowerBook G4 with a PPC32 processor CRASHES on boot. That is a lot more
>> serious than the console output disappearing.
>
> Crashes as in init dies due to lack of a console, right?

It gets a kernel panic because of an attempt to kill process 1 (init). It then
waits 120 seconds and tries to reboot.

>> As it seems unlikely that this regression will be fixed in the current
>> cycle, I recommend that the reversion of commit 05fd007e4629 until a proper
>> fix is available.
>
> I agree that reverting is probably the best option for now, and have replied
> with that in the other thread too.

Good.

Larry

2016-11-08 13:22:27

by Sergey Senozhatsky

[permalink] [raw]
Subject: revert 05fd007e46296afb (was: [PATCH v3] console: use first console if stdout-path device doesn't appear)

Hello Andrew,


(just in case)

please revert 'commit 05fd007e46296afb24 ("console: don't prefer first
registered if DT specifies stdout-path")'

-ss