From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E841C36010 for ; Fri, 4 Apr 2025 06:35:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 360586B0022; Fri, 4 Apr 2025 02:35:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30DD36B0023; Fri, 4 Apr 2025 02:35:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D88E6B0024; Fri, 4 Apr 2025 02:35:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0093D6B0022 for ; Fri, 4 Apr 2025 02:35:47 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8A19D1621D4 for ; Fri, 4 Apr 2025 06:35:48 +0000 (UTC) X-FDA: 83295400776.05.8967426 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) by imf30.hostedemail.com (Postfix) with ESMTP id BF4B58000C for ; Fri, 4 Apr 2025 06:35:45 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=VLtktzyg; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf30.hostedemail.com: domain of bhsharma@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=bhsharma@igalia.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743748546; a=rsa-sha256; cv=none; b=J3h31vXSxmXhuHnAdo2b8RGbgC91D3vspd4nD7S3GDzeYtp6Hyal7+UlfyhT8IoRLj1iSa ppxAbIhOMtbCReNANpVVxNS+UMYiY/BFetKUgUm87vwLWOv+WuzSX04gJuzgDvoju30OG1 hwIxOvG9OdmQrieuhN6QYcajCZ5CGus= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=igalia.com header.s=20170329 header.b=VLtktzyg; dmarc=pass (policy=none) header.from=igalia.com; spf=pass (imf30.hostedemail.com: domain of bhsharma@igalia.com designates 178.60.130.6 as permitted sender) smtp.mailfrom=bhsharma@igalia.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743748546; h=from:from:sender: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:dkim-signature; bh=0rog/nxboMHnwuFuI69UvOFfP3CGYosW55e+1Io3x50=; b=b4xzuGBSJiSwMDiv1JbD3/WWI6WIXWMYGGgZ0VKrsTywCGHbx0pJ+dmhzsB+CFYZ1XiHdM lmR9/V7bDLljqtx/ZH71RAcNHigFG/7HGNLGQ/UbrxYJAtyOZQg4deuhhjiuxconr8XvRk sdJVnajGRnbop1TZJ1+4XIZNQS+51ko= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=0rog/nxboMHnwuFuI69UvOFfP3CGYosW55e+1Io3x50=; b=VLtktzygHenGP22YTGx9UMPXIs obpPCT9aIas2r7evBpL2D0bb1js6q0i/B4uC2opnWfDUipcfONy+0g0IbelLJS8aWQuyS2PsuDIdm 7w0cjzbWLsM7LHRK3mT51Cc3k9Ln/ZQIsH1KX/wq6HZzUcbB72ZYToUAJurnXWcFJEdpGZUbdw3BA eh4hfAftwtmwzZFx1nZQs65zJEKslflvY7h601Fs48wxfKauy8fCWwVUIJ5I1FVouXn1lFW/1ES93 UOhDoOM9fSM2eyYscL3Uhqe7g8Qpi9xnwtjK0geFQUNqmvLdom5iBDTzulTdeQFl3ou1zbJmbqssb K7OyNpGw==; Received: from [223.233.74.223] (helo=[192.168.1.12]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim) id 1u0aeJ-00BDab-Pv; Fri, 04 Apr 2025 08:35:32 +0200 Message-ID: <6beead5a-8c21-af57-0304-1bf825588481@igalia.com> Date: Fri, 4 Apr 2025 12:05:26 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2 1/3] exec: Dynamically allocate memory to store task's full name Content-Language: en-US To: Yafang Shao , Bhupesh , Linus Torvalds Cc: akpm@linux-foundation.org, kernel-dev@igalia.com, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, oliver.sang@intel.com, lkp@intel.com, pmladek@suse.com, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, alexei.starovoitov@gmail.com, andrii.nakryiko@gmail.com, mirq-linux@rere.qmqm.pl, peterz@infradead.org, willy@infradead.org, david@redhat.com, viro@zeniv.linux.org.uk, keescook@chromium.org, ebiederm@xmission.com, brauner@kernel.org, jack@suse.cz, mingo@redhat.com, juri.lelli@redhat.com, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com References: <20250331121820.455916-1-bhupesh@igalia.com> <20250331121820.455916-2-bhupesh@igalia.com> From: Bhupesh Sharma In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BF4B58000C X-Stat-Signature: kxpepcj8bi5tbqs18d7otdgsmss5bwbd X-Rspam-User: X-HE-Tag: 1743748545-915021 X-HE-Meta: U2FsdGVkX1/EGXAWVDL81Sid0FnmDpLlFuCoh/PvpVPNy1Fao9NjNzB8GhFhLep/Ri83Nz2E4BbP9t1eGCJk2eJMo5/J7sRxl9YxYrobZaW7+12HWkeLZiSM8U4vK3HP8csrbYnnagJPkntfqJfGf+QBMwKIWRBG+66w63IhpSZjvKR0Y+pu5eRO0bctdN9kVX9LKxyblyJAHU7dFIsyP/HTwOIfyNe7GllMDt9M12AudPe6pYt3VafcpbFA7pZSMmk30379FLprjzhPwOizHNgwpMa5id1vaLl6g6Id+POJtn7jVEC7q3l2ZN5+XH0pxWznzp4wXMzqoHGjrPsTWonEwq5xPs/HY8xGTIy7vuA2Z+CXi3w7tfsiMvmgxtVHr3KiNsVfo88BRwGL9U1LdVmwHMq+VD2cZRehQ/HBDGcEsom3YEkC/b9vrPIJJkdo3OQNMUuYINGGb3zmSKng83KjQU0wuoOWkLwyl3TIDS/zRvDTpsoE7dWDqMRL3PKrY6y488bA5UD3qrit5/RE0BE+qf0MtijduM6cg1V6DRRl9H0urcYHtwQ095dD9uOMjdpsyuoavCMAMSdlGTP6SJuT66Gu40lWZd555VJNjGgT5655B3Tj/3XpXpw6kOZaxuEwV8I5jA37kaQTOexGWHdcwG7eGrA/Q4EFVRYVHqohI7aqP3lrmlbIpsLs/l0dls3SiSdXORWYVFuzdddbjqKwuJg2Mfhd7YA4SmLgbu4X1ndFnvshLugZxMaeIopsGn+AkDdVmENQQS+MG4gHOhbYLvtp6OI3QuXKVtxhhS6Zad/qS8GwUdqRBinqMfpp27VRcF2ATloI2CO5mC+uOsI+oLTvpM+rQDxzmC+fR+cCR67LsZfda4xOuNNDro1YOMROv5H/OICtHvO1l0GmMfZULbdp8tIJ+XhNRQKDoX+QmzAWsf5fJD1PVtshUFv2HTMzCYC+HC3+GT99UMs 4qhCbwct uregVKz94E/jA8XhZdtVFyNB58bH6tF8r8s7DJH9jvrOWZFVrXhb8nNteMPyC/1n4dYLsZvF59RBtSkfqAdT5rmUVxQ9BF/GgAA6e7kUWqosahHpQuhjGjgBrGUak0TGhJ0cAmjVfjasphqwOanP+ioA3RJZ8DsynipGNjIRYGH32CS/XdFaNKGCMSWu2UTqvPGVhfgu5WaU8OxJSCY3nmBglk4Oz0g1sIG0Q/KaZP/GmKj1ZJqwLGvT+9ekd4xtSp10hucjS2X4onqJpSJFUEfxFpq4Vqphm3yvacX7S/Z/eGwxk2mWb2Ie4uNoGuvnvimL95G9FJdMjzqdCvYWFgIV+mCtARyBOvSVFr9TrWU1qKvb8Hjlhy8qdMKypH2dBBI/HV3+VcO+HMQZuhUVUcMtR8/hiwF5uObK/ainLXgbjXCI= 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: List-Subscribe: List-Unsubscribe: On 4/1/25 7:37 AM, Yafang Shao wrote: > On Mon, Mar 31, 2025 at 8:18 PM Bhupesh wrote: >> Provide a parallel implementation for get_task_comm() called >> get_task_full_name() which allows the dynamically allocated >> and filled-in task's full name to be passed to interested >> users such as 'gdb'. >> >> Currently while running 'gdb', the 'task->comm' value of a long >> task name is truncated due to the limitation of TASK_COMM_LEN. >> >> For example using gdb to debug a simple app currently which generate >> threads with long task names: >> # gdb ./threadnames -ex "run info thread" -ex "detach" -ex "quit" > log >> # cat log >> >> NameThatIsTooLo >> >> This patch does not touch 'TASK_COMM_LEN' at all, i.e. >> 'TASK_COMM_LEN' and the 16-byte design remains untouched. Which means >> that all the legacy / existing ABI, continue to work as before using >> '/proc/$pid/task/$tid/comm'. >> >> This patch only adds a parallel, dynamically-allocated >> 'task->full_name' which can be used by interested users >> via '/proc/$pid/task/$tid/full_name'. >> >> After this change, gdb is able to show full name of the task: >> # gdb ./threadnames -ex "run info thread" -ex "detach" -ex "quit" > log >> # cat log >> >> NameThatIsTooLongForComm[4662] >> >> Signed-off-by: Bhupesh >> --- >> fs/exec.c | 21 ++++++++++++++++++--- >> include/linux/sched.h | 9 +++++++++ >> 2 files changed, 27 insertions(+), 3 deletions(-) >> >> diff --git a/fs/exec.c b/fs/exec.c >> index f45859ad13ac..4219d77a519c 100644 >> --- a/fs/exec.c >> +++ b/fs/exec.c >> @@ -1208,6 +1208,9 @@ int begin_new_exec(struct linux_binprm * bprm) >> { >> struct task_struct *me = current; >> int retval; >> + va_list args; >> + char *name; >> + const char *fmt; >> >> /* Once we are committed compute the creds */ >> retval = bprm_creds_from_file(bprm); >> @@ -1348,11 +1351,22 @@ int begin_new_exec(struct linux_binprm * bprm) >> * detecting a concurrent rename and just want a terminated name. >> */ >> rcu_read_lock(); >> - __set_task_comm(me, smp_load_acquire(&bprm->file->f_path.dentry->d_name.name), >> - true); >> + fmt = smp_load_acquire(&bprm->file->f_path.dentry->d_name.name); >> + name = kvasprintf(GFP_KERNEL, fmt, args); >> + if (!name) >> + return -ENOMEM; >> + >> + me->full_name = name; >> + __set_task_comm(me, fmt, true); >> rcu_read_unlock(); >> } else { >> - __set_task_comm(me, kbasename(bprm->filename), true); >> + fmt = kbasename(bprm->filename); >> + name = kvasprintf(GFP_KERNEL, fmt, args); >> + if (!name) >> + return -ENOMEM; >> + >> + me->full_name = name; >> + __set_task_comm(me, fmt, true); >> } >> >> /* An exec changes our domain. We are no longer part of the thread >> @@ -1399,6 +1413,7 @@ int begin_new_exec(struct linux_binprm * bprm) >> return 0; >> >> out_unlock: >> + kfree(me->full_name); >> up_write(&me->signal->exec_update_lock); >> if (!bprm->cred) >> mutex_unlock(&me->signal->cred_guard_mutex); >> diff --git a/include/linux/sched.h b/include/linux/sched.h >> index 56ddeb37b5cd..053b52606652 100644 >> --- a/include/linux/sched.h >> +++ b/include/linux/sched.h >> @@ -1166,6 +1166,9 @@ struct task_struct { >> */ >> char comm[TASK_COMM_LEN]; >> >> + /* To store the full name if task comm is truncated. */ >> + char *full_name; >> + > Adding another field to store the task name isn’t ideal. What about > combining them into a single field, as Linus suggested [0]? > > [0]. https://lore.kernel.org/all/CAHk-=wjAmmHUg6vho1KjzQi2=psR30+CogFd4aXrThr2gsiS4g@mail.gmail.com/ > Thanks for sharing Linus's suggestion. I went through the suggested changes in the related threads and came up with the following set of points: 1. struct task_struct would contain both 'comm' and 'full_name', 2. Remove the task_lock() inside __get_task_comm(), 3. Users of task->comm will be affected in the following ways:     (a). Printing with '%s' and tsk->comm would just continue to work,but will get a longer max string.     (b). For users of memcpy.*->comm\>', we should change 'memcpy()' to 'copy_comm()' which would look like: memcpy(dst, src, TASK_COMM_LEN); dst[TASK_COMM_LEN-1] = 0; (c). Users which use "sizeof(->comm)" will continue to get the old value because of the hacky union. Am I missing something here. Please let me know your views. Thanks, Bhupesh