linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Andy Lutomirski <luto@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Linux API <linux-api@vger.kernel.org>
Subject: Re: [PATCH] Document that PF_KTHREAD _is_ ABI
Date: Sat, 20 Mar 2021 20:39:09 +0300	[thread overview]
Message-ID: <YFYzPcHKWm3U04pN@localhost.localdomain> (raw)
In-Reply-To: <CALCETrUPAvUOr8V5db0gu5RKVftKFwbBEkh6Aob57v+D-xdEig@mail.gmail.com>

On Sat, Mar 20, 2021 at 10:23:12AM -0700, Andy Lutomirski wrote:
> > On Mar 20, 2021, at 9:31 AM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
> >
> > PF_KTHREAD value is visible via field number 9 of /proc/*/stat
> >
> >    $ sudo cat /proc/2/stat
> >    2 (kthreadd) S 0 0 0 0 -1 2129984 0 ...
> >                  ^^^^^^^
> >
> > It is used by at least systemd to check for kernel-threadness:
> > https://github.com/systemd/systemd/blob/main/src/basic/process-util.c#L354
> > src/basic/process-util.c:is_kernel_thread()
> 
> Eww.
> 
> Could we fix it differently and more permanently by modifying the proc
> code to display the values systemd expects?

Right now there is no need to fix anything because 4 bits are available.
I put a comment so that PF_KTHREAD won't be moved accidently definitely
breaking systemd.

> > It means that the value can't be changed despite perceived notion that
> > task_struct flags are internal to kernel and can be shuffled at whim.
> >
> > Formally, _all_ struct task_struct::flags PF_* values are kernel ABI
> > which is a disaster.
> >
> > I hope we can mask everything but few flags and hope for the best :^)

> > +/*
> > + * PF_KTHREAD is part of kernel ABI, visible via value #9 in /proc/$pid/stat
> > + */
> > #define PF_KTHREAD        0x00200000    /* I am a kernel thread */

I think everything should be masked except PF_KTHREAD and maybe few
flags for which known users exist and then don't touch them.

Some flags are clearly internal like PF_MEMALLOC and PF_IDLE.

Some aren't -- PF_FORKNOEXEC. However it is silly for userspace to query it
because programs knows if it forked but didn't exec without external help.

  reply	other threads:[~2021-03-20 17:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-20 16:30 [PATCH] Document that PF_KTHREAD _is_ ABI Alexey Dobriyan
2021-03-20 17:23 ` Andy Lutomirski
2021-03-20 17:39   ` Alexey Dobriyan [this message]
2021-03-20 19:20     ` Florian Weimer
2021-03-22  7:53   ` Christoph Hellwig
2021-03-31 19:23     ` Alexey Dobriyan
2021-04-01 15:05       ` Stefan Metzmacher

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=YFYzPcHKWm3U04pN@localhost.localdomain \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).