linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] printk: Declare log_wait as external variable
@ 2020-02-03 13:15 Andy Shevchenko
  2020-02-04  2:16 ` Sergey Senozhatsky
  2020-02-11 12:43 ` Petr Mladek
  0 siblings, 2 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-03 13:15 UTC (permalink / raw)
  To: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt
  Cc: 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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 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


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-03 13:15 [PATCH v1] printk: Declare log_wait as external variable Andy Shevchenko
@ 2020-02-04  2:16 ` Sergey Senozhatsky
  2020-02-04  9:05   ` Andy Shevchenko
  2020-02-11 12:43 ` Petr Mladek
  1 sibling, 1 reply; 10+ messages in thread
From: Sergey Senozhatsky @ 2020-02-04  2:16 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-04  2:16 ` Sergey Senozhatsky
@ 2020-02-04  9:05   ` Andy Shevchenko
  2020-02-04 11:22     ` Sergey Senozhatsky
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-04  9:05 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Petr Mladek, Sergey Senozhatsky, linux-kernel, Steven Rostedt

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



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-04  9:05   ` Andy Shevchenko
@ 2020-02-04 11:22     ` Sergey Senozhatsky
  2020-02-04 11:31       ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Sergey Senozhatsky @ 2020-02-04 11:22 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Sergey Senozhatsky, Petr Mladek, Sergey Senozhatsky,
	linux-kernel, Steven Rostedt

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-04 11:22     ` Sergey Senozhatsky
@ 2020-02-04 11:31       ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2020-02-04 11:31 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Sergey Senozhatsky, Petr Mladek, linux-kernel, Steven Rostedt

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



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-03 13:15 [PATCH v1] printk: Declare log_wait as external variable Andy Shevchenko
  2020-02-04  2:16 ` Sergey Senozhatsky
@ 2020-02-11 12:43 ` Petr Mladek
  2020-02-12  1:31   ` Sergey Senozhatsky
  1 sibling, 1 reply; 10+ messages in thread
From: Petr Mladek @ 2020-02-11 12:43 UTC (permalink / raw)
  To: Andy Shevchenko; +Cc: Sergey Senozhatsky, linux-kernel, Steven Rostedt

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 <andriy.shevchenko@linux.intel.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-11 12:43 ` Petr Mladek
@ 2020-02-12  1:31   ` Sergey Senozhatsky
  2020-02-12 14:03     ` Petr Mladek
  0 siblings, 1 reply; 10+ messages in thread
From: Sergey Senozhatsky @ 2020-02-12  1:31 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Andy Shevchenko, Sergey Senozhatsky, linux-kernel, Steven Rostedt

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-12  1:31   ` Sergey Senozhatsky
@ 2020-02-12 14:03     ` Petr Mladek
  2020-02-12 14:24       ` John Ogness
  0 siblings, 1 reply; 10+ messages in thread
From: Petr Mladek @ 2020-02-12 14:03 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Andy Shevchenko, Sergey Senozhatsky, linux-kernel,
	Steven Rostedt, John Ogness

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-12 14:03     ` Petr Mladek
@ 2020-02-12 14:24       ` John Ogness
  2020-02-13 12:02         ` Sergey Senozhatsky
  0 siblings, 1 reply; 10+ messages in thread
From: John Ogness @ 2020-02-12 14:24 UTC (permalink / raw)
  To: Petr Mladek
  Cc: Sergey Senozhatsky, Andy Shevchenko, Sergey Senozhatsky,
	linux-kernel, Steven Rostedt

On 2020-02-12, Petr Mladek <pmladek@suse.com> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v1] printk: Declare log_wait as external variable
  2020-02-12 14:24       ` John Ogness
@ 2020-02-13 12:02         ` Sergey Senozhatsky
  0 siblings, 0 replies; 10+ messages in thread
From: Sergey Senozhatsky @ 2020-02-13 12:02 UTC (permalink / raw)
  To: John Ogness
  Cc: Petr Mladek, Sergey Senozhatsky, Andy Shevchenko,
	Sergey Senozhatsky, linux-kernel, Steven Rostedt

On (20/02/12 15:24), John Ogness wrote:
> On 2020-02-12, Petr Mladek <pmladek@suse.com> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-02-13 12:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-03 13:15 [PATCH v1] printk: Declare log_wait as external variable Andy Shevchenko
2020-02-04  2:16 ` Sergey Senozhatsky
2020-02-04  9:05   ` Andy Shevchenko
2020-02-04 11:22     ` Sergey Senozhatsky
2020-02-04 11:31       ` Andy Shevchenko
2020-02-11 12:43 ` Petr Mladek
2020-02-12  1:31   ` Sergey Senozhatsky
2020-02-12 14:03     ` Petr Mladek
2020-02-12 14:24       ` John Ogness
2020-02-13 12:02         ` Sergey Senozhatsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).