printk: Declare log_wait as external variable
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
@@ -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
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_waitin 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. declaringlog_waitas external variable to make static analyzer happy.
[..]
Quoted 5 lines
kernel/printk/printk.c +0
-0
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
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_waitin 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. declaringlog_waitas external variable to make static analyzer happy.[..]
Quoted 15 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 */ [..]
Quoted 2 lines
Since we are now introducing
CONFIG_PROC_FSdependency to printk (and proc/kmsg already hasCONFIG_PRINTKdependency),
I'm not sure I understood. The above does not introduce any dependencies.
Quoted 3 lines
then I guess I wouldn't
mind it iffs/proc/kmsgwould just relocate to printk, next to devksmg implementation. Just saying.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 9 lines
Quoted 6 lines
---
a/kernel/printk/printk.ckernel/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_FSdependency to printk (and proc/kmsg already hasCONFIG_PRINTKdependency),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
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.ckernel/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_FSdependency to printk (and proc/kmsg already hasCONFIG_PRINTKdependency),
Quoted 7 lines
Quoted 1 line
I'm not sure I understood. The above does not introduce any dependencies.
kernel/printk/printk.c
+#ifdefCONFIG_PROC_FS
..Not exactly "dependency"... what is the correct word here.
Maybe "ifdeferry" ?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Petr Mladek
maintainerQuoted 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_waitin 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. declaringlog_waitas external variable to make static analyzer happy.Note the above is done if and only if the
CONFIG_PROC_FSis enabled, otherwise we fallback to static variable.Signed-off-by Andy Shevchenko <[email protected]>--- kernel/printk/printk.c | 7 +++++++ 1 file changed, 7 insertions(+)kernel/printk/printk.c +0
-0
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
Quoted 5 lines · Petr Mladek
Even better solution might be to move
fs/proc/kmsg.ctokernel/printk/proc_kmsg.cand declareprintk_log_waitonly inkernel/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.cand put it intokernel/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
Petr Mladek
maintainerQuoted 7 lines · Sergey Senozhatsky
Quoted 5 lines · Petr Mladek
Even better solution might be to move
fs/proc/kmsg.ctokernel/printk/proc_kmsg.cand declareprintk_log_waitonly inkernel/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.cand put it intokernel/printk/dev_kmsg.c.Yeah, can do, I would still prefer
proc_kmsgto "move in". Either both can live inprintk.c(won't make it much worse), or inkernel/printk/dev_kmsg.candkernel/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.coption, 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
John Ogness
maintainerQuoted 9 lines · Petr Mladek
I would prefer to split it:
+
printk.cis 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.coption, 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
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.coption, 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