Skip to contentSkip to conversation

printk: Declare log_wait as external variable

PATCH In review Andy Shevchenko 5 participants 10 messages Feb 3, 2020 – Feb 13, 2020 Printk

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 printk: Declare log_wait as external variable

Static analyzer is not happy:

kernel/printk/printk.c:421:1: warning: symbol 'log_wait' was not declared. Should it be static?

This is due to usage of log_wait in the other module without announcing its declaration to the world. I wasn't able to dug into deep history of reasons why it is so, and thus decide to make less invasive change, i.e. declaring log_wait as external variable to make static analyzer happy.

Note the above is done if and only if the CONFIG_PROC_FS is enabled, otherwise we fallback to static variable.

---
 kernel/printk/printk.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/printk/printk.c +7 -0
index 633f41a11d75..43b5cb88c607 100644
@@ -418,7 +418,14 @@ DEFINE_RAW_SPINLOCK(logbuf_lock);
 	} while (0)
 
 #ifdef CONFIG_PRINTK
+
+#ifdef CONFIG_PROC_FS
+extern wait_queue_head_t log_wait;	/* Used in fs/proc/kmsg.c */
 DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#else
+static DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#endif /* CONFIG_PROC_FS */
+
 /* the next printk record to read by syslog(READ) or /proc/kmsg */
 static u64 syslog_seq;
 static u32 syslog_idx;
Signature · 1 line
2.24.1
#1 lore raw
Quoted 8 lines · Andy Shevchenko

Static analyzer is not happy:

kernel/printk/printk.c:421:1: warning: symbol 'log_wait' was not declared. Should it be static?

This is due to usage of log_wait in the other module without announcing its declaration to the world. I wasn't able to dug into deep history of reasons why it is so, and thus decide to make less invasive change, i.e. declaring log_wait as external variable to make static analyzer happy.

[..]

Quoted 5 lines
kernel/printk/printk.c +0 -0
index 633f41a11d75..43b5cb88c607 100644

kernel/printk/printk.c DEFINE_RAW_SPINLOCK(logbuf_lock); · line 427

Quoted 10 lines
kernel/printk/printk.c +6 -0
@@ -418,7 +418,14 @@ DEFINE_RAW_SPINLOCK(logbuf_lock);
 	} while (0)
 
 #ifdef CONFIG_PRINTK
+
+#ifdef CONFIG_PROC_FS
+extern wait_queue_head_t log_wait;	/* Used in fs/proc/kmsg.c */
 DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#else
+static DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#endif /* CONFIG_PROC_FS */

[..]

Since we are now introducing CONFIG_PROC_FS dependency to printk (and proc/kmsg already has CONFIG_PRINTK dependency), then I guess I wouldn't mind it if fs/proc/kmsg would just relocate to printk, next to devksmg implementation. Just saying.

	-ss
#2 lore raw
Quoted 30 lines · Sergey Senozhatsky
Quoted 8 lines · Andy Shevchenko

Static analyzer is not happy:

kernel/printk/printk.c:421:1: warning: symbol 'log_wait' was not declared. Should it be static?

This is due to usage of log_wait in the other module without announcing its declaration to the world. I wasn't able to dug into deep history of reasons why it is so, and thus decide to make less invasive change, i.e. declaring log_wait as external variable to make static analyzer happy.

[..]

Quoted 15 lines
kernel/printk/printk.c +6 -0
index 633f41a11d75..43b5cb88c607 100644
@@ -418,7 +418,14 @@ DEFINE_RAW_SPINLOCK(logbuf_lock);
 	} while (0)
 
 #ifdef CONFIG_PRINTK
+
+#ifdef CONFIG_PROC_FS
+extern wait_queue_head_t log_wait;	/* Used in fs/proc/kmsg.c */
 DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#else
+static DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#endif /* CONFIG_PROC_FS */

[..]

Quoted 2 lines

