Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1311208 > unrolled thread

[PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

Started byByungchul Park <byungchul.park@lge.com>
First post2016-01-18 02:00 +0100
Last post2016-01-27 03:30 +0100
Articles 7 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump() Byungchul Park <byungchul.park@lge.com> - 2016-01-18 02:00 +0100
    Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive  cycle in spin_dump() Byungchul Park <byungchul.park@lge.com> - 2016-01-19 03:00 +0100
      Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive  cycle in spin_dump() Byungchul Park <byungchul.park@lge.com> - 2016-01-21 09:20 +0100
    Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive  cycle in spin_dump() Andrew Morton <akpm@linux-foundation.org> - 2016-01-27 01:20 +0100
      Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive  cycle in spin_dump() Peter Hurley <peter@hurleysoftware.com> - 2016-01-27 02:20 +0100
      Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive  cycle in spin_dump() Byungchul Park <byungchul.park@lge.com> - 2016-01-27 03:10 +0100
        Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive  cycle in spin_dump() Byungchul Park <byungchul.park@lge.com> - 2016-01-27 03:30 +0100

#1311208 — [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromByungchul Park <byungchul.park@lge.com>
Date2016-01-18 02:00 +0100
Subject[PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qS6kO-1AW-3@gated-at.bofh.it>
It causes an infinite recursive cycle when using CONFIG_DEBUG_SPINLOCK,
in the spin_dump(). Backtrace prints printk() -> console_trylock() ->
do_raw_spin_lock() -> spint_bug() -> spin_dump() -> printk()...
infinitely.

If the spin_bug() is called from a function like printk() which is
trying to obtain the console lock, we should prevent the debug spinlock
code from calling printk() again in that context.

Signed-off-by: Byungchul Park <byungchul.park@lge.com>
---
 kernel/locking/spinlock_debug.c | 11 +++++++++++
 kernel/printk/printk.c          |  5 +++++
 2 files changed, 16 insertions(+)

diff --git a/kernel/locking/spinlock_debug.c b/kernel/locking/spinlock_debug.c
index 0374a59..e745973 100644
--- a/kernel/locking/spinlock_debug.c
+++ b/kernel/locking/spinlock_debug.c
@@ -67,11 +67,22 @@ static void spin_dump(raw_spinlock_t *lock, const char *msg)
 	dump_stack();
 }
 
+extern int is_console_lock(raw_spinlock_t *lock);
+
 static void spin_bug(raw_spinlock_t *lock, const char *msg)
 {
 	if (!debug_locks_off())
 		return;
 
+	/*
+	 * If this function is called from a function like printk()
+	 * which is trying to obtain the console lock, then we should
+	 * not call printk() any more. Or it will cause an infinite
+	 * recursive cycle!
+	 */
+	if (unlikely(is_console_lock(lock)))
+		return;
+
 	spin_dump(lock, msg);
 }
 
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 2ce8826..50ea552 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -119,6 +119,11 @@ static int __down_trylock_console_sem(unsigned long ip)
 	up(&console_sem);\
 } while (0)
 
+int is_console_lock(raw_spinlock_t *lock)
+{
+	return &console_sem.lock == lock;
+}
+
 /*
  * This is used for debugging the mess that is the VT code by
  * keeping track if we have the console semaphore held. It's
-- 
1.9.1

[toc] | [next] | [standalone]


#1311890 — Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromByungchul Park <byungchul.park@lge.com>
Date2016-01-19 03:00 +0100
SubjectRe: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qStKq-Kn-7@gated-at.bofh.it>
In reply to#1311208
I missed the version change desciption when I sent this v2. This patch
worked for me. Please let me know if you have other opinions.

Changes from v1 to v2
- only change comment and commit message esp. replacing "deadlock"
  with "infinite recursive cycle", since it is not an actual deadlock.

Thanks,
Byungchul

[toc] | [prev] | [next] | [standalone]


#1313991 — Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromByungchul Park <byungchul.park@lge.com>
Date2016-01-21 09:20 +0100
SubjectRe: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qTiDg-2B3-7@gated-at.bofh.it>
In reply to#1311890
On Tue, Jan 19, 2016 at 10:53:56AM +0900, Byungchul Park wrote:
> I missed the version change desciption when I sent this v2. This patch
> worked for me. Please let me know if you have other opinions.
> 
> Changes from v1 to v2
> - only change comment and commit message esp. replacing "deadlock"
>   with "infinite recursive cycle", since it is not an actual deadlock.

I was careless. I think it should be fixed by another way, instead of
the way this patch suggested.

> 
> Thanks,
> Byungchul

[toc] | [prev] | [next] | [standalone]


#1318490 — Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromAndrew Morton <akpm@linux-foundation.org>
Date2016-01-27 01:20 +0100
SubjectRe: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qVm01-3EK-1@gated-at.bofh.it>
In reply to#1311208
On Mon, 18 Jan 2016 09:58:12 +0900 Byungchul Park <byungchul.park@lge.com> wrote:

> It causes an infinite recursive cycle when using CONFIG_DEBUG_SPINLOCK,
> in the spin_dump(). Backtrace prints printk() -> console_trylock() ->
> do_raw_spin_lock() -> spint_bug() -> spin_dump() -> printk()...
> infinitely.
> 
> If the spin_bug() is called from a function like printk() which is
> trying to obtain the console lock, we should prevent the debug spinlock
> code from calling printk() again in that context.
> 

lol.  Excellent.

> --- a/kernel/locking/spinlock_debug.c
> +++ b/kernel/locking/spinlock_debug.c
> @@ -67,11 +67,22 @@ static void spin_dump(raw_spinlock_t *lock, const char *msg)
>  	dump_stack();
>  }
>  
> +extern int is_console_lock(raw_spinlock_t *lock);
> +
>  static void spin_bug(raw_spinlock_t *lock, const char *msg)
>  {
>  	if (!debug_locks_off())
>  		return;
>  
> +	/*
> +	 * If this function is called from a function like printk()
> +	 * which is trying to obtain the console lock, then we should
> +	 * not call printk() any more. Or it will cause an infinite
> +	 * recursive cycle!
> +	 */
> +	if (unlikely(is_console_lock(lock)))
> +		return;
> +
>  	spin_dump(lock, msg);
>  }
>  
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 2ce8826..50ea552 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -119,6 +119,11 @@ static int __down_trylock_console_sem(unsigned long ip)
>  	up(&console_sem);\
>  } while (0)
>  
> +int is_console_lock(raw_spinlock_t *lock)
> +{
> +	return &console_sem.lock == lock;
> +}
> +
>  /*
>   * This is used for debugging the mess that is the VT code by
>   * keeping track if we have the console semaphore held. It's

I can't immediately think of anything better than this.  It's a hack, but
it's a small and quite clear hack.

[toc] | [prev] | [next] | [standalone]


#1318519 — Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromPeter Hurley <peter@hurleysoftware.com>
Date2016-01-27 02:20 +0100
SubjectRe: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qVmW6-4h1-9@gated-at.bofh.it>
In reply to#1318490
On 01/26/2016 04:11 PM, Andrew Morton wrote:
> On Mon, 18 Jan 2016 09:58:12 +0900 Byungchul Park <byungchul.park@lge.com> wrote:
> 
>> It causes an infinite recursive cycle when using CONFIG_DEBUG_SPINLOCK,
>> in the spin_dump(). Backtrace prints printk() -> console_trylock() ->
>> do_raw_spin_lock() -> spint_bug() -> spin_dump() -> printk()...
>> infinitely.
>>
>> If the spin_bug() is called from a function like printk() which is
>> trying to obtain the console lock, we should prevent the debug spinlock
>> code from calling printk() again in that context.
>>
> 
> lol.  Excellent.

[...]

> I can't immediately think of anything better than this.  It's a hack, but
> it's a small and quite clear hack.

Andrew,

I think you may have missed this follow-up from Byungchul:

On 01/21/2016 12:12 AM, Byungchul Park wrote:
> I was careless. I think it should be fixed by another way, instead of
> the way this patch suggested.

Regards,
Peter Hurley

[toc] | [prev] | [next] | [standalone]


#1318550 — Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromByungchul Park <byungchul.park@lge.com>
Date2016-01-27 03:10 +0100
SubjectRe: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qVnIu-4QH-9@gated-at.bofh.it>
In reply to#1318490
On Tue, Jan 26, 2016 at 04:11:24PM -0800, Andrew Morton wrote:
> I can't immediately think of anything better than this.  It's a hack, but
> it's a small and quite clear hack.

I am sorry for making you confused. :( I think I need to find another way
to solve this problem. At first, when I wrote this patch, I was also
confused.

thanks,
byungchul

[toc] | [prev] | [next] | [standalone]


#1318562 — Re: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()

FromByungchul Park <byungchul.park@lge.com>
Date2016-01-27 03:30 +0100
SubjectRe: [PATCH v2] lib/spinlock_debug.c: prevent an infinite recursive cycle in spin_dump()
Message-ID<qVo1Q-4Y0-11@gated-at.bofh.it>
In reply to#1318550
On Wed, Jan 27, 2016 at 11:00:14AM +0900, Byungchul Park wrote:
> On Tue, Jan 26, 2016 at 04:11:24PM -0800, Andrew Morton wrote:
> > I can't immediately think of anything better than this.  It's a hack, but
> > it's a small and quite clear hack.
> 
> I am sorry for making you confused. :( I think I need to find another way
> to solve this problem. At first, when I wrote this patch, I was also
> confused.

Even though this can fix symptoms..

> 
> thanks,
> byungchul

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web