Skip to contentSkip to conversation

UML: Support lockdep on x86-64 UML

RFC PATCH New Paul Menage 1 participant 6 messages Jun 16, 2009 User-mode Linux (UML)

lore
Share & tools
lore
#0 lore raw

cover UML: Support lockdep on x86-64 UML

The following series provides the basic support for lockdep on UML running on x86-64, and fixes a few lockdep-generated warnings.

It's not yet sufficient to properly use lockdep yet - currently lockdep disables itself with the stacktrace/warning below; presumably there's a point in the UML code where an unblock_signals() call needs to be accompanied by a trace_hardirqs_off(), but I'm not familiar enough with the UML code to figure out which one(s). Any suggestions from those more familiar with either lockdep or UML would be welcome.

 [<0000000060025e3d>] show_trace+0x61/0x78
 [<0000000060025f64>] dump_stack+0x22/0x2e
 [<0000000060043192>] warn_slowpath_common+0x66/0x90
 [<00000000600431ce>] warn_slowpath_null+0x12/0x14
 [<00000000600648c3>] check_flags+0xbb/0x1c0
 [<0000000060069dcc>] lock_acquire+0x61/0xd9
 [<0000000060082236>] find_get_page+0x47/0xb1
 [<0000000060082539>] find_lock_page+0x25/0x77
 [<0000000060082ed9>] find_or_create_page+0x3c/0xa8
 [<00000000600cdca3>] __getblk+0x144/0x25e
 [<0000000060119025>] jread+0x13c/0x24c
 [<00000000601191a8>] do_one_pass+0x73/0x4b9
 [<00000000601196c3>] journal_recover+0x54/0xf1
 [<000000006011c159>] journal_load+0x59/0xa5
 [<0000000060109eec>] ext3_fill_super+0x10c7/0x1884
 [<00000000600ad64a>] get_sb_bdev+0x123/0x175
 [<00000000601068f2>] ext3_get_sb+0x12/0x14
 [<00000000600ac475>] vfs_kern_mount+0x5d/0xae
 [<00000000600ac52e>] do_kern_mount+0x52/0x103
 [<00000000600c476e>] do_mount+0x7ca/0x861
 [<00000000600c4894>] sys_mount+0x8f/0xeb
 [<00000000600129f3>] mount_block_root+0xf8/0x2d3
 [<0000000060012c1e>] mount_root+0x50/0x57
 [<0000000060012d47>] prepare_namespace+0x122/0x14d
 [<00000000600121f2>] kernel_init+0x10f/0x120
 [<000000006003443d>] run_kernel_thread+0x41/0x4a
 [<0000000060024c9d>] new_thread_handler+0x7f/0xb2
 [<ffffffffffffffff>] 0xffffffffffffffff
---[ end trace ee4fa9a354ebc0b4 ]---
possible reason: unannotated irqs-on.
irq event stamp: 29900
hardirqs last  enabled at (29899): [<00000000600a87a5>] kmem_cache_alloc+0xa0/0x10b
hardirqs last disabled at (29900): [<00000000600240a3>] sigio_handler+0x18/0x76
softirqs last  enabled at (19414): [<00000000601c1706>] xfrm_state_unlock_afinfo+0xe/0x10
softirqs last disabled at (19412): [<00000000601d0cda>] _write_lock_bh+0x13/0x77

---

Paul Menage (5):
UML: Remove sigio_lock()/sigio_unlock() lockdep warnings
UML: Avoid lockdep issues during initialization
UML: Enable CONFIG_STACKTRACE_SUPPORT
UML: Enable CONFIG_TRACE_IRQFLAGS_SUPPORT
UML: Fix some apparent bitrot

 arch/um/Kconfig.common             |    4 +-
 arch/um/drivers/slip_kern.c        |    1 -
 arch/um/drivers/slirp_kern.c       |    1 -
 arch/um/include/asm/dma-mapping.h  |    4 +-
 arch/um/include/asm/system.h       |   39 ++++++++++++---------
 arch/um/include/shared/as-layout.h |    4 +-
 arch/um/include/shared/sigio.h     |    4 +-
 arch/um/kernel/Makefile            |    1 +
 arch/um/kernel/irq.c               |    1 +
 arch/um/kernel/process.c           |    1 -
 arch/um/kernel/sigio.c             |    8 ++--
 arch/um/kernel/skas/process.c      |   28 ++++++++++++++-
 arch/um/kernel/stacktrace.c        |   68 ++++++++++++++++++++++++++++++++++++
 arch/um/kernel/sysrq.c             |   20 +++++++++++
 arch/um/kernel/um_arch.c           |   20 -----------
 arch/um/os-Linux/sigio.c           |   55 +++++++++++++++--------------
 16 files changed, 179 insertions(+), 80 deletions(-)
 create mode 100644 arch/um/kernel/stacktrace.c

------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw

PATCH 1/5 UML: Fix some apparent bitrot

UML: Fix some apparent bitrot

- migration of net_device methods into net_device_ops
- address space layout changes
- dma_sync_single() changes

---

 arch/um/drivers/slip_kern.c        |    1 -
 arch/um/drivers/slirp_kern.c       |    1 -
 arch/um/include/asm/dma-mapping.h  |    4 ++--
 arch/um/include/shared/as-layout.h |    4 +---
 4 files changed, 3 insertions(+), 7 deletions(-)
arch/um/drivers/slip_kern.c +0 -1
index 5ec1756..dd2aadc 100644
@@ -30,7 +30,6 @@ static void slip_init(struct net_device *dev, void *data)
 
 	slip_proto_init(&spri->slip);
 
-	dev->init = NULL;
 	dev->hard_header_len = 0;
 	dev->header_ops = NULL;
 	dev->addr_len = 0;
arch/um/drivers/slirp_kern.c +0 -1
index f15a6e7..e376284 100644
@@ -32,7 +32,6 @@ void slirp_init(struct net_device *dev, void *data)
 
 	slip_proto_init(&spri->slip);
 
-	dev->init = NULL;
 	dev->hard_header_len = 0;
 	dev->header_ops = NULL;
 	dev->addr_len = 0;
arch/um/include/asm/dma-mapping.h +2 -2
index 90fc708..378de4b 100644
@@ -79,14 +79,14 @@ dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nhwentries,
 }
 
 static inline void
-dma_sync_single(struct device *dev, dma_addr_t dma_handle, size_t size,
+dma_sync_single_for_cpu(struct device *dev, dma_addr_t dma_handle, size_t size,
 		enum dma_data_direction direction)
 {
 	BUG();
 }
 
 static inline void
-dma_sync_sg(struct device *dev, struct scatterlist *sg, int nelems,
+dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, int nelems,
 	    enum dma_data_direction direction)
 {
 	BUG();
arch/um/include/shared/as-layout.h +1 -3
index a92b678..05e4573 100644
@@ -52,9 +52,7 @@ extern unsigned long end_vm;
 extern unsigned long start_vm;
 extern unsigned long long highmem;
 
-extern unsigned long _stext, _etext, _sdata, _edata, __bss_start, _end;
-extern unsigned long _unprotected_end;
-extern unsigned long brk_start;
+extern unsigned long _end;
 
 extern unsigned long host_task_size;
 

------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw

PATCH 2/5 UML: Enable CONFIG_TRACE_IRQFLAGS_SUPPORT

In reply to Paul Menage

UML: Enable CONFIG_TRACE_IRQFLAGS_SUPPORT

---

 arch/um/Kconfig.common        |    2 +-
 arch/um/include/asm/system.h  |   39 ++++++++++++++++++++++-----------------
 arch/um/kernel/irq.c          |    1 +
 arch/um/kernel/process.c      |    1 -
 arch/um/kernel/skas/process.c |    2 +-
 5 files changed, 25 insertions(+), 20 deletions(-)
arch/um/Kconfig.common +1 -1
index 0d207e7..8a54ae4 100644
@@ -36,7 +36,7 @@ config PCMCIA
 # Yet to do!
 config TRACE_IRQFLAGS_SUPPORT
 	bool
-	default n
+	default y
 
 config LOCKDEP_SUPPORT
 	bool
arch/um/include/asm/system.h +22 -17
index 753346e..dd76c29 100644
@@ -11,23 +11,28 @@ extern int get_signals(void);
 extern void block_signals(void);
 extern void unblock_signals(void);
 
-#define local_save_flags(flags) do { typecheck(unsigned long, flags); \
-				     (flags) = get_signals(); } while(0)
-#define local_irq_restore(flags) do { typecheck(unsigned long, flags); \
-				      set_signals(flags); } while(0)
-
-#define local_irq_save(flags) do { local_save_flags(flags); \
-                                   local_irq_disable(); } while(0)
-
-#define local_irq_enable() unblock_signals()
-#define local_irq_disable() block_signals()
-
-#define irqs_disabled()                 \
-({                                      \
-        unsigned long flags;            \
-        local_save_flags(flags);        \
-        (flags == 0);                   \
-})
+#define raw_local_save_flags(flags) do { typecheck(unsigned long, flags); \
+					 (flags) = get_signals(); } while (0)
+#define raw_local_irq_restore(flags) do { typecheck(unsigned long, flags); \
+					  set_signals(flags); } while (0)
+
+#define raw_local_irq_save(flags) do { raw_local_save_flags(flags); \
+				       raw_local_irq_disable(); } while (0)
+
+#define raw_local_irq_enable() unblock_signals()
+#define raw_local_irq_disable() block_signals()
+
+static inline int raw_irqs_disabled_flags(unsigned long flags)
+{
+	return (flags == 0);
+}
+
+static inline int raw_irqs_disabled(void)
+{
+	unsigned long flags;
+	raw_local_save_flags(flags);
+	return raw_irqs_disabled_flags(flags);
+}
 
 extern void *_switch_to(void *prev, void *next, void *last);
 #define switch_to(prev, next, last) prev = _switch_to(prev, next, last)
