Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp631911pxb; Thu, 30 Sep 2021 13:36:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXf/+4waz1paZuyxJBlfZLIUraQ8zsQ0J3xbcJfniGfeyvq0Jotu//7deL3h4A7AsaBVf+ X-Received: by 2002:a62:7dd3:0:b0:447:dd44:1580 with SMTP id y202-20020a627dd3000000b00447dd441580mr6178626pfc.19.1633034164570; Thu, 30 Sep 2021 13:36:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633034164; cv=none; d=google.com; s=arc-20160816; b=AZ4ue5hDk7H5FPdmr8m3MONCqFs5xsQLPIhqLd5YCxl1XG4SIuJ9xiFRMan1zwqy9C 9FsUMJMe9gXyfsHf81Q1LY983LsGbtw5/ISQUWQ2Gqd29Hl5r7+1KCxvLd4cBb7FR6nP 7cinjivvkBraDVhm+3qwxgHSIERY+flAgOn3fg2wd8M+SK2RapR5RaD98gXf9jfvEYnt KkX0A53xC1shgVsKoVYQw9kYOHMRCYkR3cG8feHH6i+pqUeSJLhOgOvw0ioqVNzmuGrl lxFeHtembUScqDxJRVofk6zcID4WEKKj5xkRhR5j49O6Dge/g8pA0h7WGd4P3jYikv0t EEhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=7UMsJP7OUZHXdosqHccx8PfVbVZmFr+TX6TvsVLAlzc=; b=LyGClt2b93vFgLl5MGcRVVl8B5nxJNjEbCE98jZtfvzT/eqz56O+tzJcWPYREf+0Jl LZbH+xGrFS1AXXsYY2COTGyDRJC/xg0Osu/Urezh2P3sNb74nMeyOzaPVyn7cxXAuTYt MeqWHiFLEG6H0knqS7Y08GQikz95F76H5FCGcURP+oXiowJV4uHC7cM+QLxQ2k+ASWaa tnJq0rntHw7G2lqGcn6I2Xmlb9AUHRUVOr8jiWa0OL/SrjIgeYKn2TI++9HKIGaC4lP9 ucmJeHAAoj9D3njmUJovDpb5+WJCZ57AX4Uu1UsR6efHHTVDfGIDxw5wOySKqYxSRRXT uu0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="p9jN8Yu/"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si4257093pli.167.2021.09.30.13.35.48; Thu, 30 Sep 2021 13:36:04 -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=@suse.com header.s=susede1 header.b="p9jN8Yu/"; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351980AbhI3Ox0 (ORCPT + 99 others); Thu, 30 Sep 2021 10:53:26 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:46860 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351935AbhI3Ox0 (ORCPT ); Thu, 30 Sep 2021 10:53:26 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id AA2232003B; Thu, 30 Sep 2021 14:51:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1633013502; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7UMsJP7OUZHXdosqHccx8PfVbVZmFr+TX6TvsVLAlzc=; b=p9jN8Yu/BpaUeW4SkvSnWNgOZFT8eYkXWF5kfKD2iHa4ZAK41E9HtNVO69KcpRqfZ/w6/p 8mKwf3SFDGcFiFbO99VDsahxQRiM2G4poXJjGvf2XOJq+VpOYLW5tAIjEhUkhJxKNiF5MT aMDLXu8ipzyoFNYYcp/fyqA1OAFqr+w= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 401D4A4666; Thu, 30 Sep 2021 14:51:42 +0000 (UTC) Date: Thu, 30 Sep 2021 16:51:42 +0200 From: Petr Mladek To: Yafang Shao Cc: Kees Cook , Andrew Morton , Peter Zijlstra , Valentin Schneider , Mathieu Desnoyers , qiang.zhang@windriver.com, robdclark@chromium.org, Al Viro , christian@brauner.io, Dietmar Eggemann , LKML Subject: Re: [PATCH 2/5] kernel/fork: allocate task->comm dynamicly Message-ID: References: <20210929115036.4851-1-laoar.shao@gmail.com> <20210929115036.4851-3-laoar.shao@gmail.com> <202109291109.FAF3F47BA@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 2021-09-30 20:41:40, Yafang Shao wrote: > On Thu, Sep 30, 2021 at 2:11 AM Kees Cook wrote: > > > > On Wed, Sep 29, 2021 at 11:50:33AM +0000, Yafang Shao wrote: > > > task->comm is defined as an array embedded in struct task_struct before. > > > This patch changes it to a char pointer. It will be allocated in the fork > > > and freed when the task is freed. > > > > > > Signed-off-by: Yafang Shao > > > --- > > > include/linux/sched.h | 2 +- > > > kernel/fork.c | 19 +++++++++++++++++++ > > > 2 files changed, 20 insertions(+), 1 deletion(-) > > > > > > diff --git a/include/linux/sched.h b/include/linux/sched.h > > > index e12b524426b0..b387b5943db4 100644 > > > --- a/include/linux/sched.h > > > +++ b/include/linux/sched.h > > > @@ -1051,7 +1051,7 @@ struct task_struct { > > > * - access it with [gs]et_task_comm() > > > * - lock it with task_lock() > > > */ > > > - char comm[TASK_COMM_LEN]; > > > + char *comm; > > > > This, I think, is basically a non-starter. It adds another kmalloc to > > the fork path without a well-justified reason. TASK_COMM_LEN is small, > > yes, but why is growing it valuable enough to slow things down? > > > > (Or, can you prove that this does NOT slow things down? It seems like > > it would.) > > > > Right, the new kmalloc would take some extra latency. > Seems it is not easy to measure which one is more valuable. Honestly, I do not think that this exercise is worth it. The patchset adds a lot of complexity and potential problems just to extend comm from 16 to 24 for kthreads. Is the problem real or just cosmetic? If you really want it then it would be much easier to increase TASK_COMM_LEN. task_struct is growing rather regularly. Extra 8 bytes should be acceptable. If you want to make it more acceptable then keep 16 for CONFIG_BASE_SMALL. > > > diff --git a/kernel/fork.c b/kernel/fork.c > > > index 38681ad44c76..227aec240501 100644 > > > --- a/kernel/fork.c > > > +++ b/kernel/fork.c > > > @@ -753,6 +767,7 @@ void __put_task_struct(struct task_struct *tsk) > > > bpf_task_storage_free(tsk); > > > exit_creds(tsk); > > > delayacct_tsk_free(tsk); > > > + task_comm_free(tsk); Just one example of the potential problems. Are you sure that nobody will access tsk->comm after this point? task->comm is widely used to describe the affected task_struct because it is user friendly. Also __put_task_struct() later calls also profile_handoff_task() that might get registered even by some external module. Best Regards, Petr PS: I think that the fork performance is important. It is tested by benchmarks, for example, lmbench. But for me, the reliability is even more important and any pointer/alloc/free just adds another weak point.