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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9205AC433FE for ; Thu, 25 Nov 2021 14:49:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355857AbhKYOwV (ORCPT ); Thu, 25 Nov 2021 09:52:21 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:20190 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355922AbhKYOuU (ORCPT ); Thu, 25 Nov 2021 09:50:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637851628; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r0YfT7b8wVOeig/3+IUDAZI2A/DKcXL2UWIWBuICztQ=; b=ej9W3Fbf/IUcF9HbEuPoaqklwj3tyoT4a5DQQfJ+2UwZUs/c+3qa4sklIhVj5s+gA/Nvrf fhN0bk1hIe0S8/Z5Z2AkqAdOiPPUTo2EWJFC/yl/IOFf60vMMKRjUZw6MOxjrpSQZ0CGW6 BwXdiuk7fA6WQGi7h++Sb9A/2d1dKZg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-569-HevEeTaJN9Ob77Xes9Q75g-1; Thu, 25 Nov 2021 09:47:07 -0500 X-MC-Unique: HevEeTaJN9Ob77Xes9Q75g-1 Received: by mail-wm1-f71.google.com with SMTP id g11-20020a1c200b000000b003320d092d08so3340813wmg.9 for ; Thu, 25 Nov 2021 06:47:07 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=r0YfT7b8wVOeig/3+IUDAZI2A/DKcXL2UWIWBuICztQ=; b=uPtxJ8mcOvakaxEfo+ST482Vu4hEz5bfZjYbNbUQUkMYxMHbL7ztSpIvC6BLy6FSaP y+G6Z1BpV/7O2eachRxZWPc5J5zwZ//ndo6/7zQkqdEtuB8HiVFOxBPvgOfvZtP+YAIj I6AmmnwggO2iV/6uVbRdHKWOA8zv+FtkAP1+VdVYLhZunpWr/aqsAnme1i8/n825fn+l 9cqOvUNbjcASPD4TGySThZVx01v91hrX+M3+rDQCQbNryE5AEMUe7VzWflGLcbR4T8fq RWWthkv223/r4uPu4v7cLNvtne3qUjGy3pmtj5r8pAoZkX5S0h87EajMBT9bGOnmUAtk VX6A== X-Gm-Message-State: AOAM532wslcVhGyHReWPNFuDRRlnqeM4/PsoJ4i52bPH7J20DaIQm+xu v3wGJee3M4bob5XpQg3pQ4XCOpXZV7cEd7ZD0xj69X9cGKWCefVK0zi1FxLVJj4wDOaEkvB7usF 930Iw5hVFmwSGTIM8uOt9mBVy X-Received: by 2002:a7b:c763:: with SMTP id x3mr7962969wmk.31.1637851626023; Thu, 25 Nov 2021 06:47:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWw5wfsPq7LRSM9hRLSA4XFFZZK0hqXGaWJlTIAPX0085VuaF1bzZGOZEdl44rHrNuL6HnNg== X-Received: by 2002:a7b:c763:: with SMTP id x3mr7962942wmk.31.1637851625817; Thu, 25 Nov 2021 06:47:05 -0800 (PST) Received: from [192.168.3.132] (p5b0c679e.dip0.t-ipconnect.de. [91.12.103.158]) by smtp.gmail.com with ESMTPSA id be3sm9930088wmb.1.2021.11.25.06.47.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Nov 2021 06:47:05 -0800 (PST) Message-ID: <68615778-08cc-6216-1def-764dff112a72@redhat.com> Date: Thu, 25 Nov 2021 15:47:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v2] kthread: dynamically allocate memory to store kthread's full name Content-Language: en-US To: Petr Mladek Cc: Yafang Shao , akpm@linux-foundation.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, Steven Rostedt , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Alexei Starovoitov , Andrii Nakryiko , Michal Miroslaw , Peter Zijlstra , Matthew Wilcox , Al Viro , Kees Cook References: <20211120112850.46047-1-laoar.shao@gmail.com> <435fab0b-d345-3698-79af-ff858181666a@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 25.11.21 15:46, Petr Mladek wrote: > On Thu 2021-11-25 10:36:49, David Hildenbrand wrote: >> On 20.11.21 12:28, Yafang Shao wrote: >>> 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 >>> >>> Currently 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 can shorten these names to work around this problem, but it may be >>> not applied to all of the truncated kthreads. Take 'jbd2/nvme0n1p2-' for >>> example, it is a nice name, and it is not a good idea to shorten it. >>> >>> One possible way to fix this issue is extending the task comm size, but >>> as task->comm is used in lots of places, that may cause some potential >>> buffer overflows. Another more conservative approach is introducing a new >>> pointer to store kthread's full name if it is truncated, which won't >>> introduce too much overhead as it is in the non-critical path. Finally we >>> make a dicision to use the second approach. See also the discussions in >>> this thread: >>> https://lore.kernel.org/lkml/20211101060419.4682-1-laoar.shao@gmail.com/ >>> >>> After this change, the full name of these truncated kthreads will be >>> displayed via /proc/[pid]/comm: >>> >>> 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 >> >> I do wonder if that could break some user space that assumes these names >> have maximum length .. > > There is high chance that we will be on the safe side. Workqueue > kthreads already provided longer names. They are even dynamic > because the currently handled workqueue name is part of the name, > see wq_worker_comm(). Great, thanks! -- Thanks, David / dhildenb