From patchwork Sun Feb 4 01:16: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: 196381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147312dyb; Sat, 3 Feb 2024 17:19:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHGMqifbbgA1I3Sgp5f6MNbDfWUP1lZuuxPuyX1i4E+qeJ9yzDOD5cc8cs6fyB8JpX7g8MK X-Received: by 2002:aca:1c06:0:b0:3be:3e88:215f with SMTP id c6-20020aca1c06000000b003be3e88215fmr9250525oic.21.1707009568970; Sat, 03 Feb 2024 17:19:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009568; cv=pass; d=google.com; s=arc-20160816; b=ZrTI4z/OLJiB+IJzupn7Z/z+MG+DAIJa4and1w6Tv5NaUb1Y+zp8PdqLQqUbGjMslz ueyomBtWXvVF4SPGmyKyzLJP5W1+WWJAIEQvRf/VfKNhJcRzUVqJdzIP6nmTizOIXloK RYagrfVDsODr/Z1u3VoUcwYdy+AVbdom99nmo46kSHXXmdcy1qTzKUTdrq9rdgWiltth +9TyqI00zK5UgviydJDolzeDKrmze9D1Ya87WKfwefTiLzDeoEQioOCprt3o8WoNTh2K u7w58Sw10+daq0eOI+YIvl4MnZ7q5PZFDwFLeqj4IZJQDurKYQT4KXvwn6jSSU1eTPWs 3yFA== 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=aslnr/pTrb4nEnroPWMcmbcBXjfFRT9lZN/yQlB9EPs=; fh=jdv0FSPWnVMKtQ3CWwqfWntHrKMtzGwEAa94xQ+fsgk=; b=H4RS3kPyJqi5sT2AHO/2yuz1GjwojxuDq/dLBUzv2kBdG1lXLU4jpjj1D22nymT4rM 2W68PTXt7xcELkmNW0SEi/2e4TOhfghtU9DLLk3EJWOx3NcmbSK9CPDHa+XOdDWi9aU5 UaJGehbC2sKGYhGLlWJkGMLQr8Z5/YhJXzA2buDwR44fjUDsX8lL3cds7c/y1a2GWnYh nYHDP144osE/7pKKP9m2k0w+VZsmG9xauvOEolLKvEFAl0m0eeramyUjmscYai9X4l7J LPIA5bdQZ1EVakGbDKqy8EfVPAgrzXgfsHNmWnFSToVG4u33FzzjMMCy71Ozadxi8s0T y1MA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51336-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU5itvr/Or+/OZvglAS/Xgjs33fqbpHdswhfD0vlp/pAno/vkgyvxoKm9imcQuy523cGvr1SJZU9V02s5B4dC4AcMqpfA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id p19-20020a05622a049300b0042bfeb18fc4si5310737qtx.761.2024.02.03.17.19.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:19:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51336-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-51336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51336-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 98B731C2211F for ; Sun, 4 Feb 2024 01:19:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6F8B3BA26; Sun, 4 Feb 2024 01:18:07 +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 11553EBE; Sun, 4 Feb 2024 01:18:04 +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=1707009485; cv=none; b=S745id4pcc78RUqG9HkUWqPtnvm9dQtNQe9Nv2wfaljotCPbVyAHV+hZnTLCKTdhsdqdL1zQTNN4aE8x8HWajcplEtcDaJgll8WpDJhwLPSHavrj86hkMH0wXxpt5mujp+AZT0TfmQe0cQ6vOrubmJ3zb02vvgasDyrIMyH6W6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=EZcovijnhX0uyo9T5RItBcYWeSIYKlNQ85lLrAUNg7I=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pBdzjztki31VKO/foFhmv/sak91Lswr8Q0xBwA0cnvGmkhAFs2uGuSFHWlaGosjWhdVOmTT2rpSyniZ2LmvB5QubZLx5rlHbyjSdoK6QYt/jPRwKyVHBa34ze2cfpNE7Z9pW6aqGhc3ajXT2G+/iMZTsBGfwHitDh0Urwmjrw2o= 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 95783C433F1; Sun, 4 Feb 2024 01:18:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9P-00000006Okq-0otJ; Sat, 03 Feb 2024 20:18:27 -0500 Message-ID: <20240204011827.061811169@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Andrew Morton , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.7][PATCH 01/23] eventfs: Remove "lookup" parameter from create_dir/file_dentry() References: <20240204011615.703023949@goodmis.org> 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: 1789929265717269157 X-GMAIL-MSGID: 1789929265717269157 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) --- 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 Sun Feb 4 01:16: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: 196384 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147393dyb; Sat, 3 Feb 2024 17:19:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IF57rgxd/QJKBpAUD20Erh0VKmcmDxdlJ9C3N1kbYEYVMiL69s1RoIvPaEDPZEhbm96NJ7V X-Received: by 2002:a05:6a20:3b83:b0:19c:64a5:2162 with SMTP id b3-20020a056a203b8300b0019c64a52162mr9695710pzh.20.1707009588381; Sat, 03 Feb 2024 17:19:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009588; cv=pass; d=google.com; s=arc-20160816; b=XWeNmNrQgDP7sD4hdY17zJqSqu7BWZWed47U0R+HI45zDqvGs/YoFM9CPDrbLjyonP BBJcMBrfAFAgOVggYCOHQc9ssNVD8gR+AZRmZTbOP9/Egose6boqYvPCfjXd4w/YkrsU 2N1XSKdxdjuamZfgSjJzuHxwp9FoafIqp77F6UqLiWEXEUgQVYVcfaS58BBjuZnUrFfZ 9xe8jt6kuaNifRbP08mDQ5L5qL0NLWP5OQBjE2637+ocOuCchk9lJLjkoabgXUFGU455 Y/ioazyN//C6LJBoalHMzEjCNhAqBuHdcy9kRaoVJOjJakue8YU/mvwwUiJpUZefwqv/ sXFA== 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=bKxvc4YAzpSO7BBwJjKNak+96BkMkatBM5CtvJqdiEc=; fh=ojN0cQQXaJA+M8LUMz0Ih8rGYdbNW7U5J9uHzRfXsgk=; b=N7VI9/X0+tlWQIsQwg6QHmbh88jj2SrsqGr1M105AQhXz/kUzQNhZGuMe8USFa4Fmo uDVluRI0KUHmqhcxjdUTI7mZz7FxI1aicCLPEt3ns+Q9ScNZ6QsBpbRnG21aIpJ/sOVa LWPueEiuUpZg7lraJmJKDKKEjdDeghKAusWu/vmtgDI0OhkBrT22Y5a4K8W1Ak3ysvK8 1kCoXg92c8TTQ0VbUbiIAbN5fmKuiAoYklcwg1SvU3NPR/VA0A2niXnC6H3ptJlsAKCK L2sK9xeBxTHUqGnCsjJ8dY+jqL2ORUsXRPvV4f8xZFTDDOq4IaLJq0+xHqG3gukcWca4 WdCg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51338-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51338-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUEGYbIbUDbUNPOKBTqQ0zFgE5unOLOw4XI5bhLhjOHz+A4RO151bZY4esEjOWu+MIVpTjDQy6GeunbdtkiTwubK+6/Ew== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id t26-20020a63535a000000b005d74823c24fsi3890089pgl.440.2024.02.03.17.19.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:19:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51338-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-51338-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51338-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 15074285996 for ; Sun, 4 Feb 2024 01:19:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAE12CA73; Sun, 4 Feb 2024 01:18:07 +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 491F610EB; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=lOJ5W/biCnqu13z69PGLYwTmoM3oWJKS/L8vPvZY8LnpfHywRgaIlJj9LawHCWHxlildEbWdF45baqE+ZaTI8fqWv9bSrzSKbV7kT5aKigljdxbVb8/NZD9e0DuBhTkjrRuTqlFihKJJmX1uQqAHGYSkOHY7Hv8AtlMFZ96Z7qs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=jUJ5vcplB4p9wFqT5/y72+aXssR5CrN6vKMhVt9y3RY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=bQJ3mmG2sx09Yr8bFAreRYvJnMdezIe4ijU2NXimWLRSdySwWn39rE8csVvpIFAAZ78ztrxz1gFokgX5sAjPVgj+wLxYmV8xr597LSKBJmJ6t6GJ9vvH4ScXljLgR3qoDNOLfSTXMe2V7JXVFpLrdg/rbhvo/mgzI/5VZjM/0L0= 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 D1888C433B2; Sun, 4 Feb 2024 01:18:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9P-00000006OlL-1Vi8; Sat, 03 Feb 2024 20:18:27 -0500 Message-ID: <20240204011827.216552402@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Andrew Morton , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.7][PATCH 02/23] eventfs: Stop using dcache_readdir() for getdents() References: <20240204011615.703023949@goodmis.org> 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: 1789929286019456110 X-GMAIL-MSGID: 1789929286019456110 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) --- 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 Sun Feb 4 01:16: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: 196401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148936dyb; Sat, 3 Feb 2024 17:25:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IG/ULcDqgvh8cPItHiKJwoV6yu0hg2F0DNYs++XnPvigoU601+bStyvrPPWda3x516S2qAs X-Received: by 2002:a17:90b:19d4:b0:296:19f2:235f with SMTP id nm20-20020a17090b19d400b0029619f2235fmr3437739pjb.11.1707009937536; Sat, 03 Feb 2024 17:25:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009937; cv=pass; d=google.com; s=arc-20160816; b=r/qh9urkJD2j5ypgsiASGE2R+bLoS5GPMQNiF9Ty47TLWewBLYBg5SLRrYweKhykk9 LBE7Cv4kptozSR8JlHwPQlEQA32FX+FC0kmj+AdqFiqZChz4/KFGuTs+asy1L5WH2Xd+ wVkwmLmYx7suh+G3RfHYl4BJJtLljHg6a2e2Pp7l9A/pYVef96daAcdGIb99SSYxv/s/ dQtdF2lFazihS1R8XR8m7Ut4usxBkBHXX+ohsNu54UZ5iiMOM/K64AylKnSTwt57ECMx c/S+zj7Xxhk16FUtt4b+8rL3BDALkIpG1tCx/wGjh/IPqVSWmzUWiE3MfAaRXk5cIPE2 E0KA== 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=DMMuGiMehTAiMlQ3gAn/tR6jywu2LPfCKkRLpe3IXbQ=; fh=2pukvG5MAwInS/2kNXkCXAayx5a+YhY+lNCw2lBJXVw=; b=CXCgZZ3aX8AypeXcRkWzBQyGD/llR88R1z4+hibUHEoEPEV9AxyyGRQ9ubjtkzwQgo RjlM8Yce28e9SucIsi+ET+ieYTycnQkCdeULzcKDGc/lTyOJswKn1aPrIqCY1qO2kTb3 gL1tgq19EUguq1V1yKvo4ubXErNOscDJKFswaBkVTwrGIod+CuhCAmzEK9ZCVWNV1TiS yxsoev0JiHBP8nQpwHgwl2V8z9h9M7AbRqeAErwgcz4syzd9NkEh+553nr2aQp3LyHq/ 9JZAyM8H+0cbTifgHdi4j0+ldWF8MhCSt0BFZBCHhVEK72rmx47yl4AGB3EygcnKrCek F30w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51342-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51342-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUPaeaPXa+f26HATV37ZdTal9Wb0Y2yKfWiUb1mBEWL7DwNuBu1Q9Z8mHj5Xh/6w95sg+vTGSo9Vj4NkhWZpXWj7DUteg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id br24-20020a17090b0f1800b00296181ae98esi2204409pjb.180.2024.02.03.17.25.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:25:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51342-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-51342-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51342-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 D9047B24FAD for ; Sun, 4 Feb 2024 01:22:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2075617BC9; Sun, 4 Feb 2024 01:18:12 +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 A57331FA5; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=nKACV/P6ZmmX2wMXYPGQ3ltMFscDBajblrE0/WATlrNZSY7U3cWKlsLylGq+7YoBpKnlORYKxSl0XUGJ7NAKq5Vtsd5BXwqeG8j1su4TllLABYfqu9pNp1aZCJ7boB6rYTYMDMTBpiiYekGJLtpmeN8ZfDM25GT6LqnmC5KmILg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=dacRcw2gKC+9hghT3w2xgO3dhpT8lAcxuQ2XeqmMTek=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Oslk8W7t7j8blEkdzcGYewGwFNx1IGrLsB4Z71HlSRvwCUmFnyQCEmXk0gWKS3BBw690uu1vTenvVsyPeflsj6wVsG03xfIvdyJRZZHvJnmv5LUY3d8zrrEaWg3wUOkWiQQmkdyGYAJ6qsZU6c3MxlY3+5Rg+W+Sac9yXLEtVps= 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 F4143C43142; Sun, 4 Feb 2024 01:18:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9P-00000006Olv-29w3; Sat, 03 Feb 2024 20:18:27 -0500 Message-ID: <20240204011827.381351684@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH 03/23] tracefs/eventfs: Use root and instance inodes as default ownership References: <20240204011615.703023949@goodmis.org> 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: 1789929652330697680 X-GMAIL-MSGID: 1789929652330697680 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) --- 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 Sun Feb 4 01:16: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: 196382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147325dyb; Sat, 3 Feb 2024 17:19:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrRAIQbtKe+O6u/oKl53LXgXSNr/LHhHqCqg7HDKpjt3TwWWTEB3yg4H1PxzYGGl+5Hc4O X-Received: by 2002:a17:902:f683:b0:1d9:3edf:1e2 with SMTP id l3-20020a170902f68300b001d93edf01e2mr3726702plg.3.1707009571794; Sat, 03 Feb 2024 17:19:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009571; cv=pass; d=google.com; s=arc-20160816; b=kzOPTvhv5g320zaE+Nw289DRWM21SMlL+Pbl4wf/cTtxhRXRB2+KdWmpmAtFLNFBq0 c7upI4C/Djdi4/GcjVg04XTqggtq8xeaHT0iGXfWTZ5ToX1hJMl2tfV98JBrD815LcT+ jl6F9ODa/3IEGvXjPNbJWl8SCFAA6qtO44+QmUdHl+RqVfOqL1F/b4S148ymEMhEobGL laeS9rbPk0kY8S51Sb1BBgbMHZPoPm27FflCIBpcUrPJslmd0/+7oyssH0baGqiMGlLS vRk/B0nW6784MFbv9+H6DV9RhN1sHp48jlQIUhg8lLN1QBW0W7mlZ6GUqOaKFgySQI/R HbkQ== 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=G94krBZ90YOfynXklLjFFv1YKZHn7bbkOvvSG6fKVRk=; fh=HdcLdX95CU86UmCXKUSi7mbymhyVDdLUjSahVdAJOIE=; b=X6GmBZ9fl1CmnyIO9INxC4tQNBtOplCZRuEWLhjBZafQOUBZ0e2CFwjGkKJHT34jgr 6FEKkF3R6JnZFpcXd6SLbARWKlaJTCvE1invQ3lUOxh95BUp24dj+uebbhWYRHmQd8r6 p7hmJI29UI5elQfKwNpo3CRQQKFesXM6jWVxAMUYca1PCDVbxnHVBfFXwj5OR0GqAs0T w+8QtWv0hlGKbV7NajHq69zLvj2O9dFKIzGq4+m9No+apUSJU45nWNzrk+2MW3usgsWz kAvXsrblVVloN0XgK6H03h9NoXvsbpuzfophI/XiVO5SmmorQtCF3KIkTa/gPDe45+vC HY8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51339-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW1+OXxLdZF4Snzekurvq+Bo9A9G4mYHVue28HXChZ7AE4v5PfPcmp5YPZTWocRjHUQAmGPN8xiV74jo/+bQ5N6CJkenQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z1-20020a631901000000b005dbee5249fcsi3954088pgl.688.2024.02.03.17.19.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:19:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51339-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-51339-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51339-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 4C570B23CCC for ; Sun, 4 Feb 2024 01:19:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48115AD55; Sun, 4 Feb 2024 01:18:07 +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 75F20138E; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=lQk0ENDVnhfdSD1eHW8kl2EhWF+qvRKrJotqySWs598qOS7dfAYhn4TcZ7IDHAewWGZo92zDDrVizsQRjLv/WkT27LOsEolI627saoEBpLcc7suJbxMenK8vAnroBFyAfqK3p5pUDLK4oEBmj1qfNrnoh0cr80Tr9v+D69oLnHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=ggzO8piDWd729+n8HwEUay+QGmmX3pyBkc192DI4teg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=d0uv/Z7th/C39yWIWSuVDdhJ15MCtX7AYkX2FiqRY+AgGD27TppyEcpBEbhW9AeUFrotCUgZSPQkJSHWGPIVzBy3w6ZkN84oB2ikiPQ3XG4xzf1ZQfiEbCwTa6CMxQEtPZaJXBItwoxQafR27d9YfpMxVJp0L+qhNLXMUZpr6GM= 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 0ABE8C43609; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9P-00000006OmP-2pcL; Sat, 03 Feb 2024 20:18:27 -0500 Message-ID: <20240204011827.535604040@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH 04/23] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set References: <20240204011615.703023949@goodmis.org> 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: 1789929268337435507 X-GMAIL-MSGID: 1789929268337435507 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) --- 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 Sun Feb 4 01:16: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: 196385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147810dyb; Sat, 3 Feb 2024 17:21:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IFw4Uwos2/3f93+ZYsIHrfgxtPDsCw20qp1O5rf6Q0Mkt04klYkoAmRy2BWN+NedSZqjdpm X-Received: by 2002:a05:620a:10af:b0:785:5913:c465 with SMTP id h15-20020a05620a10af00b007855913c465mr6206526qkk.0.1707009681896; Sat, 03 Feb 2024 17:21:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009681; cv=pass; d=google.com; s=arc-20160816; b=LowYVYGs9SYuyTC2GidLu6EVfdOgniiYE/AifCiBxueP+qCj7oq5UJni/rw/EgrSNp NjVTi4FH//wpRyYqYtbWNZBhoiYobKzmnngZgndIhEosgcA2SJDZZzuo0cem7x8m4aYE Ee9ZOAIMLbC+9PoX1Gi81kmNA/uvVFdUWbbzcMRIpDuIwn3IDZ1h2dB+y4C6q5YOVmGV /G8m2kVEwfzJtash0al+Kp+1XyXNzeIuYD3QAmovUdZASdvKe/IQHlccRH0guHvahCJ+ /adAs/CJ1Cs6IAZHJqS8YtAEGH3RBuSti/L7Mi0UejvpAXphLeryUUWVav4L35I8asA2 65CQ== 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=+ogg/UgV27PhdL6foBSoEIa1i6xq/Q7UxaznoXL1uwE=; fh=JX/9LIYRdAub/fDwvGHjFhcdFV99YgjOo4XnSvsqJdE=; b=ENpBdEgfkL1hF/qVjB+1fSiKzqgtvNbf8o4vknvIr6CkDf9qiJUA2Mb738vOSHIksf ZvP6JuVmWaSeWbru6IxVT98tHkdWjDaKX+E5OQYv/Wnf3a5Rr/TFoLc1Oo6IGL9w7jJP 3ujdsGh7eIvgcOSBMasO1ykguahSU9q0cs49FZwbEWXDa0oTzmxOhgVZtLyZoudisqQy uUNevM1LIxA611lb4XzwKCX7jnp2kpCQZhu5cls8EDfJZVq9t2vx2PQPWBWVtHFJvpHi P9DF6cL0iBpUzuDkmf5zIgGT7wspO4dWkPm/dEF1aZNLfXpwd1hBDz6OGLwxN0rdQqGG yV8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51341-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51341-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCURlAF/q0RGa40j4I6g44mFPkxqfTb1+gNL1R+lAw8gecBGVVvXfb+ESMnDd9KOvP+8KYcJEeZ2ScFTvkwg35o1H29Oew== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j16-20020a05620a147000b00785559a133fsi4737047qkl.391.2024.02.03.17.21.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:21:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51341-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-51341-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51341-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 9ECEE1C20FF7 for ; Sun, 4 Feb 2024 01:21:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 045AB14005; Sun, 4 Feb 2024 01:18:10 +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 A570C1FA0; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=rBe+KZ9WW8h+ciK1lTdFYgMGUNc4SPnygpPn2+hc1iT+lAVDbsM2qGfbdnFPEvFrsm3fE4rk76Lfm4vai9XTmJ+RoQH9B5ePj/THuu8WRfnT2DiRUeosUpqVbcOe4keBtAkkq0ko2gzJ++YH8Wf3enD8v31EuZtSwa+xw7RFqAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=Z0WFv+6WQ373ABo/KMOyPZvBrXjCfwOl5DRRrGItHYo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Jyao2nWgTt+1iFmN5tg2YhWwFyqo/CqJrXFkPnYp0t8donaEOnH7TCt/uEtQl2V/xXV0adeAtVf+p9njmmWOjGMWTh3nS5JhxFjjGz9ApQo3LfcYBUueQeP8ATLdSU5+lHM0PndK1oV1LP3uuGrUFgwPbjwFzsmlq+YeDAd3vA4= 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 4D91BC41674; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9P-00000006Omt-3Wit; Sat, 03 Feb 2024 20:18:27 -0500 Message-ID: <20240204011827.696890375@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH 05/23] eventfs: Do ctx->pos update for all iterations in eventfs_iterate() References: <20240204011615.703023949@goodmis.org> 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: 1789929383819750018 X-GMAIL-MSGID: 1789929383819750018 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) --- 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 Sun Feb 4 01:16: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: 196383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147331dyb; Sat, 3 Feb 2024 17:19:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2dhUUVdTKI4cEl+eBMYnTOk5HD1Sc3x01+xoKW34my/ynHlvw4q3BV4sz2SQO6DxLW+lO X-Received: by 2002:a05:6358:d592:b0:176:302b:addf with SMTP id ms18-20020a056358d59200b00176302baddfmr12020037rwb.11.1707009572336; Sat, 03 Feb 2024 17:19:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009572; cv=pass; d=google.com; s=arc-20160816; b=AD8XVetm2YJZadDIs+UykK94A5dFpvTpregRrF4Rvzx9/paHKY2fZE9GJeEaajn8tM 9wcS0v8lj7cZoA1P+uAHqJorJTZ2xGQqiwTFnFbLk/jCQbW5NJky/eAP+TWfBAr2dJ9c dN/OFs8bhOfOAILSu4P3AwRX/XQh4Eeq8tJefZ++sMEeqARinA32716OCioBqDFaED/J D5lZ7FmEIeHyvxOd4d9lkNvtWmEIMwwqTQsaEno5hvpDMNUyF6YmCLP2gXlEnXmPTXCH sLRhoXyQ7ASB0HZJrG2ftXW8k1I5LIUBhJ/CxEFaTXZeFABVH10RrxhflMOuLLwx3jQ/ gAww== 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=+Iu3NRUooZKj5Akt5qgA83cQX3PY7XYlAwqwf6MKS6g=; fh=NmuWRW0uJWdMFnHPoWZRG2qoYr6YlSLpAurTy7sumqw=; b=bizoFkSRW9eOBl+anIsckZ6GySnwr0onLM0HD+UFIeT5jlLXl1F+IuTimC6d7qpqy9 iuI++fjNI0oyNf7tiCt/wDeHNVDyTlIywj4PiJ8xDLg4VP76SnP9YwzlxkpzTMMrvBu0 z5h5vnaPfkV41ERotJkeRCD2mFJvZSOlgHgB8B3tre3z5C7I49Cl8L+feZyJz1IMU6W6 yQcbbYC9ZJNGCYN0ahxmZoe4HXjRpF1Emg/hrvk7Y3AadLZ0BtuvFdQLfeAcqmnF9RVB n+jhYvo36C/XqAzacSmy2hN7l0tl4RTJhxpgr1Ymo0C80mXKC1A+xtbHyotj56lrNeUv RQvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51340-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51340-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWQNaGE0NGVNEnn2Bz6YJTC9nDRUjQwtSqi5s0dFqu9aLNMoycH/L/gcNJ+jJL2UyFY0xH9dGErVH/LC+46gTijySI16g== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g3-20020aa79dc3000000b006e02672acafsi1139780pfq.38.2024.02.03.17.19.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:19:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51340-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-51340-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51340-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 195CC284474 for ; Sun, 4 Feb 2024 01:19:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81ED5BA56; Sun, 4 Feb 2024 01:18:07 +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 A56D51C3D; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=sMixlXe2yy6/Xc+43/lYndK0qyLLttv9e9ty3l/JFj+6E5YenBm3EvQ9dMaeB/rxXoakO6HQ14x/eIrzQFPX3EMzHIUWGA+l0B62n73FZIXMJMdzJ2gMjLUxGSyLif+eEWs2pu7hg+WKOdZFtiVca6ZtbwKGAClyL4OMuaZA3nQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=457Nek55iCxNWFMYlAJ4La72v4encx2620jX8BgfCwU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ppv2WxcK3l39+RjEeJYk6HTCReSJ5sUbPqokwPR8i5c1FCyYMAqvUyRCklXH+sFiYoXJufNMi/yVsgtDnwcdPKe88mBuxwISVd1Q2xaLew5pSSkBjLjI3KB3mOvBOuKJExuKsoijWcy6uBopBf6BSgaS9KgJsfc9kjAVXS9FO0o= 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 60A43C4167E; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006OnN-00lz; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011827.860926069@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH 06/23] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240204011615.703023949@goodmis.org> 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: 1789929268861544812 X-GMAIL-MSGID: 1789929268861544812 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) --- 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 Sun Feb 4 01:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147843dyb; Sat, 3 Feb 2024 17:21:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IGIvv0Y+xGMH10OQQVBKGhuEXOq2V6Fi1zNM19rPU3JPgkXh++WQ78Phhq5+jAyaiFjo/V1 X-Received: by 2002:ae9:f446:0:b0:785:46d6:6453 with SMTP id z6-20020ae9f446000000b0078546d66453mr10369494qkl.32.1707009691805; Sat, 03 Feb 2024 17:21:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009691; cv=pass; d=google.com; s=arc-20160816; b=NxSLDVBQhkRTzrHCDUBaYDBYjhCdyE1QREqvuDTdOkDr7MVtuOiOubQN6t4JU70dXQ E8xMbvmyv53hP90ferF6kQ4B6NrFrFkIsoGnzQKMUtsNZuEZLKyg0C6XZW5Lpw6/A7qx c7STscdOXGfcwC7mX4aGsM4PmfqcA1d5MlzvuS4NpXa3wWluMeuCEp0lUtw2sm/l/iAF /c7PDL5FB4AkfqpTIaFyXpQwjqgivtNgUTM66O+b+0Zw6/LgsK6EVQaboSSlYfhpD9gn 1evIna+769rNS4b8CaydQ+9XF/IKaGsQM9YPvLW3iRqSAhHoB5IkiKUg20NCHsehLm0h BZHA== 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=YwqLk1uJxQv3r8TleNW+O+NucMtqbl56Sd0zNEC5kow=; fh=n5TvF+fAPfBazVDXQeY4dPxUs5foeqokAwVVeXSJFAw=; b=QXQ7U3Q0StRd6pZ49mr7e66KtWfzRhTV7KRDO1ixG3RVd/X6y4z7q0wneu3ZYojvBC 4dlMSm1I9CZQkHZfZ6FGwXUEYxkkTLsqmXOubINzO1AUrohQKO15zZ1vOR9CjJke7w+S gJlqblMIqsyKZ0FondAFV8vJxW1XHv7OTULtQLMBnD3TOmTRWEQiWb6AfonC9OR+q6kB CVV1/zs9woLPZsa6ddfz0b/GWs5/3TAckUfCI3KXfqTew9uI8Fa2qpx8U6FPWFOXLx4w PX55zYqgCRqN4cyShcj7XNeF+RGSpmxeqzk5m/QsUXoFZXgnfG+6xEonOOdLIR0AMR2X mJNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51346-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51346-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXXk4ZkGLzoLP4vv2pQHbmAcL2Zdw0621I72NcZQTkAQMyjojWXagmGFqmKbVmoRoe3V8s3u1s5jFRqx6DcCZi5jJqhiA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id bs30-20020a05620a471e00b0078562086535si2891154qkb.620.2024.02.03.17.21.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:21:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51346-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-51346-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51346-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 97CAF1C21028 for ; Sun, 4 Feb 2024 01:21:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CC6614275; Sun, 4 Feb 2024 01:18:10 +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 01B6E5660; Sun, 4 Feb 2024 01:18:05 +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=1707009486; cv=none; b=XIOFKkvJAJozx0jkBmDoOyq+zdrB0Mkj/M+KS6+uJslKLv/bdbUyFJGEab4hsUqU2CKNtCDiYf/79EXNIUsrzmcKjksYbePHYVbkPrqdyo8rXlpv8sftbsjkKQGTES5CFJRBlzB7wZdGJpUqNfle1j/6Xhar9fx/exD4Fxm6cYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009486; c=relaxed/simple; bh=/JpS99lNgHIlmUQoiQN2u6X1Nyd8YU3yIhcsAIJ1oQc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pyZwXklrAueG4tjuwnfkUCYcnuXU1RV23o2R2fDk8+mpddGSPomXhqXwt9h4M7arnMWcybY3SIHu1BS+suM5ZK9pvk0ddjCF4uQ+ivbD8CheI7DxX1aBCien4k12KSoBpWgLs7TZ3agxzXOvTgarNDm6Wlt18dM6OCsZY/InpvY= 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 8B658C32789; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006Onr-0hp8; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.022360802@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:22 -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 07/23] eventfs: Shortcut eventfs_iterate() by skipping entries already read References: <20240204011615.703023949@goodmis.org> 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: 1789929394743608656 X-GMAIL-MSGID: 1789929394743608656 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) --- 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 Sun Feb 4 01:16:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148450dyb; Sat, 3 Feb 2024 17:23:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5zSnimSePTtMn1hiGkfZhjaZVw57kCkIApowk/R+m8iWdteZ0QquIPOoBh4LOiIoPH4Ke X-Received: by 2002:a17:902:ce8a:b0:1d9:93d2:5208 with SMTP id f10-20020a170902ce8a00b001d993d25208mr2803530plg.49.1707009830522; Sat, 03 Feb 2024 17:23:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009830; cv=pass; d=google.com; s=arc-20160816; b=gXj/mk7ZU6tkXQVRHJJ3H6z64oobGKE/FI6COijtbY/0WuV8RTTuv+nIeg2S1j9jIh 05Pl/tbZmVvNhtqU68qebMih9E7wjL2psM+Z+6dXKxlpcIauYmO5svRZ7NS1iFDTJkf8 Lhiw81jh5NMWqv3Suh6XKwFvM63ddV3NXdUuELOZinzFZ55vH8CkbiEOw167919joHDR PXArm8XuxGPsX8YomS+bcCxSJ2SPcsvvM2LNgkNff+dADQ5Y7lfbGnBq6Dkup1smDtzT O6tRjI3Z/tdxxj7O6TYF2EMD9v8GByEYwp4T707KQf9kskOQGCztESaNXzQYoK4zq4D1 Zwbg== 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=I1A9XLc5OJzUlzQ1jciqsKfoXBmPjrac43W3isgcF3c=; fh=sX2U4fn5nXNdqkLT1dHacTBbKDWCkf/VnF2DbXzJnzU=; b=BxVw5UOl5TTPtStzJqVpxgPGsHgk+xgVO3l3gCbwA/MktDdCoet8UYyXJrDFqHTdjV e2L2EdcbZogpiG3Rx4VGnDVjrvJDYhElfuE1ayBH81Q0mj5r53zms4pINxjZBWDJZbq8 hs97TKnDcwhDQln2sL4ESVrJvCE1n6BigvM9bXn0kPKzzvAoEpyecZQvAAKqQXb5mY/K Wib5eArmbqFwZRjuaOl2d7gt8khl2auGVI9qro0nDHz0bNgTxsvhh+dVINis/dIHqLKf POqZDut4SD3u7g+toQO561mwBAx8AS/AiRGAXnQdtZK+t87pFGlpWn4qXFPafmtoxuNs t6zQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51343-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWFy7yY1DPSww8Wtg0WE1vqKQteRK5lEGJYcfXMNsov73xyh0aEfmm7K/Sc1seDT3vzkxVP4KQEdZqWdoZ9L6QDkZquRA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id j20-20020a170902f25400b001d94544ed1esi3925809plc.410.2024.02.03.17.23.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51343-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-51343-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51343-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 85492B25BFF for ; Sun, 4 Feb 2024 01:21:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D503C13AF0; Sun, 4 Feb 2024 01:18:09 +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 C863915E5D4; Sun, 4 Feb 2024 01:18:05 +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=1707009485; cv=none; b=lqiNP3mVwEcNk4HwjCc9KMb8JlRpDWdgnVLt9qUqh3liyicAov5uZ4rHGkdt/UlUI+QjIHPfkwQMALElAkgc2qqEuVAosLeZzGc1mOC7CFOSc7Iq3SPF+SWhmaQ8TqReM1xfu9cmf6XmntULdFkOoCiEnySJCfncDE6f7W+KpYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=+l/2J1wuNvwwox8H/9diOMBy2Vp1lI/iE/4NnUV0Ybw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RCsmJ5UAXhOWayFjOG/76WbNyPadgsJwsvnIhrCP59RiB/lURfveoncOuZMDO7BYYz0PgDhJVikDpZyudCPS4G6nPvSdmH8CXKEnSHKxSwf+eJ/oBphWhIxVmGV7wjD2S9AmFbh3KmCLBC6Zazz/g6AM9Bkn2HrX3BHcjz2v1n0= 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 A9046C433C7; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006OoL-1NNa; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.189770756@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:23 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 08/23] eventfs: Have the inodes all for files and directories all be the same References: <20240204011615.703023949@goodmis.org> 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: 1789929540439830228 X-GMAIL-MSGID: 1789929540439830228 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) --- 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 Sun Feb 4 01:16:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147918dyb; Sat, 3 Feb 2024 17:21:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdjXf+fpNQczt9CFPxJqJukiRGXgeuqyA5d2ZRlXA8Boq4Xm/9aFB0rFfJYlBdEDQ7NnHy X-Received: by 2002:a05:6358:9999:b0:178:799f:bcea with SMTP id j25-20020a056358999900b00178799fbceamr6655286rwb.7.1707009707520; Sat, 03 Feb 2024 17:21:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009707; cv=pass; d=google.com; s=arc-20160816; b=pBEu7ofVM/EtXYz5mMur0+PLRvQwNOo06QC5m7u06AYrnj7WBQ++vKPMctmbwS30Bm ZId6BgUs6Xvy1sTzGHnDtLpsJFNkl3BpbV1Pp9Yvi7MEe4AvVy7iezQMDEzg8zOuT7IB nn1tLgzGp6Ls3Pokw4JXl6piwK/civyLHlZStR11rgfp+pA5QWIEwhqu4YVafOpvX2lx 4UinItqyIcI8R9/qvm73vhlMvE9i0zPVRroZeKctmK0ab46cRKOLmBYmcBxz1b8iSiMP Fdu5lbwm83cOgvFQDdpDQWN/9CZIOdCgWy09D5BQlAns9znS4TSIwBb1hcuGyagmVMps QBQg== 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=l/2uxjQ+8Z6/39Y2ky//q130sJAaOymcYlpgIthCiUg=; fh=C+95gD1vF6yFX5i9IKrTrhtflwPIKdCckblK16aW8FY=; b=tPeM3ByEAe542og/R9qzBPYYyMhRGip7BBjvHLX7/YZsWJaj3cN2U33VGV9JQEqJzN TpCraxTiotloomcqt4XeXzgZ/aE10OylS+aYADy3BZ1UncWZ8jeXLXG1vzc/Goic4Xcv b44AMn1wD1ikeLKuMKJGGbdUDFpigb5UCZUhbkSJ8mbjOqGC0CucrLDppUSF9lNdjtJY KCUkFbKY6uoEQn/bQWOEhceN1qne0mOXTkLcSUR6liA02JU2IPP7k4dU+AXzV3swnCIm GD8KxGcJ9Ew5kmdRvBMYySCdE0rSrUZS5oeV5bTNIgAHAvINT5xwHN3SQWaX2pSGDwsr f3Vg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51344-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51344-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVaRB6fUNCZSHH/YlunH3sRwLlSmMgQnguUWyTEpQglEUsahqB+Y2JH4Clcz+QNN6W99ZfZ4gOvT6sM5FqnXURFiPoLFA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id kx17-20020a17090b229100b00295d4e9dbf4si2190756pjb.54.2024.02.03.17.21.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:21:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51344-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-51344-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51344-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 43885285A88 for ; Sun, 4 Feb 2024 01:21:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8D59414A94; Sun, 4 Feb 2024 01:18:10 +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 E81E7522E; Sun, 4 Feb 2024 01:18:05 +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=1707009486; cv=none; b=jW+0ClRf9WhnuiiCTOICm8PqE5r+niv+dKq8ViHqY3hK0r9rYZAsVW0TAKjGIXakrw+4z3Oii31D1SMyBRfDsJYYLJeMbpmtRhK4xDwaIzc3wI0HgwOKYnvM2JSmE3Hc9eGdUAq7OKgOggI3KBVdEpQloT1be81ejlGV7xPuN2Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009486; c=relaxed/simple; bh=kdVBorZqhrlAzJnHue7J/bMpS46boW/Qgz6CQs5DZdw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=iMi8ATxgXBkw+R3knOrQoPa761K4FgyqB96l0vmsj7mPalyB9lyn4Y00Rp8hFYbJ7OBD7cQYneYkTbyEZ7mpxtrZ0DmIsO9z7vMQWlTS8Yzs1wWPCf0lp7rQ+/M/zdcKQmtbRt1gOEu54J4RV37uSAW7lNcflS378z36uKOsLK0= 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 CE30EC3278E; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006Oor-23iK; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.349167176@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:24 -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 , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.7][PATCH 09/23] eventfs: Do not create dentries nor inodes in iterate_shared References: <20240204011615.703023949@goodmis.org> 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: 1789929410790985111 X-GMAIL-MSGID: 1789929410790985111 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) --- 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 Sun Feb 4 01:16:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147847dyb; Sat, 3 Feb 2024 17:21:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfRqCHf17u3qbLWX5YTcrYsZ+E2f9IYZlNoeVHYXaRjztAD64Tz72s+zd9lpckHBMCmj/Z X-Received: by 2002:a2e:8518:0:b0:2d0:8b22:a79a with SMTP id j24-20020a2e8518000000b002d08b22a79amr3118660lji.23.1707009692523; Sat, 03 Feb 2024 17:21:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009692; cv=pass; d=google.com; s=arc-20160816; b=d0MeB/W7QzBb4MGg6Yi961wCeR2VAe4SnuW4B53/5QekVLcr5pbIEMqK6Aup+kj50/ jhxRFWk6/TbsDpJJAg6RsVQClGnmjaG+qY7oDKAtDuI1BNh+ZobEJLMvmuPCWzW83CFZ TxqnGFj/AY/ETf+2bIDXQ7WSSWY/SCHD5bqQiPVQrhjZRRH3JgSUyK/juO1nMKQAiYse 7xF5memzsmBzrAp1WZTyVpeGfPRkyOYqXpdqQbP/S7tfUD+8UY4o/oe3Bw2nYtmy4skB bOpJl85WxLHZjy9HbMDlhzB651GrbPZ2YD3jXudyJ7XE0dSQrEf20grDER2IZGd8zkoZ jzFw== 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=GPohKznXU2BNmlCVHYAj4MeIS3nZM5k3Ff/hCqQFXzA=; fh=JWv0HP5E9F6XTEPoiTwCevC6qTdvLCqdxf1Gn7FeNU0=; b=0LpFtK0Qn3gyXxqgmcqjTz8u/SQujJkV08iYKhyb4QV9kw+vsVCcw5UiP/E0nro8yn VyrFSM9mZ7ZlemqxHsgu8CMocD0951/fBUH8VRJ5JpZ6hL7oiykoFDi62PYLDCQkvwt9 9/uWQSONMIzriSfgqepFGnBNzN0bAgQwh/AffvNHf+MXKC+1gN2GCc0qG8U0anYqP0Sc u9nrYIlfRoWKelJYWEk3n1NLwwGp3ycOogMC1bYU8qMTdBg8rog6+4ohcs1TcSBp4dfe /+QT7d+9C0vgn3NRdEZ6OgSe5A4x4J3ct0RmwU5HRL+YNuOEUAZ506aAXf+Nzrlr6rpg Bsyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVHSgdLaU0FFzj6EUFvBBGALoYujYqr/oEoZRvVintLVPeM1MOcdwW+g0AyDC+9+Ne4PVQd5rW/xl2N0/vfx4lrhDFStg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id df23-20020a05640230b700b0056023d8f37dsi953794edb.653.2024.02.03.17.21.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:21:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51345-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51345-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 2298A1F217D7 for ; Sun, 4 Feb 2024 01:21:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3784414273; Sun, 4 Feb 2024 01:18:10 +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 1DD226FB5; Sun, 4 Feb 2024 01:18:06 +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=1707009486; cv=none; b=FMCWZgOz79ZTiH5/hmTapw4Dcyup0xI6XNNxiPlCqq355Dt2c3OkZh+JcAq+KFs1LnyQEKIfwBNcU+/wbRd34yde2bxkriGF4Tk8N2ar7mQPIyTuxf16FfeG8aM4AXZ4T7PLMdx05jV96trUhqV/qvURjeGuzPxGCdnS7yvJ8iE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009486; c=relaxed/simple; bh=GD76TU70lFmz5imut84Og/YwBOUVo8vHQeAC83rp8IM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=WBOoVIfQwaDjVCpet7mz0fKNmYG9ZLleHveUw6zTnrH6Vv8QTNwrWud97dFtPdGgf8oHkRFenaM1s48zSJV4r7Xl1JZ+v+GRGY/Ue1ptwELBD6ny+dqeD6a82cYRzsl/1kNl6kDAVL78oQphoukvBxoy3bHaHrdSZiaEfAWimmA= 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 03F68C433B1; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006OpL-2kK1; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.512011833@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:25 -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 , Erick Archer , "Gustavo A. R. Silva" Subject: [v6.7][PATCH 10/23] eventfs: Use kcalloc() instead of kzalloc() References: <20240204011615.703023949@goodmis.org> 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: 1789929395313724118 X-GMAIL-MSGID: 1789929395313724118 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) --- 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 Sun Feb 4 01:16:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147978dyb; Sat, 3 Feb 2024 17:22:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IHVmAY0cd+qMlgmCPCQ3UW0LqdlXnnKe9Lf4DppT5OHEuAxT6TZDLwTQTkRjh/wNKCKv2xk X-Received: by 2002:a05:6214:410e:b0:68c:8b88:1bfc with SMTP id kc14-20020a056214410e00b0068c8b881bfcmr3666749qvb.52.1707009721980; Sat, 03 Feb 2024 17:22:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009721; cv=pass; d=google.com; s=arc-20160816; b=eMINJwdvP3Vxn9rZjYo4MsF1zCskfPWEA+Kx1gToqLTedTPNvUaLH/slakJ+hckEyb jQD/Yh6yuVmsTHF44kpNkLHBA4qlggVahwEDexV8XoIpBTSzHX6GTSAThTNnzK8Dq6Bm KU1Lty0e+oZVd8avXoXpH/SNqDftqi4Iaof1fF2rZQKjKL7C1D5HFn1J0+WUlfKCw+RM 1qXmagelclPGz3xSuGnuCdbouWGRYnUj7llpASMkKFSsEqyy80LbijyVlSg+RycqqLVo UEgrieR7a0ISkfkwzQjblw0S0JdX9BGmSbi77SKn0JzrH59g9j4S43qF3ZqTvTeHV7DR uyfQ== 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=kwTRVaPFi7jFT7FybTiKSvJzwUhui/eRif8AThJ9z+A=; fh=HwopmI7t+sSdbULx3GT74Kb1Hs5EQ8HiSixt9xqZrHo=; b=JbcW93tKWsHrHAxWhkLvNeFsRXlYD6qaQkn/8JUxg3sRdahY4J29B0lg/R7Bk0neNR k70OxIgdRq0sRkVRrRXpnt5eLnsX5m91FdskN/f+62JOP9Rt6gQb8kl0F32OVDIQz5p2 xgSQP3fzIo7Uw9+BmBHYksVY5U8ZPUm6Bu1f8ZicN5pNTQBDTBOI+IddUrRdfhnfSSY/ xVr4x2vCP0JlhVSYTG3K9v4I0rUk/H/X/NY39szDVb1W7rgXOqKKqOozgpKRzF4GKVcj Bp3Yn55VjZ5cnY3EdYMwotD+f+AnrgdAwbz/HyjuqJrKV5h60MmxGlmHUQ91xjEQM4cS DfUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51348-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51348-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXyGEZ3oOExSHzi9kfD4IpHZ0Wad2/Ry/ezHl7IWC6LBR80UXvUWqKe6GdQW6o2Ey8ecOggv4P6RB34V//047KPBhhu2g== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m2-20020a0cf182000000b0068c7251fe66si5555219qvl.568.2024.02.03.17.22.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:22:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51348-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-51348-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51348-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 C13921C22BC5 for ; Sun, 4 Feb 2024 01:22:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E2CCA168DA; Sun, 4 Feb 2024 01:18:10 +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 4D900AD5C; Sun, 4 Feb 2024 01:18:06 +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=1707009487; cv=none; b=r5WMeHoE0FaqrwEkuRxXlIZBBrEU3ckHD9jtPcF3KEVnOpfBOEvTaR6jfpuGaoYFQNEOccNh/DsO5BVdIiEF6KuKTZO5/KlwwNZB7L/IVlzJ5OR3Ugjl/a2QM7dSpM7yrkGFIK7YE5L6lGQIS0EHvXFSfO2kitC7mxS5ExwR8mg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=B0uV6XWIxjvgJPAviJ7+MRlI7Dxo4ugR+2338kkGDTE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=s7o+5TGkAaVWxegpjAEExBuv1PBICdavY5qyAGR40jGJrJ+mTZj9tFKIoKqbxddIASv8iyk1QYebtkRP0yHKfhzelkZJx+hMNToAvrXtavg15Kgn5OgMsDtGo9YQP06kGiFeE6h/hTvyMv+2xHLo++383NhzYP8bjbws/V3wd/c= 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 2BB3FC4AF69; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006Opr-3R73; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.676131911@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:26 -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 , Geert Uytterhoeven , Geert Uytterhoeven , Kees Cook Subject: [v6.7][PATCH 11/23] eventfs: Save directory inodes in the eventfs_inode structure References: <20240204011615.703023949@goodmis.org> 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: 1789929426537700968 X-GMAIL-MSGID: 1789929426537700968 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 --- 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 Sun Feb 4 01:16:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147986dyb; Sat, 3 Feb 2024 17:22:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHUCrCqTE/imKhpQVRK+9CAc/+2ezEshrtSgwfSbs9KxqK4LWfl2GMfLLqW1QLR+40akvKX X-Received: by 2002:a05:620a:c17:b0:784:af9:6fa9 with SMTP id l23-20020a05620a0c1700b007840af96fa9mr8260700qki.78.1707009723440; Sat, 03 Feb 2024 17:22:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009723; cv=pass; d=google.com; s=arc-20160816; b=lBorJL/bhUtw2kY5OW84Oqoteab3vKl5M7reYAqD5mRpdgd4GptGm+cd7ohd3SqCvc rRZixvEhQBhMpvwkW4UUiFKWMxEJTeWmMh3dQh+uXJSX7qJxKJ2JK1vBg7PxQyMKlwXb HcmmobtIqXe2tF8Sqt7LQ5WSoutEqdWg3PKSX4AkeUCwZPyumDXOG1SR07H8jGpY6Cvg 1GyE5BCJOhh64UH28GHeJavul6uypjCnb8n4Nwf4pkwoYMliFThsJq8bFvsqcuklQli1 FuWkZHFdBDJWrRGw79fvuH6TU+sIHf0Kqg29UvJqJV6SD0W8nubVxj8Q/ROAUorTu9GH BZ4A== 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=Y0oO9OYv4fsUuM0r75f6NybcP+SEzVd4nX4k5C6cREM=; fh=APpePMExRUn7uLVWZW3BwtR9nObY8Cf9bmjDzr2ywBc=; b=tkKXC6X1L+nCQ4gqlXEM0X/uiwEnMvf1awXs8S4ogpcvURfonjuUJezdNUv8xg4s+7 1SKGFYIOlowYyGKKyMHts7RqC2PlPCDXebzR7UtFWRRIwD9O8xRlsQZZI0GgHrEpeK39 a5k6wCe0YJPleAvTQHqmdrk6Udgf0UgpxFIR9QLSR20TJFybVKXpBQJmy7LFZrL4kCFQ Rj9DhGeaQoR9ptmXvxQqao000ECg0Bj8SHRZlDmwBVT3XKirxYI7GgLfZZIlq6budZb2 ykyVF47VYasdrdI6gCevVJYCJ5RdQCBI22IEpJVR78LupI5/gFvyFCxiR2q2ICQDYISp V2OQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51349-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51349-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXKrTy2tjyOOsVPAQb1KgMk2rmECfKdaT5Poo6fWzbhndruxAWrNiLQ4ZODsBJvlrB+Kblza2vf2iwHtuctdNkK8tS1JA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d17-20020a05620a241100b007855ec2861dsi3813993qkn.338.2024.02.03.17.22.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:22:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51349-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-51349-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51349-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 4043E1C229AA for ; Sun, 4 Feb 2024 01:22:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EC4F3168DF; Sun, 4 Feb 2024 01:18:10 +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 4D9CFB651; Sun, 4 Feb 2024 01:18:06 +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=1707009487; cv=none; b=T214Iq8Y8ycUi3nZW4CPehSz+olYrgxiedbl4tEyNVqkHc2fg+DGUGq3g9nWx0RcIcGzqPbrP0mg6/zagaUJ6sMZb2KTwaVzitOoHBrYPkPu2XxFK3qE2HGcWf2vh3zRtPzBk71lJkTOBCM8vN6Oea2wlsZL1cXoXjJCqgC42I8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=RnbwjrjDZZt5dBQ8lSVav9CcZQtdfsC0kXd6oQD/gQw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=DEyjiCbAG8wFfMawl4qqd/UAILFK2WYb9CZoLrvH56Cttg4GmoPYdf/wrzqHC2ZENh9URxK9aDZpvULB1VkjQNMCc5O8kW5tH2dugwV1gklUVsYL6YDaSVSMH2SluQFHD0V8QhtBps4wXIhA6ahLvHvP+qd74Ko0NNhB0ByVDu4= 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 4EE90C3279D; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006OqM-497i; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.840729219@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:27 -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 Subject: [v6.7][PATCH 12/23] tracefs: remove stale update_gid code References: <20240204011615.703023949@goodmis.org> 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: 1789929428142774704 X-GMAIL-MSGID: 1789929428142774704 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) --- 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 Sun Feb 4 01:16:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196391 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147992dyb; Sat, 3 Feb 2024 17:22:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaIGk9YPUAmNIJaBBTCb+1yGR2OGhIZpKOF0mx6WUpnAwUi5rBpCwgnajFqCPEtF+L1Wu4 X-Received: by 2002:a92:ce4f:0:b0:363:c305:1032 with SMTP id a15-20020a92ce4f000000b00363c3051032mr1266796ilr.19.1707009725546; Sat, 03 Feb 2024 17:22:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009725; cv=pass; d=google.com; s=arc-20160816; b=VtfzVYC9+7Sbr3FdoHRNqz8jcdGa3Yf9Cab/E9OJEesjnaV8wpE6t4exNXrv4t1pgA RFosAxC6J3Ca3lYjVYfPG271HHtXuskbAqZOcOQoySgaHrSdGbdN9ubAAtCgskbPN+2I rOUy9ZD4ieFs4TZVheD0uCyz2eGkD+zBsjlosqcQ0SIONffbTKI+u07GBjLPwrmWHS7a m7WkWlBi9E0jB/VL7R9+bvHz7wWqR4NUzHDT55bMNqYd0g1wn0/a2g/Ru1bdZ0JvO3ff bnFA3ulcSQu7uPJ5SCt75FCkHnq5+UmQM1h1QzP8cmxtmbZ5DUnSls9TcypJa7Vphpy+ +vgQ== 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=9a6mlKxBAB+nG1o/FkoaS+LuUNdfuJ0NPVKe/J3/wfQ=; fh=iHEdDgS3o4pcBBJDecpITgeTklN0PS7zqd498i0z4q4=; b=klbKmPePZWhgn+tZZaynNztn+Tkb8sRah5uwDLG/oUcmZwWjRl27tMdSOqgyDuy2VQ UsXlveQYUWdYPY0OLN3fZzaLT7uJ0lZtrKWVXvLCPjM+MBAivs9gcS0nt9i3N2Abdx4u I4bKXrVjpP4pFGq93zQ1/13sk/ZCDHpJh+SdwrcQA9r0047K4ITfs0QfqRK4ozZhSdwN NMJLpwl2raAwN4RVpK0oU0I4tyXAqRD1iGrcuHNwvTwBzmBvWJ6fx/ph3wEoCKKH5CKZ dNgZdfzh38MmAWPZ0p1AK8X5IPhDSoF1cM0B8hisSGxEkYsEXBj3fU6dPaYgZNMJp5c1 opEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51350-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51350-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVTlwyBEvU1lYm28U/Yz4K6SgKFpOUfJLfXmF/tW5U8pM1v31bItRiT7UNc8NtOP+exskHLWHQOPPsg780WCMY6mgsZeg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l19-20020a635b53000000b005d8e38097ffsi3749578pgm.715.2024.02.03.17.22.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:22:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51350-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-51350-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51350-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 50380285BAC for ; Sun, 4 Feb 2024 01:22:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 06D3E171AC; Sun, 4 Feb 2024 01:18:11 +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 4DA1AB654; Sun, 4 Feb 2024 01:18:07 +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=1707009487; cv=none; b=Na4nM/pjeQwVasU9jqD2rinphziaZZ8/Ed+Yia5ChwDZ9u9Yarmz4qs34PNsh6TrDZpVH55FWgt4R4gE6hjr8zRRYxAfHHVRHmVhaHoJkgNGexCqOrCAP/tPl/UlwFPW/iad8ByIXRdYd4vYB91sXXVgG66gaUvs1bSA+9MEjFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=3adZE3XRvsxSdhBsQIqBjy7xLEJW/dok2uD8qBYZMss=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=GInzBFKRQE0+viDe0f/tRVUB9NcdtQpJizeH2zONviJRj1+2feSJZY3NLUfAjVdzAxKQTbePJ3+kLn9hDNMoc6lCaK455mT/QMSsX2wFwWHgf98iIViywwbnO3NCVgjGnAbb7RYxVJ7ARn48YqllFx4/EE7i3UiiQFEmzBTm3sg= 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 7DA0CC4AF75; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9R-00000006Oqs-0cRt; Sat, 03 Feb 2024 20:18:29 -0500 Message-ID: <20240204011829.008666210@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:28 -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 , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.7][PATCH 13/23] tracefs: Zero out the tracefs_inode when allocating it References: <20240204011615.703023949@goodmis.org> 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: 1789929429957581686 X-GMAIL-MSGID: 1789929429957581686 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) --- 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 Sun Feb 4 01:16:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148356dyb; Sat, 3 Feb 2024 17:23:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlAliBKpCh25Jx/XkaHm/Cq8vDNqYudJRy9E/sarLWVynyVdqJARiYOoES6eQWXnoQy8fZ X-Received: by 2002:ac8:5450:0:b0:42b:fcde:1a87 with SMTP id d16-20020ac85450000000b0042bfcde1a87mr2350657qtq.14.1707009811284; Sat, 03 Feb 2024 17:23:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009811; cv=pass; d=google.com; s=arc-20160816; b=h1DlryJeZy5mGPo3kKEP+NWQabt0+p330fVRG4N3Jnay+Qxmi9zu8aCN69Qhs+Olnq LBnBzmRfb3+XsuUtTzzw+n+74yNq8UBQ7a/Nl+rIz0axMJuFLS2+rwFN6Eow6X/vAvt/ s9Z8bh9aNInwK7IKuNZed3UG8ZbeG5rfo/aOBfFZennT661ZRrakU/qDzoCmbEV5Yxny eQwtZ8Be23obCdr10e4Vrcd4ndi1v93IGVKUtnpxDuExo3pmJLJrtqVxVbqC6A4eLYCy mZtudyHTw1bjhWYfZyyqYJ28ukTAQflFtiFHgDTFWNckZfIREd7/OAo+/fOiBrEOMdha EymA== 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=wKE/WufTyap63SfcxU9dPL8mhs39rgxfXyZYuQOvuDU=; fh=MTFDAV2NFOkkAC8aVmF/VtoXV0IT3q49c7Fm7n9koQo=; b=V8Pln5kp706lnnxWeQWGEKDTc7wE3DCP1xtAcWzaVV3mMd7rGgDU2zGYVte4vNnFsG +HMd5U+Kv6/VRWeOhFXzhlYBj6IHWqPUmgSkRs8hB1qM/K+3RRzYxgjLiUr4xzjfXPbc uNAj+BtObphIA2DIcBiBbQltZ8x6iLFdXeivXqsVa2BhEvlDyCHV5ru8/CYDdaqGNnOf cLmGD1yxxYnl9J7NNakr7R/a3MprQ2lcawYfCdaIhXdxHg1Pv4g3xr9c7MLirIS3OY3i TkRbgMVx3t5jGmQ3HHlEARPP6iJW3uNio/7FiF7Cc78zVQP5Ib1s0LQLckKFHNjhqdQU xdNA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51351-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51351-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX9aqr8tfisxbaazH0FNDz8gzEjYsDvkD7BJny7FAcVLxI8sIheCvwkfN3qIwcFrIiOCKXtODqzlLYoIYLy3vJO18eJWA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f3-20020ac859c3000000b0042bf703cfb6si5391217qtf.612.2024.02.03.17.23.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51351-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51351-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51351-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 071981C22C0B for ; Sun, 4 Feb 2024 01:23:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0084818AEE; Sun, 4 Feb 2024 01:18:13 +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 6B4E7EDE; Sun, 4 Feb 2024 01:18:07 +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=1707009487; cv=none; b=Hmo3uCYGpsJoTdV0SPnhHjbnZuJkEGsaoJFRsWQeR47Gm/i4xtLWrOl+B5gn8oRJGBRAQ58MGchp0ohnQVbAnIMiGIYyB2bbg9LV5uOIkr8OFVfHlyyWjWqCcGm8Nt+20hd+PvQ8UUGtVRWcXIJHql1vD4yW/iwAcJYkYHlyRbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=NR3h4mErQ47RHUi+GxBhB9CL/lVTmIE+3l5kJKozkPk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=e6oJYQaQ9xmtD4vudplaefhW2xVtL1cKdNkExEA8Lxd+QPK3Lt93JjLNkeDECGrrSriUYZz1CtWK9MYJos8EHFDF2pmacxe+Lg3nAoQSlVRhbbc7uYfoRasIOU2T6V5DukepcawK3t0AeSsjxXpKQMbYaYEf0RObxNG0YeQSJ1U= 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 CB49CC4AF7E; Sun, 4 Feb 2024 01:18:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9R-00000006Ors-1zJh; Sat, 03 Feb 2024 20:18:29 -0500 Message-ID: <20240204011829.331283280@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:30 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 15/23] tracefs: Avoid using the ei->dentry pointer unnecessarily References: <20240204011615.703023949@goodmis.org> 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: 1789929519613263996 X-GMAIL-MSGID: 1789929519613263996 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) --- 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 Sun Feb 4 01:16:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148505dyb; Sat, 3 Feb 2024 17:24:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IE0x93RNatiHwrqOCy8s70k+K1ewBLHKUOoDai2z3o5HEHPFrHopDDkFwEYOONUXTjmq/hB X-Received: by 2002:a92:dc8f:0:b0:363:bfae:da3a with SMTP id c15-20020a92dc8f000000b00363bfaeda3amr2210243iln.3.1707009843150; Sat, 03 Feb 2024 17:24:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009843; cv=pass; d=google.com; s=arc-20160816; b=IW5B9vIRQl5ex0h+zV5i47AHdHANUSzeCjQJDG61kRy17CIImWw9y7GaWPX+YEid7s FSJu/te8kt5AqjgyaH7+tL+a6l3JC0lUPWNTgtIo3aVvjxerOtCuR8nWHsKziEySJUBj jiNnxtTcUbyLANvKy2NtKwpZ2zYxqwM8bTZ/Oi9JMpkFWQ4Ov8QPTowBPlTOfKQy72LB laTJC7jmZ7C3Cc4P8UaQhcJdSkv66M4JCpkk6nB/JxEXbjCWhdBNvSdH2XCujQsrXeuc /OWDutlJ4Prcg+Z6ds0JFx2OlgUgL6sLWEVuny+QhaaXIkk9GyxyfqpZ8CJT6hGcxs/l SWog== 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=4XkxVuc7TkRtpWqPMO0Yc/aqN2EqMnt8E24nNNyQX0g=; fh=JxFns2wG39coZLaTiA4DJBU15KawTBd0Hyy0Ng6r+sg=; b=JbraM9W3DFzXL5UNe7mdqv3kVBBOirRr0hK4vh6+EHdjlN5Mrryp33NoLGMUEGYg0p 1ZYSLUoaSVYZ2CVOBSGSE6E1zLUmSeAXGuoExrHx1o1CzIh/xivUoo9MyMoePaLDRWgt vR58CyExYTMz63W3IHOwKQrMTDzAH5icm+CSZmTBjgh1KqUhUkHJBVyV2p2fIUbDeAzn 6jDZ2AQdS9HYqQb+Px7xLmd/T4l54WZW8yWncoGV1vMMTBc7R5lIUxd6s18y/s6NkWwB LOdQqHYIGI/p4dTe7O4ckhGMJ1y1+haQhKYrK833ZBCjPZt87c3oNeFsh23yHoGuKB4n 3nUA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51353-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51353-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVVGOl+yHCKO8S4NXFJrPRF2TVjavlDYTgxltOAPyDcryOQ09+/XYLgzwABF3FJ/wgqlLnBvDoCC6URyBOFX0aj7xiV4A== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id v13-20020a63480d000000b005d8bf42e02dsi3871270pga.544.2024.02.03.17.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:24:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51353-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-51353-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51353-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 DFBCC281E80 for ; Sun, 4 Feb 2024 01:24:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A01F199DC; Sun, 4 Feb 2024 01:18:15 +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 E518BC8E0; Sun, 4 Feb 2024 01:18:07 +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=1707009487; cv=none; b=CBXgzIN9R3ZE9ymWusR6tIO+vFfNQ1W62YAA2/rWzZd1F5wa9Dz/v/+KquhyUZ2pLxTZpCH51BwUs+woNEQuNgX8PouwGB2spBiRgkzrugotv6To2JsfWgn9XzOg+GhXEr1LpoiHsHqxgHBrAOnU1WO9pyHz/oTNJVg+r4BftwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=cr+GgZ2Oo7pPysP4OkmIebaGO97qT8YCrojf8D9bds0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=t26JSUmTZFdCTlGxzEQabJhcBhOYqT51Ym73Z21YVSlT5PW3JcPgNgJnPph5WmjhkIbNtSJpoYN+jWDx0fbGeDuz9ZMyeWM/sBQAUtFRzN8l2+RKnZOKpE+r1DkbkPVsFrDTKIWasLWBRZ/zbngqUM4TeeBRO4CzTjnYmV+oqDc= 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 02665C32789; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9R-00000006OsN-2fAl; Sat, 03 Feb 2024 20:18:29 -0500 Message-ID: <20240204011829.495916275@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:31 -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 , Ajay Kaher Subject: [v6.7][PATCH 16/23] tracefs: dentry lookup crapectomy References: <20240204011615.703023949@goodmis.org> 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: 1789929552858606894 X-GMAIL-MSGID: 1789929552858606894 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) --- 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 Sun Feb 4 01:16:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148276dyb; Sat, 3 Feb 2024 17:23:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYwUtKNrHFjM7BYNb8PG5r3rJwPbDECG2K3R13XHxwnXqKZeWiAPjp4H6YDpw2muHFPi4G X-Received: by 2002:a05:622a:268c:b0:42b:ff78:2033 with SMTP id kd12-20020a05622a268c00b0042bff782033mr2576058qtb.56.1707009794370; Sat, 03 Feb 2024 17:23:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009794; cv=pass; d=google.com; s=arc-20160816; b=T998Omdds6salJigoZ0pvnuVuoSDds9nxN1LgkBawYwwCHBrVDpFR4gDhmD/XQa0Gc Pp3ap3cHddWKpfKTtmVzy7i5L9kmWp1eW+TkZXF+oEVmNGqfmLzSNhpqAAzAJ5SED2aU 8tc60SoYVRd0wF/ee79OQK5NT6q+iAj5KpImoUEq2+JIZbiFso/Kbn+ZqMH3NUztrP8Q +C1jKEkpVBaVAzxRpyekI9RftSVznBdR8l8y+uq6Z1gjuX/lMQ3llj8ODqWdv9c5IdKE OHElX5ugtYxavVp/vcMLBQ7Lq2IWppMTr1ibiZpKUyqkMbOHvee+PlPr9yzyAgiPxqMw /SAA== 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=IE+OBaRn2JS7wfyfQbpNdsst8lzA+UlBabjQDbi1O0s=; fh=UUPXfBh3D2C5KJSgaedc/OBvhJpysaplAGuqV+VzIws=; b=htVs9I7XqP1gZnIrBWXdwhm26FhvQdOpRj/SOYARis4SXEpo1hxVyKYh5fdQQx/Huf BWyBohlsIz3FYFvM7roSgwZ/2mmdVSdglHrImK/IKSkYPCOwgtCT8/02iEisknGvelEE 56KsUQoKNWWaLOsXfdymzZwpGd0LSdG/SkC0NHd9txT4P8MAjJeOlVUM89kw4DiKse3D +Zop2ySu4jLCidz9Nmr73TAef0Pd+0GP6BlvYtUgvxfA2m5l6QtyCBwQckw3BqjARwht lG6YYKj/5nr6Pwr4ylxXwUG2KtbMEJjKA8viSVSWNp4WWHKycdxb7Dl10IlPKjB3fDle Hi8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51352-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51352-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCV9k9jYMOeRowE9CDVajMmDsnuab/SLB7SsMQUmi5bP4ZHRPRAwhA7pZ6Z1dCpyUi9fcZiY0bLjj/iSsXfZfQbgxqjqPA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e10-20020a05622a110a00b0042c134e4232si1905811qty.341.2024.02.03.17.23.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51352-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-51352-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51352-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 29C1F1C21082 for ; Sun, 4 Feb 2024 01:23:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BD3E182BB; Sun, 4 Feb 2024 01:18:12 +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 DA4E6C2FE; Sun, 4 Feb 2024 01:18:07 +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=1707009487; cv=none; b=hYoxle+rixhdxqYAtSbL1iQneRPwfoD7CsO7HrS1l+Gl58qINl5on2F65Q8q0PYdqGr2nNSwqMebFK0HAQpzG7/lL/dtk1xHB4JdbHmu3pVNaIRecycgJLUcb3SdtBapLadtLwnpIunsTg6tnO6LpRwpiX3bQvEHI7VEK4sisQE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009487; c=relaxed/simple; bh=6ZjGB20lu+D72LkOxZozH0kq/zHvSI+SlGbD2+KSFzM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=jywflouJluNoBvjaa5btLXQNm+7e3cQHiwbv+EhX8rdJla46pl4MpWj38Fevz4zT148sURU/U083KVs7syZqBbVMWpUN+N9rhH1SpozbWMuewvGpTtuNyz9T6iF9PVILLwBYFW4Pil+bP0dpFwgt1E6XRHDdI2LzBjOYEbMCBnU= 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 1D72DC32788; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9R-00000006Oss-3KkG; Sat, 03 Feb 2024 20:18:29 -0500 Message-ID: <20240204011829.656627126@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:32 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 17/23] eventfs: Remove unused d_parent pointer field References: <20240204011615.703023949@goodmis.org> 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: 1789929502291528225 X-GMAIL-MSGID: 1789929502291528225 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) --- 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 Sun Feb 4 01:16:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148412dyb; Sat, 3 Feb 2024 17:23:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEICfe2JX+zLJbDddbC/BSnmB7Dp9DYB46MiFhAe+PX+Ev8lkXi+tKSNlJQv91XJUv6audW X-Received: by 2002:a05:620a:6012:b0:785:7aa7:cfd6 with SMTP id dw18-20020a05620a601200b007857aa7cfd6mr280927qkb.60.1707009823082; Sat, 03 Feb 2024 17:23:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009823; cv=pass; d=google.com; s=arc-20160816; b=j9jFSTPkM8VUuxd9VGAXn3QJuAnGFNBm1WgrbHBPpv3diLXHehyKykkECnICSNlZQt tHXSQ4htARqhgKTEUTlEci5Xdf12u97BaCt6BcrwmBQrTW9ToyuspVOP0hUjiVI7yMTR Me9Oir6k18uEKhesPK/+M64amdHASZEXKxO++Y1N/MIs6K76Ie+95QjV0HY0K8Y1N1LA FzdeOaE3lunZ0eKur5gPF1XWqFItT5fLDlDWj6n6Lx7CvH7Kxq48ZqcKAET3H1rDQsze D/YZ5jMEvQmMTQqe/AEDhmq7CMhyZnsdGrGLgjCGFBs0pxFxmFJS2iJEkuQwTfTaWFxy p03A== 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=1StJzQdcbFCUjy6KdEzslNkyz9IsDAJM/7sSK4pi1Uo=; fh=TfxHbH7jeIriu8Sf3ZDqwnQn4/HQ0zGZAZ600/6Ef/8=; b=eT7te5c0b40Nr5i6ciSHrlLnHF97/dFGj9A9lyCLve0HoRQzhQkVPC5LhbQjTRaIDj kFpmJdo9ycknMpKSXckJ/emTqfzutNtZ6WmB5QVije9Nb/Gqzh4uBU/FQXdKUMSBqrPz 9IpgnYtBKx4s3PQ2JiYGjjmOLdWjsOS6XwHGaE0QcJMEd6qLWt7Hn8a+udKIiJLt606W V7BC9p60xQwjYetFVJSVUV0JdrnKSnDMO2/6+ffrLU7byhyrRgAgWGLedMWWuMOq0gdK 56q4wekifsA1nY2vpxztNve+T1H0j+oHRgqzDS0eGVhunPErYtfzaHKkzhijy3mY6ocE pEIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51355-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU/Tr1H/k3c7iX3zrIJPX34WRgflMxrNG/17Ys49T5kuqJ1O0GeOSj/qXyh09v1wGd4GcItocZY2+1qq0+jcwo/aipGXA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe18-20020a05620a851200b0078153cbf56fsi5097018qkn.607.2024.02.03.17.23.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51355-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51355-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 DB97C1C22853 for ; Sun, 4 Feb 2024 01:23:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DFEC18E1C; Sun, 4 Feb 2024 01:18:13 +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 EFA63D272; Sun, 4 Feb 2024 01:18:07 +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=1707009488; cv=none; b=HclpD+3YiRZLIyV0EIrYVsqQfcnMu9xsPNPnT1ewBXPRih/5BNkBxZLfTgTXacJj6X7GEofDsZWCpMhEPEmYVcYccKl5mc8knPkwvRM9NKMZES8UpQ7WgRk/OohfIv2GBWC4oaAx6tZDWzuErU1H/O+soxGHjrZ1j/dMGmONkYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=VbPnmr5i8jO9pUVUWfcJV065CxA6MC9e4dU/HikVKBs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=h6jEcHs4sRkmcEmXh7+3S5GatTry1TBNv/xADOmfxQH0Mx4oqUCiY+csF4ai95nouFJHYp5aSXiXq1f2mTsmnyoj5h1E6aU8K+0RXmqIEZE0WXMLd0OLF8ldJTBsdqtNNO6VPUqbsTOrZ5uHHmlsh0b1uFL0ovWGOqc6xcSiHIQ= 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 4C3BCC32785; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9R-00000006OtN-41u8; Sat, 03 Feb 2024 20:18:29 -0500 Message-ID: <20240204011829.816275573@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:33 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 18/23] eventfs: Clean up dentry ops and add revalidate function References: <20240204011615.703023949@goodmis.org> 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: 1789929531888221774 X-GMAIL-MSGID: 1789929531888221774 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) --- 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 Sun Feb 4 01:16:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148498dyb; Sat, 3 Feb 2024 17:24:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IHXQnLXUjsZ8tMn1apn0kpjGiDsEWYegMyH8PORFM4Ey3gxlZ3IotVsECPjY1GA6QevEotl X-Received: by 2002:ac2:5298:0:b0:511:48ff:3a72 with SMTP id q24-20020ac25298000000b0051148ff3a72mr1044994lfm.59.1707009841458; Sat, 03 Feb 2024 17:24:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009841; cv=pass; d=google.com; s=arc-20160816; b=lhxnR03zikqUTcsKVmOHbV/NHXiBx8X+pb3VegY4j9C+DgII41dqpdoOghFJc0o1vj B7vSBa4En8/di+/5Gk9IpqIMbTxQJL2rk0MOOhDwqt2A8dJk4rPsmHIOPPjOE9E8W5zK WBnjtDWD0J+hAbBbMt7S1K6fTZdAj44s2JH89GaWpdWL9ojWetYQheJfnmjt+WHz/sG4 o4wzrIPiECzHPh8nlj08r/M/qtxxf5QdtVHhE1o384oP2geCoC854YeuO9p3jO+9XIqW eT2SgxLB0IE+kMNbHOevRtND86tSQVseR9i9jju57CBQ1pgl6t//2pK+UeADKeCT7PPc W6pg== 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=oFPBEb/dUmEu/q/lkN1kMYnXczPrIpYVoYuX0/gk96U=; fh=hJ8ccmRrsPVgeqYbjPU9bjAb8QP7Cw2KVKvYLBo8KzA=; b=rQAWZ4+6+ajay5UMP/au0R1c2uI5aQK9wTgqqYSSX3Fsd3l3MEMxIlJYjNoJBdXifX 1EI/q1b2l/PDpAkPh6UT1TXj075uZdsCQ/AsDyPChlzFtt/jRINe/qHhoZ/7/tnIINn9 hqKocFdYNlZIr6kpni1/ESCG/AOki2qH/6oKMDuyPgC2Mx5EQywc02OH8a/ylyHlZvhz GbeEg51T7d8k92Lvn5GA5HFTKZR1pQM2k2ZI+yLnN9X0N+j/wPsHmT1Fv9S4xoNGl7+j Nvjy4vV0U7u0tfnUse5iIiKZi0DBcWRtPoBnFLcQGGB3Df0Sj8qnMh7dCu95xVDmri5P VN1g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51354-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX3b9a/HsVYxT4UTFLQa2fSA0FhTsUGWYehPzWnf2Z+Arw79UwxIctv4gMvv2C7aLfXMrQlhJ2ORRm6ZQ0LSxcqzZVJ6A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v8-20020a170906338800b00a2edc907039si2319391eja.496.2024.02.03.17.24.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:24:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51354-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51354-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 DC9421F23CD8 for ; Sun, 4 Feb 2024 01:24:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24577199BA; Sun, 4 Feb 2024 01:18:15 +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 134C1D524; Sun, 4 Feb 2024 01:18:08 +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=1707009488; cv=none; b=ukG1W20v3fjL3nPMGeBhss9wGD9xx1r3FgkEJ6pE+erSTcDTw4Q9V/oGjNiJH3oCe1VL9W7yULEG6KO6EOGK8VX0aLevfSDH8j8iTEUGEqWMfYHsCklagD62hpZJbvTumdtRyD/oT7/pzBENkrBOcbjiSBgR/gCZvFhXTiGdKcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=FQje08LmHM6G8HbOiV3jqPivUqmoI4i3V9I+jN3t5GM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=PzbE98392BMgIGuTlbl4Bw24Pyizhv7DB9cxzRs3IHnWMbx1Hyk1I3Zrx5G8Q18rmdV8CDFMQqP7Ix1/VuAqTgeDTmY8XkDFSNRu/rPtyHV1UWdGKx2i+UoYcNLO9f0AAPBrATaOBIehemdqqKjjNSn9cpPt1aRaOLrmEgaQG7Q= 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 6ABFCC32791; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9S-00000006Ots-0Utg; Sat, 03 Feb 2024 20:18:30 -0500 Message-ID: <20240204011829.982737081@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:34 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 19/23] eventfs: Get rid of dentry pointers without refcounts References: <20240204011615.703023949@goodmis.org> 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: 1789929551544103994 X-GMAIL-MSGID: 1789929551544103994 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) --- 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 Sun Feb 4 01:16:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196396 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148371dyb; Sat, 3 Feb 2024 17:23:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IHj+blfqfMA/GODFZAujy6tFjhKhh4GPWobZLODl+RWwEpVbNLqg5w78curX7V6Z4fqRG8a X-Received: by 2002:a17:90b:387:b0:296:24cf:bae6 with SMTP id ga7-20020a17090b038700b0029624cfbae6mr6086171pjb.27.1707009813725; Sat, 03 Feb 2024 17:23:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009813; cv=pass; d=google.com; s=arc-20160816; b=Ow6L9k2l7YfzApXjXwYv6qOiMo3zRFxfRvi/UQCIpAVbZCP73DKCaMJs74u4PerzMR 5VVqoiQEvAonfBIme2bAHv/nA+OEofXdbnGtGMIgY87Kl0zrLv4EfSGS8nEueqYlFWsK 7+lolUECQg6F+QWhUIIHtazpb3NJgGGS1XZtbYsilvcXLonGG3wmZL6PcNsfN31ijvGm BDlq9eCgTdS5+iT+Kf/gQs0G2lL4I/T7pNseU7PJbh8zuBclWnykKLG2kxsl6Z0pUljX BDVvWm1BnYIXt8QK+EKxRJhxJvcGvPmPuVRWy3Yj6nVGeV6F0oasn270G4CvDapAxSgu uZ4A== 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=Z0tluB0AlM/xl4gpfRjrJde9FCeKqB9q1rVWFbwkCwE=; fh=QqCO9/FAo/k1GcJ6icYnX8tB7usSHothMInOGicCz6o=; b=DoTcRDiIRA4QkuC/eEPJyhznMDed802FcAAXByQRRX4E7YvbCqJ7Z1//RyTU+2Hsm9 ZXW+f8SrMqUfiqheMPbsLthMu0+BZvLCi8dvlBHXWbBRamIqtfT5+juzQXnVxB3efDrc eqq7FFsFCJKCZ1RMz8jLkhl3tvmsBfVpfhN3jNg/5N19fggs50BUB06hqzNLlTev8yOW zekMJFyeXJuyHzT7pwMzf9JPy72fwRGjizkyAvYrTyH82uaFkWHO+R9HT8mCLhfDhRqQ X+I1ThWCZrFegBogf5FKAXwQvpX0klh+tn1HulsRJOc6tlrliV2yqRbx425uoxdrpOMJ URSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51356-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX1+yLDFwu4hqFJZyEhA9JJSbGDEhMkynfrrNf3Mak4kbicN0f3SeC28h12BVpaSfSwA3ugpxR0mTWljKmSXDpfGkYPJQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id kx17-20020a17090b229100b00295d4e9dbf4si2190756pjb.54.2024.02.03.17.23.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51356-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-51356-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51356-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 7EFBC285B61 for ; Sun, 4 Feb 2024 01:23:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1730418C05; Sun, 4 Feb 2024 01:18:13 +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 24B18E57F; Sun, 4 Feb 2024 01:18:08 +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=1707009488; cv=none; b=mUG1d39Zu3n26H1r7R4SRtiYLYkj+8Qseyz8MbftZYLDBasfq0xm0TFHvz/OvYuyKikAv2Gc6uk7r7/tY/Lu//wnNh16x8bb8PK3NlZ5JjuC4nVm+6HtsbPuSLUXAaBTblae2RwHvgNLcZHr7yqiZ7cnQuKDwakAZFKGHHuZO4Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=bzFVFZX6ZxTI6abHrIBPqY91OKE0skzJprX6xWIWAm4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Vpb0npwZ5jFdAdve30voao4s2bGrDIH2VsdcQwmjYKma9L7MzMwzdDOhQ7OGHZHsIDT3ZpjalA8iLppxtOiGYyNffiqkD4qpW3Q/8rrrrLKbZLhiPnlzpMezhsDQwAtK8orjLIWKsf0+x7uVlqEEcmiEZXhCOspiY/1sE/Rsbo0= 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 A3E3FC3278D; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9S-00000006OuN-1E5D; Sat, 03 Feb 2024 20:18:30 -0500 Message-ID: <20240204011830.140246345@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:35 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 20/23] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240204011615.703023949@goodmis.org> 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: 1789929522632022290 X-GMAIL-MSGID: 1789929522632022290 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) --- 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 Sun Feb 4 01:16:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196395 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148370dyb; Sat, 3 Feb 2024 17:23:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGTi3wcVkneDC1IoHKQSiBb1P/cK5BFQT4+2dnzksT/CA1loVsZB8W4EgchbRnrLwiUL9A X-Received: by 2002:a05:6808:118c:b0:3be:2f6e:5a93 with SMTP id j12-20020a056808118c00b003be2f6e5a93mr11064941oil.14.1707009813565; Sat, 03 Feb 2024 17:23:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009813; cv=pass; d=google.com; s=arc-20160816; b=KrG/wIOYU9rdLWoBoZPUY4rHdEh3mzGB1qEW9Zgzy7G4FZ07o+nuYKqnQZT8fAygss HPG8HljWnh1vlypXMsQ8uwatKUACynSudCuDgZ+ZYwRVRvclZh1izG5UD6Eb8UtRUJcK /eP4hNyUq3uoA4y+IyZLDTMkDRJOcE+S5shD5PIO99vO14EvwusmWsuXT2I1ugmUmo+5 Gc4oIcbyFow+9Obje5MM5bZzxcvLr8TMyCVrOmyffZe/JQBJl5wH8dSTidlOR/DfTqhn 5jUfToPk/3SN204EHpAw26DqLoA84AlINYfiGJqT8hxFnTrGs0JVvy97VdGhk6HfxbEG aKuQ== 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=tzkWTNCsTQTwXNr62epHyvoEkAdMMSPbxF+s4xRRn/g=; fh=smh3nPhj+1ACE/S0RaleWW0gJufEBDnXh2ESqzR86bg=; b=jcg0a7DXCR8uc+Z0l7dS3JMf7/tlM0kQH+SZTDafeOzaBn282gMAyMmNbDwH+BotJW GfObAhg+3fu0mX+u5cnmb4UboNdzTPOrDcwu0iH8PUU1pQJczAb5ZyMYRU1u31fgEj2l aX5N+Rel3fuPLt+kWJ6kwAJS4LCPhdHL2NZ5Dzkb6o6ELJFcT5F2R/vB3DwnRUQJVd3U mC7A2csxIG4/W/iLi0YCQUqw6+P5YszGEPypBoEkGX3oZLCyxN9begHZRyxY0sysp24E Y5/980d/h9PNwtIx9awwJ0owG0VG3c19S/Lgi7nB+DLlcgXPsGhggtpjzEV+TlzExxEp fbSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51357-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51357-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCV1ELSjUHIjAwy19KZ/H1l0Zob873XTZx2ORHqlcIUmqI0BDtqGo8U1YUiIo4FgwCJ+butp1qdLPAgwDYohJ9H2E7xDJA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e10-20020a05622a110a00b0042c134e4232si1905811qty.341.2024.02.03.17.23.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51357-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-51357-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51357-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 5A5681C20924 for ; Sun, 4 Feb 2024 01:23:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1549218B14; Sun, 4 Feb 2024 01:18:13 +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 42F5F101FA; Sun, 4 Feb 2024 01:18:08 +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=1707009488; cv=none; b=baHu0vwkzBR0gYKnYacZ96zEsLEe4OXT7d+lchAYJY5421xBTz8XFDTRYaIkrjM7ee3I05x0UE2rCLNbMK8rj9r6kqnQc0qoIjViT/SI6oR92arEvhP5C0F++qXaNO2T9xesV6GwCb1FXUNj4sSifJ5S7R++D3yvDNlpg6bm8/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=1bWv9KlxHQzO4IJ5J8Xlt8xuUk/3QGMai5L7xRHgYPA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=biJZ+0qtNlzu7Y098Z4rxo7BzuoQX8QjlNd9JdvaY/KojfJupkWW24G5k0fDr29v24gIvXqHr43j7EVTN0lD6LY615/vvOjrL/GmDK6HkIV8k6oJdBdJvBOtBXHfjr09ikLVJ4xUZbkBs8SS24Sv5R8G8rgD6gDL6NwfbqmXBP4= 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 C497BC32799; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9S-00000006Our-1vXx; Sat, 03 Feb 2024 20:18:30 -0500 Message-ID: <20240204011830.314244430@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:36 -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 , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.7][PATCH 21/23] eventfs: Restructure eventfs_inode structure to be more condensed References: <20240204011615.703023949@goodmis.org> 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: 1789929522423459512 X-GMAIL-MSGID: 1789929522423459512 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) --- 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 Sun Feb 4 01:16:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp148338dyb; Sat, 3 Feb 2024 17:23:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdAFVVGB77nHK4tsMmXLs4TQJEOgpQEXA7cZC5Jsg2vZNQhhW1Ex4e5OTB6AjipnRj8ln3 X-Received: by 2002:a17:90a:8049:b0:296:4170:aaf8 with SMTP id e9-20020a17090a804900b002964170aaf8mr3534401pjw.18.1707009809149; Sat, 03 Feb 2024 17:23:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009809; cv=pass; d=google.com; s=arc-20160816; b=lut5eTTrxg7HyZwjow+9kdQqKyebfhuLJ2m9yVPf6doZ8m9xInunmzDUKOonCTbsKJ lwEErOxgkz9RKu27lSCkwS+HbqittROqxr7nSdSdtvKOxAt/IslvK/qRtQHD3js8vAbt TOIZk+SAdwxq7ICdB206lmyP59Z9+0RXf7zQrBOUnpw98AoyUE8Yzp0eENkuxnnaP08B EE5hFCtgl3yHzrH+WnLEOtyWrlJg6nECxI++poUKWTk/B9vnvPojcQuWRa/MUEnvIXHJ 0cBz+lgnAD5mDicMerAOApPRmqUkF3YAfTH1yeYOSEJzjcc3H3j230Sp7uDFupQ5LVi7 KGlg== 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=GdTlwYEOaQ93M+seSEUVljEDzKoBPS0AJLTWFZWlso4=; fh=v0elI7fExnC9k8+xun8UV/DEQsMwBUfg/4y5/rn2Cn0=; b=DrsSxvqoHqnMBTuD++y2V2Jq2rcr2VIcD6Trs3EZZ/OL4JZ/QthUvQXJ8gJQAhcgrw TJKrHfEhETAtfz/ckWdTnPB44z1fdwimVri4sYjoInppIASqbyh6GaZCUIQ3zge+DOEk nCB0oiJ6h2kynFesrnWmm/Oe0KHL6UaPMLZzZvNmNhNaKI6iQoMLbKgk0HUT5tLM9+Dc c+FD2MGLnc17YUtQKBuIWiL7WMv0ODIyq8X3LU9tInQw9heV17XbCvzCREjZFPh7X07W VPcjE6mzRYYEx6qkmItWHCR29dzdkFQziciR+c1FBUmUlDzrfMwghmCUrS6oO8I9HrFa Eonw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51358-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51358-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVKm/SGM9/9BId35JEJbcZR16UflKXrXsKTy0CKGe2kS/anC/czpcXZDbJajJMD86z7it6ekJ7YNneBjRuv0KloDOl8Bw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z19-20020a17090ad79300b002909c51fb3csi2232320pju.62.2024.02.03.17.23.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:23:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51358-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-51358-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51358-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 BA7DF282986 for ; Sun, 4 Feb 2024 01:23:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F159418AE0; Sun, 4 Feb 2024 01:18:12 +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 5200B10A25; Sun, 4 Feb 2024 01:18:08 +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=1707009488; cv=none; b=RR89i/l9BtgJrS9raimPAbs2C1DgU4pAqYOsu+4/hS5nRVIflkKYH4vOEAf5zG/IgtZOluC51nX3zknnt+wFjaRrXbtbL5E4ZkXjaMBSv3dZQTxKpMqFIU38T6F45aj3xId4abcsRj8LxR+bZmf907EelX6wDRF3c4Cv1SRFVXU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=c2ljJPiZws6OX2OlljjxZ50rg8MQ1U9fnX0GsF88OI4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=TVNyQHvMqmgO1uK6SMHMhwt7xBWthSBKgO8nM/Zq54OIkDIOPNfsNnMVn2ShIRFpMBjCezCTiu0LbifiqH048yHkau2coiAA/R8XrKHX5ZhI9p+JPi5ThUyH9aAsQdNwpfOdjrQLdzRSWlFadI1qeTRQyIUdo1juTLPGUlEchJU= 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 E5298C43141; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9S-00000006OvN-2bzX; Sat, 03 Feb 2024 20:18:30 -0500 Message-ID: <20240204011830.479095089@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:37 -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 , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.7][PATCH 22/23] eventfs: Remove fsnotify*() functions from lookup() References: <20240204011615.703023949@goodmis.org> 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: 1789929517642421137 X-GMAIL-MSGID: 1789929517642421137 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) --- 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 Sun Feb 4 01:16:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 196402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp149088dyb; Sat, 3 Feb 2024 17:26:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJvaNreuxsT+iGYysABjbEMTiK0S1TI8FsqRTFw3gU0PpEpSxOimkzbz72nqK7nvR9Az1y X-Received: by 2002:a05:6a20:da85:b0:19e:4f07:16c3 with SMTP id iy5-20020a056a20da8500b0019e4f0716c3mr6324431pzb.55.1707009973013; Sat, 03 Feb 2024 17:26:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009973; cv=pass; d=google.com; s=arc-20160816; b=ZdyKFCD/Ei4CFzMT1t6OkEjrlGKgl7uP1dWHQ8oGL2ZZIZJ3BUdK++Nv58+aJ2sWqP u+UkpmIVmYoOddlJwqZH1fS3DaKBZ05yWRD9imJ+yP6RD/fwr3//QaAXAO0y4veUuKQg ryBeEU2wZQ3c+bfVYB5uzxe0pw0bXFAoGWPzGzXS/8KkwdqR62FdY2PRU+MDr+BtrQ7V DhfPPJ5mGJFTtD0QDJNRAvwC3oBrcD366Kgmk/ii3BarFvxymF1w91FSJDCeB1kFKJKU hqf8L9RR+Sm4Zc7jDYfcZKx4oZ292p3AnloOYDqXOHDpMhQHzLbdYi7w1LGDH0wIKxPY Xpeg== 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=4GpbK88Sjv3E086VZC2iFw20VfSgG6CnwKNDusGLVJA=; fh=CR1xVXqqYuEBi23csitwDmJ0qTuToErM+URwkAIfYeg=; b=dkDp1XDILT9KPl50xVIOXmwCFslAyMGXSKqlSqqegS+DZrdelYYnpiw3LkpQacdCAw BGtLBVCW02jqiEYlCNvHaRlYuMR3aZcMeIl37sq5wF1MOXge93cRTzPwHu2/Q+wWuyzI QlFEA1vmiugumbN1Kfph/0lUj9EH7U7Yth1IjRG4f25xCSIsNp5G0Z/qNr5XDC/U/0MZ Arq8JJiOAg+igHE4yzrbIS3UkbtRgAlyF5UVn2pmftVPNbwYBwW2TLSSlAoZau6WejnB EuD1vSasuTQ3G7X0WmkeYNZId7DifWpOjegtKj/gwyopTiNEdLO3FcyhdWWdZZZCceOF g6Ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51359-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51359-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXKlmzQ0hNYbe8ODQLCLd6yTvgO2We65YoafWVFUNamBpBlt8vbgsf9PokRBFF5kS5umwob8/QdJlsAYe+pzC97X+EHhw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id n15-20020aa7984f000000b006de3b4d5865si3756254pfq.157.2024.02.03.17.26.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:26:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51359-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-51359-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51359-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 BE3E7B258C5 for ; Sun, 4 Feb 2024 01:23:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E5AD18C3A; Sun, 4 Feb 2024 01:18:13 +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 6245910A35; Sun, 4 Feb 2024 01:18:08 +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=1707009488; cv=none; b=TnelbHwJLYvabgAKCE2RUzoYslItwg/Kwpwgeqi6obD6Oy40aGqmPcObqGBBMRi9iC3yN2Q1vf4NZJGl9FsDaf0hQNFdkz5qGsiNmZ+6+NLmuB2P2Vi5ElzQHEIbHUcGHPaTy2CU5SrOku4m0Kydc/+F6Ojl63nI51KHHLwFdTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009488; c=relaxed/simple; bh=Dq6x99Zk/Vun27CnDuFYUGrU4i510huChkfoAHC46Jo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=XIYOrdg7xT403U3vVMIvH/0XfsItB+o7SLlhLp2AMzeC13xBtRe5g7J2lAOALrwGwmIofd/LRdZ18o6/IewfVZca4SUymDcaSjq7DANeB8h3URmkLRo+gxJDl/zcqETQ0gtPUb8srilvZ6MfYEkVu2mJIzphw5+D3gaJUlZDRF4= 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 1E319C43601; Sun, 4 Feb 2024 01:18:08 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9S-00000006Ovr-3Hf2; Sat, 03 Feb 2024 20:18:30 -0500 Message-ID: <20240204011830.644439410@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:38 -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 , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.7][PATCH 23/23] eventfs: Keep all directory links at 1 References: <20240204011615.703023949@goodmis.org> 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: 1789929689639206829 X-GMAIL-MSGID: 1789929689639206829 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) --- 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);