From patchwork Fri Feb 2 02:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp164844dyc; Thu, 1 Feb 2024 18:31:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvfd/rmdOEv5ASw7waN3l/+jZdmXePnY+19ks1vx0Bt6XGE+WpuvQcjmwiMnBRruVJ4HLO X-Received: by 2002:a17:906:3094:b0:a36:fa18:ba60 with SMTP id 20-20020a170906309400b00a36fa18ba60mr374598ejv.26.1706841066995; Thu, 01 Feb 2024 18:31:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841066; cv=pass; d=google.com; s=arc-20160816; b=OUmJ7UisNkIiVDD2KGQAzEpYJ0Xs3ZbMZENWkeQGtMh7lPENKMU7/lXVqV5fiPl/CL iQ+Q8le1pmgodncWt5bK6/ObWLlwQMz36z9EM1DEBwe0Q/0g2JpRVn1XhL2ogedYpaXd hQeqfF/nAR4jwVg0JLvtwQX0B0ygNh3aLHh5/dshOsYZtKaOGu/Kd1D+Himb968yvah+ iseAJmyJDkJKXfeZOhEgDGPmaupsglKHAQPGfu1rgX8zNaOpV7S/OTYg08u0xxBULKm1 ht2LmV3JExVoKkkQ22D11V4OTX4LBvrGh5WrNUwk6wrc8TXQ7/y8y0xaP536x6MNmmiB odRA== 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=JRjNVYZl3ghK5UnsgmNByJmHlDz2LQTp1xWPAXXL6BA=; b=lTx0s84evdhlZstqjEqyYyDgy8VVrRBQHyxQYFMxr2iOpBF8vYnBtDftDovWH9dmCV /r28CNagGnlGe1qkelDmWWwzL/mzXJTp9GSD/A83gnbPWUq8oVKtufx8j99LzFTbgKRE DeavwWAKCMEvmpgCwKLc0XAeGZaM2REqZLY6qZeBBX6IZkvsScXH7NuNPVHd7P/SfkRC u4F5n7XEEBxIxB8CtKFSFIux5xq+Veg/g0y+y1WZ86rkbIY8gxWhRODazkddd8nOmJFz qCzIHspXW7fK3JOBPhGbx8vrJwzYtUZTnoTxSuInVyq/Bj+dOj8sAbXxqgbA7naHLvUO pRhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49095-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUvrCRBJyxId0gQyuzmujHjXpdVnTww7/ZvJOyTsuhAeqjXW93BX1/JV3H2BRpsQHVh3DJ5cFxCDf5jhYXLk46o+UAEJA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v10-20020a170906180a00b00a360a6e87e4si367861eje.400.2024.02.01.18.31.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:31:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49095-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-49095-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49095-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 9B5F41F256CC for ; Fri, 2 Feb 2024 02:31:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E758101C1; Fri, 2 Feb 2024 02:30:06 +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 ACBE8BA2C; Fri, 2 Feb 2024 02:30: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=1706841004; cv=none; b=HSYF7+cYrKo4w3n0RthivfVzaJNt2caOc3sB2i6YFjZcA8me2vjVd0BBMj7KzBgY2NMuCs2KWpt7Z9Jr6Pk7PHHQciCxbN01jP4RWQnEBYLPXzA5yJABeVGLMx9iLXtba12SACsJDjLMCrMXExCgJ9lr3o5+bGij6sZpbmBBrT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841004; c=relaxed/simple; bh=3adZE3XRvsxSdhBsQIqBjy7xLEJW/dok2uD8qBYZMss=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=J5pt1w7VAeyOqlSkP+/m+pCL9FNQPkwscLJ5mX3tK3L5SPuul7TyKkuJ+tgGofwHb+Qe9HVaWcXx5PCnx6eVd5lEkYpyX+fhlWdWTZyI9X+M69+aOT7sjjrS1KJSts4PK00k/ZAC2CMn+t2CjU7ah+oWoOCZThE+bWe9kEduC2g= 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 52AEFC433A6; Fri, 2 Feb 2024 02:30:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJu-00000005k6e-1YVm; Thu, 01 Feb 2024 21:30:22 -0500 Message-ID: <20240202023022.238836873@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:01 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , kernel test robot , Linus Torvalds Subject: [for-linus][PATCH 02/13] tracefs: Zero out the tracefs_inode when allocating it References: <20240202022959.515961549@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: 1789752578233025297 X-GMAIL-MSGID: 1789752578233025297 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 Fri Feb 2 02:30:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165002dyc; Thu, 1 Feb 2024 18:31:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEGZuV5gKjuqZtK7BsqKzn5yGg4TBrhn/BiVttb0cG7Z5x3PpCmb0sxZDI5xqNDqv/8b52v X-Received: by 2002:a92:b70b:0:b0:363:a8fc:9a8d with SMTP id k11-20020a92b70b000000b00363a8fc9a8dmr2415729ili.30.1706841089843; Thu, 01 Feb 2024 18:31:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841089; cv=pass; d=google.com; s=arc-20160816; b=ejIxCagfdwjwil5dr5hpIJoZQOMSb39bBjIh6JKBEwAakmR/Rnjh0g1TNIZIQamtdB 4f+j8OuyLM8JncNKVfAn1qb7JPVGdYg3VevHZ8LXyQXr69bR7mIHIk53PUcd4uPUNL+e dHQT7gNbsdQsdWbvo3h/WSr+nD+55Q8xGDMG+Kh4JGrkZaU/xUSnLzrHn1Oi+BSyzNmS ayDh02nGbVSLbHMwpamK5VXfRibw1o55VKvhO0S71u/uXNcBQVHuTwMT24ShrKAzDBJG hdGZrUptuAzJEJsrKnEMT9C7G0VKmP1FZBLcM+JKmWepsA3AVoa1dyV/D0/8zCDoegIY z07g== 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=ZShNmrTTRFnD228HR7YcHUJ6VJrJ3dwDecnB2ebtYXg=; b=X+iv4fMI4FxqH72AyCwrIi9RAR9+3a7A+sR8v/4n0nozJOVPmhwFAyujJPRjyyGCfU iI2grgd4VKHvyVQ/4ztzINba57puSrg4aMkW7iz4wg/9fJvlPzvlF/Pt/H32lAgtktgZ dd678qUsJjqJUS5WY6schBH+kv/sJfef/CfUQPSmJYnEHYm7oKuv6h93RX96lQguUJ5n ZrsEcD0DZCC9OsqfALJPPZTsS/2LNnwlDiwpM1BvqyF8iBRZBn/slOP+ova5BLQrlk0T fcNKG3p1sHaHj+nbCxF5mD8fSj1yad6IsMy89vj0874iMC9sBsNLwD9NdhKmfcV525u6 QCXw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49097-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49097-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWWzxrSKrc/Pf/k2+5h1u/E6hwNLK61Y+HClAS4onG++JPEO0HGxFEhyfZkgJPlgOElaO40O/LxkL+0zrsC7mFkZG5uew== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 19-20020a631953000000b005d79125d04dsi742947pgz.726.2024.02.01.18.31.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:31:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49097-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-49097-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49097-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 8E0FA28A683 for ; Fri, 2 Feb 2024 02:31:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3B5E8168AF; Fri, 2 Feb 2024 02:30: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 1A6B3C8DB; Fri, 2 Feb 2024 02:30: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=1706841005; cv=none; b=m1hjlENu/2p0GcEDCV72iKhx5hx9FbKQPCUFei+dRFflc/BGq4vZxXx/HqxY+TVVnjoUvtEtJi2GmUmDMgn17/W82AKvjQMj1YJ5W29LM7DV6JNmwb1/K93CWOH1fg4J0s/D612kEo/z4gXb1ilxfEQZ4jhPktuzlstbMNTxvWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=NR3h4mErQ47RHUi+GxBhB9CL/lVTmIE+3l5kJKozkPk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rswfJaxezvlxFotSZLfo05E7DWzMaC0Ci4feCCiMQXc9VbfIVVgpIgAdEYKB6IIjyIqJ32izABQGDcjHgsWfPanSM1JFn/Y7cUAKYzvnLFhipUNIIsRZSLYb5uNCE3lS7OH327FxQQFZZQZmB9KaCoWvy8OlzpQRh6djk8IWO94= 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 A9488C43390; Fri, 2 Feb 2024 02:30:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJu-00000005k7c-2tuQ; Thu, 01 Feb 2024 21:30:22 -0500 Message-ID: <20240202023022.554271330@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:03 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , Linus Torvalds Subject: [for-linus][PATCH 04/13] tracefs: Avoid using the ei->dentry pointer unnecessarily References: <20240202022959.515961549@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: 1789752602451483642 X-GMAIL-MSGID: 1789752602451483642 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 Fri Feb 2 02:30:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195540 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165639dyc; Thu, 1 Feb 2024 18:33:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHpI26EKR7Vc1vNDNsWMJLJYupvOeUC5FU7T4sD2sfMkcXCjzoZVpCtznB3hkaEKGILAiIs X-Received: by 2002:a17:906:58f:b0:a36:4908:1dcc with SMTP id 15-20020a170906058f00b00a3649081dccmr533250ejn.29.1706841193051; Thu, 01 Feb 2024 18:33:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841193; cv=pass; d=google.com; s=arc-20160816; b=VMGGjlvKIM4aTWVhcEFQ0I0uwIuxGQsmLE40vc9VW9wpuA36evzJ65GV8u1wvXw3MQ GnnljieUJMabVkj4CoffZ1EUAcU+uHMoLe8bOx+lRpqxVTpzGL2arV/bMCobRs6slMeN lLUYBTRHKW4XY7V9KDuckzsdtaP/ML5ysm8tmlYXh5KCP9SbFb186UVde6JrK5eWpvYk rz7m7ZVV1AngPc2MDlKqR/qKf7trk8Xi/iJrt6IZzoTrYQ8qF7IFhnVbtogjdOPAg/yX B5/cq4Q/nGZN4ZCsocAqck9MVngJp0bvZUpAjz9nb3w5NKeE/qITWFprnkXyk/S3VXlk Rutg== 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=t0+EVeJC8+aUlO5JSFKqkfWJllQ2EJT+YjLZOdeu4JQ=; b=PnjxuiA9TpsPa3pDFLwtO7L4dGfv1+fW6S+SrzafvnM6JZI3fUOwEgC6qbH9NtH5GC w2uOGo9zRrMmZSisXkWjXVlHVcTUs7CwyuGCHB8RYx524sC+jISJ06ZFHQ5C39RkyHRD 6eCkT5bEltQQWH8ylwNYNnWT0mMxf1cfNHq+D8L4c9YtPAM29YdYMPot/k5NDcpkwUY4 7HsdC4xo3GvwNfmvdx3lxyuyiVBI6O59zvZROYjHnO87MFOxKlMxwPVa+RVbpAobNIr+ FH5Yq8zH2tczIwfu2xH09c/bLZtUpJv+lZ0lAS1tgkb+VAvDnubTt7DRoJH/Z/nMXX8z 48jw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49099-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49099-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWBcb/f4GHS1B1UNJ7K2jkwDlinhVUlVtSs6u2ebWq/auyLeJYpvo8r1GsBnqDH8yI3JPEAXbq2evAsFyCMHWPrS6UhGw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id e19-20020a170906375300b00a35c634880esi351985ejc.344.2024.02.01.18.33.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:33:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49099-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-49099-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49099-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 7AD851F235F4 for ; Fri, 2 Feb 2024 02:33:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1732171A5; Fri, 2 Feb 2024 02:30: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 684DFE541; Fri, 2 Feb 2024 02:30: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=1706841005; cv=none; b=cRFGGlDvGs0c7UkeR75eTpuYMoWwXhTh5U8DpenDUFGz4yi2PBv41FuJcnAF0sbOFZZMZwz9Zb68s4ZNcVT5WWzsTviUfqyRRk4uNfv2fM9nCCtzVQl7h6RSOJI5Pa8QWTtcbxqzwkuAlyR72ZrS1vSlkBk6iNXxshEwoVNec9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=cr+GgZ2Oo7pPysP4OkmIebaGO97qT8YCrojf8D9bds0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=e5KB2IUeuSgcnQglpYAF+IGv4Pcd+6sndUEMcNxnpHCe/mMQlLUdsbYupElud7bm9pvXGRHP6jFHx9rhX+k7D7nHOsSf0HC9X243Gap5hsgsDp2vHP7JG9b873XHKhh0bCcZOzNSl+vRlULyXs1lpnW/Tml5ScpSNiT88+R/Ixo= 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 C1036C433F1; Fri, 2 Feb 2024 02:30:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJu-00000005k86-3Y4P; Thu, 01 Feb 2024 21:30:22 -0500 Message-ID: <20240202023022.712421755@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:04 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Al Viro , Christian Brauner , Greg Kroah-Hartman , Ajay Kaher , Linus Torvalds Subject: [for-linus][PATCH 05/13] tracefs: dentry lookup crapectomy References: <20240202022959.515961549@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: 1789752711263637819 X-GMAIL-MSGID: 1789752711263637819 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 Fri Feb 2 02:30:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165427dyc; Thu, 1 Feb 2024 18:32:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IE5cBb8Aa0SJ8M57vi1AmGr8ywL0ETsqAePveEQpuYBU93oYzfNnZWRgMozQEbaBIKEKDeS X-Received: by 2002:a17:906:1355:b0:a36:459:51fd with SMTP id x21-20020a170906135500b00a36045951fdmr547705ejb.69.1706841156188; Thu, 01 Feb 2024 18:32:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841156; cv=pass; d=google.com; s=arc-20160816; b=Enn/zOI73bmnulK+BPajltYEV44QO/x5OwEaN/RXq4M6JqDwQvBL6HwH5weEoww1hZ TY8ppeoeUB9E85eXAptqMKZ7OlRen1pVJ705hsVa5Nx3bGQ0GJiFk7ot+B91dQmGmgBj o7ZLB3xXmSrB3MJzdlEU/iUK39sseiEg59hiUDoSgTVRYpUuj2TtypY6b5tF13twuUbW Y1wqGUBzXJTwB+3J08zjrmkqPnwvXshksSbfyz3q6kqiOCn8BqM4VtSiVCLUXpqaWY6n vTYdh03wPJJZbzBbYFrfpl74kyw369pWaS7yLAdyz96dmwwGlblV2FR4ggFj/1l+QEIv udKA== 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=JfNPPKjFOyd7HwLDhh4hreDzawWhjlCOEnp7c3TSB2M=; b=ZYN24bAHYEBQuuKJMALWfB420qLNfZQlB8C64kQBODGyvlLq/pF1M+6BAuhhyzFzbL arWeltgvUPhGe870nR8lmXRBJ3/tHbC3GDw9cGbwI/MKz5igYWMxh7CW6CIWCorCPie1 F2G0OTnMC6IHvARHeepp0wmIg7g32s0j9w2B6QzStRCEWOTPucepFc8N2wmFXv/P7h1N X6cNK1VQPtGgo6f8ZN9RDv04wMA+5KOnZf+BR1lEKNOnflnqbdrPFsWHWTd/2bu6KN9E jtK7/pN0O02TbnH8U816kgxKlhmRvdQRXRtUIsItjaqMWBNOFWzPXyGZy+7rZ0iukqQd LuUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49100-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49100-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVh3K6p17h2j/ckGGOqnXdg/xPGlELoautFxZG5epg2I6bEL65+3emtpsb1NJBzDsUBCZGVTcnDr4B05L3HTwKy2301ow== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qw22-20020a170906fcb600b00a28f4f98d3bsi361089ejb.717.2024.02.01.18.32.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49100-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-49100-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49100-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 C80331F22AF9 for ; Fri, 2 Feb 2024 02:32:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 345981799F; Fri, 2 Feb 2024 02:30: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 78629E563; Fri, 2 Feb 2024 02:30: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=1706841005; cv=none; b=sgZ9Y854jx6Jt2l5Cvq9kFg4PAID18wiL7zj6UmraHHllPG82yEeXYSMHkFPuDmwkBBFvqqkZikxUQP3tRYLNjWiMFAiaXD43A1QMn3WvVHliotUXM2Xpn4sZTL1e1PPoyzAVPjSZllfVtljWx4P2wrC0cCieksQKELwXIyk9/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=6ZjGB20lu+D72LkOxZozH0kq/zHvSI+SlGbD2+KSFzM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sRy8CM92HTBBpn1/UlaZfViI9FkVjXKTv4K5aU3SYL+hu8jhSOef4wU2OagVdEXp6SZDHaUV9nVvvHFd3wWw5x3AebHfolugkcsZPgYxNup6dWvv92IylLZ3x/y5QfeW/SSt/HnKcUCw5uG5oPzrt8b6prgd+8LKDHhbgaWPaNM= 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 017A2C43143; Fri, 2 Feb 2024 02:30:04 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005k8a-01rm; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023022.865893901@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:05 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , Linus Torvalds Subject: [for-linus][PATCH 06/13] eventfs: Remove unused d_parent pointer field References: <20240202022959.515961549@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: 1789752672489207277 X-GMAIL-MSGID: 1789752672489207277 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 Fri Feb 2 02:30:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165489dyc; Thu, 1 Feb 2024 18:32:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUaR68ssMXdxwx/KdOnWS4hwYiQxB1EtNemPkFdlxLIa8soGywSKCheEqFlgsfwJF53ulo X-Received: by 2002:a05:620a:4629:b0:783:7a44:3787 with SMTP id br41-20020a05620a462900b007837a443787mr1429182qkb.15.1706841164273; Thu, 01 Feb 2024 18:32:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841164; cv=pass; d=google.com; s=arc-20160816; b=ie5G0DNfgzX3jghzjitADzdby1kgN6P2annBGIdDYLj9bROs/58P0/Gqd66u5mq3RX +5C6jTS12m01jl3MuU6FBHWJZr5xJFes0VGBlUtnbbiJFSnZDDCj4/2pISx+FMnYuIfJ kI88+nv+wEdOROZw2y1QmyRuMQR6pzjvD06FuleUeqWryWU82BghjkhzFaf/4Lpd2QZx 8DAX/7iLLyZSrkk0nHaNRkaLdbTmeH1TBBc2ss/wGrBPJ/SECL/VgupUU2pXSUB/IqLo 9zmRO4CGz1hYHmz8gyQz0tmZXUJnyVBKvGntvAnBHbV3e00T8fJPlMBmbYPVJsJoZPgR lNOw== 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=eqZCkaObjF44xMz8fOKl9vYFj3+ypL/RQhNc+mUV8P8=; b=YJTaUiz+7Mwf1xul+nmH+NDoncTN26wehv5BYVMK3IFnY4jKDxnliU6dzVKy1ItSXk KwfZlQxleu+fYfNfLUPPYV4boaftE8R59DlUoYFNA6ShnOnLj2mcI1EmUc4ezVz64878 iuFK7ieIVM9Eanv68lQrvRm980noa5psY5uHwwM8tEY0S5tpfHoCbBKgx49DwIc8dphF 5sSyW0O99FQVUcavpFIwtlN888IxUckjQ3EQrP4Oldqy93HIuV36wF5pEq/opR9QFbMc Hv3EEBgullyC4d3N32np33EaXJqND62zKR8SLR4BjhBh4sHMFgU5P2HUdWry2quiUXCQ u95g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49098-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49098-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVn7su4LP4JV+daQMChVDrHxJ8xhDA9Es4tRILCc/qnnULtSqcUBdMLBdrMYKohVl175DkEmqYUR5K2v4LSt4ocSg2/TQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id b8-20020a05620a04e800b007840449a485si1005749qkh.234.2024.02.01.18.32.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49098-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-49098-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49098-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 139861C2327E for ; Fri, 2 Feb 2024 02:32:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6ED1017BA8; Fri, 2 Feb 2024 02:30: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 3EB82D30E; Fri, 2 Feb 2024 02:30: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=1706841005; cv=none; b=fmc76MBLtwFS24uDs7Jh34kOzj3hLnoX3GFZWNDGGWHB/L1jSx8KNDO3ltdlxG3G9Aq06SqwrDn2C/goRFD2Yf3Y4EcFF2AKa8XKI3Pwmw5nmXCp9rsrNmRY3BymtaOleinbIyt4Kbwc/klB0gY+NR/tss7a0ohudyk2GbfjcZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=VbPnmr5i8jO9pUVUWfcJV065CxA6MC9e4dU/HikVKBs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=uId2wm7LgiRAmli/Uc5UAJCbX9f0cqaK5jyy2dfOJ1lLAwoiFl706itrtR4GOpvd6RBBGoQ36MoOe1NwuKQLW4gKAbLLegtQkuxTh3rm9v3Kwcyrgis6Bsee6HsWfbK+8Pxl4hQeaVY4PDbmJbFByG5FNNOETUbJYECENo2O0RI= 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 27C26C41612; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005k94-0huT; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.027918668@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:06 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , Linus Torvalds Subject: [for-linus][PATCH 07/13] eventfs: Clean up dentry ops and add revalidate function References: <20240202022959.515961549@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: 1789752680583017344 X-GMAIL-MSGID: 1789752680583017344 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 Fri Feb 2 02:30:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165626dyc; Thu, 1 Feb 2024 18:33:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFnD0n2cNjo89XpUoDOK/CJxrdKvyjDgDaEQ84UvY3Er2BFpF931pmmOGIu2P7Q5YRTCJn X-Received: by 2002:a05:651c:454:b0:2cf:1395:5d69 with SMTP id g20-20020a05651c045400b002cf13955d69mr298946ljg.52.1706841190860; Thu, 01 Feb 2024 18:33:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841190; cv=pass; d=google.com; s=arc-20160816; b=qKpgOJ3vvXuLPov4ac7bCcUsbUnO1aYFQ6+i0gwIWDDADd6uUJ7SreRFuWOlVYkmCW WkX3DEyZA4oUVLKDutx1GaDCqgcOp05uLclchBsTQOpA2n5U7zjyvCRw4TIm7izuXXqr 6xVB3VhGueZYgdIh7493dMMAh0iDcIwmgFKDDV9FC7i6Y0ShwCCp5s/phNpja6T7UX2Y 4KSZfj/HLIsP3Gf8VC0pYDwV6wCTSBqObGsliyVD6ye2A3Jobj6TCDZuQCDwI+cYK4+y J5bxHN9PEyK/LnGFEyuCyOsvmlgDa9FwIFDyzUFCI7gR0dgeIFCusqcEXjxXmCpN6b1s m96g== 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=hNMpIGSHRXpK/DK7jgpwaN1/FsV7w9AzZcVP8u9yHLE=; b=RGpQxpz6rPVAwusJWv+QcmR3Q+a1ETsPKdMXH5efLlvIfWPf8J/bHGpFY+1jycNehK l1NLFHoETKo78+IL4xxnek0rCOBrJrIZIOJt/blnG34YYyUW+eisVszNbyn/LsVMyvwZ /LAJLnpFKl3N83ahxpGEYiepa9FnvivWrwuQhkT1Lj3G9WEDmayHBSdYhZgkn0NXvYIp lmHTtMANYFhjjuaeXYe1+amChV3SNVzm8zflKLeYniV7xq+GHZLX7WG6BQ+YrJD+XRMX OECHuT1AIn0PkAJOPIvtiyNjSIyyEIbSHRbNewQWJVTEQzr0T95JWGB//NFTlN6n3kwv YgyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49102-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49102-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXt0NV2gwDd+np5P+zI5wdf+v5/IgnLTr9jY6TjsM+rFSJqdlH/dQwfEbZj+1k8BrenHGoERGz1K647k0/nQs5InZ/VDA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d10-20020a056402516a00b0055f870fd0dbsi381208ede.511.2024.02.01.18.33.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:33:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49102-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-49102-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49102-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 4B9661F23ABF for ; Fri, 2 Feb 2024 02:33:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5216917C72; Fri, 2 Feb 2024 02:30: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 978B2EAE7; Fri, 2 Feb 2024 02:30: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=1706841005; cv=none; b=AVieF4CRk5GLudXD8uVzX/AIL3fNXjmDfKw825Z1k/1RrBIgvVVS5AGkh/a5rMXoddmdWTg/fW2Cv4iPm2JMOf3drISVOhfIl+Cx68QyXi/ed98jh4aPtMKDYyMM4ttf1jJ1qAT2h2SANbCJ1Dxnl9dyEqC9w5o1FRIq1PP6PO8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=FQje08LmHM6G8HbOiV3jqPivUqmoI4i3V9I+jN3t5GM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rYjV4Qgxl+B3VhnIEajVMVNx0PMXfB3c5S583AnkkEUthWPaEyTziiBQfYAM9xq3naijwfRnZA/HK1jjBNXZTQCwmneXjzWhWAo/8BjtadjujNVBSU7tEnEb7qfPT6ic315vmiFyeW/tVafCq9B+miZQLaUzsvwrKsm+nfFM9/k= 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 4EC87C32786; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005k9Z-1Nxm; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.189067454@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:07 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Christian Brauner , Al Viro , Ajay Kaher , Greg Kroah-Hartman , Linus Torvalds Subject: [for-linus][PATCH 08/13] eventfs: Get rid of dentry pointers without refcounts References: <20240202022959.515961549@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: 1789752708459941421 X-GMAIL-MSGID: 1789752708459941421 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 Fri Feb 2 02:30:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165444dyc; Thu, 1 Feb 2024 18:32:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjTeLF4h0mEtg8iJ8RHurszDUWnq2Fxf5ZNSGYBtIdLVfWbDTQOO/7vtrG4SEik2E+921+ X-Received: by 2002:a05:620a:108d:b0:783:9953:a02d with SMTP id g13-20020a05620a108d00b007839953a02dmr4448391qkk.66.1706841158766; Thu, 01 Feb 2024 18:32:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841158; cv=pass; d=google.com; s=arc-20160816; b=HD5IvZBX1Pa8ECBwxPlFzUQcCOgyZHrqjUy9n21iZmrjsGVSY2Ho2hBmgiVjZx6DGU 4VOSzWnAWZ2yoErNdFL0LhvSx/ES1thgOoAdMsyAhr4cIn4OyglulcDf3qX8hpb2IAtu n78eujWz2j8ASq9DGbFbquTlARSFBmuzljse3w/5oBXzT4MRmaydMU66Q3DAONbq1c1s VZD+/sL84voJsX6yU0IkVTW+3LXaT9WET3vHB7MGEzfauRncVqd8oOgk33RlGq/rrnUg c6YDZz2J9YPdkmoARZxOuDxUrz8oI5VTW/Emb+Qc93WHSDX9edFo3zv091svcK8IatJ6 hSlg== 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=rtZjtFaYQxdbKNGGEEinbFN52McDsC+54nNuVZhNUWQ=; b=pPqrKhVUVWG2GkYq05BWHsjtalhOgjRRQBAkmDLxwjVqh6PwWWF82Ci1ZUvCxdUxqx /yE6Rvf5t8FUKHgs7dOKqQaQf4hiPTepJ90J8fRcBRa6axpU/IFLOojG6yp6DVXkjz6o ju3zGOrG8j4PN0dfWRm/7T5qTE8U8RpsQ6K9oFW5R4uXh6UsUikIA/QHz03usmyoPhfQ mwwdcnSlfTu+gSgRn7UnrgqJOxgyM8SZUOdoOgmZlH8ie4MCjznxHAwBfWxTrp92W5SZ N6JuF8gqJ6tWaFw9IZ52k6UTTrFPsupUWErLGiAHaKY3lsiRADK0RnjgARI5x3GELD3i 2u/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWBtKK/2zR4LqqCGYmJmILplbQxbCHP3yqiR2rUWjLkm3OKRKx1Wwqstr2qGRdoz3OQHMa8Xfa0Yw7fOznuxJeP+YuvDw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe18-20020a05620a851200b00785466d67ecsi978491qkn.66.2024.02.01.18.32.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49103-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-49103-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49103-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 8D52D1C23865 for ; Fri, 2 Feb 2024 02:32:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E206179B0; Fri, 2 Feb 2024 02:30: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 A3719EAFB for ; Fri, 2 Feb 2024 02:30: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=1706841005; cv=none; b=bhgowyBESenmgL4XlXCD+Jbea/pnTBTQDjwbalAqlIVN6XIJWmO99gVD8tS9f5sq5tl/Wa/HhHntwXK53VzK8AhnKTot8cqDuaZwANvEjCLD5h8vO7CLisvdNQuIHuXWbWXMFJ6KuOnvdjELJtQDeiutqO+L4Tz73zKVtv4w9j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=bzFVFZX6ZxTI6abHrIBPqY91OKE0skzJprX6xWIWAm4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UE5OrY9dgpRb9mdx61g19Y/NjqWQJRXz2iIMItkhdj4qU9DRouqEx7SdUYqSsT/URFOAE/1jf59N0xObuIiwAhqbkEja6U2uurUEiHg3jSn8qf1bCmAkap4RDGLBjBO+NaisYwv95dELm7Mi9Clv3A/Jh1VaoB0vx8dB4bRnWLo= 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 84E8DC43601; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005kAa-2jFi; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.512233945@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:09 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Christian Brauner , Al Viro , Ajay Kaher Subject: [for-linus][PATCH 10/13] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240202022959.515961549@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: 1789752674916236777 X-GMAIL-MSGID: 1789752674916236777 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 Fri Feb 2 02:30:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165497dyc; Thu, 1 Feb 2024 18:32:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IFD9vavKPEe4iUk8wOwi1UvSFegyKusyEEn+0SI7Prt961wVqb55mO6s3rxMIFeTixQSjWA X-Received: by 2002:ac8:120c:0:b0:42c:524:ef2b with SMTP id x12-20020ac8120c000000b0042c0524ef2bmr9646qti.8.1706841166167; Thu, 01 Feb 2024 18:32:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841166; cv=pass; d=google.com; s=arc-20160816; b=Ajt4FHsZCKsl3LNo2mY2YtkxUsVQSBWCrj1q5p3KRjVXq2sTuG4EWPGtSjGH5j4jm6 3SPHg/zGp+fTp91GsPBRTZVwzqfbBrVPv2C22D4xoF4t3/boy2H7ZN5D/q6Io5g83ikA dZ1KAfZ5eqtcQwJGZ5Rq3xaYcou+kianpX14J1ixNEMtZvFghrioW803RyhaFNIIGzvU M7xaw/xhUVC7NPuKBRU8lV8Y8flnzOP4ntBBa+PYy99dL8AzjkJlhsQ0L+3sHnlKLG2v mVPTp5fyr4C4Av+uEoXv10OeuasywoI93h081P+/KFfn9NRSq4Lz2QGAK6QzPh1Qb21h aADw== 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=BlH24Hp+wE3pJTepBos8dWfi0DYhq58IiyfO/lVjDDY=; b=02V9b1VJSZHrPtxfYB0q5HP2KI+FzQRxjH+SKqfaefuCkcmFgnKwgbfUBxp93ZHmGo gTpP3HcEtj1HAcpyaf3tExnacXHF/ABjkK4WdKXNRnTADBuHomlnFJRZoUXT9OSW0FdK gTd45DR0fYtlZ/luW6HkWvRLyM+WEXVw8O9nrBLP7fnXcqgSfga4mnQC9oNpsL3ueJF+ w1OB5IuFR5TMWYz5dvopufwXDIGxC2rO+em8yQkweMhrHxt0+9IbGrkOE5c54tHr+8nI fQuGYFCnNApVEdW0RQN41ATMLPZwR9B7+d/rUeIvwCtlZJoKnSsb8r2h3//mzzGXSd2k 1MNQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49104-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49104-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXZFNRITtCtceP1dMb9gawyEl5nwDjGKKgfkcuqKzdfADS/To/REOX6VSs10CyeRcjJYNdbPtxWecs4A30zPnhlMNGYmw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u2-20020a05622a010200b0042bf207ab08si952903qtw.436.2024.02.01.18.32.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49104-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-49104-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49104-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 EFA401C240AB for ; Fri, 2 Feb 2024 02:32:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 77B7717BAC; Fri, 2 Feb 2024 02:30: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 2ECE5F9E2 for ; Fri, 2 Feb 2024 02:30: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=1706841006; cv=none; b=bkoC6jHtMXhklHv2UU4SCbP0gogN8aQW11xocR0gP43PB3lZ97OK43CAQ+wWCjLmJr6H9rhNHnQt0pHXsRjYaU/2NRvgH+VZQNimfL9y8O4VKW6MtnTG2GghGvq6GA+d1YMCm0nMt94bY602nXpPvDH3E/eqpF1vuAYyaXJzzTs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841006; c=relaxed/simple; bh=1bWv9KlxHQzO4IJ5J8Xlt8xuUk/3QGMai5L7xRHgYPA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hhB5Ton2OINDYq46qwVKd0xy5LkX+WUeGMOkHWYIJuGVGVmjZgdtkZ/VY5kzWOzmq0P0Kz0Z1zqmnCJ9TBHxzfc8UTM3idTUExNd+3vTp7Mth2t8adyONGlIBuC9wlATqRynglyjVpCeIcA/KSXlaIt6u8seTCROnPjYIbWYjHQ= 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 BF115C4AF6A; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005kB4-3PGd; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.672365977@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:10 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Christian Brauner , Al Viro , Ajay Kaher Subject: [for-linus][PATCH 11/13] eventfs: Restructure eventfs_inode structure to be more condensed References: <20240202022959.515961549@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: 1789752682339128932 X-GMAIL-MSGID: 1789752682339128932 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 Fri Feb 2 02:30:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165447dyc; Thu, 1 Feb 2024 18:32:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFREVvusoRq5Xo5HOisFef3A7yU4YKz9rG5QZlj+7V3Pk0K29RVbiSf6kzSVVkT3n72d13j X-Received: by 2002:ac5:c0c3:0:b0:4c0:d4a:33a with SMTP id b3-20020ac5c0c3000000b004c00d4a033amr461473vkk.9.1706841159235; Thu, 01 Feb 2024 18:32:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841159; cv=pass; d=google.com; s=arc-20160816; b=Nh9Gm/TuGxKy9DRrxJo8w7f5beLTW5rFzMpnL/Ed6P4OM9eBYXLXvSWWUsmzhvqIsO 7nf/eAUYblZ/VmRVVkDBVoHx5AE7aZq4zL6BLiqXP569+VpjKBagZgEhi+HvVAmkMpv4 i+8MqF6jz2iHbAj+swFhPZKEmd1K2ozv1dtMHX7oZs6uNUl+ih9QoOJRB7aev/Cygvb4 Malkdkaz0FrOeRUCm6zfq334su2+qvpAizAyWBaQ2yG/tJ4smyR9frqQRYW9rs6q7e2H QAqGIdqSp5ZGilm0geg8NPVgbIHVrA7H3J4lZmkoFUYXhV4iynUPRLztIWds1VKeU1bK Kzhg== 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=C9iCRcWmW9oCmT4LWAk7N9FJ418dLbotyx5fieYfaVg=; b=zbJg5rxge8IyP2UVyl0HaqANgyxE+K06ISwh98eDdYEqpLnYG0dzTgV1IL3hDStbc9 sxdzhat+i2cuDSwsF/TGsCsYN+vsASA7lSNurllm6bWUftZvy0yweZSI6E58Jih0jo3U 5t0PYvLQGEFwSTMjyZN1+Wgf2A9lGnvTag84UptWbQF1f2snDZ8/HEnH4qYoiEQ4HRbs DxKFjzzB4W++ydce4oi2Z+8CXuYIsrUnTNF8zBWtLh4cyqOAzL9TuPnfQmdD7QZashLO UK3dzlFNtBvSNHn8nZG/KqxbbrMkLSH/SvHz/iXMV0DOBMr5OtvZAOzzRXaOJusF2Zuz yIbw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49105-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49105-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXHoHZpQ/sD+FQ7AMfJQthassZvVfFGcgwNrzwZn200ucf2CLKIKsPJ/9wvPwyHUiSL0Uc5l0L1xjHcfAZMf4xL7nTa5A== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id ew8-20020a0562140aa800b0068c8243e6a6si1005058qvb.4.2024.02.01.18.32.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49105-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-49105-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49105-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 0A6E11C2255C for ; Fri, 2 Feb 2024 02:32:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5324B179B8; Fri, 2 Feb 2024 02:30: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 6C454FC03; Fri, 2 Feb 2024 02:30: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=1706841006; cv=none; b=apPK8tNkUTFn+ICTl4gXOkjFXfJNDPBA17RsFX30gMUrk/5jKaMQFZ+Nw4Tz99cWUKTHUFB80MyGkNeokNkFQ2COnGk8tNe6NAfq+Ob2Xyxm4T2VyT/RQ++TAOx2uOCjclRhk49p5GZ/VYQbTpf0GP+IE2jFjnAcj2tFHFZQhu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841006; c=relaxed/simple; bh=c2ljJPiZws6OX2OlljjxZ50rg8MQ1U9fnX0GsF88OI4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Lt1aCBWheqeqzt3jbeEgLJS+OrkpfEGhiIEWzinPgR4w3Mbz36QIYeIR7y2ZnJ2DZLJ9VkRmxQqL8Iv9vsOwveYa6PAAnLyNTCd3fbUzBa6wnaIeFrqxgRK31go6MSpsiiytNvmSjQvGvPBVSLUZASWvGgavxJFgLasMutP7BFc= 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 DAC6CC43142; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005kBZ-45i4; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.834732790@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:11 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Linus Torvalds , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [for-linus][PATCH 12/13] eventfs: Remove fsnotify*() functions from lookup() References: <20240202022959.515961549@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: 1789752675471027788 X-GMAIL-MSGID: 1789752675471027788 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 Fri Feb 2 02:30:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165550dyc; Thu, 1 Feb 2024 18:32:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVc9nOLEz7U+LgyUO5sURfBXKpWaWc10e+7inCc+XLufT56SGPOmRgJJWhXvGr5CaNRhEm X-Received: by 2002:a05:620a:158f:b0:783:f827:124 with SMTP id d15-20020a05620a158f00b00783f8270124mr4454439qkk.78.1706841175035; Thu, 01 Feb 2024 18:32:55 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841175; cv=pass; d=google.com; s=arc-20160816; b=rfJofww+Yg6G1qCXfYOwCUqYJxaqhGNO0/E4RIE9CB4ZMRwkuXp1KNbFEQMf4uur4M ZJLpfCziKmDnP5PZchRCNxBKXnNehVYZZfFtgmCnWzdlQ8CzHHL2eHLhddX1e6tvk0pv Q2x9s5AVa7fHu6g7kr0XuWXLuTO6ciLYJ8asCpi/TzUqAjOsTG/VcEA5e7PK19Tnq/z6 B5cnFKTe3jOyYp30se5dShjXvwc4LjqjBzemMlCb/TYdVXxMdtcvJFxxEUwb5t/wcG1P pf2HYFqcgdC4aIaNOQ4X/xHp/VP3kkbSPfObzfcYKXgfve58a70vH/VAVma6I+CTzS5B QMIw== 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=tnZqb9oZCmbjA9/ix03+k9/HbKVZ3gwhrkKMJ+pRi4U=; b=Qj7bBpSksUkVbl8j1nCt85jQZNQMpVr+vauA/jv+Gj9iPAiUtbCQlfNV8ggZyp+22m Bonztb5fjphcSp6jXrlUYj7IsAABvmxMRGe6YGJs/RR21TnemsW1OE8ksOKa1oHx+hmg Lzuk9GR4Cg33nzOXNWGlso7eKzU9LpD18TyKB01WFxgn/BoYW4LOP7aBskBgmfmwLrSJ sgvYU8//t/M06Z71cP3PkOJp8tSLpyNaLEQS0N5/AZYeqFJ9Dtzv2w24sJMHtXnc20rq 1fkexJZffWVvKGEvCay7v3XETN02BqZ3e/UIykMvRh/iZOh+GnncZwSIpo7lc8PkO+cY YMwQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49106-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXeTMw6hgr+TRVr3g1IsxUF1cBuyqY9eVzLM4NAWHlIrzyjro6C5wL/0epf6mkLV6PRrslKTcbPNxuaUVl6nNSnS8g3sQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe18-20020a05620a851200b00785466d67ecsi978491qkn.66.2024.02.01.18.32.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49106-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-49106-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49106-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 D039F1C22E24 for ; Fri, 2 Feb 2024 02:32:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C355617BDD; Fri, 2 Feb 2024 02:30: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 970E6107A6; Fri, 2 Feb 2024 02:30: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=1706841006; cv=none; b=uSamPuVTQn/gMC/IrMoibgFdB/sOeD4iCCzd02Bi2KWpBmEoJeZp9M3p8pbaRQbcauPpqwvi5gHVMcbu6bH20W9+Iw1WFloVPRwfUDUuUTE1AzEeB/ETY9DPgmFLYdAZ9CDb/DoLbLdEtiXhVC5LpYdUHrq23h3yRxhdZEN1SDA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841006; c=relaxed/simple; bh=Dq6x99Zk/Vun27CnDuFYUGrU4i510huChkfoAHC46Jo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KMfbIYwRHCfQe0Pka7flpga/zIXxqzH5PIM7NXLJPf8voZRNqI9OGCmywBPrBcZcXU5trsEARi/j/eNU7OAwtWXMfu9/pcyyy7FNIm5rbb4vMMtQdwufbnKY/vDeNCi2Z93hHdA46IUeocgBr/k+bLsJD3muNtmaQTOi5oiKF5Y= 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 13BECC41679; Fri, 2 Feb 2024 02:30:06 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJw-00000005kC4-0a2m; Thu, 01 Feb 2024 21:30:24 -0500 Message-ID: <20240202023023.996375893@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:12 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , stable@vger.kernel.org, Linus Torvalds , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [for-linus][PATCH 13/13] eventfs: Keep all directory links at 1 References: <20240202022959.515961549@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: 1789752691669299358 X-GMAIL-MSGID: 1789752691669299358 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);