Thread (6 messages) flat view 6 messages, 4 authors, 2021-04-01

Re: [PATCH] Document that PF_KTHREAD _is_ ABI

From: Alexey Dobriyan <hidden>
Date: 2021-03-20 17:40:08
Also in: lkml

On Sat, Mar 20, 2021 at 10:23:12AM -0700, Andy Lutomirski wrote:
quoted
On Mar 20, 2021, at 9:31 AM, Alexey Dobriyan [off-list ref] 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.
quoted
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 :^)
quoted
+/*
+ * 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help