arch/um/kernel/irq.c +1 -0
index 454cdb4..f7374a2 100644
@@ -80,6 +80,7 @@ void sigio_handler(int sig, struct uml_pt_regs *regs)
 	if (smp_sigio_handler())
 		return;
 
+	trace_hardirqs_off();
 	while (1) {
 		n = os_waiting_for_events(active_fds);
 		if (n <= 0) {
arch/um/kernel/process.c +0 -1
index 4a28a15..c55debf 100644
@@ -450,4 +450,3 @@ int elf_core_copy_fpregs(struct task_struct *t, elf_fpregset_t *fpu)
 
 	return save_fp_registers(userspace_pid[cpu], (unsigned long *) fpu);
 }
-
arch/um/kernel/skas/process.c +1 -1
index 2e9852c..4a21c5c 100644
@@ -35,7 +35,7 @@ static int __init start_kernel_proc(void *unused)
 {
 	int pid;
 
-	block_signals();
+	local_irq_disable();
 	pid = os_getpid();
 
 	cpu_tasks[0].pid = pid;

------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#3 lore raw

PATCH 3/5 UML: Enable CONFIG_STACKTRACE_SUPPORT

In reply to Paul Menage

UML: Enable CONFIG_STACKTRACE_SUPPORT

Adds a simple stacktrace function, only tested/enabled on X86

---

 arch/um/Kconfig.common      |    2 +
 arch/um/kernel/Makefile     |    1 +
 arch/um/kernel/stacktrace.c |   68 +++++++++++++++++++++++++++++++++++++++++++
 arch/um/kernel/sysrq.c      |   20 +++++++++++++
 4 files changed, 90 insertions(+), 1 deletions(-)
 create mode 100644 arch/um/kernel/stacktrace.c
arch/um/Kconfig.common +1 -1
index 8a54ae4..b757c36 100644
@@ -44,7 +44,7 @@ config LOCKDEP_SUPPORT
 
 config STACKTRACE_SUPPORT
 	bool
-	default n
+	default UML_X86
 
 config GENERIC_CALIBRATE_DELAY
 	bool
arch/um/kernel/Makefile +1 -0
index 388ec0a..b1867a0 100644
@@ -14,6 +14,7 @@ obj-y = config.o exec.o exitcode.o init_task.o irq.o ksyms.o mem.o \
 obj-$(CONFIG_BLK_DEV_INITRD) += initrd.o
 obj-$(CONFIG_GPROF)	+= gprof_syms.o
 obj-$(CONFIG_GCOV)	+= gmon_syms.o
+obj-$(CONFIG_STACKTRACE_SUPPORT) += stacktrace.o
 
 USER_OBJS := config.o
 
arch/um/kernel/stacktrace.c new file +68 -0

68 lines not on this page · raw message

arch/um/kernel/sysrq.c +20 -0
index 56d43d0..42b832c 100644
@@ -11,6 +11,25 @@
 
 /* Catch non-i386 SUBARCH's. */
 #if !defined(CONFIG_UML_X86) || defined(CONFIG_64BIT)
+#ifdef CONFIG_STACKTRACE
+void show_trace(struct task_struct *task, unsigned long * stack)
+{
+	struct stack_trace trace;
+	unsigned long entries[64];
+
+	if (!stack) {
+		stack = (unsigned long *) &stack;
+		WARN_ON(1);
+	}
+
+	trace.nr_entries = 0;
+	trace.max_entries = ARRAY_SIZE(entries);
+	trace.entries = entries;
+	trace.skip = 0;
+	save_stack_trace(&trace);
+	print_stack_trace(&trace, 0);
+}
+#else
 void show_trace(struct task_struct *task, unsigned long * stack)
 {
 	unsigned long addr;
@@ -33,6 +52,7 @@ void show_trace(struct task_struct *task, unsigned long * stack)
 	}
 	printk(KERN_INFO "\n");
 }
+#endif  /& CONFIG_STACKTRACE */
 #endif
 
 /*

------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#4 lore raw

PATCH 4/5 UML: Avoid lockdep issues during initialization

In reply to Paul Menage

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.

---

 arch/um/kernel/skas/process.c |   26 ++++++++++++++++++++++++++
 arch/um/kernel/um_arch.c      |   20 --------------------
 2 files changed, 26 insertions(+), 20 deletions(-)
arch/um/kernel/skas/process.c +26 -0
index 4a21c5c..2b62a72 100644
@@ -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();
 
arch/um/kernel/um_arch.c +0 -20
index 8d84250..364c589 100644
@@ -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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#5 lore raw

PATCH 5/5 UML: Remove sigio_lock()/sigio_unlock() lockdep warnings

In reply to Paul Menage

UML: Remove sigio_lock()/sigio_unlock() lockdep warnings

When lockdep is enabled on UML, calls to sigio_lock() and sigio_unlock() trigger a lockdep warning since this function is called both from interrupt context and process context. This patch allows a "flags" argument to be passed to sigio_lock() and sigio_unlock() to allow them to use spin_lock_irqsave() and spin_unlock_irqrestore().

---

 arch/um/include/shared/sigio.h |    4 +--
 arch/um/kernel/sigio.c         |    8 +++---
 arch/um/os-Linux/sigio.c       |   55 +++++++++++++++++++++-------------------
 3 files changed, 35 insertions(+), 32 deletions(-)
arch/um/include/shared/sigio.h +2 -2
index 434f1a9..5b16047 100644
@@ -8,7 +8,7 @@
 
 extern int write_sigio_irq(int fd);
 extern int register_sigio_fd(int fd);
-extern void sigio_lock(void);
-extern void sigio_unlock(void);
+extern void sigio_lock(unsigned long *flags);
+extern void sigio_unlock(unsigned long flags);
 
 #endif
arch/um/kernel/sigio.c +4 -4
index 2b272b6..f258501 100644
@@ -39,12 +39,12 @@ int write_sigio_irq(int fd)
 /* These are called from os-Linux/sigio.c to protect its pollfds arrays. */
 static DEFINE_SPINLOCK(sigio_spinlock);
 
-void sigio_lock(void)
+void sigio_lock(unsigned long *flags)
 {
-	spin_lock(&sigio_spinlock);
+	spin_lock_irqsave(&sigio_spinlock, *flags);
 }
 
-void sigio_unlock(void)
+void sigio_unlock(unsigned long flags)
 {
-	spin_unlock(&sigio_spinlock);
+	spin_unlock_irqrestore(&sigio_spinlock, flags);
 }
arch/um/os-Linux/sigio.c +29 -26

140 lines not on this page · raw message

------------------------------------------------------------------------------
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 [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel