Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2291029pxf; Sat, 20 Mar 2021 10:25:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq+VKdK8PspgYyFwkXirskqQ5meKyYm12bpkuqxsU9R0fQ2pXNgPGsPE/7i8WmhmKdvrrX X-Received: by 2002:aa7:c497:: with SMTP id m23mr16541538edq.74.1616261138612; Sat, 20 Mar 2021 10:25:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616261138; cv=none; d=google.com; s=arc-20160816; b=I6Ne6L4y/0CHdXNyc2B8bvTcFJp2hoW+6BFseJ10tVyk/Zq6eKYLfALt7F8SbwMJxE GaHC77sagWBJ7cRAJ01v0sEFngAgtvEN7GeT8McNSJGdFjIR16NyciW+en0jLfFigCwt RBHsYDrKH7LH1JMxOrK7dUkx0toCKn9cB3fcKzZBnbFGCXe55ad+ec+L308YtLGzTxwW 5Gsj5iN6cRHaVIFK2zIRBAK36iB5RzWS9EXJfqDuN7GWjTg5Ju4DlOj8hYBV5EO6SjeB ImfxvMUG1CALTSLgfVxFO+9PBKcgGnObICQm9tYeMz/VjD6ZZo2w5k6xVyU8tP/nVOVh fvXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+xM+GGTqNKeaRa+33EhsUASZowFGPm/eogpWHPk9+14=; b=j9tFmVl2xr5H/OXNBGOz3hIemnFW2Am+pEu1tyimiPgfR/ahIssj2WiYnY3qYKDVOl gXFiYlNtYBlxEaVzMuVsbLsgrPkVPZA1RlhiBtzfAorA8BVWqUaKlOTROlL4YBwFQFyy 9aE2cmMEJNFpsUXTpWfEWKJlO7LP7gWYVPF56WJm6zdS2ybNf3tv7z48sEWXJ2sqoWmx RBTBmfYWubnix5lpvXEq0jyzwohMEnqBxKavPCAVLGS1Q5li7w07515Uksi+5R+a0CdA RiHZx2SLhr7Ki/RegOMhOppwdOfUogC44c5CsOLJQEYOtHbCJgQ9HEvn2eYlefcYIR1m 4YbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TPHe98WX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p25si6841602edm.297.2021.03.20.10.25.16; Sat, 20 Mar 2021 10:25:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TPHe98WX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbhCTRXs (ORCPT + 99 others); Sat, 20 Mar 2021 13:23:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:59530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229840AbhCTRX0 (ORCPT ); Sat, 20 Mar 2021 13:23:26 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 878546192D for ; Sat, 20 Mar 2021 17:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616261005; bh=/b25iKJZ9KZluzyNkg+H4bqhRAkDvPRLLwwMd97ZR+0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TPHe98WXNAl7xLc0QDXbr9795qTaPMEbiGwSoIjnmlrkPZZNoe2sAKfep58FWbzwK ghVRTxtNB7Nt0WQ4LYlEfXeFWWpTwlw3foUQnv1Uy9zTMiBcdIihU1EaSFz0f92LD9 B+7fAKqalctoc0qQG39d5o2qUiMvBkCji3VqYkWAzx8M50H/L5ZxBMSgcDW1/leTUJ 2PweDIHxtFj7hcM494kMCyfDqqbppwRvHAf0k0VdKycmUQwwRF27paNGZkWQn2f4YL qIVXgR5KhQ4LI1FWgxrHfW66b6GFQQi/0eqOlejFUEeDtvQEHboIkcyTNf/W+ea4ip IQ/8n+csOw+5g== Received: by mail-ej1-f48.google.com with SMTP id k10so14652778ejg.0 for ; Sat, 20 Mar 2021 10:23:25 -0700 (PDT) X-Gm-Message-State: AOAM532FZOZU1z8uVG3ma7S+J7axnQt8Lfs9HitY+DvEfUedrB1fr6f1 XlklMlCpU2MKFekSuHxypb1jiEDBq+iVXf10cy5ElA== X-Received: by 2002:a17:906:1494:: with SMTP id x20mr10645998ejc.101.1616261004125; Sat, 20 Mar 2021 10:23:24 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Andy Lutomirski Date: Sat, 20 Mar 2021 10:23:12 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] Document that PF_KTHREAD _is_ ABI To: Alexey Dobriyan Cc: Andrew Morton , LKML , Linux API Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Mar 20, 2021, at 9:31 AM, Alexey Dobriyan wrote: > > =EF=BB=BFPF_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#L35= 4 > 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? > > 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 :^) > > Note for beginner Linux programmers: > every other way you find on the interwebs and Stack Overflow > for checking if pid belongs to a kernel thread is broken one way or > another. > > Signed-off-by: Alexey Dobriyan > --- > > include/linux/sched.h | 3 +++ > 1 file changed, 3 insertions(+) > > --- a/include/linux/sched.h > +++ b/include/linux/sched.h > @@ -1566,6 +1566,9 @@ extern struct pid *cad_pid; > #define PF_MEMALLOC_NOIO 0x00080000 /* All allocation requests will= inherit GFP_NOIO */ > #define PF_LOCAL_THROTTLE 0x00100000 /* Throttle writes only agains= t the bdi I write to, > * I am cleaning dirty pages from some other bdi. = */ > +/* > + * PF_KTHREAD is part of kernel ABI, visible via value #9 in /proc/$pid/= stat > + */ > #define PF_KTHREAD 0x00200000 /* I am a kernel thread */ > #define PF_RANDOMIZE 0x00400000 /* Randomize virtual address sp= ace */ > #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */