linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: dianders@chromium.org (Doug Anderson)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: samsung: avoid racy early printk at bootup
Date: Tue,  4 Jun 2013 18:58:59 -0700	[thread overview]
Message-ID: <1370397539-21653-1-git-send-email-dianders@chromium.org> (raw)

At boot, we've got a stack trace that looks something like this
(exynos5 as example)
* exynos5_map_io
* s3c_init_cpu
* exynos_init_io
* exynos5_dt_map_io
* paging_init
* setup_arch

When paging_init() runs we'll lose any early MMU mappings that we
might have had to allow us access to S3C_VA_UART.  We won't add those
mappings back in until after the SoC-specific map_io() function is
called.  However, we print the CPU ID _right before_ we call the
SoC-specific function.  Oops.

Things happen to work all right most of the time because the mapping
is sticking around in our TLB.  ...but if we get really unlucky (like
me!) or we put an explicit flush_tlb_all() at the start of
exynos_init_io(), then things go boom.

This patch moves the problematic printk() till after the cpu->map_io()
call.  It also switches it over to pr_info().  This patch _doesn't_
remove the questionable printks in the panic case, since we might get
lucky and the TLB might still let us print.  This patch also adds a
few warnings to help others avoid similar headaches.

Signed-off-by: Doug Anderson <dianders@chromium.org>
---
 arch/arm/mach-exynos/common.c | 7 +++++++
 arch/arm/plat-samsung/init.c  | 8 +++++---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-exynos/common.c b/arch/arm/mach-exynos/common.c
index 027c9e7..8b51b0d 100644
--- a/arch/arm/mach-exynos/common.c
+++ b/arch/arm/mach-exynos/common.c
@@ -386,6 +386,13 @@ int __init exynos_fdt_map_chipid(unsigned long node, const char *uname,
 
 void __init exynos_init_io(struct map_desc *mach_desc, int size)
 {
+	/*
+	 * WARNING: use of printk in this function or its children can be
+	 * deadly.  We've switched over to new page tables but haven't yet
+	 * added S3C_VA_UART into the mapping.  You might get lucky and see a
+	 * printout work, but if you call flush_tlb_all() it will fail reliably.
+	 */
+
 #ifdef CONFIG_OF
 	if (initial_boot_params)
 		of_scan_flat_dt(exynos_fdt_map_chipid, NULL);
diff --git a/arch/arm/plat-samsung/init.c b/arch/arm/plat-samsung/init.c
index 79d10fc..494cfbb 100644
--- a/arch/arm/plat-samsung/init.c
+++ b/arch/arm/plat-samsung/init.c
@@ -49,18 +49,20 @@ void __init s3c_init_cpu(unsigned long idcode,
 	cpu = s3c_lookup_cpu(idcode, cputab, cputab_size);
 
 	if (cpu == NULL) {
+		/* Questionable printk; S3C_VA_UART not mapped yet! */
 		printk(KERN_ERR "Unknown CPU type 0x%08lx\n", idcode);
 		panic("Unknown S3C24XX CPU");
 	}
-
-	printk("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
-
 	if (cpu->map_io == NULL || cpu->init == NULL) {
+		/* Questionable printk; S3C_VA_UART not mapped yet! */
 		printk(KERN_ERR "CPU %s support not enabled\n", cpu->name);
 		panic("Unsupported Samsung CPU");
 	}
 
 	cpu->map_io();
+
+	/* IMPORTANT: call this after cpu->map_io() so we can print reliably */
+	pr_info("CPU %s (id 0x%08lx)\n", cpu->name, idcode);
 }
 
 /* s3c24xx_init_clocks
-- 
1.8.3

             reply	other threads:[~2013-06-05  1:58 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-05  1:58 Doug Anderson [this message]
2013-06-05  3:15 ` [PATCH] ARM: samsung: avoid racy early printk at bootup Olof Johansson
2013-06-05 20:56   ` Doug Anderson
2013-06-05 20:56 ` [PATCH v2] ARM: exynos: add debug_ll_io_init() call in exynos_init_io() Doug Anderson
2013-06-05 21:12   ` Olof Johansson
2013-06-05 23:32     ` Kukjin Kim
2013-06-08  1:12       ` Olof Johansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370397539-21653-1-git-send-email-dianders@chromium.org \
    --to=dianders@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).