From patchwork Tue Feb 6 11:31:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197333 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1479313dyb; Tue, 6 Feb 2024 03:45:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvh5oy4fh1DBIU4K9wrDoMHhmC+aFRa0V66SuDiw6oSuwq8GFuWoY8ZX8P0oDei1qTGFRD X-Received: by 2002:a05:6358:d048:b0:176:4aae:515c with SMTP id jb8-20020a056358d04800b001764aae515cmr2672753rwb.17.1707219923241; Tue, 06 Feb 2024 03:45:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707219923; cv=pass; d=google.com; s=arc-20160816; b=RqJoY6k3hURfPwH7c04cSMvcOF42M2mGIZY3Jb3ylD58T33cB8PuBrO6bSn8cKQYme fd3IUhgUpNKSD+24HrJ3RnVMIeDJXFu043u5ahIDXST1N6xZpW1KETMGAXLs43BrcF0z Yqn18zwlqxaDqjvCikOy4GUET/1D1p0UGFB58r71tUywVZfpiYj8lP5a4l0AV1ZYxZpG Mh9d3GpKvNonfUFqQk6L+jmW9lx+YDmtx/wy3l8f7joiMioYxVBH0qM+/LnoBaME1M5K BtRcryL+ZfuBCuBuDf3OtmMp1Q13VAbBVYeWDiNrVItyBbA3ca22STHi2NqSokJYLl+E Vutg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=uXyNTi+hcecekKn8pb9kUZDns5PCP3zA+0J9cysBCZk=; fh=pr6DRTO2GnTiuf3ykTtZP1DysMERSUEhwK4PGyideV8=; b=oKFmOH0r57QqWu6LpqQxQKIbEy+0p5CxF4dvv550DsX9OaCuVN2e/i0XXNVFqT/udc 3z8SwUbMIWk14TmOWlVsjMnT52ncVPa47I1+VK6X73ZqSPDe6QWBou6TtH1+TRAqoy46 NnDuLLQYG5jaanIfIDJXIOUfmwPZne/0JMpBlUosGLwKxZXWnlfI4g1tTXV6gP5pg/4B JZ8TXzxQToN/BmhhwtOZEMj1m8OdwnTd4pqtadHPdOdSRccXfjvWlRq9lDc8KtBUzfqk OFpkSs1CrGvdpZzFjcuzk0QMQzRR8hNaZk9kX2yAUwyMXuKtoWMRszEI8R4J5i+/1Mgt YnHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54787-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54787-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWuj6qobI7rv5mV8pGTiJnSCuB2JoDb4JAPeaHxcGX79Q/BXrkLTvebsCeXdXBnKU+SOuV46biqnrV6GSkpNEXQw8OCng== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u8-20020a63f648000000b005d44d02525bsi1499435pgj.633.2024.02.06.03.45.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:45:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54787-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54787-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54787-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2F9D12879D8 for ; Tue, 6 Feb 2024 11:44:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 431FD134CF2; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA185130E4A; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; cv=none; b=RU9fsoUCyYq1sFCvm73mIUh5/tPNI+FiG7Qn2S7gBbdFhRae6XMjJcF5nDTg95vsLPvYla0K8/3iCCEFNzHtN+9BxXLC2s9dK+5LSvLKd9OlV2cVmbqCP2k0Az9uCFISAXF6ZYN9WtpiniUu0q7f4AWGXr650cJYcr4lHHDRhVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; c=relaxed/simple; bh=k2T8+mfZwwC/SEoIfiKTy8FA9wi/cqLxT6cnp0Xwewc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Su0bki+sUlGXKJLxMyLG7edRVXTHYvaSnUMdiPQQ3MdQhwsH03VC1hYjdoxMRzyb5JEgrR2f9hTGwQtsM2xM3jCNrBq5xUegk8IAcKP4uAEANoFcC2oXI20HwZbAcKJHs+GMNYynRAI2xLcd+duUqSzaqKCDKrhMidF6ESth/kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E5CEC43390; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiA-00000006aGu-1a9Y; Tue, 06 Feb 2024 06:33:58 -0500 Message-ID: <20240206113358.234112125@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:31:59 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 01/23] eventfs: Remove "lookup" parameter from create_dir/file_dentry() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149837968007970 X-GMAIL-MSGID: 1790149837968007970 From: "Steven Rostedt (Google)" The "lookup" parameter is a way to differentiate the call to create_file/dir_dentry() from when it's just a lookup (no need to up the dentry refcount) and accessed via a readdir (need to up the refcount). But reality, it just makes the code more complex. Just up the refcount and let the caller decide to dput() the result or not. Link: https://lore.kernel.org/linux-trace-kernel/20240103102553.17a19cea@gandalf.local.home Link: https://lore.kernel.org/linux-trace-kernel/20240104015435.517502710@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Ajay Kaher Cc: Al Viro Cc: Christian Brauner Signed-off-by: Steven Rostedt (Google) (cherry picked from commit b0f7e2d739b4aac131ea1662d086a07775097b05) --- fs/tracefs/event_inode.c | 55 +++++++++++++++------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f0677ea0ec24..c360300fb866 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -390,16 +390,14 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) * @mode: The mode of the file. * @data: The data to use to set the inode of the file with on open() * @fops: The fops of the file to be created. - * @lookup: If called by the lookup routine, in which case, dput() the created dentry. * * Create a dentry for a file of an eventfs_inode @ei and place it into the - * address located at @e_dentry. If the @e_dentry already has a dentry, then - * just do a dget() on it and return. Otherwise create the dentry and attach it. + * address located at @e_dentry. */ static struct dentry * create_file_dentry(struct eventfs_inode *ei, int idx, struct dentry *parent, const char *name, umode_t mode, void *data, - const struct file_operations *fops, bool lookup) + const struct file_operations *fops) { struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; @@ -414,9 +412,7 @@ create_file_dentry(struct eventfs_inode *ei, int idx, } /* If the e_dentry already has a dentry, use it */ if (*e_dentry) { - /* lookup does not need to up the ref count */ - if (!lookup) - dget(*e_dentry); + dget(*e_dentry); mutex_unlock(&eventfs_mutex); return *e_dentry; } @@ -441,13 +437,12 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * way to being freed, don't return it. If e_dentry is NULL * it means it was already freed. */ - if (ei->is_freed) + if (ei->is_freed) { dentry = NULL; - else + } else { dentry = *e_dentry; - /* The lookup does not need to up the dentry refcount */ - if (dentry && !lookup) dget(dentry); + } mutex_unlock(&eventfs_mutex); return dentry; } @@ -465,9 +460,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, } mutex_unlock(&eventfs_mutex); - if (lookup) - dput(dentry); - return dentry; } @@ -500,13 +492,12 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) * @pei: The eventfs_inode parent of ei. * @ei: The eventfs_inode to create the directory for * @parent: The dentry of the parent of this directory - * @lookup: True if this is called by the lookup code * * This creates and attaches a directory dentry to the eventfs_inode @ei. */ static struct dentry * create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, - struct dentry *parent, bool lookup) + struct dentry *parent) { struct dentry *dentry = NULL; @@ -518,11 +509,9 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, return NULL; } if (ei->dentry) { - /* If the dentry already has a dentry, use it */ + /* If the eventfs_inode already has a dentry, use it */ dentry = ei->dentry; - /* lookup does not need to up the ref count */ - if (!lookup) - dget(dentry); + dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; } @@ -542,7 +531,7 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * way to being freed. */ dentry = ei->dentry; - if (dentry && !lookup) + if (dentry) dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; @@ -562,9 +551,6 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, } mutex_unlock(&eventfs_mutex); - if (lookup) - dput(dentry); - return dentry; } @@ -589,8 +575,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct eventfs_inode *ei; struct dentry *ei_dentry = NULL; struct dentry *ret = NULL; + struct dentry *d; const char *name = dentry->d_name.name; - bool created = false; umode_t mode; void *data; int idx; @@ -626,13 +612,10 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, ret = simple_lookup(dir, dentry, flags); if (IS_ERR(ret)) goto out; - create_dir_dentry(ei, ei_child, ei_dentry, true); - created = true; - break; - } - - if (created) + d = create_dir_dentry(ei, ei_child, ei_dentry); + dput(d); goto out; + } for (i = 0; i < ei->nr_entries; i++) { entry = &ei->entries[i]; @@ -650,8 +633,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, ret = simple_lookup(dir, dentry, flags); if (IS_ERR(ret)) goto out; - create_file_dentry(ei, i, ei_dentry, name, mode, cdata, - fops, true); + d = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + dput(d); break; } } @@ -768,9 +751,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) inode_lock(parent->d_inode); list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dir_dentry(ei, ei_child, parent, false); + d = create_dir_dentry(ei, ei_child, parent); if (d) { ret = add_dentries(&dentries, d, cnt); + dput(d); if (ret < 0) break; cnt++; @@ -790,9 +774,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) mutex_unlock(&eventfs_mutex); if (r <= 0) continue; - d = create_file_dentry(ei, i, parent, name, mode, cdata, fops, false); + d = create_file_dentry(ei, i, parent, name, mode, cdata, fops); if (d) { ret = add_dentries(&dentries, d, cnt); + dput(d); if (ret < 0) break; cnt++; From patchwork Tue Feb 6 11:32:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197334 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1479469dyb; Tue, 6 Feb 2024 03:45:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEczQ78iyuY6wRmyRjoz4wR/r7zjD1CfY0Dhxrr5qRCiMz2KyxCo526JGtnmulj3GYMgQjG X-Received: by 2002:a9d:6a12:0:b0:6e2:b25c:c81e with SMTP id g18-20020a9d6a12000000b006e2b25cc81emr672752otn.0.1707219946798; Tue, 06 Feb 2024 03:45:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707219946; cv=pass; d=google.com; s=arc-20160816; b=u3J3G+jVyU5dOZfvbmuNAgA13dblpcTlHOKI5cwFpS99FU/9AHu1h3m5lxCqzmmeww OKluGBR2B0Fu0CbJqD8wEOpmYBzyJHpWTYsuNmqyI2CzHU/b+u5eDN8I7Eq48ufosXEq W0q3uIDNTX8vcOymSIG35EruT3vGd+4OaqUttPhePIn7e/T2SXWallVSRowT3k4M0aMo At43NRJDDdWGsH5JqYFt1TISoZEp9Y0h6ZsRfwIBzav64VhLR59fPnhGKCyBr/HI5ZWU T8CkpVLhXCbKpLpN99sIUfkLq8xJUgmjFZOvps2p5fyETjZL30+pYsUOaD98JOuiHkb/ GQEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=K16ORpNo1U2aN5VYISFPkBUUl5NEx/u13xyJsewSfsI=; fh=U6txYCoo5kg47KbAP75IkYFNftXaUFYiZgfkTssmHsY=; b=GQUD0Tudv+ToeQq1twk5L7fWM5gdMPwR9Nle+7gSGiTmRc3jde7jeD57vc98bE7qJ/ SHAACDEZZmazKv68HhSEomDecr+y113z7EAD048V1FiRI5ixIJnEuzd7P7lAtYn/fIwa fifRMdynnVbzvxOZpWsDxbsm3vmMwdGME+kF3K7Y++Xx/qfyvCd2erjW5VLi0+urnv3T xnbn8hfhorbG8zWtKZ6BDaUHIuDIaozYXnINWb3cWiWBA+ppMTr8O4UterySOHIubjGb NdhqzulgfgFEU+oR0SZedtZQiuFAqZ2O0GyvwS4OMiyeKs7bipdnBQ8KF0L0FwEpBjCJ X+rA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54788-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54788-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUjQPvXxL6530iJUlolqgdp+bpWMVNIQaMMkYJjjR3q+0wIDjpLIHRwpen1i/yDCInRNhabSpOcPRMyx1cZp1FJ+krxhw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id v15-20020a63464f000000b005cf1b38c7cesi1560068pgk.732.2024.02.06.03.45.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:45:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54788-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54788-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54788-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AE177B2309A for ; Tue, 6 Feb 2024 11:44:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 85F0812B152; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA1A3130E59; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; cv=none; b=LrymI5q36fTlBnjb4oT9MK+op7o9aEMssTYrja29RXlokNKp5KdzFgxqSDXpf3oOgJJLmpY6m+S9ju9m/8pdFIOMGLEg3PhpItyqhCG5pStpHfdid6umzrNPFcxbCI7H/Hk2EfgoPYwG/grxwzTMYLRcwqtjHNT3hQK27sZ3F2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; c=relaxed/simple; bh=PY2TEAkLo+5aq9G2jZ7fftRc6t/u8z0IYGwANgHoKpU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nGaSx5cJUj+hW9BRZt8Dc59SX87P9SICxThxhVQ+IjdVkdQuuNYlDQYCJmexdfRDwMAKe1AAaKKV7yL00tFWnr08RA64G3tR4QWs9BwOQgKIok1H+bVpRN1tRH11NTwrNgaZKn9fkHtpcknRzhzVBi6F5JCfoB5HpZdjFmyUgkE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C427C433C7; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiA-00000006aHN-2G87; Tue, 06 Feb 2024 06:33:58 -0500 Message-ID: <20240206113358.399057730@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:00 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 02/23] eventfs: Stop using dcache_readdir() for getdents() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149862979168579 X-GMAIL-MSGID: 1790149862979168579 From: "Steven Rostedt (Google)" The eventfs creates dynamically allocated dentries and inodes. Using the dcache_readdir() logic for its own directory lookups requires hiding the cursor of the dcache logic and playing games to allow the dcache_readdir() to still have access to the cursor while the eventfs saved what it created and what it needs to release. Instead, just have eventfs have its own iterate_shared callback function that will fill in the dent entries. This simplifies the code quite a bit. Link: https://lore.kernel.org/linux-trace-kernel/20240104015435.682218477@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Ajay Kaher Cc: Al Viro Cc: Christian Brauner Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 493ec81a8fb8e4ada6f223b8b73791a1280d4774) --- fs/tracefs/event_inode.c | 194 +++++++++++++-------------------------- 1 file changed, 64 insertions(+), 130 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index c360300fb866..41af56f44f0a 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -52,9 +52,7 @@ enum { static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); -static int dcache_dir_open_wrapper(struct inode *inode, struct file *file); -static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx); -static int eventfs_release(struct inode *inode, struct file *file); +static int eventfs_iterate(struct file *file, struct dir_context *ctx); static void update_attr(struct eventfs_attr *attr, struct iattr *iattr) { @@ -148,11 +146,9 @@ static const struct inode_operations eventfs_file_inode_operations = { }; static const struct file_operations eventfs_file_operations = { - .open = dcache_dir_open_wrapper, .read = generic_read_dir, - .iterate_shared = dcache_readdir_wrapper, + .iterate_shared = eventfs_iterate, .llseek = generic_file_llseek, - .release = eventfs_release, }; /* Return the evenfs_inode of the "events" directory */ @@ -643,128 +639,87 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, return ret; } -struct dentry_list { - void *cursor; - struct dentry **dentries; -}; - -/** - * eventfs_release - called to release eventfs file/dir - * @inode: inode to be released - * @file: file to be released (not used) - */ -static int eventfs_release(struct inode *inode, struct file *file) -{ - struct tracefs_inode *ti; - struct dentry_list *dlist = file->private_data; - void *cursor; - int i; - - ti = get_tracefs(inode); - if (!(ti->flags & TRACEFS_EVENT_INODE)) - return -EINVAL; - - if (WARN_ON_ONCE(!dlist)) - return -EINVAL; - - for (i = 0; dlist->dentries && dlist->dentries[i]; i++) { - dput(dlist->dentries[i]); - } - - cursor = dlist->cursor; - kfree(dlist->dentries); - kfree(dlist); - file->private_data = cursor; - return dcache_dir_close(inode, file); -} - -static int add_dentries(struct dentry ***dentries, struct dentry *d, int cnt) -{ - struct dentry **tmp; - - tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_NOFS); - if (!tmp) - return -1; - tmp[cnt] = d; - tmp[cnt + 1] = NULL; - *dentries = tmp; - return 0; -} - -/** - * dcache_dir_open_wrapper - eventfs open wrapper - * @inode: not used - * @file: dir to be opened (to create it's children) - * - * Used to dynamic create file/dir with-in @file, all the - * file/dir will be created. If already created then references - * will be increased +/* + * Walk the children of a eventfs_inode to fill in getdents(). */ -static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) +static int eventfs_iterate(struct file *file, struct dir_context *ctx) { const struct file_operations *fops; + struct inode *f_inode = file_inode(file); const struct eventfs_entry *entry; struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct dentry_list *dlist; - struct dentry **dentries = NULL; - struct dentry *parent = file_dentry(file); - struct dentry *d; - struct inode *f_inode = file_inode(file); - const char *name = parent->d_name.name; + struct dentry *ei_dentry = NULL; + struct dentry *dentry; + const char *name; umode_t mode; - void *data; - int cnt = 0; int idx; - int ret; - int i; - int r; + int ret = -EINVAL; + int ino; + int i, r, c; + + if (!dir_emit_dots(file, ctx)) + return 0; ti = get_tracefs(f_inode); if (!(ti->flags & TRACEFS_EVENT_INODE)) return -EINVAL; - if (WARN_ON_ONCE(file->private_data)) - return -EINVAL; + c = ctx->pos - 2; idx = srcu_read_lock(&eventfs_srcu); mutex_lock(&eventfs_mutex); ei = READ_ONCE(ti->private); + if (ei && !ei->is_freed) + ei_dentry = READ_ONCE(ei->dentry); mutex_unlock(&eventfs_mutex); - if (!ei) { - srcu_read_unlock(&eventfs_srcu, idx); - return -EINVAL; - } - - - data = ei->data; + if (!ei || !ei_dentry) + goto out; - dlist = kmalloc(sizeof(*dlist), GFP_KERNEL); - if (!dlist) { - srcu_read_unlock(&eventfs_srcu, idx); - return -ENOMEM; - } + ret = 0; - inode_lock(parent->d_inode); + /* + * Need to create the dentries and inodes to have a consistent + * inode number. + */ list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dir_dentry(ei, ei_child, parent); - if (d) { - ret = add_dentries(&dentries, d, cnt); - dput(d); - if (ret < 0) - break; - cnt++; + + if (c > 0) { + c--; + continue; } + + if (ei_child->is_freed) + continue; + + name = ei_child->name; + + dentry = create_dir_dentry(ei, ei_child, ei_dentry); + if (!dentry) + goto out; + ino = dentry->d_inode->i_ino; + dput(dentry); + + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + goto out; + ctx->pos++; } for (i = 0; i < ei->nr_entries; i++) { - void *cdata = data; + void *cdata = ei->data; + + if (c > 0) { + c--; + continue; + } + entry = &ei->entries[i]; name = entry->name; + mutex_lock(&eventfs_mutex); /* If ei->is_freed, then the event itself may be too */ if (!ei->is_freed) @@ -774,42 +729,21 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) mutex_unlock(&eventfs_mutex); if (r <= 0) continue; - d = create_file_dentry(ei, i, parent, name, mode, cdata, fops); - if (d) { - ret = add_dentries(&dentries, d, cnt); - dput(d); - if (ret < 0) - break; - cnt++; - } - } - inode_unlock(parent->d_inode); - srcu_read_unlock(&eventfs_srcu, idx); - ret = dcache_dir_open(inode, file); - /* - * dcache_dir_open() sets file->private_data to a dentry cursor. - * Need to save that but also save all the dentries that were - * opened by this function. - */ - dlist->cursor = file->private_data; - dlist->dentries = dentries; - file->private_data = dlist; - return ret; -} + dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + if (!dentry) + goto out; + ino = dentry->d_inode->i_ino; + dput(dentry); -/* - * This just sets the file->private_data back to the cursor and back. - */ -static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx) -{ - struct dentry_list *dlist = file->private_data; - int ret; + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + goto out; + ctx->pos++; + } + ret = 1; + out: + srcu_read_unlock(&eventfs_srcu, idx); - file->private_data = dlist->cursor; - ret = dcache_readdir(file, ctx); - dlist->cursor = file->private_data; - file->private_data = dlist; return ret; } From patchwork Tue Feb 6 11:32:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1480332dyb; Tue, 6 Feb 2024 03:47:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEroph63sV9MIdDx8CzG8kyvKx8wEG1oVUiwLcMEAnbgoOJQlwQa6/61xa/LY1NUn/u6cif X-Received: by 2002:a05:6402:1814:b0:55f:2be4:61d with SMTP id g20-20020a056402181400b0055f2be4061dmr1595126edy.14.1707220067128; Tue, 06 Feb 2024 03:47:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220067; cv=pass; d=google.com; s=arc-20160816; b=F5ZOL1V7W7WrdUGKbT9HPzgie5YEN5VZflW3S6j53+GKfNltAt4kfNfiYN2P83UHT+ pGYHrbOXXINmGbBQAWA9if88GS+ROhOovt3r5U4jI3mlFalAan2BqjldYrMJWntCujC3 57Ov/dR0rwR/HGdHHLhiyXVyTdXINuQWZHaSShYaJ/OfOorjV9ykQ9brGZyeQJJgWDHl 5WNArKgAnwoXXlrgkowoQD/jnKlVVChTBuG2UVvuTUJE/wrzUju3Qfm172PC1MZ7ezZx bh53iU6qKgRo8qlMzNF/uVAlhREnvLpgoS4khnjIf/6R8ND9/siesD7f3eTvZSb63M5m WQkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=2igeLfdjB4Au9sgTG3fZuxieWviVS3ftRTaHmDifVb4=; fh=ig6hBenndPEClopjOgzPck3DIzushG+8m0WYMz1xoZc=; b=k46rsqyfSE+rn+l1+GPKVBIaD5zXhX8fw5mRNt0HfQ9ZU+mJHqTK9GCr7HVsSY8Ecc 18ynFDIWAapVWZ/GIqaq3UipmkSal/kVuCGWJtWcFdMKZS2DFgqOMaMXD4pVDiYgvFY6 9tYm+azD3MPRjHPMCZWSST75dXL3tkF6hVVZVQTxLIsIX2u323HfhbFaoEYvkdjHXiCu edkFDHfg9bS1egqHCzQmokOXY9Mpr4VLRpGQAZ1CajsHpLP7d5CqqebPFIqTayAomqN2 PpUVlZPSBKyZLTMdkKo8l/z5RhiOzw6+PvmbZqhKoQ9ALVH8/GS7XUHbyKuMnA2AkTs9 GpQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54790-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54790-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX4KzzK31I8HPChcfYRnPRmfaipMXou7IisxcpYAMfBxjAtFxkEh3dUU+noCSirdIEYXqAveLe2U1HYOpERkZC3m++Yuw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v2-20020aa7d802000000b0056002c29444si1024074edq.638.2024.02.06.03.47.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:47:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54790-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54790-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54790-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 111941F24910 for ; Tue, 6 Feb 2024 11:47:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7321E136643; Tue, 6 Feb 2024 11:33:35 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C08CC130E5E; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; cv=none; b=oX3uIM9FqLno8wdZUJHfsT4lzdch1XbKd1gGdgT5VxBzY3QQ8T1bQg5jygc8JMtGhYJhrKzWbbKQqZQRoSS56TJdc/z6FIpB+xB+THFiDuKMAJYyPBVgoERWxq/IAaQMwphlraKXt93ZrKpyyJPxGeq5+YKWBOqO8unPX5/QYDw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; c=relaxed/simple; bh=2py7fgnyWKSs78aFz5LfqcwX0ZSbePLjoJxU6WYULo4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=kQiBGc3TDw5Th3UdAxxCbEUvOuHwpBcN80BUCnXUW8uZonZJ2eu9YzA7ETAOXZb0mtr3Z4YfDwlk1JyQni8W3ihWjPwgUH7rnYiMW00r+L8jELo+vSiEmsKOB/8i5NU72QzcSo/3VRY+TSM50bt6lJ5BfuaBITH3/ibT7Y/5Ky4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C66CC43394; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiA-00000006aHt-2xN5; Tue, 06 Feb 2024 06:33:58 -0500 Message-ID: <20240206113358.560456584@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:01 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 03/23] tracefs/eventfs: Use root and instance inodes as default ownership References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149989048067630 X-GMAIL-MSGID: 1790149989048067630 From: "Steven Rostedt (Google)" Instead of walking the dentries on mount/remount to update the gid values of all the dentries if a gid option is specified on mount, just update the root inode. Add .getattr, .setattr, and .permissions on the tracefs inode operations to update the permissions of the files and directories. For all files and directories in the top level instance: /sys/kernel/tracing/* It will use the root inode as the default permissions. The inode that represents: /sys/kernel/tracing (or wherever it is mounted). When an instance is created: mkdir /sys/kernel/tracing/instance/foo The directory "foo" and all its files and directories underneath will use the default of what foo is when it was created. A remount of tracefs will not affect it. If a user were to modify the permissions of any file or directory in tracefs, it will also no longer be modified by a change in ownership of a remount. The events directory, if it is in the top level instance, will use the tracefs root inode as the default ownership for itself and all the files and directories below it. For the events directory in an instance ("foo"), it will keep the ownership of what it was when it was created, and that will be used as the default ownership for the files and directories beneath it. Link: https://lore.kernel.org/linux-trace-kernel/CAHk-=wjVdGkjDXBbvLn2wbZnqP4UsH46E3gqJ9m7UG6DpX2+WA@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240103215016.1e0c9811@gandalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 8186fff7ab649085e2c60d032d9a20a85af1d87c) --- fs/tracefs/event_inode.c | 79 +++++++++++++++- fs/tracefs/inode.c | 198 ++++++++++++++++++++++----------------- fs/tracefs/internal.h | 3 + 3 files changed, 190 insertions(+), 90 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 41af56f44f0a..72912b5f9a90 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -45,6 +45,7 @@ enum { EVENTFS_SAVE_MODE = BIT(16), EVENTFS_SAVE_UID = BIT(17), EVENTFS_SAVE_GID = BIT(18), + EVENTFS_TOPLEVEL = BIT(19), }; #define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1) @@ -115,10 +116,17 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, * The events directory dentry is never freed, unless its * part of an instance that is deleted. It's attr is the * default for its child files and directories. - * Do not update it. It's not used for its own mode or ownership + * Do not update it. It's not used for its own mode or ownership. */ - if (!ei->is_events) + if (ei->is_events) { + /* But it still needs to know if it was modified */ + if (iattr->ia_valid & ATTR_UID) + ei->attr.mode |= EVENTFS_SAVE_UID; + if (iattr->ia_valid & ATTR_GID) + ei->attr.mode |= EVENTFS_SAVE_GID; + } else { update_attr(&ei->attr, iattr); + } } else { name = dentry->d_name.name; @@ -136,9 +144,66 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, return ret; } +static void update_top_events_attr(struct eventfs_inode *ei, struct dentry *dentry) +{ + struct inode *inode; + + /* Only update if the "events" was on the top level */ + if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL)) + return; + + /* Get the tracefs root inode. */ + inode = d_inode(dentry->d_sb->s_root); + ei->attr.uid = inode->i_uid; + ei->attr.gid = inode->i_gid; +} + +static void set_top_events_ownership(struct inode *inode) +{ + struct tracefs_inode *ti = get_tracefs(inode); + struct eventfs_inode *ei = ti->private; + struct dentry *dentry; + + /* The top events directory doesn't get automatically updated */ + if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL)) + return; + + dentry = ei->dentry; + + update_top_events_attr(ei, dentry); + + if (!(ei->attr.mode & EVENTFS_SAVE_UID)) + inode->i_uid = ei->attr.uid; + + if (!(ei->attr.mode & EVENTFS_SAVE_GID)) + inode->i_gid = ei->attr.gid; +} + +static int eventfs_get_attr(struct mnt_idmap *idmap, + const struct path *path, struct kstat *stat, + u32 request_mask, unsigned int flags) +{ + struct dentry *dentry = path->dentry; + struct inode *inode = d_backing_inode(dentry); + + set_top_events_ownership(inode); + + generic_fillattr(idmap, request_mask, inode, stat); + return 0; +} + +static int eventfs_permission(struct mnt_idmap *idmap, + struct inode *inode, int mask) +{ + set_top_events_ownership(inode); + return generic_permission(idmap, inode, mask); +} + static const struct inode_operations eventfs_root_dir_inode_operations = { .lookup = eventfs_root_lookup, .setattr = eventfs_set_attr, + .getattr = eventfs_get_attr, + .permission = eventfs_permission, }; static const struct inode_operations eventfs_file_inode_operations = { @@ -174,6 +239,8 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) } while (!ei->is_events); mutex_unlock(&eventfs_mutex); + update_top_events_attr(ei, dentry); + return ei; } @@ -887,6 +954,14 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry uid = d_inode(dentry->d_parent)->i_uid; gid = d_inode(dentry->d_parent)->i_gid; + /* + * If the events directory is of the top instance, then parent + * is NULL. Set the attr.mode to reflect this and its permissions will + * default to the tracefs root dentry. + */ + if (!parent) + ei->attr.mode = EVENTFS_TOPLEVEL; + /* This is used as the default ownership of the files and directories */ ei->attr.uid = uid; ei->attr.gid = gid; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index bc86ffdb103b..e1b172c0e091 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -91,6 +91,7 @@ static int tracefs_syscall_mkdir(struct mnt_idmap *idmap, struct inode *inode, struct dentry *dentry, umode_t mode) { + struct tracefs_inode *ti; char *name; int ret; @@ -98,6 +99,15 @@ static int tracefs_syscall_mkdir(struct mnt_idmap *idmap, if (!name) return -ENOMEM; + /* + * This is a new directory that does not take the default of + * the rootfs. It becomes the default permissions for all the + * files and directories underneath it. + */ + ti = get_tracefs(inode); + ti->flags |= TRACEFS_INSTANCE_INODE; + ti->private = inode; + /* * The mkdir call can call the generic functions that create * the files within the tracefs system. It is up to the individual @@ -141,10 +151,76 @@ static int tracefs_syscall_rmdir(struct inode *inode, struct dentry *dentry) return ret; } -static const struct inode_operations tracefs_dir_inode_operations = { +static void set_tracefs_inode_owner(struct inode *inode) +{ + struct tracefs_inode *ti = get_tracefs(inode); + struct inode *root_inode = ti->private; + + /* + * If this inode has never been referenced, then update + * the permissions to the superblock. + */ + if (!(ti->flags & TRACEFS_UID_PERM_SET)) + inode->i_uid = root_inode->i_uid; + + if (!(ti->flags & TRACEFS_GID_PERM_SET)) + inode->i_gid = root_inode->i_gid; +} + +static int tracefs_permission(struct mnt_idmap *idmap, + struct inode *inode, int mask) +{ + set_tracefs_inode_owner(inode); + return generic_permission(idmap, inode, mask); +} + +static int tracefs_getattr(struct mnt_idmap *idmap, + const struct path *path, struct kstat *stat, + u32 request_mask, unsigned int flags) +{ + struct inode *inode = d_backing_inode(path->dentry); + + set_tracefs_inode_owner(inode); + generic_fillattr(idmap, request_mask, inode, stat); + return 0; +} + +static int tracefs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, + struct iattr *attr) +{ + unsigned int ia_valid = attr->ia_valid; + struct inode *inode = d_inode(dentry); + struct tracefs_inode *ti = get_tracefs(inode); + + if (ia_valid & ATTR_UID) + ti->flags |= TRACEFS_UID_PERM_SET; + + if (ia_valid & ATTR_GID) + ti->flags |= TRACEFS_GID_PERM_SET; + + return simple_setattr(idmap, dentry, attr); +} + +static const struct inode_operations tracefs_instance_dir_inode_operations = { .lookup = simple_lookup, .mkdir = tracefs_syscall_mkdir, .rmdir = tracefs_syscall_rmdir, + .permission = tracefs_permission, + .getattr = tracefs_getattr, + .setattr = tracefs_setattr, +}; + +static const struct inode_operations tracefs_dir_inode_operations = { + .lookup = simple_lookup, + .permission = tracefs_permission, + .getattr = tracefs_getattr, + .setattr = tracefs_setattr, +}; + +static const struct inode_operations tracefs_file_inode_operations = { + .permission = tracefs_permission, + .getattr = tracefs_getattr, + .setattr = tracefs_setattr, }; struct inode *tracefs_get_inode(struct super_block *sb) @@ -183,87 +259,6 @@ struct tracefs_fs_info { struct tracefs_mount_opts mount_opts; }; -static void change_gid(struct dentry *dentry, kgid_t gid) -{ - if (!dentry->d_inode) - return; - dentry->d_inode->i_gid = gid; -} - -/* - * Taken from d_walk, but without he need for handling renames. - * Nothing can be renamed while walking the list, as tracefs - * does not support renames. This is only called when mounting - * or remounting the file system, to set all the files to - * the given gid. - */ -static void set_gid(struct dentry *parent, kgid_t gid) -{ - struct dentry *this_parent; - struct list_head *next; - - this_parent = parent; - spin_lock(&this_parent->d_lock); - - change_gid(this_parent, gid); -repeat: - next = this_parent->d_subdirs.next; -resume: - while (next != &this_parent->d_subdirs) { - struct tracefs_inode *ti; - struct list_head *tmp = next; - struct dentry *dentry = list_entry(tmp, struct dentry, d_child); - next = tmp->next; - - /* Note, getdents() can add a cursor dentry with no inode */ - if (!dentry->d_inode) - continue; - - spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); - - change_gid(dentry, gid); - - /* If this is the events directory, update that too */ - ti = get_tracefs(dentry->d_inode); - if (ti && (ti->flags & TRACEFS_EVENT_INODE)) - eventfs_update_gid(dentry, gid); - - if (!list_empty(&dentry->d_subdirs)) { - spin_unlock(&this_parent->d_lock); - spin_release(&dentry->d_lock.dep_map, _RET_IP_); - this_parent = dentry; - spin_acquire(&this_parent->d_lock.dep_map, 0, 1, _RET_IP_); - goto repeat; - } - spin_unlock(&dentry->d_lock); - } - /* - * All done at this level ... ascend and resume the search. - */ - rcu_read_lock(); -ascend: - if (this_parent != parent) { - struct dentry *child = this_parent; - this_parent = child->d_parent; - - spin_unlock(&child->d_lock); - spin_lock(&this_parent->d_lock); - - /* go into the first sibling still alive */ - do { - next = child->d_child.next; - if (next == &this_parent->d_subdirs) - goto ascend; - child = list_entry(next, struct dentry, d_child); - } while (unlikely(child->d_flags & DCACHE_DENTRY_KILLED)); - rcu_read_unlock(); - goto resume; - } - rcu_read_unlock(); - spin_unlock(&this_parent->d_lock); - return; -} - static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts) { substring_t args[MAX_OPT_ARGS]; @@ -336,10 +331,8 @@ static int tracefs_apply_options(struct super_block *sb, bool remount) if (!remount || opts->opts & BIT(Opt_uid)) inode->i_uid = opts->uid; - if (!remount || opts->opts & BIT(Opt_gid)) { - /* Set all the group ids to the mount option */ - set_gid(sb->s_root, opts->gid); - } + if (!remount || opts->opts & BIT(Opt_gid)) + inode->i_gid = opts->gid; return 0; } @@ -573,6 +566,26 @@ struct dentry *eventfs_end_creating(struct dentry *dentry) return dentry; } +/* Find the inode that this will use for default */ +static struct inode *instance_inode(struct dentry *parent, struct inode *inode) +{ + struct tracefs_inode *ti; + + /* If parent is NULL then use root inode */ + if (!parent) + return d_inode(inode->i_sb->s_root); + + /* Find the inode that is flagged as an instance or the root inode */ + while (!IS_ROOT(parent)) { + ti = get_tracefs(d_inode(parent)); + if (ti->flags & TRACEFS_INSTANCE_INODE) + break; + parent = parent->d_parent; + } + + return d_inode(parent); +} + /** * tracefs_create_file - create a file in the tracefs filesystem * @name: a pointer to a string containing the name of the file to create. @@ -603,6 +616,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops) { + struct tracefs_inode *ti; struct dentry *dentry; struct inode *inode; @@ -621,7 +635,11 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, if (unlikely(!inode)) return tracefs_failed_creating(dentry); + ti = get_tracefs(inode); + ti->private = instance_inode(parent, inode); + inode->i_mode = mode; + inode->i_op = &tracefs_file_inode_operations; inode->i_fop = fops ? fops : &tracefs_file_operations; inode->i_private = data; inode->i_uid = d_inode(dentry->d_parent)->i_uid; @@ -634,6 +652,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, static struct dentry *__create_dir(const char *name, struct dentry *parent, const struct inode_operations *ops) { + struct tracefs_inode *ti; struct dentry *dentry = tracefs_start_creating(name, parent); struct inode *inode; @@ -651,6 +670,9 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent, inode->i_uid = d_inode(dentry->d_parent)->i_uid; inode->i_gid = d_inode(dentry->d_parent)->i_gid; + ti = get_tracefs(inode); + ti->private = instance_inode(parent, inode); + /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); d_instantiate(dentry, inode); @@ -681,7 +703,7 @@ struct dentry *tracefs_create_dir(const char *name, struct dentry *parent) if (security_locked_down(LOCKDOWN_TRACEFS)) return NULL; - return __create_dir(name, parent, &simple_dir_inode_operations); + return __create_dir(name, parent, &tracefs_dir_inode_operations); } /** @@ -712,7 +734,7 @@ __init struct dentry *tracefs_create_instance_dir(const char *name, if (WARN_ON(tracefs_ops.mkdir || tracefs_ops.rmdir)) return NULL; - dentry = __create_dir(name, parent, &tracefs_dir_inode_operations); + dentry = __create_dir(name, parent, &tracefs_instance_dir_inode_operations); if (!dentry) return NULL; diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 42bdeb471a07..12b7d0150ae9 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -5,6 +5,9 @@ enum { TRACEFS_EVENT_INODE = BIT(1), TRACEFS_EVENT_TOP_INODE = BIT(2), + TRACEFS_GID_PERM_SET = BIT(3), + TRACEFS_UID_PERM_SET = BIT(4), + TRACEFS_INSTANCE_INODE = BIT(5), }; struct tracefs_inode { From patchwork Tue Feb 6 11:32:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197331 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1478628dyb; Tue, 6 Feb 2024 03:43:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEUv2AbmUW6ctoSLRt0YNJGGyNtGFo/Nm56csV/gmw3NARq7I2Z0j3e2u60FCpe0Drf+FT X-Received: by 2002:a05:6402:1a24:b0:560:58f:7148 with SMTP id be4-20020a0564021a2400b00560058f7148mr1730140edb.34.1707219824718; Tue, 06 Feb 2024 03:43:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707219824; cv=pass; d=google.com; s=arc-20160816; b=j1WinulbFmFCS7Vgg8uKdGRHABj6DOdjRRcKQgRh7jHSY0MFnRSk/e6JlLX3w5usQb lLvFQB42qZfBvr6xiI/LqfadCQr9woq1kKXt80tUFHb/HRlusvf7XHU6nhxg+nnoy2bN Dxll0ZhQWiipz4PEjbnfnvTfB/dUx5Vk6MfNxljBJ9misBV6HQqWKq9UMLuS2WiRuvtO oY1FMF0bRkbu3oAwwaK4VqFUVWKszOQWA0kc2iXjjcYN6UqZ2Y2l/LOqJv4EsLvmykDg ubt72hdLcGp3wky6gWpjF1imACzWPu0UM5/0g/hUu13Osg6SgNLSrppSMhUBfdSt45F3 Qylg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=w/iPhJOudMj5zSlscWJCTndr2nhDIzagNWRmI9xY/Ss=; fh=usQ77r2XR8Mt8SclEXuQnRAFRnlBhV9qUfte7MB+pMA=; b=XcyqcobXzvW2oxl8UjyslDH+U63loLjGViDTILocu4PJc+YdqMRZoeJoTg8GLDpK5u LjTUXuBydmUChMMJC+BnmYnteSdSFiH/ZiOh9/+5cKA8t/HwPE7XEJT0EpNgz8JJh9rO TzR+kQcNb+V3VudL7TacTcTaEcjXEvcZ6wD6pBacyEvXy/ilAW+rwnO2RdRug360DDNr q9MPpTHQ31OEZ/XfqKo50k3iqMGmYI7UaR9pYwhX5/yZnn71hZJpcQTNlcxEliWBIMZ+ OVpghZak8FQbyo86L37RqoiD7AQQ4L27bAUZZQrdb28zkt392ArIw9JVV8YpSX0Lxae9 uDbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU+GTW1PsqZmXL5X5INZC3OwwXxUtPMvxDNWaQHFomFsW09iWuNHIYS4G+vVbtwk75D81PjSgEGrWicO82VYBCnWPcPaA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w8-20020aa7cb48000000b0055ff974eb1bsi995363edt.508.2024.02.06.03.43.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:43:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54789-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id DC9941F22706 for ; Tue, 6 Feb 2024 11:43:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 832B513474D; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C089F130E53; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; cv=none; b=TlCeMx91WGzxUc+RubxIzep94PCwmxOqfTQIwTT5SqK01Lcc2e4ZG4dKBHh1tsUTAQRPquGVSpqtjBaeoHMTc67IQx721OlgIu4FMsFJ4X8tIpexwGMyNaCVC+4ef9/X093rDN6KWICoxkbgv+ys3xPdFk0GkoL5bzyH0TP3ZKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219210; c=relaxed/simple; bh=3jDSxRh6ezDXpMpe9bCVmX2ZEPsqcyYEs+U1X03bFjY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KUPv4lJ8XwGwNoxzOlZxVcfKonx3LNAIpbneJAwqGfP0sv8hLu7/3ywRDtisybqvYgigpBZGzXkoobEJOBQIW+EkSo7gR4EVCHSdyFlpLrzuIxUgr/HDWku/Ci0437Bd1SI3hOk6/MNNG4pModXqdNfONEDTArZ/cWSrO4Mck5Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D193C43601; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiA-00000006aIN-3fhr; Tue, 06 Feb 2024 06:33:58 -0500 Message-ID: <20240206113358.729003384@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:02 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 04/23] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149734865780610 X-GMAIL-MSGID: 1790149734865780610 From: "Steven Rostedt (Google)" If ei->is_freed is set in eventfs_iterate(), it means that the directory that is being iterated on is in the process of being freed. Just exit the loop immediately when that is ever detected, and separate out the return of the entry->callback() from ei->is_freed. Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.016261289@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit e109deadb73318cf4a3bd61287d969f705df278f) --- fs/tracefs/event_inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 72912b5f9a90..0aca6910efb3 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -788,11 +788,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = entry->name; mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r = entry->callback(name, &mode, &cdata, &fops); - else - r = -1; + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out; + } + r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); if (r <= 0) continue; From patchwork Tue Feb 6 11:32:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197332 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1479155dyb; Tue, 6 Feb 2024 03:45:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IH+Ha0hXsu1b87Hz03Pm6mqyJW8aiWjD81D3o1vRtK2xRDjqYIWg960QdFT1nqFGqy9aaRU X-Received: by 2002:a17:906:f90f:b0:a36:f672:5dab with SMTP id lc15-20020a170906f90f00b00a36f6725dabmr2681050ejb.16.1707219903687; Tue, 06 Feb 2024 03:45:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707219903; cv=pass; d=google.com; s=arc-20160816; b=egppx8nXyEHNpnBU/od+te8Za+wCSAdFEMLIRkPOfhSX/cmSIhkU2XxyIe0z+V1eEc nTPfE0hEh+kCdUcnRSYEKXJxL5cmK3wK6+KI1d65s1h6wFCKfaszAzxGmt3mqwL6FAZc LMkpseD+J68jrdveRXMMq8PP4UaRVuSIyuBX2Kpxn3qeTBVU4O+lVuNJh9dRlvAyyG2x /mwqiNLAzubYifylPFRPAM/EB1+np5USuYIkb3BP9T3rXPA2ztWU7xPrPr0VeACkzQnv MrErpnGs+GXzJGtlDPYNqPWpJ3HAJs6qmmLihoaBOaux83crvB79cCw+XMTKbbcxrMB9 yFzw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=97GT1y81ODm767N+vaTtb7CLJ/49FtWR2HrL/alCa6U=; fh=n3LjkBeIMS4+6lY59lra3FDvMZO76clPqjuCqXwgMJc=; b=kot2VKTzFHpREaMYkgmEdF5yUyALojZkyNqxPtlC3W3BlmOGXAoB3EvUcc7pD94gx9 yXsqK/sLsWdRZ5Lxlns3JEsvDquGkUVhSx09ha16G2Ddx0VT3qrY91Z9d7/5Ht9sRuSB GsD1r6BqnULV3UWSzYT8WP6crae9O23RnEQueF+ecCJPio7bsMh8ZFT1lC+MXBIFgDj/ UqiWIrSAenmygzy0Mrl45UvOQKF7TVBFC9tJLTkZQBgvBDlD9a8Vi/Z8oJNso6OeWZ2x Igft4pbU7z+AiXs6QSbvtUyk/kp2f+rYZyKLBtBWqNw6D4keJ4zEbHUkKy5O/zMPF4KO 7WOA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54791-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUBFVJkt8rXvLvc1niW8tLToWht9OgNgQLbCmlEcLnCiLX0zZxMc+G/WVeIbqiIllPlPyBRrjdiO9P86PD4mDt4YcHBpg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id p7-20020a170906614700b00a38100b17d4si836021ejl.932.2024.02.06.03.45.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:45:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54791-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54791-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 67C451F24CD7 for ; Tue, 6 Feb 2024 11:45:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F95D1350CA; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 07924130E44; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; cv=none; b=JMIy7SN1/iVX4fyB066M/6W3NhrMbM/0F1bIKycKRJwbPzHGx7NZUvmgjR6fN83jR9EGxuSqu4Jm/qlM/CMPB1uxFNEEXc9Cu4e9uVe0HpqCndpctxuYpo3ujkGCvBQ0Rgcwu5VjPpUUER6XHKym0XU7WABjZstXpYYZqjtiBFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=1TOxKL8RRnNxulvXK50DzgvXwAnmOluv224Nju/yrew=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=A5CURwFB8zw/bOT+k/+44NQKkOfsdQS8nye+LyPe2NywbsxNGt/DmLPC27+shGB24ioM1W6sYSxSEqdzKfIrgd7CXq52UruTLynqa8p8ktBf7MOPTksZ/8LVMq9i8rLnfNydEVGEn9i989S7ZrbyJRym4JuNMrytBum9ib7bgLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8BD5C41674; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aIr-0AN3; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113358.897028018@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:03 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 05/23] eventfs: Do ctx->pos update for all iterations in eventfs_iterate() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149817772533645 X-GMAIL-MSGID: 1790149817772533645 From: "Steven Rostedt (Google)" The ctx->pos was only updated when it added an entry, but the "skip to current pos" check (c--) happened for every loop regardless of if the entry was added or not. This inconsistency caused readdir to be incorrect. It was due to: for (i = 0; i < ei->nr_entries; i++) { if (c > 0) { c--; continue; } mutex_lock(&eventfs_mutex); /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); goto out; } r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); [..] ctx->pos++; } But this can cause the iterator to return a file that was already read. That's because of the way the callback() works. Some events may not have all files, and the callback can return 0 to tell eventfs to skip the file for this directory. for instance, we have: # ls /sys/kernel/tracing/events/ftrace/function format hist hist_debug id inject and # ls /sys/kernel/tracing/events/sched/sched_switch/ enable filter format hist hist_debug id inject trigger Where the function directory is missing "enable", "filter" and "trigger". That's because the callback() for events has: static int event_callback(const char *name, umode_t *mode, void **data, const struct file_operations **fops) { struct trace_event_file *file = *data; struct trace_event_call *call = file->event_call; [..] /* * Only event directories that can be enabled should have * triggers or filters, with the exception of the "print" * event that can have a "trigger" file. */ if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) { if (call->class->reg && strcmp(name, "enable") == 0) { *mode = TRACE_MODE_WRITE; *fops = &ftrace_enable_fops; return 1; } if (strcmp(name, "filter") == 0) { *mode = TRACE_MODE_WRITE; *fops = &ftrace_event_filter_fops; return 1; } } if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) || strcmp(trace_event_name(call), "print") == 0) { if (strcmp(name, "trigger") == 0) { *mode = TRACE_MODE_WRITE; *fops = &event_trigger_fops; return 1; } } [..] return 0; } Where the function event has the TRACE_EVENT_FL_IGNORE_ENABLE set. This means that the entries array elements for "enable", "filter" and "trigger" when called on the function event will have the callback return 0 and not 1, to tell eventfs to skip these files for it. Because the "skip to current ctx->pos" check happened for all entries, but the ctx->pos++ only happened to entries that exist, it would confuse the reading of a directory. Which would cause: # ls /sys/kernel/tracing/events/ftrace/function/ format hist hist hist_debug hist_debug id inject inject The missing "enable", "filter" and "trigger" caused ls to show "hist", "hist_debug" and "inject" twice. Update the ctx->pos for every iteration to keep its update and the "skip" update consistent. This also means that on error, the ctx->pos needs to be decremented if it was incremented without adding something. Link: https://lore.kernel.org/all/20240104150500.38b15a62@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.172295263@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Fixes: 493ec81a8fb8e ("eventfs: Stop using dcache_readdir() for getdents()") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 1e4624eb5a0ecaae0d2c4e3019bece119725bb98) --- fs/tracefs/event_inode.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 0aca6910efb3..c73fb1f7ddbc 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -760,6 +760,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) continue; } + ctx->pos++; + if (ei_child->is_freed) continue; @@ -767,13 +769,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) dentry = create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) - goto out; + goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) - goto out; - ctx->pos++; + goto out_dec; } for (i = 0; i < ei->nr_entries; i++) { @@ -784,6 +785,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) continue; } + ctx->pos++; + entry = &ei->entries[i]; name = entry->name; @@ -791,7 +794,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); - goto out; + goto out_dec; } r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); @@ -800,19 +803,23 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) - goto out; + goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) - goto out; - ctx->pos++; + goto out_dec; } ret = 1; out: srcu_read_unlock(&eventfs_srcu, idx); return ret; + + out_dec: + /* Incremented ctx->pos without adding something, reset it */ + ctx->pos--; + goto out; } /** From patchwork Tue Feb 6 11:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1480013dyb; Tue, 6 Feb 2024 03:47:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGST2bNW0MSic0CMakrlsbRiZ6GMAcshYjYL97lTWxy0aN8AxnIc05sr59QfMIiKpVW5GWd X-Received: by 2002:a17:906:3718:b0:a38:47b5:efe7 with SMTP id d24-20020a170906371800b00a3847b5efe7mr202266ejc.2.1707220023242; Tue, 06 Feb 2024 03:47:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220023; cv=pass; d=google.com; s=arc-20160816; b=CJ+eVypZ7rqE7+7A/ofgyXiZKEIilvqK3beKa9HpXVFNUH1/v5h5nM33xyHkrIUhEq WViQFxrLSLOKdnuaWCslYQNUuLInKTzlCnxp7yqzninvZtCrUjnYbYfUtK0ifptQGN/n +EC2PGyVlJqQXKQpbDFYMLWd6DWsQfVnvdBGxM/m8tEC2+slnSiC7Gg6cbrzVxNyebu6 ALmBaZjQNirwimuDmXZCeIX8SLiycG7nger6bLkx72ccDaoSKc9T44uwAu8j8tZ/rv27 WsGDIUqRf5+a4RpOBKOeTb+K+L2ow9aSJ8Vyq5/kxKSQ+I1o2U4MqA7pPrNfrjd52AvG smDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=SXG6kX6vpOBEiMVmlEzwWPSMsib1/4LFk5czFSKSK4M=; fh=Vfa0+vs+phltZ3eJfYQwTgeYlRMN2P/oaxI95UkvYQk=; b=ODIwM4mMPw5GDJTKaOBuEu9NEVIUuGWzhluQB4H4WZnsQZG1yXA01JURTyo9X9kiTy MIeQ93IW+YgpMkRg4/Wgh+KdQsbtB0uy4x1hapFILEAJL9/9F3yKnohWksnGJEOpUQUr XDx2FzERER+sEyxqtRbSiVckj9CuBObFPVPsRE08Nv0vW+imfsd8OSEooLsOjkzHdwr2 GOIAQbwmHSZd49cmZZnxZm3X7zmKnnWV7FkMWmiWfjuUnwniUN+nO6NxXx/eVAtH/GIt Cage7Yw5kz2XTcJRCexdHAGgs4thxHZ1UcknSwFQ1gvQ7sRCSZPVmcVo1yIhucwmUtlf gIwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW2CxwbFARb3ODPUIyJESD9PooR2bU4fz8zs1uUUeUqVCtbjtvqj5foScKJi+JuAfYCBPDW7XR+C5FhBA9jNBvlbTqHhw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dt15-20020a170906b78f00b00a37bc6b8154si1014899ejb.439.2024.02.06.03.47.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:47:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C56601F21BCF for ; Tue, 6 Feb 2024 11:47:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F37A7135A52; Tue, 6 Feb 2024 11:33:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3706C133980; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; cv=none; b=ZqzBA6vIrI10RRV5CODRgnrtyuprFJuZM+bk4Wr4/GUhPiccX7/anuER+iKb97UiH2jsf+naEDjMiiR0a4PND06tHId+wCf+SLxoKVadQGHArn+TeZNh48dOWMtkRHRLkhtLA2lWBJJ9djnSz/t+51+kzLyNY40bmtsIuOIxWwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=msUlAhKaN43vF7JsX1xwBfcdPGlDn+EyYYaBimHJa/8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=EXN0IfK9sgLcsgKLzAA0b4mlAZJTHTXCe4zr4n5AvFbYoOFxT4bTi0PtgxTtkBNFowPY6gstlCzmvwhJu6VmSZBvSum8uGghhMf2dFxM8zTNSXj/XTCAxbm8QHKP8Vp9DielsrQXLOO2t3HBxff+GHDOyyUjLsHbbCm6ei0DOHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC1D4C433B1; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aJL-0sJS; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.062398719@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:04 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 06/23] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149942947702990 X-GMAIL-MSGID: 1790149942947702990 From: "Steven Rostedt (Google)" In order to apply a shortcut to skip over the current ctx->pos immediately, by using the ei->entries array, the reading of that array should be first. Moving the array reading before the linked list reading will make the shortcut change diff nicer to read. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.333115095@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 704f960dbee2f1634f4b4e16f208cb16eaf41c1e) --- fs/tracefs/event_inode.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index c73fb1f7ddbc..a1934e0eea3b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -752,8 +752,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) * Need to create the dentries and inodes to have a consistent * inode number. */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { + for (i = 0; i < ei->nr_entries; i++) { + void *cdata = ei->data; if (c > 0) { c--; @@ -762,23 +762,32 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - if (ei_child->is_freed) - continue; + entry = &ei->entries[i]; + name = entry->name; - name = ei_child->name; + mutex_lock(&eventfs_mutex); + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out_dec; + } + r = entry->callback(name, &mode, &cdata, &fops); + mutex_unlock(&eventfs_mutex); + if (r <= 0) + continue; - dentry = create_dir_dentry(ei, ei_child, ei_dentry); + dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out_dec; } - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; + list_for_each_entry_srcu(ei_child, &ei->children, list, + srcu_read_lock_held(&eventfs_srcu)) { if (c > 0) { c--; @@ -787,27 +796,18 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - entry = &ei->entries[i]; - name = entry->name; - - mutex_lock(&eventfs_mutex); - /* If ei->is_freed then just bail here, nothing more to do */ - if (ei->is_freed) { - mutex_unlock(&eventfs_mutex); - goto out_dec; - } - r = entry->callback(name, &mode, &cdata, &fops); - mutex_unlock(&eventfs_mutex); - if (r <= 0) + if (ei_child->is_freed) continue; - dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + name = ei_child->name; + + dentry = create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; } ret = 1; From patchwork Tue Feb 6 11:32:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1480965dyb; Tue, 6 Feb 2024 03:49:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMx7sN72i0VHEf4nNKbSajKySQLxZhDK82wRfE6fxZfOmOl3PcyqiCYXTQIVKS5Oy1zs9r X-Received: by 2002:a05:6122:16a4:b0:4c0:2332:5b5e with SMTP id 36-20020a05612216a400b004c023325b5emr2626125vkl.0.1707220158409; Tue, 06 Feb 2024 03:49:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220158; cv=pass; d=google.com; s=arc-20160816; b=No4WDWb+rrCyjgdtjvkhPhB1kKL352w6M9PaSnlT174jnBp7cfoJuf7VhTKihlIyAq JQjb1zpkrXi+qdjeOgEIKClt1eZwxFhBRcGormCP7PsSVn9F/7XP60D9jKchleJDxEcv 606gib8pUwoLHVzyzS5+GQofvt/n1Mo4r3cu0QB4e7A0DQzh/GjmOROsoUuwDTY2P4dG 6f49Vsj2WNLbRHexun001dg5IEhjWHpH54kQbmxqPwAw/+CmJG24Y6NWhyb56WNrKsZQ 0BmibaWvcFX0qjdhvROJ7krrg5a+Qu66xTVpeUYTqMook/A4ar7m1hg3oUMjO2qG2WoU ZCoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=mZzhfG64JOfp2veODtxBU/uq10vZEr4hoZ4aj1eAhnY=; fh=tN0UuEIWJEavcDR2EkpJjml1yKZ5hKvbw1KCU9KDgu4=; b=Z6Mr0gP4uMzCV3qoE5eY31kMXWWbViTl4ldeOhjSmxEFBYGGzLIHzEpSfo00wJa/J/ 99osn7OIKgsKIbzRHWUpBvCCzwep0CEgWjdzx0KjBa0Uw4+ULP9xgz3mPtXqySZfaVHv GP+7/GZDivA34cBRB5WvNtYPomdH0LyxxaQ3+nqaiIHhsTfah6mmAygFww/2t6vNxBW4 BWte8C/oIPvLGOCXBuAPtstYCUlTOJxT20s0BUsx2XejVmA/nOrzIK0xRBCkDYZs05PC gqFkTmdQqNl8Fbq/QQ5DSJJZAV8ucq68qIx8jRyUTjTX+nOqWxm+iv9cfnZoJuVvkkKA Guxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX8wVmLKP9Le3bQCspA6+fEJ+UoPSadbwc9Gc7E/m3OA1IH929jwLROKe1un9NySP0hZy8SYvMUlaEHsNAwGvN1Y2nskA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jk8-20020ad45d48000000b0068cb7c04c0csi354009qvb.186.2024.02.06.03.49.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:49:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 337C51C21C70 for ; Tue, 6 Feb 2024 11:49:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 993A81369A3; Tue, 6 Feb 2024 11:33:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 873BC13399F; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; cv=none; b=Hbi3YIqnCcpGxKoFQnTYNQtcZ3QLovp2pE3ErykzzTulWA1HhGK8n3TQOoiJhpCeVh6Z2f4TAx+OFGzPbLYtxx0sy7+6UHjyg3Y76tAXF3vK1XVal9pkyD9+tcmftcyOAbHcVTw4H+9u7PvIe6WhkA1mN5hWH5XZEPwXwrdJTVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=KBGhBIbjsMRKtn4hdiJH0PuIBiRoV1R54hmlDTiI6ZI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gGHJi9W05AmW0q/MANbK6ReNScgqdc/PMfeYtgwS9vVRhqchugnLaiPPolJdFj1LMCaIDjQdEXsBgatMIX4s1wYuBzbYmlxjncL6nY5Fox/zC6MGX42aLpjc56inf5mJRZ5f5RgEYbLnASsyXQrV2g+VoxKtx7v4kRziaFeqr3s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10A93C3277D; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aJp-1YvH; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.229236339@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:05 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 07/23] eventfs: Shortcut eventfs_iterate() by skipping entries already read References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150084610032262 X-GMAIL-MSGID: 1790150084610032262 From: "Steven Rostedt (Google)" As the ei->entries array is fixed for the duration of the eventfs_inode, it can be used to skip over already read entries in eventfs_iterate(). That is, if ctx->pos is greater than zero, there's no reason in doing the loop across the ei->entries array for the entries less than ctx->pos. Instead, start the lookup of the entries at the current ctx->pos. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.494956957@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 1de94b52d5e8d8b32f0252f14fad1f1edc2e71f1) --- fs/tracefs/event_inode.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index a1934e0eea3b..fdff53d5a1f8 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -746,21 +746,15 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) if (!ei || !ei_dentry) goto out; - ret = 0; - /* * Need to create the dentries and inodes to have a consistent * inode number. */ - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; - - if (c > 0) { - c--; - continue; - } + ret = 0; - ctx->pos++; + /* Start at 'c' to jump over already read entries */ + for (i = c; i < ei->nr_entries; i++, ctx->pos++) { + void *cdata = ei->data; entry = &ei->entries[i]; name = entry->name; @@ -769,7 +763,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); - goto out_dec; + goto out; } r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); @@ -778,14 +772,17 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) - goto out_dec; + goto out; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) - goto out_dec; + goto out; } + /* Subtract the skipped entries above */ + c -= min((unsigned int)c, (unsigned int)ei->nr_entries); + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { From patchwork Tue Feb 6 11:32:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197335 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1479861dyb; Tue, 6 Feb 2024 03:46:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5++dNCbdOOvz/o2jQiFnEqmIUWVg35OxadM2JMQg0TnlvyBZbd5LKGQpIzgOg2omSBB58 X-Received: by 2002:a9d:64d4:0:b0:6dd:e29d:dbf6 with SMTP id n20-20020a9d64d4000000b006dde29ddbf6mr1914956otl.16.1707220002995; Tue, 06 Feb 2024 03:46:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220002; cv=pass; d=google.com; s=arc-20160816; b=B8ua0Yk5+La4aSyq7Xg3hS7UKvUDBhRq6Ed8Hh+KHF0v2sGL2l0CmpS/dLcVEhXONy 0sUv2tJzTdLsJbvKPE5CcJVkor7bXvUumURstEPXYRJBaWlGClZ7Aop9gzgM/QDzi2il NxYptQoQlnkk4F4beQlKFbAdVbjNSqmEhN4npQXurYWo4pg6z7uy4KaemAI5voZ6rZUU shvoesJv+J2NBh2b47l5tvS/myTeQzdG2oHqxPwrjO1KueV5j//Y9vllPSSdqTIrFe4l 70o20CQey8jadWlq4Gi2oWWpbxz3TCD35GHNSgrk9XWMGZkOn1AmO2daL32Q8qmqdDg6 VCKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=td1cyB3gu4vQ5m1uxuZTAdd1+/C4/C4JbPlA6D7R5q4=; fh=XznEfJaYTlPakgPdqXirKeyyJrCljedkxrjjPMvkHt0=; b=JCICoRV/VFjkWQf9fEyQ1QbAGk+rTzR1eJcQp0zhFUFUFI/B3ynYaR1souAvxnfaY8 hsvaLBKQWnsLb2POtkpBTgfG0J4P8Yj/Ea70JN43E6p8wLRE8pCxuqVlfnbdhnwtXwYF i+8mXA3l3t1iskDFkOykjPExqNkRmzgtD/nEInycPf5dB6Rfe5tdriBSt8OF4czHLxwU kucH4B4YBJ1gURLxcexY5WjMzJBUE/d1mjIl0/gaJ+DMz4yUlHzeKJb5xEm7Wmp4IzsQ tTu1TJIHNZcGktOca4wTa4PJfErXLhbCsHu92J/RL41yjb7gwOmCjNZNGkzfg/0Rm2zr A5lQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54792-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54792-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUAGqc6hnqNYWikpRq/tCcWyUDXmJjnJd3+Fj/rExZ6W2PrPGnyPoliHKBr/UlV049pYc5zVJLPJ7UB7XLvguskH827Gg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id i38-20020a635866000000b005d622b60818si1552944pgm.803.2024.02.06.03.46.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:46:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54792-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54792-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54792-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id F374FB223E4 for ; Tue, 6 Feb 2024 11:46:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD99D135A45; Tue, 6 Feb 2024 11:33:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B136133987; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; cv=none; b=PBJwj2CcHbU3Qsc2uLHuio2wxfLDKOR+bISjr4W6Rlgo9TFYRVjihSvNQPCO9wy/ZSEPPlGuAkTZuzsmaFkCu6AKvOjnqKosHhFZXfpFvBTgtTVFl7pnEkOfiHAqhH9IxQjAO7zva6kHUOaX3eaiZ4zcF4f3rgCR1igS6bocz1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=JSygnlx6+56lX3XXzthIgsNjw4j5XL26vPR3L/z2tEs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aNHJpennxOWhSmaLTPRnq8Jd5WX9qI7JzeT/ryWz5eDLa7h9pLVmzERqmx6kY8LKI0DYF0BrbvzojNd1VImkrhKE6G/gxVYIcHoWH7wJuGRKbtqm0ycDNBlmQa8NM+ERVCzzWx+Hq26FyUAotuibgIGnxb7TJN4M73Gay3Jdxm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1EEF0C43330; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aKJ-2Ejb; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.393228331@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:06 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 08/23] eventfs: Have the inodes all for files and directories all be the same References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790149921747454755 X-GMAIL-MSGID: 1790149921747454755 From: "Steven Rostedt (Google)" The dentries and inodes are created in the readdir for the sole purpose of getting a consistent inode number. Linus stated that is unnecessary, and that all inodes can have the same inode number. For a virtual file system they are pretty meaningless. Instead use a single unique inode number for all files and one for all directories. Link: https://lore.kernel.org/all/20240116133753.2808d45e@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240116211353.412180363@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 53c41052ba3121761e6f62a813961164532a214f) --- fs/tracefs/event_inode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index fdff53d5a1f8..5edf0b96758b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -32,6 +32,10 @@ */ static DEFINE_MUTEX(eventfs_mutex); +/* Choose something "unique" ;-) */ +#define EVENTFS_FILE_INODE_INO 0x12c4e37 +#define EVENTFS_DIR_INODE_INO 0x134b2f5 + /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from * its parent's list and will have is_freed set (under eventfs_mutex). @@ -352,6 +356,9 @@ static struct dentry *create_file(const char *name, umode_t mode, inode->i_fop = fop; inode->i_private = data; + /* All files will have the same inode number */ + inode->i_ino = EVENTFS_FILE_INODE_INO; + ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; d_instantiate(dentry, inode); @@ -388,6 +395,9 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; + /* All directories will have the same inode number */ + inode->i_ino = EVENTFS_DIR_INODE_INO; + ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; From patchwork Tue Feb 6 11:32:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197341 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481127dyb; Tue, 6 Feb 2024 03:49:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcOq9Nb03GAWcwBhdtlAt9AOGiDXL0OmPvUXKIh7BrP+Di7MAqQqokJhbnwkZGMo17q/pL X-Received: by 2002:a05:6358:5e05:b0:176:56b9:d4e1 with SMTP id q5-20020a0563585e0500b0017656b9d4e1mr2366514rwn.23.1707220179059; Tue, 06 Feb 2024 03:49:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220179; cv=pass; d=google.com; s=arc-20160816; b=NlGuU8+l9OhI3ctc5IU2v7PfRl6OGUmPdzggriAKvi9XTzC7/2b5ibpn8QO1fV0X42 9MBmjD+kP/PeCwG5lGRTWfSdzPlQJ5TnU6kWluWjEaxygncp+VKDxOgC2VsAj41doUs1 qN4OqxKH6HIvIx9xLPfHo4W5eamJtb4aYYK/JPxP0zv2zKkswTGtSi8jshmPtB6B7/4P aNyOgx3Vpy2oFdeZcJF6DfVCfd8WzHwEbUTepjYaegiFrVzwuLiMGKcKBOazkJuxXgkS leXq+e3UF2AGk+2WixUpFiDyz9LgRffYgQcreief6+005GBmDfQcD8BVUlWZEa7g1cXp yfXg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=4kJElqzHxcp8SMj6H2Aq/UhawQMCk4MTJETashvgb4Y=; fh=R3Gp4ReT6kVBtpDTnuSowjwl8rBEZgedXHtpbDdN+qM=; b=w/lXCTbzR3UXJFE+nptRXFWZSiYlVD4mQjo+Bk17rDGUHqnCmDsVdclRAKdLg1ZXkS f8ESIQ82pWbJlMVMRLfUGraLBU3SXYQUkvES+fcEt3wihhnJJU0KaLRe28YP7RmjZevk BChGaRfzuucb+j3HOWQ7M5DxoUnDYbZHpnOj6kX70eJcdRIA8zVDsDwbHkBzM8h+Lbjz z8LQP+mnX25wu626GEszj/2nNBVEkUdLGjcEE4x5DAr+MqbaHq8+2dCb2xaPFsSvKKXQ SQoB3kbzuNBYa3JGXVfes7h1CziO/luWLqFoXDULZrd0u3Vy+e0bDcQMW4UMcsUj6s6B 1blQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54795-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54795-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVQGb9p1OaE+6BHstN/TR4ajLzM1UactKSYbmxqTFWnLIde79zQ0quFbcvkNVhPDRG0PZXoKBSgLEgcnujwePeB33P1iA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q124-20020a632a82000000b005dc15e82c47si1555129pgq.363.2024.02.06.03.49.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:49:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54795-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54795-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54795-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id C4BEF281AAA for ; Tue, 6 Feb 2024 11:49:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8DD0137C20; Tue, 6 Feb 2024 11:33:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CF9F13399D; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; cv=none; b=KVDfZGkyJDJsBZQxdY25OgvqKHJDlyRTTy+iqUjf8UB/W1+xoFXE+W9nua+bRGJD4O/nkU3bGWxBtROn1hYQoK3z5a/1itYAE5WA1HExltIUDUJVMItK//1NeQJOX776xVmMPG7trtfqomhIezV0Pie0hUsvz2xy8D7uhutxQsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=iFY7n9Vhp/1z36GCtxu4sEAjzXxFREHW/cV48tOlaOw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=N1C0I2XVTIRK7a+hXA0K+5uyWQ6KCvvPbZBNFYN07v7gzqKclkMC+svMY+pSrdEhEFIi43a42bY3w2CsAVDHeyFIzrekp5t3hUs8k5Y7z8muOLlijj2FQDwmL58MIX/N1yeEV8WBJMi2jYDME6lVTKn3r9MfGu48ZG96lmIZpjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 589ABC43390; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aKn-2upQ; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.552951427@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:07 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.7][PATCH v2 09/23] eventfs: Do not create dentries nor inodes in iterate_shared References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150106536649920 X-GMAIL-MSGID: 1790150106536649920 From: "Steven Rostedt (Google)" The original eventfs code added a wrapper around the dcache_readdir open callback and created all the dentries and inodes at open, and increment their ref count. A wrapper was added around the dcache_readdir release function to decrement all the ref counts of those created inodes and dentries. But this proved to be buggy[1] for when a kprobe was created during a dir read, it would create a dentry between the open and the release, and because the release would decrement all ref counts of all files and directories, that would include the kprobe directory that was not there to have its ref count incremented in open. This would cause the ref count to go to negative and later crash the kernel. To solve this, the dentries and inodes that were created and had their ref count upped in open needed to be saved. That list needed to be passed from the open to the release, so that the release would only decrement the ref counts of the entries that were incremented in the open. Unfortunately, the dcache_readdir logic was already using the file->private_data, which is the only field that can be used to pass information from the open to the release. What was done was the eventfs created another descriptor that had a void pointer to save the dcache_readdir pointer, and it wrapped all the callbacks, so that it could save the list of entries that had their ref counts incremented in the open, and pass it to the release. The wrapped callbacks would just put back the dcache_readdir pointer and call the functions it used so it could still use its data[2]. But Linus had an issue with the "hijacking" of the file->private_data (unfortunately this discussion was on a security list, so no public link). Which we finally agreed on doing everything within the iterate_shared callback and leave the dcache_readdir out of it[3]. All the information needed for the getents() could be created then. But this ended up being buggy too[4]. The iterate_shared callback was not the right place to create the dentries and inodes. Even Christian Brauner had issues with that[5]. An attempt was to go back to creating the inodes and dentries at the open, create an array to store the information in the file->private_data, and pass that information to the other callbacks.[6] The difference between that and the original method, is that it does not use dcache_readdir. It also does not up the ref counts of the dentries and pass them. Instead, it creates an array of a structure that saves the dentry's name and inode number. That information is used in the iterate_shared callback, and the array is freed in the dir release. The dentries and inodes created in the open are not used for the iterate_share or release callbacks. Just their names and inode numbers. Linus did not like that either[7] and just wanted to remove the dentries being created in iterate_shared and use the hard coded inode numbers. [ All this while Linus enjoyed an unexpected vacation during the merge window due to lack of power. ] [1] https://lore.kernel.org/linux-trace-kernel/20230919211804.230edf1e@gandalf.local.home/ [2] https://lore.kernel.org/linux-trace-kernel/20230922163446.1431d4fa@gandalf.local.home/ [3] https://lore.kernel.org/linux-trace-kernel/20240104015435.682218477@goodmis.org/ [4] https://lore.kernel.org/all/202401152142.bfc28861-oliver.sang@intel.com/ [5] https://lore.kernel.org/all/20240111-unzahl-gefegt-433acb8a841d@brauner/ [6] https://lore.kernel.org/all/20240116114711.7e8637be@gandalf.local.home/ [7] https://lore.kernel.org/all/20240116170154.5bf0a250@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240116211353.573784051@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: 493ec81a8fb8 ("eventfs: Stop using dcache_readdir() for getdents()") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401152142.bfc28861-oliver.sang@intel.com Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 852e46e239ee6db3cd220614cf8bce96e79227c2) --- fs/tracefs/event_inode.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 5edf0b96758b..10580d6b5012 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -727,8 +727,6 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct dentry *ei_dentry = NULL; - struct dentry *dentry; const char *name; umode_t mode; int idx; @@ -749,11 +747,11 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) mutex_lock(&eventfs_mutex); ei = READ_ONCE(ti->private); - if (ei && !ei->is_freed) - ei_dentry = READ_ONCE(ei->dentry); + if (ei && ei->is_freed) + ei = NULL; mutex_unlock(&eventfs_mutex); - if (!ei || !ei_dentry) + if (!ei) goto out; /* @@ -780,11 +778,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) if (r <= 0) continue; - dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); - if (!dentry) - goto out; - ino = dentry->d_inode->i_ino; - dput(dentry); + ino = EVENTFS_FILE_INODE_INO; if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out; @@ -808,11 +802,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = ei_child->name; - dentry = create_dir_dentry(ei, ei_child, ei_dentry); - if (!dentry) - goto out_dec; - ino = dentry->d_inode->i_ino; - dput(dentry); + ino = EVENTFS_DIR_INODE_INO; if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; From patchwork Tue Feb 6 11:32:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197340 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481101dyb; Tue, 6 Feb 2024 03:49:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMMVXCjCF6nI1VyO1Wb5mRdWjG18mw8smQ32/L3qGi3HbS7vk+O3SFBmUA1cODCu7kB+yp X-Received: by 2002:a05:6870:d107:b0:219:442b:abd0 with SMTP id e7-20020a056870d10700b00219442babd0mr2536972oac.49.1707220175005; Tue, 06 Feb 2024 03:49:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220174; cv=pass; d=google.com; s=arc-20160816; b=CQnf0o+TdeJfXLd023OLiYBZByPWQtTD9PfJYJrG6n3/RQrT44g33qnRva/7TlYTyg 9WO55DyCmHB3lOMKRY/V1dyDp+loeJXEyvxF5++BX2yjhxBmrnlAb53NPSoR/+1O745F iVASH0n7pFd1xXO8l2sO0fCixJMS67xSldvs86MmJcjYXEmkO60cXzHKt8O0l92e4Pne rlBS3WOaTAksErYcVJxFEiP6hvTsST0gWpb9621B9sXJPN5eZ3KloA4ETmGX1z41I+q2 j+B8sFAdDwbPG97troejj3i1Kr/753P8DkgMPzSN/HlWUzrZ5NMsdEESN7M6dhfYs+BH wLvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=lR6au0kG3WFsHJQwGXzt6iecpuPnXQli3iId+Lo3sbw=; fh=/Teh1vuF58PkzZmpoz/B5X9cN9rS7nQNBXDuw3yKtMs=; b=lGuAlUdlhSPQyaMLNcUtXB5/EC3qfWlAcwW7GQICq4QfobArJ5hDoIZRRMdIq7sLFj GjIc2KoE7ThcpNV7F6WlA06RlgCdJyWiRt7env3th3MTDd095+swQmmadod3CSbSjo9E 4C0pZjM0gaoaSX7owjqC3awtXQc0tXUSJoS+4yVUCTa8TBgYnd1cmiitGzlMcOiRcbt0 3+d06pAr7G4II1m75pURf0I0E1DGtH6WBS5Pt5XdeNRAF3iXAt+gt26rAubTgCX6LOLn QcS9XMCV/jUMM+oNCMDEJ1nZga8PHJ3ylqmX5Y7zpEfGK0pbArkOVgYW1cry28qNF3Zi 8Z0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXClOkMkDqtbDQ8zUKdb9tUfi15M1Pxik/9n9hcUKRpLjhdlMKiy/00ekoZqkoI2ga7I/hhBJoXIdybfBG7yLdHaKXZRg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 187-20020a6301c4000000b005d8e3a180cbsi1578390pgb.841.2024.02.06.03.49.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:49:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54797-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 11AAF288550 for ; Tue, 6 Feb 2024 11:49:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C09131369B1; Tue, 6 Feb 2024 11:33:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B65C1339A6; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; cv=none; b=an8vO7GRstKip+ehyZT2mx3nrI9R2XUM2NP7KJA+PetsvXACkCn8HUeRjBnRDMzLFn0qdydQs1XGSGdH7ObW77WFHDsDVfNWyR+hdyVT294+cO/1k4ji9vgQ2nXF6WTv4x/8aSyDfqLNS8kE1RVqMCMLOtF+MmOCnd61xeBCE54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=S927KE9dYG/Lzm2Z83o0zTy+NJITK2h/kIEZaYEod3o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sCqYJT54z6FIHdc24IaW/wC9caSfmOuXrghXEbSjRwXecVCSz4S2zeT6j6VJ8Cb+lNLnU1Wt1KSZ6Kq5qpfPjXhqCfgHkW65Lquee75xAz9tQlVgZCBVOScCF3y0KedZu14hClkth3flYysQBIL5O89UD4oN+l/iT476YyVE+ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71994C3278F; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aLJ-3ZBf; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.716264689@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:08 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Erick Archer , "Gustavo A. R. Silva" Subject: [v6.7][PATCH v2 10/23] eventfs: Use kcalloc() instead of kzalloc() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150102275186632 X-GMAIL-MSGID: 1790150102275186632 From: Erick Archer As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, use the purpose specific kcalloc() function instead of the argument size * count in the kzalloc() function. [1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments Link: https://lore.kernel.org/linux-trace-kernel/20240115181658.4562-1-erick.archer@gmx.com Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Mark Rutland Link: https://github.com/KSPP/linux/issues/162 Signed-off-by: Erick Archer Reviewed-by: Gustavo A. R. Silva Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 1057066009c4325bb1d8430c9274894d0860e7c3) --- fs/tracefs/event_inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 10580d6b5012..6795fda2af19 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -97,7 +97,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, /* Preallocate the children mode array if necessary */ if (!(dentry->d_inode->i_mode & S_IFDIR)) { if (!ei->entry_attrs) { - ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, + ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs), GFP_NOFS); if (!ei->entry_attrs) { ret = -ENOMEM; @@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode } if (size) { - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) { kfree_const(ei->name); kfree(ei); @@ -941,7 +941,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry goto fail; if (size) { - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) goto fail; } From patchwork Tue Feb 6 11:32:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197342 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481317dyb; Tue, 6 Feb 2024 03:50:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEJH7eHBGumjD32uSjulFttCgIsMjjE1Yr4FAPlW7FILAXhEQpN1fiT3xyznlJNfPqlHsb4 X-Received: by 2002:a17:907:785a:b0:a37:ee9c:273e with SMTP id lb26-20020a170907785a00b00a37ee9c273emr1306319ejc.53.1707220205948; Tue, 06 Feb 2024 03:50:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220205; cv=pass; d=google.com; s=arc-20160816; b=O821WxdlZd52yUnUNk1/QecRNNRCJ+/dRmdtPkGyOgORRnrCCBxh8Cb/ne2DLBPZVK DIjBHHK1EBTB32IHZ0djeaUjZvyFlkrw2PibmegbEZBi1lJvliYfwgHDoSGwahCmlAdZ /gisnePiB4Io0PrELz+bAp7K9NOXNeYIbvC8JqCqfK/HPmthCAqaZwCnncEYDloyYV3k +2BOO4eq/V1H+qTJi3m1JEP/nHLZ4oslpK+NVR08F17wBfRydicN9hLuRP7f1pxpL/9L DCaeO51Peis9IdUUkDMFc8tGPwN2ssHhFiGCuoOf6lDljPX0+nPKYCDe2RNrTQvZLfGO OIsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=3RN4NWB+356xYpNgRECCmh0ARfrJ2zZfC34yg1jzV3w=; fh=gOjtFAl+vS7MdbkqXBKD/MnK+1fW2Xhgxr+Ufc79yJo=; b=ARCa9OyibUydLnb6YyFfegXS+qjHcu1drd86GZcOreI9Y5tdATRSOJKLqDxPr7P4eS +BFOYsZnOPCMXEr2JqiymRCH3pwKRUFqs/j9GXJqAYOJnzConMBflyzZzSxtHiSHujI7 fYyaIf9N1rc7+QaMoc5v8fDgco98dedfVvUI2YvUuiXAAZjfTS34UJa1Xxvbrogc7KnE mjApLVKWlKuL76Bw2RqCYnoE18kNO+h6x94YgSSwwJ1hS+x2SZMcxFT42S+caxH1oVz2 g98wAiV5owoEZ7o8PYTeDRLe7zKpQGWm7KajQqOUESD6dy2irixDaYJwdPuwzeG7TezR RJHA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54798-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54798-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVYdm0ydzfv/Ikte+OsbWFAZo6PHv3ZLxIk+e4YV/Y36Ewl67AIlYYXMIgNC9LcgBhri1O0AuBepncXZu3bd+wXSzYHBA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l17-20020a170906079100b00a373e466cb8si1017440ejc.528.2024.02.06.03.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:50:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54798-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54798-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54798-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 854AE1F24F64 for ; Tue, 6 Feb 2024 11:50:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ACB3132485; Tue, 6 Feb 2024 11:33:37 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AFDA134742; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=Bf4mnMQ10pqkr9Gfb5McnQAAT2VvHTVinKtCQ2wjdkLtsyxreNAo8rtMuQdY5ALGEccEYs8mWtTTcU1j9h1l5SlrWj34oZcJAh+q6kdqWSMUCP83nZbBrA5VHeJmiGhIQtwdlZ5HfOHYlfblEEZql3AONBy4+rQ5PKmfQAZMeDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=gW8Qs5dhqv8o0qe0O7sTx8CGnoF40JWC8ay85t0nh1E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nyLod5wHtFJe3hFL0Yk3eH32WM+eElEj8VnRunAyNPnvbLEgYxyUVLLxBz6lKe2w9XR4qH0beZ5MyIhNXTblzRoiyoE583YuEQ6uYSDg79nFifPmc0juh39J8p+1QJzLrs/ki26p7wOJgKDY2By35ejnsUIovhzLf9OUAo7YKLA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0B01C433B1; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aLp-042z; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113359.872124971@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:09 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Geert Uytterhoeven , Geert Uytterhoeven , Kees Cook Subject: [v6.7][PATCH v2 11/23] eventfs: Save directory inodes in the eventfs_inode structure References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150134661350555 X-GMAIL-MSGID: 1790150134661350555 From: "Steven Rostedt (Google)" The eventfs inodes and directories are allocated when referenced. But this leaves the issue of keeping consistent inode numbers and the number is only saved in the inode structure itself. When the inode is no longer referenced, it can be freed. When the file that the inode was representing is referenced again, the inode is once again created, but the inode number needs to be the same as it was before. Just making the inode numbers the same for all files is fine, but that does not work with directories. The find command will check for loops via the inode number and having the same inode number for directories triggers: # find /sys/kernel/tracing find: File system loop detected; '/sys/kernel/debug/tracing/events/initcall/initcall_finish' is part of the same file system loop as '/sys/kernel/debug/tracing/events/initcall'. [..] Linus pointed out that the eventfs_inode structure ends with a single 32bit int, and on 64 bit machines, there's likely a 4 byte hole due to alignment. We can use this hole to store the inode number for the eventfs_inode. All directories in eventfs are represented by an eventfs_inode and that data structure can hold its inode number. That last int was also purposely placed at the end of the structure to prevent holes from within. Now that there's a 4 byte number to hold the inode, both the inode number and the last integer can be moved up in the structure for better cache locality, where the llist and rcu fields can be moved to the end as they are only used when the eventfs_inode is being deleted. Link: https://lore.kernel.org/all/CAMuHMdXKiorg-jiuKoZpfZyDJ3Ynrfb8=X+c7x0Eewxn-YRdCA@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240122152748.46897388@gandalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Linus Torvalds Reported-by: Geert Uytterhoeven Tested-by: Geert Uytterhoeven Fixes: 53c41052ba31 ("eventfs: Have the inodes all for files and directories all be the same") Signed-off-by: Steven Rostedt (Google) Reviewed-by: Kees Cook (cherry picked from commit 834bf76add3e6168038150f162cbccf1fd492a67) --- fs/tracefs/event_inode.c | 14 +++++++++++--- fs/tracefs/internal.h | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 6795fda2af19..6b211522a13e 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -34,7 +34,15 @@ static DEFINE_MUTEX(eventfs_mutex); /* Choose something "unique" ;-) */ #define EVENTFS_FILE_INODE_INO 0x12c4e37 -#define EVENTFS_DIR_INODE_INO 0x134b2f5 + +/* Just try to make something consistent and unique */ +static int eventfs_dir_ino(struct eventfs_inode *ei) +{ + if (!ei->ino) + ei->ino = get_next_ino(); + + return ei->ino; +} /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from @@ -396,7 +404,7 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent inode->i_fop = &eventfs_file_operations; /* All directories will have the same inode number */ - inode->i_ino = EVENTFS_DIR_INODE_INO; + inode->i_ino = eventfs_dir_ino(ei); ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; @@ -802,7 +810,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = ei_child->name; - ino = EVENTFS_DIR_INODE_INO; + ino = eventfs_dir_ino(ei_child); if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 12b7d0150ae9..45397df9bb65 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -55,6 +55,10 @@ struct eventfs_inode { struct eventfs_attr *entry_attrs; struct eventfs_attr attr; void *data; + unsigned int is_freed:1; + unsigned int is_events:1; + unsigned int nr_entries:30; + unsigned int ino; /* * Union - used for deletion * @llist: for calling dput() if needed after RCU @@ -64,9 +68,6 @@ struct eventfs_inode { struct llist_node llist; struct rcu_head rcu; }; - unsigned int is_freed:1; - unsigned int is_events:1; - unsigned int nr_entries:30; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) From patchwork Tue Feb 6 11:32:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197339 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481004dyb; Tue, 6 Feb 2024 03:49:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEsEqBzV7RboRozoagGtVYYbhxh90m09+b869mcRBvK42qTzLGiB1QebC1IT5M1YYnPER3P X-Received: by 2002:a17:906:32da:b0:a35:3c1f:b29f with SMTP id k26-20020a17090632da00b00a353c1fb29fmr2288603ejk.5.1707220161757; Tue, 06 Feb 2024 03:49:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220161; cv=pass; d=google.com; s=arc-20160816; b=gpFPpc5psMayKSLX58E1YzAKMFK/CZm00QG9GDO6Fqc/uHWEiW80PJrSkGJvEDgU2A TYlmu6/hGIvfPoNWhX7OP/G/n4U9IPdGLQMgeK8Os8spTuux6CB/WS0dofKsRdRTmwVe sPLkExFnYQYLJSxyDaRUYgCkACfBF7pL8LmESiM5GdVUpFkyVBDSv4vcKD0epCtJNp2Z v/ch9WwYvUKIdkBvILpuk51OcYDIGyjTifgMGZgxOLF0SMShODMY2XJFhsp73zgeRO6L ILk+qgH+3a7d4mXoMq9OVKnPF9GBNp0VJne+1Q3BS50ewo2HYYzvaGKL8y7A80EfFPrM 3pQw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=ez93nIj3r0KL5LhMXr8lgScygvkcsmAkg7g6211UaaY=; fh=qIgmGzPK2k9cCvD5p5Scv/I/U4TTnU6X0uN566hvy/Y=; b=J/wKo9k06Z77Q0KWWvpB7WdI1e4/Inf8Za2a3WMIybAoN2+Gj7ZcfpHLzLt34wHbhh G+rdiR18kcSrFJRMAClHoTLBte6YTezgmjSN6+3u+JVc3+M5kgMs29donYe+ogETZp10 0ptSuqRRa2iuw9sexCGN1ErWIbxn7jmTivErSBCf7JaaqpZMvyfWEWGWgGFwalY4Ez2M s5/ZwanBu0XGp2XBj+wc2rhlwJQcbQ4f54mZGHRf5zOxl3VX06Yid6XauJ6SUZU6Om6P cldfKN6HyuQsxv0miMai5InXDm0bwyLJnS4VrPKDE7msdfMzY3n7KMpveiPWPMRWGJkQ ZKoA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54799-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54799-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXxRnwGmZObjuU3ew+O5pZye2NWox0XEi1Sfz9pVpqgauyiWsrHaB69Y3/1bVS8teqbzVFr1ZxKLtMBnyiAtv17lhI3cA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id g19-20020a170906595300b00a3647d924ddsi954064ejr.79.2024.02.06.03.49.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:49:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54799-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54799-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54799-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 01F951F24E76 for ; Tue, 6 Feb 2024 11:49:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A40071369A9; Tue, 6 Feb 2024 11:33:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 734F3134747; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=eKC8slVqQratL83v4LPgSi3VU9YWjZL3/FbHA/9AoBOMAU2EheSZZM/3GwmpwHsQJcSdEh4a/r0WQkGun7e+eAnpsZErHRCFj7BT0VvBl22szAYv6n8yzJP37Rd/S18tRPT08uFx2uIJi4FfGdWBp9Q2kHh+jtRDecobkMnmTro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=3cuwo8jKNFJ8ZNaRFdtkUgaWTecxRB1l6ECQ5pijtZI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=SU0Q4xoQIxmhdVJp55/zreRVBoqnnJypBwuH4v4gzTUpnonPxqnSwR6Gya4JM6vfSBFTLXnkNtrzPejNd9NIEpy6EBf0KcbeIoWAbf6RWOwDOP8tzvaGkj8rsDuzW31019E5Djn+2Uw4C5F3Ei9+4FDfuufb+s5Z9BWECGnaKGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5504C43399; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aMK-0l4Q; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.036997635@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:10 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.7][PATCH v2 12/23] tracefs: remove stale update_gid code References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150088400917437 X-GMAIL-MSGID: 1790150088400917437 From: Linus Torvalds The 'eventfs_update_gid()' function is no longer called, so remove it (and the helper function it uses). Link: https://lore.kernel.org/all/CAHk-=wj+DsZZ=2iTUkJ-Nojs9fjYMvPs1NuoM3yK7aTDtJfPYQ@mail.gmail.com/ Fixes: 8186fff7ab64 ("tracefs/eventfs: Use root and instance inodes as default ownership") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 29142dc92c37d3259a33aef15b03e6ee25b0d188) --- fs/tracefs/event_inode.c | 38 -------------------------------------- fs/tracefs/internal.h | 1 - 2 files changed, 39 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 6b211522a13e..1c3dd0ad4660 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -281,44 +281,6 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, inode->i_gid = attr->gid; } -static void update_gid(struct eventfs_inode *ei, kgid_t gid, int level) -{ - struct eventfs_inode *ei_child; - - /* at most we have events/system/event */ - if (WARN_ON_ONCE(level > 3)) - return; - - ei->attr.gid = gid; - - if (ei->entry_attrs) { - for (int i = 0; i < ei->nr_entries; i++) { - ei->entry_attrs[i].gid = gid; - } - } - - /* - * Only eventfs_inode with dentries are updated, make sure - * all eventfs_inodes are updated. If one of the children - * do not have a dentry, this function must traverse it. - */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { - if (!ei_child->dentry) - update_gid(ei_child, gid, level + 1); - } -} - -void eventfs_update_gid(struct dentry *dentry, kgid_t gid) -{ - struct eventfs_inode *ei = dentry->d_fsdata; - int idx; - - idx = srcu_read_lock(&eventfs_srcu); - update_gid(ei, gid, 0); - srcu_read_unlock(&eventfs_srcu, idx); -} - /** * create_file - create a file in the tracefs filesystem * @name: the name of the file to create. diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 45397df9bb65..91c2bf0b91d9 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -82,7 +82,6 @@ struct inode *tracefs_get_inode(struct super_block *sb); struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); struct dentry *eventfs_failed_creating(struct dentry *dentry); struct dentry *eventfs_end_creating(struct dentry *dentry); -void eventfs_update_gid(struct dentry *dentry, kgid_t gid); void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 11:32:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197344 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481824dyb; Tue, 6 Feb 2024 03:51:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IENkl5CTbX0KWLNoi0+zimktum6LvAF0qo7oFeVJrXcJYswwRv+IJZC1PAAPlbWjevGzxLx X-Received: by 2002:a05:6a20:9f07:b0:19e:9adc:b274 with SMTP id mk7-20020a056a209f0700b0019e9adcb274mr638949pzb.41.1707220290082; Tue, 06 Feb 2024 03:51:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220290; cv=pass; d=google.com; s=arc-20160816; b=Rks5JSE+PxMwoTXt6QMgtnGW4DZgNngu1lvNXvIZhRfcAgVW0um3g6bYQg3hhO+0nO iNbeXh3m+a8OsrBayjTRyAkRc9FCzPCt1Bxcb07x21jjiJhSe5DwOerv06yrCeu2atgE 2ZWDxzq2Fd6xjzJHXLoQaXXlrSkUQMwVBR8783fwv4stlHdv0bb8xmJVKKaTGELNTgLW WqQ9bO5ijxzUxOA57KyO9xziSrQAfi3MxZmCkNqEqt+tyCmSBnVHVDeHFKyuHNNRNRBw rMxjwpdU75RJotrDO5rM8TuJ6eBxSCCpM3eKQB9yUYD7WVS4Rx0jPNT03gguhxw9pZkP 6gCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=AcY/gmMvKwen29N+PLFW2SFwBOrjsupe21rRw/oEiNk=; fh=mdLRaWUXB/wyN2KcmuhLhgOCw8weVRAsoYfE0Im5BX4=; b=n+wl6xzPts8JuCWQkc/IZ51YswUfy6VpLbNG+4OandITad9DrqPveWfKzqduBdpsdG QkEqi8Lzdn9Pw3Jmyy1Zet5i2YPrJ7yvBK6mvoF04w5T5ZCUcTCFuH8eY/9WcivVDsHZ eoTf3kX7N3pYio9rPnRjqcMQ9jzXs1rkkHFRrimPbEe/WRH1voNG+w6/YHePLMtOD2FP yezqcCUT9qnr4e8Jg10sMut24A4VXgobMeH8nQBgbRxe1BVW2DvuoYbNkwVJdgLcDlx5 6qQ3wc6Ya3GhKvY0z8Ip48RuaDplx/pi2nLAXTyP9twv3dtiu2HWUPZIKrXhrBZvh0gk VywQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXAbqyL0+ZMR5LLVeUp8ow3RnNLMTL1Mb9t3yX3x3Ll6SVIpbvE/z4l2GccB6X4NmwHsZzbCs7s5rbcaVVbV6n2raCTzA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id it21-20020a056a00459500b006e04d1b0394si1479240pfb.48.2024.02.06.03.51.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:51:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54800-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D7A3D2857C8 for ; Tue, 6 Feb 2024 11:51:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E18C1384AF; Tue, 6 Feb 2024 11:33:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7354D134748; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=toSh0inuM0BxM83f1Ztx+pY/fhvmgKmQGuo12vmIAgiai0KGYgbus55wAlSynXOqIIFDnmrE7QnOtXJ+qrK3+3nt6hUG/bzSVkyV5cOtNdIvGJsDSK25CsZEQMtZKj8WBBOFefurHj0c7QNrZZIzuPNWh6RETQh65IQ9hSDxmMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=sfvjVRo/uEnLvIM2+rrv73QKbK6qOK2EnD7X46CxfoY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hb3tnC/C6Y5E4VwA76ssI6bMjNdArdGl+HfIM4ZFKizne9War8xNBspclfGuD5qred3/c5orKlCNl6YieLCMroZdNB10x10nxfPEvUSWMhIoIbCGSct01Ay6pAwPUkpPHWwKxg58G/GDRkLr/FJYg6FwVbyYeKjwmW83HKHIIlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09E2DC43601; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aMp-1QiL; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.202745776@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:11 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.7][PATCH v2 13/23] tracefs: Zero out the tracefs_inode when allocating it References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150223367052655 X-GMAIL-MSGID: 1790150223367052655 From: "Steven Rostedt (Google)" eventfs uses the tracefs_inode and assumes that it's already initialized to zero. That is, it doesn't set fields to zero (like ti->private) after getting its tracefs_inode. This causes bugs due to stale values. Just initialize the entire structure to zero on allocation so there isn't any more surprises. This is a partial fix to access to ti->private. The assignment still needs to be made before the dentry is instantiated. Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.315825944@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401291043.e62e89dc-oliver.sang@intel.com Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit d81786f53aec14fd4d56263145a0635afbc64617) --- fs/tracefs/inode.c | 6 ++++-- fs/tracefs/internal.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index e1b172c0e091..888e42087847 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -38,8 +38,6 @@ static struct inode *tracefs_alloc_inode(struct super_block *sb) if (!ti) return NULL; - ti->flags = 0; - return &ti->vfs_inode; } @@ -779,7 +777,11 @@ static void init_once(void *foo) { struct tracefs_inode *ti = (struct tracefs_inode *) foo; + /* inode_init_once() calls memset() on the vfs_inode portion */ inode_init_once(&ti->vfs_inode); + + /* Zero out the rest */ + memset_after(ti, 0, vfs_inode); } static int __init tracefs_init(void) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 91c2bf0b91d9..7d84349ade87 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -11,9 +11,10 @@ enum { }; struct tracefs_inode { + struct inode vfs_inode; + /* The below gets initialized with memset_after(ti, 0, vfs_inode) */ unsigned long flags; void *private; - struct inode vfs_inode; }; /* From patchwork Tue Feb 6 11:32:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1481795dyb; Tue, 6 Feb 2024 03:51:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlv2bZzMebcFUUgbqbHiq4jGxtvZ0Bi0rrVCZx0p/i28qvWMcPT+w16gxVqT73jJdyx2Gx X-Received: by 2002:a05:6a00:2da7:b0:6e0:46fc:c2f7 with SMTP id fb39-20020a056a002da700b006e046fcc2f7mr2557345pfb.8.1707220286720; Tue, 06 Feb 2024 03:51:26 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220286; cv=pass; d=google.com; s=arc-20160816; b=PSWtJSfZoEEWoV7vukJex2If2OTeZC3jccTLeLJUCgeCmle6U7Dzr6CXqAGBgloesW ubPCp/Xqn9P+UrPeM+Q5kBSIhQ8TjWslCJXxiDUMsQFIZIMLD+Zzeu+EqUvxmSbmn30h MnRbSurH3G2v046/8dNww2W1UXWGjvGV9lCHTIr75ulBcqQPeV29yO4E6j4F2TtHYeuf xFgNxaF/njvqr4cloN9WRz8zysiEB0tdbwvudg/sthqvlNDAlN/Qc23NrHJDxhdgUwpl DQ63SfDeNEyU8Jeq3uy8g7lc6PvkdWIrTttclMySpuk0yrQKj0dXmbc53pVrZddZTLEE 8+Uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Vc5Hl8wHLvI4a/MX2Qudri1ew2Nu0ownXruYvDF/VTo=; fh=//Q9oHG9xDAus2xGOuEUhvwTZf3qOeF1NOFCBNeMCGU=; b=K/kKfubdbP1yI7goZWthJq0YVGE4g/rQEZq5hMpFoWpXXqbtx0Dq99GohtiUbG89fQ ZfHVXCS9b8drn4v5hUlklQ7xwo3saxS5Y4Ak2Lan6n0rWf7NLjDUKC7Hjv27LUTGouBA fmEsFixytV182E2tSmAqTA6Up2DabTUkuD8i4bpjU2z+h5XbjU3y4iZDQoz4xQU2U/e1 daUTyqm/nlcXeg8mw0/dlkOFj3BMIjf6G33AF/pBcnJC/LgM1JOMn/Y1Op3SUhUH07UD IntKmZQ2LwguqelG5HRknTLYNUj8q3VQL7w/A/8UyKJdIqpmNohQZhNLbXcGAQrB7PXa 3JKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54801-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54801-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWrzWMPKxjTsGYGNyuYMPixgTWoscjJTPu5y8lUupNhQk9ieBNvPQKsuG8ZVhDC5QVznvoAOrn/1JJvnkmJnTezWpG0Qg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p2-20020a63fe02000000b005dbf2ca6e6csi1466583pgh.714.2024.02.06.03.51.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:51:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54801-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54801-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54801-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 74D0B2854D0 for ; Tue, 6 Feb 2024 11:51:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2654A1384AC; Tue, 6 Feb 2024 11:33:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7359113474A; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=qYY6gV65qVnQtVLBYAmRc72mjzKIbSadKF5G6pSpsbbrKJDXtFEqoKMcDT1kDhtUodc6yD+g5HbtO6vrGRShIsCeWUSgBvqFJBq2Xj6dXdS5BCv8gs1E6sl17J2Y/Gefpd8tlsPhCjZGF+yWUOiEzrFCkgz4ODD+DNKS+BOJd1Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=/K/tqg9istqeXtA6KzMmoqfKg3qYs4d2GHKRR+nK7sY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BaFmHSQJ6VY/N0eyuH+Py26guINifwbzU3PawqeZZRlMW0K4ZiuId53M1Rkh2BTDy6CcszPRqzq3Xr9yVWdoy5VLjYaHll7EGljpv7YlmCCSQeIoBm9ObXj2mRPwG8sYhhwhyAuKVHINzaN3x29Mj41Mz6kE9++NIej/R9EYhKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 134D1C3277D; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aNJ-27Hk; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.362338010@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:12 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.7][PATCH v2 14/23] eventfs: Initialize the tracefs inode properly References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150219629787502 X-GMAIL-MSGID: 1790150219629787502 From: Linus Torvalds The tracefs-specific fields in the inode were not initialized before the inode was exposed to others through the dentry with 'd_instantiate()'. Move the field initializations up to before the d_instantiate. Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.478449628@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401291043.e62e89dc-oliver.sang@intel.com Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 4fa4b010b83fb2f837b5ef79e38072a79e96e4f1) --- fs/tracefs/event_inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1c3dd0ad4660..824b1811e342 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -370,6 +370,8 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; + /* Only directories have ti->private set to an ei, not files */ + ti->private = ei; inc_nlink(inode); d_instantiate(dentry, inode); @@ -515,7 +517,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, static void eventfs_post_create_dir(struct eventfs_inode *ei) { struct eventfs_inode *ei_child; - struct tracefs_inode *ti; lockdep_assert_held(&eventfs_mutex); @@ -525,9 +526,6 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) srcu_read_lock_held(&eventfs_srcu)) { ei_child->d_parent = ei->dentry; } - - ti = get_tracefs(ei->dentry->d_inode); - ti->private = ei; } /** From patchwork Tue Feb 6 11:32:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482369dyb; Tue, 6 Feb 2024 03:52:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGA/pY7s/txrkob7QNvOJYey7KotFB33Te9WnbLF51hYqm6zv7J3S1rEZGEZROCcSiNBufA X-Received: by 2002:a17:902:e5c4:b0:1d9:a5ec:30d2 with SMTP id u4-20020a170902e5c400b001d9a5ec30d2mr1505046plf.12.1707220378627; Tue, 06 Feb 2024 03:52:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220378; cv=pass; d=google.com; s=arc-20160816; b=JfO8lB7EIgJoc0DVa5fRY7J5yhnYUxysU7Gc4qHWDpe1JRsM/pCRqY729Og8LL8cX7 yfD3+eChqXuou0Gr45r5ZHEArxQUBVxZ7TRWn+MEvsFp5ViVM0vCORxEqulipCOg24CG J9MThVBm972KcUtwXHOxYHE4R3FD6fSQneQWby70qr0EU2JqwpLin6FJzDaVFlXi0UmH 4vmMy+PCnGsm/pJi9ZHp1DXkuRidYVgo6tU8qlX8ZM9qSpG+BOzCOZD0Eb1HBYWbV++j qJo+eFR1ZicPbBJ6eWyQBnMeGv86LNBVrOfZ0mL3014HKFRVLHxzHMUJvaiOVV9IaUtv twAw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=qLO9528/AFQeQ08mVECH/y3JPQcyc9jWqtGZe8Oheaw=; fh=IQawZvBLYF5JFZI+rFb8AokumLl5RtI5O3pDK2MGN+c=; b=Rak8PtN+cdF30ZgqBr0iuZTiM/Am7aYaOVGZL08quAkkfQx9q3udUlwTBIbd/ZE8oo 3ym9H3CCHlCIQWgbX7X3GFfj1gPFy0eELfTv/b89xeWWKZIbtE07K9to6j4tRYAko7F7 EJ8E//Wci75JgS5rsxGvTw6JgHSW4YnS15IOqoig95tOC9N4XFAV60HLt8dKTv3jLnWz hHYxnUrY032YzRLm/o70pfHIOTuk/9zh5XWn+VExNxZh6y8HePO3P/AIp+7iHb7Kl2W0 oZF35spILvAZ/VsPL9eIahTDvS4e/aeJjTMn3D25vBSO9qGiD7UIv6TTi/u87dbM5N+W vrsQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWBRvQvSJK2Kxf/B0TTxRB5T73KXFTUplQTCpFtJPV4DM0EC6pMouoW6FSxdmAnDOJwgqdX0TfDrizxHgj6j0i+PoV+Gg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ju1-20020a170903428100b001d9871e4da8si1515816plb.33.2024.02.06.03.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:52:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54802-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E8C26B239E8 for ; Tue, 6 Feb 2024 11:52:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95EDF1386C2; Tue, 6 Feb 2024 11:33:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2E69134759; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=DvTdwPh6wkEOjVT3j5LoRf7IQG1sDPZJP5NCg2prG6Q9Aybjwt2+V7aR4pFPWQirMftTTFaK33kkqiXVUFaLEvOLPrWC3AHuEwiZSdPrzz++ec1GkdQD9Btb29mHOYTHVKL+lNUTkP1U5xDqvoGaRyuYaQlX69fmLHmd/bN9J98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=QRzNsPzlJd46xARPV8LoVgr8hMSulcnSOm9LygT2RX0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=OUjuScDnonfNQvBUhWKjsf755H0P4o5VQRAoBmlfJYOsThlIwgOc53RvhKdLN5LXfrASCWgYVlWXXnp4cNafaJpPpOKvS8jkRBotji1Ln93GKZL4Rgi41xR6q9JY7aZvove39Zj/fNu+FsMS+I9609f8Foy3Jmd6oZjRAUCL8kA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BF7DC433C7; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aNp-2mUJ; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.525587454@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:13 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 15/23] tracefs: Avoid using the ei->dentry pointer unnecessarily References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150315383295399 X-GMAIL-MSGID: 1790150315383295399 From: Linus Torvalds The eventfs_find_events() code tries to walk up the tree to find the event directory that a dentry belongs to, in order to then find the eventfs inode that is associated with that event directory. However, it uses an odd combination of walking the dentry parent, looking up the eventfs inode associated with that, and then looking up the dentry from there. Repeat. But the code shouldn't have back-pointers to dentries in the first place, and it should just walk the dentry parenthood chain directly. Similarly, 'set_top_events_ownership()' looks up the dentry from the eventfs inode, but the only reason it wants a dentry is to look up the superblock in order to look up the root dentry. But it already has the real filesystem inode, which has that same superblock pointer. So just pass in the superblock pointer using the information that's already there, instead of looking up extraneous data that is irrelevant. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.638645365@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 99c001cb617df409dac275a059d6c3f187a2da7a) --- fs/tracefs/event_inode.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 824b1811e342..e9819d719d2a 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -156,33 +156,30 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, return ret; } -static void update_top_events_attr(struct eventfs_inode *ei, struct dentry *dentry) +static void update_top_events_attr(struct eventfs_inode *ei, struct super_block *sb) { - struct inode *inode; + struct inode *root; /* Only update if the "events" was on the top level */ if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL)) return; /* Get the tracefs root inode. */ - inode = d_inode(dentry->d_sb->s_root); - ei->attr.uid = inode->i_uid; - ei->attr.gid = inode->i_gid; + root = d_inode(sb->s_root); + ei->attr.uid = root->i_uid; + ei->attr.gid = root->i_gid; } static void set_top_events_ownership(struct inode *inode) { struct tracefs_inode *ti = get_tracefs(inode); struct eventfs_inode *ei = ti->private; - struct dentry *dentry; /* The top events directory doesn't get automatically updated */ if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL)) return; - dentry = ei->dentry; - - update_top_events_attr(ei, dentry); + update_top_events_attr(ei, inode->i_sb); if (!(ei->attr.mode & EVENTFS_SAVE_UID)) inode->i_uid = ei->attr.uid; @@ -235,8 +232,10 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) mutex_lock(&eventfs_mutex); do { - /* The parent always has an ei, except for events itself */ - ei = dentry->d_parent->d_fsdata; + // The parent is stable because we do not do renames + dentry = dentry->d_parent; + // ... and directories always have d_fsdata + ei = dentry->d_fsdata; /* * If the ei is being freed, the ownership of the children @@ -246,12 +245,11 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) ei = NULL; break; } - - dentry = ei->dentry; + // Walk upwards until you find the events inode } while (!ei->is_events); mutex_unlock(&eventfs_mutex); - update_top_events_attr(ei, dentry); + update_top_events_attr(ei, dentry->d_sb); return ei; } From patchwork Tue Feb 6 11:32:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197352 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482936dyb; Tue, 6 Feb 2024 03:54:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IEK9vfH88yyALKqh2NiJHey1HQq4bXENrWP8wxxvDuUT4tuQBE++BtwKGtkhxRZUH2yNYkC X-Received: by 2002:a17:906:6806:b0:a36:7969:c49d with SMTP id k6-20020a170906680600b00a367969c49dmr1747365ejr.26.1707220467388; Tue, 06 Feb 2024 03:54:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220467; cv=pass; d=google.com; s=arc-20160816; b=Bm0VLypmnc6yDLqIi2yoW5BLr3/YeNroTstBUz02slwkoMbIQydkMw7TgtQMOSpT6e bh2iIHlYcgSwrKJpaKmzuchL1McBH0vKnEjiSRcBaCQT4ogIFfZBx8s5QI+yznLZx9Wv iqgFqtMTsTIeLxxFeIAj7P+1Pb+d0Tias/3aCjkN6opROOuHz9auxGPpGVT6PVeyONL7 vln0lP5W+ZbAreTE1V/oe0tr2scKAtQWLLb4gGpvImzSflsGHKG2xTISMQ/8DOY2IvhO 0Mf0e8BGQKD09sfMl3vKyyjh/au0i6YPFf79M5kyESrxPCR770koRSfh3MkP785GrHsj YP3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=es8S7dWQFCSWQLlQNN2IENIto37jTQmmdW50NhmxiZA=; fh=XW5K9eq3lqmDJ9jQ/nUV9rXzB8EpVUDW0QnIZvWZi3s=; b=y288TbRbn383HC/Vx8SYtLwjaTbqNPhNLPmYRkd2FO063LACFw2ShAT+ez3YA3UyhJ uXFudpdYBuEABlz+6tDk37u71bBzw243jU3fvO7knXiL4J5KfqZwO7ikrhvI0LlA9bit yz1tgPnPjDAu2kJ05GksjGCUZl9R6x3Fl/XFlcC71V/fkUiXVz00zFzR4iNqB7DxML9H AP2PvOCoHy9qiMkcDzYBeUR3aijWS9sA+mW2k14E6e2qW+wb4bzGv85Nr3eFoCSQ7Tcr ImcffVRKhbR1bkgHlTqp9TQYrh5YHqny6MBpURQQ/waUZkYDg0DPKHE/Gx4s3r59a2TH UZXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54803-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54803-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVDHGkJpLGu97RZnIXrn4G4AlyUj6Qbpqgl1nvLgc8xSwznTU3/NXQy9Kj2ZOfwh7oVzDq04eki4dB7iBVOnOWSAqGC7w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gs20-20020a170906f19400b00a37e659a352si1044251ejb.325.2024.02.06.03.54.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:54:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54803-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54803-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54803-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2CABD1F22494 for ; Tue, 6 Feb 2024 11:54:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BEEF513A87B; Tue, 6 Feb 2024 11:33:40 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6FA8134CC0; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=AcZhZyZs1AKSkWHCeQScE3Iijc8IR5/wTqch0RRvGjNjrlgD/3JChMZO4WUPnMxmW7oaJJLx2RXKEpM+W+8N7C7W8zlSrMi0u713rEsg3YUh3X1dkmOuSXszMnjkxOWVxiot9THWpf8/d6JvuoIjdi1PrmkdgztfPGbr7nvZUlI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=4fdTsrKq+QjZ1Zi87qAZNdd04dmBOM86q8a7ygS5m18=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=SXcFLkVtfV6NA4ZhdTAPEKYurCyKlHSz4z2dPNY9S8GqkhdFD1Z7Duy3qKmHrW+gWfcKufpLZPRMTj46MrBePEX1l1nMjawX6lNJ2FLtojCqx7GZDD1m/GjwyJrIP6uH5YasMnqmSCk8wO1U8H+O66G6CXjOKJ2P/eqileIMIBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70BEAC43390; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aOK-3T18; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.685349714@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:14 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Al Viro , Christian Brauner , Ajay Kaher Subject: [v6.7][PATCH v2 16/23] tracefs: dentry lookup crapectomy References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150408995225155 X-GMAIL-MSGID: 1790150408995225155 From: Linus Torvalds The dentry lookup for eventfs files was very broken, and had lots of signs of the old situation where the filesystem names were all created statically in the dentry tree, rather than being looked up dynamically based on the eventfs data structures. You could see it in the naming - how it claimed to "create" dentries rather than just look up the dentries that were given it. You could see it in various nonsensical and very incorrect operations, like using "simple_lookup()" on the dentries that were passed in, which only results in those dentries becoming negative dentries. Which meant that any other lookup would possibly return ENOENT if it saw that negative dentry before the data was then later filled in. You could see it in the immense amount of nonsensical code that didn't actually just do lookups. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131233227.73db55e1@gandalf.local.home Cc: stable@vger.kernel.org Cc: Al Viro Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Greg Kroah-Hartman Cc: Ajay Kaher Cc: Mark Rutland Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 49304c2b93e4f7468b51ef717cbe637981397115) --- fs/tracefs/event_inode.c | 275 +++++++-------------------------------- fs/tracefs/inode.c | 69 ---------- fs/tracefs/internal.h | 3 - 3 files changed, 50 insertions(+), 297 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index e9819d719d2a..04c2ab90f93e 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -230,7 +230,6 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) { struct eventfs_inode *ei; - mutex_lock(&eventfs_mutex); do { // The parent is stable because we do not do renames dentry = dentry->d_parent; @@ -247,7 +246,6 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) } // Walk upwards until you find the events inode } while (!ei->is_events); - mutex_unlock(&eventfs_mutex); update_top_events_attr(ei, dentry->d_sb); @@ -280,11 +278,10 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, } /** - * create_file - create a file in the tracefs filesystem - * @name: the name of the file to create. + * lookup_file - look up a file in the tracefs filesystem + * @dentry: the dentry to look up * @mode: the permission that the file should have. * @attr: saved attributes changed by user - * @parent: parent dentry for this file. * @data: something that the caller will want to get to later on. * @fop: struct file_operations that should be used for this file. * @@ -292,13 +289,13 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, * directory. The inode.i_private pointer will point to @data in the open() * call. */ -static struct dentry *create_file(const char *name, umode_t mode, +static struct dentry *lookup_file(struct dentry *dentry, + umode_t mode, struct eventfs_attr *attr, - struct dentry *parent, void *data, + void *data, const struct file_operations *fop) { struct tracefs_inode *ti; - struct dentry *dentry; struct inode *inode; if (!(mode & S_IFMT)) @@ -307,15 +304,9 @@ static struct dentry *create_file(const char *name, umode_t mode, if (WARN_ON_ONCE(!S_ISREG(mode))) return NULL; - WARN_ON_ONCE(!parent); - dentry = eventfs_start_creating(name, parent); - - if (IS_ERR(dentry)) - return dentry; - inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) - return eventfs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); /* If the user updated the directory's attributes, use them */ update_inode_attr(dentry, inode, attr, mode); @@ -329,32 +320,29 @@ static struct dentry *create_file(const char *name, umode_t mode, ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; - d_instantiate(dentry, inode); + + d_add(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); - return eventfs_end_creating(dentry); + return dentry; }; /** - * create_dir - create a dir in the tracefs filesystem + * lookup_dir_entry - look up a dir in the tracefs filesystem + * @dentry: the directory to look up * @ei: the eventfs_inode that represents the directory to create - * @parent: parent dentry for this file. * - * This function will create a dentry for a directory represented by + * This function will look up a dentry for a directory represented by * a eventfs_inode. */ -static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent) +static struct dentry *lookup_dir_entry(struct dentry *dentry, + struct eventfs_inode *pei, struct eventfs_inode *ei) { struct tracefs_inode *ti; - struct dentry *dentry; struct inode *inode; - dentry = eventfs_start_creating(ei->name, parent); - if (IS_ERR(dentry)) - return dentry; - inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) - return eventfs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); /* If the user updated the directory's attributes, use them */ update_inode_attr(dentry, inode, &ei->attr, @@ -371,11 +359,14 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent /* Only directories have ti->private set to an ei, not files */ ti->private = ei; + dentry->d_fsdata = ei; + ei->dentry = dentry; // Remove me! + inc_nlink(inode); - d_instantiate(dentry, inode); + d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); - return eventfs_end_creating(dentry); + return dentry; } static void free_ei(struct eventfs_inode *ei) @@ -425,7 +416,7 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) } /** - * create_file_dentry - create a dentry for a file of an eventfs_inode + * lookup_file_dentry - create a dentry for a file of an eventfs_inode * @ei: the eventfs_inode that the file will be created under * @idx: the index into the d_children[] of the @ei * @parent: The parent dentry of the created file. @@ -438,157 +429,21 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) * address located at @e_dentry. */ static struct dentry * -create_file_dentry(struct eventfs_inode *ei, int idx, - struct dentry *parent, const char *name, umode_t mode, void *data, +lookup_file_dentry(struct dentry *dentry, + struct eventfs_inode *ei, int idx, + umode_t mode, void *data, const struct file_operations *fops) { struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; - struct dentry *dentry; - - WARN_ON_ONCE(!inode_is_locked(parent->d_inode)); - mutex_lock(&eventfs_mutex); - if (ei->is_freed) { - mutex_unlock(&eventfs_mutex); - return NULL; - } - /* If the e_dentry already has a dentry, use it */ - if (*e_dentry) { - dget(*e_dentry); - mutex_unlock(&eventfs_mutex); - return *e_dentry; - } - - /* ei->entry_attrs are protected by SRCU */ if (ei->entry_attrs) attr = &ei->entry_attrs[idx]; - mutex_unlock(&eventfs_mutex); - - dentry = create_file(name, mode, attr, parent, data, fops); + dentry->d_fsdata = ei; // NOTE: ei of _parent_ + lookup_file(dentry, mode, attr, data, fops); - mutex_lock(&eventfs_mutex); - - if (IS_ERR_OR_NULL(dentry)) { - /* - * When the mutex was released, something else could have - * created the dentry for this e_dentry. In which case - * use that one. - * - * If ei->is_freed is set, the e_dentry is currently on its - * way to being freed, don't return it. If e_dentry is NULL - * it means it was already freed. - */ - if (ei->is_freed) { - dentry = NULL; - } else { - dentry = *e_dentry; - dget(dentry); - } - mutex_unlock(&eventfs_mutex); - return dentry; - } - - if (!*e_dentry && !ei->is_freed) { - *e_dentry = dentry; - dentry->d_fsdata = ei; - } else { - /* - * Should never happen unless we get here due to being freed. - * Otherwise it means two dentries exist with the same name. - */ - WARN_ON_ONCE(!ei->is_freed); - dentry = NULL; - } - mutex_unlock(&eventfs_mutex); - - return dentry; -} - -/** - * eventfs_post_create_dir - post create dir routine - * @ei: eventfs_inode of recently created dir - * - * Map the meta-data of files within an eventfs dir to their parent dentry - */ -static void eventfs_post_create_dir(struct eventfs_inode *ei) -{ - struct eventfs_inode *ei_child; - - lockdep_assert_held(&eventfs_mutex); - - /* srcu lock already held */ - /* fill parent-child relation */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { - ei_child->d_parent = ei->dentry; - } -} - -/** - * create_dir_dentry - Create a directory dentry for the eventfs_inode - * @pei: The eventfs_inode parent of ei. - * @ei: The eventfs_inode to create the directory for - * @parent: The dentry of the parent of this directory - * - * This creates and attaches a directory dentry to the eventfs_inode @ei. - */ -static struct dentry * -create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, - struct dentry *parent) -{ - struct dentry *dentry = NULL; - - WARN_ON_ONCE(!inode_is_locked(parent->d_inode)); - - mutex_lock(&eventfs_mutex); - if (pei->is_freed || ei->is_freed) { - mutex_unlock(&eventfs_mutex); - return NULL; - } - if (ei->dentry) { - /* If the eventfs_inode already has a dentry, use it */ - dentry = ei->dentry; - dget(dentry); - mutex_unlock(&eventfs_mutex); - return dentry; - } - mutex_unlock(&eventfs_mutex); - - dentry = create_dir(ei, parent); - - mutex_lock(&eventfs_mutex); - - if (IS_ERR_OR_NULL(dentry) && !ei->is_freed) { - /* - * When the mutex was released, something else could have - * created the dentry for this e_dentry. In which case - * use that one. - * - * If ei->is_freed is set, the e_dentry is currently on its - * way to being freed. - */ - dentry = ei->dentry; - if (dentry) - dget(dentry); - mutex_unlock(&eventfs_mutex); - return dentry; - } - - if (!ei->dentry && !ei->is_freed) { - ei->dentry = dentry; - eventfs_post_create_dir(ei); - dentry->d_fsdata = ei; - } else { - /* - * Should never happen unless we get here due to being freed. - * Otherwise it means two dentries exist with the same name. - */ - WARN_ON_ONCE(!ei->is_freed); - dentry = NULL; - } - mutex_unlock(&eventfs_mutex); + *e_dentry = dentry; // Remove me return dentry; } @@ -607,79 +462,49 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) { - const struct file_operations *fops; - const struct eventfs_entry *entry; struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct dentry *ei_dentry = NULL; - struct dentry *ret = NULL; - struct dentry *d; const char *name = dentry->d_name.name; - umode_t mode; - void *data; - int idx; - int i; - int r; ti = get_tracefs(dir); if (!(ti->flags & TRACEFS_EVENT_INODE)) - return NULL; - - /* Grab srcu to prevent the ei from going away */ - idx = srcu_read_lock(&eventfs_srcu); + return ERR_PTR(-EIO); - /* - * Grab the eventfs_mutex to consistent value from ti->private. - * This s - */ mutex_lock(&eventfs_mutex); - ei = READ_ONCE(ti->private); - if (ei && !ei->is_freed) - ei_dentry = READ_ONCE(ei->dentry); - mutex_unlock(&eventfs_mutex); - if (!ei || !ei_dentry) + ei = ti->private; + if (!ei || ei->is_freed) goto out; - data = ei->data; - - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { + list_for_each_entry(ei_child, &ei->children, list) { if (strcmp(ei_child->name, name) != 0) continue; - ret = simple_lookup(dir, dentry, flags); - if (IS_ERR(ret)) + if (ei_child->is_freed) goto out; - d = create_dir_dentry(ei, ei_child, ei_dentry); - dput(d); + lookup_dir_entry(dentry, ei, ei_child); goto out; } - for (i = 0; i < ei->nr_entries; i++) { - entry = &ei->entries[i]; - if (strcmp(name, entry->name) == 0) { - void *cdata = data; - mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r = entry->callback(name, &mode, &cdata, &fops); - else - r = -1; - mutex_unlock(&eventfs_mutex); - if (r <= 0) - continue; - ret = simple_lookup(dir, dentry, flags); - if (IS_ERR(ret)) - goto out; - d = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); - dput(d); - break; - } + for (int i = 0; i < ei->nr_entries; i++) { + void *data; + umode_t mode; + const struct file_operations *fops; + const struct eventfs_entry *entry = &ei->entries[i]; + + if (strcmp(name, entry->name) != 0) + continue; + + data = ei->data; + if (entry->callback(name, &mode, &data, &fops) <= 0) + goto out; + + lookup_file_dentry(dentry, ei, i, mode, data, fops); + goto out; } out: - srcu_read_unlock(&eventfs_srcu, idx); - return ret; + mutex_unlock(&eventfs_mutex); + return NULL; } /* diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 888e42087847..5c84460feeeb 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -495,75 +495,6 @@ struct dentry *tracefs_end_creating(struct dentry *dentry) return dentry; } -/** - * eventfs_start_creating - start the process of creating a dentry - * @name: Name of the file created for the dentry - * @parent: The parent dentry where this dentry will be created - * - * This is a simple helper function for the dynamically created eventfs - * files. When the directory of the eventfs files are accessed, their - * dentries are created on the fly. This function is used to start that - * process. - */ -struct dentry *eventfs_start_creating(const char *name, struct dentry *parent) -{ - struct dentry *dentry; - int error; - - /* Must always have a parent. */ - if (WARN_ON_ONCE(!parent)) - return ERR_PTR(-EINVAL); - - error = simple_pin_fs(&trace_fs_type, &tracefs_mount, - &tracefs_mount_count); - if (error) - return ERR_PTR(error); - - if (unlikely(IS_DEADDIR(parent->d_inode))) - dentry = ERR_PTR(-ENOENT); - else - dentry = lookup_one_len(name, parent, strlen(name)); - - if (!IS_ERR(dentry) && dentry->d_inode) { - dput(dentry); - dentry = ERR_PTR(-EEXIST); - } - - if (IS_ERR(dentry)) - simple_release_fs(&tracefs_mount, &tracefs_mount_count); - - return dentry; -} - -/** - * eventfs_failed_creating - clean up a failed eventfs dentry creation - * @dentry: The dentry to clean up - * - * If after calling eventfs_start_creating(), a failure is detected, the - * resources created by eventfs_start_creating() needs to be cleaned up. In - * that case, this function should be called to perform that clean up. - */ -struct dentry *eventfs_failed_creating(struct dentry *dentry) -{ - dput(dentry); - simple_release_fs(&tracefs_mount, &tracefs_mount_count); - return NULL; -} - -/** - * eventfs_end_creating - Finish the process of creating a eventfs dentry - * @dentry: The dentry that has successfully been created. - * - * This function is currently just a place holder to match - * eventfs_start_creating(). In case any synchronization needs to be added, - * this function will be used to implement that without having to modify - * the callers of eventfs_start_creating(). - */ -struct dentry *eventfs_end_creating(struct dentry *dentry) -{ - return dentry; -} - /* Find the inode that this will use for default */ static struct inode *instance_inode(struct dentry *parent, struct inode *inode) { diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 7d84349ade87..09037e2c173d 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -80,9 +80,6 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); struct dentry *tracefs_end_creating(struct dentry *dentry); struct dentry *tracefs_failed_creating(struct dentry *dentry); struct inode *tracefs_get_inode(struct super_block *sb); -struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); -struct dentry *eventfs_failed_creating(struct dentry *dentry); -struct dentry *eventfs_end_creating(struct dentry *dentry); void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 11:32:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197346 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482447dyb; Tue, 6 Feb 2024 03:53:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGp/HA89FE5VbFcP41lUSMGmU6QeeVdjqDRM19G6getRAmkplzmxUwxD5xavhu+KISaaI1o X-Received: by 2002:a17:906:646:b0:a35:e7a1:66ec with SMTP id t6-20020a170906064600b00a35e7a166ecmr1659780ejb.44.1707220390576; Tue, 06 Feb 2024 03:53:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220390; cv=pass; d=google.com; s=arc-20160816; b=GZGfxIkeFCV/tKDudoOxesnaZv5nTPoXBOHzghwK4e5V5bD/sv87metdeKjh0sbCtl OnSA9zkwPOrF+VJuMzCm5lQUAAxrmaPwm2K8cu07v4tlXwOAmqb1qYHM3yH3xsZHhbyv /8dOcQkKJ1rVG+W+h6MAfu/jL7ItTSXwobSLAhrpW3/A+LPhkj+dZu6vFN74vwxJz8F5 4ehzpfbUpa9PBf+FzpWi+cDETuHUnl+Kf1eXl0rPXaSIb3am8Q8S/HjDdGK/MB+eunzX jfKd1ZpVlAwEOApimayI6cDooX3j//KeDzcm9FCOUo9crwataJ2wF3of/8Ay/b5gmOfd a1Mw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=5P4MAWSKMmD3/d6RtYJCLwc+pyfvZUI8lTsxddGrfqo=; fh=aQIx6UaqQxtN6Say8Loh6h9yebHf9foO8TQH+O37ceU=; b=M7TlSgWiqsuukIerMvtMPIDmH3T8+9cPZxUN54nf5ZMmFzDHM9xf43K92TNLUTXMf0 3sD7hBu9vxAb7caHyiiX+yv5hfqI5Cum22i2L9Yot+JsKAvHsKAXqrmI8IUtT17rD8/k WseWz+V9/PK0iwN1f/hqDYfqD+gKJXp5bcvk2V2BXQeJ5Q5y20WGXqWNEkfN951eZQA2 iL1G9JfmHZnVz5xOcUTFlvbJG2+IgmM29vxu5oU2BAqQR0gcjjIRx1ZITBTT5lNSpaK8 lSC8F7afb+hZqED65j8UtCNpYODCsR55Mnh2ovncxqID7/hudyafVwy0Nel92KTXNVfG Wihw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54804-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54804-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWCAKjZRTWcZACw13zraJFiFbBVH8rtO3kE1WWvz/RT8fY5COxQPehE5B+imTeeudIvj9geGr7fodyhYsrDHc3XgYo0iA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d8-20020a17090648c800b00a36715df0f8si1035313ejt.112.2024.02.06.03.53.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54804-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54804-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54804-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2D1991F21BB8 for ; Tue, 6 Feb 2024 11:53:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39141134759; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6FDF134CC2; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=nStlZScr91mcHlkzgQi24CbkI+vBugWEShqiRzZGGBd2wcX8g3eazMiOgR1jmHnhJtQvTbbSEF5A7NRbiTesMhoObKz+gqafVBon2hX71aViOsGn7dNE1e+6cDkQmy02xbh9x7vvR7Ko0ZeSkwssrzVsxKQZ8QO/K3m59FtvXsA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=WyXLYu467PqbTFP05lGa1iuD6tL0QtugqCd95Pr2/KA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=bPXjXaNc+71j/HipkXw+UurMookgUP+MbgkMbHGZul3ZrTZn06ziITqIicpqgLrmF8LKuV8fgN9HmMz9H45r1Sv8JpbKSY1OJz1HkxniPr4GgPF5jVTtoNiLTOd7e4YghXNa3i+3JgdDXSzfAzj0tzRO86XQVFciC42EpKjdNvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96F8BC433A6; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiC-00000006aOq-49aQ; Tue, 06 Feb 2024 06:34:00 -0500 Message-ID: <20240206113400.846719926@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:15 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 17/23] eventfs: Remove unused d_parent pointer field References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150328368131294 X-GMAIL-MSGID: 1790150328368131294 From: Linus Torvalds It's never used Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.961772428@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 408600be78cdb8c650a97ecc7ff411cb216811b5) --- fs/tracefs/event_inode.c | 4 +--- fs/tracefs/internal.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 04c2ab90f93e..16ca8d9759b1 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -680,10 +680,8 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode INIT_LIST_HEAD(&ei->list); mutex_lock(&eventfs_mutex); - if (!parent->is_freed) { + if (!parent->is_freed) list_add_tail(&ei->list, &parent->children); - ei->d_parent = parent->dentry; - } mutex_unlock(&eventfs_mutex); /* Was the parent freed? */ diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 09037e2c173d..932733a2696a 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -36,7 +36,6 @@ struct eventfs_attr { * @name: the name of the directory to create * @children: link list into the child eventfs_inode * @dentry: the dentry of the directory - * @d_parent: pointer to the parent's dentry * @d_children: The array of dentries to represent the files when created * @entry_attrs: Saved mode and ownership of the @d_children * @attr: Saved mode and ownership of eventfs_inode itself @@ -51,7 +50,6 @@ struct eventfs_inode { const char *name; struct list_head children; struct dentry *dentry; /* Check is_freed to access */ - struct dentry *d_parent; struct dentry **d_children; struct eventfs_attr *entry_attrs; struct eventfs_attr attr; From patchwork Tue Feb 6 11:32:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197349 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482614dyb; Tue, 6 Feb 2024 03:53:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IH5PjcgcuVr0VQWu0lyK3CncLSJcX3VTHFz2LLfJaXy3ltI7FsEylfl8JBtNmL+tcbx6keZ X-Received: by 2002:a05:620a:110b:b0:783:d369:6e5a with SMTP id o11-20020a05620a110b00b00783d3696e5amr2115831qkk.76.1707220418117; Tue, 06 Feb 2024 03:53:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220418; cv=pass; d=google.com; s=arc-20160816; b=hF6X0qMYw6YVxcoqY/lmUMdleC9sc7ZwRKAvG/t8dqvKY1sHFxQXtkjCiAXluyGxHw mhVFvVOlrOTgCFtkMz1+ClS34ork+qlyGGbd2LIW/HaUzQSCCEXtga9zutM/GWliMTTk 7vU+ocgO5yTKqnJ1+LQk2xlxJd/OQT10uBui30XaZtI7KwPMfnuecY+EK4aVUeQgoKa1 TNpVLcASWCJRXjX1IQTPG9CVwDjNlKsDplnE57LtHRzorGOdwvMztvSfyicc7MEW5IuE +L9jrobGxNUC3aiZv0oITaJVcltmGXgR6lXeKtzI13Qy+CU/X6BfS5jP2veNFd9CRync u3lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=ATYjBrgrQgHux704Rexi0i1KZf3q/HOV5z1Ibp2pi6Y=; fh=GrnETzDgXL+QIWrSyG2PtEzPcrjYYdKBv9r7ah9uAig=; b=zqhhJWfhl1Q/XjNrcQ9yda3ZSqACSTtOYgpS7Guu8a/m5d+xj0hs/jXBfT16EvRhfV TVA6BxUKdDO5hN/88EQm3oBMyE8sJUEEB+GryoRAdR/XmgpEI2QZESV8Jrm+7rSFQXit Vd0e/4eCVDSYvUorWBVGp9RoUkrj57RlJfE81vUzxQ0Dg3mzwiKdhPk5Ja3286QSSE/n Iu24JpVP3MP68z8h9UX/X22UcrfQqZ3cuVjnKnMZIYDqfiBFSvMCDsa18jIqsWeZV8y+ JYdb1g51vwV+ThMom6LvaXgN3gINfW/u/hrAYEpKSEL8wOR1MwUFz1ARCT8mmeQJJPPm sovw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVT4SDWyrk9OBttsTKos2n+eXVLxhQ7p34rA/Jr5EXsfSOkaMUUytfzSjr0OafpKVPAI/mX5XLBIkXFYUMJkr4hZEp7VQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c4-20020a05620a164400b0078532a9689dsi2055060qko.623.2024.02.06.03.53.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54805-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E485A1C226B2 for ; Tue, 6 Feb 2024 11:53:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8284B13A267; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4ED9134CD1; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; cv=none; b=m7Oddcg0ezdJG+SEHewvOHMGPBNjP0NSfRbLp7xM/t+P+MQgiU1CvwNlmHvUPUWVKsmI2d8Gef++rYbNzx8sd+PRRvFvvlSNHlZ+ZSnCPaK0aVspghUw+eCM4Bh0L1mHusrIt8JMVtpd+j6qwJjrctcJc7H4kNPIC3WoE5ArTOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219212; c=relaxed/simple; bh=d4lAO/Lp5Wz8u/KkIxfXJiOAORWOFSfTFPDiSHjfGI4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RxfiupDuDgqM8LN5NQjKrGapYUbec+kO8Qsgs/2QrqIaE0rzhs9ExNY+QCRTr+8W6wvOgFfg9SoqsyIClmOQXoQ7eszXPxs3fuK3EMM/ZOKeNNk+zYQiaaz7fFRJA2KOh9V1rkde4kxTzoqo7rUnULoY9tTov9biz+CyPLCHeu4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B58A3C43399; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aPK-0cXc; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.010494265@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:16 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 18/23] eventfs: Clean up dentry ops and add revalidate function References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150357534781604 X-GMAIL-MSGID: 1790150357534781604 From: Linus Torvalds In order for the dentries to stay up-to-date with the eventfs changes, just add a 'd_revalidate' function that checks the 'is_freed' bit. Also, clean up the dentry release to actually use d_release() rather than the slightly odd d_iput() function. We don't care about the inode, all we want to do is to get rid of the refcount to the eventfs data added by dentry->d_fsdata. It would probably be cleaner to make eventfs its own filesystem, or at least set its own dentry ops when looking up eventfs files. But as it is, only eventfs dentries use d_fsdata, so we don't really need to split these things up by use. Another thing that might be worth doing is to make all eventfs lookups mark their dentries as not worth caching. We could do that with d_delete(), but the DCACHE_DONTCACHE flag would likely be even better. As it is, the dentries are all freeable, but they only tend to get freed at memory pressure rather than more proactively. But that's a separate issue. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.124644253@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 8dce06e98c70a7fcbb4bca7d90faf40522e65c58) --- fs/tracefs/event_inode.c | 5 ++--- fs/tracefs/inode.c | 27 ++++++++++++++++++--------- fs/tracefs/internal.h | 3 ++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 16ca8d9759b1..b2285d5f3fed 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -378,13 +378,12 @@ static void free_ei(struct eventfs_inode *ei) } /** - * eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode - * @ti: the tracefs_inode of the dentry + * eventfs_d_release - dentry is going away * @dentry: dentry which has the reference to remove. * * Remove the association between a dentry from an eventfs_inode. */ -void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) +void eventfs_d_release(struct dentry *dentry) { struct eventfs_inode *ei; int i; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 5c84460feeeb..d65ffad4c327 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -377,21 +377,30 @@ static const struct super_operations tracefs_super_operations = { .show_options = tracefs_show_options, }; -static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode) +/* + * It would be cleaner if eventfs had its own dentry ops. + * + * Note that d_revalidate is called potentially under RCU, + * so it can't take the eventfs mutex etc. It's fine - if + * we open a file just as it's marked dead, things will + * still work just fine, and just see the old stale case. + */ +static void tracefs_d_release(struct dentry *dentry) { - struct tracefs_inode *ti; + if (dentry->d_fsdata) + eventfs_d_release(dentry); +} - if (!dentry || !inode) - return; +static int tracefs_d_revalidate(struct dentry *dentry, unsigned int flags) +{ + struct eventfs_inode *ei = dentry->d_fsdata; - ti = get_tracefs(inode); - if (ti && ti->flags & TRACEFS_EVENT_INODE) - eventfs_set_ei_status_free(ti, dentry); - iput(inode); + return !(ei && ei->is_freed); } static const struct dentry_operations tracefs_dentry_operations = { - .d_iput = tracefs_dentry_iput, + .d_revalidate = tracefs_d_revalidate, + .d_release = tracefs_d_release, }; static int trace_fill_super(struct super_block *sb, void *data, int silent) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 932733a2696a..4b50a0668055 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -78,6 +78,7 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); struct dentry *tracefs_end_creating(struct dentry *dentry); struct dentry *tracefs_failed_creating(struct dentry *dentry); struct inode *tracefs_get_inode(struct super_block *sb); -void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); + +void eventfs_d_release(struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 11:32:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197353 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482983dyb; Tue, 6 Feb 2024 03:54:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLqS89hqpHeiYs/kjV+8CTbaQcAnCNeKqI2+Ri0p+oEnhs8uRKqhlkAYGgvoVo5f6MqrNS X-Received: by 2002:a17:906:1451:b0:a38:4aa:f61b with SMTP id q17-20020a170906145100b00a3804aaf61bmr1591215ejc.36.1707220475974; Tue, 06 Feb 2024 03:54:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220475; cv=pass; d=google.com; s=arc-20160816; b=qCSJMlphcVtFraZICX5moHUAvDwUnQgUZgpw5XyhQoZcnIvpZwQTgIDPBG+UhMu/r2 cfo8XbJmPq+7bgviifcMY1+FnIuU3vbe1wnrJJ2Tyxm4glbHDn6l80aSFBSMIHBy3nxy jKgoU7McaGwiMmNXEnjm0OiH1XsUXMwlKsAClC+vxYXy6UJcqhkWQ/fbzNZmy1/ql2nj 1bSO6ofCmYSJ32Z0p1eizIXGCNR3Wwixe9bAUzcSnqeJOkTirewIHjSszck4gdXqaf62 xMA2qiDbAnaQCug/Ua31/jwtF4vpl6pgprQQHKoda+yJSVdnUYz66nmEvHDen6yvQqTU omEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=ibplbWfYp5SZrjt6tuasl1pCx5FeUok3G24cS59kGbw=; fh=DnHwoLlMto1YOBbTGVjUOgM21ck4lor0Pgycq+rO6eI=; b=o9NgKUCkSR9kb6ooZLL6/dSqzJ4OLXJEkOfgQ8G/AhrBrdNV8bEAiJCQoE3JgCCOXN qNiWE+lM7lO4CqucDJHRpDXMXpQXy4URfG6Sc5wNTEiwSGrxxzyUWfaqP7J9o8llTX3X JtJ4SiWBL0B8VBeP4ZcHRcVnkkTf9Jid433xZ04ptz+JzJT8q1YdzMEwtY/oRTNeMECl iYQeHYxLTtyY1X1pLTSEYsln1MEJjKXMl2vD0bqvU2ONDyipi7bHIebnrAxqWwuDQvgE GAtCFASJZ8da5KY99+XUjDH4Da+mG1Zs2+DJGAoFEctELHO0K6fkHCKkavPaU4BmZJPJ SBhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54807-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54807-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXUzN11hrGWOxwTPGBCRgR6RLXIsj9sCTMES3ry7PKAEgNoGt/dmRNUX3p1HxPjz5HwMPBTiQ6M8Fa3qxGX8uYvLkrzzA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d8-20020a17090648c800b00a36715df0f8si1035313ejt.112.2024.02.06.03.54.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:54:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54807-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54807-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54807-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 500311F21A59 for ; Tue, 6 Feb 2024 11:54:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FF6213A887; Tue, 6 Feb 2024 11:33:41 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 768F51350C1; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; cv=none; b=DCqnNb/M2yHcmEmuCg454DXBBJyGQB7g4lpm6hRvWaWcn5LOyS9OcyIVbsmvtqEodhJtm+G7i59SS72oKCIxHyXVl5/xIKTtrXLZ2kB+C4QIWW9w8bVGXEskqrZFq3gg/Ez89TKs/dgAAAZc1xtl6CwDKVnCvOkh639De+mq0D8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=YPpxQFfVye3420wXVrWufA0oagWv//U74Rk3/6Lvtfw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=X5grTO6muJsiRZIBXP5KZh20RP+fegnJSoGOK0TU6uzieqteIiPJp1oR5KSzDCgC20A7moozxZ9K49c4e3khmvrVEfwjEJeWkkCMn+0wFggAiSQoBi2RRcC8xiOUoAM38fgkuJmCGr+hf9UQnxdOvPc0dJOkxi2mLNI4cjaX3Ac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1FF8C433A6; Tue, 6 Feb 2024 11:33:32 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aPq-1Gr6; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.170105803@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:17 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 19/23] eventfs: Get rid of dentry pointers without refcounts References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150417861590947 X-GMAIL-MSGID: 1790150417861590947 From: Linus Torvalds The eventfs inode had pointers to dentries (and child dentries) without actually holding a refcount on said pointer. That is fundamentally broken, and while eventfs tried to then maintain coherence with dentries going away by hooking into the '.d_iput' callback, that doesn't actually work since it's not ordered wrt lookups. There were two reasonms why eventfs tried to keep a pointer to a dentry: - the creation of a 'events' directory would actually have a stable dentry pointer that it created with tracefs_start_creating(). And it needed that dentry when tearing it all down again in eventfs_remove_events_dir(). This use is actually ok, because the special top-level events directory dentries are actually stable, not just a temporary cache of the eventfs data structures. - the 'eventfs_inode' (aka ei) needs to stay around as long as there are dentries that refer to it. It then used these dentry pointers as a replacement for doing reference counting: it would try to make sure that there was only ever one dentry associated with an event_inode, and keep a child dentry array around to see which dentries might still refer to the parent ei. This gets rid of the invalid dentry pointer use, and renames the one valid case to a different name to make it clear that it's not just any random dentry. The magic child dentry array that is kind of a "reverse reference list" is simply replaced by having child dentries take a ref to the ei. As does the directory dentries. That makes the broken use case go away. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.280463000@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 43aa6f97c2d03a52c1ddb86768575fc84344bdbb) --- fs/tracefs/event_inode.c | 248 ++++++++++++--------------------------- fs/tracefs/internal.h | 7 +- 2 files changed, 78 insertions(+), 177 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index b2285d5f3fed..515fdace1eea 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -62,6 +62,35 @@ enum { #define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1) +/* + * eventfs_inode reference count management. + * + * NOTE! We count only references from dentries, in the + * form 'dentry->d_fsdata'. There are also references from + * directory inodes ('ti->private'), but the dentry reference + * count is always a superset of the inode reference count. + */ +static void release_ei(struct kref *ref) +{ + struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + kfree(ei->entry_attrs); + kfree_const(ei->name); + kfree_rcu(ei, rcu); +} + +static inline void put_ei(struct eventfs_inode *ei) +{ + if (ei) + kref_put(&ei->kref, release_ei); +} + +static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei) +{ + if (ei) + kref_get(&ei->kref); + return ei; +} + static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); @@ -289,7 +318,8 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, * directory. The inode.i_private pointer will point to @data in the open() * call. */ -static struct dentry *lookup_file(struct dentry *dentry, +static struct dentry *lookup_file(struct eventfs_inode *parent_ei, + struct dentry *dentry, umode_t mode, struct eventfs_attr *attr, void *data, @@ -302,7 +332,7 @@ static struct dentry *lookup_file(struct dentry *dentry, mode |= S_IFREG; if (WARN_ON_ONCE(!S_ISREG(mode))) - return NULL; + return ERR_PTR(-EIO); inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) @@ -321,9 +351,12 @@ static struct dentry *lookup_file(struct dentry *dentry, ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; + // Files have their parent's ei as their fsdata + dentry->d_fsdata = get_ei(parent_ei); + d_add(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); - return dentry; + return NULL; }; /** @@ -359,22 +392,29 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, /* Only directories have ti->private set to an ei, not files */ ti->private = ei; - dentry->d_fsdata = ei; - ei->dentry = dentry; // Remove me! + dentry->d_fsdata = get_ei(ei); inc_nlink(inode); d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); - return dentry; + return NULL; } -static void free_ei(struct eventfs_inode *ei) +static inline struct eventfs_inode *alloc_ei(const char *name) { - kfree_const(ei->name); - kfree(ei->d_children); - kfree(ei->entry_attrs); - kfree(ei); + struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL); + + if (!ei) + return NULL; + + ei->name = kstrdup_const(name, GFP_KERNEL); + if (!ei->name) { + kfree(ei); + return NULL; + } + kref_init(&ei->kref); + return ei; } /** @@ -385,39 +425,13 @@ static void free_ei(struct eventfs_inode *ei) */ void eventfs_d_release(struct dentry *dentry) { - struct eventfs_inode *ei; - int i; - - mutex_lock(&eventfs_mutex); - - ei = dentry->d_fsdata; - if (!ei) - goto out; - - /* This could belong to one of the files of the ei */ - if (ei->dentry != dentry) { - for (i = 0; i < ei->nr_entries; i++) { - if (ei->d_children[i] == dentry) - break; - } - if (WARN_ON_ONCE(i == ei->nr_entries)) - goto out; - ei->d_children[i] = NULL; - } else if (ei->is_freed) { - free_ei(ei); - } else { - ei->dentry = NULL; - } - - dentry->d_fsdata = NULL; - out: - mutex_unlock(&eventfs_mutex); + put_ei(dentry->d_fsdata); } /** * lookup_file_dentry - create a dentry for a file of an eventfs_inode * @ei: the eventfs_inode that the file will be created under - * @idx: the index into the d_children[] of the @ei + * @idx: the index into the entry_attrs[] of the @ei * @parent: The parent dentry of the created file. * @name: The name of the file to create * @mode: The mode of the file. @@ -434,17 +448,11 @@ lookup_file_dentry(struct dentry *dentry, const struct file_operations *fops) { struct eventfs_attr *attr = NULL; - struct dentry **e_dentry = &ei->d_children[idx]; if (ei->entry_attrs) attr = &ei->entry_attrs[idx]; - dentry->d_fsdata = ei; // NOTE: ei of _parent_ - lookup_file(dentry, mode, attr, data, fops); - - *e_dentry = dentry; // Remove me - - return dentry; + return lookup_file(ei, dentry, mode, attr, data, fops); } /** @@ -465,6 +473,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct tracefs_inode *ti; struct eventfs_inode *ei; const char *name = dentry->d_name.name; + struct dentry *result = NULL; ti = get_tracefs(dir); if (!(ti->flags & TRACEFS_EVENT_INODE)) @@ -481,7 +490,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, continue; if (ei_child->is_freed) goto out; - lookup_dir_entry(dentry, ei, ei_child); + result = lookup_dir_entry(dentry, ei, ei_child); goto out; } @@ -498,12 +507,12 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, if (entry->callback(name, &mode, &data, &fops) <= 0) goto out; - lookup_file_dentry(dentry, ei, i, mode, data, fops); + result = lookup_file_dentry(dentry, ei, i, mode, data, fops); goto out; } out: mutex_unlock(&eventfs_mutex); - return NULL; + return result; } /* @@ -653,25 +662,10 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode if (!parent) return ERR_PTR(-EINVAL); - ei = kzalloc(sizeof(*ei), GFP_KERNEL); + ei = alloc_ei(name); if (!ei) return ERR_PTR(-ENOMEM); - ei->name = kstrdup_const(name, GFP_KERNEL); - if (!ei->name) { - kfree(ei); - return ERR_PTR(-ENOMEM); - } - - if (size) { - ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); - if (!ei->d_children) { - kfree_const(ei->name); - kfree(ei); - return ERR_PTR(-ENOMEM); - } - } - ei->entries = entries; ei->nr_entries = size; ei->data = data; @@ -685,7 +679,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode /* Was the parent freed? */ if (list_empty(&ei->list)) { - free_ei(ei); + put_ei(ei); ei = NULL; } return ei; @@ -720,28 +714,20 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry if (IS_ERR(dentry)) return ERR_CAST(dentry); - ei = kzalloc(sizeof(*ei), GFP_KERNEL); + ei = alloc_ei(name); if (!ei) - goto fail_ei; + goto fail; inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) goto fail; - if (size) { - ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); - if (!ei->d_children) - goto fail; - } - - ei->dentry = dentry; + // Note: we have a ref to the dentry from tracefs_start_creating() + ei->events_dir = dentry; ei->entries = entries; ei->nr_entries = size; ei->is_events = 1; ei->data = data; - ei->name = kstrdup_const(name, GFP_KERNEL); - if (!ei->name) - goto fail; /* Save the ownership of this directory */ uid = d_inode(dentry->d_parent)->i_uid; @@ -772,7 +758,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; - dentry->d_fsdata = ei; + dentry->d_fsdata = get_ei(ei); /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); @@ -784,72 +770,11 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ei; fail: - kfree(ei->d_children); - kfree(ei); - fail_ei: + put_ei(ei); tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } -static LLIST_HEAD(free_list); - -static void eventfs_workfn(struct work_struct *work) -{ - struct eventfs_inode *ei, *tmp; - struct llist_node *llnode; - - llnode = llist_del_all(&free_list); - llist_for_each_entry_safe(ei, tmp, llnode, llist) { - /* This dput() matches the dget() from unhook_dentry() */ - for (int i = 0; i < ei->nr_entries; i++) { - if (ei->d_children[i]) - dput(ei->d_children[i]); - } - /* This should only get here if it had a dentry */ - if (!WARN_ON_ONCE(!ei->dentry)) - dput(ei->dentry); - } -} - -static DECLARE_WORK(eventfs_work, eventfs_workfn); - -static void free_rcu_ei(struct rcu_head *head) -{ - struct eventfs_inode *ei = container_of(head, struct eventfs_inode, rcu); - - if (ei->dentry) { - /* Do not free the ei until all references of dentry are gone */ - if (llist_add(&ei->llist, &free_list)) - queue_work(system_unbound_wq, &eventfs_work); - return; - } - - /* If the ei doesn't have a dentry, neither should its children */ - for (int i = 0; i < ei->nr_entries; i++) { - WARN_ON_ONCE(ei->d_children[i]); - } - - free_ei(ei); -} - -static void unhook_dentry(struct dentry *dentry) -{ - if (!dentry) - return; - /* - * Need to add a reference to the dentry that is expected by - * simple_recursive_removal(), which will include a dput(). - */ - dget(dentry); - - /* - * Also add a reference for the dput() in eventfs_workfn(). - * That is required as that dput() will free the ei after - * the SRCU grace period is over. - */ - dget(dentry); -} - /** * eventfs_remove_rec - remove eventfs dir or file from list * @ei: eventfs_inode to be removed. @@ -862,8 +787,6 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) { struct eventfs_inode *ei_child; - if (!ei) - return; /* * Check recursion depth. It should never be greater than 3: * 0 - events/ @@ -875,28 +798,12 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) return; /* search for nested folders or files */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - lockdep_is_held(&eventfs_mutex)) { - /* Children only have dentry if parent does */ - WARN_ON_ONCE(ei_child->dentry && !ei->dentry); + list_for_each_entry(ei_child, &ei->children, list) eventfs_remove_rec(ei_child, level + 1); - } - ei->is_freed = 1; - - for (int i = 0; i < ei->nr_entries; i++) { - if (ei->d_children[i]) { - /* Children only have dentry if parent does */ - WARN_ON_ONCE(!ei->dentry); - unhook_dentry(ei->d_children[i]); - } - } - - unhook_dentry(ei->dentry); - - list_del_rcu(&ei->list); - call_srcu(&eventfs_srcu, &ei->rcu, free_rcu_ei); + list_del(&ei->list); + put_ei(ei); } /** @@ -907,22 +814,12 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) */ void eventfs_remove_dir(struct eventfs_inode *ei) { - struct dentry *dentry; - if (!ei) return; mutex_lock(&eventfs_mutex); - dentry = ei->dentry; eventfs_remove_rec(ei, 0); mutex_unlock(&eventfs_mutex); - - /* - * If any of the ei children has a dentry, then the ei itself - * must have a dentry. - */ - if (dentry) - simple_recursive_removal(dentry, NULL); } /** @@ -935,7 +832,11 @@ void eventfs_remove_events_dir(struct eventfs_inode *ei) { struct dentry *dentry; - dentry = ei->dentry; + dentry = ei->events_dir; + if (!dentry) + return; + + ei->events_dir = NULL; eventfs_remove_dir(ei); /* @@ -945,5 +846,6 @@ void eventfs_remove_events_dir(struct eventfs_inode *ei) * sticks around while the other ei->dentry are created * and destroyed dynamically. */ + d_invalidate(dentry); dput(dentry); } diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 4b50a0668055..1886f1826cd8 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -35,8 +35,7 @@ struct eventfs_attr { * @entries: the array of entries representing the files in the directory * @name: the name of the directory to create * @children: link list into the child eventfs_inode - * @dentry: the dentry of the directory - * @d_children: The array of dentries to represent the files when created + * @events_dir: the dentry of the events directory * @entry_attrs: Saved mode and ownership of the @d_children * @attr: Saved mode and ownership of eventfs_inode itself * @data: The private data to pass to the callbacks @@ -45,12 +44,12 @@ struct eventfs_attr { * @nr_entries: The number of items in @entries */ struct eventfs_inode { + struct kref kref; struct list_head list; const struct eventfs_entry *entries; const char *name; struct list_head children; - struct dentry *dentry; /* Check is_freed to access */ - struct dentry **d_children; + struct dentry *events_dir; struct eventfs_attr *entry_attrs; struct eventfs_attr attr; void *data; From patchwork Tue Feb 6 11:32:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197348 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482608dyb; Tue, 6 Feb 2024 03:53:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IHR+K1HOmVga4YiyWbZqL59IzzH7QS06x2X2q3gciYij+zBJQ/7DCiwcBZzNd/afea68VfC X-Received: by 2002:a17:902:d4cb:b0:1d8:ffbe:82d9 with SMTP id o11-20020a170902d4cb00b001d8ffbe82d9mr2246480plg.14.1707220416660; Tue, 06 Feb 2024 03:53:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220416; cv=pass; d=google.com; s=arc-20160816; b=gFJz8RTGHh92r/D1Sj1QLCyC5LxGhYoipqsxo9lTEekXNNMJU0VKyLbRDl500OZxR4 19HM3Ql3fwnKaHvmhexfAbepCdDn7yAHwoN4EQbvBF4X5vvEAJIyEB9ktjdNKjfQoP2j xzUdwBGO1J7SEZCuHRCHpvafUQnYrMGeS/JJW2DOpoUTQ481jD+OB3X/L4rjB83i9jWY eHuL/pgByuSXhq+8iHq0pgOWthUyudxBYXMtJdZNGSoHN9jMjiVGX/d1LwIOyLcblq7h R+HsETanbOjJGWqTUfVnEQHO2H5VaehQQj2H1tsdhOO3voSGuyl2sRAYCNvGVBEdkWqZ a7VQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Es1r5HTFTxAVE2/80lM01ZTjBkU6nxyuvtLC74Fluw4=; fh=EwNlCSW1Q1A17pJKCFqYnPbYcCYL+52jUgQ2gBk/W/8=; b=ckkL26OAp4ADMDbx9snrZH+z41v3Gx7knHtWvnOAmYFq6883Y8dj0RjAefqKhLd1gq XgRGkgXjx08ViERrnM2oT5CWoP5dSy4q9ZWlCRWqonCAyyA403WjrVGDJ5uuBa7ZlRrk 6SXAWAk3dZp3gZvCYuTu/h2Ce8A9kzvPPbTOQsM5yv9WAmKhrzG1SpWaKD/I0I0lpQlP Cn3TkRgVw1PqF/xeyVuPYGdbm5+6AAbtKJ3EWh2GKBNn6g4nxHpOysrA+tjs08cCu6GZ XxAM025p6WOyhzfBx5YYllqi4JhfQuiUh+9QJMQZ/ToT6Jx0Nus72i7WDrkc1DmT7Srg lAnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUoltyEVabYx6qOpLFr+Qb2aUBRxOdVTe5uVUC7sDrjpEB6APn40MAeklaWR/4iooVMfZQBgTOOEF+pOfC/s5wM9hg0TA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j11-20020a170902da8b00b001d98c856c67si1576853plx.222.2024.02.06.03.53.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54808-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 6CC0F2855A7 for ; Tue, 6 Feb 2024 11:53:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 864EB13A268; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D48B1350C9; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; cv=none; b=QoR0OSxG988P4HJlVviihmPRGCk3cYlFX4QI1cN7F6/clbBDn3MesyWsyWwy5Uti/NivEwa2ncZh697vQdx5gD3DxRTnkq4dVb9I8DI1YjJ+0CsEKjsGGvv7Kc+oZO3G+4dYFxvrt6HbWdtgVKqJYWr++l70or0gAx9R4CKhlMw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=TqvI80mt2ZF0Gnam5nEwnKCPn9ZXmcExO8VO54BJ8Dg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=tMOudrTHLR74+2JBsZ7vW/W3ESa8tCEkK4ZsF5MdE7AWFddfmvEUhXCmsVqSSXWK0V00EY2dXWFDuTrJRnJOUgrXOqDGwPKcplaQkjhSPiLUpXJ4pcilm76UZiVcJh86se6EgHUJmVX8udnPRxCzXF7UpL5ZYQX8b4TIpkj/Ofs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C08AC433B1; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aQK-1xR7; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.324608021@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:18 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 20/23] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150355919363576 X-GMAIL-MSGID: 1790150355919363576 From: "Steven Rostedt (Google)" There should never be a case where an evenfs_inode is being freed without is_freed being set. Add a WARN_ON_ONCE() if it ever happens. That would mean there was one too many put_ei()s. Link: https://lore.kernel.org/linux-trace-kernel/20240201161616.843551963@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 5a49f996046ba947466bc7461e4b19c4d1daf978) --- fs/tracefs/event_inode.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 515fdace1eea..ca7daee7c811 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -73,6 +73,9 @@ enum { static void release_ei(struct kref *ref) { struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + + WARN_ON_ONCE(!ei->is_freed); + kfree(ei->entry_attrs); kfree_const(ei->name); kfree_rcu(ei, rcu); @@ -84,6 +87,14 @@ static inline void put_ei(struct eventfs_inode *ei) kref_put(&ei->kref, release_ei); } +static inline void free_ei(struct eventfs_inode *ei) +{ + if (ei) { + ei->is_freed = 1; + put_ei(ei); + } +} + static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei) { if (ei) @@ -679,7 +690,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode /* Was the parent freed? */ if (list_empty(&ei->list)) { - put_ei(ei); + free_ei(ei); ei = NULL; } return ei; @@ -770,7 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ei; fail: - put_ei(ei); + free_ei(ei); tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } @@ -801,9 +812,8 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) list_for_each_entry(ei_child, &ei->children, list) eventfs_remove_rec(ei_child, level + 1); - ei->is_freed = 1; list_del(&ei->list); - put_ei(ei); + free_ei(ei); } /** From patchwork Tue Feb 6 11:32:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197347 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482546dyb; Tue, 6 Feb 2024 03:53:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIQGMd9ULAvW1MUoM1cSWpsxdnP+9f6KgJd4r8yhicMgf2SQjh4EjrAMEHKP4aIDu+Ktax X-Received: by 2002:a17:902:e80e:b0:1d9:3d72:b296 with SMTP id u14-20020a170902e80e00b001d93d72b296mr1332697plg.35.1707220404509; Tue, 06 Feb 2024 03:53:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220404; cv=pass; d=google.com; s=arc-20160816; b=IKRsf0P7zE72ikqEUnFwm4L39LkjpqtfXN1rnhZJ+EP3OjOOWp9oDLL/gqUIV2nD2e fWqRUA72ApWNggGPJ+dwJX4JjKPOyzzMs3yOdz3ZujgOnZuxC1AMgx1TFG/oJcwBa6tb FIYIgc1JE2Wq3yYw/q+Ex1sKpBYimsHvE4T6LOkKgNlvOIkFlXc5Gvh2Gntbu0hwHVbt l4rR1I8Vi3DsTanjwccE7ESh+22AN7lDOAYvjHYgc4F3rV+suAsWRoHaLHX45RDx4NFA TpvJzBw2aVuJhDNsHvMoSJ9t1vp6U2/hQNS0/Ti/F/Oh7TFAvgZ1cM8dBfqW6strKUiG wRxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=yQvYu4PlEpv1rOx1zrXjk3aBdiBZnT+MjoFuOI8rBCM=; fh=Je29vOftpQjkhRFvQH0oQq74xN/iJ8xAywjnscmezpA=; b=0GB9N/IhU0rDOzg6zqkWh6PBx5/fKgnwTppP5Yw8zvlqcI986EuXKBcueVXYp9Ol4G YGzlhSY7QAye9LxQSiQFcVM7zVNkm7NYdYbpNipkvDIshddloA2ZXY60JeO1f/H7TX92 O7te6Gu7zL8eNtwdlGIkZQigrDDrm6yM+ZTRYCudOod1mTdm95ndSGwqs5HtOtVmorIi 9FYuQxgasoYXy4FOV+v56iJynJnqFryUvoiwF4XTjJJZgweCyz4Qs/Hz682tFfb1uU60 09BDhN4Q4FzOtZ+CvVhiKCMM+aDUj+BxF/2+/dWXsWXTPYEiAKFO81p6t1MVPuUxitEv TcLg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54806-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54806-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWhroTwRnRk+SZmeBgFQUHF2eQbwLRjJLqTs0qiqxwiTY+7ZzajmuZpwdhtm4+PMxv7sLGfV2H6ht0hKX1zOereG6gAiQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id b11-20020a170903228b00b001d942aa254csi1546482plh.294.2024.02.06.03.53.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54806-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54806-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54806-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 1D767285150 for ; Tue, 6 Feb 2024 11:53:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6419D13A25B; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69FCD134CFD; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; cv=none; b=GELwH/kn162Pyy/qhPD9MsW0W/8Uy9tpR9oXxFiC0BcpGzvLAEJvktt5cCHSGIi+6727WO1puPsBPeaPQWoKrbPTrzFJqbplJu3Tis66pvmXmWEhrDzbfc3AhMIjWYMzgk93UiTyuI6cmux/f1uSJu9JS5a+kBm/CtZrzN0RU2M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=ovB9zqm93FTVxxBECSNPxdclrmbXtlerbnuNH1s24zo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cFHJmruJDfhbljS00I7crpY/KsKIJvcQBgGia9xeXWuhx6zJLKHvEe8TGVAyK5gyDtgumDiSesg/QJNAoBHui5inxNtPGyGUDwqypLlLcsqtxcDVdkLuVdlOUnWrfmk9I8pInv/MOm/BZx3v4PtomN/6w2HGHY7TxD0s+8ZvkYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 430E6C43394; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aQq-2eTT; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.490005209@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:19 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH v2 21/23] eventfs: Restructure eventfs_inode structure to be more condensed References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150342600830155 X-GMAIL-MSGID: 1790150342600830155 From: "Steven Rostedt (Google)" Some of the eventfs_inode structure has holes in it. Rework the structure to be a bit more condensed, and also remove the no longer used llist field. Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.002321438@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 264424dfdd5cbd92bc5b5ddf93944929fc877fac) --- fs/tracefs/internal.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 1886f1826cd8..beb3dcd0e434 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -32,40 +32,37 @@ struct eventfs_attr { /* * struct eventfs_inode - hold the properties of the eventfs directories. * @list: link list into the parent directory + * @rcu: Union with @list for freeing + * @children: link list into the child eventfs_inode * @entries: the array of entries representing the files in the directory * @name: the name of the directory to create - * @children: link list into the child eventfs_inode * @events_dir: the dentry of the events directory * @entry_attrs: Saved mode and ownership of the @d_children - * @attr: Saved mode and ownership of eventfs_inode itself * @data: The private data to pass to the callbacks + * @attr: Saved mode and ownership of eventfs_inode itself * @is_freed: Flag set if the eventfs is on its way to be freed * Note if is_freed is set, then dentry is corrupted. + * @is_events: Flag set for only the top level "events" directory * @nr_entries: The number of items in @entries + * @ino: The saved inode number */ struct eventfs_inode { - struct kref kref; - struct list_head list; + union { + struct list_head list; + struct rcu_head rcu; + }; + struct list_head children; const struct eventfs_entry *entries; const char *name; - struct list_head children; struct dentry *events_dir; struct eventfs_attr *entry_attrs; - struct eventfs_attr attr; void *data; + struct eventfs_attr attr; + struct kref kref; unsigned int is_freed:1; unsigned int is_events:1; unsigned int nr_entries:30; unsigned int ino; - /* - * Union - used for deletion - * @llist: for calling dput() if needed after RCU - * @rcu: eventfs_inode to delete in RCU - */ - union { - struct llist_node llist; - struct rcu_head rcu; - }; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) From patchwork Tue Feb 6 11:32:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197350 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482660dyb; Tue, 6 Feb 2024 03:53:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYYTJciJfA+e1/4bWh4J8vMj+sQ2uMerBzQYrtqSxsY98wfRXR2G3k+VBF0tsF8oPhNomr X-Received: by 2002:a05:6808:f01:b0:3be:b86e:35d with SMTP id m1-20020a0568080f0100b003beb86e035dmr2611943oiw.12.1707220425853; Tue, 06 Feb 2024 03:53:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220425; cv=pass; d=google.com; s=arc-20160816; b=he7QSCUeahx1Bn+07PwFo60Tb57O9X8buHByudB0Y9k0wx1CWGy40GQezpfyUfOjUm lpoA1WQv706Y2nyTeNVGPD9UaRaEckk6mWzEfzvBqX/PYfDNn0vxZnZKyWE//ntWsruA vqXOB+qrtMw8IgHb/WT7d0OCzZWnVxZYUQXrF3C2uaM4LQPSE9eqZIzgZVqLri3sWIpu KEuQ3eT2/TIXBGXhvEre/RmI/KOW+xqViaTWqe/kkzOlsR5+m+3uciA/qDxsLxj6CIjP PjIoLAi2AvwxWUpgl8y/l4RW+5LkooyicvaYTIxgJoCD3+1tuwRhra0cm5Z4CaMxzhiU Cnhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=//znUvdDCjBcws5msj92W0S44vVgjzgRljeV2BJnUc4=; fh=ozfrZl2C32zY8sXewKj+d3iCwGLgxutsxD1ZuXez52M=; b=YW8LjGbWewNYEsbj6XK3LlPJRuxv3sspvDSS/xb7og3Y3sjN33Xl40x6Otfc+l4YZK 21Vv7EQ5jeLVh6qFXXJMW3kQ7W8Zh05sfc1UmVkdF3EBkoEnNCR34ewhjwyifCn3BQp6 sz+K21SVZ3AoaDqo37OCmRHY605XXqmLY2wKzIKqkjx4eqozl1258/zkcFK5HfAJZqCu N1AIXA4ayf9HS9YeyonVj+kKZna/CcAaG9oygB3RmE6a/EwDoycPfuy3I3wwUNuNO324 cZ9hxqTLZNDqTl3oTKwyZH6esLRlCb2E9QspTYIOAUNxi/l3p5HAu6fsDMBURK8Z/WOl r8dA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54810-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54810-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWb3Zj7Ve9yXZi8UDQGpk7k0V5/okMKT3D3/rwfE7kLSMRLcvBRkr5/uQEnuecCXfCw5kAc2Hf57fye84R7L1rWuWSACA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i24-20020a63e918000000b005cddfe0c82bsi1534721pgh.211.2024.02.06.03.53.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54810-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54810-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54810-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 968C9285E17 for ; Tue, 6 Feb 2024 11:53:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1FC613A275; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B570C1350DE; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; cv=none; b=b+E+gcksx227dnj8RHUFFW4aMTdgsYJAUmsGz0150id19T6DjANzlqY68aE6DmmWrb5aJPjygB9Uq8nfmqT/Co93PRFcZkMpvY4KTQv4ga4PM0i40Z0XqvJGH4BGEiVDVebkCYOMpKSkPeZf5uuo/JFkozDkOzoAd5F3PiUT8jk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=5yqaMUzsL24Xo1kXlS9YCQkGhNmG85TgGVOtLxrgq1g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=IWQ5mga3cxQEFYWO/rTVDMlnwF1lA1vg+HgGfEnBzSPSTisx/QBVSTS52Kovr+HSI9Dx/xxb0JpIxGxosYegknJ9BK5x9pGIQ5Tlrol4CYLMoryguxMNUVbmVkcvTCdx8oxLCbl1JG6kC8UKbvgq5gymtujDOByRVnGhCdH3qr4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 633FCC43399; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aRK-3LIc; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.654906760@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:20 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.7][PATCH v2 22/23] eventfs: Remove fsnotify*() functions from lookup() References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150365278772520 X-GMAIL-MSGID: 1790150365278772520 From: "Steven Rostedt (Google)" The dentries and inodes are created when referenced in the lookup code. There's no reason to call fsnotify_*() functions when they are created by a reference. It doesn't make any sense. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.166973329@goodmis.org Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: a376007917776 ("eventfs: Implement functions to create files and dirs when accessed"); Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 12d823b31fadf47c8f36ecada7abac5f903cac33) --- fs/tracefs/event_inode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index ca7daee7c811..9e031e5a2713 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -366,7 +366,6 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei, dentry->d_fsdata = get_ei(parent_ei); d_add(dentry, inode); - fsnotify_create(dentry->d_parent->d_inode, dentry); return NULL; }; @@ -408,7 +407,6 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, inc_nlink(inode); d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); - fsnotify_mkdir(dentry->d_parent->d_inode, dentry); return NULL; } From patchwork Tue Feb 6 11:32:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197351 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1482681dyb; Tue, 6 Feb 2024 03:53:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHqIa5W0T3LMkoeEhF5ySLcGdFIdnVQA8gNgbcUbGGaV9JThLOK7nFySBrIEJZa1IDEZ23u X-Received: by 2002:a05:6214:2262:b0:68c:a7f6:12b2 with SMTP id gs2-20020a056214226200b0068ca7f612b2mr3051989qvb.8.1707220428312; Tue, 06 Feb 2024 03:53:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220428; cv=pass; d=google.com; s=arc-20160816; b=FEeCsiubcstUZj5Pr3WNChp1cqBctVkKEnIp5m0MIY7WT5LWI1OPix0+YDr2vXtHrT xptqia+kI0FgXbJWn0vFN9D9Pnjgh4nrXs1V9Sp+t1W7kOqyjRF6zmowtvJ8dHHdC5Tm oE6F+uHXJ0CVJxXZ3dIfCBonMF1MJJPqdkSXFV0EkRnK39gAXcumBN81Db3Wo4AVAL0/ con0L1xUdXDQ/AJqs2NqyH6Zv4ChixPxNod77oAa0MovzArJURGX3OCu8aixbmUsGU5C tE++99V61ED7Gc28Cu13wPhdksZMO/g68HtNnT+yZTADdJvp2I9wMaA/vJ1PIdZAkSY5 d6Gw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=3rg9wT42s0qbZ5O6GIg3gk9NLZhbRpGnQkxTjHAIRpw=; fh=8v+vbw1jqa24zdhVIP0NCwKXip8uAMfkbjswAD7cRGM=; b=cdPwhAzhMYIYSkTO9oWwY/+RXo/7MhHVeezcs+CpqLImS6pe/4Uofk91+fq5H2ptqF wC6VORaIiVHxJ3Dg7W/REs+Zy04I39DdJJrzBnuTm9B9QtdR23bFc1DO8d3iD0zbIVnH t4iNp9TwsyIab4B68qhUgGU6qotkQdGskWSaZLI9cPcMkj9SyA9zFfSciOJWAMVV7PSz bLJvb4BCb+LV7vwqUxTDL54+Bfv2NeUsCfGkX2FjQBHoApMhbuqzCaqkiSXdJ3Bcapuh hBlM5ZSkh0LLHbvv2xjKA7jiIVlt7jUmPcja6AmrZq0kXoUpByIEKC29YaZNbUSXoCUI IFpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUlqkYCzD+D+H3lLJibB2CPwjGUFhibHzP31mtQi2WHPKiFF/ilxMYmsWElDhiszhkYESArxSo4x7Ui1QTeKjz2wVcE2Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j2-20020a0ceb02000000b00688b198a444si2136928qvp.97.2024.02.06.03.53.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:53:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54809-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 1DB611C220AF for ; Tue, 6 Feb 2024 11:53:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A738113A276; Tue, 6 Feb 2024 11:33:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9948E1350D0; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; cv=none; b=qlnBMp8+kCeV4V1+Q62WxuIk+YD3hEzqzeHNUg8vPKTIPuTBBaDxJ8WhgqRXgCZd5OYXB5Sf+NnBMFVgCVYhSRM1iYi5uXGZPi6s93COdvfFakPpWBVZiY8+q1JVZ1IqYEB5fyVJJBpUplUtSVmOo6sL3RAOhjAlC1U7so2p/nE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219213; c=relaxed/simple; bh=K0Ph34GY80unDV6Wcvz0AavqMJytP5uSNCEE07y3Q00=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=R+YfVpntuY9rMvHY0L0Mo0ERrA38qXWVQ2UtCgSZFn5ZaDq+feRj6v+R6nGllm5NlVUMobZhhInF04QtlJV9j8EKIg0RJScD9Qu57Sn7UgGCxBhsPrT19491kTAs82UkvNrY5xenfkLCFUqSs5kwDqX53Q4jcp66hPqlIDq8fdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 849F1C43141; Tue, 6 Feb 2024 11:33:33 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiD-00000006aRp-42bw; Tue, 06 Feb 2024 06:34:01 -0500 Message-ID: <20240206113401.818811467@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.7][PATCH v2 23/23] eventfs: Keep all directory links at 1 References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150367935398712 X-GMAIL-MSGID: 1790150367935398712 From: "Steven Rostedt (Google)" The directory link count in eventfs was somewhat bogus. It was only being updated when a directory child was being looked up and not on creation. One solution would be to update in get_attr() the link count by iterating the ei->children list and then adding 2. But that could slow down simple stat() calls, especially if it's done on all directories in eventfs. Another solution would be to add a parent pointer to the eventfs_inode and keep track of the number of sub directories it has on creation. But this adds overhead for something not really worthwhile. The solution decided upon is to keep all directory links in eventfs as 1. This tells user space not to rely on the hard links of directories. Which in this case it shouldn't. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.339968298@goodmis.org Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) (cherry picked from commit ca185770db914869ff9fe773bac5e0e5e4165b83) --- fs/tracefs/event_inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9e031e5a2713..110e8a272189 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -404,9 +404,7 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, dentry->d_fsdata = get_ei(ei); - inc_nlink(inode); d_add(dentry, inode); - inc_nlink(dentry->d_parent->d_inode); return NULL; } @@ -769,9 +767,17 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry dentry->d_fsdata = get_ei(ei); - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); + /* + * Keep all eventfs directories with i_nlink == 1. + * Due to the dynamic nature of the dentry creations and not + * wanting to add a pointer to the parent eventfs_inode in the + * eventfs_inode structure, keeping the i_nlink in sync with the + * number of directories would cause too much complexity for + * something not worth much. Keeping directory links at 1 + * tells userspace not to trust the link number. + */ d_instantiate(dentry, inode); + /* The dentry of the "events" parent does keep track though */ inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); tracefs_end_creating(dentry);