UML: Avoid lockdep issues during initialization

UML calls atomic_notifier_chain_register() very early during
initialization. When lockdep is in use, the spinlock operations thus
invoked make use of current_thread_info(), which isn't valid in UML
until start_kernel_proc() is reached (running on the init_thread_union
stack rather than the default stack at the top of the address space).

This patch moves the call to the beginning of start_kernel_proc(), and
additionally disables lock debugging for the duration of the call,
since lockdep_init() doesn't occur until start_kernel() is called.

Signed-off-by: Paul Menage <men...@google.com>

---

 arch/um/kernel/skas/process.c |   26 ++++++++++++++++++++++++++
 arch/um/kernel/um_arch.c      |   20 --------------------
 2 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/arch/um/kernel/skas/process.c b/arch/um/kernel/skas/process.c
index 4a21c5c..2b62a72 100644
--- a/arch/um/kernel/skas/process.c
+++ b/arch/um/kernel/skas/process.c
@@ -5,7 +5,9 @@
 
 #include "linux/init.h"
 #include "linux/sched.h"
+#include "linux/debug_locks.h"
 #include "as-layout.h"
+#include "shared/kern_util.h"
 #include "kern.h"
 #include "os.h"
 #include "skas.h"
@@ -31,10 +33,34 @@ int new_mm(unsigned long stack)
 
 extern void start_kernel(void);
 
+static int panic_exit(struct notifier_block *self, unsigned long unused1,
+                     void *unused2)
+{
+       bust_spinlocks(1);
+       show_regs(&(current->thread.regs));
+       bust_spinlocks(0);
+       uml_exitcode = 1;
+       os_dump_core();
+       return 0;
+}
+
+static struct notifier_block panic_exit_notifier = {
+       .notifier_call          = panic_exit,
+       .next                   = NULL,
+       .priority               = 0
+};
+
 static int __init start_kernel_proc(void *unused)
 {
        int pid;
 
+       /* lockdep hasn't yet been initialized, but this call takes
+        * spinlocks. Temporarily disable lock debugging */
+       int saved_debug_locks = debug_locks;
+       debug_locks = 0;
+       atomic_notifier_chain_register(&panic_notifier_list,
+                                      &panic_exit_notifier);
+       debug_locks = saved_debug_locks;
        local_irq_disable();
        pid = os_getpid();
 
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 8d84250..364c589 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -223,23 +223,6 @@ static void __init uml_postsetup(void)
        return;
 }
 
-static int panic_exit(struct notifier_block *self, unsigned long unused1,
-                     void *unused2)
-{
-       bust_spinlocks(1);
-       show_regs(&(current->thread.regs));
-       bust_spinlocks(0);
-       uml_exitcode = 1;
-       os_dump_core();
-       return 0;
-}
-
-static struct notifier_block panic_exit_notifier = {
-       .notifier_call          = panic_exit,
-       .next                   = NULL,
-       .priority               = 0
-};
-
 /* Set during early boot */
 unsigned long task_size;
 EXPORT_SYMBOL(task_size);
@@ -360,9 +343,6 @@ int __init linux_main(int argc, char **argv)
                printf("Kernel virtual memory size shrunk to %lu bytes\n",
                       virtmem_size);
 
-       atomic_notifier_chain_register(&panic_notifier_list,
-                                      &panic_exit_notifier);
-
        uml_postsetup();
 
        stack_protections((unsigned long) &init_thread_info);


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

Reply via email to