Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2265469pxf; Sat, 20 Mar 2021 09:34:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVzDQDkoHKuRrEPUB/8XokTlAMk2TUzbYgcC7Fio3/I7eTHTtpZcGkIRz2UHZCpyhOOscE X-Received: by 2002:a17:906:f56:: with SMTP id h22mr10673301ejj.494.1616258085646; Sat, 20 Mar 2021 09:34:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616258085; cv=none; d=google.com; s=arc-20160816; b=dBkYg10wBxJQ/QvIWhU4R4jmRocYVgTHgACcSc5n9t+FGH070nPqqkkaJJ1Jdk6vL6 2hYFztesRoHQg4jvt5fLV58kfO/Er3KHfFuwQyQujkokugMPuo7aGFj86IA+AeIIF5dY skBfseecsjZRvCBki8996ktu02n4npF5WgYmUdM6gDEt1/LQCed2czuyljSMm/nVTdv9 WeQiA0Jqn8xst/pk6EDHbST0PJE6jlUzZvWXRduqm+51JCUTDfaRzts6uHXW7j3oeRDN yilOFzcMWC4iX2w6hP5lqnqQqBT24yynPE42/Q1LjeJ9Wn1ZKPdzG4M7ZhPMig+MDGSq 7gsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=krowSy1qOb6baq8siG2DkcMBMFG/XPZkvaDkKFj+3Jk=; b=tA7xpRDlE4GT3rkB7vkMqefI1AhVA5oYrDrcbSCusNYcGDXF+VLNoDyx4awkY0usZB ZR5fG6fD0AYAckSQVLW9JNMezRed3PntDAk3oNbNcwbPmqRlNXQPD/TCm1JW0n1Lnt9S qH/jgPlW6pYkXgBwlR6PXFp++Fk9Mg3Tad7m+gNchbe/w1WvoyGXke/kEFers6M/4GEH o08XHjhfKkEYTGaU1elLpe1zJmqG4boSZ0UrQEmjDZ0qCOsfDNpfjZknjWJAGroCwc8y ZC9oiWqeIYjiWZgn3DZsU4Wuz4t/hWZYVuNkwBFUlwlnopv6Je0cchc39l/ghFRLXOxb 1R7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=V3dQbMpC; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gv18si7219603ejc.674.2021.03.20.09.34.23; Sat, 20 Mar 2021 09:34:45 -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=@gmail.com header.s=20161025 header.b=V3dQbMpC; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbhCTQbP (ORCPT + 99 others); Sat, 20 Mar 2021 12:31:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229780AbhCTQaw (ORCPT ); Sat, 20 Mar 2021 12:30:52 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2543C061574; Sat, 20 Mar 2021 09:30:51 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id jy13so14486025ejc.2; Sat, 20 Mar 2021 09:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=krowSy1qOb6baq8siG2DkcMBMFG/XPZkvaDkKFj+3Jk=; b=V3dQbMpC5FUnNbOCzKlRG8CeS1LagpymcblrFYVop9Cek9l35jtwY6Wz1maEZ0XPwh ++FZ7BdeNlxVf1oyxiuqiPUL2EtglhsoPo6EXmLXx3DSRWuisf69q72/gubK2deZjYPu awQwAUpqD2t+PdfTL8MLhxLELJFf2Dm4UyNtIWCUENLqdh1EPt7AE61Glh9mp24BF5T/ 5O6/qAyjcbju8PzGsSCjl8GEQ7hVfVLPY2lYsPr50cvfL1SRhWz2W89bIC0vxFZDqBtz KGKJBxR3cDiOx5OBDJzG1B5d6jEva8BNh/0H7ukiK7B3YCjUenEA+0Un+ZHZ5ugid7hv Dl0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=krowSy1qOb6baq8siG2DkcMBMFG/XPZkvaDkKFj+3Jk=; b=soQDYEBu1O/eapTwNxFoex6lit3aQ6ZWsvBWYzx0EnWOItOIdwA2vZXXr4gjgha1I1 NO2SAuU3mASQj631iNFZdHY4eTL8WZkbQYrghHey7S3owtlYB07Cy8QwpFYMO1IWgCJN UfjSsNeh3zhnKHQrCDyn4i1p5gQo+y17ZWFRMzXN/JD0HkFxFKJROBja2FlwffvREun9 V3A1e7JIr4klFl6SSy9mws3vmSTZbZfoqYQaMwmlksCnldqernH/NQUGJ5NUkBYZ8bZF gbJd2cfGappfv5MgkPCd9qBZa+nwvngyDhdxKoHetZ1hDcdrNXd+fwbVGNiVuTiL4ztw uS8w== X-Gm-Message-State: AOAM531viiMLiimfhSjBEUBGyUnG9stwaJIHbdR0GIssHvyEs6kBYVsi jFclSgImGEG+nQfRV91cymZ+ZCn+rw== X-Received: by 2002:a17:906:e2d4:: with SMTP id gr20mr10683539ejb.432.1616257850724; Sat, 20 Mar 2021 09:30:50 -0700 (PDT) Received: from localhost.localdomain ([46.53.248.213]) by smtp.gmail.com with ESMTPSA id v24sm5586298ejw.17.2021.03.20.09.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 09:30:50 -0700 (PDT) Date: Sat, 20 Mar 2021 19:30:48 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org Subject: [PATCH] Document that PF_KTHREAD _is_ ABI Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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() 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 against 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 space */ #define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */