LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.com>
To: Yafang Shao <laoar.shao@gmail.com>
Cc: akpm@linux-foundation.org, peterz@infradead.org,
	valentin.schneider@arm.com, keescook@chromium.org,
	mathieu.desnoyers@efficios.com, qiang.zhang@windriver.com,
	robdclark@chromium.org, viro@zeniv.linux.org.uk,
	christian@brauner.io, dietmar.eggemann@arm.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 5/5] kernel/kthread: show a warning if kthread's comm is still trucated
Date: Thu, 30 Sep 2021 17:17:25 +0200	[thread overview]
Message-ID: <YVXVBXSZ1m4ScvbX@alley> (raw)
In-Reply-To: <20210929115036.4851-6-laoar.shao@gmail.com>

On Wed 2021-09-29 11:50:36, Yafang Shao wrote:
> Show a warning if the ktrhead's comm is still trucated. Below is the
> result of my test case -
> 
> __kthread_create_on_node:410: comm of pid 14 is truncated from "I-am-a-kthread-with-long-name" to "I-am-a-kthread-with-lon"
> 
> Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
> ---
>  kernel/kthread.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/kernel/kthread.c b/kernel/kthread.c
> index 6def951c605a..aa093f1f423a 100644
> --- a/kernel/kthread.c
> +++ b/kernel/kthread.c
> @@ -404,7 +404,11 @@ struct task_struct *__kthread_create_on_node(int (*threadfn)(void *data),
>  		 * task is already visible to other tasks, so updating
>  		 * COMM must be protected.
>  		 */
> -		vsnprintf(name, sizeof(name), namefmt, args);
> +		if (vsnprintf(name, KTHREAD_COMM_LEN, namefmt, args) >=
> +		    KTHREAD_COMM_LEN)
> +			pr_warn("%s:%d: comm of pid %d is truncated from \"%s\" to \"%s\"\n",
> +				__func__, __LINE__, task->pid, namefmt, name);

The warning makes sense. But the use of "namefmt" looks wrong. It is
format and not the name. Also __func__ and __LINE__ is overkill. It will
be always the same.

I would do something like:

		len = vsnprintf(name, sizeof(name), namefmt, args);
		if (len >= KTHREAD_COMM_LEN) {
			pr_warn("truncated kthread comm:%s, pid:%d by %d characters\n",
				name, task->pid, len - KTHREAD_COMM_LEN + 1);
		}

Best Regards,
Petr

  parent reply	other threads:[~2021-09-30 15:17 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 11:50 [PATCH 0/5] kthread: increase the size of kthread's comm Yafang Shao
2021-09-29 11:50 ` [PATCH 1/5] kernel: replace sizeof(task->comm) with TASK_COMM_LEN Yafang Shao
2021-09-29 18:09   ` Kees Cook
2021-09-30 12:27     ` Yafang Shao
2021-10-03  3:31   ` Al Viro
2021-10-03 14:14     ` Yafang Shao
2021-09-29 11:50 ` [PATCH 2/5] kernel/fork: allocate task->comm dynamicly Yafang Shao
2021-09-29 13:08   ` Yafang Shao
2021-09-29 18:11   ` Kees Cook
2021-09-30 12:41     ` Yafang Shao
2021-09-30 14:51       ` Petr Mladek
2021-10-01 11:58         ` Yafang Shao
2021-09-29 11:50 ` [PATCH 3/5] kernel/sched: improve the BUILD_BUG_ON() in get_task_comm() Yafang Shao
2021-09-29 18:12   ` Kees Cook
2021-09-30 12:43     ` Yafang Shao
2021-09-29 11:50 ` [PATCH 4/5] kernel: increase the size of kthread's comm Yafang Shao
2021-09-29 18:19   ` Kees Cook
2021-09-30 12:53     ` Yafang Shao
2021-09-29 11:50 ` [PATCH 5/5] kernel/kthread: show a warning if kthread's comm is still trucated Yafang Shao
2021-09-29 18:20   ` Kees Cook
2021-09-30 12:54     ` Yafang Shao
2021-09-30 15:17   ` Petr Mladek [this message]
2021-10-01 11:59     ` Yafang Shao
2021-10-03  3:41 ` [PATCH 0/5] kthread: increase the size of kthread's comm Al Viro
2021-10-03 14:20   ` Yafang Shao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YVXVBXSZ1m4ScvbX@alley \
    --to=pmladek@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=christian@brauner.io \
    --cc=dietmar.eggemann@arm.com \
    --cc=keescook@chromium.org \
    --cc=laoar.shao@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=peterz@infradead.org \
    --cc=qiang.zhang@windriver.com \
    --cc=robdclark@chromium.org \
    --cc=valentin.schneider@arm.com \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH 5/5] kernel/kthread: show a warning if kthread'\''s comm is still trucated' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).