public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH RFC] Fix bug if earlyprintk is called twice
@ 2013-04-18 14:23 Gregory CLEMENT
  2013-04-18 14:23 ` [PATCH RFC] ARM: don't allow to register the early_console twice Gregory CLEMENT
  0 siblings, 1 reply; 3+ messages in thread
From: Gregory CLEMENT @ 2013-04-18 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

Hello,

If on the kernel command line the parameter "earlyprintk" is written
twice, then setup_early_printk is called twice. This can happen for
example with the option CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND is
selected, and the "earlyprintk" is passed from the ATAG_CMDLINE and
from the dtb.

This lead to an infinite loop on the message "Booting Linux on
physical CPU 0" displayed from smp_setup_processor_id() in
arch/arm/kernel/setup.c. This behavior as been reproduced on ARMv7
architecture (Armada XP and Armada 370), and on a ARMv5 one
(AT91SAMG35 thanks to Richard Genoud), with and with CONFIG_SMP
selected.

After some investigation I found that the problem happened when the
early_console is register for the second time in file kernel/printk.c
on line 2310 when the function console_lock() is called, and in this
function I managed to have traces until the call to down(&console_sem)
one line 1922. Keep in mind that I had this information using printk
so maybe it was not the best way to debug the console!

I didn't had other platform that ARM one for testing this behavior, so
I don't know if this bug is specific to ARM. If you think it is
something specific to ARM then I propose the patch in the following
email.

Any feedback on this issue would be welcome

Thanks,

Gregory CLEMENT (1):
  ARM: don't allow to register the early_console twice

 arch/arm/kernel/early_printk.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH RFC] ARM: don't allow to register the early_console twice
  2013-04-18 14:23 [PATCH RFC] Fix bug if earlyprintk is called twice Gregory CLEMENT
@ 2013-04-18 14:23 ` Gregory CLEMENT
  2013-04-18 15:04   ` Richard GENOUD
  0 siblings, 1 reply; 3+ messages in thread
From: Gregory CLEMENT @ 2013-04-18 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

If on the kernel command line the parameter "earlyprintk" is written
twice, then setup_early_printk is called twice. This can happen for
example with the option CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND is
selected, and the "earlyprintk" is passed from the ATAG_CMDLINE and
from the dtb.

This lead to an infinite loop on the message "Booting Linux on
physical CPU 0" displayed from smp_setup_processor_id() in
arch/arm/kernel/setup.c. This behavior as been reproduced on ARMv7
architecture (Armada XP and Armada 370), and on a ARMv5 one
(AT91SAMG35 thanks to Richard Genoud), with and with CONFIG_SMP
selected.

This patch simply doesn't allow to call twice register_console() with
the early_console.

Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
---
 arch/arm/kernel/early_printk.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/arm/kernel/early_printk.c b/arch/arm/kernel/early_printk.c
index 85aa2b2..435577a 100644
--- a/arch/arm/kernel/early_printk.c
+++ b/arch/arm/kernel/early_printk.c
@@ -50,7 +50,11 @@ asmlinkage void early_printk(const char *fmt, ...)
 
 static int __init setup_early_printk(char *buf)
 {
-	register_console(&early_console);
+	static int done;
+	if (!done) {
+		register_console(&early_console);
+		done = 1;
+	}
 	return 0;
 }
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH RFC] ARM: don't allow to register the early_console twice
  2013-04-18 14:23 ` [PATCH RFC] ARM: don't allow to register the early_console twice Gregory CLEMENT
@ 2013-04-18 15:04   ` Richard GENOUD
  0 siblings, 0 replies; 3+ messages in thread
From: Richard GENOUD @ 2013-04-18 15:04 UTC (permalink / raw)
  To: linux-arm-kernel

On [jeu., 18.04.2013 16:23:39], Gregory CLEMENT wrote:
> If on the kernel command line the parameter "earlyprintk" is written
> twice, then setup_early_printk is called twice. This can happen for
> example with the option CONFIG_ARM_ATAG_DTB_COMPAT_CMDLINE_EXTEND is
> selected, and the "earlyprintk" is passed from the ATAG_CMDLINE and
> from the dtb.
> 
> This lead to an infinite loop on the message "Booting Linux on
> physical CPU 0" displayed from smp_setup_processor_id() in
> arch/arm/kernel/setup.c. This behavior as been reproduced on ARMv7
> architecture (Armada XP and Armada 370), and on a ARMv5 one
> (AT91SAMG35 thanks to Richard Genoud), with and with CONFIG_SMP
> selected.
> 
> This patch simply doesn't allow to call twice register_console() with
> the early_console.
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
> ---
>  arch/arm/kernel/early_printk.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/kernel/early_printk.c b/arch/arm/kernel/early_printk.c
> index 85aa2b2..435577a 100644
> --- a/arch/arm/kernel/early_printk.c
> +++ b/arch/arm/kernel/early_printk.c
> @@ -50,7 +50,11 @@ asmlinkage void early_printk(const char *fmt, ...)
>  
>  static int __init setup_early_printk(char *buf)
>  {
> -	register_console(&early_console);
> +	static int done;
> +	if (!done) {
> +		register_console(&early_console);
> +		done = 1;
> +	}
>  	return 0;
>  }
>  
> -- 
> 1.7.9.5
Tested on at91sam9g35-ek kernel 3.9-rc7 +custom patches

Tested-by: Richard Genoud <richard.genoud@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-18 15:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-18 14:23 [PATCH RFC] Fix bug if earlyprintk is called twice Gregory CLEMENT
2013-04-18 14:23 ` [PATCH RFC] ARM: don't allow to register the early_console twice Gregory CLEMENT
2013-04-18 15:04   ` Richard GENOUD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox