Skip to contentSkip to conversation

fbdev/core: Disable console-lock warnings when fb.lockless_register_fb is set

PATCH In review Thomas Zimmermann 6 participants 11 messages Jul 19, 2018 – Jul 31, 2018

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover fbdev/core: Disable console-lock warnings when fb.lockless_register_fb is set

Hi,

this is version 3 of the WARN_CONSOLE_UNLOCKED patch set. The macro prints a warning if the console's critical sections are entered without holding the console lock. This patch set allows to disable the warnings while debugging the console.

In the original approach, WARN_CONSOLE_UNLOCKED was disabled by setting ignore_console_lock_warning of type bool. As suggested by Petr Mladek, the new implementation is based on atomic_t and allows multiple threads to manipulate the warning state concurrently.

With version 3, the patch set now includes the patch for introducing ignore_console_lock_warning. This patch superseds all previous patches of the same purpose.

Best regards
Thomas

v3:
- implement ignore_console_lock_warning with atomic_t
v2:
- restore ignore_console_lock_warning if lock_fb_info() fails

Thomas Zimmermann (2):
console: Replace #if 0 with atomic var 'ignore_console_lock_warning' fbdev/core: Disable console-lock warnings when fb.lockless_register_fb
is set

 drivers/video/fbdev/core/fbmem.c | 13 +++++++++----
 include/linux/console.h          | 14 +++++++++-----
 kernel/printk/printk.c           |  3 +++
 3 files changed, 21 insertions(+), 9 deletions(-)

--
2.18.0

#1 lore raw

PATCH v3 1/2 console: Replace #if 0 with atomic var 'ignore_console_lock_warning'

The macro WARN_CONSOLE_UNLOCKED prints a warning when a thread enters the console's critical section without having acquired the console lock. The console lock can be ignored when debugging the console using printk, but this makes WARN_CONSOLE_UNLOCKED generate unnecessary warnings.

The variable ignore_console_lock_warning temporarily disables WARN_CONSOLE_UNLOCKED. Developers interested in debugging the console's critical sections should increment it before entering the CS and decrement it after leaving the CS. Setting ignore_console_lock_warning is only for debugging. Regular operation should not manipulate it.

Acknoledgements: This patch is based on an earlier version by Steven Rostedt. The use of atomic increment/decrement was suggested by Petr Mladek.

---
 include/linux/console.h | 14 +++++++++-----
 kernel/printk/printk.c  |  3 +++
 2 files changed, 12 insertions(+), 5 deletions(-)
include/linux/console.h +9 -5
index f59f3dbca65c..a3307bcab947 100644
@@ -14,6 +14,7 @@
 #ifndef _LINUX_CONSOLE_H_
 #define _LINUX_CONSOLE_H_ 1
 
+#include <asm/atomic.h>
 #include <linux/types.h>
 
 struct vc_data;
@@ -201,11 +202,14 @@ void vcs_make_sysfs(int index);
 void vcs_remove_sysfs(int index);
 
 /* Some debug stub to catch some of the obvious races in the VT code */
-#if 1
-#define WARN_CONSOLE_UNLOCKED()	WARN_ON(!is_console_locked() && !oops_in_progress)
-#else
-#define WARN_CONSOLE_UNLOCKED()
-#endif
+#define WARN_CONSOLE_UNLOCKED()						\
+	WARN_ON(!atomic_read(&ignore_console_lock_warning) &&		\
+		!is_console_locked() && !oops_in_progress)
+/*
+ * Increment ignore_console_lock_warning if you need to quiet
+ * WARN_CONSOLE_UNLOCKED() for debugging purposes.
+ */
+extern atomic_t ignore_console_lock_warning;
 
 /* VESA Blanking Levels */
 #define VESA_NO_BLANKING        0
kernel/printk/printk.c +3 -0
index 3f041e7cbfc9..7d32a86758cd 100644
@@ -66,6 +66,9 @@ int console_printk[4] = {
 	CONSOLE_LOGLEVEL_DEFAULT,	/* default_console_loglevel */
 };
 
+atomic_t ignore_console_lock_warning __read_mostly = ATOMIC_INIT(0);
+EXPORT_SYMBOL(ignore_console_lock_warning);
+
 /*
  * Low level drivers may need that to know if they can schedule in
  * their unblank() callback or not. So let's export it.
Signature · 1 line
2.18.0
maintainer Acked-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] console: Replace #if 0 with atomic var 'ignore_console_lock_warning'

Quoted 12 lines · Thomas Zimmermann

The macro WARN_CONSOLE_UNLOCKED prints a warning when a thread enters the console's critical section without having acquired the console lock. The console lock can be ignored when debugging the console using printk, but this makes WARN_CONSOLE_UNLOCKED generate unnecessary warnings.

The variable ignore_console_lock_warning temporarily disables WARN_CONSOLE_UNLOCKED. Developers interested in debugging the console's critical sections should increment it before entering the CS and decrement it after leaving the CS. Setting ignore_console_lock_warning is only for debugging. Regular operation should not manipulate it.

Quoted 6 lines

Acknoledgements: This patch is based on an earlier version by Steven Rostedt. The use of atomic increment/decrement was suggested by Petr Mladek.

I have vacation the following two weeks. I prefer this version over the previous one but I could live with both.

Best Regards,
Petr

#3 lore raw

Re: [PATCH v3 1/2] console: Replace #if 0 with atomic var 'ignore_console_lock_warning'

In reply to Thomas Zimmermann
Quoted 12 lines · Thomas Zimmermann

The macro WARN_CONSOLE_UNLOCKED prints a warning when a thread enters the console's critical section without having acquired the console lock. The console lock can be ignored when debugging the console using printk, but this makes WARN_CONSOLE_UNLOCKED generate unnecessary warnings.

The variable ignore_console_lock_warning temporarily disables WARN_CONSOLE_UNLOCKED. Developers interested in debugging the console's critical sections should increment it before entering the CS and decrement it after leaving the CS. Setting ignore_console_lock_warning is only for debugging. Regular operation should not manipulate it.

Quoted 6 lines

Acknoledgements: This patch is based on an earlier version by Steven Rostedt. The use of atomic increment/decrement was suggested by Petr Mladek.

Patch queued for 4.19 (w/ <asm/atomic.h> -> <linux/atomic.h> fixup), thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

#4 lore raw

Re: [PATCH v3 1/2] console: Replace #if 0 with atomic var 'ignore_console_lock_warning'

In reply to Thomas Zimmermann
Quoted 12 lines · On Thu, 19 Jul 2018 12:16:00 +0200 Thomas Zimmermann <[email protected]>…

The macro WARN_CONSOLE_UNLOCKED prints a warning when a thread enters the console's critical section without having acquired the console lock. The console lock can be ignored when debugging the console using printk, but this makes WARN_CONSOLE_UNLOCKED generate unnecessary warnings.

The variable ignore_console_lock_warning temporarily disables WARN_CONSOLE_UNLOCKED. Developers interested in debugging the console's critical sections should increment it before entering the CS and decrement it after leaving the CS. Setting ignore_console_lock_warning is only for debugging. Regular operation should not manipulate it.

Quoted 3 lines

Acknoledgements: This patch is based on an earlier version by Steven Rostedt. The use of atomic increment/decrement was suggested by Petr Mladek.

You can also add a reference to that patch as well:

-- Steve

Quoted 54 lines
---
 include/linux/console.h | 14 +++++++++-----
 kernel/printk/printk.c  |  3 +++
 2 files changed, 12 insertions(+), 5 deletions(-)
include/linux/console.h +9 -5
index f59f3dbca65c..a3307bcab947 100644
@@ -14,6 +14,7 @@
 #ifndef _LINUX_CONSOLE_H_
 #define _LINUX_CONSOLE_H_ 1
 
+#include <asm/atomic.h>
 #include <linux/types.h>
 
 struct vc_data;
@@ -201,11 +202,14 @@ void vcs_make_sysfs(int index);
 void vcs_remove_sysfs(int index);
 
 /* Some debug stub to catch some of the obvious races in the VT code */
-#if 1
-#define WARN_CONSOLE_UNLOCKED()	WARN_ON(!is_console_locked() && !oops_in_progress)
-#else
-#define WARN_CONSOLE_UNLOCKED()
-#endif
+#define WARN_CONSOLE_UNLOCKED()						\
+	WARN_ON(!atomic_read(&ignore_console_lock_warning) &&		\
+		!is_console_locked() && !oops_in_progress)
+/*
+ * Increment ignore_console_lock_warning if you need to quiet
+ * WARN_CONSOLE_UNLOCKED() for debugging purposes.
+ */
+extern atomic_t ignore_console_lock_warning;
 
 /* VESA Blanking Levels */
 #define VESA_NO_BLANKING        0
kernel/printk/printk.c +3 -0
index 3f041e7cbfc9..7d32a86758cd 100644
@@ -66,6 +66,9 @@ int console_printk[4] = {
 	CONSOLE_LOGLEVEL_DEFAULT,	/* default_console_loglevel */
 };
 
+atomic_t ignore_console_lock_warning __read_mostly = ATOMIC_INIT(0);
+EXPORT_SYMBOL(ignore_console_lock_warning);
+
 /*
  * Low level drivers may need that to know if they can schedule in
  * their unblank() callback or not. So let's export it.
#5 lore raw

PATCH v3 2/2 fbdev/core: Disable console-lock warnings when fb.lockless_register_fb is set

In reply to Thomas Zimmermann

If the console is unlocked during registration, the console subsystem generates significant amounts of warnings, which obfuscate actual debugging messages. Setting ignore_console_lock_warning while debugging console registration avoid the noise.

v3:
- manipulate ignore_console_lock_warning with atomic_{inc,dec}
v2:
- restore ignore_console_lock_warning if lock_fb_info() fails

---
 drivers/video/fbdev/core/fbmem.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/fbmem.c +9 -4
index 9e2f9d3c760e..cb72cd6c5892 100644
@@ -1691,17 +1691,22 @@ static int do_register_framebuffer(struct fb_info *fb_info)
 	event.info = fb_info;
 	if (!lockless_register_fb)
 		console_lock();
+	else
+		atomic_inc(&ignore_console_lock_warning);
 	if (!lock_fb_info(fb_info)) {
-		if (!lockless_register_fb)
-			console_unlock();
-		return -ENODEV;
+		ret = -ENODEV;
+		goto unlock_console;
 	}
+	ret = 0;
 
 	fb_notifier_call_chain(FB_EVENT_FB_REGISTERED, &event);
 	unlock_fb_info(fb_info);
+unlock_console:
 	if (!lockless_register_fb)
 		console_unlock();
-	return 0;
+	else
+		atomic_dec(&ignore_console_lock_warning);
+	return ret;
 }
 
 static int do_unregister_framebuffer(struct fb_info *fb_info)
Signature · 1 line
2.18.0
maintainer Reviewed-by on v3 2/2
#6 lore raw
Quoted 11 lines · Thomas Zimmermann

If the console is unlocked during registration, the console subsystem generates significant amounts of warnings, which obfuscate actual debugging messages. Setting ignore_console_lock_warning while debugging console registration avoid the noise.

v3:
- manipulate ignore_console_lock_warning with atomic_{inc,dec}
v2:
- restore ignore_console_lock_warning if lock_fb_info() fails

I have vacation the following two weeks. Note that I am fine with v2 if anyone see the atomic as an overkill.

Best Regards,
Petr

#7 lore raw
In reply to Thomas Zimmermann
Quoted 11 lines · Thomas Zimmermann

If the console is unlocked during registration, the console subsystem generates significant amounts of warnings, which obfuscate actual debugging messages. Setting ignore_console_lock_warning while debugging console registration avoid the noise.

v3:
- manipulate ignore_console_lock_warning with atomic_{inc,dec}
v2:
- restore ignore_console_lock_warning if lock_fb_info() fails

Patch queued for 4.19, thanks.

Best regards,
--
Bartlomiej Zolnierkiewicz
Samsung R&D Institute Poland
Samsung Electronics

Acked-by on the v3 series
#8 lore raw
In reply to Thomas Zimmermann

Hi,

Quoted 24 lines · Thomas Zimmermann

Hi,

this is version 3 of the WARN_CONSOLE_UNLOCKED patch set. The macro prints a warning if the console's critical sections are entered without holding the console lock. This patch set allows to disable the warnings while debugging the console.

In the original approach, WARN_CONSOLE_UNLOCKED was disabled by setting ignore_console_lock_warning of type bool. As suggested by Petr Mladek, the new implementation is based on atomic_t and allows multiple threads to manipulate the warning state concurrently.

With version 3, the patch set now includes the patch for introducing ignore_console_lock_warning. This patch superseds all previous patches of the same purpose.

Best regards
Thomas

v3:
- implement ignore_console_lock_warning with atomic_t
v2:
- restore ignore_console_lock_warning if lock_fb_info() fails

Quoted 4 lines

Thomas Zimmermann (2):
console: Replace #if 0 with atomic var 'ignore_console_lock_warning' fbdev/core: Disable console-lock warnings when fb.lockless_register_fb
is set

I just saw this version after my comment on v2 that the race there was not really a problem.

This version is even better though :) :

Regards,

Hans

Reviewed-by on the v3 series
#10 lore raw
In reply to Thomas Zimmermann
Quoted 14 lines · Thomas Zimmermann

this is version 3 of the WARN_CONSOLE_UNLOCKED patch set. The macro prints a warning if the console's critical sections are entered without holding the console lock. This patch set allows to disable the warnings while debugging the console.

In the original approach, WARN_CONSOLE_UNLOCKED was disabled by setting ignore_console_lock_warning of type bool. As suggested by Petr Mladek, the new implementation is based on atomic_t and allows multiple threads to manipulate the warning state concurrently.

With version 3, the patch set now includes the patch for introducing ignore_console_lock_warning. This patch superseds all previous patches of the same purpose.

Quoted 7 lines

Best regards
Thomas

v3:
- implement ignore_console_lock_warning with atomic_t
v2:
- restore ignore_console_lock_warning if lock_fb_info() fails

	-ss