Linux-csky Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH V2 0/3] riscv: Enable LOCKDEP
@ 2020-06-27 13:57 guoren
  2020-06-27 13:57 ` [PATCH V2 1/3] riscv: Fixup static_obj() fail guoren
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: guoren @ 2020-06-27 13:57 UTC (permalink / raw)
  To: palmerdabbelt, paul.walmsley, anup, greentime.hu, zong.li, aou,
	tglx, tycho, nickhu
  Cc: linux-riscv, linux-kernel, linux-csky, Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

Lockdep is needed by proving the spinlocks and rwlocks. To support it,
we need to add TRACE_IRQFLAGS codes in kernel/entry.S. These patches
follow Documentation/irqflags-tracing.txt.

Fixup 2 bugs that block the lockdep implementation.

---
Changes in v2
 - Remove sX regs recovery codes which are unnecessary, because
   callee will handle them. Thx Greentime :)

 - Move "restore a0 - a7" to handle_syscall, but if _TIF_SYSCALL_WORK
   is set, "restore a1 - a7" is still duplicated. I prefer a C wrapper
   for syscall.

Guo Ren (2):
  riscv: Fixup static_obj() fail
  riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT

Zong Li (1):
  riscv: Fixup lockdep_assert_held with wrong param cpu_running

 arch/riscv/Kconfig              |  3 +++
 arch/riscv/kernel/entry.S       | 33 ++++++++++++++++++++++++++++++++-
 arch/riscv/kernel/smpboot.c     |  1 -
 arch/riscv/kernel/vmlinux.lds.S |  2 +-
 4 files changed, 36 insertions(+), 3 deletions(-)

-- 
2.7.4


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

* [PATCH V2 1/3] riscv: Fixup static_obj() fail
  2020-06-27 13:57 [PATCH V2 0/3] riscv: Enable LOCKDEP guoren
@ 2020-06-27 13:57 ` guoren
  2020-06-27 13:57 ` [PATCH V2 2/3] riscv: Fixup lockdep_assert_held with wrong param cpu_running guoren
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2020-06-27 13:57 UTC (permalink / raw)
  To: palmerdabbelt, paul.walmsley, anup, greentime.hu, zong.li, aou,
	tglx, tycho, nickhu
  Cc: linux-riscv, linux-kernel, linux-csky, Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

When enable LOCKDEP, static_obj() will cause error. Because some
__initdata static variables is before _stext:

static int static_obj(const void *obj)
{
        unsigned long start = (unsigned long) &_stext,
                      end   = (unsigned long) &_end,
                      addr  = (unsigned long) obj;

        /*
         * static variable?
         */
        if ((addr >= start) && (addr < end))
                return 1;

[    0.067192] INFO: trying to register non-static key.
[    0.067325] the code is fine but needs lockdep annotation.
[    0.067449] turning off the locking correctness validator.
[    0.067718] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.7.0-rc7-dirty #44
[    0.067945] Call Trace:
[    0.068369] [<ffffffe00020323c>] walk_stackframe+0x0/0xa4
[    0.068506] [<ffffffe000203422>] show_stack+0x2a/0x34
[    0.068631] [<ffffffe000521e4e>] dump_stack+0x94/0xca
[    0.068757] [<ffffffe000255a4e>] register_lock_class+0x5b8/0x5bc
[    0.068969] [<ffffffe000255abe>] __lock_acquire+0x6c/0x1d5c
[    0.069101] [<ffffffe0002550fe>] lock_acquire+0xae/0x312
[    0.069228] [<ffffffe000989a8e>] _raw_spin_lock_irqsave+0x40/0x5a
[    0.069357] [<ffffffe000247c64>] complete+0x1e/0x50
[    0.069479] [<ffffffe000984c38>] rest_init+0x1b0/0x28a
[    0.069660] [<ffffffe0000016a2>] 0xffffffe0000016a2
[    0.069779] [<ffffffe000001b84>] 0xffffffe000001b84
[    0.069953] [<ffffffe000001092>] 0xffffffe000001092

static __initdata DECLARE_COMPLETION(kthreadd_done);

noinline void __ref rest_init(void)
{
	...
	complete(&kthreadd_done);

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
---
 arch/riscv/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/vmlinux.lds.S b/arch/riscv/kernel/vmlinux.lds.S
index e6f8016..f3586e3 100644
--- a/arch/riscv/kernel/vmlinux.lds.S
+++ b/arch/riscv/kernel/vmlinux.lds.S
@@ -22,6 +22,7 @@ SECTIONS
 	/* Beginning of code and text segment */
 	. = LOAD_OFFSET;
 	_start = .;
+	_stext = .;
 	HEAD_TEXT_SECTION
 	. = ALIGN(PAGE_SIZE);
 
@@ -54,7 +55,6 @@ SECTIONS
 	. = ALIGN(SECTION_ALIGN);
 	.text : {
 		_text = .;
-		_stext = .;
 		TEXT_TEXT
 		SCHED_TEXT
 		CPUIDLE_TEXT
-- 
2.7.4


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

* [PATCH V2 2/3] riscv: Fixup lockdep_assert_held with wrong param cpu_running
  2020-06-27 13:57 [PATCH V2 0/3] riscv: Enable LOCKDEP guoren
  2020-06-27 13:57 ` [PATCH V2 1/3] riscv: Fixup static_obj() fail guoren
@ 2020-06-27 13:57 ` guoren
  2020-06-27 13:57 ` [PATCH V2 3/3] riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT guoren
  2020-07-09 22:06 ` [PATCH V2 0/3] riscv: Enable LOCKDEP Palmer Dabbelt
  3 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2020-06-27 13:57 UTC (permalink / raw)
  To: palmerdabbelt, paul.walmsley, anup, greentime.hu, zong.li, aou,
	tglx, tycho, nickhu
  Cc: linux-riscv, linux-kernel, linux-csky, Guo Ren

From: Zong Li <zong.li@sifive.com>

The cpu_running is not a lock-class, it lacks the dep_map member in
completion. It causes the error as follow:

arch/riscv/kernel/smpboot.c: In function '__cpu_up':
./include/linux/lockdep.h:364:52: error: 'struct completion' has no member named 'dep_map'
  364 | #define lockdep_is_held(lock)  lock_is_held(&(lock)->dep_map)
      |                                                    ^~
./include/asm-generic/bug.h:113:25: note: in definition of macro 'WARN_ON'
  113 |  int __ret_warn_on = !!(condition);    \
      |                         ^~~~~~~~~
./include/linux/lockdep.h:390:27: note: in expansion of macro 'lockdep_is_held'
  390 |   WARN_ON(debug_locks && !lockdep_is_held(l)); \
      |                           ^~~~~~~~~~~~~~~
arch/riscv/kernel/smpboot.c:118:2: note: in expansion of macro 'lockdep_assert_held'
  118 |  lockdep_assert_held(&cpu_running);

There are a lot of archs which use cpu_running in smpboot.c (arm,
arm64, openrisc, xtensa, s390, x86, mips), but none of them try
lockdep_assert_held(&cpu_running.wait.lock). So Just remove it.

Signed-off-by: Zong Li <zong.li@sifive.com>
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
---
 arch/riscv/kernel/smpboot.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
index 4e99227..defc4e1 100644
--- a/arch/riscv/kernel/smpboot.c
+++ b/arch/riscv/kernel/smpboot.c
@@ -121,7 +121,6 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
 
 	ret = start_secondary_cpu(cpu, tidle);
 	if (!ret) {
-		lockdep_assert_held(&cpu_running);
 		wait_for_completion_timeout(&cpu_running,
 					    msecs_to_jiffies(1000));
 
-- 
2.7.4


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

* [PATCH V2 3/3] riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT
  2020-06-27 13:57 [PATCH V2 0/3] riscv: Enable LOCKDEP guoren
  2020-06-27 13:57 ` [PATCH V2 1/3] riscv: Fixup static_obj() fail guoren
  2020-06-27 13:57 ` [PATCH V2 2/3] riscv: Fixup lockdep_assert_held with wrong param cpu_running guoren
@ 2020-06-27 13:57 ` guoren
  2020-07-09 22:06 ` [PATCH V2 0/3] riscv: Enable LOCKDEP Palmer Dabbelt
  3 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2020-06-27 13:57 UTC (permalink / raw)
  To: palmerdabbelt, paul.walmsley, anup, greentime.hu, zong.li, aou,
	tglx, tycho, nickhu
  Cc: linux-riscv, linux-kernel, linux-csky, Guo Ren

From: Guo Ren <guoren@linux.alibaba.com>

Lockdep is needed by proving the spinlocks and rwlocks. To suupport
it, we need fixup TRACE_IRQFLAGS_SUPPORT in kernel/entry.S. This
patch follow Documentation/irqflags-tracing.txt.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Cc: Greentime Hu <greentime.hu@sifive.com>
---
 arch/riscv/Kconfig        |  3 +++
 arch/riscv/kernel/entry.S | 34 +++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 58d6f66..d5d5100 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -179,6 +179,9 @@ config PGTABLE_LEVELS
 	default 3 if 64BIT
 	default 2
 
+config LOCKDEP_SUPPORT
+	def_bool y
+
 source "arch/riscv/Kconfig.socs"
 
 menu "Platform type"
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index cae7e6d..45c81e4 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -97,19 +97,26 @@ _save_context:
 	la gp, __global_pointer$
 .option pop
 
-	la ra, ret_from_exception
+#ifdef CONFIG_TRACE_IRQFLAGS
+	call trace_hardirqs_off
+#endif
 	/*
 	 * MSB of cause differentiates between
 	 * interrupts and exceptions
 	 */
 	bge s4, zero, 1f
 
+	la ra, ret_from_exception
+
 	/* Handle interrupts */
 	move a0, sp /* pt_regs */
 	la a1, handle_arch_irq
 	REG_L a1, (a1)
 	jr a1
 1:
+#ifdef CONFIG_TRACE_IRQFLAGS
+	call trace_hardirqs_on
+#endif
 	/*
 	 * Exceptions run with interrupts enabled or disabled depending on the
 	 * state of SR_PIE in m/sstatus.
@@ -119,6 +126,7 @@ _save_context:
 	csrs CSR_STATUS, SR_IE
 
 1:
+	la ra, ret_from_exception
 	/* Handle syscalls */
 	li t0, EXC_SYSCALL
 	beq s4, t0, handle_syscall
@@ -137,6 +145,17 @@ _save_context:
 	tail do_trap_unknown
 
 handle_syscall:
+#ifdef CONFIG_TRACE_IRQFLAGS
+	/* Recover a0 - a7 for system calls */
+	REG_L a0, PT_A0(sp)
+	REG_L a1, PT_A1(sp)
+	REG_L a2, PT_A2(sp)
+	REG_L a3, PT_A3(sp)
+	REG_L a4, PT_A4(sp)
+	REG_L a5, PT_A5(sp)
+	REG_L a6, PT_A6(sp)
+	REG_L a7, PT_A7(sp)
+#endif
 	 /* save the initial A0 value (needed in signal handlers) */
 	REG_S a0, PT_ORIG_A0(sp)
 	/*
@@ -190,6 +209,9 @@ ret_from_syscall_rejected:
 ret_from_exception:
 	REG_L s0, PT_STATUS(sp)
 	csrc CSR_STATUS, SR_IE
+#ifdef CONFIG_TRACE_IRQFLAGS
+	call trace_hardirqs_off
+#endif
 #ifdef CONFIG_RISCV_M_MODE
 	/* the MPP value is too large to be used as an immediate arg for addi */
 	li t0, SR_MPP
@@ -216,6 +238,16 @@ resume_userspace:
 	csrw CSR_SCRATCH, tp
 
 restore_all:
+#ifdef CONFIG_TRACE_IRQFLAGS
+	REG_L s1, PT_STATUS(sp)
+	andi t0, s1, SR_PIE
+	beqz t0, 1f
+	call trace_hardirqs_on
+	j 2f
+1:
+	call trace_hardirqs_off
+2:
+#endif
 	REG_L a0, PT_STATUS(sp)
 	/*
 	 * The current load reservation is effectively part of the processor's
-- 
2.7.4


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

* Re: [PATCH V2 0/3] riscv: Enable LOCKDEP
  2020-06-27 13:57 [PATCH V2 0/3] riscv: Enable LOCKDEP guoren
                   ` (2 preceding siblings ...)
  2020-06-27 13:57 ` [PATCH V2 3/3] riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT guoren
@ 2020-07-09 22:06 ` Palmer Dabbelt
  2020-07-09 23:15   ` Guo Ren
  3 siblings, 1 reply; 6+ messages in thread
From: Palmer Dabbelt @ 2020-07-09 22:06 UTC (permalink / raw)
  To: guoren
  Cc: Paul Walmsley, anup, greentime.hu, zong.li, aou, tglx, tycho,
	nickhu, linux-riscv, linux-kernel, linux-csky, guoren

On Sat, 27 Jun 2020 06:57:05 PDT (-0700), guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
>
> Lockdep is needed by proving the spinlocks and rwlocks. To support it,
> we need to add TRACE_IRQFLAGS codes in kernel/entry.S. These patches
> follow Documentation/irqflags-tracing.txt.
>
> Fixup 2 bugs that block the lockdep implementation.
>
> ---
> Changes in v2
>  - Remove sX regs recovery codes which are unnecessary, because
>    callee will handle them. Thx Greentime :)
>
>  - Move "restore a0 - a7" to handle_syscall, but if _TIF_SYSCALL_WORK
>    is set, "restore a1 - a7" is still duplicated. I prefer a C wrapper
>    for syscall.
>
> Guo Ren (2):
>   riscv: Fixup static_obj() fail
>   riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT
>
> Zong Li (1):
>   riscv: Fixup lockdep_assert_held with wrong param cpu_running
>
>  arch/riscv/Kconfig              |  3 +++
>  arch/riscv/kernel/entry.S       | 33 ++++++++++++++++++++++++++++++++-
>  arch/riscv/kernel/smpboot.c     |  1 -
>  arch/riscv/kernel/vmlinux.lds.S |  2 +-
>  4 files changed, 36 insertions(+), 3 deletions(-)

These are on for-next.  As far as I can tell lockdep is working, but I'm just
doing some simple boot tests.

Thanks!

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

* Re: [PATCH V2 0/3] riscv: Enable LOCKDEP
  2020-07-09 22:06 ` [PATCH V2 0/3] riscv: Enable LOCKDEP Palmer Dabbelt
@ 2020-07-09 23:15   ` Guo Ren
  0 siblings, 0 replies; 6+ messages in thread
From: Guo Ren @ 2020-07-09 23:15 UTC (permalink / raw)
  To: Palmer Dabbelt
  Cc: Paul Walmsley, Anup Patel, Greentime Hu, Zong Li, Albert Ou,
	Thomas Gleixner, Tycho Andersen, Nick Hu, linux-riscv,
	Linux Kernel Mailing List, linux-csky, Guo Ren

Thank you, Palmer

On Fri, Jul 10, 2020 at 6:06 AM Palmer Dabbelt <palmerdabbelt@google.com> wrote:
>
> On Sat, 27 Jun 2020 06:57:05 PDT (-0700), guoren@kernel.org wrote:
> > From: Guo Ren <guoren@linux.alibaba.com>
> >
> > Lockdep is needed by proving the spinlocks and rwlocks. To support it,
> > we need to add TRACE_IRQFLAGS codes in kernel/entry.S. These patches
> > follow Documentation/irqflags-tracing.txt.
> >
> > Fixup 2 bugs that block the lockdep implementation.
> >
> > ---
> > Changes in v2
> >  - Remove sX regs recovery codes which are unnecessary, because
> >    callee will handle them. Thx Greentime :)
> >
> >  - Move "restore a0 - a7" to handle_syscall, but if _TIF_SYSCALL_WORK
> >    is set, "restore a1 - a7" is still duplicated. I prefer a C wrapper
> >    for syscall.
> >
> > Guo Ren (2):
> >   riscv: Fixup static_obj() fail
> >   riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT
> >
> > Zong Li (1):
> >   riscv: Fixup lockdep_assert_held with wrong param cpu_running
> >
> >  arch/riscv/Kconfig              |  3 +++
> >  arch/riscv/kernel/entry.S       | 33 ++++++++++++++++++++++++++++++++-
> >  arch/riscv/kernel/smpboot.c     |  1 -
> >  arch/riscv/kernel/vmlinux.lds.S |  2 +-
> >  4 files changed, 36 insertions(+), 3 deletions(-)
>
> These are on for-next.  As far as I can tell lockdep is working, but I'm just
> doing some simple boot tests.
>
> Thanks!



-- 
Best Regards
 Guo Ren

ML: https://lore.kernel.org/linux-csky/

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

end of thread, back to index

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 13:57 [PATCH V2 0/3] riscv: Enable LOCKDEP guoren
2020-06-27 13:57 ` [PATCH V2 1/3] riscv: Fixup static_obj() fail guoren
2020-06-27 13:57 ` [PATCH V2 2/3] riscv: Fixup lockdep_assert_held with wrong param cpu_running guoren
2020-06-27 13:57 ` [PATCH V2 3/3] riscv: Enable LOCKDEP_SUPPORT & fixup TRACE_IRQFLAGS_SUPPORT guoren
2020-07-09 22:06 ` [PATCH V2 0/3] riscv: Enable LOCKDEP Palmer Dabbelt
2020-07-09 23:15   ` Guo Ren

Linux-csky Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-csky/0 linux-csky/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-csky linux-csky/ https://lore.kernel.org/linux-csky \
		linux-csky@vger.kernel.org
	public-inbox-index linux-csky

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-csky


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git