2020-02-03 14:53:18

by Andy Shevchenko

[permalink] [raw]
Subject: [PATCH v1] 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.

Signed-off-by: Andy Shevchenko <[email protected]>
---
kernel/printk/printk.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 633f41a11d75..43b5cb88c607 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -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;
--
2.24.1


2020-02-04 02:19:05

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On (20/02/03 15:15), Andy Shevchenko wrote:
> 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.

[..]

> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 633f41a11d75..43b5cb88c607 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -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

2020-02-04 09:07:08

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On Tue, Feb 04, 2020 at 11:16:20AM +0900, Sergey Senozhatsky wrote:
> On (20/02/03 15:15), Andy Shevchenko wrote:
> > 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.
>
> [..]
>
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index 633f41a11d75..43b5cb88c607 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -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),

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

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

--
With Best Regards,
Andy Shevchenko


2020-02-04 11:23:18

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On (20/02/04 11:05), Andy Shevchenko wrote:
> > > --- a/kernel/printk/printk.c
> > > +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),
>
> 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

2020-02-04 11:33:25

by Andy Shevchenko

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On Tue, Feb 04, 2020 at 08:22:11PM +0900, Sergey Senozhatsky wrote:
> On (20/02/04 11:05), Andy Shevchenko wrote:
> > > > --- a/kernel/printk/printk.c
> > > > +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),
> >
> > 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" ?

--
With Best Regards,
Andy Shevchenko


2020-02-11 12:49:41

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On Mon 2020-02-03 15:15:28, Andy Shevchenko wrote:
> 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.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> kernel/printk/printk.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 633f41a11d75..43b5cb88c607 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -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

2020-02-12 01:34:56

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On (20/02/11 13:43), Petr Mladek wrote:
>
> 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.

> 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

2020-02-12 14:04:38

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On Wed 2020-02-12 10:31:33, Sergey Senozhatsky wrote:
> On (20/02/11 13:43), Petr Mladek wrote:
> >
> > 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.
>
> > 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.


> 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

2020-02-12 14:26:40

by John Ogness

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On 2020-02-12, Petr Mladek <[email protected]> wrote:
> 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.
>
>
>> 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

2020-02-13 12:03:06

by Sergey Senozhatsky

[permalink] [raw]
Subject: Re: [PATCH v1] printk: Declare log_wait as external variable

On (20/02/12 15:24), John Ogness wrote:
> On 2020-02-12, Petr Mladek <[email protected]> wrote:
[..]
> >> 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.

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

-ss