Since we are now introducing CONFIG_PROC_FS dependency to printk (and proc/kmsg already has CONFIG_PRINTK dependency),

I'm not sure I understood. The above does not introduce any dependencies.

Quoted 3 lines

then I guess I wouldn't
mind it if fs/proc/kmsg would just relocate to printk, next to devksmg implementation. Just saying.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 9 lines
Quoted 6 lines

--- a/kernel/printk/printk.c

kernel/printk/printk.c +4 -0
+extern wait_queue_head_t log_wait;	/* Used in fs/proc/kmsg.c */
 DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#else
+static DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#endif /* CONFIG_PROC_FS */

[..]

Quoted 4 lines
Quoted 2 lines

Since we are now introducing CONFIG_PROC_FS dependency to printk (and proc/kmsg already has CONFIG_PRINTK dependency),

I'm not sure I understood. The above does not introduce any dependencies.

kernel/printk/printk.c
+#ifdef CONFIG_PROC_FS
..

Not exactly "dependency"... what is the correct word here.

	-ss
#4 lore raw
Quoted 13 lines · Sergey Senozhatsky
Quoted 12 lines · Andy Shevchenko
Quoted 11 lines

kernel/printk/printk.c DEFINE_RAW_SPINLOCK(logbuf_lock); · line 427

Quoted 6 lines

--- a/kernel/printk/printk.c

kernel/printk/printk.c +4 -0
+extern wait_queue_head_t log_wait;	/* Used in fs/proc/kmsg.c */
 DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#else
+static DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#endif /* CONFIG_PROC_FS */

[..]

Since we are now introducing CONFIG_PROC_FS dependency to printk (and proc/kmsg already has CONFIG_PRINTK dependency),

Quoted 7 lines
Quoted 1 line

I'm not sure I understood. The above does not introduce any dependencies.

kernel/printk/printk.c
+#ifdef CONFIG_PROC_FS
..

Not exactly "dependency"... what is the correct word here.

Maybe "ifdeferry" ?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw
In reply to Andy Shevchenko
Quoted 22 lines · Andy Shevchenko

Static analyzer is not happy:

kernel/printk/printk.c:421:1: warning: symbol 'log_wait' was not declared. Should it be static?

This is due to usage of log_wait in the other module without announcing its declaration to the world. I wasn't able to dug into deep history of reasons why it is so, and thus decide to make less invasive change, i.e. declaring log_wait as external variable to make static analyzer happy.

Note the above is done if and only if the CONFIG_PROC_FS is enabled, otherwise we fallback to static variable.

---
 kernel/printk/printk.c | 7 +++++++
 1 file changed, 7 insertions(+)
kernel/printk/printk.c +0 -0
index 633f41a11d75..43b5cb88c607 100644

kernel/printk/printk.c DEFINE_RAW_SPINLOCK(logbuf_lock); · line 427

Quoted 10 lines
kernel/printk/printk.c +6 -0
@@ -418,7 +418,14 @@ DEFINE_RAW_SPINLOCK(logbuf_lock);
 	} while (0)
 
 #ifdef CONFIG_PRINTK
+
+#ifdef CONFIG_PROC_FS
+extern wait_queue_head_t log_wait;	/* Used in fs/proc/kmsg.c */
 DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#else
+static DECLARE_WAIT_QUEUE_HEAD(log_wait);
+#endif /* CONFIG_PROC_FS */

This looks too complicated as a workaround for a warning.

I got really confused. Probably also because the macro DECLARE_*() does a definition instead of a declaration.

As a minimal fix, I suggest to rename log_wait -> printk_log_wait and declare it in include/linux/printk.h.

Even better solution might be to move fs/proc/kmsg.c to kernel/printk/proc_kmsg.c and declare printk_log_wait only in kernel/printk/internal.h. I think that this is what Sergey suggested.

Another great thing would be to extract devkmsg stuff from kernel/printk/printk.c and put it into kernel/printk/dev_kmsg.c.

I am not sure but it might help people to realize that there are actually two different interfaces (old in /proc dmesg-like, and in /dev new for systemd). Sigh.

I am not sure how deep and far you would like to go ;-)

Best Regards,
Petr

#6 lore raw
Quoted 5 lines · Petr Mladek

Even better solution might be to move fs/proc/kmsg.c to kernel/printk/proc_kmsg.c and declare printk_log_wait only in kernel/printk/internal.h. I think that this is what Sergey suggested.

Yes, right.

Quoted 2 lines

Another great thing would be to extract devkmsg stuff from kernel/printk/printk.c and put it into kernel/printk/dev_kmsg.c.

Yeah, can do, I would still prefer proc_kmsg to "move in". Either both can live in printk.c (won't make it much worse), or in kernel/printk/dev_kmsg.c and kernel/printk/proc_kmsg.c

I can take a look at dev_ksmg.c/proc_kmsg.c option, unless someone else wants to spend their time on this.

	-ss
maintainer
#7 lore raw
Quoted 7 lines · Sergey Senozhatsky
Quoted 5 lines · Petr Mladek

Even better solution might be to move fs/proc/kmsg.c to kernel/printk/proc_kmsg.c and declare printk_log_wait only in kernel/printk/internal.h. I think that this is what Sergey suggested.

Quoted 8 lines

Yes, right.

Quoted 2 lines

Another great thing would be to extract devkmsg stuff from kernel/printk/printk.c and put it into kernel/printk/dev_kmsg.c.

Yeah, can do, I would still prefer proc_kmsg to "move in". Either both can live in printk.c (won't make it much worse), or in kernel/printk/dev_kmsg.c and kernel/printk/proc_kmsg.c

I would prefer to split it:

+ printk.c is already too big and would deserve splitting.

+ The two different kmgs interfaces are confusing on its own. IMHO, it will be even more confusing when they live in one huge source file.

Quoted 2 lines

I can take a look at dev_ksmg.c/proc_kmsg.c option, unless someone else wants to spend their time on this.

It would be lovely from my POV. I am only concerned about the lockless printk() stuff. I would prefer to avoid creating too many conflicts in the same merge window. Well, I am not sure how many conflicts there would be. Adding John into CC.

Best Regards,
Petr

maintainer
#8 lore raw
Quoted 9 lines · Petr Mladek

I would prefer to split it:

+ printk.c is already too big and would deserve splitting.

+ The two different kmgs interfaces are confusing on its own. IMHO, it will be even more confusing when they live in one huge source file.

Quoted 8 lines
Quoted 2 lines

I can take a look at dev_ksmg.c/proc_kmsg.c option, unless someone else wants to spend their time on this.

It would be lovely from my POV. I am only concerned about the lockless printk() stuff. I would prefer to avoid creating too many conflicts in the same merge window. Well, I am not sure how many conflicts there would be. Adding John into CC.

I would also love to see these changes. But can we _please_ focus on the lockless printk ringbuffer merge first? The patches already exist and are (hopefully) being reviewed. I would prefer that such a heavy API replacement is done _before_ we start any massive refactoring.

John Ogness

#9 lore raw
Quoted 1 line · John Ogness

On 2020-02-12, Petr Mladek <[email protected]> wrote:

[..]

Quoted 11 lines
Quoted 8 lines
Quoted 2 lines

I can take a look at dev_ksmg.c/proc_kmsg.c option, unless someone else wants to spend their time on this.

It would be lovely from my POV. I am only concerned about the lockless printk() stuff. I would prefer to avoid creating too many conflicts in the same merge window. Well, I am not sure how many conflicts there would be. Adding John into CC.

I would also love to see these changes. But can we _please_ focus on the lockless printk ringbuffer merge first?

Agreed.

Quoted 1 line

The patches already exist and are (hopefully) being reviewed.

				^^^
				are (hopefully) being tested.

	-ss