From patchwork Mon Oct 25 08:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12581049 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6351AC4332F for ; Mon, 25 Oct 2021 08:34:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1BE8F61002 for ; Mon, 25 Oct 2021 08:34:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1BE8F61002 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id AF96A94000F; Mon, 25 Oct 2021 04:34:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AA508940007; Mon, 25 Oct 2021 04:34:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8830C94000F; Mon, 25 Oct 2021 04:34:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 75148940007 for ; Mon, 25 Oct 2021 04:34:09 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 361F91802E61B for ; Mon, 25 Oct 2021 08:34:09 +0000 (UTC) X-FDA: 78734297418.29.DCC159A Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by imf21.hostedemail.com (Postfix) with ESMTP id 0B026D0396E6 for ; Mon, 25 Oct 2021 08:34:05 +0000 (UTC) Received: by mail-pl1-f171.google.com with SMTP id f8so613780plo.12 for ; Mon, 25 Oct 2021 01:34:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=w7dW1iNbq1Wg2WuKYJlcYSndnkowZDcd1bFguHKF6IE=; b=U4i0No+EGDrlJQePYnoMIOFXR8R7nulw7jyU+4G06XBewuwtvRrbzHuzPd0qpgHOFA pcSNEIYL3ncWLV8C32z/LvGr7OsnV7o61Qie1FqPfkGj7vpzYELToUSZmNo8Ip3dZUhz BuCnVkXiLGcsBJG19c95EuFLLvDshR/dOYVCczQwJYqtgiKMU5TCBGR2iKr/JtqfF1vT N91zQnWaAmVc1UkEqkyAkH4BeiRGW/2Z9EzoW1rr9B6FWkZMUznOG6iyw/6c14qRkPRl kDbqpSwf19sWPYlrUhhTt1F1eI4WPYl7Yt7KKN1smPCDtwaZ03fW7SO6+/A/myUKSpDh mMVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=w7dW1iNbq1Wg2WuKYJlcYSndnkowZDcd1bFguHKF6IE=; b=L8qIBgz183AwG1ASMkgwUu3FXQAqwApbqA/KS9tWWysswf2zIobXur0+5TCSF5pFpT BHxFKGvB1U1jx31c8ZyPzZjpbMlG+/draJ9TB4UPsOmSfBPZPn+17UxkApMgaRe0P98q PEZZa+6FcJdPT/++iw+Ae7HacmrQOiK4BAzRtYOLAgl19aoi9zUoKChnJ+BmD42Lw9XD JEYlLC3m7ZCdOf3597VQ5rZQqSRp9FYJpROv3tCLJ66KbnYX3L2vHo78cbH4Ty8jEgi0 XjeWzwsQ+oEcUMY0uB0wie85SSSTqNdKGAvX6bzWoMNoChajwgk8lOPswuUvn8PKyYpi U77w== X-Gm-Message-State: AOAM532IYEC397IbwthZaKEygwZ386DtoQXJhXXAxMz4IBzWb4nlxqz8 1qWNt+ldB83ZP4KWRR0pIDI= X-Google-Smtp-Source: ABdhPJwFC4zTTp4l0K+QrkkRFDcEYhrKjwwpL/YCU9oKIw4H/35xwZzLIb7TJAj/167JmR/qYIhF5g== X-Received: by 2002:a17:90a:4890:: with SMTP id b16mr19994866pjh.82.1635150847878; Mon, 25 Oct 2021 01:34:07 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.34.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:34:07 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Andrii Nakryiko Subject: [PATCH v6 11/12] sched.h: extend task comm from 16 to 24 Date: Mon, 25 Oct 2021 08:33:14 +0000 Message-Id: <20211025083315.4752-12-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0B026D0396E6 X-Stat-Signature: e6w8aihi865n45gxy86ypdqita6axwwu Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=U4i0No+E; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.214.171 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1635150845-604442 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When I was implementing a new per-cpu kthread cfs_migration, I found the comm of it "cfs_migration/%u" is truncated due to the limitation of TASK_COMM_LEN. For example, the comm of the percpu thread on CPU10~19 are all with the same name "cfs_migration/1", which will confuse the user. This issue is not critical, because we can get the corresponding CPU from the task's Cpus_allowed. But for kthreads correspoinding to other hardware devices, it is not easy to get the detailed device info from task comm, for example, jbd2/nvme0n1p2- xfs-reclaim/sdf We can also shorten the name to work around this problem, but I find there are so many truncated kthreads: rcu_tasks_kthre rcu_tasks_rude_ rcu_tasks_trace poll_mpt3sas0_s ext4-rsv-conver xfs-reclaim/sd{a, b, c, ...} xfs-blockgc/sd{a, b, c, ...} xfs-inodegc/sd{a, b, c, ...} audit_send_repl ecryptfs-kthrea vfio-irqfd-clea jbd2/nvme0n1p2- ... We should improve this problem fundamentally by extending comm size to 24 bytes. task_struct is growing rather regularly by 8 bytes. After this change, the truncated kthreads listed above will be displayed as: rcu_tasks_kthread rcu_tasks_rude_kthread rcu_tasks_trace_kthread poll_mpt3sas0_statu ext4-rsv-conversion xfs-reclaim/sdf1 xfs-blockgc/sdf1 xfs-inodegc/sdf1 audit_send_reply ecryptfs-kthread vfio-irqfd-cleanup jbd2/nvme0n1p2-8 As we have converted all the unsafe copy of task comm to the safe one, this change won't make any trouble to the kernel or the in-tree tools. The safe one and unsafe one of comm copy as follows, Unsafe Safe strlcpy strscpy_pad strncpy strscpy_pad bpf_probe_read_kernel bpf_probe_read_kernel_str bpf_core_read_str bpf_get_current_comm perf_event__prepare_comm prctl(2) Regarding the possible risk it may take to the out-of-tree user tools, if the user tools get the task comm through kernel API like prctl(2), bpf_get_current_comm() and etc, the tools still work well after this change. While If the user tools get the task comm through direct string copy, it must make sure the copied string should be with a nul terminator. Signed-off-by: Yafang Shao Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- include/linux/sched.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index 124538db792c..490d12eabe44 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -279,7 +279,7 @@ struct task_group; * BPF programs. */ enum { - TASK_COMM_LEN = 16, + TASK_COMM_LEN = 24, }; extern void scheduler_tick(void);