2022-02-28 09:41:06

by Maninder Singh

[permalink] [raw]
Subject: [PATCH v4] scripts/checkpatch.pl: remove _deferred and _deferred_once false warning

with commit 98e35f5894cf ("printk: git rid of [sched_delayed] message for
printk_deferred") printk_deferred and printk_deferred_once requires
LOGLEVEL in argument, but checkpatch.pl was not fixed and still reports
it as warning:

WARNING: Possible unnecessary KERN_ALERT
printk_deferred(KERN_ALERT "checking deferred\n");

Co-developed-by: Vaneet Narang <[email protected]>
Signed-off-by: Vaneet Narang <[email protected]>
Signed-off-by: Maninder Singh <[email protected]>
---
v3 -> v4: v3 was dropped, because it starts reporting *_printk as
unnecessary KERNEL_* levels as report by Joe Perches.
dev_printk(KERN_DEBUG "foo", ...). thus fixing it with simple
addition of deferred in same line of _ratelimited as original
https://lkml.org/lkml/2021/8/24/91

scripts/checkpatch.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2653177f52d9..78053545a0d5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6312,7 +6312,7 @@ sub process {
}

# check for logging functions with KERN_<LEVEL>
- if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
+ if ($line !~ /printk(?:_ratelimited|_once|_deferred|_deferred_once)?\s*\(/ &&
$line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
my $level = $1;
if (WARN("UNNECESSARY_KERN_LEVEL",
--
2.17.1


2022-03-01 00:32:36

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH v4] scripts/checkpatch.pl: remove _deferred and _deferred_once false warning

On Mon, 2022-02-28 at 13:07 +0530, Maninder Singh wrote:
> with commit 98e35f5894cf ("printk: git rid of [sched_delayed] message for
> printk_deferred") printk_deferred and printk_deferred_once requires
> LOGLEVEL in argument, but checkpatch.pl was not fixed and still reports
> it as warning:
>
> WARNING: Possible unnecessary KERN_ALERT
> printk_deferred(KERN_ALERT "checking deferred\n");

I don't care for this patch at all.

There are many existing uses of printk_deferred both with and without a
specific KERN_<LEVEL>.

printk_deferred currently always emits at LOGLEVEL_SCHED/KERN_DEFAULT.

I think it's be better to modify vprintk_emit when LOGLEVEL_SCHED
is used and if a KERN_<LEVEL> exists in the format, use it.

Perhaps instead:
---
kernel/printk/printk.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 1ce242f34d2be..6b5baf14f6d56 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -2247,7 +2247,13 @@ asmlinkage int vprintk_emit(int facility, int level,
return 0;

if (level == LOGLEVEL_SCHED) {
- level = LOGLEVEL_DEFAULT;
+ level = printk_get_level(fmt);
+ if (level) {
+ level -= '0';
+ fmt = printk_skip_level(fmt);
+ } else {
+ level = LOGLEVEL_DEFAULT;
+ }
in_sched = true;
}



2022-03-02 06:37:06

by Maninder Singh

[permalink] [raw]
Subject: RE: [PATCH v4] scripts/checkpatch.pl: remove _deferred and _deferred_once false warning

Hi,

> On Mon, 2022-02-28 at 13:07 +0530, Maninder Singh wrote:
> > with commit 98e35f5894cf ("printk: git rid of [sched_delayed] message for
> > printk_deferred") printk_deferred and printk_deferred_once requires
> > LOGLEVEL in argument, but checkpatch.pl was not fixed and still reports
> > it as warning:
> >
> > WARNING: Possible unnecessary KERN_ALERT
> > printk_deferred(KERN_ALERT "checking deferred\n");
>
> I don't care for this patch at all.

But still it needs to be fixed, either with current suggested patch or with something else.

> There are many existing uses of printk_deferred both with and without a
> specific KERN_<LEVEL>.

Yes, Because earlier to this commit 98e35f5894cf, printk_deferred was expected
with KERN_WARNING by default.

- if (in_sched)
- text_len = scnprintf(text, sizeof(textbuf),
- KERN_WARNING "[sched_delayed] ");

But now it is aligned with normal printk level handling, only printing to console from current context
is avoided in case of deferred.
So earlier printk_deferred's should be fixed if it is meant to be printed on console with particular
level.

> printk_deferred currently always emits at LOGLEVEL_SCHED/KERN_DEFAULT.
>
> I think it's be better to modify vprintk_emit when LOGLEVEL_SCHED
> is used and if a KERN_<LEVEL> exists in the format, use it.
> Perhaps instead:
> ---
> kernel/printk/printk.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 1ce242f34d2be..6b5baf14f6d56 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2247,7 +2247,13 @@ asmlinkage int vprintk_emit(int facility, int level,
> return 0;
>
> if (level == LOGLEVEL_SCHED) {
> - level = LOGLEVEL_DEFAULT;
> + level = printk_get_level(fmt);
> + if (level) {
> + level -= '0';
> + fmt = printk_skip_level(fmt);
> + } else {
> + level = LOGLEVEL_DEFAULT;
> + }
> in_sched = true;
> }

And I think it is already handled for printk (facility = 0).
after setting level to KERN_DEFAULT at first for in_sched case to make it normal
printk case as it is changed from vprintk_store as per the string in printk based on
current default loglevel.

int vprintk_store(int facility, int level,
const struct dev_printk_info *dev_info,
const char *fmt, va_list args)
{
...
/* Extract log level or control flags. */
if (facility == 0)
printk_parse_prefix(&prefix_buf[0], &level, &flags);
..


u16 printk_parse_prefix(const char *text, int *level,
enum printk_info_flags *flags)
{
..
case '0' ... '7':
if (level && *level == LOGLEVEL_DEFAULT)
*level = kern_level - '0';
break;
...
}

So, for printk, printk_deferred, printk_deferred_once, its level is picked if its provided.
thus level in printk_deferred is "not unnecessary".
And checkpatch.pl should not give w WARNING for this.


Thanks,
Maninder Singh

2022-03-03 00:12:26

by Petr Mladek

[permalink] [raw]
Subject: Re: [PATCH v4] scripts/checkpatch.pl: remove _deferred and _deferred_once false warning

On Wed 2022-03-02 10:02:59, Maninder Singh wrote:
> Hi,
>
> > On Mon, 2022-02-28 at 13:07 +0530, Maninder Singh wrote:
> > > with commit 98e35f5894cf ("printk: git rid of [sched_delayed] message for
> > > printk_deferred") printk_deferred and printk_deferred_once requires
> > > LOGLEVEL in argument, but checkpatch.pl was not fixed and still reports
> > > it as warning:
> > >
> > > WARNING: Possible unnecessary KERN_ALERT
> > > printk_deferred(KERN_ALERT "checking deferred\n");
> >
> > I don't care for this patch at all.
>
> But still it needs to be fixed, either with current suggested patch or with something else.
>
> > I think it's be better to modify vprintk_emit when LOGLEVEL_SCHED
> > is used and if a KERN_<LEVEL> exists in the format, use it.
> > Perhaps instead:
> > ---
> > kernel/printk/printk.c | 8 +++++++-
> > 1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> > index 1ce242f34d2be..6b5baf14f6d56 100644
> > --- a/kernel/printk/printk.c
> > +++ b/kernel/printk/printk.c
> > @@ -2247,7 +2247,13 @@ asmlinkage int vprintk_emit(int facility, int level,
> > return 0;
> >
> > if (level == LOGLEVEL_SCHED) {
> > - level = LOGLEVEL_DEFAULT;
> > + level = printk_get_level(fmt);
> > + if (level) {
> > + level -= '0';
> > + fmt = printk_skip_level(fmt);
> > + } else {
> > + level = LOGLEVEL_DEFAULT;
> > + }
> > in_sched = true;
> > }
>
> And I think it is already handled for printk (facility = 0).

Yes, this is not needed. The log level will be updated by parsing
"fmt" even LOGLEVEL_SCHED was used. It is well described by Maninder
below.


> after setting level to KERN_DEFAULT at first for in_sched case to make it normal
> printk case as it is changed from vprintk_store as per the string in printk based on
> current default loglevel.
>
> int vprintk_store(int facility, int level,
> const struct dev_printk_info *dev_info,
> const char *fmt, va_list args)
> {
> ...
> /* Extract log level or control flags. */
> if (facility == 0)
> printk_parse_prefix(&prefix_buf[0], &level, &flags);
> ..
>
> So, for printk, printk_deferred, printk_deferred_once, its level is picked if its provided.
> thus level in printk_deferred is "not unnecessary".
> And checkpatch.pl should not give w WARNING for this.

Alternative solution would be to introduce pr_<level>_deferred()
wrappers. But there is a pushback against it. printk_deferred()
is a whack-a-mole approach. There is a chance that it will get
obsoleted by the offload to kthreads, see
https://lore.kernel.org/r/[email protected]

Best Regards,
Petr