linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Fw: [PATCHSET] workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status}
       [not found] <20180516214750.82710e21075ad1461dd4c04b@linux-foundation.org>
@ 2018-05-17  7:51 ` Alexey Dobriyan
  2018-05-17 17:01   ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Alexey Dobriyan @ 2018-05-17  7:51 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Tejun Heo, linux-kernel

On Wed, May 16, 2018 at 09:47:50PM -0700, Andrew Morton wrote:
> Alexey, can you please review the proc bits of this series?
> 
> Thanks.
> 
> Begin forwarded message:
> 
> Date: Wed, 16 May 2018 21:34:42 -0700
> From: Tejun Heo <tj@kernel.org>
> To: torvalds@linux-foundation.org, jiangshanlai@gmail.com, akpm@linux-foundation.org
> Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, kernel-team@fb.com, csmall@enc.com.au
> Subject: [PATCHSET] workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status}
> 
> 
> There can be a lot of workqueue workers and they all show up with the
> cryptic kworker/* names making it difficult to understand which is
> doing what and how they came to be.
> 
>  # ps -ef | grep kworker
>  root           4       2  0 Feb25 ?        00:00:00 [kworker/0:0H]
>  root           6       2  0 Feb25 ?        00:00:00 [kworker/u112:0]
>  root          19       2  0 Feb25 ?        00:00:00 [kworker/1:0H]
>  root          25       2  0 Feb25 ?        00:00:00 [kworker/2:0H]
>  root          31       2  0 Feb25 ?        00:00:00 [kworker/3:0H]
>  ...
> 
> This patchset makes workqueue workers report the latest workqueue it
> was executing for through /proc/PID/{comm,stat,status}.  The extra
> information is appended to the kthread name with intervening '+' if
> currently executing, otherwise '-'.
> 
>  # cat /proc/25/comm
>  kworker/2:0-events_power_efficient
>  # cat /proc/25/stat
>  25 (kworker/2:0-events_power_efficient) I 2 0 0 0 -1 69238880 0 0...
>  # grep Name /proc/25/status
>  Name:   kworker/2:0-events_power_efficient

I'd say anything that extends ->comm past 16 charactes is no-no.
The reason is that userspace may do something stupid like:

	char comm[16];

	start = strchr(s, '(');
	end   = strrchr(s, ')');
	// 16 bytes tops.
	memcpy(comm, s + start + 1, end - start);

I think procps-ng does strdup, but there is an infinite amount of
monitoring tools written.

Add /proc/*/wq for kernel threads which is A SYMBOLIC LINK,
and instantiate it only for kernel threads so it doesn't pollute icache
and dcache much. 4KB realink limit should be enough for kthreads.

Now I'm probably obligated to find such a broken userspace tool...

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

* Re: Fw: [PATCHSET] workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status}
  2018-05-17  7:51 ` Fw: [PATCHSET] workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status} Alexey Dobriyan
@ 2018-05-17 17:01   ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2018-05-17 17:01 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Andrew Morton, Tejun Heo, Linux Kernel Mailing List

On Thu, May 17, 2018 at 12:51 AM Alexey Dobriyan <adobriyan@gmail.com>
wrote:


> I'd say anything that extends ->comm past 16 charactes is no-no.
> The reason is that userspace may do something stupid like:

>          char comm[16];

Not may - does. We're already talking to the procps-ng people exactly
because of this.

That said, nobody actually mis-parses anything or overflows any buffers
(you'd actually have to work at it to do so), it's just that they don't
save the full length of the result.

So we can extend the kernel size (there are others who want it
independently of the workqueue issue), but some of the tools simply won't
show the full name until updated.

So instead of showing "[kworker/4:2-events]", current procps-ng shows
"[kworker/4:2-eve]" for example. Annoying, but not really any more cryptic
than the current situation without the patch.

               Linus

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

end of thread, other threads:[~2018-05-17 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20180516214750.82710e21075ad1461dd4c04b@linux-foundation.org>
2018-05-17  7:51 ` Fw: [PATCHSET] workqueue: Show the latest workqueue name in /proc/PID/{comm,stat,status} Alexey Dobriyan
2018-05-17 17:01   ` Linus Torvalds

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