From patchwork Tue Feb 6 12:09: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: 197382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1495642dyb; Tue, 6 Feb 2024 04:16:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9Xhahsnq58OT/f7maJenMwxgSgbL3ABoLSe7yYV3/ApRMWaDGA4dH9AFLSDdN1km70Lzn X-Received: by 2002:a05:6214:21e9:b0:680:f8d2:c828 with SMTP id p9-20020a05621421e900b00680f8d2c828mr2531537qvj.16.1707221816480; Tue, 06 Feb 2024 04:16:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221816; cv=pass; d=google.com; s=arc-20160816; b=u25XJdVh9eO4R8N41QT2kxYP7M/QB+fujNUEkbC52hAYRmoUMXWBylLyt0WPBK07le MVCwiClAL1R/yVzHUBRF8w/2Z50hQbyeJNP7YwcPzuT5Z/v3tdp7+/IOMw5pdyjpGGGG BZblkm7m1DhE5Tnwxz2qvE2jVQdCQrI+wWnqcXGmAd4YfwhWPS3hrPlRKGCs6yhWqDa/ 0ec7uG74yQnwYSguaFYXWCMTTULUunIHbnpYGZ5dqMhb8P/CXr9thzWlGFhuXY4I3mrF LI5MlGrkWj2hzSFdogzTfWP1A8g51MILnoXOfZwpqj4iviRt6iQIV3R3nod33pRG8HlR OMcg== 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=ZQWhTM2mFBcdUFwWjx/kMRG2BZ/9iHJmObEJ7/Ahn08=; fh=Pdb5gx68wr6TjMdZUvXqDspAvM+tOwGfGf3mcCC4V5Q=; b=PltoQOdrKM6i9liKRC7tGMUTUWGbVOIBnRxiIxmWXHPGcM1RlKYHkh57waOtHHcE0t 06nVPjl1VN2w8eDIHGjCg+cFkAaiOwmCHNySw27FeG8nd95z9B9/MFjLLsuV3p1NkTC2 BZDo3pVwLFHuOznXOsbNlev/hJdO0mzHKqbnKT7cy/PMGX5+tdV9wkszMpPPH1JF9u5o fUGK586mNPPqfL6bpG6rl2x4LFJpZ8fQR1SKFHZ75G6shAFakVFTrK+/zPwaqXpqPOUH c1fJY/a3yldCL2UmJyMp177c0tA8CmllrmeOaWxy6j3TweiSfrI7AiSL6+xK7q3yaijN 5fJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54880-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54880-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVdh4yK1BHEINki/WBga8p51/MObE+mv0AYCUnDOIfnqY5ei/rsWL9wUUBzp2St/w42ltqHXHoMoJEkHTq+QJNVeJMfeg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g14-20020ad457ae000000b006852904842csi2244292qvx.276.2024.02.06.04.16.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:16:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54880-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54880-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54880-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 3B1F91C23DCB for ; Tue, 6 Feb 2024 12:16:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 053431384B8; Tue, 6 Feb 2024 12:09:23 +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 6007A1350EC; Tue, 6 Feb 2024 12:09:19 +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=1707221359; cv=none; b=qzf4uDzs2Gf9YlG5w8O66NMyJXGlZFOIeIcnlTGgK0FAo9g35LhrMGSQsvEMxc6efP5NcGc5lI4820T9X1TBQgoIycu7UbQNxeV3q1FKqSps4PiK4WkDehVXGc3CDXGXs32631dTvxBxO18u7WrKB4pncpElNOfzheUpXcWGq4k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221359; c=relaxed/simple; bh=PSi5n8hXvrxTnOnndtW7rBtA25suX6bR1nY9wf/5kJE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=EDjz0WdkmZMMWKDCN1U0vWptSuQ57uJ18Oo15gn8GB6AsoGWTHnJtLoCWLnEfJP3NmFCf2jpSYfWvtlQ5N2Tf0on+L1FL19sXuNKRdj4kS9hFSoqoYjZdHa1pRvKIrahBNV9BRpq2oxCkoeDk0Fye0IxrfuHGpqaEsExzxSwN4c= 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 DCC62C43399; Tue, 6 Feb 2024 12:09:18 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGp-00000006b3r-1NvX; Tue, 06 Feb 2024 07:09:47 -0500 Message-ID: <20240206120947.186364236@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:10 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.6][PATCH 05/57] Revert "eventfs: Save ownership and mode" References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151823776486987 X-GMAIL-MSGID: 1790151823776486987 From: "Steven Rostedt (Google)" This reverts commit 9aaee3eebc91dd9ccebf6b6bc8a5f59d04ef718b. The eventfs was not designed properly and may have some hidden bugs in it. Linus rewrote it properly and I trust his version more than this one. Revert the backported patches for 6.6 and re-apply all the changes to make it equivalent to Linus's version. Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 107 ++++++--------------------------------- 1 file changed, 16 insertions(+), 91 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 6a3f7502310c..a64d8fa39e54 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -40,8 +40,6 @@ struct eventfs_inode { * @data: something that the caller will want to get to later on * @is_freed: Flag set if the eventfs is on its way to be freed * @mode: the permission that the file or directory should have - * @uid: saved uid if changed - * @gid: saved gid if changed */ struct eventfs_file { const char *name; @@ -63,22 +61,11 @@ struct eventfs_file { void *data; unsigned int is_freed:1; unsigned int mode:31; - kuid_t uid; - kgid_t gid; }; static DEFINE_MUTEX(eventfs_mutex); DEFINE_STATIC_SRCU(eventfs_srcu); -/* Mode is unsigned short, use the upper bits for flags */ -enum { - EVENTFS_SAVE_MODE = BIT(16), - EVENTFS_SAVE_UID = BIT(17), - EVENTFS_SAVE_GID = BIT(18), -}; - -#define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1) - static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); @@ -86,54 +73,8 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file); static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx); static int eventfs_release(struct inode *inode, struct file *file); -static void update_attr(struct eventfs_file *ef, struct iattr *iattr) -{ - unsigned int ia_valid = iattr->ia_valid; - - if (ia_valid & ATTR_MODE) { - ef->mode = (ef->mode & ~EVENTFS_MODE_MASK) | - (iattr->ia_mode & EVENTFS_MODE_MASK) | - EVENTFS_SAVE_MODE; - } - if (ia_valid & ATTR_UID) { - ef->mode |= EVENTFS_SAVE_UID; - ef->uid = iattr->ia_uid; - } - if (ia_valid & ATTR_GID) { - ef->mode |= EVENTFS_SAVE_GID; - ef->gid = iattr->ia_gid; - } -} - -static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, - struct iattr *iattr) -{ - struct eventfs_file *ef; - int ret; - - mutex_lock(&eventfs_mutex); - ef = dentry->d_fsdata; - /* The LSB is set when the eventfs_inode is being freed */ - if (((unsigned long)ef & 1UL) || ef->is_freed) { - /* Do not allow changes if the event is about to be removed. */ - mutex_unlock(&eventfs_mutex); - return -ENODEV; - } - - ret = simple_setattr(idmap, dentry, iattr); - if (!ret) - update_attr(ef, iattr); - mutex_unlock(&eventfs_mutex); - return ret; -} - static const struct inode_operations eventfs_root_dir_inode_operations = { .lookup = eventfs_root_lookup, - .setattr = eventfs_set_attr, -}; - -static const struct inode_operations eventfs_file_inode_operations = { - .setattr = eventfs_set_attr, }; static const struct file_operations eventfs_file_operations = { @@ -144,20 +85,10 @@ static const struct file_operations eventfs_file_operations = { .release = eventfs_release, }; -static void update_inode_attr(struct inode *inode, struct eventfs_file *ef) -{ - inode->i_mode = ef->mode & EVENTFS_MODE_MASK; - - if (ef->mode & EVENTFS_SAVE_UID) - inode->i_uid = ef->uid; - - if (ef->mode & EVENTFS_SAVE_GID) - inode->i_gid = ef->gid; -} - /** * create_file - create a file in the tracefs filesystem - * @ef: the eventfs_file + * @name: the name of the file to create. + * @mode: the permission that the file should have. * @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. @@ -173,7 +104,7 @@ static void update_inode_attr(struct inode *inode, struct eventfs_file *ef) * If tracefs is not enabled in the kernel, the value -%ENODEV will be * returned. */ -static struct dentry *create_file(struct eventfs_file *ef, +static struct dentry *create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fop) { @@ -181,13 +112,13 @@ static struct dentry *create_file(struct eventfs_file *ef, struct dentry *dentry; struct inode *inode; - if (!(ef->mode & S_IFMT)) - ef->mode |= S_IFREG; + if (!(mode & S_IFMT)) + mode |= S_IFREG; - if (WARN_ON_ONCE(!S_ISREG(ef->mode))) + if (WARN_ON_ONCE(!S_ISREG(mode))) return NULL; - dentry = eventfs_start_creating(ef->name, parent); + dentry = eventfs_start_creating(name, parent); if (IS_ERR(dentry)) return dentry; @@ -196,10 +127,7 @@ static struct dentry *create_file(struct eventfs_file *ef, if (unlikely(!inode)) return eventfs_failed_creating(dentry); - /* If the user updated the directory's attributes, use them */ - update_inode_attr(inode, ef); - - inode->i_op = &eventfs_file_inode_operations; + inode->i_mode = mode; inode->i_fop = fop; inode->i_private = data; @@ -212,7 +140,7 @@ static struct dentry *create_file(struct eventfs_file *ef, /** * create_dir - create a dir in the tracefs filesystem - * @ei: the eventfs_inode that represents the directory to create + * @name: the name of the file to create. * @parent: parent dentry for this file. * @data: something that the caller will want to get to later on. * @@ -227,14 +155,13 @@ static struct dentry *create_file(struct eventfs_file *ef, * If tracefs is not enabled in the kernel, the value -%ENODEV will be * returned. */ -static struct dentry *create_dir(struct eventfs_file *ef, - struct dentry *parent, void *data) +static struct dentry *create_dir(const char *name, struct dentry *parent, void *data) { struct tracefs_inode *ti; struct dentry *dentry; struct inode *inode; - dentry = eventfs_start_creating(ef->name, parent); + dentry = eventfs_start_creating(name, parent); if (IS_ERR(dentry)) return dentry; @@ -242,8 +169,7 @@ static struct dentry *create_dir(struct eventfs_file *ef, if (unlikely(!inode)) return eventfs_failed_creating(dentry); - update_inode_attr(inode, ef); - + inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; inode->i_private = data; @@ -380,9 +306,10 @@ create_dentry(struct eventfs_file *ef, struct dentry *parent, bool lookup) inode_lock(parent->d_inode); if (ef->ei) - dentry = create_dir(ef, parent, ef->data); + dentry = create_dir(ef->name, parent, ef->data); else - dentry = create_file(ef, parent, ef->data, ef->fop); + dentry = create_file(ef->name, ef->mode, parent, + ef->data, ef->fop); if (!lookup) inode_unlock(parent->d_inode); @@ -548,7 +475,6 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) if (d) { struct dentry **tmp; - tmp = krealloc(dentries, sizeof(d) * (cnt + 2), GFP_KERNEL); if (!tmp) break; @@ -623,14 +549,13 @@ static struct eventfs_file *eventfs_prepare_ef(const char *name, umode_t mode, return ERR_PTR(-ENOMEM); } INIT_LIST_HEAD(&ef->ei->e_top_files); - ef->mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; } else { ef->ei = NULL; - ef->mode = mode; } ef->iop = iop; ef->fop = fop; + ef->mode = mode; ef->data = data; return ef; } From patchwork Tue Feb 6 12:09: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: 197413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500976dyb; Tue, 6 Feb 2024 04:26:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyrihQimRKWDvPoJvTgjd7JPgEq15HuRELaXb+J8Pce9n338NyTFoL11MQgF9zt+LujhU7 X-Received: by 2002:a0c:f244:0:b0:68c:521f:707b with SMTP id z4-20020a0cf244000000b0068c521f707bmr1932956qvl.64.1707222401771; Tue, 06 Feb 2024 04:26:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222401; cv=pass; d=google.com; s=arc-20160816; b=JTWqXvDaXgBOgvkUdGjOI6wqumAay/04fpgex8TJAeLc128WjXLaoGsViTeZHWlxg/ hg4kRMJwYJEAbPq2n9gT/eI+V+Svr2GiA+OS38sM5X+0Tr+Sn4ScOE25TvLtGsnac5mG Y7v5DiJPMHTPZTULA2uPI1g2AKTnzs7Jlu8KmmwqjbPrMGf5PSqOh2oGb2jwoHxHg3Oa h+m6eyO0go4FDonMobQnVL3i24ZZJQAO38XRg6FKFUDGV/ESx+YMT2r5dk6maFn/1q3Y lzQdwjPaGlaeGFTTf+R6I3pakGMBwVM83FZdFZlDayavBtpQyreje9DrE9DZ7VtJtx57 tFDQ== 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=1KX/rOIlpoV6dxCWxqCPO1HHbHAuxC6BWDuhqb8vpt8=; fh=dSnrJZbsjirdOeK9zgJRj4TZe71Wp9TTjgrbuw0QNGs=; b=gYqxI4hSNcLZrOJq6ej9lsi26ecLYzOifEkikBZvNpCnT4Sw+miiSlDh3tkBM2nhXI PZvdsljt5IJirG0ynqb+0I+gO2vfCZbAW3qyPX7DUwDCykD0UJXQvd3aw8o7TIBQO3Ff azQ+yZ3lLnseJbLcQO4ilUPOe4EnQYZoRWDRf7WxMVUStuBlWNTRgCrJERw5X9yh3udq EqFo3WyxSw1/rzrP0OczZ8mwU2WprSkEOgLGh5GnUU7pZVBLK9LcpFQ07FMQTAmxWBmQ WGckDHwtsY3fbsITZq/1bEn+7Ta0yo1YxWNzO+9rnbS8ep7LJWMqFPrQE7yNQXWCvfAf 5o1Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54882-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54882-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUcgAs2yxwrHPNSNuMxVs/I/o+SDzObML2xPiax2UYs/ZllDLrkxuq6xHJfpe5XMa6qDA72PccUlq55TK6vX1Fm1srQUA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c12-20020a056214070c00b00681955e64bcsi2162071qvz.604.2024.02.06.04.26.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54882-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-54882-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54882-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 6CF051C240C7 for ; Tue, 6 Feb 2024 12:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 42F4B14FF91; Tue, 6 Feb 2024 12:09:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E8091350FA; Tue, 6 Feb 2024 12:09:19 +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=1707221359; cv=none; b=KhvcY2m8OYPg6hP9qWzhyEEkElxLvkU6ajg9L3G99SvLUiAimNnjTIUGzUcHJQfk0kV2WBe5SBpi+9ZHCCGjuyWlyVuO2VJvv7wvFhqu3BD6gEmmFW73Ial8iITVk2alcfht/nLqhtc7dE++F2t5EF0V3eP62h2jUALYGtY7m3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221359; c=relaxed/simple; bh=MnUSwu0Vh8hX2WD17BFBgVAjPS9gCClUCjo4l7sYgVk=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=VCZ0Kboag3qdvY4WzX+pVzx8B/hyzHbnx2LCbR95ayE1db2XRDbTDfpYJjGIR8wUPO1qB7tgcoCcA4d9jUEWhZDmZr/AZGVyOiqfX0EtoQpJS4Be2XnEvNLkp8oiNonI56JwieU86TI8Y5/gNSud/52SlDF/6qCNtoVgI9xBZMs= 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 38AC8C43390; Tue, 6 Feb 2024 12:09:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGp-00000006b4p-2mXn; Tue, 06 Feb 2024 07:09:47 -0500 Message-ID: <20240206120947.516739239@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:12 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ajay Kaher Subject: [v6.6][PATCH 07/57] eventfs: Remove eventfs_file and just use eventfs_inode References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152436958825281 X-GMAIL-MSGID: 1790152436958825281 From: "Steven Rostedt (Google)" Instead of having a descriptor for every file represented in the eventfs directory, only have the directory itself represented. Change the API to send in a list of entries that represent all the files in the directory (but not other directories). The entry list contains a name and a callback function that will be used to create the files when they are accessed. struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent, const struct eventfs_entry *entries, int size, void *data); is used for the top level eventfs directory, and returns an eventfs_inode that will be used by: struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent, const struct eventfs_entry *entries, int size, void *data); where both of the above take an array of struct eventfs_entry entries for every file that is in the directory. The entries are defined by: typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data, const struct file_operations **fops); struct eventfs_entry { const char *name; eventfs_callback callback; }; Where the name is the name of the file and the callback gets called when the file is being created. The callback passes in the name (in case the same callback is used for multiple files), a pointer to the mode, data and fops. The data will be pointing to the data that was passed in eventfs_create_dir() or eventfs_create_events_dir() but may be overridden to point to something else, as it will be used to point to the inode->i_private that is created. The information passed back from the callback is used to create the dentry/inode. If the callback fills the data and the file should be created, it must return a positive number. On zero or negative, the file is ignored. This logic may also be used as a prototype to convert entire pseudo file systems into just-in-time allocation. The "show_events_dentry" file has been updated to show the directories, and any files they have. With just the eventfs_file allocations: Before after deltas for meminfo (in kB): MemFree: -14360 MemAvailable: -14260 Buffers: 40 Cached: 24 Active: 44 Inactive: 48 Inactive(anon): 28 Active(file): 44 Inactive(file): 20 Dirty: -4 AnonPages: 28 Mapped: 4 KReclaimable: 132 Slab: 1604 SReclaimable: 132 SUnreclaim: 1472 Committed_AS: 12 Before after deltas for slabinfo: : [ * = ] ext4_inode_cache 27 [* 1184 = 31968 ] extent_status 102 [* 40 = 4080 ] tracefs_inode_cache 144 [* 656 = 94464 ] buffer_head 39 [* 104 = 4056 ] shmem_inode_cache 49 [* 800 = 39200 ] filp -53 [* 256 = -13568 ] dentry 251 [* 192 = 48192 ] lsm_file_cache 277 [* 32 = 8864 ] vm_area_struct -14 [* 184 = -2576 ] trace_event_file 1748 [* 88 = 153824 ] kmalloc-1k 35 [* 1024 = 35840 ] kmalloc-256 49 [* 256 = 12544 ] kmalloc-192 -28 [* 192 = -5376 ] kmalloc-128 -30 [* 128 = -3840 ] kmalloc-96 10581 [* 96 = 1015776 ] kmalloc-64 3056 [* 64 = 195584 ] kmalloc-32 1291 [* 32 = 41312 ] kmalloc-16 2310 [* 16 = 36960 ] kmalloc-8 9216 [* 8 = 73728 ] Free memory dropped by 14,360 kB Available memory dropped by 14,260 kB Total slab additions in size: 1,771,032 bytes With this change: Before after deltas for meminfo (in kB): MemFree: -12084 MemAvailable: -11976 Buffers: 32 Cached: 32 Active: 72 Inactive: 168 Inactive(anon): 176 Active(file): 72 Inactive(file): -8 Dirty: 24 AnonPages: 196 Mapped: 8 KReclaimable: 148 Slab: 836 SReclaimable: 148 SUnreclaim: 688 Committed_AS: 324 Before after deltas for slabinfo: : [ * = ] tracefs_inode_cache 144 [* 656 = 94464 ] shmem_inode_cache -23 [* 800 = -18400 ] filp -92 [* 256 = -23552 ] dentry 179 [* 192 = 34368 ] lsm_file_cache -3 [* 32 = -96 ] vm_area_struct -13 [* 184 = -2392 ] trace_event_file 1748 [* 88 = 153824 ] kmalloc-1k -49 [* 1024 = -50176 ] kmalloc-256 -27 [* 256 = -6912 ] kmalloc-128 1864 [* 128 = 238592 ] kmalloc-64 4685 [* 64 = 299840 ] kmalloc-32 -72 [* 32 = -2304 ] kmalloc-16 256 [* 16 = 4096 ] total = 721352 Free memory dropped by 12,084 kB Available memory dropped by 11,976 kB Total slab additions in size: 721,352 bytes That's over 2 MB in savings per instance for free and available memory, and over 1 MB in savings per instance of slab memory. Link: https://lore.kernel.org/linux-trace-kernel/20231003184059.4924468e@gandalf.local.home Link: https://lore.kernel.org/linux-trace-kernel/20231004165007.43d79161@gandalf.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 5790b1fb3d672d9a1fe3881a7181dfdbe741568f) --- fs/tracefs/event_inode.c | 847 ++++++++++++++++++----------------- fs/tracefs/inode.c | 2 +- fs/tracefs/internal.h | 37 +- include/linux/trace_events.h | 2 +- include/linux/tracefs.h | 29 +- kernel/trace/trace.c | 7 +- kernel/trace/trace.h | 4 +- kernel/trace/trace_events.c | 313 +++++++++---- 8 files changed, 705 insertions(+), 536 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 8c8d64e76103..eab18b157ef5 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -2,8 +2,9 @@ /* * event_inode.c - part of tracefs, a pseudo file system for activating tracing * - * Copyright (C) 2020-23 VMware Inc, author: Steven Rostedt (VMware) + * Copyright (C) 2020-23 VMware Inc, author: Steven Rostedt * Copyright (C) 2020-23 VMware Inc, author: Ajay Kaher + * Copyright (C) 2023 Google, author: Steven Rostedt * * eventfs is used to dynamically create inodes and dentries based on the * meta data provided by the tracing system. @@ -23,46 +24,6 @@ #include #include "internal.h" -struct eventfs_inode { - struct list_head e_top_files; -}; - -/* - * struct eventfs_file - hold the properties of the eventfs files and - * directories. - * @name: the name of the file or directory to create - * @d_parent: holds parent's dentry - * @dentry: once accessed holds dentry - * @list: file or directory to be added to parent directory - * @ei: list of files and directories within directory - * @fop: file_operations for file or directory - * @iop: inode_operations for file or directory - * @data: something that the caller will want to get to later on - * @mode: the permission that the file or directory should have - */ -struct eventfs_file { - const char *name; - struct dentry *d_parent; - struct dentry *dentry; - struct list_head list; - struct eventfs_inode *ei; - const struct file_operations *fop; - const struct inode_operations *iop; - /* - * Union - used for deletion - * @del_list: list of eventfs_file to delete - * @rcu: eventfs_file to delete in RCU - * @is_freed: node is freed if one of the above is set - */ - union { - struct list_head del_list; - struct rcu_head rcu; - unsigned long is_freed; - }; - void *data; - umode_t mode; -}; - static DEFINE_MUTEX(eventfs_mutex); DEFINE_STATIC_SRCU(eventfs_srcu); @@ -93,16 +54,9 @@ static const struct file_operations eventfs_file_operations = { * @data: something that the caller will want to get to later on. * @fop: struct file_operations that should be used for this file. * - * This is the basic "create a file" function for tracefs. It allows for a - * wide range of flexibility in creating a file. - * - * This function will return a pointer to a dentry if it succeeds. This - * pointer must be passed to the tracefs_remove() function when the file is - * to be removed (no automatic cleanup happens if your module is unloaded, - * you are responsible here.) If an error occurs, %NULL will be returned. - * - * If tracefs is not enabled in the kernel, the value -%ENODEV will be - * returned. + * This function creates a dentry that represents a file in the eventsfs_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, struct dentry *parent, void *data, @@ -118,6 +72,7 @@ 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)) @@ -142,20 +97,11 @@ static struct dentry *create_file(const char *name, umode_t mode, * create_dir - create a dir in the tracefs filesystem * @name: the name of the file to create. * @parent: parent dentry for this file. - * @data: something that the caller will want to get to later on. - * - * This is the basic "create a dir" function for eventfs. It allows for a - * wide range of flexibility in creating a dir. - * - * This function will return a pointer to a dentry if it succeeds. This - * pointer must be passed to the tracefs_remove() function when the file is - * to be removed (no automatic cleanup happens if your module is unloaded, - * you are responsible here.) If an error occurs, %NULL will be returned. * - * If tracefs is not enabled in the kernel, the value -%ENODEV will be - * returned. + * This function will create a dentry for a directory represented by + * a eventfs_inode. */ -static struct dentry *create_dir(const char *name, struct dentry *parent, void *data) +static struct dentry *create_dir(const char *name, struct dentry *parent) { struct tracefs_inode *ti; struct dentry *dentry; @@ -172,7 +118,6 @@ static struct dentry *create_dir(const char *name, struct dentry *parent, void * inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; - inode->i_private = data; ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; @@ -185,18 +130,18 @@ static struct dentry *create_dir(const char *name, struct dentry *parent, void * } /** - * eventfs_set_ef_status_free - set the ef->status to free + * eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode * @ti: the tracefs_inode of the dentry - * @dentry: dentry who's status to be freed + * @dentry: dentry which has the reference to remove. * - * eventfs_set_ef_status_free will be called if no more - * references remain + * Remove the association between a dentry from an eventfs_inode. */ -void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry) +void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) { struct tracefs_inode *ti_parent; + struct eventfs_inode *ei_child, *tmp; struct eventfs_inode *ei; - struct eventfs_file *ef, *tmp; + int i; /* The top level events directory may be freed by this */ if (unlikely(ti->flags & TRACEFS_EVENT_TOP_INODE)) { @@ -207,9 +152,9 @@ void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry) ei = ti->private; /* Record all the top level files */ - list_for_each_entry_srcu(ef, &ei->e_top_files, list, + list_for_each_entry_srcu(ei_child, &ei->children, list, lockdep_is_held(&eventfs_mutex)) { - list_add_tail(&ef->del_list, &ef_del_list); + list_add_tail(&ei_child->del_list, &ef_del_list); } /* Nothing should access this, but just in case! */ @@ -218,11 +163,13 @@ void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry) mutex_unlock(&eventfs_mutex); /* Now safely free the top level files and their children */ - list_for_each_entry_safe(ef, tmp, &ef_del_list, del_list) { - list_del(&ef->del_list); - eventfs_remove(ef); + list_for_each_entry_safe(ei_child, tmp, &ef_del_list, del_list) { + list_del(&ei_child->del_list); + eventfs_remove_dir(ei_child); } + kfree_const(ei->name); + kfree(ei->d_children); kfree(ei); return; } @@ -233,68 +180,162 @@ void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry) if (!ti_parent || !(ti_parent->flags & TRACEFS_EVENT_INODE)) goto out; - ef = dentry->d_fsdata; - if (!ef) + ei = dentry->d_fsdata; + if (!ei) goto out; /* - * If ef was freed, then the LSB bit is set for d_fsdata. + * If ei was freed, then the LSB bit is set for d_fsdata. * But this should not happen, as it should still have a * ref count that prevents it. Warn in case it does. */ - if (WARN_ON_ONCE((unsigned long)ef & 1)) + if (WARN_ON_ONCE((unsigned long)ei & 1)) 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 { + ei->dentry = NULL; + } + dentry->d_fsdata = NULL; - ef->dentry = NULL; -out: + out: mutex_unlock(&eventfs_mutex); } +/** + * create_file_dentry - create a dentry for a file of an eventfs_inode + * @ei: the eventfs_inode that the file will be created under + * @e_dentry: a pointer to the d_children[] 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. + * @data: The data to use to set the inode of the file with on open() + * @fops: The fops of the file to be created. + * @lookup: If called by the lookup routine, in which case, dput() the created dentry. + * + * Create a dentry for a file of an eventfs_inode @ei and place it into the + * address located at @e_dentry. If the @e_dentry already has a dentry, then + * just do a dget() on it and return. Otherwise create the dentry and attach it. + */ +static struct dentry * +create_file_dentry(struct eventfs_inode *ei, struct dentry **e_dentry, + struct dentry *parent, const char *name, umode_t mode, void *data, + const struct file_operations *fops, bool lookup) +{ + struct dentry *dentry; + bool invalidate = false; + + mutex_lock(&eventfs_mutex); + /* If the e_dentry already has a dentry, use it */ + if (*e_dentry) { + /* lookup does not need to up the ref count */ + if (!lookup) + dget(*e_dentry); + mutex_unlock(&eventfs_mutex); + return *e_dentry; + } + mutex_unlock(&eventfs_mutex); + + /* The lookup already has the parent->d_inode locked */ + if (!lookup) + inode_lock(parent->d_inode); + + dentry = create_file(name, mode, parent, data, fops); + + if (!lookup) + inode_unlock(parent->d_inode); + + 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. + * + * Note, with the mutex held, the e_dentry cannot have content + * and the ei->is_freed be true at the same time. + */ + WARN_ON_ONCE(ei->is_freed); + dentry = *e_dentry; + /* The lookup does not need to up the dentry refcount */ + if (dentry && !lookup) + 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); + invalidate = true; + } + mutex_unlock(&eventfs_mutex); + + if (invalidate) + d_invalidate(dentry); + + if (lookup || invalidate) + dput(dentry); + + return invalidate ? NULL : dentry; +} + /** * eventfs_post_create_dir - post create dir routine - * @ef: eventfs_file of recently created dir + * @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_file *ef) +static void eventfs_post_create_dir(struct eventfs_inode *ei) { - struct eventfs_file *ef_child; + struct eventfs_inode *ei_child; struct tracefs_inode *ti; /* srcu lock already held */ /* fill parent-child relation */ - list_for_each_entry_srcu(ef_child, &ef->ei->e_top_files, list, + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - ef_child->d_parent = ef->dentry; + ei_child->d_parent = ei->dentry; } - ti = get_tracefs(ef->dentry->d_inode); - ti->private = ef->ei; + ti = get_tracefs(ei->dentry->d_inode); + ti->private = ei; } /** - * create_dentry - helper function to create dentry - * @ef: eventfs_file of file or directory to create - * @parent: parent dentry - * @lookup: true if called from lookup routine + * create_dir_dentry - Create a directory dentry for the eventfs_inode + * @ei: The eventfs_inode to create the directory for + * @parent: The dentry of the parent of this directory + * @lookup: True if this is called by the lookup code * - * Used to create a dentry for file/dir, executes post dentry creation routine + * This creates and attaches a directory dentry to the eventfs_inode @ei. */ static struct dentry * -create_dentry(struct eventfs_file *ef, struct dentry *parent, bool lookup) +create_dir_dentry(struct eventfs_inode *ei, struct dentry *parent, bool lookup) { bool invalidate = false; - struct dentry *dentry; + struct dentry *dentry = NULL; mutex_lock(&eventfs_mutex); - if (ef->is_freed) { - mutex_unlock(&eventfs_mutex); - return NULL; - } - if (ef->dentry) { - dentry = ef->dentry; - /* On dir open, up the ref count */ + if (ei->dentry) { + /* If the dentry already has a dentry, use it */ + dentry = ei->dentry; + /* lookup does not need to up the ref count */ if (!lookup) dget(dentry); mutex_unlock(&eventfs_mutex); @@ -302,42 +343,44 @@ create_dentry(struct eventfs_file *ef, struct dentry *parent, bool lookup) } mutex_unlock(&eventfs_mutex); + /* The lookup already has the parent->d_inode locked */ if (!lookup) inode_lock(parent->d_inode); - if (ef->ei) - dentry = create_dir(ef->name, parent, ef->data); - else - dentry = create_file(ef->name, ef->mode, parent, - ef->data, ef->fop); + dentry = create_dir(ei->name, parent); if (!lookup) inode_unlock(parent->d_inode); mutex_lock(&eventfs_mutex); - if (IS_ERR_OR_NULL(dentry)) { - /* If the ef was already updated get it */ - dentry = ef->dentry; + + 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. + * + * Note, with the mutex held, the e_dentry cannot have content + * and the ei->is_freed be true at the same time. + */ + dentry = ei->dentry; if (dentry && !lookup) dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; } - if (!ef->dentry && !ef->is_freed) { - ef->dentry = dentry; - if (ef->ei) - eventfs_post_create_dir(ef); - dentry->d_fsdata = ef; + if (!ei->dentry && !ei->is_freed) { + ei->dentry = dentry; + eventfs_post_create_dir(ei); + dentry->d_fsdata = ei; } else { - /* A race here, should try again (unless freed) */ - invalidate = true; - /* * Should never happen unless we get here due to being freed. * Otherwise it means two dentries exist with the same name. */ - WARN_ON_ONCE(!ef->is_freed); + WARN_ON_ONCE(!ei->is_freed); + invalidate = true; } mutex_unlock(&eventfs_mutex); if (invalidate) @@ -349,50 +392,85 @@ create_dentry(struct eventfs_file *ef, struct dentry *parent, bool lookup) return invalidate ? NULL : dentry; } -static bool match_event_file(struct eventfs_file *ef, const char *name) -{ - bool ret; - - mutex_lock(&eventfs_mutex); - ret = !ef->is_freed && strcmp(ef->name, name) == 0; - mutex_unlock(&eventfs_mutex); - - return ret; -} - /** * eventfs_root_lookup - lookup routine to create file/dir * @dir: in which a lookup is being done * @dentry: file/dir dentry - * @flags: to pass as flags parameter to simple lookup + * @flags: Just passed to simple_lookup() * - * Used to create a dynamic file/dir within @dir. Use the eventfs_inode - * list of meta data to find the information needed to create the file/dir. + * Used to create dynamic file/dir with-in @dir, search with-in @ei + * list, if @dentry found go ahead and create the file/dir */ + 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 eventfs_file *ef; + struct dentry *ei_dentry = NULL; struct dentry *ret = NULL; + const char *name = dentry->d_name.name; + bool created = false; + umode_t mode; + void *data; int idx; + int i; + int r; ti = get_tracefs(dir); if (!(ti->flags & TRACEFS_EVENT_INODE)) return NULL; - ei = ti->private; + /* Grab srcu to prevent the ei from going away */ idx = srcu_read_lock(&eventfs_srcu); - list_for_each_entry_srcu(ef, &ei->e_top_files, list, + + /* + * Grab the eventfs_mutex to consistent value from ti->private. + * This s + */ + mutex_lock(&eventfs_mutex); + ei = READ_ONCE(ti->private); + if (ei) + ei_dentry = READ_ONCE(ei->dentry); + mutex_unlock(&eventfs_mutex); + + if (!ei || !ei_dentry) + goto out; + + data = ei->data; + + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - if (!match_event_file(ef, dentry->d_name.name)) + if (strcmp(ei_child->name, name) != 0) continue; ret = simple_lookup(dir, dentry, flags); - create_dentry(ef, ef->d_parent, true); + create_dir_dentry(ei_child, ei_dentry, true); + created = true; break; } + + if (created) + goto out; + + for (i = 0; i < ei->nr_entries; i++) { + entry = &ei->entries[i]; + if (strcmp(name, entry->name) == 0) { + void *cdata = data; + r = entry->callback(name, &mode, &cdata, &fops); + if (r <= 0) + continue; + ret = simple_lookup(dir, dentry, flags); + create_file_dentry(ei, &ei->d_children[i], + ei_dentry, name, mode, cdata, + fops, true); + break; + } + } + out: srcu_read_unlock(&eventfs_srcu, idx); return ret; } @@ -432,29 +510,48 @@ static int eventfs_release(struct inode *inode, struct file *file) return dcache_dir_close(inode, file); } +static int add_dentries(struct dentry ***dentries, struct dentry *d, int cnt) +{ + struct dentry **tmp; + + tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_KERNEL); + if (!tmp) + return -1; + tmp[cnt] = d; + tmp[cnt + 1] = NULL; + *dentries = tmp; + return 0; +} + /** * dcache_dir_open_wrapper - eventfs open wrapper * @inode: not used - * @file: dir to be opened (to create its child) + * @file: dir to be opened (to create it's children) * - * Used to dynamically create the file/dir within @file. @file is really a - * directory and all the files/dirs of the children within @file will be - * created. If any of the files/dirs have already been created, their - * reference count will be incremented. + * Used to dynamic create file/dir with-in @file, all the + * file/dir will be created. If already created then references + * will be increased */ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) { + const struct file_operations *fops; + const struct eventfs_entry *entry; + struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct eventfs_file *ef; struct dentry_list *dlist; struct dentry **dentries = NULL; - struct dentry *dentry = file_dentry(file); + struct dentry *parent = file_dentry(file); struct dentry *d; struct inode *f_inode = file_inode(file); + const char *name = parent->d_name.name; + umode_t mode; + void *data; int cnt = 0; int idx; int ret; + int i; + int r; ti = get_tracefs(f_inode); if (!(ti->flags & TRACEFS_EVENT_INODE)) @@ -463,25 +560,51 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) if (WARN_ON_ONCE(file->private_data)) return -EINVAL; + idx = srcu_read_lock(&eventfs_srcu); + + mutex_lock(&eventfs_mutex); + ei = READ_ONCE(ti->private); + mutex_unlock(&eventfs_mutex); + + if (!ei) { + srcu_read_unlock(&eventfs_srcu, idx); + return -EINVAL; + } + + + data = ei->data; + dlist = kmalloc(sizeof(*dlist), GFP_KERNEL); - if (!dlist) + if (!dlist) { + srcu_read_unlock(&eventfs_srcu, idx); return -ENOMEM; + } - ei = ti->private; - idx = srcu_read_lock(&eventfs_srcu); - list_for_each_entry_srcu(ef, &ei->e_top_files, list, + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dentry(ef, dentry, false); + d = create_dir_dentry(ei_child, parent, false); if (d) { - struct dentry **tmp; + ret = add_dentries(&dentries, d, cnt); + if (ret < 0) + break; + cnt++; + } + } - tmp = krealloc(dentries, sizeof(d) * (cnt + 2), GFP_KERNEL); - if (!tmp) + for (i = 0; i < ei->nr_entries; i++) { + void *cdata = data; + entry = &ei->entries[i]; + name = entry->name; + r = entry->callback(name, &mode, &cdata, &fops); + if (r <= 0) + continue; + d = create_file_dentry(ei, &ei->d_children[i], + parent, name, mode, cdata, fops, false); + if (d) { + ret = add_dentries(&dentries, d, cnt); + if (ret < 0) break; - tmp[cnt] = d; - tmp[cnt + 1] = NULL; cnt++; - dentries = tmp; } } srcu_read_unlock(&eventfs_srcu, idx); @@ -514,63 +637,90 @@ static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx) } /** - * eventfs_prepare_ef - helper function to prepare eventfs_file - * @name: the name of the file/directory to create. - * @mode: the permission that the file should have. - * @fop: struct file_operations that should be used for this file/directory. - * @iop: struct inode_operations that should be used for this file/directory. - * @data: something that the caller will want to get to later on. The - * inode.i_private pointer will point to this value on the open() call. + * eventfs_create_dir - Create the eventfs_inode for this directory + * @name: The name of the directory to create. + * @parent: The eventfs_inode of the parent directory. + * @entries: A list of entries that represent the files under this directory + * @size: The number of @entries + * @data: The default data to pass to the files (an entry may override it). + * + * This function creates the descriptor to represent a directory in the + * eventfs. This descriptor is an eventfs_inode, and it is returned to be + * used to create other children underneath. + * + * The @entries is an array of eventfs_entry structures which has: + * const char *name + * eventfs_callback callback; + * + * The name is the name of the file, and the callback is a pointer to a function + * that will be called when the file is reference (either by lookup or by + * reading a directory). The callback is of the prototype: * - * This function allocates and fills the eventfs_file structure. + * int callback(const char *name, umode_t *mode, void **data, + * const struct file_operations **fops); + * + * When a file needs to be created, this callback will be called with + * name = the name of the file being created (so that the same callback + * may be used for multiple files). + * mode = a place to set the file's mode + * data = A pointer to @data, and the callback may replace it, which will + * cause the file created to pass the new data to the open() call. + * fops = the fops to use for the created file. */ -static struct eventfs_file *eventfs_prepare_ef(const char *name, umode_t mode, - const struct file_operations *fop, - const struct inode_operations *iop, - void *data) +struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent, + const struct eventfs_entry *entries, + int size, void *data) { - struct eventfs_file *ef; + struct eventfs_inode *ei; - ef = kzalloc(sizeof(*ef), GFP_KERNEL); - if (!ef) + if (!parent) + return ERR_PTR(-EINVAL); + + ei = kzalloc(sizeof(*ei), GFP_KERNEL); + if (!ei) return ERR_PTR(-ENOMEM); - ef->name = kstrdup(name, GFP_KERNEL); - if (!ef->name) { - kfree(ef); + ei->name = kstrdup_const(name, GFP_KERNEL); + if (!ei->name) { + kfree(ei); return ERR_PTR(-ENOMEM); } - if (S_ISDIR(mode)) { - ef->ei = kzalloc(sizeof(*ef->ei), GFP_KERNEL); - if (!ef->ei) { - kfree(ef->name); - kfree(ef); + if (size) { + ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + if (!ei->d_children) { + kfree_const(ei->name); + kfree(ei); return ERR_PTR(-ENOMEM); } - INIT_LIST_HEAD(&ef->ei->e_top_files); - } else { - ef->ei = NULL; } - ef->iop = iop; - ef->fop = fop; - ef->mode = mode; - ef->data = data; - return ef; + ei->entries = entries; + ei->nr_entries = size; + ei->data = data; + INIT_LIST_HEAD(&ei->children); + + mutex_lock(&eventfs_mutex); + list_add_tail(&ei->list, &parent->children); + ei->d_parent = parent->dentry; + mutex_unlock(&eventfs_mutex); + + return ei; } /** - * eventfs_create_events_dir - create the trace event structure - * @name: the name of the directory to create. - * @parent: parent dentry for this file. This should be a directory dentry - * if set. If this parameter is NULL, then the directory will be - * created in the root of the tracefs filesystem. + * eventfs_create_events_dir - create the top level events directory + * @name: The name of the top level directory to create. + * @parent: Parent dentry for this file in the tracefs directory. + * @entries: A list of entries that represent the files under this directory + * @size: The number of @entries + * @data: The default data to pass to the files (an entry may override it). * * This function creates the top of the trace event directory. */ -struct dentry *eventfs_create_events_dir(const char *name, - struct dentry *parent) +struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent, + const struct eventfs_entry *entries, + int size, void *data) { struct dentry *dentry = tracefs_start_creating(name, parent); struct eventfs_inode *ei; @@ -581,19 +731,32 @@ struct dentry *eventfs_create_events_dir(const char *name, return NULL; if (IS_ERR(dentry)) - return dentry; + return (struct eventfs_inode *)dentry; ei = kzalloc(sizeof(*ei), GFP_KERNEL); if (!ei) - return ERR_PTR(-ENOMEM); + goto fail; + inode = tracefs_get_inode(dentry->d_sb); - if (unlikely(!inode)) { - kfree(ei); - tracefs_failed_creating(dentry); - return ERR_PTR(-ENOMEM); + if (unlikely(!inode)) + goto fail; + + if (size) { + ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + if (!ei->d_children) + goto fail; } - INIT_LIST_HEAD(&ei->e_top_files); + ei->dentry = dentry; + ei->entries = entries; + ei->nr_entries = size; + ei->data = data; + ei->name = kstrdup_const(name, GFP_KERNEL); + if (!ei->name) + goto fail; + + INIT_LIST_HEAD(&ei->children); + INIT_LIST_HEAD(&ei->list); ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE | TRACEFS_EVENT_TOP_INODE; @@ -608,193 +771,41 @@ struct dentry *eventfs_create_events_dir(const char *name, d_instantiate(dentry, inode); inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); - return tracefs_end_creating(dentry); -} + tracefs_end_creating(dentry); -/** - * eventfs_add_subsystem_dir - add eventfs subsystem_dir to list to create later - * @name: the name of the file to create. - * @parent: parent dentry for this dir. - * - * This function adds eventfs subsystem dir to list. - * And all these dirs are created on the fly when they are looked up, - * and the dentry and inodes will be removed when they are done. - */ -struct eventfs_file *eventfs_add_subsystem_dir(const char *name, - struct dentry *parent) -{ - struct tracefs_inode *ti_parent; - struct eventfs_inode *ei_parent; - struct eventfs_file *ef; + /* Will call dput when the directory is removed */ + dget(dentry); - if (security_locked_down(LOCKDOWN_TRACEFS)) - return NULL; - - if (!parent) - return ERR_PTR(-EINVAL); - - ti_parent = get_tracefs(parent->d_inode); - ei_parent = ti_parent->private; + return ei; - ef = eventfs_prepare_ef(name, S_IFDIR, NULL, NULL, NULL); - if (IS_ERR(ef)) - return ef; - - mutex_lock(&eventfs_mutex); - list_add_tail(&ef->list, &ei_parent->e_top_files); - ef->d_parent = parent; - mutex_unlock(&eventfs_mutex); - return ef; + fail: + kfree(ei->d_children); + kfree(ei); + tracefs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); } -/** - * eventfs_add_dir - add eventfs dir to list to create later - * @name: the name of the file to create. - * @ef_parent: parent eventfs_file for this dir. - * - * This function adds eventfs dir to list. - * And all these dirs are created on the fly when they are looked up, - * and the dentry and inodes will be removed when they are done. - */ -struct eventfs_file *eventfs_add_dir(const char *name, - struct eventfs_file *ef_parent) +static void free_ei(struct rcu_head *head) { - struct eventfs_file *ef; - - if (security_locked_down(LOCKDOWN_TRACEFS)) - return NULL; + struct eventfs_inode *ei = container_of(head, struct eventfs_inode, rcu); - if (!ef_parent) - return ERR_PTR(-EINVAL); - - ef = eventfs_prepare_ef(name, S_IFDIR, NULL, NULL, NULL); - if (IS_ERR(ef)) - return ef; - - mutex_lock(&eventfs_mutex); - list_add_tail(&ef->list, &ef_parent->ei->e_top_files); - ef->d_parent = ef_parent->dentry; - mutex_unlock(&eventfs_mutex); - return ef; -} - -/** - * eventfs_add_events_file - add the data needed to create a file for later reference - * @name: the name of the file to create. - * @mode: the permission that the file should have. - * @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. - * - * This function is used to add the information needed to create a - * dentry/inode within the top level events directory. The file created - * will have the @mode permissions. The @data will be used to fill the - * inode.i_private when the open() call is done. The dentry and inodes are - * all created when they are referenced, and removed when they are no - * longer referenced. - */ -int eventfs_add_events_file(const char *name, umode_t mode, - struct dentry *parent, void *data, - const struct file_operations *fop) -{ - struct tracefs_inode *ti; - struct eventfs_inode *ei; - struct eventfs_file *ef; - - if (security_locked_down(LOCKDOWN_TRACEFS)) - return -ENODEV; - - if (!parent) - return -EINVAL; - - if (!(mode & S_IFMT)) - mode |= S_IFREG; - - if (!parent->d_inode) - return -EINVAL; - - ti = get_tracefs(parent->d_inode); - if (!(ti->flags & TRACEFS_EVENT_INODE)) - return -EINVAL; - - ei = ti->private; - ef = eventfs_prepare_ef(name, mode, fop, NULL, data); - - if (IS_ERR(ef)) - return -ENOMEM; - - mutex_lock(&eventfs_mutex); - list_add_tail(&ef->list, &ei->e_top_files); - ef->d_parent = parent; - mutex_unlock(&eventfs_mutex); - return 0; -} - -/** - * eventfs_add_file - add eventfs file to list to create later - * @name: the name of the file to create. - * @mode: the permission that the file should have. - * @ef_parent: parent eventfs_file 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. - * - * This function is used to add the information needed to create a - * file within a subdirectory of the events directory. The file created - * will have the @mode permissions. The @data will be used to fill the - * inode.i_private when the open() call is done. The dentry and inodes are - * all created when they are referenced, and removed when they are no - * longer referenced. - */ -int eventfs_add_file(const char *name, umode_t mode, - struct eventfs_file *ef_parent, - void *data, - const struct file_operations *fop) -{ - struct eventfs_file *ef; - - if (security_locked_down(LOCKDOWN_TRACEFS)) - return -ENODEV; - - if (!ef_parent) - return -EINVAL; - - if (!(mode & S_IFMT)) - mode |= S_IFREG; - - ef = eventfs_prepare_ef(name, mode, fop, NULL, data); - if (IS_ERR(ef)) - return -ENOMEM; - - mutex_lock(&eventfs_mutex); - list_add_tail(&ef->list, &ef_parent->ei->e_top_files); - ef->d_parent = ef_parent->dentry; - mutex_unlock(&eventfs_mutex); - return 0; -} - -static void free_ef(struct rcu_head *head) -{ - struct eventfs_file *ef = container_of(head, struct eventfs_file, rcu); - - kfree(ef->name); - kfree(ef->ei); - kfree(ef); + kfree_const(ei->name); + kfree(ei->d_children); + kfree(ei); } /** * eventfs_remove_rec - remove eventfs dir or file from list - * @ef: eventfs_file to be removed. - * @head: to create list of eventfs_file to be deleted - * @level: to check recursion depth + * @ei: eventfs_inode to be removed. * - * The helper function eventfs_remove_rec() is used to clean up and free the - * associated data from eventfs for both of the added functions. + * This function recursively remove eventfs_inode which + * contains info of file or dir. */ -static void eventfs_remove_rec(struct eventfs_file *ef, struct list_head *head, int level) +static void eventfs_remove_rec(struct eventfs_inode *ei, struct list_head *head, int level) { - struct eventfs_file *ef_child; + struct eventfs_inode *ei_child; - if (!ef) + if (!ei) return; /* * Check recursion depth. It should never be greater than 3: @@ -806,62 +817,68 @@ static void eventfs_remove_rec(struct eventfs_file *ef, struct list_head *head, if (WARN_ON_ONCE(level > 3)) return; - if (ef->ei) { - /* search for nested folders or files */ - list_for_each_entry_srcu(ef_child, &ef->ei->e_top_files, list, - lockdep_is_held(&eventfs_mutex)) { - eventfs_remove_rec(ef_child, head, level + 1); - } + /* search for nested folders or files */ + list_for_each_entry_srcu(ei_child, &ei->children, list, + lockdep_is_held(&eventfs_mutex)) { + eventfs_remove_rec(ei_child, head, level + 1); } - list_del_rcu(&ef->list); - list_add_tail(&ef->del_list, head); + list_del_rcu(&ei->list); + list_add_tail(&ei->del_list, head); } +static void unhook_dentry(struct dentry **dentry, struct dentry **list) +{ + if (*dentry) { + unsigned long ptr = (unsigned long)*list; + + /* Keep the dentry from being freed yet */ + dget(*dentry); + + /* + * Paranoid: The dget() above should prevent the dentry + * from being freed and calling eventfs_set_ei_status_free(). + * But just in case, set the link list LSB pointer to 1 + * and have eventfs_set_ei_status_free() check that to + * make sure that if it does happen, it will not think + * the d_fsdata is an eventfs_inode. + * + * For this to work, no eventfs_inode should be allocated + * on a odd space, as the ef should always be allocated + * to be at least word aligned. Check for that too. + */ + WARN_ON_ONCE(ptr & 1); + + (*dentry)->d_fsdata = (void *)(ptr | 1); + *list = *dentry; + *dentry = NULL; + } +} /** * eventfs_remove - remove eventfs dir or file from list - * @ef: eventfs_file to be removed. + * @ei: eventfs_inode to be removed. * * This function acquire the eventfs_mutex lock and call eventfs_remove_rec() */ -void eventfs_remove(struct eventfs_file *ef) +void eventfs_remove_dir(struct eventfs_inode *ei) { - struct eventfs_file *tmp; - LIST_HEAD(ef_del_list); + struct eventfs_inode *tmp; + LIST_HEAD(ei_del_list); struct dentry *dentry_list = NULL; struct dentry *dentry; + int i; - if (!ef) + if (!ei) return; mutex_lock(&eventfs_mutex); - eventfs_remove_rec(ef, &ef_del_list, 0); - list_for_each_entry_safe(ef, tmp, &ef_del_list, del_list) { - if (ef->dentry) { - unsigned long ptr = (unsigned long)dentry_list; - - /* Keep the dentry from being freed yet */ - dget(ef->dentry); - - /* - * Paranoid: The dget() above should prevent the dentry - * from being freed and calling eventfs_set_ef_status_free(). - * But just in case, set the link list LSB pointer to 1 - * and have eventfs_set_ef_status_free() check that to - * make sure that if it does happen, it will not think - * the d_fsdata is an event_file. - * - * For this to work, no event_file should be allocated - * on a odd space, as the ef should always be allocated - * to be at least word aligned. Check for that too. - */ - WARN_ON_ONCE(ptr & 1); - - ef->dentry->d_fsdata = (void *)(ptr | 1); - dentry_list = ef->dentry; - ef->dentry = NULL; - } - call_srcu(&eventfs_srcu, &ef->rcu, free_ef); + eventfs_remove_rec(ei, &ei_del_list, 0); + + list_for_each_entry_safe(ei, tmp, &ei_del_list, del_list) { + for (i = 0; i < ei->nr_entries; i++) + unhook_dentry(&ei->d_children[i], &dentry_list); + unhook_dentry(&ei->dentry, &dentry_list); + call_srcu(&eventfs_srcu, &ei->rcu, free_ei); } mutex_unlock(&eventfs_mutex); @@ -876,8 +893,8 @@ void eventfs_remove(struct eventfs_file *ef) mutex_lock(&eventfs_mutex); /* dentry should now have at least a single reference */ WARN_ONCE((int)d_count(dentry) < 1, - "dentry %p less than one reference (%d) after invalidate\n", - dentry, d_count(dentry)); + "dentry %px (%s) less than one reference (%d) after invalidate\n", + dentry, dentry->d_name.name, d_count(dentry)); mutex_unlock(&eventfs_mutex); dput(dentry); } diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 891653ba9cf3..34ffb2f8114e 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -385,7 +385,7 @@ static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode) ti = get_tracefs(inode); if (ti && ti->flags & TRACEFS_EVENT_INODE) - eventfs_set_ef_status_free(ti, dentry); + eventfs_set_ei_status_free(ti, dentry); iput(inode); } diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 4f2e49e2197b..298d3ecaf621 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -13,6 +13,41 @@ struct tracefs_inode { struct inode vfs_inode; }; +/* + * struct eventfs_inode - hold the properties of the eventfs directories. + * @list: link list into the parent directory + * @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_parent: pointer to the parent's dentry + * @d_children: The array of dentries to represent the files when created + * @data: The private data to pass to the callbacks + * @nr_entries: The number of items in @entries + */ +struct eventfs_inode { + struct list_head list; + const struct eventfs_entry *entries; + const char *name; + struct list_head children; + struct dentry *dentry; + struct dentry *d_parent; + struct dentry **d_children; + void *data; + /* + * Union - used for deletion + * @del_list: list of eventfs_inode to delete + * @rcu: eventfs_indoe to delete in RCU + * @is_freed: node is freed if one of the above is set + */ + union { + struct list_head del_list; + struct rcu_head rcu; + unsigned long is_freed; + }; + int nr_entries; +}; + static inline struct tracefs_inode *get_tracefs(const struct inode *inode) { return container_of(inode, struct tracefs_inode, vfs_inode); @@ -25,6 +60,6 @@ struct inode *tracefs_get_inode(struct super_block *sb); struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); struct dentry *eventfs_failed_creating(struct dentry *dentry); struct dentry *eventfs_end_creating(struct dentry *dentry); -void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry); +void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h index cf9f0c61796e..696f8dc4aa53 100644 --- a/include/linux/trace_events.h +++ b/include/linux/trace_events.h @@ -652,7 +652,7 @@ struct trace_event_file { struct list_head list; struct trace_event_call *event_call; struct event_filter __rcu *filter; - struct eventfs_file *ef; + struct eventfs_inode *ei; struct trace_array *tr; struct trace_subsystem_dir *system; struct list_head triggers; diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 009072792fa3..0c39704455d9 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -23,26 +23,25 @@ struct file_operations; struct eventfs_file; -struct dentry *eventfs_create_events_dir(const char *name, - struct dentry *parent); +typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data, + const struct file_operations **fops); -struct eventfs_file *eventfs_add_subsystem_dir(const char *name, - struct dentry *parent); +struct eventfs_entry { + const char *name; + eventfs_callback callback; +}; -struct eventfs_file *eventfs_add_dir(const char *name, - struct eventfs_file *ef_parent); +struct eventfs_inode; -int eventfs_add_file(const char *name, umode_t mode, - struct eventfs_file *ef_parent, void *data, - const struct file_operations *fops); +struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent, + const struct eventfs_entry *entries, + int size, void *data); -int eventfs_add_events_file(const char *name, umode_t mode, - struct dentry *parent, void *data, - const struct file_operations *fops); +struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent, + const struct eventfs_entry *entries, + int size, void *data); -void eventfs_remove(struct eventfs_file *ef); - -void eventfs_remove_events_dir(struct dentry *dentry); +void eventfs_remove_dir(struct eventfs_inode *ei); struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index fc00356a5a0a..33a6ea7145c2 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -9758,7 +9758,6 @@ static __init void create_trace_instances(struct dentry *d_tracer) static void init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) { - struct trace_event_file *file; int cpu; trace_create_file("available_tracers", TRACE_MODE_READ, d_tracer, @@ -9791,11 +9790,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer) trace_create_file("trace_marker", 0220, d_tracer, tr, &tracing_mark_fops); - file = __find_event_file(tr, "ftrace", "print"); - if (file && file->ef) - eventfs_add_file("trigger", TRACE_MODE_WRITE, file->ef, - file, &event_trigger_fops); - tr->trace_marker_file = file; + tr->trace_marker_file = __find_event_file(tr, "ftrace", "print"); trace_create_file("trace_marker_raw", 0220, d_tracer, tr, &tracing_mark_raw_fops); diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h index 51c0a970339e..02b727a54648 100644 --- a/kernel/trace/trace.h +++ b/kernel/trace/trace.h @@ -381,7 +381,7 @@ struct trace_array { struct dentry *dir; struct dentry *options; struct dentry *percpu_dir; - struct dentry *event_dir; + struct eventfs_inode *event_dir; struct trace_options *topts; struct list_head systems; struct list_head events; @@ -1345,7 +1345,7 @@ struct trace_subsystem_dir { struct list_head list; struct event_subsystem *subsystem; struct trace_array *tr; - struct eventfs_file *ef; + struct eventfs_inode *ei; int ref_count; int nr_events; }; diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 82cb22ad6d61..6595317c3830 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -984,7 +984,7 @@ static void remove_subsystem(struct trace_subsystem_dir *dir) return; if (!--dir->nr_events) { - eventfs_remove(dir->ef); + eventfs_remove_dir(dir->ei); list_del(&dir->list); __put_system_dir(dir); } @@ -1013,7 +1013,7 @@ void event_file_put(struct trace_event_file *file) static void remove_event_file_dir(struct trace_event_file *file) { - eventfs_remove(file->ef); + eventfs_remove_dir(file->ei); list_del(&file->list); remove_subsystem(file->system); free_event_filter(file->filter); @@ -2302,14 +2302,40 @@ create_new_subsystem(const char *name) return NULL; } -static struct eventfs_file * +int system_callback(const char *name, umode_t *mode, void **data, + const struct file_operations **fops) +{ + if (strcmp(name, "filter") == 0) + *fops = &ftrace_subsystem_filter_fops; + + else if (strcmp(name, "enable") == 0) + *fops = &ftrace_system_enable_fops; + + else + return 0; + + *mode = TRACE_MODE_WRITE; + return 1; +} + +static struct eventfs_inode * event_subsystem_dir(struct trace_array *tr, const char *name, - struct trace_event_file *file, struct dentry *parent) + struct trace_event_file *file, struct eventfs_inode *parent) { struct event_subsystem *system, *iter; struct trace_subsystem_dir *dir; - struct eventfs_file *ef; - int res; + struct eventfs_inode *ei; + int nr_entries; + static struct eventfs_entry system_entries[] = { + { + .name = "filter", + .callback = system_callback, + }, + { + .name = "enable", + .callback = system_callback, + } + }; /* First see if we did not already create this dir */ list_for_each_entry(dir, &tr->systems, list) { @@ -2317,7 +2343,7 @@ event_subsystem_dir(struct trace_array *tr, const char *name, if (strcmp(system->name, name) == 0) { dir->nr_events++; file->system = dir; - return dir->ef; + return dir->ei; } } @@ -2341,39 +2367,29 @@ event_subsystem_dir(struct trace_array *tr, const char *name, } else __get_system(system); - ef = eventfs_add_subsystem_dir(name, parent); - if (IS_ERR(ef)) { + /* ftrace only has directories no files */ + if (strcmp(name, "ftrace") == 0) + nr_entries = 0; + else + nr_entries = ARRAY_SIZE(system_entries); + + ei = eventfs_create_dir(name, parent, system_entries, nr_entries, dir); + if (!ei) { pr_warn("Failed to create system directory %s\n", name); __put_system(system); goto out_free; } - dir->ef = ef; + dir->ei = ei; dir->tr = tr; dir->ref_count = 1; dir->nr_events = 1; dir->subsystem = system; file->system = dir; - /* the ftrace system is special, do not create enable or filter files */ - if (strcmp(name, "ftrace") != 0) { - - res = eventfs_add_file("filter", TRACE_MODE_WRITE, - dir->ef, dir, - &ftrace_subsystem_filter_fops); - if (res) { - kfree(system->filter); - system->filter = NULL; - pr_warn("Could not create tracefs '%s/filter' entry\n", name); - } - - eventfs_add_file("enable", TRACE_MODE_WRITE, dir->ef, dir, - &ftrace_system_enable_fops); - } - list_add(&dir->list, &tr->systems); - return dir->ef; + return dir->ei; out_free: kfree(dir); @@ -2422,15 +2438,134 @@ event_define_fields(struct trace_event_call *call) return ret; } +static int event_callback(const char *name, umode_t *mode, void **data, + const struct file_operations **fops) +{ + struct trace_event_file *file = *data; + struct trace_event_call *call = file->event_call; + + if (strcmp(name, "format") == 0) { + *mode = TRACE_MODE_READ; + *fops = &ftrace_event_format_fops; + *data = call; + return 1; + } + + /* + * Only event directories that can be enabled should have + * triggers or filters, with the exception of the "print" + * event that can have a "trigger" file. + */ + if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) { + if (call->class->reg && strcmp(name, "enable") == 0) { + *mode = TRACE_MODE_WRITE; + *fops = &ftrace_enable_fops; + return 1; + } + + if (strcmp(name, "filter") == 0) { + *mode = TRACE_MODE_WRITE; + *fops = &ftrace_event_filter_fops; + return 1; + } + } + + if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) || + strcmp(trace_event_name(call), "print") == 0) { + if (strcmp(name, "trigger") == 0) { + *mode = TRACE_MODE_WRITE; + *fops = &event_trigger_fops; + return 1; + } + } + +#ifdef CONFIG_PERF_EVENTS + if (call->event.type && call->class->reg && + strcmp(name, "id") == 0) { + *mode = TRACE_MODE_READ; + *data = (void *)(long)call->event.type; + *fops = &ftrace_event_id_fops; + return 1; + } +#endif + +#ifdef CONFIG_HIST_TRIGGERS + if (strcmp(name, "hist") == 0) { + *mode = TRACE_MODE_READ; + *fops = &event_hist_fops; + return 1; + } +#endif +#ifdef CONFIG_HIST_TRIGGERS_DEBUG + if (strcmp(name, "hist_debug") == 0) { + *mode = TRACE_MODE_READ; + *fops = &event_hist_debug_fops; + return 1; + } +#endif +#ifdef CONFIG_TRACE_EVENT_INJECT + if (call->event.type && call->class->reg && + strcmp(name, "inject") == 0) { + *mode = 0200; + *fops = &event_inject_fops; + return 1; + } +#endif + return 0; +} + static int -event_create_dir(struct dentry *parent, struct trace_event_file *file) +event_create_dir(struct eventfs_inode *parent, struct trace_event_file *file) { struct trace_event_call *call = file->event_call; - struct eventfs_file *ef_subsystem = NULL; struct trace_array *tr = file->tr; - struct eventfs_file *ef; + struct eventfs_inode *e_events; + struct eventfs_inode *ei; const char *name; + int nr_entries; int ret; + static struct eventfs_entry event_entries[] = { + { + .name = "enable", + .callback = event_callback, + }, + { + .name = "filter", + .callback = event_callback, + }, + { + .name = "trigger", + .callback = event_callback, + }, + { + .name = "format", + .callback = event_callback, + }, +#ifdef CONFIG_PERF_EVENTS + { + .name = "id", + .callback = event_callback, + }, +#endif +#ifdef CONFIG_HIST_TRIGGERS + { + .name = "hist", + .callback = event_callback, + }, +#endif +#ifdef CONFIG_HIST_TRIGGERS_DEBUG + { + .name = "hist_debug", + .callback = event_callback, + }, +#endif +#ifdef CONFIG_TRACE_EVENT_INJECT + { + .name = "inject", + .callback = event_callback, + }, +#endif + }; /* * If the trace point header did not define TRACE_SYSTEM @@ -2440,29 +2575,20 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file) if (WARN_ON_ONCE(strcmp(call->class->system, TRACE_SYSTEM) == 0)) return -ENODEV; - ef_subsystem = event_subsystem_dir(tr, call->class->system, file, parent); - if (!ef_subsystem) + e_events = event_subsystem_dir(tr, call->class->system, file, parent); + if (!e_events) return -ENOMEM; + nr_entries = ARRAY_SIZE(event_entries); + name = trace_event_name(call); - ef = eventfs_add_dir(name, ef_subsystem); - if (IS_ERR(ef)) { + ei = eventfs_create_dir(name, e_events, event_entries, nr_entries, file); + if (IS_ERR(ei)) { pr_warn("Could not create tracefs '%s' directory\n", name); return -1; } - file->ef = ef; - - if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) - eventfs_add_file("enable", TRACE_MODE_WRITE, file->ef, file, - &ftrace_enable_fops); - -#ifdef CONFIG_PERF_EVENTS - if (call->event.type && call->class->reg) - eventfs_add_file("id", TRACE_MODE_READ, file->ef, - (void *)(long)call->event.type, - &ftrace_event_id_fops); -#endif + file->ei = ei; ret = event_define_fields(call); if (ret < 0) { @@ -2470,35 +2596,6 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file) return ret; } - /* - * Only event directories that can be enabled should have - * triggers or filters. - */ - if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) { - eventfs_add_file("filter", TRACE_MODE_WRITE, file->ef, - file, &ftrace_event_filter_fops); - - eventfs_add_file("trigger", TRACE_MODE_WRITE, file->ef, - file, &event_trigger_fops); - } - -#ifdef CONFIG_HIST_TRIGGERS - eventfs_add_file("hist", TRACE_MODE_READ, file->ef, file, - &event_hist_fops); -#endif -#ifdef CONFIG_HIST_TRIGGERS_DEBUG - eventfs_add_file("hist_debug", TRACE_MODE_READ, file->ef, file, - &event_hist_debug_fops); -#endif - eventfs_add_file("format", TRACE_MODE_READ, file->ef, call, - &ftrace_event_format_fops); - -#ifdef CONFIG_TRACE_EVENT_INJECT - if (call->event.type && call->class->reg) - eventfs_add_file("inject", 0200, file->ef, file, - &event_inject_fops); -#endif - return 0; } @@ -3644,30 +3741,65 @@ static __init int setup_trace_event(char *str) } __setup("trace_event=", setup_trace_event); +static int events_callback(const char *name, umode_t *mode, void **data, + const struct file_operations **fops) +{ + if (strcmp(name, "enable") == 0) { + *mode = TRACE_MODE_WRITE; + *fops = &ftrace_tr_enable_fops; + return 1; + } + + if (strcmp(name, "header_page") == 0) + *data = ring_buffer_print_page_header; + + else if (strcmp(name, "header_event") == 0) + *data = ring_buffer_print_entry_header; + + else + return 0; + + *mode = TRACE_MODE_READ; + *fops = &ftrace_show_header_fops; + return 1; +} + /* Expects to have event_mutex held when called */ static int create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) { - struct dentry *d_events; + struct eventfs_inode *e_events; struct dentry *entry; - int error = 0; + int nr_entries; + static struct eventfs_entry events_entries[] = { + { + .name = "enable", + .callback = events_callback, + }, + { + .name = "header_page", + .callback = events_callback, + }, + { + .name = "header_event", + .callback = events_callback, + }, + }; entry = trace_create_file("set_event", TRACE_MODE_WRITE, parent, tr, &ftrace_set_event_fops); if (!entry) return -ENOMEM; - d_events = eventfs_create_events_dir("events", parent); - if (IS_ERR(d_events)) { + nr_entries = ARRAY_SIZE(events_entries); + + e_events = eventfs_create_events_dir("events", parent, events_entries, + nr_entries, tr); + if (IS_ERR(e_events)) { pr_warn("Could not create tracefs 'events' directory\n"); return -ENOMEM; } - error = eventfs_add_events_file("enable", TRACE_MODE_WRITE, d_events, - tr, &ftrace_tr_enable_fops); - if (error) - return -ENOMEM; - /* There are not as crucial, just warn if they are not created */ trace_create_file("set_event_pid", TRACE_MODE_WRITE, parent, @@ -3677,16 +3809,7 @@ create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) TRACE_MODE_WRITE, parent, tr, &ftrace_set_event_notrace_pid_fops); - /* ring buffer internal formats */ - eventfs_add_events_file("header_page", TRACE_MODE_READ, d_events, - ring_buffer_print_page_header, - &ftrace_show_header_fops); - - eventfs_add_events_file("header_event", TRACE_MODE_READ, d_events, - ring_buffer_print_entry_header, - &ftrace_show_header_fops); - - tr->event_dir = d_events; + tr->event_dir = e_events; return 0; } @@ -3770,7 +3893,7 @@ int event_trace_del_tracer(struct trace_array *tr) down_write(&trace_event_sem); __trace_remove_event_dirs(tr); - eventfs_remove_events_dir(tr->event_dir); + eventfs_remove_dir(tr->event_dir); up_write(&trace_event_sem); tr->event_dir = NULL; From patchwork Tue Feb 6 12:09:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1496657dyb; Tue, 6 Feb 2024 04:18:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTpb9/8cs2UDJGmtDo8W/GUkHZCwlU5/xuqh+SgrrA8HraNnLmlN+rKNahoTm0q+UXR0vO X-Received: by 2002:a05:620a:b8b:b0:785:59fa:9b38 with SMTP id k11-20020a05620a0b8b00b0078559fa9b38mr12302707qkh.3.1707221918748; Tue, 06 Feb 2024 04:18:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221918; cv=pass; d=google.com; s=arc-20160816; b=MC3wOxnGmPoN+f026hXJyH/JOxYm+L80E+uLsd9c0rBhogFSlxWrHudu2EQNMfk6wF llkaYXX2W5JzIaEcT8PJPorxEe4PAosYpedRVQVv36i7Xhbj3//1Ph1zqyxxQUUi7TVD JptpH842Ar3JZFNNi5TVTlpj2AOaB6VN8jh7wKQVRbhOFfZY8xJMbz3dagwsucpO3cDv ir/AGvMmHfHNaPA13z2jHszyUqRiaqdtseHMEtSUGOAvMMUm5Ck99hOp2PFIbJUFfTvn A+BPR6B+wvTRNE5NLF+ThScR4/ZXOS4YR3XqivAmi7kzfcQG95MXUmY9A7/GFSn3G4XL GkNw== 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=cuxUpn7P+XyYdAXWckL1D93jFQg/Q4qoJ+VPSLKM9A0=; fh=pGM5mbbJHVTzlcxldXfgWfeR+WrQIlFGE/IkCpXja5s=; b=hG/mXk8gvEAG2e/JQc3J3k3K6rNLmtu30KOUbw1hGrxQuFBbeuwn1ef5SrHrwplv8C jBRi0h4BNDD7KLxMc3OmUTfIhcB+QnTXU59ReFsSQkvafBJskzcNV8wuLfY0drmOE0nV wuuQlo3gB8CPGpwbiHynNLiDUat+JUBVTZM0m2i+7YpO4d3NsMIjsabgknwoGARa59Hy h5ld4vDFzGki7vLkXCEOn+cd/P7J9PfmEJpB2UQolDcef41Qjhl+sl03UuoAPoBtsCf2 9l5J/Zoje/AjEA593OTwCuIzZohlwrENJaaGb1smoDy4J9hx+n3MvZybjfKm84McCP/Y 4mkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54884-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54884-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVcQLdzQ3QQUufBBlYjmqrnA0jAjVbxyPUkD8Ae4l7tKvorwM2mBLmq2Yc1qOX4CUtr98gSy8DFlU2Rzad1CXB0EQ03TA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id w19-20020ae9e513000000b0078545ce745fsi2021389qkf.326.2024.02.06.04.18.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:18:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54884-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54884-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54884-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 870791C24036 for ; Tue, 6 Feb 2024 12:18:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F97F13B281; Tue, 6 Feb 2024 12:09:25 +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 C691A1353F6; Tue, 6 Feb 2024 12:09:19 +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=1707221359; cv=none; b=j10sjl/smn0N9a0Dq5uXHp7TIP2NIxB5SuimRFe73cwtsQoifQzV2qw2zkIBgG1H2luZXCWxbxcVgW9IE/vJL52q9CNA30Ly5sanN3uIU1uiWgxFsU/lLEJCeBQlkRwAIFJu1pe23k13JLVg1p7rHrXSZ8WkfMPB0WU61+GyNIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221359; c=relaxed/simple; bh=rJbSuvhtLipDc17VpOUCoHRbi16A8mbSZ9ZCLhURrio=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=nC/NKnTaV3MMCJa0VmLVPtN/TU1X9gdWosO9wEtfwUOd+HYTnI+AP1DVmtt5dmpHX9dkwhA0D460Mdb9Ddw7CYUpvonUbon9RT5AwDxsJQPgph1gW5VvaEhqidC86PAfgjxHg3Ncymw7H4VjQiKvLZ7qZuKTBFbCMCDRv9tNPJw= 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 57C93C43394; Tue, 6 Feb 2024 12:09:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGp-00000006b5L-3Rzc; Tue, 06 Feb 2024 07:09:47 -0500 Message-ID: <20240206120947.686070579@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:13 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , kernel test robot Subject: [v6.6][PATCH 08/57] eventfs: Use eventfs_remove_events_dir() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151930756993753 X-GMAIL-MSGID: 1790151930756993753 From: "Steven Rostedt (Google)" The update to removing the eventfs_file changed the way the events top level directory was handled. Instead of returning a dentry, it now returns the eventfs_inode. In this changed, the removing of the events top level directory is not much different than removing any of the other directories. Because of this, the removal just called eventfs_remove_dir() instead of eventfs_remove_events_dir(). Although eventfs_remove_dir() does the clean up, it misses out on the dget() of the ei->dentry done in eventfs_create_events_dir(). It makes more sense to match eventfs_create_events_dir() with a specific function eventfs_remove_events_dir() and this specific function can then perform the dput() to the dentry that had the dget() when it was created. Fixes: 5790b1fb3d67 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202310051743.y9EobbUr-lkp@intel.com/ Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 2819f23ac12ce93ff79ca7a54597df9a4a1f6331) --- fs/tracefs/event_inode.c | 19 +++++++------------ include/linux/tracefs.h | 1 + kernel/trace/trace_events.c | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index eab18b157ef5..1ccd100bc565 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -901,22 +901,17 @@ void eventfs_remove_dir(struct eventfs_inode *ei) } /** - * eventfs_remove_events_dir - remove eventfs dir or file from list - * @dentry: events's dentry to be removed. + * eventfs_remove_events_dir - remove the top level eventfs directory + * @ei: the event_inode returned by eventfs_create_events_dir(). * - * This function remove events main directory + * This function removes the events main directory */ -void eventfs_remove_events_dir(struct dentry *dentry) +void eventfs_remove_events_dir(struct eventfs_inode *ei) { - struct tracefs_inode *ti; - - if (!dentry || !dentry->d_inode) - return; + struct dentry *dentry = ei->dentry; - ti = get_tracefs(dentry->d_inode); - if (!ti || !(ti->flags & TRACEFS_EVENT_INODE)) - return; + eventfs_remove_dir(ei); - d_invalidate(dentry); + /* Matches the dget() from eventfs_create_events_dir() */ dput(dentry); } diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 0c39704455d9..13359b1a35d1 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -41,6 +41,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode const struct eventfs_entry *entries, int size, void *data); +void eventfs_remove_events_dir(struct eventfs_inode *ei); void eventfs_remove_dir(struct eventfs_inode *ei); struct dentry *tracefs_create_file(const char *name, umode_t mode, diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 6595317c3830..697163f8f670 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c @@ -3893,7 +3893,7 @@ int event_trace_del_tracer(struct trace_array *tr) down_write(&trace_event_sem); __trace_remove_event_dirs(tr); - eventfs_remove_dir(tr->event_dir); + eventfs_remove_events_dir(tr->event_dir); up_write(&trace_event_sem); tr->event_dir = NULL; From patchwork Tue Feb 6 12:09:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1496481dyb; Tue, 6 Feb 2024 04:18:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IFuZlCClay+eLV+/9VNO/hW6FzKp7HaFsrsifRlCqxASQ5gB8QqdYST3RaDDStO101PiMSK X-Received: by 2002:a67:f658:0:b0:46d:21fa:4a07 with SMTP id u24-20020a67f658000000b0046d21fa4a07mr2705024vso.12.1707221898076; Tue, 06 Feb 2024 04:18:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221898; cv=pass; d=google.com; s=arc-20160816; b=Ys6ykRRn6sCbkWO8LkzOTVaaODx80pRjZXBQObKDEF36iad7ksk/vRxNbYFNBQ/kYy z+5ox9l9MmyEaWY7eyEBIsk42dQc+cMNPP1tPiAfYaExAv+jqeCCTYS5wWsIV7vqN1Pi 43v1IlPXf/EywHsKoeK4FOxEzFNA+2gGnNMo0keGL6s4tr2L2eXqd6tKdqdE4jwG6d1j TcsjWKYv9RpONyog8uU7K5EDQPIGSQIsskZ4CqWkuZlExhqS7rkJ9HvbK0snfkwo9aLy N9Gelpv5xyVTO3S0NnYiwVMO6/nuvwdyWu+fpvaM6/9ga1001+N6jpdHpWs2oVYAEunK xk1Q== 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=3iwUmHWTXbz8u79IY/p9Fqrev4clGIsNQ9gW8d7QDr8=; fh=XztBmt7SpU3hWQ8LTwh60qEt1olkK8QMGvp+t8jJHG0=; b=Oi7yXV1MXIwQRT6bB9juIEG44h1lAeRwAtD7ATzl1ZWkGWCsGTQb0F4sZg2iDJ0acv 1V40wAxNpC8vmwtByCcHPvjHjaE8hqN3LuCcADS+4aJ8uRICjJMr7/dCHkw7gg2yOlqE albQoHka5xMVzQQXV0qFZ6oog8mWgVGsga9tPJutnGYVR3S0CUzPosci396IhM4uoDYH /K+4+aNx+S4rEI5Nf+oww39bw0mcm9dP1QKdAWKHHOoYKnFF5IUNpPPaPawp4F2VBtuE YCygXFFJ6EIArdLJa26F6FNivNFhEWhwSka0XA55KAHgvgxbDuUQYuhyhNEkR5FuJ1Xj 1lEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54883-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWgSjQUjk/R2pYKLn6mY+qjV3VGnRXzTFULi6svfdhLw0MRJCQlG+4f5NjxgbVhCivxILsIj4xnaeBj9FzJzmFzWh+iUA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g14-20020ad457ae000000b006852904842csi2244292qvx.276.2024.02.06.04.18.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:18:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54883-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54883-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 D7E5C1C24015 for ; Tue, 6 Feb 2024 12:18:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13CB113AA33; Tue, 6 Feb 2024 12:09:25 +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 9FB0B1353E2; Tue, 6 Feb 2024 12:09:19 +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=1707221359; cv=none; b=JPKlCowuhEJYgsDuDfQjSEw7maJkUABSzQIZZFDiHpO3GvBPaOsKkMxunVleiIl+3uTfx90gxp3Wz5hWrtkkzG3thmC831cmhPcZpNt58NmyR82dncJ4Wkpbyo5MhGT7oc5akC6nJHz2TPuhb3/rL0CFQFjVQOGiPV/dWsM+8Ao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221359; c=relaxed/simple; bh=U8O8HbXTyCH85fzphuPj2gzKXQlZuOW81DY3SFrBp6U=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=lMqlO1EERJ/qxICVaJXvGVCP27hy+3GlQu7YsshPtEMkniIa+BFbVgCzpKPX4Pi+2QfNOoBDHvG5p2T7bCycXNPrrzYBGRINvTRpIhqZmwiG+qjbbMQM80UWHtBK9nXcF2JbUR7igd9MVyGZEnGWOqbufFeRuBCNm04pECVyIrI= 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 891EBC4166B; Tue, 6 Feb 2024 12:09:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGp-00000006b5q-47OS; Tue, 06 Feb 2024 07:09:47 -0500 Message-ID: <20240206120947.843106843@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:14 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Kees Cook , Nathan Chancellor Subject: [v6.6][PATCH 09/57] eventfs: Use ERR_CAST() in eventfs_create_events_dir() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151908983469867 X-GMAIL-MSGID: 1790151908983469867 From: Nathan Chancellor When building with clang and CONFIG_RANDSTRUCT_FULL=y, there is an error due to a cast in eventfs_create_events_dir(): fs/tracefs/event_inode.c:734:10: error: casting from randomized structure pointer type 'struct dentry *' to 'struct eventfs_inode *' 734 | return (struct eventfs_inode *)dentry; | ^ 1 error generated. Use the ERR_CAST() function to resolve the error, as it was designed for this exact situation (casting an error pointer to another type). Link: https://lore.kernel.org/linux-trace-kernel/20231018-ftrace-fix-clang-randstruct-v1-1-338cb214abfb@kernel.org Closes: https://github.com/ClangBuiltLinux/linux/issues/1947 Fixes: 5790b1fb3d67 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reviewed-by: Kees Cook Signed-off-by: Nathan Chancellor Signed-off-by: Steven Rostedt (Google) (cherry picked from commit b8a555dc31e5aa18d976de0bc228006e398a2e7d) --- fs/tracefs/event_inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1ccd100bc565..9f19b6608954 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -731,7 +731,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return NULL; if (IS_ERR(dentry)) - return (struct eventfs_inode *)dentry; + return ERR_CAST(dentry); ei = kzalloc(sizeof(*ei), GFP_KERNEL); if (!ei) From patchwork Tue Feb 6 12:09:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197387 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1496635dyb; Tue, 6 Feb 2024 04:18:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFin+XloxY9cis7pOE0uKEg/A2OmOc/mG0AXn1ztHVkr4LnMrebLgmQNZ06l+yoq3XrylTN X-Received: by 2002:a05:6122:4d10:b0:4c0:1afb:b4cc with SMTP id fi16-20020a0561224d1000b004c01afbb4ccmr2760079vkb.13.1707221915926; Tue, 06 Feb 2024 04:18:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221915; cv=pass; d=google.com; s=arc-20160816; b=Fkcr1+xif0lYhi/6QG9MuoZ/hzHsS5+v86Dc6xX45Jbif+1S5T8BPMB+3izb5+LhQ5 IzmWevXWZOB0mXYkRw9Yhuy2I+diMq5DDh+60CGJmZHxyKsCIEKQ76EpcQHlD5GyD569 yGR/bq88Hbo0eHddPXnfLNcd9UvWRHwJxvgH7wL1oK9MKftB7EgX+WxsfEb5T7uC7QKN FOGhmcXfLcX28oo4my6H/rkMFJ9CWR39UCeh/r9l0rpfYl2diBlwQFNEMOafbMT2yieN 9HJmXv2JYk+SouRBBiqdpsIPTDUKkHJWzjglzowGZBsLqEMmlDOkR/JewiviTjsevTKT ZuAQ== 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=Hfusfzjs0UZKElxuqb1X8cC1ErykGUVmsm2+3ArQrQo=; fh=BOxf5attRC46ACH3+g1OVz0NDaYUyKC2bLN2g+NW3AA=; b=l2vVbh3N+FeQ6Wo7Fxb93pyR7EXh+LXM3l2JyeAfJktMK69uNG4sWghdsetE8hehoS chpxanBUXoRuMRMk2s5WW/iORbDJOti8PzP43qbzBARpvVTp4IqrEnvgIiR2jZL+aqJn QG3//sYTq0OhnACG61sQV97fPBefnhWVMrC0dLWMGvhC/IY4jUf0BeCzlaC3npreJ07g ejHoJm64KXKEnU7GQfsCnnV9PI/gt0b2LdiBgo9twaLKf/1ekQlPzabZiQEFeKgv27yX 718cu5793zqTShS8Fc8Ef6+OXbPe8ZIvHB9/DfSrWoLVC74DW5hBwIVRHB193uXPs1wn tFbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54885-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54885-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWVgaLy8QeJCb22ZsgGJ0aEFeIVNkbU0Q/6p9IXKQx9I8LZ3/uYjpceHzViqOpOGzLGj6H7hO8bfKBlvftJWo3R8KxP+Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kd26-20020a056214401a00b006819bba47f3si2551945qvb.508.2024.02.06.04.18.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:18:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54885-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54885-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54885-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 988A31C23CF4 for ; Tue, 6 Feb 2024 12:18:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FAC513B282; Tue, 6 Feb 2024 12:09:25 +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 C33701353F4; Tue, 6 Feb 2024 12:09:19 +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=1707221359; cv=none; b=LXUQa516Csi2cv3g4WpoQVbwtqRfhQY1mvAut+90eCmpeCbGhXPrnkhuklbDKiNMWCXNZtLAKm6FtpIW0uVm/Occ0IC3b2k25VObh3J1aIEfEy5naLYy2wiAXrBtJuSyDTdvgr7fRin47iJzP1KWDqZvX6BtHgkKlyIw4rZ8jMI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221359; c=relaxed/simple; bh=yxagGa01h2asUZexPZIm50VtsB5OwdxwdGuVM2gCW2Q=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pH9bKuaCWChFkY6iw3xGpc3FdOqfbd6X0dGf+GOECCRBSzHpi6JBQ7gIN28NcSaFzz8veR+sHgwjoZ9d1gfqrTCvs0YO0hjyBUcTD3YShsgOPR6TO/GfQo64QqAc9Fo60ljk2x4y1wdUAbKZPxqIkTKADFH+gjrBwfe9GzIwBAg= 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 AE411C433B1; Tue, 6 Feb 2024 12:09:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGq-00000006b6L-0bJb; Tue, 06 Feb 2024 07:09:48 -0500 Message-ID: <20240206120948.003109160@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:15 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Julia Lawall Subject: [v6.6][PATCH 10/57] eventfs: Fix failure path in eventfs_create_events_dir() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151927542280314 X-GMAIL-MSGID: 1790151927542280314 From: "Steven Rostedt (Google)" The failure path of allocating ei goes to a path that dereferences ei. Add another label that skips over the ei dereferences to do the rest of the clean up. Link: https://lore.kernel.org/all/70e7bace-561c-95f-1117-706c2c220bc@inria.fr/ Link: https://lore.kernel.org/linux-trace-kernel/20231019204132.6662fef0@gandalf.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Fixes: 5790b1fb3d67 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: Julia Lawall Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 7e8ad67c9b5c11e990c320ed7e7563f2301672a7) --- fs/tracefs/event_inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9f19b6608954..1885f1f1f339 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -735,7 +735,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry ei = kzalloc(sizeof(*ei), GFP_KERNEL); if (!ei) - goto fail; + goto fail_ei; inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) @@ -781,6 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry fail: kfree(ei->d_children); kfree(ei); + fail_ei: tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } From patchwork Tue Feb 6 12:09:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1496507dyb; Tue, 6 Feb 2024 04:18:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJAlLcmA8nOMZPX6DRW7arWpxmZmYygxNqm+p/TPU3ud+gkxAxF2i2F28yyN1x3meOYckE X-Received: by 2002:a05:6a20:841f:b0:19b:a07a:3495 with SMTP id c31-20020a056a20841f00b0019ba07a3495mr1963848pzd.25.1707221900222; Tue, 06 Feb 2024 04:18:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221900; cv=pass; d=google.com; s=arc-20160816; b=A5Nfa2uRunpQ0qJ4cHPlMRs2cHuwxQ6CwHAZrjrMV01UJHoJUYjduVdiADWpTpgPvF JxjjBN6NIpQTPhdgSCXNZ9B4VG+d/Aqvp19AgETK6w4tx3UyDhG1tFGG9Hltu8o+wL7l iuRTrU6A9Qs/iQXoIRdOGQdlbIdRgUtH/kI3qJSir6hyOUJyOuti+0uCtEey0fkcyY47 ZR0KGbkDZRCdpXgUqToCPG6a4cQeLwIsfS0HXeWX1S8icwsUbXmneFuon0jR4D2r+7KB rGs8bsp7UJxErmurpAnVzyLC7BzKufKHii8ZgkJQoxmfNKw1Jswh0zm1LSPRPcwTifHX sGZA== 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=OViA1JekFB0y1DYK7su6HDmcEWviw0D/LB+Ve6JrJQo=; fh=y3G01HOWvmV8M32YoDlif7RT2OZl3GTVwW2gHWIDFek=; b=MlyIC+k9wuI4kXfoQR7+SVeMGQUKvFM3f/7oDgOYDj/zjZudmvrtUhLKYDeXtjJfUC wgN3HGE3vxfGO3MjjBNXqXW2B2n0XyktEKvFvySx3GVLhDuvP7Rbc+jCmJtOSu/819AS MYr+ZxhxtEnaCbzP1p5GYxzCgGsS/vCS58ztVDB7I5WpAeTq2po6jUpohsTX3wUNHISj XGwwC+rKTZ1xpSqYXrGjaVm3Yd2kteg1m36rK01Y9xGZb8w5Z8pupotMEaBSxOB3RsPt FmDuUwWIa+giAOlpbYup/4OjkZ85QWHQ9NTsTLhInksi6FxxdT7i14o/oul3uZt4wUxC 7CtA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54886-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54886-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXJUHeffyYti9f56+TeFf+LGFUrLCvQlYRaM0F0RQqq7gebQemrMB62q4wMy0BroR1oPKPAH46ZllkH3Efqj5aputha2Q== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w30-20020a63491e000000b005c6763c0965si1629524pga.58.2024.02.06.04.18.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:18:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54886-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-54886-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54886-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 DC5D52831DF for ; Tue, 6 Feb 2024 12:18:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15D2513AA34; Tue, 6 Feb 2024 12:09:25 +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 5A318135A48; Tue, 6 Feb 2024 12:09:20 +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=1707221360; cv=none; b=NxpmgoEQw1/FDCVamYN1EiWL+Skkv719a1dB9qySkzNifx1bVcW4kztA9DpCA1ZxvA3NsNKG6nmwi40S6xISzbkyRSlVmxe/eQbt4wPvCDEy9vk0U/Q3zGnW6oAv8tWMxn9dwtvm6cMTtIHPTnhK126izGKUUKIwXP++uJrB8qU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221360; c=relaxed/simple; bh=XeV1VUlwi1FILGXqC+sGicaJJYQTw6C1fAun/XWmlNM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=BnX746K1P/68WAxBGvM2OuTecLdSoDH29ZCNN4ZPQ1JwjAq+wBRrlz9BughYX3jG4Iy6Gcp1tKS/75QLgYs0r1/nyFMOMUx50eqA+MgulCyB10p412B1sVjNjcFPeA+/NobXrKRYyofLnV9HRGK9u/6tQD5PpJJYaF+7MFG7VKQ= 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 E168CC43394; Tue, 6 Feb 2024 12:09:19 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGq-00000006b6p-1Iig; Tue, 06 Feb 2024 07:09:48 -0500 Message-ID: <20240206120948.165080330@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:16 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Abaci Robot , Jiapeng Chong Subject: [v6.6][PATCH 11/57] tracefs/eventfs: Modify mismatched function name References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151911124920338 X-GMAIL-MSGID: 1790151911124920338 From: Jiapeng Chong No functional modification involved. fs/tracefs/event_inode.c:864: warning: expecting prototype for eventfs_remove(). Prototype was for eventfs_remove_dir() instead. Link: https://lore.kernel.org/linux-trace-kernel/20231019031353.73846-1-jiapeng.chong@linux.alibaba.com Reported-by: Abaci Robot Closes: https://bugzilla.openanolis.cn/show_bug.cgi?id=6939 Signed-off-by: Jiapeng Chong Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 64bf2f685c795e75dd855761c75a193ee5998731) --- fs/tracefs/event_inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1885f1f1f339..09ab93357957 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -856,7 +856,7 @@ static void unhook_dentry(struct dentry **dentry, struct dentry **list) } } /** - * eventfs_remove - remove eventfs dir or file from list + * eventfs_remove_dir - remove eventfs dir or file from list * @ei: eventfs_inode to be removed. * * This function acquire the eventfs_mutex lock and call eventfs_remove_rec() From patchwork Tue Feb 6 12:09:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1496817dyb; Tue, 6 Feb 2024 04:18:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHs5QkauF8YVQraXArb8G83o8ZQaAHqM23DBbeapbSo0eRTEKuWOhWFebv15ndMArudHEi2 X-Received: by 2002:ac8:44d4:0:b0:42a:cdb9:5d9f with SMTP id b20-20020ac844d4000000b0042acdb95d9fmr1917380qto.17.1707221937373; Tue, 06 Feb 2024 04:18:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221937; cv=pass; d=google.com; s=arc-20160816; b=HsbQF6tLuGyUAG6ccNP1qbIq3zO+UuTVPSGCBNJCDj7mjhci2zV2mu8wAr77xdSMmX A4VnuKmWyIKZlewMOubZZgJL94oF7cFJ6P40qTjQrzT3rov08ShH13civBbrpnEJA9dJ xOv+JIfFfOQtrIjVP4jTBdhbYXMCvFsu7H+dCzRCZFGuTeyTcU8blkANWC0EySMvQWBB ChoFOZXVoAf5HLcj68IVVO0eanLjugSc8n8vNfGwAKFniaAPSvirPVFR1WTLvgKonRLm 4/T6oGxisdA/Us1+BOBLcqs0HvW2fO1NaU3s6hSTXy5plzmgnIEUb11gC8VzCeLD2PJ8 +mBg== 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=ZlGoeyKLS0nVE4T8xfdj7NnUNORmtQA9/juv1ILReAQ=; fh=zz0Se07kAtH2vw7RhkVStRGlxv+1orb3A9VCOgyerrQ=; b=o8PR5HQXyPtHPHtaLqv5CjQbAhs6Wy5WtRvNFjdbZDBZ+bozalYHbC9N4vGN44rjbt vPDQYX2bT2T6+q4awxeWZXppqH0LxYz3qdZs/pK8Fo/6VSbiva5k0edOY58qBjpBVBq0 8fw7S9l5OfQUH699gqW9LLpwK/ckGXhdg/+K7sb1KNfcd1uriHCKyVCLPf73ZkkNMppC apAzm8qw2XwEUgvc+QeCUjxBnxrP89ASyaXgXqMKMIDs1ZLOvZrDMvaDU7nery23U693 FEbrXf62W+ssPTlRR94COJEtbS/ioPBiWZ9yS323aBw5Zvm53R/D8KmLRuxeRl2+QoiH 0QQw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54887-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVI4/0sSo15nvYfFuk66E3kSCHlQ5eU8S3dx3/XwtWPQVP9R+SblXag96xfB2mV319kMur3UxStR1hanJ/M46OzNvfSrg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b9-20020ac85bc9000000b0042c0b21c031si2228967qtb.183.2024.02.06.04.18.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:18:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54887-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54887-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 25F261C216E1 for ; Tue, 6 Feb 2024 12:18:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43F6B1386D6; Tue, 6 Feb 2024 12:09:26 +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 5AD8F135A49; Tue, 6 Feb 2024 12:09:20 +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=1707221360; cv=none; b=gqWOfjL7NhsNP8hYNCXR9rwmmBI76v5TKWVYX6uBiEPpZyrZMoMLMdwav1w89AqpsKFI9slXiluAfYajuzu14ih2jdWtfO7n1UyegZhUcLsTGVwLouKCP4qCK8lht+1yF0Sn8Kmtgwb4AT1plXX+8b4sYGYoqnQBp1zpBt1eqAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221360; c=relaxed/simple; bh=ag23ZLNHvKwtbUtFEFGHSFqm7C64xgRkm1HvLw4xCCI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ud4DNtBHsIUPXjWVUDE3IdsvGNTccqYyZaIuYAZWjjiDv/T07Ee6vNp3CQtwFvbnM2+SNYQeJQFISeHnGy4kpnHPwewbl6Jn7PdURJ0+6YN/V+1faMuYSvbVqqq80l2FeScdOpoJvzksNTNLe3C/eZc+rexYnkK93L/YRRCzGmE= 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 0A394C433C7; Tue, 6 Feb 2024 12:09:20 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGq-00000006b7K-1zWt; Tue, 06 Feb 2024 07:09:48 -0500 Message-ID: <20240206120948.331907337@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:17 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.6][PATCH 12/57] eventfs: Fix WARN_ON() in create_file_dentry() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151950018602370 X-GMAIL-MSGID: 1790151950018602370 From: "Steven Rostedt (Google)" As the comment right above a WARN_ON() in create_file_dentry() states: * Note, with the mutex held, the e_dentry cannot have content * and the ei->is_freed be true at the same time. But the WARN_ON() only has: WARN_ON_ONCE(ei->is_free); Where to match the comment (and what it should actually do) is: dentry = *e_dentry; WARN_ON_ONCE(dentry && ei->is_free) Also in that case, set dentry to NULL (although it should never happen). Link: https://lore.kernel.org/linux-trace-kernel/20231024123628.62b88755@gandalf.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit a9de4eb15ad430fe45747c211e367da745a90093) --- fs/tracefs/event_inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 09ab93357957..4d2da7480e5f 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -264,8 +264,9 @@ create_file_dentry(struct eventfs_inode *ei, struct dentry **e_dentry, * Note, with the mutex held, the e_dentry cannot have content * and the ei->is_freed be true at the same time. */ - WARN_ON_ONCE(ei->is_freed); dentry = *e_dentry; + if (WARN_ON_ONCE(dentry && ei->is_freed)) + dentry = NULL; /* The lookup does not need to up the dentry refcount */ if (dentry && !lookup) dget(dentry); From patchwork Tue Feb 6 12:09:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1497316dyb; Tue, 6 Feb 2024 04:19:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGnnXXYj7vAKpD+d7lUcKX0lqShVydlIN799wvtjc8vBxhzwsBOyL7KAsuQp1yHzXKNfr2P X-Received: by 2002:a05:6a20:4389:b0:19e:2d02:56c3 with SMTP id i9-20020a056a20438900b0019e2d0256c3mr1763671pzl.6.1707221993579; Tue, 06 Feb 2024 04:19:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221993; cv=pass; d=google.com; s=arc-20160816; b=0ufL1mSiBDZjs9syukk5VO/cLE6MDJOq0YTs4A04+KsBhsO9mcwLqgUJLsRSDTdWrR 7Yzt81V5ep3jPaitzSimCTW7cjoraQ0sV9/LpNk7HBpIfVPOafPB6GBAb0ihfh+MQerj rm0KQ9+9MoMjD2avkNPdXUKV3lK0Hj7A5TFx5UZdFQCiIK60bZLfiwLBz9OssVohVceQ i/TBzMRY96Hfqtm8u6Cm1jxeqqSQs4joE7N+mDtdgIJ2FC2Ia2f5Fs7yK57SsT376cTt PadRt9dPG1DnwnVDLGyNL1rwmotB6A+c6Mek/iq2tYxAzNujnMCkA4QvOA4wVUbO3OxK 4b6w== 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=zeD/4lYDEvUE7x2Xzsma9+3cAtiGUz4cqPP+4pfXhbw=; fh=IqtSKSCGFWmM3w2PoMm0B5KJdYRmQRzPYm9lzhki2ns=; b=nb0kKyaRfmhsFyTomTehox5FUAHdhLeUe5TrB9+LVA5YszP+Lt2esHR28Wrj67FLML yf08TeUs1Ok+x4cJZTUncuRY2AVh+2NPSNXVMPjeF+tchJgOD5nwwkeEMbkqiy10xokn udHNEDTzFfzQYRjKGfcN1jNVdegkFQQglyI1nxKdlBOE4sOkwSg5nfuv1h85HktTCYVB sp5+KHZpDtaBj2J3TZB+8KKnse8cSJONdUqzCVJUG5C39eWJ3aGvXWPEow0jq6HxDRaw oah/hUwWStIYHJfI/jBhvw8OTE3jH3LAXejQyFOs0zfPkHb3WZjYZE9HbC2h+S1bZhkz /NxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54890-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54890-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXhCvhb6kGZD+K6KpmS9+X35gKYUWZmBDQlq0g2xi0GtOraO4Yi+Rff5pQbtBCAcx0XOnMgFOhx2UZf/0XbhYWRhsxjSw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id i18-20020a17090ad35200b00295b3ecc46bsi1060852pjx.168.2024.02.06.04.19.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:19:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54890-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54890-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54890-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 67EA028856F for ; Tue, 6 Feb 2024 12:19:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B0DA13BE84; Tue, 6 Feb 2024 12:09:27 +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 9F5B4135A64; Tue, 6 Feb 2024 12:09:20 +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=1707221360; cv=none; b=eE1bhT2EqQggs58ogRq5zD55BAaUNLeyL8EN1lxOO6qW1HQ7Y5EUfSVAPueDk6yX53yB+He1cTME8jP5hHnpKR8HEpf1WplwXBxSUJlSkI71oGykFMFFIS2I3CPsmmnBWGvTTVM0uWGbGRnVZCu558hcsHM1gxWAgjSuBncyB0A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221360; c=relaxed/simple; bh=mublhVt1iAiu6WhkAvGlLcWbK2KJ7BEzK+6N7+17uqU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dY+2rUO2sOP1geTx8+ifAFzwgd4xSEcrpGrpMILQl3RRtdGZFy7xcUp1pJRqr6vmXr6ZG4Uwggk5nXl2qYZqwD9B9/YyVd6i2Y1d8N44g1H38i9+5kK2Ubvo/jW4NFH0eXYEdvCd2/fZg4t03puKA0tm6EwXhWYPOnzmNVHCp5w= 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 3408BC433F1; Tue, 6 Feb 2024 12:09:20 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGq-00000006b7q-2fVT; Tue, 06 Feb 2024 07:09:48 -0500 Message-ID: <20240206120948.496559787@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:18 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.6][PATCH 13/57] eventfs: Fix typo in eventfs_inode union comment References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152009216034799 X-GMAIL-MSGID: 1790152009216034799 From: "Steven Rostedt (Google)" It's eventfs_inode not eventfs_indoe. There's no deer involved! Link: https://lore.kernel.org/linux-trace-kernel/20231024131024.5634c743@gandalf.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 29e06c10702e81a7d0b75020ca514d2f2962704a) --- fs/tracefs/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 298d3ecaf621..64fde9490f52 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -37,7 +37,7 @@ struct eventfs_inode { /* * Union - used for deletion * @del_list: list of eventfs_inode to delete - * @rcu: eventfs_indoe to delete in RCU + * @rcu: eventfs_inode to delete in RCU * @is_freed: node is freed if one of the above is set */ union { From patchwork Tue Feb 6 12:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1497201dyb; Tue, 6 Feb 2024 04:19:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFyjCZzlbhtqBSVml7g5qKf0IDXIbwVPGaeZ0gKVi7QpMUefJ9jBo9KeH1s37oJSlks65nm X-Received: by 2002:a05:6902:4ec:b0:dbc:b14f:9064 with SMTP id w12-20020a05690204ec00b00dbcb14f9064mr1399383ybs.46.1707221977381; Tue, 06 Feb 2024 04:19:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221977; cv=pass; d=google.com; s=arc-20160816; b=04I+w6u9MZnH12d0K2NxFfYE+y/clBxGWkWZ4t3Uzl4pQzhLP0sdfIFGGYbtJIHqCr 06Lutc+RNThnFHf3H2JAIku12S7VM7Yv/GlWOhbQRNFVeHKiTaOVCpIc6c1N3L4zD2mw HmQpF/33iPxF2PbOBRcunBBcs2TQoOJvNQWrJePQ0wLlqhdTfOKN4/Mc07cPOYCouug5 5FXtUEnUcDMJdCoVu7wJ+lkOxUV/bGu1pOyeiwcOVX197GfEnzJPb+6H9oRj5YbY3VnB JIN1Pp5+X5yVU28+J+ih7jRtXct7wbO3dXunqDpu7JA8HSbRU2+iU+xMCRu9hdS6XEzn g3QA== 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=V/yf1Ww67fwH3Ww0NQfTCIKnyTvOEfzyJ0HNZ9lmEs4=; fh=5iuWqqZCWvXcryQAl4Sshfa5ySGPhLHFMZQ6AZBXA44=; b=XObOxL7MbWoaG78Dd3ihBH+3CRZQkh9yJ7Il61Yf+DtYVORrullla+kEbZlb20vCxT MC6qF22JPFrUT/htqVWyYjSiWopRhHgsydf+vSSAe4JaeGr32Hs7uRywk1EGpPjJ2tpL 8H5XziEon7lOyi2ng5cdfNXB68AFrRGgYHIDnikdIJAxBXbMjDfihn3YS4WfMxFeeWeP zoThCX0Fzs0ARTYzqqTJgGre68ynYfQnmBENeJRCM7I/n+t1i2569kq6VG+IuLmVXKjy daLm5opjeKAfeej/+27if7eq6hwll/COEuqBk10yWAPt7iMC3hAvAKgo2UnhCO68m21X a9qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54889-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54889-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUKa/nwaYPRQDsiuCsTej5awZ/MUlJ3f/Cd3+DzYmImJhG9jQpkwztJMbE96kcTidJp7D2btx7wLV62XJk9KynONMUNzQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kd26-20020a056214401a00b006819bba47f3si2551945qvb.508.2024.02.06.04.19.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:19:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54889-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54889-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54889-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 209F91C23D4A for ; Tue, 6 Feb 2024 12:19:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3A03113BE92; Tue, 6 Feb 2024 12:09:27 +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 9F578135A63; Tue, 6 Feb 2024 12:09:20 +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=1707221360; cv=none; b=r/GBtCUpQTH52YlMUA95X8HvDjO59M0/CrH6kY4OLT7H8RjGpj/7cwANAjmMINEZI6e8K9ZZOh3lDcl3RYvqUnMT+u9ayUIZR9CWK9xfK5i31sbtBAQ/xchTc7yXnldEBHbP2OCxXaDS92T3SBRnpMr9dBs0Z5/PEuIB145lVR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221360; c=relaxed/simple; bh=2aaBsNBmdbcGzMEkSucJzBcIVM88W8uW7E3nMS6OFqQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Dj/wrbXEOKn/wCSF2BTOyb0y2PCi8vVPQtN6vz8FiD83HP9uZaGiLqyK/rvr8USV8OopD0VAhkWa2tytP45kjYDr+stlluwUPqV4KfXj5QYERIGTfCfHu6CtHF2pMnpxJ9Xz9ev89j1/+FvoUQ6DMEloJ7fsrvTt5KOS62tuYfg= 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 534CDC433B2; Tue, 6 Feb 2024 12:09:20 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGq-00000006b8K-3L6D; Tue, 06 Feb 2024 07:09:48 -0500 Message-ID: <20240206120948.657072999@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:19 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.6][PATCH 14/57] eventfs: Remove extra dget() in eventfs_create_events_dir() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151991978610536 X-GMAIL-MSGID: 1790151991978610536 From: "Steven Rostedt (Google)" The creation of the top events directory does a dget() at the end of the creation in eventfs_create_events_dir() with a comment saying the final dput() will happen when it is removed. The problem is that a dget() is already done on the dentry when it was created with tracefs_start_creating()! The dget() now just causes a memory leak of that dentry. Remove the extra dget() as the final dput() in the deletion of the events directory actually matches the one in tracefs_start_creating(). Link: https://lore.kernel.org/linux-trace-kernel/20231031124229.4f2e3fa1@gandalf.local.home Cc: Masami Hiramatsu Cc: Mark Rutland Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 77bc4d4921bd3497678ba8e7f4e480de35692f05) --- fs/tracefs/event_inode.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 4d2da7480e5f..5536860eb2ff 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -774,9 +774,6 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry fsnotify_mkdir(dentry->d_parent->d_inode, dentry); tracefs_end_creating(dentry); - /* Will call dput when the directory is removed */ - dget(dentry); - return ei; fail: From patchwork Tue Feb 6 12:09:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501987dyb; Tue, 6 Feb 2024 04:28:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEf8XpYuXnVK54x7HlJ+vBRR9TKll+U6Gri0mFttny1MzlGmKVfHeKad06RvyLciez0o/Kz X-Received: by 2002:a17:90b:23cd:b0:295:fe86:ad25 with SMTP id md13-20020a17090b23cd00b00295fe86ad25mr2323132pjb.36.1707222524776; Tue, 06 Feb 2024 04:28:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222524; cv=pass; d=google.com; s=arc-20160816; b=KAgsBttzn62gi2I64NT3qIBe/9/FuiMNbr5wS7MbpJ35fWeP269mWWcQsUm32Hwlgy MJPq/wB5a6O2vz+Y1zKqf5QAYRBgZ+lr6bwXW9aldwNb7r2SgFeKvgCm1rcw5vaxH4IT Qj1zaJqWJ9RZcefNtNZed7P4zl/PMs0Q5LsFKtD/Wk5m1h7UARWdGmVWQNGuXDqNG0Gq LaXC/cgJyCQukXBMVG62rlmKSAFHM2ZO9D5KTp0+FPwYkfW0GcB7qGzO0+p+9LCYjngm PEI73XOevRykqfAUgvj3NGJK7aTRZ9mNJUI7OEBLu7NXzr3GEB5OiT6e6JC8gW/TsRmM XkJA== 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=sF58LG9B8PoObac1dX0XgZvr2qgINHhZV2zwGtyjWg4=; fh=RBMJg95tT+3N8ktZz4+hkjL/x3AqWkS+nKIYL1N34P8=; b=LNm8rVhU50uJKcEt4Ym+/8wKn20IMVq2NqhJ6NJoArdmM1W6Z+KU1ZmVHy4yPap9h4 K+B1wO5WeQQyZMPtvojyt6nbVyfzXpg1ECBBHrGThGwEaZsDrfAW3GcLsOUmbICmEL/H 5ZfEc4sWvF5tuG93sYbmRj9RH1t4UWRjPH8d52SyP42GZb7nL3o61W4GqudRr7RSe9uc HJuD6TciSzbknuiRmI6IXrCH4om/9ecO5pS5yvW5Oetd71OEULLIwpo+TdvNZttx6Grj TyTXvoPCwpaR440YbwbFOcNttOKTgKnRZRpsBk3bsE/O2mHqQAZxDx2pbZwUNkIbfRdp Y0Vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54891-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWw92ayXbLPIdMj8Tgr2BAmL8BylnyhJxFGGz7p7y1PayNnFt7mGwmByMrqnx47Dp6PnzKuBYSTm70Q+27ulveF+M0XbA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id b4-20020a17090a12c400b0029668a93dc8si1073783pjg.58.2024.02.06.04.28.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54891-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54891-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E6ADAB2567F for ; Tue, 6 Feb 2024 12:19:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E6CE13BEB6; Tue, 6 Feb 2024 12:09:27 +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 C12BF135A75; Tue, 6 Feb 2024 12:09:20 +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=1707221360; cv=none; b=V3THxo0kpA6mH3QqlK/T453S/jmW8iK6Tx5r4YhLfvia+D9oQMUHeHqIKnjgGk4D+T7mRTCHUpLseslc4jCMKMCmfkVdmiRGqVFVZ+7bJ9IxaVQuoEAPGChEsUrkl70BLysYCapwKAoaHV+6rId35bWqIzD6c8Jk3bfbIcm9ctQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221360; c=relaxed/simple; bh=RVnqUM31lsQW7+iA50+4o8PZzFkXqjlihPk1b0+w1h0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dTAZQCGEonNCyJC9GUJTcL5Q4qP0BrjW6IPKM3Af2P7k6PGOPjgbFzuGPPweD915+OHs3yu8mEl9GSU/64+CF4I0RsIHmy5ad7hBXmldu3ft/3IjzwHpZwdXRtkQsCMbys3/AYmH1jPuEIiv8XDo9QSAGfTCP919xJnsr7M86RI= 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 AC917C433B1; Tue, 6 Feb 2024 12:09:20 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGr-00000006b9L-0VCC; Tue, 06 Feb 2024 07:09:49 -0500 Message-ID: <20240206120948.980929088@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:21 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ajay Kaher Subject: [v6.6][PATCH 16/57] eventfs: Remove "is_freed" union with rcu head References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152565944903517 X-GMAIL-MSGID: 1790152565944903517 From: "Steven Rostedt (Google)" The eventfs_inode->is_freed was a union with the rcu_head with the assumption that when it was on the srcu list the head would contain a pointer which would make "is_freed" true. But that was a wrong assumption as the rcu head is a single link list where the last element is NULL. Instead, split the nr_entries integer so that "is_freed" is one bit and the nr_entries is the next 31 bits. As there shouldn't be more than 10 (currently there's at most 5 to 7 depending on the config), this should not be a problem. Link: https://lkml.kernel.org/r/20231101172649.049758712@goodmis.org Cc: stable@vger.kernel.org Cc: Mark Rutland Cc: Andrew Morton Cc: Ajay Kaher Fixes: 63940449555e7 ("eventfs: Implement eventfs lookup, read, open functions") Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) (cherry picked from commit f2f496370afcbc5227d7002da28c74b91fed12ff) --- fs/tracefs/event_inode.c | 2 ++ fs/tracefs/internal.h | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9f612a8f009d..1ce73acf3df0 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -824,6 +824,8 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, struct list_head *head, eventfs_remove_rec(ei_child, head, level + 1); } + ei->is_freed = 1; + list_del_rcu(&ei->list); list_add_tail(&ei->del_list, head); } diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 64fde9490f52..c7d88aaa949f 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -23,6 +23,7 @@ struct tracefs_inode { * @d_parent: pointer to the parent's dentry * @d_children: The array of dentries to represent the files when created * @data: The private data to pass to the callbacks + * @is_freed: Flag set if the eventfs is on its way to be freed * @nr_entries: The number of items in @entries */ struct eventfs_inode { @@ -38,14 +39,13 @@ struct eventfs_inode { * Union - used for deletion * @del_list: list of eventfs_inode to delete * @rcu: eventfs_inode to delete in RCU - * @is_freed: node is freed if one of the above is set */ union { struct list_head del_list; struct rcu_head rcu; - unsigned long is_freed; }; - int nr_entries; + unsigned int is_freed:1; + unsigned int nr_entries:31; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) From patchwork Tue Feb 6 12:09:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1496991dyb; Tue, 6 Feb 2024 04:19:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdixT3JnxVlyQDOb9P1ugNPubq4urCAv+AA2Wu9iOn1RvUMwrZAATOmtq5fZsbE2wADF6S X-Received: by 2002:ac8:5513:0:b0:42b:e9e3:283 with SMTP id j19-20020ac85513000000b0042be9e30283mr1634555qtq.17.1707221956471; Tue, 06 Feb 2024 04:19:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707221956; cv=pass; d=google.com; s=arc-20160816; b=uZDOtm8bu0v0pEk2mOqKYVaHewzCuXDnlfaYNg+DAEO7iZLnW45+IK7t4FDOgN66b/ Js71B4ZJ8kmw8iQjsf+Y91HoUq9OPuii+BYet0ECQyuxzRiAniDL5xdppKG30XNLBKb5 LyeQFPsIcdX73d20NsK2E2Syx5uTxtOPtAgD3a7luUHSEBml9D10acIGBaa23rGywetm uJ7bP4zoRcB+izcAs45sS4j01pECZa5pcn4QLyJVzPHqqtFpfzg8Xv/AqxjhaBNtsmpz 3bzpmy+G1zJxLVDmjTeDZgjIHrQz1Wf3SAIfDYRTV5zoDVVF8QikMZNyEL2YYM52Qwxu 9Deg== 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=edC2pGSjdH2oZhjemhrbSG+9sQgH5UdRKVYhheylhw0=; fh=AQ7Wl1RH5XYQsAqygPFWxNxHGtn0zZvAvZgLRlndXU4=; b=Eq8uDvxxe+UPmpLmhhq6pGXvlXoYE5G2r2+Ea9YbyTUvEwQWNpiTn3pyAvPR2cnZmZ Lv3/b550tbnwhgwRNfZed0nwdEueBtvfhhVYTrHAUal+J4MKfQncevS/77gYH2JTxscu mJhdPCH0mTXL2N5QsjK6acJxABr1UXp6jYuNGlfrBM26cBsYv7J4tTSGCzWfFmGtd5z6 oG0HpV5HB3djRHeRMoF5JksLMC6ekJbgUVVMsubjQY9fZElI6FIQUjiu//UJBp0LOhU1 7B5PVMORcZM4RYYxhWwq0T0h6YE4oKR2mVE5LFGbi+ThwptpjhHUWatsN/fCpvOdBcrK 5pnA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54892-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54892-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUNU8Jwvd9KBIsn6qNAcNFi4kjCc/LxuFGgd66y6UgPd/tnVmfWZdMrczluI/D3XEClrEbxFUQwKNIWGN31bYmcjv4PLg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id n11-20020a05622a11cb00b0042a2aef2a52si2233133qtk.439.2024.02.06.04.19.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:19:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54892-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54892-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54892-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 40DF11C23FA6 for ; Tue, 6 Feb 2024 12:19:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B931613B79B; Tue, 6 Feb 2024 12:09:26 +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 3E0FC136669; Tue, 6 Feb 2024 12:09:20 +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=1707221361; cv=none; b=EzYI1zSwvavP5r09nnQ2i9N8faT4tDSG2oiqcWtUJ7LSgmsqfB/iTPXlLfWYmtPqBDRz9dxxqgswvhc6UIgT0RUTNDGGzpSp0VZF2CmTyvr8c+wqAA5cWHa3lcmOSeoXgs9yu3L4Z/t/DhumAWzhIH6WtclZRg978hUWQEWrskg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221361; c=relaxed/simple; bh=WpYoW8hnMOujdkzLe1GcecRgFI7u2M+2UE6LWIzx05Y=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Zb4KLVO+nJkcxtoJzbKbrBrUoYXYLFlp95Nu+HfLj1RsCPr243N7SRSn3XJjmjLw9oAUTv5xmUUqzM5CLioedac9BwU9hp+NGPR9/7HcU2nnsEzOmDpuWoBSlO4QHJBqcNCD74c/mwLpbiiCZNui4noJkRzG/6gG1dWeDcu4L+U= 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 D0121C433C7; Tue, 6 Feb 2024 12:09:20 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGr-00000006b9q-1B0s; Tue, 06 Feb 2024 07:09:49 -0500 Message-ID: <20240206120949.141151788@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:22 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Andrew Morton Subject: [v6.6][PATCH 17/57] eventfs: Have a free_ei() that just frees the eventfs_inode References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790151970302879143 X-GMAIL-MSGID: 1790151970302879143 From: "Steven Rostedt (Google)" As the eventfs_inode is freed in two different locations, make a helper function free_ei() to make sure all the allocated fields of the eventfs_inode is freed. This requires renaming the existing free_ei() which is called by the srcu handler to free_rcu_ei() and have free_ei() just do the freeing, where free_rcu_ei() will call it. Link: https://lkml.kernel.org/r/20231101172649.265214087@goodmis.org Cc: Ajay Kaher Cc: Mark Rutland Cc: Andrew Morton Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) (cherry picked from commit db3a397209b00d2e4e0a068608e5c546fc064b82) --- fs/tracefs/event_inode.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1ce73acf3df0..dd5971855732 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -129,6 +129,13 @@ static struct dentry *create_dir(const char *name, struct dentry *parent) return eventfs_end_creating(dentry); } +static void free_ei(struct eventfs_inode *ei) +{ + kfree_const(ei->name); + kfree(ei->d_children); + kfree(ei); +} + /** * eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode * @ti: the tracefs_inode of the dentry @@ -168,9 +175,7 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) eventfs_remove_dir(ei_child); } - kfree_const(ei->name); - kfree(ei->d_children); - kfree(ei); + free_ei(ei); return; } @@ -784,13 +789,11 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ERR_PTR(-ENOMEM); } -static void free_ei(struct rcu_head *head) +static void free_rcu_ei(struct rcu_head *head) { struct eventfs_inode *ei = container_of(head, struct eventfs_inode, rcu); - kfree_const(ei->name); - kfree(ei->d_children); - kfree(ei); + free_ei(ei); } /** @@ -881,7 +884,7 @@ void eventfs_remove_dir(struct eventfs_inode *ei) for (i = 0; i < ei->nr_entries; i++) unhook_dentry(&ei->d_children[i], &dentry_list); unhook_dentry(&ei->dentry, &dentry_list); - call_srcu(&eventfs_srcu, &ei->rcu, free_ei); + call_srcu(&eventfs_srcu, &ei->rcu, free_rcu_ei); } mutex_unlock(&eventfs_mutex); From patchwork Tue Feb 6 12:09:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197395 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1497891dyb; Tue, 6 Feb 2024 04:20:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IFekmyEdzqrJbbSgrumGZBN1qkrX9Fk0U0d6WJMH2qZO2Wv2scO1aFyMx5PwDlNdLN7sCzz X-Received: by 2002:a05:6214:2621:b0:68c:5cd7:a7b4 with SMTP id gv1-20020a056214262100b0068c5cd7a7b4mr2406794qvb.14.1707222058196; Tue, 06 Feb 2024 04:20:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222058; cv=pass; d=google.com; s=arc-20160816; b=Y8dKhAbiAKUA91u+b74Ls/TrCrOfQ7BguEg0aSBj8UWaqyn1Y695+vFrZMa7oTlbqZ S1fXdtTUW7KpxxTt3PkiSrjtiuODNGYutshp9Q0QqPuVf5GcKX/Z6dxZ9WL69E9pKW7D UXJIOwfOaCABREIlkvkScgDtAjFrsGPZo4zunQrW+Ebi6PzpvsxO45Y4SNXoOyhZDEon q/sm2qtgivjuLHLf5cuy8d+gKbE8LADhHgWwh3f7qEBqAtd1UJ2ZDrsvyRyzesrZWWoe GI9m44JrtsnPBCYXO4tDC6a6lU6AdZf0I7QXeIEB+U3U4phb1PegbUYPIYiZpGOWCxF+ IxEQ== 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=Qjh1Pw31T+l4R4TFeF7Yl4py3b54+s6JoWkAPjUiXgw=; fh=4B2GAg+uz+zFNPf2t7A2GTS1slIWnv2aDReKzY2YSCk=; b=Lbs5Efu0pZP4HaqHsxl8gYcmiHgMIRISTerkX8pK7XcLB5NAtpEJcKdcUKvyjzfWRw LNcO+7yFpLPYjWGJmxkx9h4ugsGL4SD7VTns1acpYkUXFAVLc9FsddvI6nH0hPgURTtF IIFUhcJVlsHN0jDd+bdb1OyD7QJvkVQtoxXUg8PDpPemZtOdKyRKB4waAGMPF5Ztjk2O XEKmpNF952MzQmHOCl5Qqb3X7P4qfk6dPQpQypUazVuvvncPTbNAiQv/ihKBRPJIy4wA arfktJwP0+xq7LVi/L7RRvITGoLqLdfogQQSA7BXn53SOjA3WSxonQUs0uCd+1IxlSic yfhw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54894-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54894-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUP91FTI2oiEDtjmFZOh8x6UpyHwmRDae7QiC/Ia7/UWhCnq5MyD4d+E0ABmZbvIlQtoDutoUDTesqUoeSrUxBt+t0/Ig== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y7-20020ad445a7000000b0068c83d17f3csi2211241qvu.305.2024.02.06.04.20.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:20:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54894-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54894-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54894-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 D3B911C23327 for ; Tue, 6 Feb 2024 12:20:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4DDC13E224; Tue, 6 Feb 2024 12:09:29 +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 7CDBC136985; Tue, 6 Feb 2024 12:09:21 +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=1707221361; cv=none; b=XRzZwVi49uojamjaMMH6ltZJ7X7g/GiZAnsVeg1rcBH/Jg5mmqvpiKMwC+icynVDaCiFVdo0o+kX5VvWjKAxr8krfMZ5aKtP5USwmvyNrjzOi+tWaJvAEsCymrMGncZ9NkTW5TDXX+WviRol+zMQprdlr+YN41D0fiY1Q8LUXXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221361; c=relaxed/simple; bh=kG1/nxJbNWFSUElspzrXtQDehW5c+TNmxIPqBWLO/nI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hfh38pqeQhclImi3FCqMtTzKhaTPE+gE0lnHHlA7/sWI6DWUIBln0hJpELPRm/LRwS3aBxIiyTXgtrc4ssTijxIOE6BWyha1rTmuLiPCIIxYdTmLoL65eypoIu7QkHK2qd/QkmWVhY2yr0aPUucK84a5D9MuOPZRTb2dB6Jgh6c= 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 04AE0C43394; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGr-00000006bAL-1r5a; Tue, 06 Feb 2024 07:09:49 -0500 Message-ID: <20240206120949.301438848@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:23 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Andrew Morton , Linux Kernel Functional Testing , Naresh Kamboju , Beau Belgrave Subject: [v6.6][PATCH 18/57] eventfs: Test for ei->is_freed when accessing ei->dentry References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152076754211653 X-GMAIL-MSGID: 1790152076754211653 From: "Steven Rostedt (Google)" The eventfs_inode (ei) is protected by SRCU, but the ei->dentry is not. It is protected by the eventfs_mutex. Anytime the eventfs_mutex is released, and access to the ei->dentry needs to be done, it should first check if ei->is_freed is set under the eventfs_mutex. If it is, then the ei->dentry is invalid and must not be used. The ei->dentry must only be accessed under the eventfs_mutex and after checking if ei->is_freed is set. When the ei is being freed, it will (under the eventfs_mutex) set is_freed and at the same time move the dentry to a free list to be cleared after the eventfs_mutex is released. This means that any access to the ei->dentry must check first if ei->is_freed is set, because if it is, then the dentry is on its way to be freed. Also add comments to describe this better. Link: https://lore.kernel.org/all/CA+G9fYt6pY+tMZEOg=SoEywQOe19fGP3uR15SGowkdK+_X85Cg@mail.gmail.com/ Link: https://lore.kernel.org/all/CA+G9fYuDP3hVQ3t7FfrBAjd_WFVSurMgCepTxunSJf=MTe=6aA@mail.gmail.com/ Link: https://lkml.kernel.org/r/20231101172649.477608228@goodmis.org Cc: Ajay Kaher Cc: Mark Rutland Cc: Andrew Morton Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: Linux Kernel Functional Testing Reported-by: Naresh Kamboju Reported-by: Beau Belgrave Reviewed-by: Masami Hiramatsu (Google) Tested-by: Linux Kernel Functional Testing Tested-by: Naresh Kamboju Tested-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 77a06c33a22d13f3a6e31f06f6ee6bca666e6898) --- fs/tracefs/event_inode.c | 45 ++++++++++++++++++++++++++++++++++------ fs/tracefs/internal.h | 3 ++- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index dd5971855732..e9625732c52d 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -24,7 +24,20 @@ #include #include "internal.h" +/* + * eventfs_mutex protects the eventfs_inode (ei) dentry. Any access + * to the ei->dentry must be done under this mutex and after checking + * if ei->is_freed is not set. The ei->dentry is released under the + * mutex at the same time ei->is_freed is set. If ei->is_freed is set + * then the ei->dentry is invalid. + */ static DEFINE_MUTEX(eventfs_mutex); + +/* + * The eventfs_inode (ei) itself is protected by SRCU. It is released from + * its parent's list and will have is_freed set (under eventfs_mutex). + * After the SRCU grace period is over, the ei may be freed. + */ DEFINE_STATIC_SRCU(eventfs_srcu); static struct dentry *eventfs_root_lookup(struct inode *dir, @@ -239,6 +252,10 @@ create_file_dentry(struct eventfs_inode *ei, struct dentry **e_dentry, bool invalidate = false; 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) { /* lookup does not need to up the ref count */ @@ -312,6 +329,8 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) struct eventfs_inode *ei_child; struct tracefs_inode *ti; + lockdep_assert_held(&eventfs_mutex); + /* srcu lock already held */ /* fill parent-child relation */ list_for_each_entry_srcu(ei_child, &ei->children, list, @@ -325,6 +344,7 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) /** * 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 * @lookup: True if this is called by the lookup code @@ -332,12 +352,17 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) * This creates and attaches a directory dentry to the eventfs_inode @ei. */ static struct dentry * -create_dir_dentry(struct eventfs_inode *ei, struct dentry *parent, bool lookup) +create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, + struct dentry *parent, bool lookup) { bool invalidate = false; struct dentry *dentry = NULL; mutex_lock(&eventfs_mutex); + if (pei->is_freed || ei->is_freed) { + mutex_unlock(&eventfs_mutex); + return NULL; + } if (ei->dentry) { /* If the dentry already has a dentry, use it */ dentry = ei->dentry; @@ -440,7 +465,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, */ mutex_lock(&eventfs_mutex); ei = READ_ONCE(ti->private); - if (ei) + if (ei && !ei->is_freed) ei_dentry = READ_ONCE(ei->dentry); mutex_unlock(&eventfs_mutex); @@ -454,7 +479,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, if (strcmp(ei_child->name, name) != 0) continue; ret = simple_lookup(dir, dentry, flags); - create_dir_dentry(ei_child, ei_dentry, true); + create_dir_dentry(ei, ei_child, ei_dentry, true); created = true; break; } @@ -588,7 +613,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dir_dentry(ei_child, parent, false); + d = create_dir_dentry(ei, ei_child, parent, false); if (d) { ret = add_dentries(&dentries, d, cnt); if (ret < 0) @@ -705,12 +730,20 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode ei->nr_entries = size; ei->data = data; INIT_LIST_HEAD(&ei->children); + INIT_LIST_HEAD(&ei->list); mutex_lock(&eventfs_mutex); - list_add_tail(&ei->list, &parent->children); - ei->d_parent = parent->dentry; + if (!parent->is_freed) { + list_add_tail(&ei->list, &parent->children); + ei->d_parent = parent->dentry; + } mutex_unlock(&eventfs_mutex); + /* Was the parent freed? */ + if (list_empty(&ei->list)) { + free_ei(ei); + ei = NULL; + } return ei; } diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index c7d88aaa949f..5a98e87dd3d1 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -24,6 +24,7 @@ struct tracefs_inode { * @d_children: The array of dentries to represent the files when created * @data: The private data to pass to the callbacks * @is_freed: Flag set if the eventfs is on its way to be freed + * Note if is_freed is set, then dentry is corrupted. * @nr_entries: The number of items in @entries */ struct eventfs_inode { @@ -31,7 +32,7 @@ struct eventfs_inode { const struct eventfs_entry *entries; const char *name; struct list_head children; - struct dentry *dentry; + struct dentry *dentry; /* Check is_freed to access */ struct dentry *d_parent; struct dentry **d_children; void *data; From patchwork Tue Feb 6 12:09:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1498681dyb; Tue, 6 Feb 2024 04:22:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5V0ZgC3uQCyxxSj4zTtWAvwz/I0oPDmdUvuk0o2DU4uuIzNkD9CJNIrvlgPQWmIJz9Kz+ X-Received: by 2002:a05:620a:564:b0:785:6054:5f87 with SMTP id p4-20020a05620a056400b0078560545f87mr13336845qkp.21.1707222138850; Tue, 06 Feb 2024 04:22:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222138; cv=pass; d=google.com; s=arc-20160816; b=WOn8pH+SnycDxT7DSYlmDjctMfiejuZ3+ZWvY4rTdnXd0Z9OdtIE6lHOidrR0avMjt agXGGoFq89Azr5FXMkt5lQI2qN4NdPHXInnmlGY+mmfoJsDoIWD1hoLz/RzjsBY7akcU kaoT/WK8/Wg2Yw3AdgFLKLZGcboFIC2LZ7rvFlUsS/7OdTHiCb3X+h5CF1qP+i8Fk5Uj 5qN6h8TpP6JFq/XJIktXxjhriatl8klNPABjYZHgVS1PPtt4felvwZ71fFUuGQVrzozD TwbNd1fpSwoKEeqjK6tcENL2AWWEZZIumWsvyRtSnp5oOG4U5XWuMGNT2h4JCPuD5cEG 4yag== 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=zmj8crBnbvpd8Es02BcD/UUaJdr5crddTeVbe1GsjoY=; fh=0G4wByS6VpAKN+wytril2jXXfJDQoNx44cxGgpnyhmE=; b=eAKRnxxQoBk1/ru9vWqC3PG3Pyw0AJdlWKLz16La7DWejwnaEjeBV0MN/t+QKbHyXZ 9EXOuAtv53nySkvA6/2Hs3e0PHKBNCVf6U9ZFbkn9pYPI4kAM5bRTHPCcfRyqlT+k4aT 9tx46HEX9LJhhERaSLscDXgtnke50nU7c2X6VDV4kj1AFkzXVcVHukW5rD+Y/ZsTnl8e zk/VdN1UZ+6NDR2PeLbyVv/kyk+Uy363iBeisSqAVxliEl2bboRInP/wdawrepdA0Y0S zd1YhxnrdyiTZfXeeh0BP6yNaiE9L2r6G0FmBZEkQSzLIvz/Bw7OZP7XQ/uJ4uRdcvZ4 J9fQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54895-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54895-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUVRThTJdQEGKUE4AVmChscTezVzPwJCP+HYnfL4rBAyI5daoV73Boq6qKbtwiFpKyD+/6IpPgQ4aTLRmdYwlC1wtubzQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a31-20020a05620a439f00b007855e4f9279si2302874qkp.736.2024.02.06.04.22.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:22:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54895-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54895-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54895-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 955A71C23877 for ; Tue, 6 Feb 2024 12:22:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A5B3B144614; Tue, 6 Feb 2024 12:09:31 +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 7CE3B136986; Tue, 6 Feb 2024 12:09:21 +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=1707221361; cv=none; b=YUQscIpj1iFd6tpLoYmeQ22iusLVcY/3/8F/YfUIpySS9ohTHHgk0egi2ErkUuZemc5ROtr+j8tO/lF8ZF2IpwmJp0/49tSzW5443Qcf6MuctvZf6c2YGAR6v6PkaJ5IPFQFs3jXX7Laze4fYe2T1/hVaofZXPOqKbjNLM910OQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221361; c=relaxed/simple; bh=LPHCUC+XOE6a+rTOOpSZFitJzU53rMUz6survkIA3Ss=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=rMYNjOFtnbwAPJtTe6pfzzAklTRJG066nU5uTpcigs1s0CmvMFKmMpcnnc2F3FodAEu5pcxVu4TVJZDCO8BfLL91GpJVmgRpudXmirOXYE19hZcG3rmoLE8d3yCtKifT8HEz9pH5CFMWvn/mkNxXOITKu9LRW8rfZJdC0TBxexY= 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 2A1F5C43601; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGr-00000006bAq-2Y1s; Tue, 06 Feb 2024 07:09:49 -0500 Message-ID: <20240206120949.464245650@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:24 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Andrew Morton Subject: [v6.6][PATCH 19/57] eventfs: Save ownership and mode References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152161228908980 X-GMAIL-MSGID: 1790152161228908980 From: "Steven Rostedt (Google)" Now that inodes and dentries are created on the fly, they are also reclaimed on memory pressure. Since the ownership and file mode are saved in the inode, if they are freed, any changes to the ownership and mode will be lost. To counter this, if the user changes the permissions or ownership, save them, and when creating the inodes again, restore those changes. Link: https://lkml.kernel.org/r/20231101172649.691841445@goodmis.org Cc: stable@vger.kernel.org Cc: Ajay Kaher Cc: Mark Rutland Cc: Andrew Morton Fixes: 63940449555e7 ("eventfs: Implement eventfs lookup, read, open functions") Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 28e12c09f5aa081b2d13d1340e3610070b6c624d) --- fs/tracefs/event_inode.c | 148 +++++++++++++++++++++++++++++++++++---- fs/tracefs/internal.h | 16 +++++ 2 files changed, 151 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index e9625732c52d..93d08e552483 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -40,6 +40,15 @@ static DEFINE_MUTEX(eventfs_mutex); */ DEFINE_STATIC_SRCU(eventfs_srcu); +/* Mode is unsigned short, use the upper bits for flags */ +enum { + EVENTFS_SAVE_MODE = BIT(16), + EVENTFS_SAVE_UID = BIT(17), + EVENTFS_SAVE_GID = BIT(18), +}; + +#define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1) + static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); @@ -47,8 +56,89 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file); static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx); static int eventfs_release(struct inode *inode, struct file *file); +static void update_attr(struct eventfs_attr *attr, struct iattr *iattr) +{ + unsigned int ia_valid = iattr->ia_valid; + + if (ia_valid & ATTR_MODE) { + attr->mode = (attr->mode & ~EVENTFS_MODE_MASK) | + (iattr->ia_mode & EVENTFS_MODE_MASK) | + EVENTFS_SAVE_MODE; + } + if (ia_valid & ATTR_UID) { + attr->mode |= EVENTFS_SAVE_UID; + attr->uid = iattr->ia_uid; + } + if (ia_valid & ATTR_GID) { + attr->mode |= EVENTFS_SAVE_GID; + attr->gid = iattr->ia_gid; + } +} + +static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, + struct iattr *iattr) +{ + const struct eventfs_entry *entry; + struct eventfs_inode *ei; + const char *name; + int ret; + + mutex_lock(&eventfs_mutex); + ei = dentry->d_fsdata; + /* The LSB is set when the eventfs_inode is being freed */ + if (((unsigned long)ei & 1UL) || ei->is_freed) { + /* Do not allow changes if the event is about to be removed. */ + mutex_unlock(&eventfs_mutex); + return -ENODEV; + } + + /* Preallocate the children mode array if necessary */ + if (!(dentry->d_inode->i_mode & S_IFDIR)) { + if (!ei->entry_attrs) { + ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, + GFP_KERNEL); + if (!ei->entry_attrs) { + ret = -ENOMEM; + goto out; + } + } + } + + ret = simple_setattr(idmap, dentry, iattr); + if (ret < 0) + goto out; + + /* + * If this is a dir, then update the ei cache, only the file + * mode is saved in the ei->m_children, and the ownership is + * determined by the parent directory. + */ + if (dentry->d_inode->i_mode & S_IFDIR) { + update_attr(&ei->attr, iattr); + + } else { + name = dentry->d_name.name; + + for (int i = 0; i < ei->nr_entries; i++) { + entry = &ei->entries[i]; + if (strcmp(name, entry->name) == 0) { + update_attr(&ei->entry_attrs[i], iattr); + break; + } + } + } + out: + mutex_unlock(&eventfs_mutex); + return ret; +} + static const struct inode_operations eventfs_root_dir_inode_operations = { .lookup = eventfs_root_lookup, + .setattr = eventfs_set_attr, +}; + +static const struct inode_operations eventfs_file_inode_operations = { + .setattr = eventfs_set_attr, }; static const struct file_operations eventfs_file_operations = { @@ -59,10 +149,30 @@ static const struct file_operations eventfs_file_operations = { .release = eventfs_release, }; +static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, umode_t mode) +{ + if (!attr) { + inode->i_mode = mode; + return; + } + + if (attr->mode & EVENTFS_SAVE_MODE) + inode->i_mode = attr->mode & EVENTFS_MODE_MASK; + else + inode->i_mode = mode; + + if (attr->mode & EVENTFS_SAVE_UID) + inode->i_uid = attr->uid; + + if (attr->mode & EVENTFS_SAVE_GID) + inode->i_gid = attr->gid; +} + /** * create_file - create a file in the tracefs filesystem * @name: the name of the file to create. * @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. @@ -72,6 +182,7 @@ static const struct file_operations eventfs_file_operations = { * call. */ static struct dentry *create_file(const char *name, umode_t mode, + struct eventfs_attr *attr, struct dentry *parent, void *data, const struct file_operations *fop) { @@ -95,7 +206,10 @@ static struct dentry *create_file(const char *name, umode_t mode, if (unlikely(!inode)) return eventfs_failed_creating(dentry); - inode->i_mode = mode; + /* If the user updated the directory's attributes, use them */ + update_inode_attr(inode, attr, mode); + + inode->i_op = &eventfs_file_inode_operations; inode->i_fop = fop; inode->i_private = data; @@ -108,19 +222,19 @@ static struct dentry *create_file(const char *name, umode_t mode, /** * create_dir - create a dir in the tracefs filesystem - * @name: the name of the file to create. + * @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 * a eventfs_inode. */ -static struct dentry *create_dir(const char *name, struct dentry *parent) +static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent) { struct tracefs_inode *ti; struct dentry *dentry; struct inode *inode; - dentry = eventfs_start_creating(name, parent); + dentry = eventfs_start_creating(ei->name, parent); if (IS_ERR(dentry)) return dentry; @@ -128,7 +242,9 @@ static struct dentry *create_dir(const char *name, struct dentry *parent) if (unlikely(!inode)) return eventfs_failed_creating(dentry); - inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; + /* If the user updated the directory's attributes, use them */ + update_inode_attr(inode, &ei->attr, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO); + inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; @@ -146,6 +262,7 @@ static void free_ei(struct eventfs_inode *ei) { kfree_const(ei->name); kfree(ei->d_children); + kfree(ei->entry_attrs); kfree(ei); } @@ -231,7 +348,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 * @ei: the eventfs_inode that the file will be created under - * @e_dentry: a pointer to the d_children[] of the @ei + * @idx: the index into the d_children[] 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. @@ -244,10 +361,12 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) * just do a dget() on it and return. Otherwise create the dentry and attach it. */ static struct dentry * -create_file_dentry(struct eventfs_inode *ei, struct dentry **e_dentry, +create_file_dentry(struct eventfs_inode *ei, int idx, struct dentry *parent, const char *name, umode_t mode, void *data, const struct file_operations *fops, bool lookup) { + struct eventfs_attr *attr = NULL; + struct dentry **e_dentry = &ei->d_children[idx]; struct dentry *dentry; bool invalidate = false; @@ -264,13 +383,18 @@ create_file_dentry(struct eventfs_inode *ei, struct dentry **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); /* The lookup already has the parent->d_inode locked */ if (!lookup) inode_lock(parent->d_inode); - dentry = create_file(name, mode, parent, data, fops); + dentry = create_file(name, mode, attr, parent, data, fops); if (!lookup) inode_unlock(parent->d_inode); @@ -378,7 +502,7 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, if (!lookup) inode_lock(parent->d_inode); - dentry = create_dir(ei->name, parent); + dentry = create_dir(ei, parent); if (!lookup) inode_unlock(parent->d_inode); @@ -495,8 +619,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, if (r <= 0) continue; ret = simple_lookup(dir, dentry, flags); - create_file_dentry(ei, &ei->d_children[i], - ei_dentry, name, mode, cdata, + create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops, true); break; } @@ -629,8 +752,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) r = entry->callback(name, &mode, &cdata, &fops); if (r <= 0) continue; - d = create_file_dentry(ei, &ei->d_children[i], - parent, name, mode, cdata, fops, false); + d = create_file_dentry(ei, i, parent, name, mode, cdata, fops, false); if (d) { ret = add_dentries(&dentries, d, cnt); if (ret < 0) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 5a98e87dd3d1..5f60bcd69289 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -13,6 +13,18 @@ struct tracefs_inode { struct inode vfs_inode; }; +/* + * struct eventfs_attr - cache the mode and ownership of a eventfs entry + * @mode: saved mode plus flags of what is saved + * @uid: saved uid if changed + * @gid: saved gid if changed + */ +struct eventfs_attr { + int mode; + kuid_t uid; + kgid_t gid; +}; + /* * struct eventfs_inode - hold the properties of the eventfs directories. * @list: link list into the parent directory @@ -22,6 +34,8 @@ struct tracefs_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 * @data: The private data to pass to the callbacks * @is_freed: Flag set if the eventfs is on its way to be freed * Note if is_freed is set, then dentry is corrupted. @@ -35,6 +49,8 @@ struct eventfs_inode { 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; void *data; /* * Union - used for deletion From patchwork Tue Feb 6 12:09:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1497662dyb; Tue, 6 Feb 2024 04:20:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IFdlavUWWjDBth9Xyfkgy0fRW9CPtVkTwl+wSUNyyKxhgVbslyRy5TI3dnbXVGQGlDw8klr X-Received: by 2002:a17:902:ec86:b0:1d9:30e3:ea84 with SMTP id x6-20020a170902ec8600b001d930e3ea84mr2336799plg.2.1707222037521; Tue, 06 Feb 2024 04:20:37 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222037; cv=pass; d=google.com; s=arc-20160816; b=KmIyN8+NcGs8sD2+CWHkHpFdEyqPJKQXb54nbYG3dMibt2dOSCRTy8AFNIwAmTUVWu 3StLAZ/uKiMn3DpN1QPiOCt1JeELwZ7BsL9qridmls6MMQpcgxjKThBfawGNi0Vf3UX3 2Ufvhoyz17xUfpO1iFURzX6/jIY86lrGun26swXDeClJzsQDJ6Jf4Nz9oVa6o53rbCwP BePXwIgKaeOTJ2INep2SnkhHoquKiyYReOwkUY2pILWY4BxTWo8hUXFYZGaROst3rx/0 F2D9gXgwOJA5zAzx2DWnZ1/F6f/H3gBDxzCZl7sDjE+Vf/xxXdfDv4V0+7ypzE7KOJO2 Fwdw== 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=9gZ3EqP/DA/rFeehuBpzWDYpFL9+7qRhVlZGu1fiyII=; fh=84Pc4Tr5nkEYO/m/q5I2Dt/C3Qv8f2NQM11ylfcR6qc=; b=0mQCeLU7zmhCjDczmrmjb7TpUzeoktg4lF/S/roE79GDFTJVyYURlJmFJ1fPvxGi7Y ZYR/3WdGaLom8lhRew+TZv6WsNEqxkszekP818nkCkN6xvEo2FQojPULcGzsKvljvdpi ZwIT1iLi2u0tb3b3ECYXFLniF3o1QNvn6Hbz8HzVWTKQ/d//h/gM5OnaFUA7Hkhw9urz WsUA4o8PfCnlGNpmXjB6MJe+62OUosURNUiXL2g2VgaEpPY/P5kbWIbVyq4QrcxBCtYj XTWo0NfPQxHP53wd7CUD5NTiopZiJEBNTPvDoct4ih3RVCjE8YEM7inbd+r62rw2Cdor tBcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54893-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54893-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVGOpPwzQvosWqS7B8C1luza0GlYqHXTWMBpyFf1uHykai/AzakHM8oJ8K6Bhq3xmv1TxIH9Q8OaD4+0T5P+sr0YQSbgQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i17-20020a17090332d100b001d909321bffsi1573843plr.295.2024.02.06.04.20.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:20:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54893-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-54893-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54893-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 472BD2820C0 for ; Tue, 6 Feb 2024 12:20:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3330D13DBAC; Tue, 6 Feb 2024 12:09:29 +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 6E7B913340F; Tue, 6 Feb 2024 12:09:21 +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=1707221361; cv=none; b=NWjLiJud9zTgAhrDLmwqXlICWs+v4FMkR1jPkLy8+nk4gu8S9VQEdWqJ2s23OqhiY1ecprSpVXD2u+zqFg9uTsp/WRCr3fsi5JhRmQ97ZI4ZOQNY6jMU925aW5XxFXnQAPPMO8l6IFr2fkFutshSJcce5gb0HWfaY4K3k9ZLcWU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221361; c=relaxed/simple; bh=Ds/0uDvMhgVKQBK9pz1xuo17yjshJeDZO5q2PioWVWc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=a8z9JR4W5N7eptvID/D24wpnbiW5w5Uown+g9j37cf6jL9UBbPIkUnt0I+YQUltdphfbVAcnhrAAoUnV0ZCXc/o2MzDyvqMh2ubqZzlDUtq8ogI5b5M+vozKdMUtutiu+a1w5xvQI5bnu+b/Lt20nm0KhsFphbWyEqGFSnV3OrY= 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 4B99BC433B1; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGr-00000006bBL-3EKs; Tue, 06 Feb 2024 07:09:49 -0500 Message-ID: <20240206120949.629213120@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:25 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Andrew Morton , Linux Kernel Functional Testing , Naresh Kamboju Subject: [v6.6][PATCH 20/57] eventfs: Hold eventfs_mutex when calling callback functions References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152055370115076 X-GMAIL-MSGID: 1790152055370115076 From: "Steven Rostedt (Google)" The callback function that is used to create inodes and dentries is not protected by anything and the data that is passed to it could become stale. After eventfs_remove_dir() is called by the tracing system, it is free to remove the events that are associated to that directory. Unfortunately, that means the callbacks must not be called after that. CPU0 CPU1 ---- ---- eventfs_root_lookup() { eventfs_remove_dir() { mutex_lock(&event_mutex); ei->is_freed = set; mutex_unlock(&event_mutex); } kfree(event_call); for (...) { entry = &ei->entries[i]; r = entry->callback() { call = data; // call == event_call above if (call->flags ...) [ USE AFTER FREE BUG ] The safest way to protect this is to wrap the callback with: mutex_lock(&eventfs_mutex); if (!ei->is_freed) r = entry->callback(); else r = -1; mutex_unlock(&eventfs_mutex); This will make sure that the callback will not be called after it is freed. But now it needs to be known that the callback is called while holding internal eventfs locks, and that it must not call back into the eventfs / tracefs system. There's no reason it should anyway, but document that as well. Link: https://lore.kernel.org/all/CA+G9fYu9GOEbD=rR5eMR-=HJ8H6rMsbzDC2ZY5=Y50WpWAE7_Q@mail.gmail.com/ Link: https://lkml.kernel.org/r/20231101172649.906696613@goodmis.org Cc: Ajay Kaher Cc: Mark Rutland Cc: Andrew Morton Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: Linux Kernel Functional Testing Reported-by: Naresh Kamboju Tested-by: Linux Kernel Functional Testing Tested-by: Naresh Kamboju Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 44365329f8219fc379097c2c9a75ff53f123764f) --- fs/tracefs/event_inode.c | 22 ++++++++++++++++++-- include/linux/tracefs.h | 43 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 93d08e552483..8ac9abf7a3d5 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -615,7 +615,13 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, entry = &ei->entries[i]; if (strcmp(name, entry->name) == 0) { void *cdata = data; - r = entry->callback(name, &mode, &cdata, &fops); + 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); @@ -749,7 +755,13 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) void *cdata = data; entry = &ei->entries[i]; name = entry->name; - r = entry->callback(name, &mode, &cdata, &fops); + 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; d = create_file_dentry(ei, i, parent, name, mode, cdata, fops, false); @@ -819,6 +831,10 @@ static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx) * data = A pointer to @data, and the callback may replace it, which will * cause the file created to pass the new data to the open() call. * fops = the fops to use for the created file. + * + * NB. @callback is called while holding internal locks of the eventfs + * system. The callback must not call any code that might also call into + * the tracefs or eventfs system or it will risk creating a deadlock. */ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent, const struct eventfs_entry *entries, @@ -878,6 +894,8 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode * @data: The default data to pass to the files (an entry may override it). * * This function creates the top of the trace event directory. + * + * See eventfs_create_dir() for use of @entries. */ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent, const struct eventfs_entry *entries, diff --git a/include/linux/tracefs.h b/include/linux/tracefs.h index 13359b1a35d1..7a5fe17b6bf9 100644 --- a/include/linux/tracefs.h +++ b/include/linux/tracefs.h @@ -23,9 +23,52 @@ struct file_operations; struct eventfs_file; +/** + * eventfs_callback - A callback function to create dynamic files in eventfs + * @name: The name of the file that is to be created + * @mode: return the file mode for the file (RW access, etc) + * @data: data to pass to the created file ops + * @fops: the file operations of the created file + * + * The evetnfs files are dynamically created. The struct eventfs_entry array + * is passed to eventfs_create_dir() or eventfs_create_events_dir() that will + * be used to create the files within those directories. When a lookup + * or access to a file within the directory is made, the struct eventfs_entry + * array is used to find a callback() with the matching name that is being + * referenced (for lookups, the entire array is iterated and each callback + * will be called). + * + * The callback will be called with @name for the name of the file to create. + * The callback can return less than 1 to indicate that no file should be + * created. + * + * If a file is to be created, then @mode should be populated with the file + * mode (permissions) for which the file is created for. This would be + * used to set the created inode i_mode field. + * + * The @data should be set to the data passed to the other file operations + * (read, write, etc). Note, @data will also point to the data passed in + * to eventfs_create_dir() or eventfs_create_events_dir(), but the callback + * can replace the data if it chooses to. Otherwise, the original data + * will be used for the file operation functions. + * + * The @fops should be set to the file operations that will be used to create + * the inode. + * + * NB. This callback is called while holding internal locks of the eventfs + * system. The callback must not call any code that might also call into + * the tracefs or eventfs system or it will risk creating a deadlock. + */ typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data, const struct file_operations **fops); +/** + * struct eventfs_entry - dynamically created eventfs file call back handler + * @name: Then name of the dynamic file in an eventfs directory + * @callback: The callback to get the fops of the file when it is created + * + * See evenfs_callback() typedef for how to set up @callback. + */ struct eventfs_entry { const char *name; eventfs_callback callback; From patchwork Tue Feb 6 12:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1498726dyb; Tue, 6 Feb 2024 04:22:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCmvqlFSBWBh59qBBCPv0VCqADxGYXU+Rxr5tYAxuUfjGGZ7OSxc48rYLO614TDPL+BZPf X-Received: by 2002:a05:622a:1808:b0:42c:e85:f414 with SMTP id t8-20020a05622a180800b0042c0e85f414mr5515577qtc.2.1707222143832; Tue, 06 Feb 2024 04:22:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222143; cv=pass; d=google.com; s=arc-20160816; b=GoMxlcWD7+d+sV8FrwZjjCv5FyxBdLMz8ugnPEzY26tRaC8n3VywVFKGRCi8vCgSsE cHURFjVsWuWa29/0Vq7Ti7Sf7qj1fn+7JQwuQHUOMzhPkitwzfsAL0lwh6QmRDmLlqeE H2rEu/Wo3B+QjfwRuX+jmV4K5BqH7hFajmyofbFuti5KL6j6oPpkxrsZMUre1/NM8ctd +UDVLpsA6/bUaPKmq9ECc4wuSYmiC4/hfNBtN7Ax5E8okFPZva+UhONISJSCO1LJy9Za eMUNq5m2/sx6m+7f/zlGBKDaQkotNI/Bb96BophIRCcWGQM+RqvgC9VrIZg1igkGsN63 wdzQ== 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=KFfPtVWz9CXG0Wk0SFB9Ox0c3srqqmXL+2NMJ+xg+rE=; fh=dq9sNissz475WSL2nnCjrZ+o+1Ol477t7kos44ieUdo=; b=MKKm4Z/asgcNDq6YRItMU7ksv9tZKO5kLSKMTSVSlJebEfpWrpN1L7DHKITNYbg4Rr tDV23dIiUp3ufoqJt67aFqVhIRfG4XYqok7NsWZaAHSrUUM048rd1Fkv7QKnQ905ZWeS qKTbroWKgYddFHWQButRql9iKhuFGExFDYHO4CPvwsEjH9qoVND8S2TslVhpEZ8k+9tt t3n46VMnS34TgLYVRh5/QdUg7srlH7WMkxOJDgSLDSURuLWoJb5pJnJ3wAho9YlwLAKi NZoXGWzaqOyKwfSMDrdy2Eb9/XPi95AoLp/ZmBs9FvAFftgJ9LslFgSaztz9XIcW8xfz qplA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54896-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54896-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUuwegjlHNV2mzVlZ8XxAth/Hn0G4AYJcZe9LF8+N7/9HkA8A/KLCMdDaOIbPSOSGNvFx3Dwb0V3wlxq++erHxBREcuLQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u12-20020a05622a010c00b0042c3a87c09esi192325qtw.162.2024.02.06.04.22.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54896-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54896-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54896-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 8D6441C239C3 for ; Tue, 6 Feb 2024 12:22:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D463214462E; Tue, 6 Feb 2024 12:09:31 +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 92BB313698A; Tue, 6 Feb 2024 12:09:21 +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=1707221361; cv=none; b=VX5x0xl6o7GzuzjAWlZSP42PTEmCCMPqBYN6tJub8RQ3oqjuckNTn68cccWw9Lnm+RWCPUQ0omhjZXcUYSil5lOGZjNfy5cQH7NVGnCUsduHgGo6b60kmBXLPzCmPBUs7tSQvTZlnbGb4lviwjw8OKYlwoqZM+ZCLDiN4dVosuc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221361; c=relaxed/simple; bh=EX62FCliiicp1Ebv2cbXuAVT6VCGkHG/rJaEKHec0Co=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gXgmkjSoiNrwK1R6wS2+9eySybwrPX5KcqmBRDebSmLr8MLg/N1x7xJoT1tUqXIglSDIZNP6JS2kgtKKjTd+s6ToVKO8eX2oFBZ6PJNPdlfenygLiaxAkUwhwQM4MRCNs0RrWIkvNr7zqEZ3rR5xIhFrrr536XBCe4VyR3N9oOo= 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 70897C433F1; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGr-00000006bBq-3v6a; Tue, 06 Feb 2024 07:09:49 -0500 Message-ID: <20240206120949.792406858@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:26 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ajay Kaher Subject: [v6.6][PATCH 21/57] eventfs: Delete eventfs_inode when the last dentry is freed References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152166607562322 X-GMAIL-MSGID: 1790152166607562322 From: "Steven Rostedt (Google)" There exists a race between holding a reference of an eventfs_inode dentry and the freeing of the eventfs_inode. If user space has a dentry held long enough, it may still be able to access the dentry's eventfs_inode after it has been freed. To prevent this, have he eventfs_inode freed via the last dput() (or via RCU if the eventfs_inode does not have a dentry). This means reintroducing the eventfs_inode del_list field at a temporary place to put the eventfs_inode. It needs to mark it as freed (via the list) but also must invalidate the dentry immediately as the return from eventfs_remove_dir() expects that they are. But the dentry invalidation must not be called under the eventfs_mutex, so it must be done after the eventfs_inode is marked as free (put on a deletion list). Link: https://lkml.kernel.org/r/20231101172650.123479767@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Cc: Ajay Kaher Fixes: 5bdcd5f5331a2 ("eventfs: Implement removal of meta data from eventfs") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 020010fbfa202aa528a52743eba4ab0da3400a4e) --- fs/tracefs/event_inode.c | 146 ++++++++++++++++++--------------------- fs/tracefs/internal.h | 2 + 2 files changed, 69 insertions(+), 79 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 8ac9abf7a3d5..0a04ae0ca8c8 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -85,8 +85,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, mutex_lock(&eventfs_mutex); ei = dentry->d_fsdata; - /* The LSB is set when the eventfs_inode is being freed */ - if (((unsigned long)ei & 1UL) || ei->is_freed) { + if (ei->is_freed) { /* Do not allow changes if the event is about to be removed. */ mutex_unlock(&eventfs_mutex); return -ENODEV; @@ -276,35 +275,17 @@ static void free_ei(struct eventfs_inode *ei) void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) { struct tracefs_inode *ti_parent; - struct eventfs_inode *ei_child, *tmp; struct eventfs_inode *ei; int i; /* The top level events directory may be freed by this */ if (unlikely(ti->flags & TRACEFS_EVENT_TOP_INODE)) { - LIST_HEAD(ef_del_list); - mutex_lock(&eventfs_mutex); - ei = ti->private; - - /* Record all the top level files */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - lockdep_is_held(&eventfs_mutex)) { - list_add_tail(&ei_child->del_list, &ef_del_list); - } - /* Nothing should access this, but just in case! */ ti->private = NULL; - mutex_unlock(&eventfs_mutex); - /* Now safely free the top level files and their children */ - list_for_each_entry_safe(ei_child, tmp, &ef_del_list, del_list) { - list_del(&ei_child->del_list); - eventfs_remove_dir(ei_child); - } - free_ei(ei); return; } @@ -319,14 +300,6 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) if (!ei) goto out; - /* - * If ei was freed, then the LSB bit is set for d_fsdata. - * But this should not happen, as it should still have a - * ref count that prevents it. Warn in case it does. - */ - if (WARN_ON_ONCE((unsigned long)ei & 1)) - 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++) { @@ -336,6 +309,8 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) 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; } @@ -962,13 +937,65 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct 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; + + /* Keep the dentry from being freed yet (see eventfs_workfn()) */ + dget(dentry); + + dentry->d_fsdata = NULL; + d_invalidate(dentry); + mutex_lock(&eventfs_mutex); + /* dentry should now have at least a single reference */ + WARN_ONCE((int)d_count(dentry) < 1, + "dentry %px (%s) less than one reference (%d) after invalidate\n", + dentry, dentry->d_name.name, d_count(dentry)); + mutex_unlock(&eventfs_mutex); +} + /** * eventfs_remove_rec - remove eventfs dir or file from list * @ei: eventfs_inode to be removed. @@ -1006,33 +1033,6 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, struct list_head *head, list_add_tail(&ei->del_list, head); } -static void unhook_dentry(struct dentry **dentry, struct dentry **list) -{ - if (*dentry) { - unsigned long ptr = (unsigned long)*list; - - /* Keep the dentry from being freed yet */ - dget(*dentry); - - /* - * Paranoid: The dget() above should prevent the dentry - * from being freed and calling eventfs_set_ei_status_free(). - * But just in case, set the link list LSB pointer to 1 - * and have eventfs_set_ei_status_free() check that to - * make sure that if it does happen, it will not think - * the d_fsdata is an eventfs_inode. - * - * For this to work, no eventfs_inode should be allocated - * on a odd space, as the ef should always be allocated - * to be at least word aligned. Check for that too. - */ - WARN_ON_ONCE(ptr & 1); - - (*dentry)->d_fsdata = (void *)(ptr | 1); - *list = *dentry; - *dentry = NULL; - } -} /** * eventfs_remove_dir - remove eventfs dir or file from list * @ei: eventfs_inode to be removed. @@ -1043,40 +1043,28 @@ void eventfs_remove_dir(struct eventfs_inode *ei) { struct eventfs_inode *tmp; LIST_HEAD(ei_del_list); - struct dentry *dentry_list = NULL; - struct dentry *dentry; - int i; if (!ei) return; + /* + * Move the deleted eventfs_inodes onto the ei_del_list + * which will also set the is_freed value. Note, this has to be + * done under the eventfs_mutex, but the deletions of + * the dentries must be done outside the eventfs_mutex. + * Hence moving them to this temporary list. + */ mutex_lock(&eventfs_mutex); eventfs_remove_rec(ei, &ei_del_list, 0); + mutex_unlock(&eventfs_mutex); list_for_each_entry_safe(ei, tmp, &ei_del_list, del_list) { - for (i = 0; i < ei->nr_entries; i++) - unhook_dentry(&ei->d_children[i], &dentry_list); - unhook_dentry(&ei->dentry, &dentry_list); + for (int i = 0; i < ei->nr_entries; i++) + unhook_dentry(ei->d_children[i]); + unhook_dentry(ei->dentry); + list_del(&ei->del_list); call_srcu(&eventfs_srcu, &ei->rcu, free_rcu_ei); } - mutex_unlock(&eventfs_mutex); - - while (dentry_list) { - unsigned long ptr; - - dentry = dentry_list; - ptr = (unsigned long)dentry->d_fsdata & ~1UL; - dentry_list = (struct dentry *)ptr; - dentry->d_fsdata = NULL; - d_invalidate(dentry); - mutex_lock(&eventfs_mutex); - /* dentry should now have at least a single reference */ - WARN_ONCE((int)d_count(dentry) < 1, - "dentry %px (%s) less than one reference (%d) after invalidate\n", - dentry, dentry->d_name.name, d_count(dentry)); - mutex_unlock(&eventfs_mutex); - dput(dentry); - } } /** diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 5f60bcd69289..06a1f220b901 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -54,10 +54,12 @@ struct eventfs_inode { void *data; /* * Union - used for deletion + * @llist: for calling dput() if needed after RCU * @del_list: list of eventfs_inode to delete * @rcu: eventfs_inode to delete in RCU */ union { + struct llist_node llist; struct list_head del_list; struct rcu_head rcu; }; From patchwork Tue Feb 6 12:09:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197429 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1502704dyb; Tue, 6 Feb 2024 04:30:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+zLdQWzH4Kh8oQWGwNlblftBSFaI0byHZlwf16SOtDzFcSshty7Uo8IIqt53ep77l0f6A X-Received: by 2002:a62:e30d:0:b0:6df:bb25:ee25 with SMTP id g13-20020a62e30d000000b006dfbb25ee25mr2300589pfh.18.1707222605276; Tue, 06 Feb 2024 04:30:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222605; cv=pass; d=google.com; s=arc-20160816; b=N1a4BppGTzlvH8La9i+2wNhjpE8ZRN6GIWLbfhodY6IR8OxThoatjF4ykUDSh+Pz4U 4/sYl1YGC9Fs+OOtjYgQYISBsLaG8Megvts/EeWNQVjPDy0cJjxHBnOD5kWmguEvTol4 bCyl7G5YToUQznTr0LxtS0/G0O/eu2viPJEJjHn11ZTHI7Cg0aFQT2eU/0Wno/wrfhWN tlElLzdWEfh2eoxp+QRfM2KVsHODCBe5XFy1GinrEw+oCRxIePY9dfGnSUGM8lvbxlu/ 9hmAttH4/iZ6a4A0Vwtrd6sGo4HsVpMQHG0/drWAtGZxBM0Jfmn+rPrkKZXTND3vk5LD Ai1w== 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=kPf+5s8vNcVaTsPSULAocZwpEXtyatzZQyXY3z1B5Ec=; fh=+PmWt43nisI+iGh9662vXds8uHhZ/0ZiAHrJlxp2s7E=; b=OP8l9LGGI7bcFwpi7lzgqnddbQ8qmqjq/CnWzlOzVHCKUuExIahBqZRgVnAhzTvdhP QPvkkJX1hDdPQ6oxYmEHgd+i5xxtGh8MsX9ICEtEWwoGqKD43P/VrcoU9St7MfMZSCqo t8s6DDSdgseIwm+7z7Vp4kL1W3c4H+DxRlsLw8L789nIbLQljLj1elTVf8RSJkP30Lmi CfwKBDmeK6jN1eZMhKpxbwE2EuqobKXl6uO7gm2EtTB/7O/AKSYGm/3rtgXGWhsK7jAy wsfqKwQEou3pJxCpkWW+7dUSW+NbCBdmpD00Q6xbKzhDcP3XGSY4mZWxbWwGNJN/M0kI T/TA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54897-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54897-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUARD0Qsp11paspUf6UAeRhqwbrhnneUGRGvEQLMaIBdtun6Z6S2eL0xt7ID+jD5NceQSggbuQp0t9bGC0V5ghi0SVgpg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d22-20020aa78696000000b006e03d6e64d3si1562197pfo.175.2024.02.06.04.30.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:30:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54897-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54897-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54897-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D1FA0B26226 for ; Tue, 6 Feb 2024 12:21:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F30914079E; Tue, 6 Feb 2024 12:09:30 +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 B775113699D; Tue, 6 Feb 2024 12:09:21 +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=1707221361; cv=none; b=cpumw0e/kW0h0nlu2LTaOsTKtyVts7m6Br3XVr3LnOMtP4Rgj6yBnrzFVpx6ON+wiSML1y9Tzkg7DETYs2JbkbfJcQLAEQLSn2B/vNYrCerO/Rw7qr9CftwlbLMB9yopyXi771znWm2K6PIrLSwLT9LSZTMZ/94IsHYzaefy7DM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221361; c=relaxed/simple; bh=2uaDNgIJzLo4+YSpk1Akkna6ka+cyIDf3T52EWN75N8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=RkYYorVaGDm9ysSwNgJlv4m39UXoqrVDHAjcZRoqbJYFNOYg9wWBkp5f3SnIJcFKDI2eDtlUsAG3qAG92cRbwOPrENkzizZ4sVOIahqvoE2vDa3+HQv2Ix8dTnTVcDg4zA6omTnVrjJUL/RQLJiyMSCdljccM+r8R4iTFfI4kKU= 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 A1F80C43601; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bCL-0Pyc; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120949.956372816@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:27 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Andrew Morton Subject: [v6.6][PATCH 22/57] eventfs: Remove special processing of dput() of events directory References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152650175119691 X-GMAIL-MSGID: 1790152650175119691 From: "Steven Rostedt (Google)" The top level events directory is no longer special with regards to how it should be delete. Remove the extra processing for it in eventfs_set_ei_status_free(). Link: https://lkml.kernel.org/r/20231101172650.340876747@goodmis.org Cc: Ajay Kaher Cc: Mark Rutland Cc: Andrew Morton Reviewed-by: Masami Hiramatsu (Google) Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 62d65cac119d08d39f751b4e3e2063ed996edc05) --- fs/tracefs/event_inode.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 0a04ae0ca8c8..0087a3f455f1 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -274,28 +274,11 @@ static void free_ei(struct eventfs_inode *ei) */ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) { - struct tracefs_inode *ti_parent; struct eventfs_inode *ei; int i; - /* The top level events directory may be freed by this */ - if (unlikely(ti->flags & TRACEFS_EVENT_TOP_INODE)) { - mutex_lock(&eventfs_mutex); - ei = ti->private; - /* Nothing should access this, but just in case! */ - ti->private = NULL; - mutex_unlock(&eventfs_mutex); - - free_ei(ei); - return; - } - mutex_lock(&eventfs_mutex); - ti_parent = get_tracefs(dentry->d_parent->d_inode); - if (!ti_parent || !(ti_parent->flags & TRACEFS_EVENT_INODE)) - goto out; - ei = dentry->d_fsdata; if (!ei) goto out; @@ -920,6 +903,8 @@ 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; + /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); d_instantiate(dentry, inode); From patchwork Tue Feb 6 12:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1498729dyb; Tue, 6 Feb 2024 04:22:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7KEkincoOnezzgXpxyZqt/M0/buI7fdG4eF2RMZ6QeeiRr0lEzwS7kYidFWNEFto0sN/m X-Received: by 2002:a17:906:2408:b0:a38:3eb1:40a1 with SMTP id z8-20020a170906240800b00a383eb140a1mr717167eja.26.1707222143920; Tue, 06 Feb 2024 04:22:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222143; cv=pass; d=google.com; s=arc-20160816; b=NnArCYeu8PYxDqXshsG/dok9MmXTXwwR/mHE+N62WttNJ9WtrXVX1fJTse4xYEXbG/ l28dRIBh+fTgd/0JYmD33QN65GKNOXDnQJBiVaqqNmFvuvnHPPyTtdZU0bI4vt4RBXqh ehG8Lsz91eZFKNLvjFSJoGLwOb8AzZS5Id1NyFa1DQuNlHcupObFrHY3/4RXDqxYJdfR EX3roIrtT/NVsQgFuxItKs0kErv72MB3mFIuSN7+mtD2tSvXvjp30z5TwhxP4y8dgLu8 Bi0G6X+x2h3OWm4kWaPEc8vLB+cnpWxvtnhM4EncC8e1lH7aH49NvlUMoZr3r6Ss6hWU auBg== 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=SQywd03Pi2cOJEzNpCdc+jpMmfh3LsORrC2f0wzMBtk=; fh=P0hReqcfz3LlpsvRMhHWKk5bcGmM1gaD3f10tvb/Jmg=; b=EOwNPn36Bslb4joWj6A+F8sdn1jY+4BZ0pesnGfGuclsSUMzDStD5vLSc41Nx6dJbj jUcddZC2EAGPgTN/eWf3nOaw5vn8mfuyFVNeFofRfz/A0iBrDcRAg9fWnsVhshMZWakC f4Kf+MzGdOEejScQ7W297XwlcQU3lujFRGJ7UkiuNQiFQh7dbq+ri154Sp9GelyC3LIy DEnOv6Zvkv09DBKc1h99t/oYBozJJmlvWRs/soTbxQ3HfF0X2qd5w2ztueDMWMwAxHga 6oAjeEUHBNzyWujA7szvx004S8RNEYAvEdBRowuPhjrKFxvN4gd7g4pcQp5/dycCP1Jy WNPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54898-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54898-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXNsGEYjGbvZhBITOokHoXnSvOGbR3/6ZfjxRtvgQi6+AT5hM9Jgt7aChnnwPnCGfh3zhz7jnRLn7Pg16BziGvha64rdg== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id kk7-20020a170907766700b00a382baad7b5si571176ejc.919.2024.02.06.04.22.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:22:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54898-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54898-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54898-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 1BAF21F25828 for ; Tue, 6 Feb 2024 12:21:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B75841419A2; Tue, 6 Feb 2024 12:09:30 +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 3615D137C31; Tue, 6 Feb 2024 12:09:21 +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=1707221362; cv=none; b=JEq+9yV8CKf9q9sWgBRH6upoWmJWTMJGU6Ny3rvQLxlpdOhEnxndUMGANvrClDWtxiMQFFI2j9AsFP3eENneS+Lk9utRywlo4FzU4dz0wz6jiPR9DD0j+2aPZGTT4sCrqgFIvp9nvOFmCk9oICzExIJRrk/+7vGXv57kruS/wL0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; c=relaxed/simple; bh=Eo3GAzrlb3xQR8bxqyZh35WxLBG0y/2yNLrd3Y39mjg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=JXPP19sXIbQKo/GHsuH4S035MxQk5MDS1ZFAsc3Nhk43mS9eA9FreQdxeQVB7y1WTeQrjXStLkCoVfjCQSHvOXkiaFOrWryCXFd4pvMNxlpU/tvz/EWzYHkNtOKAMMTeozbmiVEFdSPYx5zxtg5CyrMNQod5hyQ+NG4Qc+SDFCg= 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 C375DC433C7; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bCq-16q1; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120950.121281039@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:28 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro Subject: [v6.6][PATCH 23/57] eventfs: Use simple_recursive_removal() to clean up dentries References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152166825236190 X-GMAIL-MSGID: 1790152166825236190 From: "Steven Rostedt (Google)" Looking at how dentry is removed via the tracefs system, I found that eventfs does not do everything that it did under tracefs. The tracefs removal of a dentry calls simple_recursive_removal() that does a lot more than a simple d_invalidate(). As it should be a requirement that any eventfs_inode that has a dentry, so does its parent. When removing a eventfs_inode, if it has a dentry, a call to simple_recursive_removal() on that dentry should clean up all the dentries underneath it. Add WARN_ON_ONCE() to check for the parent having a dentry if any children do. Link: https://lore.kernel.org/all/20231101022553.GE1957730@ZenIV/ Link: https://lkml.kernel.org/r/20231101172650.552471568@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Cc: Al Viro Fixes: 5bdcd5f5331a2 ("eventfs: Implement removal of meta data from eventfs") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 407c6726ca71b33330d2d6345d9ea7ebc02575e9) --- fs/tracefs/event_inode.c | 77 +++++++++++++++++++++++----------------- fs/tracefs/internal.h | 2 -- 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 0087a3f455f1..f8a594a50ae6 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -967,30 +967,29 @@ static void unhook_dentry(struct dentry *dentry) { if (!dentry) return; - - /* Keep the dentry from being freed yet (see eventfs_workfn()) */ + /* + * Need to add a reference to the dentry that is expected by + * simple_recursive_removal(), which will include a dput(). + */ dget(dentry); - dentry->d_fsdata = NULL; - d_invalidate(dentry); - mutex_lock(&eventfs_mutex); - /* dentry should now have at least a single reference */ - WARN_ONCE((int)d_count(dentry) < 1, - "dentry %px (%s) less than one reference (%d) after invalidate\n", - dentry, dentry->d_name.name, d_count(dentry)); - mutex_unlock(&eventfs_mutex); + /* + * 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. - * @head: the list head to place the deleted @ei and children * @level: prevent recursion from going more than 3 levels deep. * * This function recursively removes eventfs_inodes which * contains info of files and/or directories. */ -static void eventfs_remove_rec(struct eventfs_inode *ei, struct list_head *head, int level) +static void eventfs_remove_rec(struct eventfs_inode *ei, int level) { struct eventfs_inode *ei_child; @@ -1009,13 +1008,26 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, struct list_head *head, /* search for nested folders or files */ list_for_each_entry_srcu(ei_child, &ei->children, list, lockdep_is_held(&eventfs_mutex)) { - eventfs_remove_rec(ei_child, head, level + 1); + /* Children only have dentry if parent does */ + WARN_ON_ONCE(ei_child->dentry && !ei->dentry); + 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); - list_add_tail(&ei->del_list, head); + call_srcu(&eventfs_srcu, &ei->rcu, free_rcu_ei); } /** @@ -1026,30 +1038,22 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, struct list_head *head, */ void eventfs_remove_dir(struct eventfs_inode *ei) { - struct eventfs_inode *tmp; - LIST_HEAD(ei_del_list); + struct dentry *dentry; if (!ei) return; - /* - * Move the deleted eventfs_inodes onto the ei_del_list - * which will also set the is_freed value. Note, this has to be - * done under the eventfs_mutex, but the deletions of - * the dentries must be done outside the eventfs_mutex. - * Hence moving them to this temporary list. - */ mutex_lock(&eventfs_mutex); - eventfs_remove_rec(ei, &ei_del_list, 0); + dentry = ei->dentry; + eventfs_remove_rec(ei, 0); mutex_unlock(&eventfs_mutex); - list_for_each_entry_safe(ei, tmp, &ei_del_list, del_list) { - for (int i = 0; i < ei->nr_entries; i++) - unhook_dentry(ei->d_children[i]); - unhook_dentry(ei->dentry); - list_del(&ei->del_list); - call_srcu(&eventfs_srcu, &ei->rcu, free_rcu_ei); - } + /* + * If any of the ei children has a dentry, then the ei itself + * must have a dentry. + */ + if (dentry) + simple_recursive_removal(dentry, NULL); } /** @@ -1060,10 +1064,17 @@ void eventfs_remove_dir(struct eventfs_inode *ei) */ void eventfs_remove_events_dir(struct eventfs_inode *ei) { - struct dentry *dentry = ei->dentry; + struct dentry *dentry; + dentry = ei->dentry; eventfs_remove_dir(ei); - /* Matches the dget() from eventfs_create_events_dir() */ + /* + * Matches the dget() done by tracefs_start_creating() + * in eventfs_create_events_dir() when it the dentry was + * created. In other words, it's a normal dentry that + * sticks around while the other ei->dentry are created + * and destroyed dynamically. + */ dput(dentry); } diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 06a1f220b901..ccee18ca66c7 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -55,12 +55,10 @@ struct eventfs_inode { /* * Union - used for deletion * @llist: for calling dput() if needed after RCU - * @del_list: list of eventfs_inode to delete * @rcu: eventfs_inode to delete in RCU */ union { struct llist_node llist; - struct list_head del_list; struct rcu_head rcu; }; unsigned int is_freed:1; From patchwork Tue Feb 6 12:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1498951dyb; Tue, 6 Feb 2024 04:22:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGQceOOyFJIEqxE//Awzp0E6I8Ww3LkYqZKNYOYGQLGIu/7efhwVpBxD84Db6vuFxIEnd83 X-Received: by 2002:a17:903:32c6:b0:1d9:c187:3f8c with SMTP id i6-20020a17090332c600b001d9c1873f8cmr1742382plr.58.1707222169663; Tue, 06 Feb 2024 04:22:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222169; cv=pass; d=google.com; s=arc-20160816; b=cY6E8A+3Q6mh7XpNAzw/Hql9WMIdJfr+kInxI2v4RSSDIVhM1sC0FGVdCA760A2FUv FEQFr6YCysqpsDP/xkyVH9TFU263KOFiePslyYWhbfEeOZNVjTwFpY9HAgriFx2uClMX Lmm+sVUMSGxRzUYeycysDQ4YBzlVZtyP/t79I3gyswQX9C/gYhpnV5oDIvY2PwTkdOdN E/eb8BmVyzYvqGAvNLMoGWLU7PH3PaddGL89OrLvvFgF0dKmzVQNC0b1kxoICJIi9pgz CxtjToeiKn7zMNNvA7rtqsU6TPNowshV+uCRsVw3cKL2k3ivHdV0A2Ef2Xr7XiTR4nW1 f7kA== 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=wtToWHzsErUZSHrTYi952TGMfcmqd4tKVXVRALKDnPg=; fh=4qWsFWbG7U5WR2H5lhO/3zzOEgyyBKjBXFl+4fYyxfA=; b=jKGTm78pzY/Q9CQ1kwFvhbG+GOr9+/lZoILQZPPVFJOm2mwgAcpw1W8Usr7lKFfrOP 1AtJRC16+vXjPx1ic/0CpcaCU5Lar05clArScYcJBC6THHtaG3rhIFgXFesfoKqBPvEe Hxfn3kvyI6wCb1dK+/dcW6m5O1Jx5RRmvdEwQxh75m2/0+w/AdS+ig//b3/kpwlFXlDT qBbSckkFEMoauseEPMw1tr/CuEFVRTFnCxLf+O0LoaRWGB/rAnzRO8r+9NIH7OZRHmHv yxAUYZRJAxQDWARsd+6ZaE93D9PPQJuJrXNUzW4VdasGk/Vtek8MRGCUeljU2czQUzD6 FMbA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54899-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXp4q2rppRe6a7oWl5B92XC22ctgYL6sjZsfMs/k5CA83lh4AKBOWcdIf1WryTNNjk4jdZNN5nd6Hzm5qoA47gsptzBmw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i18-20020a17090acf9200b002953a1e7e33si1040784pju.164.2024.02.06.04.22.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:22:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54899-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-54899-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54899-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 6FCEA282A75 for ; Tue, 6 Feb 2024 12:22:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 960D4146903; Tue, 6 Feb 2024 12:09:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4446B137C37; Tue, 6 Feb 2024 12:09:22 +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=1707221362; cv=none; b=TWE1YE9Agu/20iI1ayjN7/64yN0EagVrPbMHQA9AqVnB4EOCv6y2SLjpsaUAk1tFg360tQ+OBnC8clYYG28B7mbNG2dyUMTW0WakE+kU7j6wch3GwMavk9le4nsyxY2rtDWTclR3O4NLBlMH0QMCgV0J7ayOJk396iOsWCUVqOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; c=relaxed/simple; bh=PbQrblDeR9F0JgOw4gGsVCF/2xvBxqNknZ0wT0MnC+M=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dnLdyaz2fELQKPO8Sl9lPqwra8UqiB7WvSLTX2tWBS6zhSKwY3Mv9rNDcSY6kOS/PT7RklMXsX7efPiv991nza+n/sACDjswwbrmH+2hxbBzhVvzrspw6UJk4kpU4FEbq2frtHX37P1t+7i2Nj9gvHILYzd9V7P0a54zNxC4I9g= 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 F1A80C433F1; Tue, 6 Feb 2024 12:09:21 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bDL-1mZY; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120950.284520771@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:29 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton Subject: [v6.6][PATCH 24/57] eventfs: Remove expectation that ei->is_freed means ei->dentry == NULL References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152194190601102 X-GMAIL-MSGID: 1790152194190601102 From: "Steven Rostedt (Google)" The logic to free the eventfs_inode (ei) use to set is_freed and clear the "dentry" field under the eventfs_mutex. But that changed when a race was found where the ei->dentry needed to be cleared when the last dput() was called on it. But there was still logic that checked if ei->dentry was not NULL and is_freed is set, and would warn if it was. But since that situation was changed and the ei->dentry isn't cleared until the last dput() is called on it while the ei->is_freed is set, do not test for that condition anymore, and change the comments to reflect that. Link: https://lkml.kernel.org/r/20231120235154.265826243@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Fixes: 020010fbfa20 ("eventfs: Delete eventfs_inode when the last dentry is freed") Reported-by: Mark Rutland Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 88903daecacf03b1e5636e1b5f18bda5b07030fc) --- fs/tracefs/event_inode.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f8a594a50ae6..f239b2b507a4 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -27,16 +27,16 @@ /* * eventfs_mutex protects the eventfs_inode (ei) dentry. Any access * to the ei->dentry must be done under this mutex and after checking - * if ei->is_freed is not set. The ei->dentry is released under the - * mutex at the same time ei->is_freed is set. If ei->is_freed is set - * then the ei->dentry is invalid. + * if ei->is_freed is not set. When ei->is_freed is set, the dentry + * is on its way to being freed after the last dput() is made on it. */ static DEFINE_MUTEX(eventfs_mutex); /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from * its parent's list and will have is_freed set (under eventfs_mutex). - * After the SRCU grace period is over, the ei may be freed. + * After the SRCU grace period is over and the last dput() is called + * the ei is freed. */ DEFINE_STATIC_SRCU(eventfs_srcu); @@ -365,12 +365,14 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * created the dentry for this e_dentry. In which case * use that one. * - * Note, with the mutex held, the e_dentry cannot have content - * and the ei->is_freed be true at the same time. + * 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. */ - dentry = *e_dentry; - if (WARN_ON_ONCE(dentry && ei->is_freed)) + if (ei->is_freed) dentry = NULL; + else + dentry = *e_dentry; /* The lookup does not need to up the dentry refcount */ if (dentry && !lookup) dget(dentry); @@ -473,8 +475,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * created the dentry for this e_dentry. In which case * use that one. * - * Note, with the mutex held, the e_dentry cannot have content - * and the ei->is_freed be true at the same time. + * If ei->is_freed is set, the e_dentry is currently on its + * way to being freed. */ dentry = ei->dentry; if (dentry && !lookup) From patchwork Tue Feb 6 12:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197400 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1498868dyb; Tue, 6 Feb 2024 04:22:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFcceqs9b+FK/2xvbz5a6A13J0gbamfO7AIMWlpBhIZUXznqvzl6nbGkQzeTdaTdPgrdoWX X-Received: by 2002:a05:6808:d52:b0:3bf:e5ad:8eed with SMTP id w18-20020a0568080d5200b003bfe5ad8eedmr1202376oik.24.1707222159679; Tue, 06 Feb 2024 04:22:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222159; cv=pass; d=google.com; s=arc-20160816; b=Nz5/kYef16DWvYoCtq/jFxtUpVp9IBjm16BzhW4zr4UYDjh9kVWNNun1l9f/NylNYR J+HM60qLLjcYwC2Hc2xhfQxiDnZxvQpvuE+VU/TOPOE+yhHYWyQrt/pcy5p1UxlRdTU0 5STs6gPYUL3iT+P8fbP2R9BqYGR4vYsc2NmYJO0FPH6+nZCeb7+1d6tOMY06+kkpXoUl ZZo+66rrmFlkpfIi9GirAc2ftt/wwEBBTPFQhbBLcPjzGCv3rtJYH85GlNT4FHFlr77P VZstzIGgLOBchOBsOsX5BT0cIoqTExi0R5lT53sRYVjsaedZVT2YuX/SSYMrgrCEvo5H goWA== 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=oHIE+QhcfaEk3owANw1ceP5hrYjvQW+yTWtSbLfxGbM=; fh=XVvSBTmH9USg0MkWY6ZbCcDws9rFdYq851AqmX8/LLw=; b=F45Y+d95GsysSY3xa8XF7hIP8xuQdgCw/TX3GYonbw+9o2shpbBHTlFjeVsHvuvzLY wkaJ0BoUjnTkvrboBnWgNI2UfxgYpW5r3elbX2tlMT/csTRP29Np+UfL42jzwqSaAkUT AN2ZkRG5G1y2RqRr9HkCHuXk1B4rtlV0AYQbYr0Xqoe3rDOI1gz76y117jV03xolGlUU Kzbz2DXXm4Dq5I+qSp61U7m/i+CZN/e5eUiUlAVmbZYPJUQfPqYriM6AjQLVRYRrC73/ 2A78Yl7CeF4wjHEhZ1wRvKm6gYfFL2yQMVCbWPEsIvXnWcLWfdTuEuIns5lgqrWELZRp hFEA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54901-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54901-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXw6OQhBcufaoLyGnS5m+Qs9Vaxb7SUb9Egz35kCjS6Uhw09VLcVrS1uoBI5giTVF6X6WlybxlBZrnmbVKlH5qhINRjAw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u12-20020a05622a010c00b0042c3a87c09esi192325qtw.162.2024.02.06.04.22.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:22:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54901-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54901-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54901-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 685491C239D4 for ; Tue, 6 Feb 2024 12:22:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 66EFD145350; Tue, 6 Feb 2024 12:09:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72662137C5C; Tue, 6 Feb 2024 12:09:22 +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=1707221362; cv=none; b=ppSRaLASj5elmipnamstQanNqnqFDpgUrJ5AQlwnhR5gj1Vj8hRCopzLwfnit2FVKSblBhjn1YUF3T8HSuFUhXG843lrIuXONn9RD4Za1nZRvQGd+S1FtTkCROc8pRe+qGWiYPBqAqpDys/ZY7OKWDBrBa1Mrfg4NIR2khaHwio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; c=relaxed/simple; bh=zEAElJsFmiyF2k5GDTno69bAq8vWad8f06dz1WGJBYo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=KOcGJJgj7tn1KzqiUiFauouZc/8OC8t1HczsTXMinbrj0MyNiWx/ut/23cjL0FRPczquUHTot1eOtEHeXb1Nkh9qMqPIvfVpeL1bgaTRuDwO20velV+kS5Nql5f77YG4AJ/HDX/RV+nmvfz5LfYAkcBt2Vt7Z+a4bCacs7bcOT0= 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 236CAC433B2; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bDq-2TH9; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120950.446963304@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:30 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Naresh Kamboju , Linux Kernel Functional Testing Subject: [v6.6][PATCH 25/57] eventfs: Do not invalidate dentry in create_file/dir_dentry() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152183079930393 X-GMAIL-MSGID: 1790152183079930393 From: "Steven Rostedt (Google)" With the call to simple_recursive_removal() on the entire eventfs sub system when the directory is removed, it performs the d_invalidate on all the dentries when it is removed. There's no need to do clean ups when a dentry is being created while the directory is being deleted. As dentries are cleaned up by the simpler_recursive_removal(), trying to do d_invalidate() in these functions will cause the dentry to be invalidated twice, and crash the kernel. Link: https://lore.kernel.org/all/20231116123016.140576-1-naresh.kamboju@linaro.org/ Link: https://lkml.kernel.org/r/20231120235154.422970988@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Fixes: 407c6726ca71 ("eventfs: Use simple_recursive_removal() to clean up dentries") Reported-by: Mark Rutland Reported-by: Naresh Kamboju Reported-by: Linux Kernel Functional Testing Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 71cade82f2b553a74d046c015c986f2df165696f) --- fs/tracefs/event_inode.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f239b2b507a4..3eb6c622a74d 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -326,7 +326,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; struct dentry *dentry; - bool invalidate = false; mutex_lock(&eventfs_mutex); if (ei->is_freed) { @@ -389,17 +388,14 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * Otherwise it means two dentries exist with the same name. */ WARN_ON_ONCE(!ei->is_freed); - invalidate = true; + dentry = NULL; } mutex_unlock(&eventfs_mutex); - if (invalidate) - d_invalidate(dentry); - - if (lookup || invalidate) + if (lookup) dput(dentry); - return invalidate ? NULL : dentry; + return dentry; } /** @@ -439,7 +435,6 @@ static struct dentry * create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, struct dentry *parent, bool lookup) { - bool invalidate = false; struct dentry *dentry = NULL; mutex_lock(&eventfs_mutex); @@ -495,16 +490,14 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * Otherwise it means two dentries exist with the same name. */ WARN_ON_ONCE(!ei->is_freed); - invalidate = true; + dentry = NULL; } mutex_unlock(&eventfs_mutex); - if (invalidate) - d_invalidate(dentry); - if (lookup || invalidate) + if (lookup) dput(dentry); - return invalidate ? NULL : dentry; + return dentry; } /** From patchwork Tue Feb 6 12:09:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1503378dyb; Tue, 6 Feb 2024 04:31:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGvpJYJUgvVgaL0vJ3GVBE8IbJ8QW1HQ4bZOJ6YG1JfriBl25+ZycvStgVNS06ujW9GAjn X-Received: by 2002:a17:90b:812:b0:296:7b91:7c9b with SMTP id bk18-20020a17090b081200b002967b917c9bmr2156094pjb.46.1707222667351; Tue, 06 Feb 2024 04:31:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222667; cv=pass; d=google.com; s=arc-20160816; b=u4tQilB95QsZDdsN8yH9Sor2M4N3u03c+9l7aOa8IO3W0sKGvcC5GVZ1ma/761GfV+ PPHn1HulSKtu7UNBLtGv3pedr36g+ShbfxXNkp37jaSjFTDdRTVQX8U2ZhzopbR5ScoU AMHPCqc+9TLNETRt4mmczeiax6xPXyfTVZ69BwKvaoMnQJjh6blFsDUf9X3okJycxy32 Unj6RyeBKbW4o6u1/GL/zawvpZG0RiN9RBMErneBZ4DPLkdQKhRokjl5u6I3ZLjnPNx0 5VW5dFkDRml4S2ltTezPtn6E3zOsnxEksNg241CGXBo40m5Ae6wKKcI0x353plX9N9pk ldEA== 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=pbHJHLjnoGTC1dZnAABIDPzt9Jk6VeoJxlGjdgVm16I=; fh=8CJ6IreVAPBzr2vnXT9kbR4Nm7C0GohYrIi8tC8KkwQ=; b=hcpKjGFYK3DXSq2wGTHW3LYBcnmPERX4iNIkwAuUMYUCY+PfOhYcoemThvW7eBdl5w 8+5jCC/Haf36WV5Xx35Yprvif3tUW4TxE/VZTkZuTkuFyiV4XQPGXMrwMeVDQ05nM9VO fPbWUWVlz4Wdh9m6cLtktnlgkzMHyni+rts7o4T1G0SThL6G3eP4F0JLxjMXPd8bhxUT zd9BXgs2d+j0AFhRzVMP42xoIn0g3ywaKeMBD0T/Q9yMhv51eubs6zN55Ct/V9Qiw3t7 DXlZ27iYMli6D5uYlbWvfUI1fUMse+bGKwBzw129W5scFDf1tW/EGBca1vdOg4gL7Vak 7tbg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54900-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUNlTyXK2rfl4/E6+PCJ2isffhXbdGy1UDxVOnhyo1rX8um/XMJmLeXkuBCKqqUo4/g3oEh26z4q0nnCm/Nl+uJiIPfNw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id f21-20020a17090ace1500b0029512f4aa0dsi1056184pju.184.2024.02.06.04.31.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:31:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54900-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54900-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 66D9DB275E0 for ; Tue, 6 Feb 2024 12:22:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6A9F5145358; Tue, 6 Feb 2024 12:09:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63376137C50; Tue, 6 Feb 2024 12:09:22 +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=1707221362; cv=none; b=tVK6AdJ3G/zmj3OJL2IPFPsXOnFykIxBix/c9qbm6gaMiiq/MLr6H+pNaEcn548dnObYaq2SD+A/58ipWjAFOeaZKIa+kAwNwAyxkZJB/vWMBrCDzCLKKADsJQA2igWUBqFPQTLgMcwJlxBjd0S+w1Cm6sGOfSU8IHjcDGdGSEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; c=relaxed/simple; bh=hnDief3HS3NBM6ZKYIfuGnDzLR4JMdJjWA5KdzPNiEA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ZuGZOJ6BGESYHJOJEkRPGwZA/WW6WkeR+RyOkmGKx+udkrpJpKaLl9GEy+kq321qqrnRMbIabVRegGpT1lQrFgpg525PZHm79zHs9AymxEfMezITI5K7pHBLJl/EX6MRGukRJiD5oNr3mFLEhJ7D7a/jGFJ7+xj5ZOUICwdsODk= 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 51081C43390; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bEL-39Zw; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120950.611237633@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:31 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Josef Bacik Subject: [v6.6][PATCH 26/57] eventfs: Use GFP_NOFS for allocation when eventfs_mutex is held References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152715881382087 X-GMAIL-MSGID: 1790152715881382087 From: "Steven Rostedt (Google)" If memory reclaim happens, it can reclaim file system pages. The file system pages from eventfs may take the eventfs_mutex on reclaim. This means that allocation while holding the eventfs_mutex must not call into filesystem reclaim. A lockdep splat uncovered this. Link: https://lkml.kernel.org/r/20231121231112.373501894@goodmis.org Cc: Masami Hiramatsu Cc: Andrew Morton Fixes: 28e12c09f5aa0 ("eventfs: Save ownership and mode") Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: Mark Rutland Reviewed-by: Josef Bacik Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 4763d635c907baed212664dc579dde1663bb2676) --- fs/tracefs/event_inode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 3eb6c622a74d..56d192f0ead8 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -95,7 +95,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, if (!(dentry->d_inode->i_mode & S_IFDIR)) { if (!ei->entry_attrs) { ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, - GFP_KERNEL); + GFP_NOFS); if (!ei->entry_attrs) { ret = -ENOMEM; goto out; @@ -627,7 +627,7 @@ static int add_dentries(struct dentry ***dentries, struct dentry *d, int cnt) { struct dentry **tmp; - tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_KERNEL); + tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_NOFS); if (!tmp) return -1; tmp[cnt] = d; From patchwork Tue Feb 6 12:09:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197402 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499056dyb; Tue, 6 Feb 2024 04:23:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2RFwN4ZL9m2mfC4Rx9gOpTZOMTCdl85zo4FYc8OfhPD9EgGe+ikd6iH33Xs68CTv6zaLq X-Received: by 2002:a05:6358:648a:b0:179:2af:2e29 with SMTP id g10-20020a056358648a00b0017902af2e29mr546906rwh.20.1707222182463; Tue, 06 Feb 2024 04:23:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222182; cv=pass; d=google.com; s=arc-20160816; b=Ve3sNjDBMc3wqKIuWuZdLupPC3ZLT02vB+6B3WeoRBZbp8oQc+Y+/juckg/mbr+Oo+ BUcrC8ha5SL0dXXyZ86qvgDDB54y4mgfwsekRo5RkJz6gsSZ6fSQI1W/O8q1u+r7kEcU KbLvVAkO7ex8Jc2jgPwiCgeTBxuIkfuj/d8Fe5bVAyfNKI/p+TB0qcupy/qCxf0yXdXZ GATxy4P3UbkFI8YM1KsjnAwWIbCHMhCq3Ml5NcNMPR/Jt8F9vQx+inWfRLTl7M0Oo55b gtQjzY4bsVHdBpbJOQK94d/THbW2hBy0MDPnb+Ti2FCcoHAS6EM7zozGXeVkp3GMXHl1 NWTQ== 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=eoyMY8ac1ATNr0DeVlJsFIdK4Z+8iFYNpQNKuNimR1E=; fh=r53gFJP3sMbzGJTC5i1QVRoQuVDMA2HnQjMutr61MDw=; b=q+gdW7XED2uU6IPihuqYbU9Yohp+jfYJHFhslECM3aq/qxi2jc860CT1OU0q62WKu+ EQHWwPpHkcnS0hG3suKfKXDMzP1NN3hyXnhOiJwXJBRZqcxKc8A1Qf2G4I9odQfbkEf7 pY1kOLiA5TvbnAiyD1VRLIfreRO8noS1wLqA0SUAq6EqpJZiCKDjBuohUCdPvgXDSSXf LxaDdr3PBdxxfm72iduK66rhJ1INWzJ6H2X5PJ5Z6uncvw6VO8pDwx7SXsX90GpmNLM3 ZsZlLDfwU9nPbfTfcmJyhie7jQsnrrRHh1DeC0lzhi6+cyLm1fxypsJTDIi4AZ7tVhyz WVrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54902-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54902-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUcdhvFVr1TkE6oybuzmcFKOcgI+gXByO4L3QHBgyou791sQWLyK0KBSVo8YKo99uRElh37bCRbPuJDfvqe2jfMuCw6HA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id a36-20020a631a24000000b005cf8b7a0629si1557881pga.663.2024.02.06.04.23.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:23:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54902-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-54902-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54902-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 39AAC2820C7 for ; Tue, 6 Feb 2024 12:23:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA0111474DB; Tue, 6 Feb 2024 12:09:32 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88D30138483; Tue, 6 Feb 2024 12:09:22 +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=1707221362; cv=none; b=pOGe1UM4ahG09RGS38FXETeyaJfKRLtCTWeOfC2BI7W78NmaZ9l3n/ocW6OpGp9GVv21WA/EgNhi9R+dkZbkxw9OAkOzCQCysoAZxhZcyYHDwzYQ/3AYkbPZrP2nWd0jJywU8mD25APcPbDY57dySxl3EaJ+yyvlG2tZQIrc6a0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221362; c=relaxed/simple; bh=KWJDRqmuSA25gha7hUXBxRETKbAFvLCSdo+JgHjFgUw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=jd39vp9jKzcOLS384JbeVi1YImJkEvvmaWPDGLiEu9/uYdfxHIeAUQRItr56obtqxPA2reO6KYUrTc9Xkhrbl/jPLuzfYSO1ec3+cddrFCZ7LcUB8qPi49cXKtdVOUpXTFD3jven1Ak+3xF5V1mFDebLRK4jlo+kh7w/j6+ZbXY= 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 754BBC433F1; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGs-00000006bEq-3oIR; Tue, 06 Feb 2024 07:09:50 -0500 Message-ID: <20240206120950.772179769@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:32 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Josef Bacik Subject: [v6.6][PATCH 27/57] eventfs: Move taking of inode_lock into dcache_dir_open_wrapper() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152207662616926 X-GMAIL-MSGID: 1790152207662616926 From: "Steven Rostedt (Google)" The both create_file_dentry() and create_dir_dentry() takes a boolean parameter "lookup", as on lookup the inode_lock should already be taken, but for dcache_dir_open_wrapper() it is not taken. There's no reason that the dcache_dir_open_wrapper() can't take the inode_lock before calling these functions. In fact, it's better if it does, as the lock can be held throughout both directory and file creations. This also simplifies the code, and possibly prevents unexpected race conditions when the lock is released. Link: https://lkml.kernel.org/r/20231121231112.528544825@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reviewed-by: Josef Bacik Signed-off-by: Steven Rostedt (Google) (cherry picked from commit bcae32c5632fc0a0dbce46fa731cd23403117e66) --- fs/tracefs/event_inode.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 56d192f0ead8..590e8176449b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -347,15 +347,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx, mutex_unlock(&eventfs_mutex); - /* The lookup already has the parent->d_inode locked */ - if (!lookup) - inode_lock(parent->d_inode); - dentry = create_file(name, mode, attr, parent, data, fops); - if (!lookup) - inode_unlock(parent->d_inode); - mutex_lock(&eventfs_mutex); if (IS_ERR_OR_NULL(dentry)) { @@ -453,15 +446,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, } mutex_unlock(&eventfs_mutex); - /* The lookup already has the parent->d_inode locked */ - if (!lookup) - inode_lock(parent->d_inode); - dentry = create_dir(ei, parent); - if (!lookup) - inode_unlock(parent->d_inode); - mutex_lock(&eventfs_mutex); if (IS_ERR_OR_NULL(dentry) && !ei->is_freed) { @@ -693,6 +679,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) return -ENOMEM; } + inode_lock(parent->d_inode); list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { d = create_dir_dentry(ei, ei_child, parent, false); @@ -725,6 +712,7 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) cnt++; } } + inode_unlock(parent->d_inode); srcu_read_unlock(&eventfs_srcu, idx); ret = dcache_dir_open(inode, file); From patchwork Tue Feb 6 12:09:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197404 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499342dyb; Tue, 6 Feb 2024 04:23:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGFEeZxao0Ko/ssJTkPFGsz8kXQGeLNrFYXsRZNnsfdjXf7vhHKEhh7Z0lMydoFo4sHonGb X-Received: by 2002:a05:6214:224d:b0:68c:9649:e2fb with SMTP id c13-20020a056214224d00b0068c9649e2fbmr2152319qvc.62.1707222216238; Tue, 06 Feb 2024 04:23:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222216; cv=pass; d=google.com; s=arc-20160816; b=mLhBtidRfMixSogtuNvsIBEqZQ6Hf0eL3DfaYsSWs02LuYY5sNDBsCuOHUr0/uvl5B BRhgPxzxCIoBsQYI+uXp6fozxWb1twMNAyr+idIFdom5t90ibxVOF5sFMv+34m+ajL7E 34OriLjDnNOQgL3H+BWLTOiyST4WNoOJ9kO99t/q5wAm4vm6OC/9+OTlJ4DU5aCxTvoZ 10KM58t8y848AwiIXqfJNQ3wzLCVVyRZ4nl/FqsxNzuh/XlHvbxzlHxuOmLYomIMAs3G Jw9zxP97BoBoRa1hWt2EgD/pF0kupdUhiF7IuGAhF5YWdVGhtNFV4iAks+J9MgfgIYW4 3nXQ== 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=kt+Wx6rLiZ+dqZAOKpCt4s0UO7Nz6IeAXI0rrIUssT4=; fh=CJSBC+JyjrofGJCw5iO3QSJ6l+DzVbxtu+lcQK5SZuE=; b=IHvb0PYC0npujcxJRK9rv3/txpKa7TVeY1D5zCFZSU8yDQGtvgdTpcLkuJu398pZcc LsKSwD0VE7cRMM0xV9uL1M/IV1OE9A9eRehKKVPy+aPPtPCk7EM/g9fl28e7drHi4wyJ i5hvL1HUte91TAi7DeTEtD7c8SJ+Wr+gy/g1MwJYy5/I4imornFnmaXujRr5d9262F6G e+mJDtDLrDmU2zDrGQAYAm2ySHbmBV47SWA+AYQZ04ugY0rtpmotzHeqY4bdd3lmO5ZI mbjr+W0XJsuKFh5aFU5nVNV6TrMrXFQ+Y0Hq/Q6ujU0A0HYRBm2UJlSPF+XQsoxraQrR lMFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54904-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54904-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUXRpUTUOfuEBLQdfkjZkp2MXZlAOdP2BQTiNlKfOCNT/az9pnH3TkGZUI3J5qFneS1nHOdq4/bg/IHRX23unOwFpNBgw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jo19-20020a056214501300b0068cafc7c1bdsi2054956qvb.237.2024.02.06.04.23.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:23:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54904-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54904-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54904-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 0CB011C238A9 for ; Tue, 6 Feb 2024 12:23:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C9D1133434; Tue, 6 Feb 2024 12:09:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA6AD1384B1; Tue, 6 Feb 2024 12:09:22 +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=1707221363; cv=none; b=ggMc1hE9s3NFUWRBl15kA3ZW65H9sdirQecUcWyGdrwgh48eDy1w98yuPR0UtyA4aTQ6CtSj0IyBTfg9y6lBjZncwA7ES+EAKieVU56ROIDlwuMNcJc+CAwkiPPpx0LkT8XZpUXX+3r7JnkZtcTu4smEGN/h8QgM6WdyTuV2Kks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=3SwXKn69jqhTzyrSfRqMAzadq7iwgEqhvz0y/eDGZkM=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=We/dMSdZ0RscfLli4/aLeah+CEeqHaI+M/YwDr3HzXhSr/2podkLi87AJR3lOqeNCMrKrSG/Ggm7TrjiOE8AlJxBuBvsJ4gT9yZ9qNl1nVx2t4AJWCTsrmkNEcLj7Zsel0bbdJD+BjNssGDOLq+7AO71OqLys8UX6ZTK30u7xos= 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 9779BC43390; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGt-00000006bFL-0JBS; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120950.930155940@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:33 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Josef Bacik Subject: [v6.6][PATCH 28/57] eventfs: Do not allow NULL parent to eventfs_start_creating() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152242883125619 X-GMAIL-MSGID: 1790152242883125619 From: "Steven Rostedt (Google)" The eventfs directory is dynamically created via the meta data supplied by the existing trace events. All files and directories in eventfs has a parent. Do not allow NULL to be passed into eventfs_start_creating() as the parent because that should never happen. Warn if it does. Link: https://lkml.kernel.org/r/20231121231112.693841807@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Reviewed-by: Josef Bacik Signed-off-by: Steven Rostedt (Google) (cherry picked from commit fc4561226feaad5fcdcb55646c348d77b8ee69c5) --- fs/tracefs/inode.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 34ffb2f8114e..b9ed8db4f6b9 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -509,20 +509,15 @@ 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 the parent is not specified, we create it in the root. - * We need the root dentry to do this, which is in the super - * block. A pointer to that is in the struct vfsmount that we - * have around. - */ - if (!parent) - parent = tracefs_mount->mnt_root; - if (unlikely(IS_DEADDIR(parent->d_inode))) dentry = ERR_PTR(-ENOENT); else From patchwork Tue Feb 6 12:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197431 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1503625dyb; Tue, 6 Feb 2024 04:31:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvKXzJJAcqPW1dnEIZqb/GUEEZqTRpU9o+XRAg7sjJfUkHU1t9Jv0L9qE11f/Rbx9f/sgG X-Received: by 2002:a05:6a20:3ca2:b0:19e:4f18:b953 with SMTP id b34-20020a056a203ca200b0019e4f18b953mr1243174pzj.16.1707222689795; Tue, 06 Feb 2024 04:31:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222689; cv=pass; d=google.com; s=arc-20160816; b=YKiTLCyTnJ/RdsNn/YNuwuwcsI8pFlVP3Q0UC3dmDQ0JFL4ESqDhKSVeZStif7+sh9 ie64Nola7VITdhTZqzQRQtcElVrlZz7Qx0ynrJocpNU98bBiG8p/pzrPfSLq5WVt6oU7 zDoLUc6N8Gk7VdQoTe40lJJkFb2oOQho9WIyFIHgztymUzGjjghX8YjaS7lSkWPIA3sA UY/47b0kzQ298uqxbw0UK7r6Eq02FjDO1xJDJ9Lg+q/3OdWAQlmuSgS6sQZ24DzGEO/6 itvY4RQiodzlTOOV82DrPQ8f2ehKOshNt9sa29ZjZ3tY9qMVyG20biCXrk/13CSNBd6m nSww== 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=Dsu+LcnJPUhPz5tbtdFla/KW2/YazHKd2WJZ6bKnGpw=; fh=LDmP2gU+Y0UBarqmhNFJZ0bJNCof8YrlQJoOHQenSco=; b=GaCRu5rf4YDZb6lmvAUy/B8YULj+ERuBgRqMjG266Cc1eFw+t0Sbu3DD4JVD6HGEnb 87yiLVEQeGvtFJdGdPidMSKttB/U5SPjpt+E0iA9Uft6XoVqjvibhFJsNpdptvRoPI2D IBSjgPWFCskfo6Dvx5fvS5Pm1qPrinz0Ec/9CN392GWggLPlXnuKT52HVsI4OVV6kDtQ LS4Ad9A74hYBpYTpoez5byoIqSohmCgjznXYxIssI+3Vk0Vq84MPb4pyGKJWA4eQC1kI 2Y3y+PwvF0Lr5gq77rB68rIswn60FtENKAQRUhyIIqOsVB1HSKqBffKPmGXQgiNn/4ri TD8g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54903-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54903-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVImyC3KizFbvfBPAFbtllikaQF/A9UHHyHNmiIppgPa6p5aAi94oh4Dl1+0r7x+W1hKlcv5JQjJsuyOj8gI2b29jDBhg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q21-20020a170902c9d500b001d9607d5cc5si1568515pld.244.2024.02.06.04.31.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:31:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54903-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54903-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54903-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 44E38B21FA5 for ; Tue, 6 Feb 2024 12:23:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 40FFC14831F; Tue, 6 Feb 2024 12:09:33 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2716F1386A8; Tue, 6 Feb 2024 12:09:22 +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=1707221363; cv=none; b=EOtQi83F3qgbvKzZQal4n20UQbfWOkvxzcAkwMhPlkFpvl9oaQ3BSdmhSZGv1QpSyhQao7w5KVSyYx6nwxks7pRPDEZfSWSAo0fcwjff0D4DcHkRnWKt14E5LlADXnQHtY66Qd9/AybVVhcA7cwM6lid8XXG83SIG9+1m4Y6/gk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=bXsar5R8Z/J/4GcAeyNBhLTiQlp64pDEtOV6uUPgCcU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=iwDdkAlUQr+Eu5VlJxUOYeuy9Wb+7XFlpGkbIBoXCmiPQidqM8K1Hj770LTw2s0MU8O1qBrwalrbKWykQIUOfq7n9g7acVkQhTvZOCM8NA6bSyhsjIcuhf/VZ4hl21EqFfqdxro817piU3auD8oajToz3PzNBhdwU6Olytw1Yww= 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 C479FC433C7; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGt-00000006bFq-0z3I; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120951.095364893@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:34 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Josef Bacik Subject: [v6.6][PATCH 29/57] eventfs: Make sure that parent->d_inode is locked in creating files/dirs References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152739122060965 X-GMAIL-MSGID: 1790152739122060965 From: "Steven Rostedt (Google)" Since the locking of the parent->d_inode has been moved outside the creation of the files and directories (as it use to be locked via a conditional), add a WARN_ON_ONCE() to the case that it's not locked. Link: https://lkml.kernel.org/r/20231121231112.853962542@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Andrew Morton Reviewed-by: Josef Bacik Signed-off-by: Steven Rostedt (Google) (cherry picked from commit f49f950c217bfb40f11662bab39cb388d41e4cfb) --- fs/tracefs/event_inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 590e8176449b..0b90869fd805 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -327,6 +327,8 @@ create_file_dentry(struct eventfs_inode *ei, int idx, 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); @@ -430,6 +432,8 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, { 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); From patchwork Tue Feb 6 12:09:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197403 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499237dyb; Tue, 6 Feb 2024 04:23:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/qgn8JVidykmyrSbVUKkqolkvB0X/2klz5J2RRuqVG08H5NbBg1e9jZ5nRz+0pAVv5YWJ X-Received: by 2002:a17:907:3fa4:b0:a38:2bef:611e with SMTP id hr36-20020a1709073fa400b00a382bef611emr1297707ejc.49.1707222204078; Tue, 06 Feb 2024 04:23:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222204; cv=pass; d=google.com; s=arc-20160816; b=zYCNNHoMMqfPlG61cHWci6/KZrX34kQHWsE2BVX5ySxKWzfTxeMXVI7KOjVgm7LUYo kAQdHGn/IiSHxfSBJ7cScePVPuvguZJsEUpBpuTUj4oTTCbRzQ2Pv+5UQ3aFR+CQd/9c hHqSBm5gvVeCEmFyh8puMjRJG/7BXJZgwXZED3BqL8HMVdnBk+PqRJKjdbYCsOeY3ngC zoY6ary0zfDawBdj8EROCBfy+AyELkXs5la2r5qEUKFsBbtEP9j4ufyb95NuiMcGwd8h zKogVY1QXenbGSoOl7U+tUkFbZR7WIBHO0Aet3TmfeIE8GZMEjaAwxfFTXzPRRjTf+z3 pwIw== 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=Lp0RKTj6GGbabZSHcEFR+RYAu/yyivVY0LVkvEguOj0=; fh=SpUiXBZymF7zCTwH888pHR9dS01LnmMhkiGrnqP31cY=; b=SgBudT9U3/4BpLTenCXLarWOj31vOx967tNQLQwE0q7UiIFdFaI9pvBX+1XaGEBij7 b4dF5pSx4UcAMrvubcbAdwOf+vtV02mFbj7gjO2m0s0Y3R4EpKzwHiyUGz4WcIZNnzKl 9nXPt3+hiecPiY7GUqfKlasfhcD+LklFH9Hi+AW7m4Kug8PLmzqfJRB8+Ty9i8RkHAKm k1CEE7VHCtxnG8gh2po3+sEE9GgiupECbxhzH6kwHMUANdt8HDGav/WEivcME563lWYq PPeE6BZNR/GG5OLK9OQry4mzlAuFi92n8GDyWR05YRvCVyANrOdvc3y0u+bnyJKlIHSW Q1mA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54906-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54906-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWmQXBwsfnjoke0D1MEAt5HAcLu2wifygjaEqFmAFC7QbyRJuPMCLAHiwlbZ8fmh6aIyCNe36bmzcI726TMkmuUl7swlA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lh9-20020a170906f8c900b00a35a576b259si986833ejb.922.2024.02.06.04.23.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:23:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54906-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-54906-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54906-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 A37D21F220D0 for ; Tue, 6 Feb 2024 12:23:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C2FA133427; Tue, 6 Feb 2024 12:09:33 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51A991386BD; Tue, 6 Feb 2024 12:09:23 +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=1707221363; cv=none; b=qnRT6Iobxg1lbn32nGnIVCSlBgDHPmaCXBOzUTf+WJ0AqeylxdCB/M0z8g0uFnhqtjKkxaS6ugTjYLqHOIOsfSQZy5Aja20o6xJT/rBOpRZgyiQGEAW81rxyMC+0hn52V7rRxcDOQdVnYQzCxkkYAHjksK/cf+ODjLo33lAH88A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=SD2Ctw8XfUaOuPz+cDqcSSEYSx7EhLuOjt5hoKj8zpc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qeEQq3REkzClJaKMN7lYX2/Var1q1m1BEBV8mSMuMf9KRKi1yEtq2IwOMdqonFbRn3iSLD75NY8M/YABf221Q1VJ3QTaRG7/UOwsdoZ38yjzwsxvOnnhe/D2+ClKHs7HCP+13W/+oPt1RZBKw3LLDkgqyEfi08UDRaytnzChvtk= 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 E6A4BC43394; Tue, 6 Feb 2024 12:09:22 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGt-00000006bGL-1eGZ; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120951.255146556@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:35 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Beau Belgrave Subject: [v6.6][PATCH 30/57] eventfs: Fix events beyond NAME_MAX blocking tasks References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152230209842762 X-GMAIL-MSGID: 1790152230209842762 From: Beau Belgrave Eventfs uses simple_lookup(), however, it will fail if the name of the entry is beyond NAME_MAX length. When this error is encountered, eventfs still tries to create dentries instead of skipping the dentry creation. When the dentry is attempted to be created in this state d_wait_lookup() will loop forever, waiting for the lookup to be removed. Fix eventfs to return the error in simple_lookup() back to the caller instead of continuing to try to create the dentry. Link: https://lore.kernel.org/linux-trace-kernel/20231210213534.497-1-beaub@linux.microsoft.com Fixes: 63940449555e ("eventfs: Implement eventfs lookup, read, open functions") Link: https://lore.kernel.org/linux-trace-kernel/20231208183601.GA46-beaub@linux.microsoft.com/ Signed-off-by: Beau Belgrave Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 5eaf7f0589c0d88178f0fbeebe0e0b7108258707) --- fs/tracefs/event_inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 0b90869fd805..43e237864a42 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -546,6 +546,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, if (strcmp(ei_child->name, name) != 0) continue; ret = simple_lookup(dir, dentry, flags); + if (IS_ERR(ret)) + goto out; create_dir_dentry(ei, ei_child, ei_dentry, true); created = true; break; @@ -568,6 +570,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, if (r <= 0) continue; ret = simple_lookup(dir, dentry, flags); + if (IS_ERR(ret)) + goto out; create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops, true); break; From patchwork Tue Feb 6 12:09:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499388dyb; Tue, 6 Feb 2024 04:23:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhfD3BdBIl3sG1Ln43oMnLPkD8LJUhqks1AZLOuqV7b8M28y+BddsLl80z8yi9wpNWmnNt X-Received: by 2002:a05:6870:1588:b0:218:ec6c:3985 with SMTP id j8-20020a056870158800b00218ec6c3985mr2236419oab.56.1707222222634; Tue, 06 Feb 2024 04:23:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222222; cv=pass; d=google.com; s=arc-20160816; b=ug4HD+9UjwjeKqG14V37rli7Ml6bryqS62fgZpjzyV+yEXjkLWZ+UoK8HCc8vaREem dNvbp86jaY8OHxlLlQ2E4p69gI/fvs0vbshBNqbo7MDcFts50Pvb/EKweiE5Ix2V50KO GydN6g0wKXR/oBKr0OgfH1lWkk7zA3PxEN0RVXFdcYjsrnSBCX+bgUDtO0hgx+FcCYdE VbKg1CZCZSYKxnpne+DUrgwmXYUFBhYmE6qtiKpXVJFRSrpzYYFttgFzGa9i4znwJCtK 5Hw/2NeMTIyR0Oyc5sBu8I822NZU/npLx2sPyPtkUp0c3NUY2JrnTCYCgeRWnFtitwCL ZrpA== 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=D1lMMwfNIo/iun5f/a1ei7r2rQaMlqe+h2QWTA4tZB0=; fh=PXGad+PhJD1mWphvUpDerIAF+D9ZTpVdxM7OHJHftmg=; b=aBQvHpk7ZRzBhq2EEB7rCz9cWjnGCLJvpOuwcHbX1AkFs76Otwxk1pQczdfDmnqlNU lxTpl2ijiXLKFcZ0Ry2QEHkpTeyCg6mHc+IMVuFMQlw5q69R0WzfbcuAjxaz6pzWV1nX lVMxhXcU6sCfQd7A5qicuXfETECk1kRc5huJvUY1KUua0sAE0bnOJuEWpiMHyHitmt6l 8BzuZTYbKVVssskFUWPnF6P4hiehRLVPH8vI/6Vys+g4CN0TLPwubK9wBPvr2DISY2XX 1sbqrm4eT7wYXtcnYRUNJHlWj9qscLt6MqLYXSFOwOWSNyJ0W5Og1zZJGvOAHqlVQXOY USSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54905-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54905-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUeFn37SvFQnyTTVeRzzpsA7vYiSjX2ynbmAEP8tLMGdSeUyhAXZvuEonrOKHxSszavVjTqVhUCjOlOWXtKjdotuxIHbQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d10-20020a65424a000000b005d61412ca90si1490770pgq.453.2024.02.06.04.23.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:23:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54905-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-54905-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54905-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 65889282B33 for ; Tue, 6 Feb 2024 12:23:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 43035141998; Tue, 6 Feb 2024 12:09:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 360F21386AA; Tue, 6 Feb 2024 12:09:23 +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=1707221363; cv=none; b=N7VLx7rxtb9fnnoEKNl661W3SUGL04KlFsqTUebZudYL1rFp/WZIKU/7ahZm7n3QBIGHSArM0Xga4MwXuDrfHfmhIkRSnAzHepoBOoYSGKoJYdJk9RpByc+XO2wuPRLO/2Uj7cMo+9YKny+k6VuM7vyZWNkKox1M3tvpJ43ZAag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=AUJA/mt2ARUFiCQkvFXc/lpdvePIFrv+PiQkEn2vk7s=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HnzRYATPuzty+jJVLuf8Z7j12shbJamMTWRsKF0JnkICEZlvaLG3gwJuN4FKrPoUkB/NTrtCHoi3VIlJYtnjltzub3lW9kG7CvGErajPTtsmdMbTwPBJ3MHqjpAZC6zmgnj7RhVV3BYmZhgmeU+SY7TEkAlsdvaQ2KhuNuf/few= 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 22E34C43399; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGt-00000006bGq-2KvK; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120951.415245327@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:36 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Hongyu Jin , Dongliang Cui Subject: [v6.6][PATCH 31/57] eventfs: Have event files and directories default to parent uid and gid References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152249508724419 X-GMAIL-MSGID: 1790152249508724419 From: "Steven Rostedt (Google)" Dongliang reported: I found that in the latest version, the nodes of tracefs have been changed to dynamically created. This has caused me to encounter a problem where the gid I specified in the mounting parameters cannot apply to all files, as in the following situation: /data/tmp/events # mount | grep tracefs tracefs on /data/tmp type tracefs (rw,seclabel,relatime,gid=3012) gid 3012 = readtracefs /data/tmp # ls -lh total 0 -r--r----- 1 root readtracefs 0 1970-01-01 08:00 README -r--r----- 1 root readtracefs 0 1970-01-01 08:00 available_events ums9621_1h10:/data/tmp/events # ls -lh total 0 drwxr-xr-x 2 root root 0 2023-12-19 00:56 alarmtimer drwxr-xr-x 2 root root 0 2023-12-19 00:56 asoc It will prevent certain applications from accessing tracefs properly, I try to avoid this issue by making the following modifications. To fix this, have the files created default to taking the ownership of the parent dentry unless the ownership was previously set by the user. Link: https://lore.kernel.org/linux-trace-kernel/1703063706-30539-1-git-send-email-dongliang.cui@unisoc.com/ Link: https://lore.kernel.org/linux-trace-kernel/20231220105017.1489d790@gandalf.local.home Cc: stable@vger.kernel.org Cc: Mathieu Desnoyers Cc: Hongyu Jin Fixes: 28e12c09f5aa0 ("eventfs: Save ownership and mode") Acked-by: Masami Hiramatsu (Google) Reported-by: Dongliang Cui Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 0dfc852b6fe3cbecbea67332a0dce2bebeba540d) --- fs/tracefs/event_inode.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 43e237864a42..2ccc849a5bda 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -148,7 +148,8 @@ static const struct file_operations eventfs_file_operations = { .release = eventfs_release, }; -static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, umode_t mode) +static void update_inode_attr(struct dentry *dentry, struct inode *inode, + struct eventfs_attr *attr, umode_t mode) { if (!attr) { inode->i_mode = mode; @@ -162,9 +163,13 @@ static void update_inode_attr(struct inode *inode, struct eventfs_attr *attr, um if (attr->mode & EVENTFS_SAVE_UID) inode->i_uid = attr->uid; + else + inode->i_uid = d_inode(dentry->d_parent)->i_uid; if (attr->mode & EVENTFS_SAVE_GID) inode->i_gid = attr->gid; + else + inode->i_gid = d_inode(dentry->d_parent)->i_gid; } /** @@ -206,7 +211,7 @@ static struct dentry *create_file(const char *name, umode_t mode, return eventfs_failed_creating(dentry); /* If the user updated the directory's attributes, use them */ - update_inode_attr(inode, attr, mode); + update_inode_attr(dentry, inode, attr, mode); inode->i_op = &eventfs_file_inode_operations; inode->i_fop = fop; @@ -242,7 +247,8 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent return eventfs_failed_creating(dentry); /* If the user updated the directory's attributes, use them */ - update_inode_attr(inode, &ei->attr, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO); + update_inode_attr(dentry, inode, &ei->attr, + S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO); inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; From patchwork Tue Feb 6 12:09:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197432 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1504876dyb; Tue, 6 Feb 2024 04:33:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFfRg+ukGDlBvzDmCrp3x8DO5kenp9EbFXR5YhZgumaOrzyYjhaopa42vJJ0gnf2b2qcACY X-Received: by 2002:a17:90b:230b:b0:296:1ac3:c573 with SMTP id mt11-20020a17090b230b00b002961ac3c573mr1999457pjb.15.1707222822383; Tue, 06 Feb 2024 04:33:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222822; cv=pass; d=google.com; s=arc-20160816; b=TuPZRUpuVbRV1iwmrNyvkYQyach48jLoK+E3IqLGdmhZQpKg3gmPQsBy9KlUDeglB9 DGwID8cnESI1YH48cNELU05BSGtMIcE3n401qnl42wUyi/rWuUR8MuJS8fOH3h+ZwPHH rbTGA9tZkjt6B4A3x6F0oewNkDAw9GxhFeOAsc9thxjnIwfzqNvAwQ6W1Ct53YSFiL+E PajF+X6qePXCPoyoO8aVPA7gtErGVirKEtdYYPMEB3m3/oULZL89EZXsoQBFTTgAAByy BNyiJ1SBMJ0c5xc2bHjM7+memc8YVbM6GY9HO27lteVnGb+VmIJ8U30YGWzk7RiXsVJf cz/w== 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=6ahLNXpRQ0H6IubAxFhLxTvbsaGsbCwjIyakSDPZd9c=; fh=NsHFoXTRgPQJTX4Plb7giGLqt1uLFs87jgAZ2FmrDWk=; b=fUCcMXpIw7d2O/Ec6IJKOQ0CS2yqCWumU9r05GtpIRmWs0HBFTWgkRcBWc3QiDF13A FhO4mcI+typOYB8fSkx2+K2pI+s4DC1GgMHgsqliHbzJ0rOSW1DKeEQuQBxbL+zJ8PUs 849r+b2cL6H/y6Fvr1KOvycycmkN9sU3H8TeL/CvOIWcONn7fpY43nGZGBHowfxyx7Bf FJbmBEYOp3stWTcZlpt9+ytNVCRZSUUF9C7Guu+qpRXuXHnW7SLlFOSb8qFT49mlBEcJ 6fBkUCuLzdxOc9wDWDIhLPOGkr7k4fW8G/yadqCd2ubCuOMAHozQu2Xyoaw7cyF5RhLV BTNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54907-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54907-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUuAR6QlPx1/JK4Jf/E9cDIZLBS6byGTYDoS34WOIr6Or9Nw+P8quYOUs1VfD5PNg2wPEWDQCBqNXkgaCM2OLFeVFFt8Q== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id y4-20020a17090a1f4400b00292a409e5b3si1053149pjy.55.2024.02.06.04.33.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:33:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54907-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54907-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54907-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 0BA0EB215EF for ; Tue, 6 Feb 2024 12:24:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E876F14A4EB; Tue, 6 Feb 2024 12:09:35 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E4DB1386CC; Tue, 6 Feb 2024 12:09:23 +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=1707221363; cv=none; b=bAe84442nxwBdab+f6YxyXs8I3/HSSgT39g+m3SpA8PEmXMGhOQ+hHc6qJSU7K/dosJ4QcDeMVyBivZBExoRdqhA5cY8oTzB+LhQ92qwTHyFphCdmiZpTLa0R/+qlG0ie7rHzv7hqRpuxKcVpL2yT841GKHDgA2pD1TOsRvyO+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=OaEXpMU8THyUZWNI/AxvCRbUXE4WI1LDjk5ZPgiKiT8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ni8WzMFHeZh3ZufBpSjRLLOUWPyLjxfbK3WsN4D3NdRxQDqFPbGuNjiql7WI43s1n60j40qzbKwnlUFqHomBOrcP2vGcNnGDxTYyIz1CHrK820rN+kz2VtJ7ZK5hIHdECsF59IcM6MfWTUmjY0rKr6WMwTzjbRVu+Q/PJgkoMOw= 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 4C07EC433A6; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGt-00000006bHL-30yX; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120951.578630343@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:37 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Dongliang Cui , Hongyu Jin Subject: [v6.6][PATCH 32/57] eventfs: Fix file and directory uid and gid ownership References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152877982613285 X-GMAIL-MSGID: 1790152877982613285 From: "Steven Rostedt (Google)" It was reported that when mounting the tracefs file system with a gid other than root, the ownership did not carry down to the eventfs directory due to the dynamic nature of it. A fix was done to solve this, but it had two issues. (a) if the attr passed into update_inode_attr() was NULL, it didn't do anything. This is true for files that have not had a chown or chgrp done to itself or any of its sibling files, as the attr is allocated for all children when any one needs it. # umount /sys/kernel/tracing # mount -o rw,seclabel,relatime,gid=1000 -t tracefs nodev /mnt # ls -ld /mnt/events/sched drwxr-xr-x 28 root rostedt 0 Dec 21 13:12 /mnt/events/sched/ # ls -ld /mnt/events/sched/sched_switch drwxr-xr-x 2 root rostedt 0 Dec 21 13:12 /mnt/events/sched/sched_switch/ But when checking the files: # ls -l /mnt/events/sched/sched_switch total 0 -rw-r----- 1 root root 0 Dec 21 13:12 enable -rw-r----- 1 root root 0 Dec 21 13:12 filter -r--r----- 1 root root 0 Dec 21 13:12 format -r--r----- 1 root root 0 Dec 21 13:12 hist -r--r----- 1 root root 0 Dec 21 13:12 id -rw-r----- 1 root root 0 Dec 21 13:12 trigger (b) When the attr does not denote the UID or GID, it defaulted to using the parent uid or gid. This is incorrect as changing the parent uid or gid will automatically change all its children. # chgrp tracing /mnt/events/timer # ls -ld /mnt/events/timer drwxr-xr-x 2 root tracing 0 Dec 21 14:34 /mnt/events/timer # ls -l /mnt/events/timer total 0 -rw-r----- 1 root root 0 Dec 21 14:35 enable -rw-r----- 1 root root 0 Dec 21 14:35 filter drwxr-xr-x 2 root tracing 0 Dec 21 14:35 hrtimer_cancel drwxr-xr-x 2 root tracing 0 Dec 21 14:35 hrtimer_expire_entry drwxr-xr-x 2 root tracing 0 Dec 21 14:35 hrtimer_expire_exit drwxr-xr-x 2 root tracing 0 Dec 21 14:35 hrtimer_init drwxr-xr-x 2 root tracing 0 Dec 21 14:35 hrtimer_start drwxr-xr-x 2 root tracing 0 Dec 21 14:35 itimer_expire drwxr-xr-x 2 root tracing 0 Dec 21 14:35 itimer_state drwxr-xr-x 2 root tracing 0 Dec 21 14:35 tick_stop drwxr-xr-x 2 root tracing 0 Dec 21 14:35 timer_cancel drwxr-xr-x 2 root tracing 0 Dec 21 14:35 timer_expire_entry drwxr-xr-x 2 root tracing 0 Dec 21 14:35 timer_expire_exit drwxr-xr-x 2 root tracing 0 Dec 21 14:35 timer_init drwxr-xr-x 2 root tracing 0 Dec 21 14:35 timer_start At first it was thought that this could be easily fixed by just making the default ownership of the superblock when it was mounted. But this does not handle the case of: # chgrp tracing instances # mkdir instances/foo If the superblock was used, then the group ownership would be that of what it was when it was mounted, when it should instead be "tracing". Instead, set a flag for the top level eventfs directory ("events") to flag which eventfs_inode belongs to it. Since the "events" directory's dentry and inode are never freed, it does not need to use its attr field to restore its mode and ownership. Use the this eventfs_inode's attr as the default ownership for all the files and directories underneath it. When the events eventfs_inode is created, it sets its ownership to its parent uid and gid. As the events directory is created at boot up before it gets mounted, this will always be uid=0 and gid=0. If it's created via an instance, then it will take the ownership of the instance directory. When the file system is mounted, it will update all the gids if one is specified. This will have a callback to update the events evenfs_inode's default entries. When a file or directory is created under the events directory, it will walk the ei->dentry parents until it finds the evenfs_inode that belongs to the events directory to retrieve the default uid and gid values. Link: https://lore.kernel.org/all/CAHk-=wiwQtUHvzwyZucDq8=Gtw+AnwScyLhpFswrQ84PjhoGsg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20231221190757.7eddbca9@gandalf.local.home Cc: stable@vger.kernel.org Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Dongliang Cui Cc: Hongyu Jin Fixes: 0dfc852b6fe3 ("eventfs: Have event files and directories default to parent uid and gid") Reviewed-by: Masami Hiramatsu (Google) Tested-by: Masami Hiramatsu (Google) Reported-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 7e8358edf503e87236c8d07f69ef0ed846dd5112) --- fs/tracefs/event_inode.c | 105 +++++++++++++++++++++++++++++++++++---- fs/tracefs/inode.c | 6 +++ fs/tracefs/internal.h | 2 + 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 2ccc849a5bda..f0677ea0ec24 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -113,7 +113,14 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, * determined by the parent directory. */ if (dentry->d_inode->i_mode & S_IFDIR) { - update_attr(&ei->attr, iattr); + /* + * The events directory dentry is never freed, unless its + * part of an instance that is deleted. It's attr is the + * default for its child files and directories. + * Do not update it. It's not used for its own mode or ownership + */ + if (!ei->is_events) + update_attr(&ei->attr, iattr); } else { name = dentry->d_name.name; @@ -148,28 +155,93 @@ static const struct file_operations eventfs_file_operations = { .release = eventfs_release, }; +/* Return the evenfs_inode of the "events" directory */ +static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) +{ + struct eventfs_inode *ei; + + mutex_lock(&eventfs_mutex); + do { + /* The parent always has an ei, except for events itself */ + ei = dentry->d_parent->d_fsdata; + + /* + * If the ei is being freed, the ownership of the children + * doesn't matter. + */ + if (ei->is_freed) { + ei = NULL; + break; + } + + dentry = ei->dentry; + } while (!ei->is_events); + mutex_unlock(&eventfs_mutex); + + return ei; +} + static void update_inode_attr(struct dentry *dentry, struct inode *inode, struct eventfs_attr *attr, umode_t mode) { - if (!attr) { - inode->i_mode = mode; + struct eventfs_inode *events_ei = eventfs_find_events(dentry); + + if (!events_ei) + return; + + inode->i_mode = mode; + inode->i_uid = events_ei->attr.uid; + inode->i_gid = events_ei->attr.gid; + + if (!attr) return; - } if (attr->mode & EVENTFS_SAVE_MODE) inode->i_mode = attr->mode & EVENTFS_MODE_MASK; - else - inode->i_mode = mode; if (attr->mode & EVENTFS_SAVE_UID) inode->i_uid = attr->uid; - else - inode->i_uid = d_inode(dentry->d_parent)->i_uid; if (attr->mode & EVENTFS_SAVE_GID) inode->i_gid = attr->gid; - else - inode->i_gid = d_inode(dentry->d_parent)->i_gid; +} + +static void update_gid(struct eventfs_inode *ei, kgid_t gid, int level) +{ + struct eventfs_inode *ei_child; + + /* at most we have events/system/event */ + if (WARN_ON_ONCE(level > 3)) + return; + + ei->attr.gid = gid; + + if (ei->entry_attrs) { + for (int i = 0; i < ei->nr_entries; i++) { + ei->entry_attrs[i].gid = gid; + } + } + + /* + * Only eventfs_inode with dentries are updated, make sure + * all eventfs_inodes are updated. If one of the children + * do not have a dentry, this function must traverse it. + */ + list_for_each_entry_srcu(ei_child, &ei->children, list, + srcu_read_lock_held(&eventfs_srcu)) { + if (!ei_child->dentry) + update_gid(ei_child, gid, level + 1); + } +} + +void eventfs_update_gid(struct dentry *dentry, kgid_t gid) +{ + struct eventfs_inode *ei = dentry->d_fsdata; + int idx; + + idx = srcu_read_lock(&eventfs_srcu); + update_gid(ei, gid, 0); + srcu_read_unlock(&eventfs_srcu, idx); } /** @@ -860,6 +932,8 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry struct eventfs_inode *ei; struct tracefs_inode *ti; struct inode *inode; + kuid_t uid; + kgid_t gid; if (security_locked_down(LOCKDOWN_TRACEFS)) return NULL; @@ -884,11 +958,20 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry ei->dentry = 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; + gid = d_inode(dentry->d_parent)->i_gid; + + /* This is used as the default ownership of the files and directories */ + ei->attr.uid = uid; + ei->attr.gid = gid; + INIT_LIST_HEAD(&ei->children); INIT_LIST_HEAD(&ei->list); @@ -897,6 +980,8 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry ti->private = ei; inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; + inode->i_uid = uid; + inode->i_gid = gid; inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index b9ed8db4f6b9..7b0ba379d6d7 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -210,6 +210,7 @@ static void set_gid(struct dentry *parent, kgid_t gid) next = this_parent->d_subdirs.next; resume: while (next != &this_parent->d_subdirs) { + struct tracefs_inode *ti; struct list_head *tmp = next; struct dentry *dentry = list_entry(tmp, struct dentry, d_child); next = tmp->next; @@ -218,6 +219,11 @@ static void set_gid(struct dentry *parent, kgid_t gid) change_gid(dentry, gid); + /* If this is the events directory, update that too */ + ti = get_tracefs(dentry->d_inode); + if (ti && (ti->flags & TRACEFS_EVENT_INODE)) + eventfs_update_gid(dentry, gid); + if (!list_empty(&dentry->d_subdirs)) { spin_unlock(&this_parent->d_lock); spin_release(&dentry->d_lock.dep_map, _RET_IP_); diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index ccee18ca66c7..899e447778ac 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -62,6 +62,7 @@ struct eventfs_inode { struct rcu_head rcu; }; unsigned int is_freed:1; + unsigned int is_events:1; unsigned int nr_entries:31; }; @@ -77,6 +78,7 @@ struct inode *tracefs_get_inode(struct super_block *sb); struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); struct dentry *eventfs_failed_creating(struct dentry *dentry); struct dentry *eventfs_end_creating(struct dentry *dentry); +void eventfs_update_gid(struct dentry *dentry, kgid_t gid); void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 12:09:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197407 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499958dyb; Tue, 6 Feb 2024 04:24:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFhlWulReVeynWy5Wlb6Z6+IzwDxkh6kiElQGFV2LnS/gBKfqXhxS7VMDoOw2t1HvzPZ53q X-Received: by 2002:a17:903:11c6:b0:1d9:91a0:da43 with SMTP id q6-20020a17090311c600b001d991a0da43mr1679212plh.31.1707222288904; Tue, 06 Feb 2024 04:24:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222288; cv=pass; d=google.com; s=arc-20160816; b=x1xpkRavpUqkXB3aVOksWq8jzSeye/85hNq9pu+mjvCNaKULT3sR27rMlx8TkUySvx ob2wE6RHJaRb4Ek5VZ5bOYQ+ELWmq62pNur71UzI3oaOW8aF88FqKYILhgZr1cKR5Q9M o1WMBPHaXhxmfaKIXiyzrihB77Lbfa+cejGC89WWKv1q/2TL+Sq+ntzvjShKm17pQsA0 hcQQ6yTWY5HxLMkGQs7K0hfMRNzUtUSf+F6mRfWIyP+HFHVi8lpYrQ04Dr4wgCfTLLR2 SupuYgiriHFWs8S3zjN5tzlL5efpwfVNJgc2KKQFEsdamcCIUcPXoPRJjOLuU8PKPoa7 yiYA== 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=wE7EPYIHf2FfE+GXOOkTMGEZO80pH7kcFtx3B2zdVj8=; fh=YRpGb1PUiARXZtm6P5l+SWQtgUtnCJSlVroGFnBrqQs=; b=PXYWBBd5vg+fZ8LRRK0PO/B4OYHs8BtbP6RLWxMcxVDVfVXMWkiSCRmhIS5M9oPjK9 V7lf7MgcsIfn7PmyveL2p3aYUVNnDNZWzYUPyalRZRQinpcchv4h/9q2ij98CFJSGO2F qDRrtqeFWe4pn170jPAbWj9uYKZGiEBj5sc+uWvIJtEK2eXw/rTsSS97Hz4hF8oq7Lu2 S4M38SOgvBXlMOGuodMqaeWYNuiPCLDuFbFZm3v/MfDDpbxdoL7qzIw2YRKPxhI19X8I 1WObzWmrda/tb3ziffql7KYpx7GInL9Yzzz/4/ji/jqWcAND95z6h8CYloQL6xM+mw3t m0yg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54908-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54908-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUAFCQbyjKtT+JKco4LSzCciAI5T3ZQs8pUOnnMDvCEcddvLLcPR6weXM9abT7kQJQOk+ol67aIokiuuia9Q3SRpzZ+oQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z16-20020a170903019000b001d94c11e7ebsi1612096plg.372.2024.02.06.04.24.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:24:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54908-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-54908-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54908-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 642222816BF for ; Tue, 6 Feb 2024 12:23:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5DB4149003; Tue, 6 Feb 2024 12:09:34 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85ADF1386DD; Tue, 6 Feb 2024 12:09:23 +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=1707221363; cv=none; b=exv13tten1F/yXmIzNi6zOU0f/JDQw+bXw9z5QKSSiaQjSGXO+Sx8LQOEYSbX3SMAlGdgKm3km3f0n0kEGuND/fykv5Cip35DZE+LR9bXIRfo66U0CtzsfDbBZXKfatbxPIlhoHxIPC3tH7PPdlxz84XkbuKxn+Cn2a1KOL30BQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=uCRKBFI8oZi6Z1Cps+YjkEugAUzD0pvOcGwAbYn4DiE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=qXo+yvNaZXZlfi6rEv0QYuVHh/oi1zXrJZ4xiiGI1sWkZX0i1RiRJieTJAzjQ449o4eSOTU++ox0EaINzewYKNwMWQQ/vym/x8snUAxU5XczQhcMhBG1sAXNtk8E1gvprywFyzq5K3iHdw3+OasS72MMbILKHE6xnt3tAoJvK00= 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 72A2AC433C7; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGt-00000006bHq-3giE; Tue, 06 Feb 2024 07:09:51 -0500 Message-ID: <20240206120951.738927603@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:38 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , "Ubisectech Sirius" Subject: [v6.6][PATCH 33/57] tracefs: Check for dentry->d_inode exists in set_gid() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152318408915314 X-GMAIL-MSGID: 1790152318408915314 From: "Steven Rostedt (Google)" If a getdents() is called on the tracefs directory but does not get all the files, it can leave a "cursor" dentry in the d_subdirs list of tracefs dentry. This cursor dentry does not have a d_inode for it. Before referencing tracefs_inode from the dentry, the d_inode must first be checked if it has content. If not, then it's not a tracefs_inode and can be ignored. The following caused a crash: #define getdents64(fd, dirp, count) syscall(SYS_getdents64, fd, dirp, count) #define BUF_SIZE 256 #define TDIR "/tmp/file0" int main(void) { char buf[BUF_SIZE]; int fd; int n; mkdir(TDIR, 0777); mount(NULL, TDIR, "tracefs", 0, NULL); fd = openat(AT_FDCWD, TDIR, O_RDONLY); n = getdents64(fd, buf, BUF_SIZE); ret = mount(NULL, TDIR, NULL, MS_NOSUID|MS_REMOUNT|MS_RELATIME|MS_LAZYTIME, "gid=1000"); return 0; } That's because the 256 BUF_SIZE was not big enough to read all the dentries of the tracefs file system and it left a "cursor" dentry in the subdirs of the tracefs root inode. Then on remounting with "gid=1000", it would cause an iteration of all dentries which hit: ti = get_tracefs(dentry->d_inode); if (ti && (ti->flags & TRACEFS_EVENT_INODE)) eventfs_update_gid(dentry, gid); Which crashed because of the dereference of the cursor dentry which had a NULL d_inode. In the subdir loop of the dentry lookup of set_gid(), if a child has a NULL d_inode, simply skip it. Link: https://lore.kernel.org/all/20240102135637.3a21fb10@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240102151249.05da244d@gandalf.local.home Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Fixes: 7e8358edf503e ("eventfs: Fix file and directory uid and gid ownership") Reported-by: "Ubisectech Sirius" Signed-off-by: Steven Rostedt (Google) (cherry picked from commit ad579864637af46447208254719943179b69d41a) --- fs/tracefs/inode.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 7b0ba379d6d7..c27b0cfff70c 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -215,6 +215,10 @@ static void set_gid(struct dentry *parent, kgid_t gid) struct dentry *dentry = list_entry(tmp, struct dentry, d_child); next = tmp->next; + /* Note, getdents() can add a cursor dentry with no inode */ + if (!dentry->d_inode) + continue; + spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); change_gid(dentry, gid); From patchwork Tue Feb 6 12:09:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197406 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1499621dyb; Tue, 6 Feb 2024 04:24:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGoFZvXXTATKtGC6Qq8x1tHzXNh3mhliVfOoZNAkm8bNsbdBjNpu53UCteQOfNAyVUixMA+ X-Received: by 2002:a05:651c:220d:b0:2d0:b090:be91 with SMTP id y13-20020a05651c220d00b002d0b090be91mr1877467ljq.6.1707222250706; Tue, 06 Feb 2024 04:24:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222250; cv=pass; d=google.com; s=arc-20160816; b=z5DHzBLv5fncFZ4ad6mzl8JLBcrl6HiFYIRivdHxe8ea9mfVt6usWSw/NEawa+uryZ CuazTljGScI7iBDkmsFfif6cgERAvOitfmLH/+378khhCleMWCNCimbgo1vnDAKqJHoY P1QD28ZYIGRPYyTWV6UkxiIghcNtZ8wCAPI93sNoHLnHS+UdVJz8cUHBdqsPNvTYpLpT 1/EYTIBqXHWFY6yDwITe+J9vCCEtfR+odI6xDKi3+wDlXnsYttyuLU0BW24WmhEyv8Kd IYN0TQAkIJMNT9L4d3drDlqq2SCgnEeXJwd/c1bv4eytmNgWlL9ggBRQaqYl4tjaHtQf /lHw== 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=8lURNWKKoUPcQ/ppbGjY8iYp0fTSqUBjsyeTeR/nU/o=; fh=gRrk8HgmudHb1fPCkAX2Zofa2UjNVWZwpqqAosOwwRM=; b=bkiCzxKuL7ZmRDHHOusWNJN3cgnSKzrDm3VwWJEzEniaXiIU5gMI/cHRcEFJOxnQ7b 79Tq8mX99lHp+6zm/s5GyN2SoSd+HnO5mlD7cTPSEaxFWPDtRTyJVy4qvJP08875Hu0T hnp/Zg7XxZIU90K6RZmUNmRm9TAwzN56KxeVtkFLV/ybBcL8bak9znbzGwwmSNU9A6Bx g+OoGE0giwM0Mt5U1p3Fo0pqCHjcVcHogWeCzLO6KWzzDPvcekT0rYRq/NfjX1VKdhdG U0UelMIQbyHQVdx4Eq5g8CpEz6ujtvGrkm56JEntCYEEEgY6W+Ct9+NtbCRe7auYlZ73 F8Wg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54909-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54909-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWYeKlORQlbJnYypneekwk+xVl144/+EzXvk9cteCdu/hg+IZMY+5ED9CbvOf6lg3R3alAv+jdkp9G1MNKy3cd+1fTQ0g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s16-20020aa7d790000000b0055fe3bf05f7si1077208edq.533.2024.02.06.04.24.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:24:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54909-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-54909-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54909-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 4D94F1F229EE for ; Tue, 6 Feb 2024 12:24:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45EFE14A097; Tue, 6 Feb 2024 12:09:35 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0B4513A249; Tue, 6 Feb 2024 12:09:23 +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=1707221363; cv=none; b=sgVaxBk79lvxaKYaYY+QDiqYoZsUn6l0MEkrKWxTYJFYF/1BTX0eLgBBdtth2d9DTxls4/zShrWnOzAzcgZoCOkwIb8Q+JYS16DLj3ljdoFRXnr+Ce5oMCOKIUjaYqIN++LrECm7J0V3SqiBy/BaVtg1lZssNpmJev7wiwrZ39U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221363; c=relaxed/simple; bh=A6km+89cOenaTUCTGM2bbrRlmoPT20kCCDzU5yT3Os4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=bRyJa1nWC4/f3gZBpwM9Z0updoZwxPefDP0FgmE6eYQaUGUKMJMsOqSXKLd0ZdXcNzwsDPvb03umtvyuR4OpTsvgRU18XjgxQlhXKVa5VWp6wQam+VK9Pt1V2GT2XzRjdExgfB+wxYqp3twwML6edACeN9SkCxVWqNFuxSB9KS8= 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 8B1FEC43399; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bIL-0CTn; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120951.901001747@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:39 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.6][PATCH 34/57] eventfs: Fix bitwise fields for "is_events" References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152278896237977 X-GMAIL-MSGID: 1790152278896237977 From: "Steven Rostedt (Google)" A flag was needed to denote which eventfs_inode was the "events" directory, so a bit was taken from the "nr_entries" field, as there's not that many entries, and 2^30 is plenty. But the bit number for nr_entries was not updated to reflect the bit taken from it, which would add an unnecessary integer to the structure. Link: https://lore.kernel.org/linux-trace-kernel/20240102151832.7ca87275@gandalf.local.home Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Fixes: 7e8358edf503e ("eventfs: Fix file and directory uid and gid ownership") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit fd56cd5f6d76e93356d9520cf9dabffe1e3d1aa0) --- fs/tracefs/internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 899e447778ac..42bdeb471a07 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -63,7 +63,7 @@ struct eventfs_inode { }; unsigned int is_freed:1; unsigned int is_events:1; - unsigned int nr_entries:31; + unsigned int nr_entries:30; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) From patchwork Tue Feb 6 12:09:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1505013dyb; Tue, 6 Feb 2024 04:33:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IHe3/2DuFN+08Z+WOb76Mk4ugWYYODt1dUVXtBspSdaiyaEYe/707rUoF+HhL2JD4HN0It3 X-Received: by 2002:a17:90b:1a88:b0:296:21dc:488c with SMTP id ng8-20020a17090b1a8800b0029621dc488cmr2131753pjb.41.1707222834552; Tue, 06 Feb 2024 04:33:54 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222834; cv=pass; d=google.com; s=arc-20160816; b=SbgKxl/AqYhqcH9fbb+7AQUGiqvBx+Fvg8yXZKo/W87DdEDuRehf6fN9szuN6WdLDj YuAnCWGylShSduGNd8E20sXhmwqT7NHaR16SSANULoc5goFe/Z+VqV9UEPRo23F7UeGj tD8NCuXexJ76ZBIT2PpwjHmVCPKwUy6N8vxwxW7YWobzzLW7Zfeby3hb84XlP9w5thRl RXZ118RR8MlGZdPAeS1waIGGvIfWkxpd+eE3pp+oPrJ6ooVVrqhsrlwBBWrkz9jpRieA ERqKylrx0e9lM388asFk7wZivkOhGiz+9xUq8daDuPFznOOVlqAFifUPdUeXkTm1orRm iMNw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=uXyNTi+hcecekKn8pb9kUZDns5PCP3zA+0J9cysBCZk=; fh=1W5b7BHlcOzQn+3B+IsaHelm7966lbw47qGVOpoHitk=; b=sQImWM5nONtwJhHqBjhvPeXlQ3SQ2wyH6nHG9ykVFH/+wc/eUdC6OcV/u4wYSq6V+x h+8Q7/aM2FGCn7p/RqbeC9ZJLEnCHqvR2qJHYt9PjRYZSoHWqEsIyZmqywKPUGNhRxjX PXGUakzGplSvW5S0ETwbvpf+BBOgNGHE9T5OgWlw987cgxWNYyme0bVffaDJ7MrYEtEh fgc6XV3yFCU+cgDc8PoUoIF8lCJzMfKrfUXyq/NuSJqvmHNUBEXP6xwf1GMKbm9qcRy6 AQ9FmOvUVTQ7aLFYXj6Ze3/SuSNMJTZAhjONQKu5qp35RYr2jYOi6KcCzXYRyYJF75Jc RUlA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCX7IW1sZ/G6SRzhmeGpgqmkJxbNTBFpcSf70yspR5lTeOgDBsCv7rNvefpr3rtnhBFZ1NxOJ3vnen+LPhHYhS3xQ85L1g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id gl1-20020a17090b120100b00295efecceaasi1072708pjb.91.2024.02.06.04.33.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:33:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54910-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 05537B2669F for ; Tue, 6 Feb 2024 12:24:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5ED6714C58A; Tue, 6 Feb 2024 12:09:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40AA513341E; Tue, 6 Feb 2024 12:09:23 +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=1707221364; cv=none; b=LjndCWVw8yK+dmWm2AZaNIx7H1NV8ynLq8Oftd1XyJuSE8UmOfFSUDSDF7MrsLdCZSAZCpXAe3h4aj4JbvyrkjjUiZoeQwO7BKc8SbGTGeXclKyHFmlhi+JqzNri8SAQ4MCJD5UzjH8lW5+k6kwbElM0FmZE2bd40sWg2qloAck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=k2T8+mfZwwC/SEoIfiKTy8FA9wi/cqLxT6cnp0Xwewc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dOw/DXcSVf2fUKVot4J3P4BeJByJKM7oMj05RHxnKkpoFuXITuT1BcgEezCyoK7YpJX9vKUQKxh19YjJDtGTE7ItRfRWkZdNb4fnnU1YwJHUSiplJ57dn2jc7YM7tKGvufXmi5kR4vfKA3A0kekm3ocOvalQe5AuXn1/UwCuaFo= 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 BFC2DC433A6; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bIq-0uEe; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120952.069546514@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:40 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.6][PATCH 35/57] eventfs: Remove "lookup" parameter from create_dir/file_dentry() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152890690715696 X-GMAIL-MSGID: 1790152890690715696 From: "Steven Rostedt (Google)" The "lookup" parameter is a way to differentiate the call to create_file/dir_dentry() from when it's just a lookup (no need to up the dentry refcount) and accessed via a readdir (need to up the refcount). But reality, it just makes the code more complex. Just up the refcount and let the caller decide to dput() the result or not. Link: https://lore.kernel.org/linux-trace-kernel/20240103102553.17a19cea@gandalf.local.home Link: https://lore.kernel.org/linux-trace-kernel/20240104015435.517502710@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Ajay Kaher Cc: Al Viro Cc: Christian Brauner Signed-off-by: Steven Rostedt (Google) (cherry picked from commit b0f7e2d739b4aac131ea1662d086a07775097b05) --- fs/tracefs/event_inode.c | 55 +++++++++++++++------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index f0677ea0ec24..c360300fb866 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -390,16 +390,14 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) * @mode: The mode of the file. * @data: The data to use to set the inode of the file with on open() * @fops: The fops of the file to be created. - * @lookup: If called by the lookup routine, in which case, dput() the created dentry. * * Create a dentry for a file of an eventfs_inode @ei and place it into the - * address located at @e_dentry. If the @e_dentry already has a dentry, then - * just do a dget() on it and return. Otherwise create the dentry and attach it. + * address located at @e_dentry. */ static struct dentry * create_file_dentry(struct eventfs_inode *ei, int idx, struct dentry *parent, const char *name, umode_t mode, void *data, - const struct file_operations *fops, bool lookup) + const struct file_operations *fops) { struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; @@ -414,9 +412,7 @@ create_file_dentry(struct eventfs_inode *ei, int idx, } /* If the e_dentry already has a dentry, use it */ if (*e_dentry) { - /* lookup does not need to up the ref count */ - if (!lookup) - dget(*e_dentry); + dget(*e_dentry); mutex_unlock(&eventfs_mutex); return *e_dentry; } @@ -441,13 +437,12 @@ create_file_dentry(struct eventfs_inode *ei, int idx, * way to being freed, don't return it. If e_dentry is NULL * it means it was already freed. */ - if (ei->is_freed) + if (ei->is_freed) { dentry = NULL; - else + } else { dentry = *e_dentry; - /* The lookup does not need to up the dentry refcount */ - if (dentry && !lookup) dget(dentry); + } mutex_unlock(&eventfs_mutex); return dentry; } @@ -465,9 +460,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, } mutex_unlock(&eventfs_mutex); - if (lookup) - dput(dentry); - return dentry; } @@ -500,13 +492,12 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) * @pei: The eventfs_inode parent of ei. * @ei: The eventfs_inode to create the directory for * @parent: The dentry of the parent of this directory - * @lookup: True if this is called by the lookup code * * This creates and attaches a directory dentry to the eventfs_inode @ei. */ static struct dentry * create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, - struct dentry *parent, bool lookup) + struct dentry *parent) { struct dentry *dentry = NULL; @@ -518,11 +509,9 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, return NULL; } if (ei->dentry) { - /* If the dentry already has a dentry, use it */ + /* If the eventfs_inode already has a dentry, use it */ dentry = ei->dentry; - /* lookup does not need to up the ref count */ - if (!lookup) - dget(dentry); + dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; } @@ -542,7 +531,7 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, * way to being freed. */ dentry = ei->dentry; - if (dentry && !lookup) + if (dentry) dget(dentry); mutex_unlock(&eventfs_mutex); return dentry; @@ -562,9 +551,6 @@ create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, } mutex_unlock(&eventfs_mutex); - if (lookup) - dput(dentry); - return dentry; } @@ -589,8 +575,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct eventfs_inode *ei; struct dentry *ei_dentry = NULL; struct dentry *ret = NULL; + struct dentry *d; const char *name = dentry->d_name.name; - bool created = false; umode_t mode; void *data; int idx; @@ -626,13 +612,10 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, ret = simple_lookup(dir, dentry, flags); if (IS_ERR(ret)) goto out; - create_dir_dentry(ei, ei_child, ei_dentry, true); - created = true; - break; - } - - if (created) + d = create_dir_dentry(ei, ei_child, ei_dentry); + dput(d); goto out; + } for (i = 0; i < ei->nr_entries; i++) { entry = &ei->entries[i]; @@ -650,8 +633,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, ret = simple_lookup(dir, dentry, flags); if (IS_ERR(ret)) goto out; - create_file_dentry(ei, i, ei_dentry, name, mode, cdata, - fops, true); + d = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + dput(d); break; } } @@ -768,9 +751,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) inode_lock(parent->d_inode); list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dir_dentry(ei, ei_child, parent, false); + d = create_dir_dentry(ei, ei_child, parent); if (d) { ret = add_dentries(&dentries, d, cnt); + dput(d); if (ret < 0) break; cnt++; @@ -790,9 +774,10 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) mutex_unlock(&eventfs_mutex); if (r <= 0) continue; - d = create_file_dentry(ei, i, parent, name, mode, cdata, fops, false); + d = create_file_dentry(ei, i, parent, name, mode, cdata, fops); if (d) { ret = add_dentries(&dentries, d, cnt); + dput(d); if (ret < 0) break; cnt++; From patchwork Tue Feb 6 12:09:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500036dyb; Tue, 6 Feb 2024 04:24:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IFVgQgwzSunXjw3sbm1hO+ikStvxQKtXTeZsNLkLWxiBBNc9JgfHePuwDHindqoYnPQ234u X-Received: by 2002:a05:6871:6ac:b0:219:30b9:fc22 with SMTP id l44-20020a05687106ac00b0021930b9fc22mr2897547oao.25.1707222299055; Tue, 06 Feb 2024 04:24:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222299; cv=pass; d=google.com; s=arc-20160816; b=q8BjRCCy/cI3aon7UoIUh7VkAlAx9vLF4FkamoDjpZUzYfyYJr3MUqd2Htk5LVK/DM KKU0BnQyn03tFzt5pc48aDOUMaeohU9dci6WgnPqap7F/JFDllBZ9INN+KaT4kcj1hKS Wb5qg2q0/fi/SwEv90bOFlfR7UYIqkjUzRt2ukj7Cme6HG3So+LK2stuD3nI59pzE5/J GxyM+oZvbPKZjQ2n3JU+fWKi1gOS32WYrfr5FB7zhBs64bpX6l1/3xVlT9GT9yGFYlGJ D9B6W32Vkfa35LG9ATpaZMYIqfMWeBZwMUKhsVLVZNz7ha8kMEQY8omhWV4VrmkymD0H uB9w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=K16ORpNo1U2aN5VYISFPkBUUl5NEx/u13xyJsewSfsI=; fh=GrkZwadlCyca7of4RrCDs6wfO0JgNpac+VqSCcZdpok=; b=E9IA9ucbV+3OjQ82olh6BRDDH3B6CTxr21aQzNUHKu79Ei1k2bhkmbZslPChl+WIsP cMCW5jNigjAq8GrHv9skSXlFv4LpSMwanwhsTMhSD/49XjWVvk9nZYZW9T78UxRi0eH0 cOnwc5hAvmrmIssDp5N7kMknguYVMaBbduv+wDJpboYVQqGH4BhBbB1qTSYJWsZQ0fKj nshGLUbwPvouFDYhn5t6kfXcqz99sEiGwJDPkcA0zYW9LpxBwFZqgz5ZZId16Aq4RLvg xUPOZQKO9ZvrD2198aTZERy1ljzG2dJZsmLmUzAG12dYCkVGoOgEf5hzABxil3DHoX/h fZlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54911-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54911-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCV2N4j+jGQ4CPYV69WPJQmuYdUZZGtnEwwb6pvGquUNarwt7hT1KJgwlPyvQburvdTRK9Yq9o/duitlWAWOnlJDUCd0zw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k16-20020a05622a03d000b0042c1eb48d17si2249885qtx.8.2024.02.06.04.24.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:24:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54911-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54911-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54911-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 C4ED91C242B8 for ; Tue, 6 Feb 2024 12:24:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C001814D450; Tue, 6 Feb 2024 12:09:36 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F71C13A870; Tue, 6 Feb 2024 12:09:24 +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=1707221364; cv=none; b=S24FG16YNry6PdgWytTV8+Hd4GBuGHwbNh6N7Y5SiPVpnXu9bjTVOih6Kjf9/Hg6r9I2Th5f0fsw4UlzUFwYzZE/zR9ih0AYoXsncF8c5i70J5va6Ps0RqhAdKhIxncdPFFAkvactN5kaDlhE0BvLqW79kMlt/RQsmHW/j5CvXg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=PY2TEAkLo+5aq9G2jZ7fftRc6t/u8z0IYGwANgHoKpU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=M7R93sKGDbIDPl91sNgo1DD/+syprDC0xRJBDQLcyO5izPbx6QYhUf96HyxZsmmpsIeWZXXAFqvunaImhOqArY381PuiAYGMnE2WobIMasx1++Lw5guKVpgzGKO3KVJReBgb3AiuaY8jQ0yp3Eus0U7yAun1tso5Y3IGGA7WJ/M= 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 E96DDC433C7; Tue, 6 Feb 2024 12:09:23 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bJL-1b0A; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120952.237926780@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:41 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Ajay Kaher , Al Viro , Christian Brauner Subject: [v6.6][PATCH 36/57] eventfs: Stop using dcache_readdir() for getdents() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152329045508737 X-GMAIL-MSGID: 1790152329045508737 From: "Steven Rostedt (Google)" The eventfs creates dynamically allocated dentries and inodes. Using the dcache_readdir() logic for its own directory lookups requires hiding the cursor of the dcache logic and playing games to allow the dcache_readdir() to still have access to the cursor while the eventfs saved what it created and what it needs to release. Instead, just have eventfs have its own iterate_shared callback function that will fill in the dent entries. This simplifies the code quite a bit. Link: https://lore.kernel.org/linux-trace-kernel/20240104015435.682218477@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Ajay Kaher Cc: Al Viro Cc: Christian Brauner Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 493ec81a8fb8e4ada6f223b8b73791a1280d4774) --- fs/tracefs/event_inode.c | 194 +++++++++++++-------------------------- 1 file changed, 64 insertions(+), 130 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index c360300fb866..41af56f44f0a 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -52,9 +52,7 @@ enum { static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); -static int dcache_dir_open_wrapper(struct inode *inode, struct file *file); -static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx); -static int eventfs_release(struct inode *inode, struct file *file); +static int eventfs_iterate(struct file *file, struct dir_context *ctx); static void update_attr(struct eventfs_attr *attr, struct iattr *iattr) { @@ -148,11 +146,9 @@ static const struct inode_operations eventfs_file_inode_operations = { }; static const struct file_operations eventfs_file_operations = { - .open = dcache_dir_open_wrapper, .read = generic_read_dir, - .iterate_shared = dcache_readdir_wrapper, + .iterate_shared = eventfs_iterate, .llseek = generic_file_llseek, - .release = eventfs_release, }; /* Return the evenfs_inode of the "events" directory */ @@ -643,128 +639,87 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, return ret; } -struct dentry_list { - void *cursor; - struct dentry **dentries; -}; - -/** - * eventfs_release - called to release eventfs file/dir - * @inode: inode to be released - * @file: file to be released (not used) - */ -static int eventfs_release(struct inode *inode, struct file *file) -{ - struct tracefs_inode *ti; - struct dentry_list *dlist = file->private_data; - void *cursor; - int i; - - ti = get_tracefs(inode); - if (!(ti->flags & TRACEFS_EVENT_INODE)) - return -EINVAL; - - if (WARN_ON_ONCE(!dlist)) - return -EINVAL; - - for (i = 0; dlist->dentries && dlist->dentries[i]; i++) { - dput(dlist->dentries[i]); - } - - cursor = dlist->cursor; - kfree(dlist->dentries); - kfree(dlist); - file->private_data = cursor; - return dcache_dir_close(inode, file); -} - -static int add_dentries(struct dentry ***dentries, struct dentry *d, int cnt) -{ - struct dentry **tmp; - - tmp = krealloc(*dentries, sizeof(d) * (cnt + 2), GFP_NOFS); - if (!tmp) - return -1; - tmp[cnt] = d; - tmp[cnt + 1] = NULL; - *dentries = tmp; - return 0; -} - -/** - * dcache_dir_open_wrapper - eventfs open wrapper - * @inode: not used - * @file: dir to be opened (to create it's children) - * - * Used to dynamic create file/dir with-in @file, all the - * file/dir will be created. If already created then references - * will be increased +/* + * Walk the children of a eventfs_inode to fill in getdents(). */ -static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) +static int eventfs_iterate(struct file *file, struct dir_context *ctx) { const struct file_operations *fops; + struct inode *f_inode = file_inode(file); const struct eventfs_entry *entry; struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct dentry_list *dlist; - struct dentry **dentries = NULL; - struct dentry *parent = file_dentry(file); - struct dentry *d; - struct inode *f_inode = file_inode(file); - const char *name = parent->d_name.name; + struct dentry *ei_dentry = NULL; + struct dentry *dentry; + const char *name; umode_t mode; - void *data; - int cnt = 0; int idx; - int ret; - int i; - int r; + int ret = -EINVAL; + int ino; + int i, r, c; + + if (!dir_emit_dots(file, ctx)) + return 0; ti = get_tracefs(f_inode); if (!(ti->flags & TRACEFS_EVENT_INODE)) return -EINVAL; - if (WARN_ON_ONCE(file->private_data)) - return -EINVAL; + c = ctx->pos - 2; idx = srcu_read_lock(&eventfs_srcu); mutex_lock(&eventfs_mutex); ei = READ_ONCE(ti->private); + if (ei && !ei->is_freed) + ei_dentry = READ_ONCE(ei->dentry); mutex_unlock(&eventfs_mutex); - if (!ei) { - srcu_read_unlock(&eventfs_srcu, idx); - return -EINVAL; - } - - - data = ei->data; + if (!ei || !ei_dentry) + goto out; - dlist = kmalloc(sizeof(*dlist), GFP_KERNEL); - if (!dlist) { - srcu_read_unlock(&eventfs_srcu, idx); - return -ENOMEM; - } + ret = 0; - inode_lock(parent->d_inode); + /* + * Need to create the dentries and inodes to have a consistent + * inode number. + */ list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { - d = create_dir_dentry(ei, ei_child, parent); - if (d) { - ret = add_dentries(&dentries, d, cnt); - dput(d); - if (ret < 0) - break; - cnt++; + + if (c > 0) { + c--; + continue; } + + if (ei_child->is_freed) + continue; + + name = ei_child->name; + + dentry = create_dir_dentry(ei, ei_child, ei_dentry); + if (!dentry) + goto out; + ino = dentry->d_inode->i_ino; + dput(dentry); + + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + goto out; + ctx->pos++; } for (i = 0; i < ei->nr_entries; i++) { - void *cdata = data; + void *cdata = ei->data; + + if (c > 0) { + c--; + continue; + } + entry = &ei->entries[i]; name = entry->name; + mutex_lock(&eventfs_mutex); /* If ei->is_freed, then the event itself may be too */ if (!ei->is_freed) @@ -774,42 +729,21 @@ static int dcache_dir_open_wrapper(struct inode *inode, struct file *file) mutex_unlock(&eventfs_mutex); if (r <= 0) continue; - d = create_file_dentry(ei, i, parent, name, mode, cdata, fops); - if (d) { - ret = add_dentries(&dentries, d, cnt); - dput(d); - if (ret < 0) - break; - cnt++; - } - } - inode_unlock(parent->d_inode); - srcu_read_unlock(&eventfs_srcu, idx); - ret = dcache_dir_open(inode, file); - /* - * dcache_dir_open() sets file->private_data to a dentry cursor. - * Need to save that but also save all the dentries that were - * opened by this function. - */ - dlist->cursor = file->private_data; - dlist->dentries = dentries; - file->private_data = dlist; - return ret; -} + dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + if (!dentry) + goto out; + ino = dentry->d_inode->i_ino; + dput(dentry); -/* - * This just sets the file->private_data back to the cursor and back. - */ -static int dcache_readdir_wrapper(struct file *file, struct dir_context *ctx) -{ - struct dentry_list *dlist = file->private_data; - int ret; + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + goto out; + ctx->pos++; + } + ret = 1; + out: + srcu_read_unlock(&eventfs_srcu, idx); - file->private_data = dlist->cursor; - ret = dcache_readdir(file, ctx); - dlist->cursor = file->private_data; - file->private_data = dlist; return ret; } From patchwork Tue Feb 6 12:09:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197418 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501372dyb; Tue, 6 Feb 2024 04:27:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMSJxAezNicQEwGnaqcIzCATcPGpNo7Jegxz9pXp+/IQI07nQFit/MPm/kZ+QP1aoKakYs X-Received: by 2002:a05:6358:291f:b0:178:c7b6:b563 with SMTP id y31-20020a056358291f00b00178c7b6b563mr3556432rwb.15.1707222445660; Tue, 06 Feb 2024 04:27:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222445; cv=pass; d=google.com; s=arc-20160816; b=emeH3OIM3kR1oWxUsuHB5RdcgBRndm7XrzfXOmtEqQATyFWFkLLSzwbbIybc8S2u4F sNOjpGF6XDWaM6hypcsZf5V7Swv0zZ3bySiXLi6vigGPcs6KJsFYE599ChJS6QhKcsOA Z7Yb+fkPqpphOYRdg4r+ah43qiajFLH1oaihBYzBe/jcptsdcBTSyL8vnQWstLpPepJp A0R44Ojf9/0PUXHxhCZhhtGXIpK4i8fn5luILy6/eHYxv3I39ou7t1keXG8jpCIKBXxL dQR2HKXOXwcGFIDYdxPVsw5PDF/TBG3/Q1yqYZy7C44l+efAUXsFn4F6g2L+NaPNEm29 x5Bg== 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=KT2wx2qwZAb7OlEngB05Tk3Ji1ao2xirvX/7B9ArfDI=; fh=/vQNuZVMwUlz+Ns5jeH48XcoXWi5aV5im4SK20bFgxo=; b=U80M+xUSItT9nUKfr7YGZz1LFblAucqbb+SP1QBPs7lpjWrVv3yDioTr765D7cwHmL asTu7ohSw9wdCcxug8krn+KXocMRH19A+Eh6uM5yXDJo2CXb49JUcwJaaaAva8INoCzA YZ9GYB2S1YBLwsxM3KmLv0gDxBEspdQeZIBp1FupSU4wmTraQJ0IHl+Tc/vS0TYc+ls8 pvKvvCqn3Fe+VlIOgXoCtoon4Uvsy3ZVpM4zAjeLSlNPWGXxI0EP4PiD/icOb3ix/GVG NBiQt9nGUrm7BiHZi0JSvr82EbSeWRZsRPNeyTQNjsQJlYfDbvjnljpPKEt5tIfEWILU D0rA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54914-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54914-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUIb6P4ClEiHuLDThkKJV6wQBiTTICDR0/4R4xP+5Tog1NF8TsbE+UB593CbDRL5SiXn6N2oTwHvFXoKRI26AiIxmwMMA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m6-20020a654386000000b005d8d56cd64esi1618691pgp.127.2024.02.06.04.27.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:27:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54914-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-54914-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54914-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 3421A283688 for ; Tue, 6 Feb 2024 12:27:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C62C1151445; Tue, 6 Feb 2024 12:09:40 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A073A13A881; Tue, 6 Feb 2024 12:09:24 +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=1707221364; cv=none; b=knt+KFY4Sx4RaDMLwxX0Ch4c/ADMsZ1gFQ1+Xnk+oWWDmYOnPiVKwtXr8t7ou77yCCGG5mRBxxa1M65PqUOL5Ug2xbZ4GWu4WFppScuzPWFg1ys2XsK7qi30li7eiE8r/wBDqojRa91nh0Am/9UhKc7j8UUqM9rlA0JhlM6nC1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=A2DmMK2DDvzIjimjnMaqbGWUoWCZE/sBDOj/DhncL2Q=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=TsIULfGWZzUaqbh9EwHlwyxv09AAYsK0j5UuIw5XnQRzjsDJssYKMubiwFUa1vqR/cpfwuNEEiHrFycdkv2V4LqmPLjty1S1ISt9tAT4kGQeoycvJoAsECuRvsd3pxZodpYCNqvKkUpvPlbvhZqcfRYK/HWpSFuNebQ05pW2sNw= 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 21A5BC43394; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bJq-2H2j; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120952.401268456@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:42 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Al Viro , Christian Brauner Subject: [v6.6][PATCH 37/57] tracefs/eventfs: Use root and instance inodes as default ownership References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152483444867673 X-GMAIL-MSGID: 1790152483444867673 From: "Steven Rostedt (Google)" Instead of walking the dentries on mount/remount to update the gid values of all the dentries if a gid option is specified on mount, just update the root inode. Add .getattr, .setattr, and .permissions on the tracefs inode operations to update the permissions of the files and directories. For all files and directories in the top level instance: /sys/kernel/tracing/* It will use the root inode as the default permissions. The inode that represents: /sys/kernel/tracing (or wherever it is mounted). When an instance is created: mkdir /sys/kernel/tracing/instance/foo The directory "foo" and all its files and directories underneath will use the default of what foo is when it was created. A remount of tracefs will not affect it. If a user were to modify the permissions of any file or directory in tracefs, it will also no longer be modified by a change in ownership of a remount. The events directory, if it is in the top level instance, will use the tracefs root inode as the default ownership for itself and all the files and directories below it. For the events directory in an instance ("foo"), it will keep the ownership of what it was when it was created, and that will be used as the default ownership for the files and directories beneath it. Link: https://lore.kernel.org/linux-trace-kernel/CAHk-=wjVdGkjDXBbvLn2wbZnqP4UsH46E3gqJ9m7UG6DpX2+WA@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240103215016.1e0c9811@gandalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 8186fff7ab649085e2c60d032d9a20a85af1d87c) --- fs/tracefs/event_inode.c | 79 +++++++++++++++- fs/tracefs/inode.c | 198 ++++++++++++++++++++++----------------- fs/tracefs/internal.h | 3 + 3 files changed, 190 insertions(+), 90 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 41af56f44f0a..72912b5f9a90 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -45,6 +45,7 @@ enum { EVENTFS_SAVE_MODE = BIT(16), EVENTFS_SAVE_UID = BIT(17), EVENTFS_SAVE_GID = BIT(18), + EVENTFS_TOPLEVEL = BIT(19), }; #define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1) @@ -115,10 +116,17 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, * The events directory dentry is never freed, unless its * part of an instance that is deleted. It's attr is the * default for its child files and directories. - * Do not update it. It's not used for its own mode or ownership + * Do not update it. It's not used for its own mode or ownership. */ - if (!ei->is_events) + if (ei->is_events) { + /* But it still needs to know if it was modified */ + if (iattr->ia_valid & ATTR_UID) + ei->attr.mode |= EVENTFS_SAVE_UID; + if (iattr->ia_valid & ATTR_GID) + ei->attr.mode |= EVENTFS_SAVE_GID; + } else { update_attr(&ei->attr, iattr); + } } else { name = dentry->d_name.name; @@ -136,9 +144,66 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, return ret; } +static void update_top_events_attr(struct eventfs_inode *ei, struct dentry *dentry) +{ + struct inode *inode; + + /* Only update if the "events" was on the top level */ + if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL)) + return; + + /* Get the tracefs root inode. */ + inode = d_inode(dentry->d_sb->s_root); + ei->attr.uid = inode->i_uid; + ei->attr.gid = inode->i_gid; +} + +static void set_top_events_ownership(struct inode *inode) +{ + struct tracefs_inode *ti = get_tracefs(inode); + struct eventfs_inode *ei = ti->private; + struct dentry *dentry; + + /* The top events directory doesn't get automatically updated */ + if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL)) + return; + + dentry = ei->dentry; + + update_top_events_attr(ei, dentry); + + if (!(ei->attr.mode & EVENTFS_SAVE_UID)) + inode->i_uid = ei->attr.uid; + + if (!(ei->attr.mode & EVENTFS_SAVE_GID)) + inode->i_gid = ei->attr.gid; +} + +static int eventfs_get_attr(struct mnt_idmap *idmap, + const struct path *path, struct kstat *stat, + u32 request_mask, unsigned int flags) +{ + struct dentry *dentry = path->dentry; + struct inode *inode = d_backing_inode(dentry); + + set_top_events_ownership(inode); + + generic_fillattr(idmap, request_mask, inode, stat); + return 0; +} + +static int eventfs_permission(struct mnt_idmap *idmap, + struct inode *inode, int mask) +{ + set_top_events_ownership(inode); + return generic_permission(idmap, inode, mask); +} + static const struct inode_operations eventfs_root_dir_inode_operations = { .lookup = eventfs_root_lookup, .setattr = eventfs_set_attr, + .getattr = eventfs_get_attr, + .permission = eventfs_permission, }; static const struct inode_operations eventfs_file_inode_operations = { @@ -174,6 +239,8 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) } while (!ei->is_events); mutex_unlock(&eventfs_mutex); + update_top_events_attr(ei, dentry); + return ei; } @@ -887,6 +954,14 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry uid = d_inode(dentry->d_parent)->i_uid; gid = d_inode(dentry->d_parent)->i_gid; + /* + * If the events directory is of the top instance, then parent + * is NULL. Set the attr.mode to reflect this and its permissions will + * default to the tracefs root dentry. + */ + if (!parent) + ei->attr.mode = EVENTFS_TOPLEVEL; + /* This is used as the default ownership of the files and directories */ ei->attr.uid = uid; ei->attr.gid = gid; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index c27b0cfff70c..fc0f133eefdb 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -91,6 +91,7 @@ static int tracefs_syscall_mkdir(struct mnt_idmap *idmap, struct inode *inode, struct dentry *dentry, umode_t mode) { + struct tracefs_inode *ti; char *name; int ret; @@ -98,6 +99,15 @@ static int tracefs_syscall_mkdir(struct mnt_idmap *idmap, if (!name) return -ENOMEM; + /* + * This is a new directory that does not take the default of + * the rootfs. It becomes the default permissions for all the + * files and directories underneath it. + */ + ti = get_tracefs(inode); + ti->flags |= TRACEFS_INSTANCE_INODE; + ti->private = inode; + /* * The mkdir call can call the generic functions that create * the files within the tracefs system. It is up to the individual @@ -141,10 +151,76 @@ static int tracefs_syscall_rmdir(struct inode *inode, struct dentry *dentry) return ret; } -static const struct inode_operations tracefs_dir_inode_operations = { +static void set_tracefs_inode_owner(struct inode *inode) +{ + struct tracefs_inode *ti = get_tracefs(inode); + struct inode *root_inode = ti->private; + + /* + * If this inode has never been referenced, then update + * the permissions to the superblock. + */ + if (!(ti->flags & TRACEFS_UID_PERM_SET)) + inode->i_uid = root_inode->i_uid; + + if (!(ti->flags & TRACEFS_GID_PERM_SET)) + inode->i_gid = root_inode->i_gid; +} + +static int tracefs_permission(struct mnt_idmap *idmap, + struct inode *inode, int mask) +{ + set_tracefs_inode_owner(inode); + return generic_permission(idmap, inode, mask); +} + +static int tracefs_getattr(struct mnt_idmap *idmap, + const struct path *path, struct kstat *stat, + u32 request_mask, unsigned int flags) +{ + struct inode *inode = d_backing_inode(path->dentry); + + set_tracefs_inode_owner(inode); + generic_fillattr(idmap, request_mask, inode, stat); + return 0; +} + +static int tracefs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, + struct iattr *attr) +{ + unsigned int ia_valid = attr->ia_valid; + struct inode *inode = d_inode(dentry); + struct tracefs_inode *ti = get_tracefs(inode); + + if (ia_valid & ATTR_UID) + ti->flags |= TRACEFS_UID_PERM_SET; + + if (ia_valid & ATTR_GID) + ti->flags |= TRACEFS_GID_PERM_SET; + + return simple_setattr(idmap, dentry, attr); +} + +static const struct inode_operations tracefs_instance_dir_inode_operations = { .lookup = simple_lookup, .mkdir = tracefs_syscall_mkdir, .rmdir = tracefs_syscall_rmdir, + .permission = tracefs_permission, + .getattr = tracefs_getattr, + .setattr = tracefs_setattr, +}; + +static const struct inode_operations tracefs_dir_inode_operations = { + .lookup = simple_lookup, + .permission = tracefs_permission, + .getattr = tracefs_getattr, + .setattr = tracefs_setattr, +}; + +static const struct inode_operations tracefs_file_inode_operations = { + .permission = tracefs_permission, + .getattr = tracefs_getattr, + .setattr = tracefs_setattr, }; struct inode *tracefs_get_inode(struct super_block *sb) @@ -183,87 +259,6 @@ struct tracefs_fs_info { struct tracefs_mount_opts mount_opts; }; -static void change_gid(struct dentry *dentry, kgid_t gid) -{ - if (!dentry->d_inode) - return; - dentry->d_inode->i_gid = gid; -} - -/* - * Taken from d_walk, but without he need for handling renames. - * Nothing can be renamed while walking the list, as tracefs - * does not support renames. This is only called when mounting - * or remounting the file system, to set all the files to - * the given gid. - */ -static void set_gid(struct dentry *parent, kgid_t gid) -{ - struct dentry *this_parent; - struct list_head *next; - - this_parent = parent; - spin_lock(&this_parent->d_lock); - - change_gid(this_parent, gid); -repeat: - next = this_parent->d_subdirs.next; -resume: - while (next != &this_parent->d_subdirs) { - struct tracefs_inode *ti; - struct list_head *tmp = next; - struct dentry *dentry = list_entry(tmp, struct dentry, d_child); - next = tmp->next; - - /* Note, getdents() can add a cursor dentry with no inode */ - if (!dentry->d_inode) - continue; - - spin_lock_nested(&dentry->d_lock, DENTRY_D_LOCK_NESTED); - - change_gid(dentry, gid); - - /* If this is the events directory, update that too */ - ti = get_tracefs(dentry->d_inode); - if (ti && (ti->flags & TRACEFS_EVENT_INODE)) - eventfs_update_gid(dentry, gid); - - if (!list_empty(&dentry->d_subdirs)) { - spin_unlock(&this_parent->d_lock); - spin_release(&dentry->d_lock.dep_map, _RET_IP_); - this_parent = dentry; - spin_acquire(&this_parent->d_lock.dep_map, 0, 1, _RET_IP_); - goto repeat; - } - spin_unlock(&dentry->d_lock); - } - /* - * All done at this level ... ascend and resume the search. - */ - rcu_read_lock(); -ascend: - if (this_parent != parent) { - struct dentry *child = this_parent; - this_parent = child->d_parent; - - spin_unlock(&child->d_lock); - spin_lock(&this_parent->d_lock); - - /* go into the first sibling still alive */ - do { - next = child->d_child.next; - if (next == &this_parent->d_subdirs) - goto ascend; - child = list_entry(next, struct dentry, d_child); - } while (unlikely(child->d_flags & DCACHE_DENTRY_KILLED)); - rcu_read_unlock(); - goto resume; - } - rcu_read_unlock(); - spin_unlock(&this_parent->d_lock); - return; -} - static int tracefs_parse_options(char *data, struct tracefs_mount_opts *opts) { substring_t args[MAX_OPT_ARGS]; @@ -336,10 +331,8 @@ static int tracefs_apply_options(struct super_block *sb, bool remount) if (!remount || opts->opts & BIT(Opt_uid)) inode->i_uid = opts->uid; - if (!remount || opts->opts & BIT(Opt_gid)) { - /* Set all the group ids to the mount option */ - set_gid(sb->s_root, opts->gid); - } + if (!remount || opts->opts & BIT(Opt_gid)) + inode->i_gid = opts->gid; return 0; } @@ -573,6 +566,26 @@ struct dentry *eventfs_end_creating(struct dentry *dentry) return dentry; } +/* Find the inode that this will use for default */ +static struct inode *instance_inode(struct dentry *parent, struct inode *inode) +{ + struct tracefs_inode *ti; + + /* If parent is NULL then use root inode */ + if (!parent) + return d_inode(inode->i_sb->s_root); + + /* Find the inode that is flagged as an instance or the root inode */ + while (!IS_ROOT(parent)) { + ti = get_tracefs(d_inode(parent)); + if (ti->flags & TRACEFS_INSTANCE_INODE) + break; + parent = parent->d_parent; + } + + return d_inode(parent); +} + /** * tracefs_create_file - create a file in the tracefs filesystem * @name: a pointer to a string containing the name of the file to create. @@ -603,6 +616,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, struct dentry *parent, void *data, const struct file_operations *fops) { + struct tracefs_inode *ti; struct dentry *dentry; struct inode *inode; @@ -621,7 +635,11 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, if (unlikely(!inode)) return tracefs_failed_creating(dentry); + ti = get_tracefs(inode); + ti->private = instance_inode(parent, inode); + inode->i_mode = mode; + inode->i_op = &tracefs_file_inode_operations; inode->i_fop = fops ? fops : &tracefs_file_operations; inode->i_private = data; inode->i_uid = d_inode(dentry->d_parent)->i_uid; @@ -634,6 +652,7 @@ struct dentry *tracefs_create_file(const char *name, umode_t mode, static struct dentry *__create_dir(const char *name, struct dentry *parent, const struct inode_operations *ops) { + struct tracefs_inode *ti; struct dentry *dentry = tracefs_start_creating(name, parent); struct inode *inode; @@ -651,6 +670,9 @@ static struct dentry *__create_dir(const char *name, struct dentry *parent, inode->i_uid = d_inode(dentry->d_parent)->i_uid; inode->i_gid = d_inode(dentry->d_parent)->i_gid; + ti = get_tracefs(inode); + ti->private = instance_inode(parent, inode); + /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); d_instantiate(dentry, inode); @@ -681,7 +703,7 @@ struct dentry *tracefs_create_dir(const char *name, struct dentry *parent) if (security_locked_down(LOCKDOWN_TRACEFS)) return NULL; - return __create_dir(name, parent, &simple_dir_inode_operations); + return __create_dir(name, parent, &tracefs_dir_inode_operations); } /** @@ -712,7 +734,7 @@ __init struct dentry *tracefs_create_instance_dir(const char *name, if (WARN_ON(tracefs_ops.mkdir || tracefs_ops.rmdir)) return NULL; - dentry = __create_dir(name, parent, &tracefs_dir_inode_operations); + dentry = __create_dir(name, parent, &tracefs_instance_dir_inode_operations); if (!dentry) return NULL; diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 42bdeb471a07..12b7d0150ae9 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -5,6 +5,9 @@ enum { TRACEFS_EVENT_INODE = BIT(1), TRACEFS_EVENT_TOP_INODE = BIT(2), + TRACEFS_GID_PERM_SET = BIT(3), + TRACEFS_UID_PERM_SET = BIT(4), + TRACEFS_INSTANCE_INODE = BIT(5), }; struct tracefs_inode { From patchwork Tue Feb 6 12:09:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197409 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500363dyb; Tue, 6 Feb 2024 04:25:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFBfsbAsGy0s9sRp92PN3y0cGs/R+YlHUEIVWK1ypIErvQ60zjQJtYC30n8tPWpekeg7ODR X-Received: by 2002:a17:902:f7d5:b0:1d9:c86c:39c2 with SMTP id h21-20020a170902f7d500b001d9c86c39c2mr1081863plw.14.1707222332161; Tue, 06 Feb 2024 04:25:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222332; cv=pass; d=google.com; s=arc-20160816; b=PKpep0J4Y1cZXwRgxHdvqz4fu3hqGAXkXLDvDyW7Wjq8/yyTRxpigM1nsLOc2qRGGH Ocn6MviHyHDHBmTwcP+geKvIChZzFyN8O7W7jn5RS443tB4UALKH2b1NQfs0j0eKs0Qf K8Sqe15jw7KYgxTolbKUfuX6qv9OnfQUCkx5sqPfrMyl2Q6wKgyJqtUCfkmABfzD0UOa jpHwZ1V2sXIuXAvCH6JBNlgk3J1/nlcgD5Ozg98+xm4PFECpg0rAZQ364i6+f8aSqxAK J+2mau7GI6Z0pLmBV41UuueyrGQvXHrN7sFB+ky5MNW27xEkRFyKx7p45UycI+Nua3Qb BVMg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=w/iPhJOudMj5zSlscWJCTndr2nhDIzagNWRmI9xY/Ss=; fh=SAGMp9qhPbl/eKj5fgp15NeoqCCufxnE+1kfLt3JFRE=; b=UmJoItM6coL+SDCMnGnfQYaMsbWmFR61qoXXcoSjQRgihih12eYbakcXr6O4gacxdt RYITRNhjoOzl2qGuX+URHQZ8s+Fv/SBCejMRr5Vou+al03Wjidz/tUkUqgdfkcZOr+Xs +a0sFdqa1fUnIkKHbI40MODrtHNeJZx91D8W4fieVnJYWSG3S0srXjtJLRrC5tXhN1g+ OL4PJY5iJUDCaEXF52rAuWHYR4ePvBqSG7G83p8IxKOoxRt3rM+CtwiOCYHfpCrBP5Gw mcIevNpkw7DhdqOnsErYgnEavdJ+e6WfpbUPRC0tphL5bwbmgaegFsgw2pU4432TiSlo QKxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54913-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54913-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVhSMGw0RL3VAGXorFUq2MrP5NYkhjv7tUda6HUWRIo1QXp/wBe4UYSebRLu4nAmmybb8hicHUfjFH6189D0YyPUaDckQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jg11-20020a17090326cb00b001d4af344a66si1538119plb.141.2024.02.06.04.25.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:25:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54913-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-54913-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54913-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 81ED628356A for ; Tue, 6 Feb 2024 12:25:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9832B14F9C2; Tue, 6 Feb 2024 12:09:37 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A07B913A882; Tue, 6 Feb 2024 12:09:24 +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=1707221364; cv=none; b=MMtmGvLXWZv7gN+Bbp8avCHvZc+CPwes2NoLve1ChHpuFC3ee4a8CzgiVjzj0UCui9WpIJmozntqNIPloy3vo+9RxOTXgvgKgOrJ8qaE7U1xSQV3+nkO2aXDnCGNDpCS6ITnpEhGBkmgPqNVHi8jsBU8C+eP35/Foa0AQ5Iykek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=3jDSxRh6ezDXpMpe9bCVmX2ZEPsqcyYEs+U1X03bFjY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=R+ycmMDvT8JqB4bgU0co7QBLiBH+/z7dfLgtU0REVkCuKEZ4mdehb5vS8/Q1WDVjRZWxl0/UecclwRXWnYigYjSPCejTqYqWXSFGTimWB10W9V9UY7VxmX9x+SaYAAUZZxfOJXnMl9cxJYS7VhS+OdsmKJvXgE1Ylb67JuT3lq4= 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 41BCDC43399; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bKL-2wSM; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120952.562520394@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:43 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.6][PATCH 38/57] eventfs: Have eventfs_iterate() stop immediately if ei->is_freed is set References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152364408441067 X-GMAIL-MSGID: 1790152364408441067 From: "Steven Rostedt (Google)" If ei->is_freed is set in eventfs_iterate(), it means that the directory that is being iterated on is in the process of being freed. Just exit the loop immediately when that is ever detected, and separate out the return of the entry->callback() from ei->is_freed. Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.016261289@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit e109deadb73318cf4a3bd61287d969f705df278f) --- fs/tracefs/event_inode.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 72912b5f9a90..0aca6910efb3 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -788,11 +788,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = entry->name; mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r = entry->callback(name, &mode, &cdata, &fops); - else - r = -1; + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out; + } + r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); if (r <= 0) continue; From patchwork Tue Feb 6 12:09:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500627dyb; Tue, 6 Feb 2024 04:26:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEkiFlM5QrYFRm2vmGZgmk0VLL89onVGfSFMXvXCTNUbXrKunbiBIBsAGl8Sb0GoZtwJQYA X-Received: by 2002:a81:af4a:0:b0:5ec:e2cd:a91 with SMTP id x10-20020a81af4a000000b005ece2cd0a91mr1333759ywj.30.1707222360323; Tue, 06 Feb 2024 04:26:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222360; cv=pass; d=google.com; s=arc-20160816; b=iocWiOdVI8NnCzfWtkkZY8eK6GoRMgNJoLd6SvK+r01Yjv75A66J+7IWyEgT6nWXZH Zn0caV/VUSEwe+lFyKllgI1EHgzrI684GFj6MCVz6v5VgkxYSdEmqvoK/TUmtpYUOutg RtF205LBOTndjco3vs0QmQVkvBP4hheTsML8Wlx86wVAwD16V6EcEhbZlE7bAdDE91HV U+XUkVbn91ClO5OXbZZ9OtAstxqQ7Ratz4bteovxZmhRkgOWGjEp+d4f7ca0Sv/zS5hy JRneoUyrpVD0fl1ybkLILqvmHtOS8pabqej+lR0pHgeP1QWSWYlCma4f4KNgZ03DCGi1 hXvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=97GT1y81ODm767N+vaTtb7CLJ/49FtWR2HrL/alCa6U=; fh=HgAeEeUBhcg8sexSbK4Q3WVb1bVcqohFGEVFTMv7TjA=; b=YCDlUB2/wNtnoIVcdflkKO56+u6Lthw40v0Jc7m5mNO3ZNf1UU+4w0Ch7V0UfN5GGr 2WFQUFmijKYpylMhRCFgfA3vytlGFLrqi7jqYe0+bvpait6vILtxXoGUhdF9QaKsO6x/ FHUb/oFl06M0eyiVXNyR2k1Y/G7yR0jPsp2v88nWyU3J06SZiZdamWlcR166LR5adgKH uPSz/sSgDRKOr6IdUF/aAki588/ERECjswJMigbEDFtf+is8uFWudKfGPd/rAJEf8mG9 CPMdYiaFkuUwmSZ5i6lN/ESdXHAhf2rnCYgLEoWttx2NbJ3Ge0Tcyh3lPKjg/hbf1EYh xo/A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54912-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54912-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWrfIx0kEUeyx8s96/PEwgGh8pBGtUos+l8gPbj/kCePQ4FJBuT/dKpYJJMg5OjPfaKMAUt5P1pZITPLwsMSMq87vmfzQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 5-20020a0562140dc500b0068cb06736a5si1967019qvt.321.2024.02.06.04.26.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54912-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-54912-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54912-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 012961C23F62 for ; Tue, 6 Feb 2024 12:26:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 70C7113343E; Tue, 6 Feb 2024 12:09:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8242C13A877; Tue, 6 Feb 2024 12:09:24 +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=1707221364; cv=none; b=LAdw1hqIwGyJDX+c6HTxCDvDELjgrU9/EjaL2/1opV5+c6QgnWsOPmATguDkCJcBcAq4YUPZ9fRR/X5QeAdlGzwEInROeLmyStJDD5H90fksv01XpH3nt9nCQZ6riX8i95UpfS062Z3KjE2p8kfy5r+LaDM835ob6rhDDOS/tgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=1TOxKL8RRnNxulvXK50DzgvXwAnmOluv224Nju/yrew=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=HRye5L24eDI2f4/mKiG5MLg+imo5jOobO9ADWZN6gLyXrAdiO52xnIJopm5RQn0rXdr+26eZo2qsS+ZQWgWtfeQSjVAOYMm9mql/DJJz7N/fZsvBT/X1HeCYml+Cfm9tdfl5wwgsM93IF1Zjqxge8AHI5dIbKpciHDiSFwBU7io= 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 6AAB7C433A6; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGu-00000006bKp-3eGw; Tue, 06 Feb 2024 07:09:52 -0500 Message-ID: <20240206120952.722064231@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:44 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.6][PATCH 39/57] eventfs: Do ctx->pos update for all iterations in eventfs_iterate() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152393511587078 X-GMAIL-MSGID: 1790152393511587078 From: "Steven Rostedt (Google)" The ctx->pos was only updated when it added an entry, but the "skip to current pos" check (c--) happened for every loop regardless of if the entry was added or not. This inconsistency caused readdir to be incorrect. It was due to: for (i = 0; i < ei->nr_entries; i++) { if (c > 0) { c--; continue; } mutex_lock(&eventfs_mutex); /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); goto out; } r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); [..] ctx->pos++; } But this can cause the iterator to return a file that was already read. That's because of the way the callback() works. Some events may not have all files, and the callback can return 0 to tell eventfs to skip the file for this directory. for instance, we have: # ls /sys/kernel/tracing/events/ftrace/function format hist hist_debug id inject and # ls /sys/kernel/tracing/events/sched/sched_switch/ enable filter format hist hist_debug id inject trigger Where the function directory is missing "enable", "filter" and "trigger". That's because the callback() for events has: static int event_callback(const char *name, umode_t *mode, void **data, const struct file_operations **fops) { struct trace_event_file *file = *data; struct trace_event_call *call = file->event_call; [..] /* * Only event directories that can be enabled should have * triggers or filters, with the exception of the "print" * event that can have a "trigger" file. */ if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) { if (call->class->reg && strcmp(name, "enable") == 0) { *mode = TRACE_MODE_WRITE; *fops = &ftrace_enable_fops; return 1; } if (strcmp(name, "filter") == 0) { *mode = TRACE_MODE_WRITE; *fops = &ftrace_event_filter_fops; return 1; } } if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) || strcmp(trace_event_name(call), "print") == 0) { if (strcmp(name, "trigger") == 0) { *mode = TRACE_MODE_WRITE; *fops = &event_trigger_fops; return 1; } } [..] return 0; } Where the function event has the TRACE_EVENT_FL_IGNORE_ENABLE set. This means that the entries array elements for "enable", "filter" and "trigger" when called on the function event will have the callback return 0 and not 1, to tell eventfs to skip these files for it. Because the "skip to current ctx->pos" check happened for all entries, but the ctx->pos++ only happened to entries that exist, it would confuse the reading of a directory. Which would cause: # ls /sys/kernel/tracing/events/ftrace/function/ format hist hist hist_debug hist_debug id inject inject The missing "enable", "filter" and "trigger" caused ls to show "hist", "hist_debug" and "inject" twice. Update the ctx->pos for every iteration to keep its update and the "skip" update consistent. This also means that on error, the ctx->pos needs to be decremented if it was incremented without adding something. Link: https://lore.kernel.org/all/20240104150500.38b15a62@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.172295263@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Fixes: 493ec81a8fb8e ("eventfs: Stop using dcache_readdir() for getdents()") Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 1e4624eb5a0ecaae0d2c4e3019bece119725bb98) --- fs/tracefs/event_inode.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 0aca6910efb3..c73fb1f7ddbc 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -760,6 +760,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) continue; } + ctx->pos++; + if (ei_child->is_freed) continue; @@ -767,13 +769,12 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) dentry = create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) - goto out; + goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) - goto out; - ctx->pos++; + goto out_dec; } for (i = 0; i < ei->nr_entries; i++) { @@ -784,6 +785,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) continue; } + ctx->pos++; + entry = &ei->entries[i]; name = entry->name; @@ -791,7 +794,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); - goto out; + goto out_dec; } r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); @@ -800,19 +803,23 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) - goto out; + goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) - goto out; - ctx->pos++; + goto out_dec; } ret = 1; out: srcu_read_unlock(&eventfs_srcu, idx); return ret; + + out_dec: + /* Incremented ctx->pos without adding something, reset it */ + ctx->pos--; + goto out; } /** From patchwork Tue Feb 6 12:09:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500687dyb; Tue, 6 Feb 2024 04:26:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2hhZ+db1ZXQoS660d6J4unNGSRHIct7Ssyq2IegRd9P4MwrN2UBgmsN1ZO89eF8stsYpj X-Received: by 2002:a17:906:f9c5:b0:a38:350:bbdd with SMTP id lj5-20020a170906f9c500b00a380350bbddmr1427632ejb.48.1707222367197; Tue, 06 Feb 2024 04:26:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222367; cv=pass; d=google.com; s=arc-20160816; b=hXYoaumiDN4AgnqPdWNOhT/ZY5BzZJbjMxOsTkaDrBnE8svdz0+XoKolumTSEX0rdp csWOBSrxE9gUZN9ELXzbf+Cq5UC75bO2ICTWXdCfK5vKRvz62qfhQaACVW2Y2POsi6iO 70POdSOsO6HdAZFXgNl/9RTPQa6YuQhjg/08jmu4H850Kfqh6GN+lFCOOQIWcMvNXkt1 Z+Cz3qfocz4rZs4kVCH7H8IEn7CWQjVlyLrwMwtzdr0T4hoL0sz+40du/+l8ZNhu1N9b DEMbJLdtGMBz3KK5T+KYhJd+btT/dI9CeBIlnOOFLAiUaROuN6vM1EvfoJdSVsQREogY 8yhA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=SXG6kX6vpOBEiMVmlEzwWPSMsib1/4LFk5czFSKSK4M=; fh=6h+FSn/J9FL7nQutFq9nHq8Aefcj+c+gywjP/7GjtQM=; b=kuBtJAmtd2SNK9YZsgUjC4d+J/F+GVdPax2Mne+7wcjjnvFEpdY4CwmlzbTIzC7qXm UjddQv9dVnbzXRXQ6zU65bBtC0JjI/rnYxh8ZMHVGKMS1Wn3ceAboqnMW+F0PYmI3AlC N7EtZv68gFv8s4TYMNTCxBEmuvnPqbvWLEu8/2VJbCdpQdVtn+da3KaWH1VMvDQE2aE0 3MqjlUqvpNfc7FasU8JlBw4G3fL9fj+aqXiKsCiJ5+RdHG49IrjQ6yRUdeKCqB+Rahi/ o9CsNg4to9NfMcHwUHPVm3NBQq5XsrdlKdVu18Zg8bbBRyesiEX00BtHzW4Q4k7tVScZ pXMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54915-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXM7ZbVSEjiu8WY+hwta7VlpRBg4Pb7SSnFBrOZynvIr04T7uoRdk6tddfAcPGGRtH1Hw7450Nv5JBLiJllJrJZgm2cxw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g13-20020a1709067c4d00b00a367f22a26csi1077008ejp.355.2024.02.06.04.26.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54915-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-54915-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54915-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 CB27B1F23B57 for ; Tue, 6 Feb 2024 12:26:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCCC214F9F6; Tue, 6 Feb 2024 12:09:38 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADFD413A889; Tue, 6 Feb 2024 12:09:24 +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=1707221364; cv=none; b=qWiyBSrWNMSmo/Dr8A3rvXJr+w0k+pq8ElAjDjP3oDbb9bnlcUcDB795IcL0Ni5HcYI0Z3/E89UosXi466tanPKIRL/2nU6y+G//uKbNF7v3RKgMkcXUAOIvAioHKRqQbFkMRaV7dUFHvNzteTKlXjAYaxjmEFiLMr9d9FctlRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221364; c=relaxed/simple; bh=msUlAhKaN43vF7JsX1xwBfcdPGlDn+EyYYaBimHJa/8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Z9cFyddLBBpVdIG8cB6CntUiAUEehdPiJjPf4fikVF6aYJR4TUY7MQqtz+of0VpX4uIlz279I/2oP5VpH888jtL+Y93SRjK6SegJYRFYNK1Ke8/xXH7nDq+9avBZPEm/i+KIUbJUabpE5TuUOe85NjFoF4gAfHBksw0ZFoxUgrw= 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 916EDC4167D; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bLL-07BP; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120952.892527913@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:45 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.6][PATCH 40/57] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152400905688593 X-GMAIL-MSGID: 1790152400905688593 From: "Steven Rostedt (Google)" In order to apply a shortcut to skip over the current ctx->pos immediately, by using the ei->entries array, the reading of that array should be first. Moving the array reading before the linked list reading will make the shortcut change diff nicer to read. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.333115095@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Linus Torvalds Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 704f960dbee2f1634f4b4e16f208cb16eaf41c1e) --- fs/tracefs/event_inode.c | 46 ++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index c73fb1f7ddbc..a1934e0eea3b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -752,8 +752,8 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) * Need to create the dentries and inodes to have a consistent * inode number. */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { + for (i = 0; i < ei->nr_entries; i++) { + void *cdata = ei->data; if (c > 0) { c--; @@ -762,23 +762,32 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - if (ei_child->is_freed) - continue; + entry = &ei->entries[i]; + name = entry->name; - name = ei_child->name; + mutex_lock(&eventfs_mutex); + /* If ei->is_freed then just bail here, nothing more to do */ + if (ei->is_freed) { + mutex_unlock(&eventfs_mutex); + goto out_dec; + } + r = entry->callback(name, &mode, &cdata, &fops); + mutex_unlock(&eventfs_mutex); + if (r <= 0) + continue; - dentry = create_dir_dentry(ei, ei_child, ei_dentry); + dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out_dec; } - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; + list_for_each_entry_srcu(ei_child, &ei->children, list, + srcu_read_lock_held(&eventfs_srcu)) { if (c > 0) { c--; @@ -787,27 +796,18 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) ctx->pos++; - entry = &ei->entries[i]; - name = entry->name; - - mutex_lock(&eventfs_mutex); - /* If ei->is_freed then just bail here, nothing more to do */ - if (ei->is_freed) { - mutex_unlock(&eventfs_mutex); - goto out_dec; - } - r = entry->callback(name, &mode, &cdata, &fops); - mutex_unlock(&eventfs_mutex); - if (r <= 0) + if (ei_child->is_freed) continue; - dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); + name = ei_child->name; + + dentry = create_dir_dentry(ei, ei_child, ei_dentry); if (!dentry) goto out_dec; ino = dentry->d_inode->i_ino; dput(dentry); - if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) + if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; } ret = 1; From patchwork Tue Feb 6 12:09:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500986dyb; Tue, 6 Feb 2024 04:26:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrR3nQL+SFMQmJuiH0g019yVEpXRd0xkChrODGYD7GlsgnrJV1TYlGX4sDuWA1jRxWKUOi X-Received: by 2002:a05:651c:b0a:b0:2d0:6874:b615 with SMTP id b10-20020a05651c0b0a00b002d06874b615mr1892805ljr.42.1707222402362; Tue, 06 Feb 2024 04:26:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222402; cv=pass; d=google.com; s=arc-20160816; b=GNbcYsHd5Tq5Sr242HVvzLebtDwpqjZys+awmyqWmcHtQa3rWcrVH50WypOjXvaM8d 2S+/FpHSnDxmBBm7FtwE8ZZxANGjuL7bzCIQhdyxljGbUt+sbStEr72Bjk4lDiyHvlnB lh1mPE7fmbWQDJK4VT5bZYK9wA0W7lLFaU0YUqOOQPRb07FafDavtLPG+LKxFQbf95F+ n2ZyBjRusgaBlcDdtfQNGNlrC6byoRWxdq+xeskVWbWLAspvWFLQW1giZMRTlZdugAg4 xat34lXAMxRLaN8bxWhbUib5VpnDoQTXRkZmyEUZZCW0g5++5xJj301NIaLjZR7VGaQe yYCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=mZzhfG64JOfp2veODtxBU/uq10vZEr4hoZ4aj1eAhnY=; fh=xLbvj7i8FMTbJA4u/tA5/Pno7VKD0wiz/JSzsQXSQiM=; b=bndX98Yci3wBHO5+2CBIhPqeh/Km6k4ChHT6+mZbiRhwJF7QLfyREC3is5I6FxtLDp JsM6XYMGW4FeKrBXDmWj+wJF5oKkNdIw3/WehJUDNpzl9CRSFtqCtnYhZaCcKTnTEgGL SdhrWs9uyfQkUF3h1Ye+MnFBC/8YYabZPMIyM9lbm2Y0RzEzTy+nWk4B7mT+bO8a6Zgh GlxSGzcKyl9+8ZRXcdEb/8mAu0JLcdX+PeE5ximnoGelhWqgHaTIHmcYJk3ILz5jGZTx KVJftWFbfjj6Hyro76W9bxlOVT4X3mtD9dZFHb+7oSnkj38HXAv90Fl9RSvl3nfhVlwY LCgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54916-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54916-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWvAPJd6XRFqykM11O0kfI6u6R+ABWlxtcxmsnTKSfIupUuRuEG2ZZXsTriPBTFhQc8oOa9WJ9pwmU5eSbhcQT9tD377Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j12-20020a05640211cc00b00560b530d441si393812edw.162.2024.02.06.04.26.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54916-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-54916-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54916-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 DCE981F23932 for ; Tue, 6 Feb 2024 12:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB15B14FFB1; Tue, 6 Feb 2024 12:09:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EAF6713AA27; Tue, 6 Feb 2024 12:09:24 +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=1707221365; cv=none; b=QZZKC95rDKtGOE1lwJM7T9lyPshhPb+3hd/dt7WtCzQEo87AmLjL4Nft3kkZ2dP2G+dARdLNZ/tCdiUB7l2uOi0xc3uyNflkPqar8W9tilLloj3KLN58RYbhHqqSPm0Bd7nvTPimJFsTSHg9K5RyNrIb3c/VWA/BWmMz2zbfYPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=KBGhBIbjsMRKtn4hdiJH0PuIBiRoV1R54hmlDTiI6ZI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hNqqS3brInlMhz58Js5IMEZcTU/ASKdW/2OwdP1C6kijrAg7otTpV2s7vw8373Sg7dhX1zdL8erdgFLvv5s1xlVvPEIT7miFZ3bsL+IioLvfJNyc0hI4ZatqI0fVZPho/RxzCXHQHYVawmBa2Md6xV9CMJYW3xvTMjPTckjx3uY= 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 BE464C4167E; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bLq-0naA; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.046426517@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:46 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.6][PATCH 41/57] eventfs: Shortcut eventfs_iterate() by skipping entries already read References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152437523771353 X-GMAIL-MSGID: 1790152437523771353 From: "Steven Rostedt (Google)" As the ei->entries array is fixed for the duration of the eventfs_inode, it can be used to skip over already read entries in eventfs_iterate(). That is, if ctx->pos is greater than zero, there's no reason in doing the loop across the ei->entries array for the entries less than ctx->pos. Instead, start the lookup of the entries at the current ctx->pos. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.494956957@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 1de94b52d5e8d8b32f0252f14fad1f1edc2e71f1) --- fs/tracefs/event_inode.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index a1934e0eea3b..fdff53d5a1f8 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -746,21 +746,15 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) if (!ei || !ei_dentry) goto out; - ret = 0; - /* * Need to create the dentries and inodes to have a consistent * inode number. */ - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; - - if (c > 0) { - c--; - continue; - } + ret = 0; - ctx->pos++; + /* Start at 'c' to jump over already read entries */ + for (i = c; i < ei->nr_entries; i++, ctx->pos++) { + void *cdata = ei->data; entry = &ei->entries[i]; name = entry->name; @@ -769,7 +763,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); - goto out_dec; + goto out; } r = entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); @@ -778,14 +772,17 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) - goto out_dec; + goto out; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) - goto out_dec; + goto out; } + /* Subtract the skipped entries above */ + c -= min((unsigned int)c, (unsigned int)ei->nr_entries); + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { From patchwork Tue Feb 6 12:09:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197415 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501063dyb; Tue, 6 Feb 2024 04:26:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IErxWL59iDFJ36UmZC41mGquENr1dJluDgvviOgX/H8gvYrYuxiHz3WSvfTsOqAFl+ahs6G X-Received: by 2002:a05:6808:648b:b0:3bf:e5bb:a924 with SMTP id fh11-20020a056808648b00b003bfe5bba924mr1174298oib.22.1707222409853; Tue, 06 Feb 2024 04:26:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222409; cv=pass; d=google.com; s=arc-20160816; b=xx5rRLS0HhfOt7cew3U9GDrYwbNOw9PvkNsz89Q8X1azsTpOS0CX/Hun/WTelGl4qF ptfXs9VkMDzNBYKiUFUcfl+zApxIFNLX74MtA3H6UFCq2aaWOJrFRYTII4T54hTzTJcV b4T0+EzrYF3ro7mJwICdhOaxeheisM8LytMQBUSIPb4ZMB+QUYhmjf8SS93tx2+9i2bS FYsLtg5ccy5x7/d0D1ComBL1ezyREvJd1xPlpttu20TkmJdFmyuMYHCgfyQY3lHsDpXS CPeg1Al8daipvQ5HbnaDcYJBze1sWLHsZHPPrto4kI/l+fOok6vel2R6NypYg5ZhdoO2 ZJZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=td1cyB3gu4vQ5m1uxuZTAdd1+/C4/C4JbPlA6D7R5q4=; fh=NFwJnllDgkmKUCAFM0ZNhValf5u7fX7uufCXeGIC+9U=; b=YdHHhMCPxqn+i/C3tS5Xml98TqFWOIk76S+KC2jZqDdcEbELO1j58ASp+FkGm7QHFH vW9b8GVlMkFV0WGAVU3Vp0NCTocc35OcST5KKcm/a1V30ZbIKFzv+AwQNCHx5HU9xazJ Jh9vySZFWw0EEcHrHTtKCBdysgaPQYHiTBXppRpGR0rS0vwyEJcU7WZDBCp7iaCR+YAy M9wokE/DKgExt7kjlY8xEJun6GDcAbyh5XwL1r3WFNJ7Dxv9lV2WUS/AUvE1eg7Nma5c WMq3zPkhVo7pzy2+z27ethsLtQJjZX5wBnLZEttmBb3ih3B5ahbiajhwY0QZJGh6AjRj 6WGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54919-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54919-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXYV6E2MmaqzkfceQB0F/SIkl8fC7Xue08XBwfwDzXVJtQu7NcoJCuQe3O2wMUb+Vx/WCnZqlbGS/Np9YE56BOcj6qIgw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p12-20020a05622a00cc00b0042bf838e0dbsi2113088qtw.416.2024.02.06.04.26.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54919-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-54919-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54919-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 8762A1C243C3 for ; Tue, 6 Feb 2024 12:26:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14318150980; Tue, 6 Feb 2024 12:09:40 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 599A113AA4F; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=BQo46NRutz+Zvau02aIT/QHezI/YRDfupUJ49e/q+l7YrawngmmXPW7RzpMx9av+u0M37Ft0vedD8Dm4S7S/onWJLzWN5IZ23sgCiDT4YV4JKazBLg1jKh7BKDmWj1OwpD3NhlURNfE+d0aXhwHsoIMYW6fcSxK/OghalqB6XjE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=JSygnlx6+56lX3XXzthIgsNjw4j5XL26vPR3L/z2tEs=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=q1daJ/dPzF6nKoLch3zSXSN0W3caS48pd9RLyWVsM6/1jl8XBjr5RTAKdvkjZ9DkYNLSXQiIDzA9SB7JVlpuJFHKld2ai9zcdylx7VYfsgj9DBJcJ+kHty6PiKsOO79BY/SfCTEZu89WzrzRDg9ZeVZ/KYbWPpNmg+avTjKAK2g= 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 E5AC5C43609; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bML-1VEK; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.213007763@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:47 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 42/57] eventfs: Have the inodes all for files and directories all be the same References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152445991954131 X-GMAIL-MSGID: 1790152445991954131 From: "Steven Rostedt (Google)" The dentries and inodes are created in the readdir for the sole purpose of getting a consistent inode number. Linus stated that is unnecessary, and that all inodes can have the same inode number. For a virtual file system they are pretty meaningless. Instead use a single unique inode number for all files and one for all directories. Link: https://lore.kernel.org/all/20240116133753.2808d45e@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240116211353.412180363@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 53c41052ba3121761e6f62a813961164532a214f) --- fs/tracefs/event_inode.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index fdff53d5a1f8..5edf0b96758b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -32,6 +32,10 @@ */ static DEFINE_MUTEX(eventfs_mutex); +/* Choose something "unique" ;-) */ +#define EVENTFS_FILE_INODE_INO 0x12c4e37 +#define EVENTFS_DIR_INODE_INO 0x134b2f5 + /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from * its parent's list and will have is_freed set (under eventfs_mutex). @@ -352,6 +356,9 @@ static struct dentry *create_file(const char *name, umode_t mode, inode->i_fop = fop; inode->i_private = data; + /* All files will have the same inode number */ + inode->i_ino = EVENTFS_FILE_INODE_INO; + ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; d_instantiate(dentry, inode); @@ -388,6 +395,9 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; + /* All directories will have the same inode number */ + inode->i_ino = EVENTFS_DIR_INODE_INO; + ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; From patchwork Tue Feb 6 12:09:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197417 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501331dyb; Tue, 6 Feb 2024 04:27:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4Z+iTcPc/iLnYCWIio31I+BNG12on2d+DuM/OYps8UYUNHea5GJykRfHRYtvl4KJdrJ82 X-Received: by 2002:a17:902:e84c:b0:1d9:1cb5:558f with SMTP id t12-20020a170902e84c00b001d91cb5558fmr1712379plg.2.1707222440890; Tue, 06 Feb 2024 04:27:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222440; cv=pass; d=google.com; s=arc-20160816; b=wxb1sDz6ljz0Lc4lFR58rMFbW9uYBhU7LbzWRPOAAWdwj9a1ut0+ScRw88zgp4sHqS zpcVAWp2mfGKl7hi93fFNvZSf/5ZxlcHtb3J7eMF+33/fMJpED0cGO2X/MWxHikO247E 9Ry1RuJ/KCjg6rOIjlRjGNRBeMccPduuJASVq0x3GEGmpO1SE6KJK5wJJfG8LGnA9xra 8Bz51juwrcgLYgTkG73Lm5zV4zqmCTNQiDKp9pDJZ9geDxijEY0zyv+EsI3iu0UaeHjn vQD1rzNU0TDdX7ULzRAokbaaDB7FgRAComD+al8gtYNkOlKSEG5r3NAey5FIYTGIc9uA Swuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=4kJElqzHxcp8SMj6H2Aq/UhawQMCk4MTJETashvgb4Y=; fh=okACu4QYcv9rrxtFaE3CInl3vrunRw4yoMxJYlGYbjo=; b=mvfOfFchnbMtoxY4WpGoLvYNSE4pOWr4hG2T+Z28JtH8qDoJzAu4dwRPbSn9apM0ey yRyTTtWl1CxrQoZ+K9GJ8T6OJhxqZfbHfw7gZDbL0Ld903kbWJpMHrdlvJo2sZCk/JzE FZcmdwaQoreERQuMyy3+a/bNN1y7bc0/wCkFG56cVb5kWsh0+mj9qk+KZrt5K5Nd1wgy DnXQf2zQvB+HiG+tJgFAFwR3A/PRPUQtGgGf3eXfseQ/enqG91DKki/+b4ZS8JYCmcee 87HC1yfVoe+FpYL/ZCoZkGxCfmWtDk5we0STkgyCRGLEJ2WsLiV6G6/FNPB2vkdfPmxK vEcg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54917-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54917-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUtFyYLi34bb/JW1H2lRly0PP4zDmJwsIDwhzbOorIsd5iS+JxZWlMVQ4Rd3oJvwwvnEQvoUnE8bgpdFuv+4Kd5BS0qGw== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z16-20020a170903019000b001d94c11e7ebsi1612096plg.372.2024.02.06.04.27.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:27:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54917-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-54917-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54917-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 9DD30281C8C for ; Tue, 6 Feb 2024 12:27:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D9656151448; Tue, 6 Feb 2024 12:09:40 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CE0113AA3F; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=iuSsnIRRqtjUzD01aYlLLNgISYo/U+NNjyPaBW8ESk2V10CVL3f4qarDYxEGLx8hq15lfDnzArhtx7fO2CW1Oi+xaiKdqeIKyR72KgQ1jMnhP0fqgkbxMzBkTipu7WDBpOX9fhNauu7vrGdGOqR5G+eeqH61gaxJd2JNzLk4oRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=iFY7n9Vhp/1z36GCtxu4sEAjzXxFREHW/cV48tOlaOw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=o+2EVLKC1LSg8ZpQgccZFZ+XAQXwwbHuKnCUExdXHiH84aPprOAMexmfY90uiUpDba7an6a2Wb13BPtKxOsG4x5dsf9H1+cKLjpUdtFC5i+nJWePonYmB5jLIyg5Y7P9v1iILz8gmTFtqLlA4Ym5k7JP/+Z/uZsOhGZJE5YPm4c= 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 13E18C32784; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bMq-2CGl; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.380140896@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:48 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.6][PATCH 43/57] eventfs: Do not create dentries nor inodes in iterate_shared References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152477918854139 X-GMAIL-MSGID: 1790152477918854139 From: "Steven Rostedt (Google)" The original eventfs code added a wrapper around the dcache_readdir open callback and created all the dentries and inodes at open, and increment their ref count. A wrapper was added around the dcache_readdir release function to decrement all the ref counts of those created inodes and dentries. But this proved to be buggy[1] for when a kprobe was created during a dir read, it would create a dentry between the open and the release, and because the release would decrement all ref counts of all files and directories, that would include the kprobe directory that was not there to have its ref count incremented in open. This would cause the ref count to go to negative and later crash the kernel. To solve this, the dentries and inodes that were created and had their ref count upped in open needed to be saved. That list needed to be passed from the open to the release, so that the release would only decrement the ref counts of the entries that were incremented in the open. Unfortunately, the dcache_readdir logic was already using the file->private_data, which is the only field that can be used to pass information from the open to the release. What was done was the eventfs created another descriptor that had a void pointer to save the dcache_readdir pointer, and it wrapped all the callbacks, so that it could save the list of entries that had their ref counts incremented in the open, and pass it to the release. The wrapped callbacks would just put back the dcache_readdir pointer and call the functions it used so it could still use its data[2]. But Linus had an issue with the "hijacking" of the file->private_data (unfortunately this discussion was on a security list, so no public link). Which we finally agreed on doing everything within the iterate_shared callback and leave the dcache_readdir out of it[3]. All the information needed for the getents() could be created then. But this ended up being buggy too[4]. The iterate_shared callback was not the right place to create the dentries and inodes. Even Christian Brauner had issues with that[5]. An attempt was to go back to creating the inodes and dentries at the open, create an array to store the information in the file->private_data, and pass that information to the other callbacks.[6] The difference between that and the original method, is that it does not use dcache_readdir. It also does not up the ref counts of the dentries and pass them. Instead, it creates an array of a structure that saves the dentry's name and inode number. That information is used in the iterate_shared callback, and the array is freed in the dir release. The dentries and inodes created in the open are not used for the iterate_share or release callbacks. Just their names and inode numbers. Linus did not like that either[7] and just wanted to remove the dentries being created in iterate_shared and use the hard coded inode numbers. [ All this while Linus enjoyed an unexpected vacation during the merge window due to lack of power. ] [1] https://lore.kernel.org/linux-trace-kernel/20230919211804.230edf1e@gandalf.local.home/ [2] https://lore.kernel.org/linux-trace-kernel/20230922163446.1431d4fa@gandalf.local.home/ [3] https://lore.kernel.org/linux-trace-kernel/20240104015435.682218477@goodmis.org/ [4] https://lore.kernel.org/all/202401152142.bfc28861-oliver.sang@intel.com/ [5] https://lore.kernel.org/all/20240111-unzahl-gefegt-433acb8a841d@brauner/ [6] https://lore.kernel.org/all/20240116114711.7e8637be@gandalf.local.home/ [7] https://lore.kernel.org/all/20240116170154.5bf0a250@gandalf.local.home/ Link: https://lore.kernel.org/linux-trace-kernel/20240116211353.573784051@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Linus Torvalds Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: 493ec81a8fb8 ("eventfs: Stop using dcache_readdir() for getdents()") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401152142.bfc28861-oliver.sang@intel.com Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 852e46e239ee6db3cd220614cf8bce96e79227c2) --- fs/tracefs/event_inode.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 5edf0b96758b..10580d6b5012 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -727,8 +727,6 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct dentry *ei_dentry = NULL; - struct dentry *dentry; const char *name; umode_t mode; int idx; @@ -749,11 +747,11 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) mutex_lock(&eventfs_mutex); ei = READ_ONCE(ti->private); - if (ei && !ei->is_freed) - ei_dentry = READ_ONCE(ei->dentry); + if (ei && ei->is_freed) + ei = NULL; mutex_unlock(&eventfs_mutex); - if (!ei || !ei_dentry) + if (!ei) goto out; /* @@ -780,11 +778,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) if (r <= 0) continue; - dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); - if (!dentry) - goto out; - ino = dentry->d_inode->i_ino; - dput(dentry); + ino = EVENTFS_FILE_INODE_INO; if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) goto out; @@ -808,11 +802,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = ei_child->name; - dentry = create_dir_dentry(ei, ei_child, ei_dentry); - if (!dentry) - goto out_dec; - ino = dentry->d_inode->i_ino; - dput(dentry); + ino = EVENTFS_DIR_INODE_INO; if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; From patchwork Tue Feb 6 12:09:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197414 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501032dyb; Tue, 6 Feb 2024 04:26:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEd+YGlC+tUk6SJQzumQQkPakXHWnhPolhG4B+6hxSYVw7nMZ7S7pvVpeBv0MMzzsiVDTgS X-Received: by 2002:a05:6830:20c3:b0:6e1:4848:a41b with SMTP id z3-20020a05683020c300b006e14848a41bmr2398307otq.24.1707222408243; Tue, 06 Feb 2024 04:26:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222408; cv=pass; d=google.com; s=arc-20160816; b=Hzoc73ACLTcNz0zbku9ENMxnrx4bRgiDMsaxe5depgMrFgqJqeQPmW3qITeA2kCbDj yZIY4oYV6JZQJkUZVJ2jq7sq8XS2nXJ382S+uCZCdb15NIFCeCsCZ8Ve/VVeq3Yx+KlX Zsncumx3D9q4ELw9YYguzoXuf2dA/6+I9GikNehEHga1ym9vhygS+qXU5Fl5wSr6Xuju yIynEFmJqUjRpeJtnqi8pCDwa/MlImXhCNniquO+Cv1z/VE+7WiyWTNnxJ8xg5MBAhFt SflU2Z3z6ZfffKOxZo17/9wKRPhRgIcIfmhiCRczlC2ez3KVoZYQGiBog/WGfqoVq+ah ssFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=lR6au0kG3WFsHJQwGXzt6iecpuPnXQli3iId+Lo3sbw=; fh=aUi2o92H7na3AikfktCLJJ9nmgMtNj7gryPNIZhys9M=; b=Xi616iGV/7/bdZWsz84EccqqG1DUfIwxWQyyvujbb7PJQB6l7EhEZSCFkiM89PNUCb BysJ5FDvlQd+saWp+WJNnrXXE1Bkvs2VdA5ZF0GTKr0sw/u1U/EUmtplF6yzMjf8MsNc 9xXMuJKo5sSLvt3oaNJITcyz7fkKYiW52ZfUm18f6zwJYQvWM6F+TnfrvJPK3XophojU 5DdJQHuXFifETURGfjiQ4LQWWELEZYmu5BDKdZjC6S0VEaVPi0scdmrlC7inHFHuHoDg m38yMA+4uLibACqB9IwA0I7CbdDzniuwWNiOz/R8shtsqB2G6ZN/nTWcT46tKSqM72M4 Kqvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWGwTJNekNU7q9cDKZZfuFJ6N9ivqaAKgMbP/p8suJo1FB8gufwzfSeEZysK8Axi938ociIRtxR/JbbLdZ3OEuAZMv2yA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o8-20020a05622a138800b0042beee75f61si2170289qtk.568.2024.02.06.04.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54918-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54918-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 060591C24341 for ; Tue, 6 Feb 2024 12:26:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E215114FFBB; Tue, 6 Feb 2024 12:09:39 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B5FD13AA4A; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=r1ltP/SvZZ15DLKT8fV1gWEG8LaQq6R6iI2u4xup0iz5/cjabiewHGkkCDoiZ5t5GY46SM6bS+ea5hDFFLdyjjtMqwA676fl745bgRMYm3gDRM4YHfnRdaaRlVmr4zVytbbkXzteUQnJsmLv32ZJkOaIloPKVpRywjkf8mU22lg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=S927KE9dYG/Lzm2Z83o0zTy+NJITK2h/kIEZaYEod3o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=V/kCj25Pb1+KVftMfixVuA/b0Yf5U7JpCZhlZ+CgOQGp06IUbSS2iNIbqK6JX8aFrX/0r3Ruz2MglBlwMJLyOCe5q+0nT2yj7Z18YRmc9yhvZPORbc3460Gf+6c0nr7UOUUdtmTKQHVt3pjzhjbFMXvQXuRKV/YXupDgdc9y6dI= 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 32A8FC43141; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bNK-2spg; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.546131126@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:49 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Erick Archer , "Gustavo A. R. Silva" Subject: [v6.6][PATCH 44/57] eventfs: Use kcalloc() instead of kzalloc() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152444021776179 X-GMAIL-MSGID: 1790152444021776179 From: Erick Archer As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. So, use the purpose specific kcalloc() function instead of the argument size * count in the kzalloc() function. [1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments Link: https://lore.kernel.org/linux-trace-kernel/20240115181658.4562-1-erick.archer@gmx.com Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Mark Rutland Link: https://github.com/KSPP/linux/issues/162 Signed-off-by: Erick Archer Reviewed-by: Gustavo A. R. Silva Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 1057066009c4325bb1d8430c9274894d0860e7c3) --- fs/tracefs/event_inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 10580d6b5012..6795fda2af19 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -97,7 +97,7 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, /* Preallocate the children mode array if necessary */ if (!(dentry->d_inode->i_mode & S_IFDIR)) { if (!ei->entry_attrs) { - ei->entry_attrs = kzalloc(sizeof(*ei->entry_attrs) * ei->nr_entries, + ei->entry_attrs = kcalloc(ei->nr_entries, sizeof(*ei->entry_attrs), GFP_NOFS); if (!ei->entry_attrs) { ret = -ENOMEM; @@ -874,7 +874,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode } if (size) { - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) { kfree_const(ei->name); kfree(ei); @@ -941,7 +941,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry goto fail; if (size) { - ei->d_children = kzalloc(sizeof(*ei->d_children) * size, GFP_KERNEL); + ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); if (!ei->d_children) goto fail; } From patchwork Tue Feb 6 12:09:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197416 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501200dyb; Tue, 6 Feb 2024 04:27:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPqfwEEfkwFwIb2jq+rgMzOARjqEMxw6E3bsz3v/RcJNi5XVeqvigJMQVTX+82UvM6MSKF X-Received: by 2002:ac8:5b8f:0:b0:42a:7782:c287 with SMTP id a15-20020ac85b8f000000b0042a7782c287mr4978378qta.24.1707222426602; Tue, 06 Feb 2024 04:27:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222426; cv=pass; d=google.com; s=arc-20160816; b=c7r0F7vbyr4q+JZbaNkuJV8zMC+y3u34wLwxB3bQBjbsuaRGnB9lWcWDj2maqBgSe/ Mv+MqOuSuc84kWJznNMusG4mqmg/3uwt0p0szrhZSzqxpeW37K0Gl4oc1AH2F592wHKN yrc7Ol3w74QCWpvOI1jVHjobdT+LSMurap/G6jNhYBvXEdzjlqT1XsHR12eI+5pKJCJi MfXeIhX7fvj2/gW+wzSyvg0ij0t+er/nUk7y24wc3oYXS6Iq0D4Cvntdik/pvMwYLNMr t9gUWPw/vzABojt95k2+WHsaP9+QwSdXAS61sKVfzM2aJgleRBDqmH5di8wBQC1N02ud oG0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=3RN4NWB+356xYpNgRECCmh0ARfrJ2zZfC34yg1jzV3w=; fh=9U4wSBvu9K2ATSvmhvzvvpNcbABYkqab2PqnKqSSGRg=; b=alLnqWWSGahl1C7t9VAIugYQrEQFml+FZgB2mW7YYUXtNcMrTbh4MoG9+wzp+N1ND2 ymJFCwd79dy3Yiumjufig30pHFGuwHhnpmYCZ2ZturHWegrTml7jQPhaaddY3RPN49cu nqJHKELvOx4mgdaqX2wMJzN1DPpgBk8kvQoZcoYvwlsAsnWva041TN/lTPCMZoJteHbF wOLDhHLfDCopyGTnRSI60Xm4wkbJQ/m2Nqt8D5oHUoCiadJx92K8sJaf5c1zl+db83Bt 2UHT8P01OXEWydV1nRQoLJVcPPM5KWlnoqaxM44sBc/u3l5qE/8/kpoSry6Q4jIVJ1O1 NdLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54920-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCXt/nVBqgceFIOGsEjtt8+bsR3ovUhugpoF6Z5U8bL3L42EDzPLLCjIrT6knjhU8DWdtm126hLsovhwUvCcOWExArJ1Eg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p12-20020a05622a00cc00b0042bf838e0dbsi2113088qtw.416.2024.02.06.04.27.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:27:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54920-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-54920-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54920-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 662801C24382 for ; Tue, 6 Feb 2024 12:27:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D0121509A2; Tue, 6 Feb 2024 12:09:40 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CCCF1386A1; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=kMZ6Ip4nHYiFKXXWtIBdiTPF24x01KXQ1x/Vwcl5H3juMw0Fs4BfDn8MIIgJN0iWXjbWTuz9G5xnUTNvQjq8ye8sz7L8Rttm2jNHpexE0s88rX0ut6qVhlMj532hqNB278ncmwM3/tP7+H0DNcw97WYxyV6DfH0wX7yqXl52kZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=gW8Qs5dhqv8o0qe0O7sTx8CGnoF40JWC8ay85t0nh1E=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=F9i5b5HJe19U/8oYhMQXXPkXw55ZbnWV1/0yVJvE7/MBQkAQqvCN5dgwEKsNfPSRB7t6mIq0Bt2BfhQB40Phlo4K8UZi6PdVsxPd2ET75aDiNev3O/ZHUCnCIPSbTZA9p4dy8gFcUEdr1D8XbLQh3Unbp8Ptc15x3lQEG/jSsoI= 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 5AE18C43399; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bNq-3Z0N; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.708915826@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:50 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Geert Uytterhoeven , Geert Uytterhoeven , Kees Cook Subject: [v6.6][PATCH 45/57] eventfs: Save directory inodes in the eventfs_inode structure References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152462769177085 X-GMAIL-MSGID: 1790152462769177085 From: "Steven Rostedt (Google)" The eventfs inodes and directories are allocated when referenced. But this leaves the issue of keeping consistent inode numbers and the number is only saved in the inode structure itself. When the inode is no longer referenced, it can be freed. When the file that the inode was representing is referenced again, the inode is once again created, but the inode number needs to be the same as it was before. Just making the inode numbers the same for all files is fine, but that does not work with directories. The find command will check for loops via the inode number and having the same inode number for directories triggers: # find /sys/kernel/tracing find: File system loop detected; '/sys/kernel/debug/tracing/events/initcall/initcall_finish' is part of the same file system loop as '/sys/kernel/debug/tracing/events/initcall'. [..] Linus pointed out that the eventfs_inode structure ends with a single 32bit int, and on 64 bit machines, there's likely a 4 byte hole due to alignment. We can use this hole to store the inode number for the eventfs_inode. All directories in eventfs are represented by an eventfs_inode and that data structure can hold its inode number. That last int was also purposely placed at the end of the structure to prevent holes from within. Now that there's a 4 byte number to hold the inode, both the inode number and the last integer can be moved up in the structure for better cache locality, where the llist and rcu fields can be moved to the end as they are only used when the eventfs_inode is being deleted. Link: https://lore.kernel.org/all/CAMuHMdXKiorg-jiuKoZpfZyDJ3Ynrfb8=X+c7x0Eewxn-YRdCA@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240122152748.46897388@gandalf.local.home Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Linus Torvalds Reported-by: Geert Uytterhoeven Tested-by: Geert Uytterhoeven Fixes: 53c41052ba31 ("eventfs: Have the inodes all for files and directories all be the same") Signed-off-by: Steven Rostedt (Google) Reviewed-by: Kees Cook (cherry picked from commit 834bf76add3e6168038150f162cbccf1fd492a67) --- fs/tracefs/event_inode.c | 14 +++++++++++--- fs/tracefs/internal.h | 7 ++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 6795fda2af19..6b211522a13e 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -34,7 +34,15 @@ static DEFINE_MUTEX(eventfs_mutex); /* Choose something "unique" ;-) */ #define EVENTFS_FILE_INODE_INO 0x12c4e37 -#define EVENTFS_DIR_INODE_INO 0x134b2f5 + +/* Just try to make something consistent and unique */ +static int eventfs_dir_ino(struct eventfs_inode *ei) +{ + if (!ei->ino) + ei->ino = get_next_ino(); + + return ei->ino; +} /* * The eventfs_inode (ei) itself is protected by SRCU. It is released from @@ -396,7 +404,7 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent inode->i_fop = &eventfs_file_operations; /* All directories will have the same inode number */ - inode->i_ino = EVENTFS_DIR_INODE_INO; + inode->i_ino = eventfs_dir_ino(ei); ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; @@ -802,7 +810,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx) name = ei_child->name; - ino = EVENTFS_DIR_INODE_INO; + ino = eventfs_dir_ino(ei_child); if (!dir_emit(ctx, name, strlen(name), ino, DT_DIR)) goto out_dec; diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 12b7d0150ae9..45397df9bb65 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -55,6 +55,10 @@ struct eventfs_inode { struct eventfs_attr *entry_attrs; struct eventfs_attr attr; void *data; + unsigned int is_freed:1; + unsigned int is_events:1; + unsigned int nr_entries:30; + unsigned int ino; /* * Union - used for deletion * @llist: for calling dput() if needed after RCU @@ -64,9 +68,6 @@ struct eventfs_inode { struct llist_node llist; struct rcu_head rcu; }; - unsigned int is_freed:1; - unsigned int is_events:1; - unsigned int nr_entries:30; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) From patchwork Tue Feb 6 12:09:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1506473dyb; Tue, 6 Feb 2024 04:36:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IGdcHl6mwPV0lnhhhXncGxBw1p1zU89tSFfkXN+a3yievpG2WLXV53hz9OWNUWj3jKUwNVc X-Received: by 2002:a05:6a20:3d20:b0:19e:982e:c3f3 with SMTP id y32-20020a056a203d2000b0019e982ec3f3mr1605802pzi.51.1707223002859; Tue, 06 Feb 2024 04:36:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223002; cv=pass; d=google.com; s=arc-20160816; b=rFdcg/kY7hvn7a2bMPxy0LAM/gyK0gsImMcAYNrpuesbjVZOF3u34+V9G2rMxxDJ3/ ERzbT4AI1SGFh/65SiqmABZ6HwG+mMqu9LikrWj3Y9KbFIDdpz1MULNu9p66OQgVaQKx 1G7iUVz2MRofcd1CG2SDE6TYw1C1Fg25tlDRgqo7eWTfqgkELXjQGvKLiRIBHtXDsjWU phHljuQrboowwLtcC+9TcysZgqGR1FjvKCZGXf2vt6Qix00ZOgh+kW6ks7n7ecpGSe1V zHlAEfpbALtksiQ4QZOx0UZPSuV9lb3YI9l7HgGT610l95vlCJfkNnA/8A/+aPOFsVlt 6Riw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=ez93nIj3r0KL5LhMXr8lgScygvkcsmAkg7g6211UaaY=; fh=slcU1Vi/WjECeD8so4t/+zX88V/gCfsyO/nwFu1nUTg=; b=WCL0N8bNJ7s9RWxXriJsOgM56T5ePTeA0mIE6tAF0UbNgGEXQmoDkm8nwY+LkkOjiZ j4lR5MrSemF0V1F8cLu9oQa11Sl9AJTfn0nao2DeOtWcQyg3Tew6qbdXnKy4lJYERAp0 uHy3zVFQl3VVt6ckBXWoB9+5jUMYrKgl3Y/K5IEQlJ1KBQdoveTzRWKl076fl+5zd/VW 6g2pQOjZpgKUuNakIZFcZi+k+hiBhtuB3F0M6e/VohP7c+cvIF6YUTuv0yOxi/fXWYnm wqEQlu2U8whfPwFvGIYz+fwaX7JOhD//iuuqiTNTJbu4kXAAr9iTQyQgtpBcbaZ8oOFC nUHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54921-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54921-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUsHquZuLLNWn7PUwgSeuZql7QY0JtvKOggIg17pBTDxMOvJHNYonz8lMk77+rnpjUCG1yMKWxxm/w2f3f2u0s+NDHILA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e24-20020a631e18000000b005d6a99217dasi1632423pge.403.2024.02.06.04.36.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:36:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54921-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54921-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54921-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id D4CCCB27EB1 for ; Tue, 6 Feb 2024 12:27:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01505151454; Tue, 6 Feb 2024 12:09:41 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4EDF13B290; Tue, 6 Feb 2024 12:09:25 +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=1707221365; cv=none; b=MMLqDeBOdJAp8eAFvqh44hJ8ngwcink92D62QdpVrtzX2/CC55TbwJeThrOfXrMzMZ6ksN+KShdcMh331k2RZeE5RXFL3vSdcg3vJFYH6bkrTJYLj4NHgdM4DdBJym2i9ffVgb46SYDQ0y0nLcKfMFdokj0FM3xqvAkmAeNdF/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=3cuwo8jKNFJ8ZNaRFdtkUgaWTecxRB1l6ECQ5pijtZI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=id7hF8Kq4zkPepNDkZxydV9VHr9jSk+WCTXnog3BXnt2Jm3UXT082zXyhf7sN7IKCesQjoYr587ODPFL1WOaoNYpMrdofqyydZCkhl0hTf2wmfjlcSLQqWz3RJhvRwJfdbk3T3x1avmo8IyGzADEmQxvUTqstczdIsqg/ykOIaI= 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 8EA08C43394; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bOL-04MI; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120953.870617585@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:51 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers Subject: [v6.6][PATCH 46/57] tracefs: remove stale update_gid code References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790153067282487787 X-GMAIL-MSGID: 1790153067282487787 From: Linus Torvalds The 'eventfs_update_gid()' function is no longer called, so remove it (and the helper function it uses). Link: https://lore.kernel.org/all/CAHk-=wj+DsZZ=2iTUkJ-Nojs9fjYMvPs1NuoM3yK7aTDtJfPYQ@mail.gmail.com/ Fixes: 8186fff7ab64 ("tracefs/eventfs: Use root and instance inodes as default ownership") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 29142dc92c37d3259a33aef15b03e6ee25b0d188) --- fs/tracefs/event_inode.c | 38 -------------------------------------- fs/tracefs/internal.h | 1 - 2 files changed, 39 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 6b211522a13e..1c3dd0ad4660 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -281,44 +281,6 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, inode->i_gid = attr->gid; } -static void update_gid(struct eventfs_inode *ei, kgid_t gid, int level) -{ - struct eventfs_inode *ei_child; - - /* at most we have events/system/event */ - if (WARN_ON_ONCE(level > 3)) - return; - - ei->attr.gid = gid; - - if (ei->entry_attrs) { - for (int i = 0; i < ei->nr_entries; i++) { - ei->entry_attrs[i].gid = gid; - } - } - - /* - * Only eventfs_inode with dentries are updated, make sure - * all eventfs_inodes are updated. If one of the children - * do not have a dentry, this function must traverse it. - */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { - if (!ei_child->dentry) - update_gid(ei_child, gid, level + 1); - } -} - -void eventfs_update_gid(struct dentry *dentry, kgid_t gid) -{ - struct eventfs_inode *ei = dentry->d_fsdata; - int idx; - - idx = srcu_read_lock(&eventfs_srcu); - update_gid(ei, gid, 0); - srcu_read_unlock(&eventfs_srcu, idx); -} - /** * create_file - create a file in the tracefs filesystem * @name: the name of the file to create. diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 45397df9bb65..91c2bf0b91d9 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -82,7 +82,6 @@ struct inode *tracefs_get_inode(struct super_block *sb); struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); struct dentry *eventfs_failed_creating(struct dentry *dentry); struct dentry *eventfs_end_creating(struct dentry *dentry); -void eventfs_update_gid(struct dentry *dentry, kgid_t gid); void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 12:09:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197435 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1506563dyb; Tue, 6 Feb 2024 04:36:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IGJ8hurkipSaJs0TtpCa2z1fUjes83bvoa85cSECiStoIDZ6JNxnREDAfBhiMIRXf9y2+2O X-Received: by 2002:a05:6a20:549e:b0:19e:499c:dd7 with SMTP id i30-20020a056a20549e00b0019e499c0dd7mr1782094pzk.52.1707223013928; Tue, 06 Feb 2024 04:36:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223013; cv=pass; d=google.com; s=arc-20160816; b=AFotcGWwYu17O7zsEp+QtPmnfuBMplRSyIm3FbqMYHRJvTM4btbO864Wdk7gMO3/v2 hColZ8DFdUgV61UrQI0UhBBCiuCoertAw2d+l9//Qe+zZTPioyITTQX7NsRiIqIRO6Ld z81NZWCbGtkXmGaZZdGh6oHwyZXRbMvzjAndKqcAoxtbjAnCL66w7KI9MkV+Mkf2o4KZ vGLQJscOOLI0OQPMeIfEJ8ssQijsx5h1NNXeM0H65kAYdGu/CD4H2c+iHnSw2+HOAutr rzsMgKHcgfNxfmCuzmuWG6PnL0uu/zIejhALALyYkn/aNMyN34dRA3Tq12auwmBLwM/M ySpQ== 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=RbZLtkYgrpGgmw3UH1Q8JIxmzSjl7CFs+4BWjGfroc0=; fh=RdAshnJ5invps6aa+A9wJKO/fyopsNdw/lln1iPQPzo=; b=uMIhqMZgVJbuTnuXNft4+vmav7fzjuFxuIZFW9gcTSta0s5F630Bza/JKzFsHYDACL eGYpYZ+U9S/jRzvbxfOl2sVbGSlsPk/KclgpOCKvSUuRLGAJ4nCkTN9owEVsW3q07i+B +mZ2YyIwVgXrW3p5fbnN0R2oQ9s7txWJUU1wezJK7DMOoWvNn2ksMoYSEh6htymEXDAY tykRfvI4dk6qnvjXDxwW2XNkjm9prUdxDYv6FaSdR//WPdMUmxitUzNQHagu+H7MbVbw bsagWNNjHcjjDLY7Ss78J3Qo1zL/KOUryoKoBUj37CLIggHJbSWms1dKFsUWkcLmfSdL sbmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWmEg1EzjmxVSvaPOntdwabAD27S3oE0vAnT/CbCcE9oijeWQRSKFUGtCl/Q7BDmzHelKauO7gMOfD/dzWjlRVXW0Yj3w== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fm23-20020a056a002f9700b006e05cb7fd6csi714981pfb.243.2024.02.06.04.36.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:36:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54922-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9FD23B27F85 for ; Tue, 6 Feb 2024 12:27:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CBF4151468; Tue, 6 Feb 2024 12:09:41 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F286913B2A5; Tue, 6 Feb 2024 12:09:25 +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=1707221366; cv=none; b=ETY56r58OlsvJMZEwJFAJmCMyggMfRMweutz6DoqzAXHpZCn0RbWOiaK0JlUQKcwWyWVI6SqjReLbyOJDBNXeK6DQ7CT3Vn5+ZNKw329BFQYbmvTwvgJAuEyPjRd+ZHuYOZdtvbywfW/kiUB1U5eVSPquAolBQaQ1nxOZ4/K8mc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=lzb1sLgZCuUuHW8/jlSYK6Gi2ueBjuBQSwLGcv1JC0U=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=OB5XYlpmpPwltR7WmgBuQEj2uUqf7FXATtLJbpuJlZ8z9ky62XuI1WUvCX2NTzk3YS9mmhYDcCDlZ2xdubyXixLM0tf1k3yjuT5f9EhyJkjVRxo5eTSuTFW+OikBmv+ZgseNXCk/39JDVF2xtI493eAY2WSy6kHCh1LAvxV8Zfs= 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 B3317C433A6; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bOq-0lXv; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.038732037@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:52 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.6][PATCH 47/57] tracefs: Zero out the tracefs_inode when allocating it References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790153079444321425 X-GMAIL-MSGID: 1790153079444321425 From: "Steven Rostedt (Google)" eventfs uses the tracefs_inode and assumes that it's already initialized to zero. That is, it doesn't set fields to zero (like ti->private) after getting its tracefs_inode. This causes bugs due to stale values. Just initialize the entire structure to zero on allocation so there isn't any more surprises. This is a partial fix to access to ti->private. The assignment still needs to be made before the dentry is instantiated. Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.315825944@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401291043.e62e89dc-oliver.sang@intel.com Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit d81786f53aec14fd4d56263145a0635afbc64617) --- fs/tracefs/inode.c | 6 ++++-- fs/tracefs/internal.h | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index fc0f133eefdb..ad4c137b7be9 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -38,8 +38,6 @@ static struct inode *tracefs_alloc_inode(struct super_block *sb) if (!ti) return NULL; - ti->flags = 0; - return &ti->vfs_inode; } @@ -779,7 +777,11 @@ static void init_once(void *foo) { struct tracefs_inode *ti = (struct tracefs_inode *) foo; + /* inode_init_once() calls memset() on the vfs_inode portion */ inode_init_once(&ti->vfs_inode); + + /* Zero out the rest */ + memset_after(ti, 0, vfs_inode); } static int __init tracefs_init(void) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 91c2bf0b91d9..7d84349ade87 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -11,9 +11,10 @@ enum { }; struct tracefs_inode { + struct inode vfs_inode; + /* The below gets initialized with memset_after(ti, 0, vfs_inode) */ unsigned long flags; void *private; - struct inode vfs_inode; }; /* From patchwork Tue Feb 6 12:09:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197419 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501601dyb; Tue, 6 Feb 2024 04:27:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBWlU/1iCVOi2n5dI1klAUaBH7A94mBrn7Cpcj8WXl8ibFx+LbltZf7eVXSMSZoczsyz1q X-Received: by 2002:a4a:d2dd:0:b0:599:c80a:2fd2 with SMTP id j29-20020a4ad2dd000000b00599c80a2fd2mr2839750oos.6.1707222476599; Tue, 06 Feb 2024 04:27:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222476; cv=pass; d=google.com; s=arc-20160816; b=oLx7gQhdOojdpNm2NleS3RokTLvPsnRxFvvMc543ZM6JVehBibe0mRuIJnHhVBMPja eunSkuuyVAVtqvbUeLyArMTcrMKGbSk+cV0I5OSmQD+ZQUiU7b9ax3RBb4EJRcV7clD2 SRlCouwkQQIBXBwtNNLDtNhJRhgNEKIRumYJ7H4hdS7WNTZ2JkL2Gx3f8JlZT71FBG8g oXS/A8huUZjGodl+ABiMNM2SAWsHkRN7gT7QDNU7O84ELUHy+voMVcFijOoxP4AQ4rly rjf3NvJ2rxoiJ0RT8lGC6fxnxo5Jrdb4BN4R6M2954fJv6G9Ou4LydRgyOfkn+OCDwNO XS1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Vc5Hl8wHLvI4a/MX2Qudri1ew2Nu0ownXruYvDF/VTo=; fh=AARvVGzm+2X6y4r3wMu9gwF/wlBjwiwbIyjDTQlpVFs=; b=bDjn6oq5Syb9QIV8V32tcJ4y8hNZGakM6QDUjmO68YC+leiR9BWzdtgjemzVEMweYT ND3cnruDwM3tLsgxdbBDz+f7g5tRBhNDNtBEV/wkFddUUQ5YS5yWxAMKLF+F2BbzRZ7D hiaPeedKsaZSbwa4vWrlo4wqMjFrLcinu7NiOfAbv0PqMGF7Y9j3Gq8xVJRZAXrhtPX0 /t7ewYS/p3TpNF5O2mnfmwsIQj9e+5ET+zxim/VxN3KvR8yRaAA1T3zcOJCEBjkI6wN8 qsXB7Q9v5IDD1ueltu0WwM56BSywkqNptOBUldK2Vycn9oCCnJRZfnjcsmdH8iGhnIjn OeUQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54923-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54923-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVZ1y2qAvB3kk/UlTZBQqxxq34wxAr+B2y2BM0uUu7ZZ7xxvqGH6EyiDGgDQ4I8OeGGRPk5+IZke4dl1avJtNH+cw7QRw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c12-20020a056214070c00b00681955e64bcsi2162071qvz.604.2024.02.06.04.27.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:27:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54923-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-54923-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54923-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 613DD1C24364 for ; Tue, 6 Feb 2024 12:27:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C71F8151CDE; Tue, 6 Feb 2024 12:09:41 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08D9613B2AA; Tue, 6 Feb 2024 12:09:26 +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=1707221366; cv=none; b=Ug0ARRJIKcOXgbwJx1KdL7pbkDkAywaI8wPMJKH35GGRVUdH2+qTCqif3ueSaLii8rw0QuqPmBAdwxHXRDwBukiSzQNkPuJhApwpx7qjpDKe3S+TEFo6E+aS3L77Ka4m6g70yJn2ZDBgRrONrsYTv3mlJE1gk+vZNCbtKgw0Qqc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=/K/tqg9istqeXtA6KzMmoqfKg3qYs4d2GHKRR+nK7sY=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=p+OYXc6q6mlGa31UxNqj223Ji68axswzRsjtE7Y7Z990VBTaS/JYECBBv2zbg4cvgDqMTp+ZVQUngQiIZ8PkeVGP7KsOKBd1hvwkZn2PVda2WOx6v84fuq5KG0xXpiZdl7lOWEt9rLndTM3hkreRrujRbRE7Ji4E8C6z5nMZGw4= 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 E1C41C433F1; Tue, 6 Feb 2024 12:09:25 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bPL-1QmP; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.203316263@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:53 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , kernel test robot Subject: [v6.6][PATCH 48/57] eventfs: Initialize the tracefs inode properly References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152515679219103 X-GMAIL-MSGID: 1790152515679219103 From: Linus Torvalds The tracefs-specific fields in the inode were not initialized before the inode was exposed to others through the dentry with 'd_instantiate()'. Move the field initializations up to before the d_instantiate. Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.478449628@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: 5790b1fb3d672 ("eventfs: Remove eventfs_file and just use eventfs_inode") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202401291043.e62e89dc-oliver.sang@intel.com Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 4fa4b010b83fb2f837b5ef79e38072a79e96e4f1) --- fs/tracefs/event_inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1c3dd0ad4660..824b1811e342 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -370,6 +370,8 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; + /* Only directories have ti->private set to an ei, not files */ + ti->private = ei; inc_nlink(inode); d_instantiate(dentry, inode); @@ -515,7 +517,6 @@ create_file_dentry(struct eventfs_inode *ei, int idx, static void eventfs_post_create_dir(struct eventfs_inode *ei) { struct eventfs_inode *ei_child; - struct tracefs_inode *ti; lockdep_assert_held(&eventfs_mutex); @@ -525,9 +526,6 @@ static void eventfs_post_create_dir(struct eventfs_inode *ei) srcu_read_lock_held(&eventfs_srcu)) { ei_child->d_parent = ei->dentry; } - - ti = get_tracefs(ei->dentry->d_inode); - ti->private = ei; } /** From patchwork Tue Feb 6 12:09:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197437 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1506837dyb; Tue, 6 Feb 2024 04:37:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUY7jL20lNUWJEGhDgHk5RPN2FHido2UoKydVMUyED6ZBzyNFBKmEW4MENsNkbJe/MRSPy X-Received: by 2002:a17:90a:43c5:b0:296:e3e:fc0 with SMTP id r63-20020a17090a43c500b002960e3e0fc0mr12291327pjg.1.1707223044123; Tue, 06 Feb 2024 04:37:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223044; cv=pass; d=google.com; s=arc-20160816; b=U42I4Kn4RDsxWpybCxprc5RFQ4AXnbhiR3oHApkDy2PQVgCGOjTJjRMD6exDzZ+13q XgwR0mLg+CeehJPcRs1se7NUS7TTgfwJtcrr8nwbKLjXpCnEw/bLWmX4hNEYj4abauwu fUZ62/Eg9jh22x3nYrOnX7XYUel3NigI3uDq5wDIn3IztLy7fFIMXXYm8Gf7NdNl1RwQ VKkT7gacvsQDK6xrfxmn+gyMFnyw/IoCIahcJZdZDwEdC2yXlbRoW/X9v0X4h4aEnvQS fXSMjBRyYUTuR2NmMepa8RqA3/dhX306YYuJzB+SY29ezIgAT/ncKPiElObL8M4cFxet BXvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=qLO9528/AFQeQ08mVECH/y3JPQcyc9jWqtGZe8Oheaw=; fh=53SKGGjhNTe5zUJRwdlIIzqN1iOz/oev+lX+dC+oJd0=; b=K/mUXgH998ssroZ3VrvbxkNe1gv4Hz6NgovU8A4o3fPt4CkLmQv64LLd/P3jYVLNGM C7/Hqnln1gVlz5qzRe+HNPwkqScRwjxPju7DAUulQeriDMUBSqT62J6eyKEOjhcpW4tX XcQizeons6/NDdLCO2ccIf+5Uqhiwn+DXfoGE71dpeP5wuV5yCFEi0gX6LvCD1UxnO3M bzM/kc554uGvNFYLyPNpSmm0/7JHKCZQQihxbspvV5ZPUB61Wq0JubRs5ZblWm1VIHBe y2+D1Y5J8aCvN2z343ak4lFBjPPHHQ+6BnNjy1Y0H8wDwxzuw1d/AHf5NWDy40A5OE8s 2awA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXSmdUm1kqi+cHwMOfUrKOIv4nItcA1zEw3ZE6h7GyJD3PLg2EXfflzaCq4dQHPvv5d14LvmnF/kxOBBKo5aFMzz7sS3g== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id pg17-20020a17090b1e1100b002960ecfb434si1086507pjb.160.2024.02.06.04.37.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:37:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54924-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B2AABB2823E for ; Tue, 6 Feb 2024 12:27:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C5B72151CDA; Tue, 6 Feb 2024 12:09:41 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2655E133422; Tue, 6 Feb 2024 12:09:26 +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=1707221366; cv=none; b=WD1noir4Et1UHXNsH63D9doQn3EXM2I4AwLN0jrTcYgrXEAjuQ0TgM4m/aPnkpDnIVM2d95hO19mgeJJnZq1vq0XX2AvMSUt8a3mdCZ4ZDhTW0r61vWdk1mG6OzVFOMdpUncjlSuNKf7onTutczuNrHplBflBc7nIMpM44d36Ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=QRzNsPzlJd46xARPV8LoVgr8hMSulcnSOm9LygT2RX0=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=AZMWv8mc3ayqjcdr0zl3XJeSe4qIg4aLn+1bbMtmzGNYvjJEeqBB77vxjy/xunW1Xkbs/xBIc1ES87JsOH6qF+xHHa5+wVWPaCjLG7RXESvTMv/2+GpZPoeCusiY8eGxhE23+nc/pKwI1/81guYbusu2h1RJqVjp7l9IRUdGMnA= 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 107E4C43394; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bPq-24wh; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.362950692@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:54 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 49/57] tracefs: Avoid using the ei->dentry pointer unnecessarily References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790153110935021690 X-GMAIL-MSGID: 1790153110935021690 From: Linus Torvalds The eventfs_find_events() code tries to walk up the tree to find the event directory that a dentry belongs to, in order to then find the eventfs inode that is associated with that event directory. However, it uses an odd combination of walking the dentry parent, looking up the eventfs inode associated with that, and then looking up the dentry from there. Repeat. But the code shouldn't have back-pointers to dentries in the first place, and it should just walk the dentry parenthood chain directly. Similarly, 'set_top_events_ownership()' looks up the dentry from the eventfs inode, but the only reason it wants a dentry is to look up the superblock in order to look up the root dentry. But it already has the real filesystem inode, which has that same superblock pointer. So just pass in the superblock pointer using the information that's already there, instead of looking up extraneous data that is irrelevant. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.638645365@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 99c001cb617df409dac275a059d6c3f187a2da7a) --- fs/tracefs/event_inode.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 824b1811e342..e9819d719d2a 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -156,33 +156,30 @@ static int eventfs_set_attr(struct mnt_idmap *idmap, struct dentry *dentry, return ret; } -static void update_top_events_attr(struct eventfs_inode *ei, struct dentry *dentry) +static void update_top_events_attr(struct eventfs_inode *ei, struct super_block *sb) { - struct inode *inode; + struct inode *root; /* Only update if the "events" was on the top level */ if (!ei || !(ei->attr.mode & EVENTFS_TOPLEVEL)) return; /* Get the tracefs root inode. */ - inode = d_inode(dentry->d_sb->s_root); - ei->attr.uid = inode->i_uid; - ei->attr.gid = inode->i_gid; + root = d_inode(sb->s_root); + ei->attr.uid = root->i_uid; + ei->attr.gid = root->i_gid; } static void set_top_events_ownership(struct inode *inode) { struct tracefs_inode *ti = get_tracefs(inode); struct eventfs_inode *ei = ti->private; - struct dentry *dentry; /* The top events directory doesn't get automatically updated */ if (!ei || !ei->is_events || !(ei->attr.mode & EVENTFS_TOPLEVEL)) return; - dentry = ei->dentry; - - update_top_events_attr(ei, dentry); + update_top_events_attr(ei, inode->i_sb); if (!(ei->attr.mode & EVENTFS_SAVE_UID)) inode->i_uid = ei->attr.uid; @@ -235,8 +232,10 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) mutex_lock(&eventfs_mutex); do { - /* The parent always has an ei, except for events itself */ - ei = dentry->d_parent->d_fsdata; + // The parent is stable because we do not do renames + dentry = dentry->d_parent; + // ... and directories always have d_fsdata + ei = dentry->d_fsdata; /* * If the ei is being freed, the ownership of the children @@ -246,12 +245,11 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) ei = NULL; break; } - - dentry = ei->dentry; + // Walk upwards until you find the events inode } while (!ei->is_events); mutex_unlock(&eventfs_mutex); - update_top_events_attr(ei, dentry); + update_top_events_attr(ei, dentry->d_sb); return ei; } From patchwork Tue Feb 6 12:09:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197427 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1502130dyb; Tue, 6 Feb 2024 04:29:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IEgfSdaijXEDnhjLla0pVTG9xRaU8ocDUI4Ttj+OLMzfXkIpPYQH9uRNc1Z9nyqf5nD3J10 X-Received: by 2002:ac8:498d:0:b0:42c:1cb9:bb5a with SMTP id f13-20020ac8498d000000b0042c1cb9bb5amr1765057qtq.47.1707222541500; Tue, 06 Feb 2024 04:29:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222541; cv=pass; d=google.com; s=arc-20160816; b=ZvD+wCkMq8dgA5A37kLM5d5GX4KO3S7RkLH+MLq4L5bsX8TkzWtcHp0IO/5F/AWgsC Wq6bDmH9gL+pyroTftY2fH9UmtJu4Wd8tMaIu/DhPJnMp0B3lAe7mQbLI4rPCj0iQORv BybCpESIDyhRZ02ywwDFUll4KhGIK0QNnG0W4hAaLBhvaCniDfeJRS/nsV0xBmgixeA8 Z7EBs8pNbHqtbCrgKe2gzVR2XHMvlrXacSFgXczWfk8RneeHt+Ps71woniaUgS7VW8dX sU2JBf24tfe7x8P7rz7Z0+skU8gFBJC8rc2sAeEG0acHG9UBld2aY/+h/Mhq5O0zmbe+ MZcw== 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=gueAIvJr5yt0wHe8+UVFWEABniCVQdSLu3ScA9LdgwU=; fh=f0L5KZSmDPHgPVBqXlDAHFwCjxa0JE2Sy3xPwrqAZEc=; b=Zp6EMF1RIeM3j+GcuvTVHx4OcLJkG+8wPm/DKxThUng+uN01nPoOpYwD9pt4egfwfs 3MTCiGt6ZmK7W1qA9wEnpfUx6Kyx8yCrT15PdkAnivjE2sjpjQ/7wVHGNvya9wv0TZyk wCO4R0tT0g+h2/VQE8KXqykRDkntdyMjWqpC+YoRjMe+x8xVC9qsqI0E7TxI/ScosqZ7 HY+F98ZqN25Cn39jrwMXBH92Dhh+U1s/gR59OQ0NiXqncizvmfhvHPTfSxlSjU5FXGUZ bJuwk8mDbGg0GnubdQ0i08EEpu6DPy8k25q4NOgejGBjusrN1H4x3v6jJ9TH6xuXIY5Y ZX7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54927-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54927-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVO4kx7waokrWXm9hfCx4N9ViOKRgUjkt6yXxU6xwG4IC8K9m/YgbqZNuPlCggwug5meMCCmZUhDmRw2v8ocLHAcQEfxw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f7-20020ac85d07000000b0042bf8e02246si2247240qtx.614.2024.02.06.04.29.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:29:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54927-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-54927-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54927-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 396FA1C243B9 for ; Tue, 6 Feb 2024 12:29:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 745C3153517; Tue, 6 Feb 2024 12:09:44 +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 C450A13B7AB; Tue, 6 Feb 2024 12:09:26 +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=1707221366; cv=none; b=ZqLSxXmctJ68OEqtSyvY8IOKGI3pNvRFz1xRB6qLcmPVQfTXUuNLdrOqbXgfAjflfo2dJHIAZfxLcHW7eTpd9Qv9uAihMQrkPvA17e7rjdLwQSlP9mQlSVO/R5SszHfSeXuT11feitEZFvazql/jnMjqJWttUSa7YWvFA7HpdYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=2VWss/PWcjeVY+fOXTxmvGbZJo/7iuUEjoQXFypRYnQ=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dD24rghXwAhk2lBylSG+UxWJQbh89FQBC9aZhd9hVctlND/f0wBWIJaeXBr+GuAIRsLA5JslFgCHwKEMpMOWqDjRfCXQR29JA1WHa2avF003nlYt6s96gsmcs/dxUJzhg+533Sn7pkEbLH6jTDYIC9RTc8Gm2gXqZrIZzgXP0Wk= 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 2F722C41679; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bQL-2lWF; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.518365320@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:55 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Al Viro , Christian Brauner , Ajay Kaher Subject: [v6.6][PATCH 50/57] tracefs: dentry lookup crapectomy References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152583484894807 X-GMAIL-MSGID: 1790152583484894807 From: Linus Torvalds The dentry lookup for eventfs files was very broken, and had lots of signs of the old situation where the filesystem names were all created statically in the dentry tree, rather than being looked up dynamically based on the eventfs data structures. You could see it in the naming - how it claimed to "create" dentries rather than just look up the dentries that were given it. You could see it in various nonsensical and very incorrect operations, like using "simple_lookup()" on the dentries that were passed in, which only results in those dentries becoming negative dentries. Which meant that any other lookup would possibly return ENOENT if it saw that negative dentry before the data was then later filled in. You could see it in the immense amount of nonsensical code that didn't actually just do lookups. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131233227.73db55e1@gandalf.local.home Cc: stable@vger.kernel.org Cc: Al Viro Cc: Masami Hiramatsu Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Greg Kroah-Hartman Cc: Ajay Kaher Cc: Mark Rutland Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 49304c2b93e4f7468b51ef717cbe637981397115) --- fs/tracefs/event_inode.c | 275 +++++++-------------------------------- fs/tracefs/inode.c | 69 ---------- fs/tracefs/internal.h | 3 - 3 files changed, 50 insertions(+), 297 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index e9819d719d2a..04c2ab90f93e 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -230,7 +230,6 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) { struct eventfs_inode *ei; - mutex_lock(&eventfs_mutex); do { // The parent is stable because we do not do renames dentry = dentry->d_parent; @@ -247,7 +246,6 @@ static struct eventfs_inode *eventfs_find_events(struct dentry *dentry) } // Walk upwards until you find the events inode } while (!ei->is_events); - mutex_unlock(&eventfs_mutex); update_top_events_attr(ei, dentry->d_sb); @@ -280,11 +278,10 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, } /** - * create_file - create a file in the tracefs filesystem - * @name: the name of the file to create. + * lookup_file - look up a file in the tracefs filesystem + * @dentry: the dentry to look up * @mode: the permission that the file should have. * @attr: saved attributes changed by user - * @parent: parent dentry for this file. * @data: something that the caller will want to get to later on. * @fop: struct file_operations that should be used for this file. * @@ -292,13 +289,13 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, * directory. The inode.i_private pointer will point to @data in the open() * call. */ -static struct dentry *create_file(const char *name, umode_t mode, +static struct dentry *lookup_file(struct dentry *dentry, + umode_t mode, struct eventfs_attr *attr, - struct dentry *parent, void *data, + void *data, const struct file_operations *fop) { struct tracefs_inode *ti; - struct dentry *dentry; struct inode *inode; if (!(mode & S_IFMT)) @@ -307,15 +304,9 @@ static struct dentry *create_file(const char *name, umode_t mode, if (WARN_ON_ONCE(!S_ISREG(mode))) return NULL; - WARN_ON_ONCE(!parent); - dentry = eventfs_start_creating(name, parent); - - if (IS_ERR(dentry)) - return dentry; - inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) - return eventfs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); /* If the user updated the directory's attributes, use them */ update_inode_attr(dentry, inode, attr, mode); @@ -329,32 +320,29 @@ static struct dentry *create_file(const char *name, umode_t mode, ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; - d_instantiate(dentry, inode); + + d_add(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); - return eventfs_end_creating(dentry); + return dentry; }; /** - * create_dir - create a dir in the tracefs filesystem + * lookup_dir_entry - look up a dir in the tracefs filesystem + * @dentry: the directory to look up * @ei: the eventfs_inode that represents the directory to create - * @parent: parent dentry for this file. * - * This function will create a dentry for a directory represented by + * This function will look up a dentry for a directory represented by * a eventfs_inode. */ -static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent) +static struct dentry *lookup_dir_entry(struct dentry *dentry, + struct eventfs_inode *pei, struct eventfs_inode *ei) { struct tracefs_inode *ti; - struct dentry *dentry; struct inode *inode; - dentry = eventfs_start_creating(ei->name, parent); - if (IS_ERR(dentry)) - return dentry; - inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) - return eventfs_failed_creating(dentry); + return ERR_PTR(-ENOMEM); /* If the user updated the directory's attributes, use them */ update_inode_attr(dentry, inode, &ei->attr, @@ -371,11 +359,14 @@ static struct dentry *create_dir(struct eventfs_inode *ei, struct dentry *parent /* Only directories have ti->private set to an ei, not files */ ti->private = ei; + dentry->d_fsdata = ei; + ei->dentry = dentry; // Remove me! + inc_nlink(inode); - d_instantiate(dentry, inode); + d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); - return eventfs_end_creating(dentry); + return dentry; } static void free_ei(struct eventfs_inode *ei) @@ -425,7 +416,7 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) } /** - * create_file_dentry - create a dentry for a file of an eventfs_inode + * lookup_file_dentry - create a dentry for a file of an eventfs_inode * @ei: the eventfs_inode that the file will be created under * @idx: the index into the d_children[] of the @ei * @parent: The parent dentry of the created file. @@ -438,157 +429,21 @@ void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) * address located at @e_dentry. */ static struct dentry * -create_file_dentry(struct eventfs_inode *ei, int idx, - struct dentry *parent, const char *name, umode_t mode, void *data, +lookup_file_dentry(struct dentry *dentry, + struct eventfs_inode *ei, int idx, + umode_t mode, void *data, const struct file_operations *fops) { struct eventfs_attr *attr = NULL; struct dentry **e_dentry = &ei->d_children[idx]; - struct dentry *dentry; - - WARN_ON_ONCE(!inode_is_locked(parent->d_inode)); - mutex_lock(&eventfs_mutex); - if (ei->is_freed) { - mutex_unlock(&eventfs_mutex); - return NULL; - } - /* If the e_dentry already has a dentry, use it */ - if (*e_dentry) { - dget(*e_dentry); - mutex_unlock(&eventfs_mutex); - return *e_dentry; - } - - /* ei->entry_attrs are protected by SRCU */ if (ei->entry_attrs) attr = &ei->entry_attrs[idx]; - mutex_unlock(&eventfs_mutex); - - dentry = create_file(name, mode, attr, parent, data, fops); + dentry->d_fsdata = ei; // NOTE: ei of _parent_ + lookup_file(dentry, mode, attr, data, fops); - mutex_lock(&eventfs_mutex); - - if (IS_ERR_OR_NULL(dentry)) { - /* - * When the mutex was released, something else could have - * created the dentry for this e_dentry. In which case - * use that one. - * - * If ei->is_freed is set, the e_dentry is currently on its - * way to being freed, don't return it. If e_dentry is NULL - * it means it was already freed. - */ - if (ei->is_freed) { - dentry = NULL; - } else { - dentry = *e_dentry; - dget(dentry); - } - mutex_unlock(&eventfs_mutex); - return dentry; - } - - if (!*e_dentry && !ei->is_freed) { - *e_dentry = dentry; - dentry->d_fsdata = ei; - } else { - /* - * Should never happen unless we get here due to being freed. - * Otherwise it means two dentries exist with the same name. - */ - WARN_ON_ONCE(!ei->is_freed); - dentry = NULL; - } - mutex_unlock(&eventfs_mutex); - - return dentry; -} - -/** - * eventfs_post_create_dir - post create dir routine - * @ei: eventfs_inode of recently created dir - * - * Map the meta-data of files within an eventfs dir to their parent dentry - */ -static void eventfs_post_create_dir(struct eventfs_inode *ei) -{ - struct eventfs_inode *ei_child; - - lockdep_assert_held(&eventfs_mutex); - - /* srcu lock already held */ - /* fill parent-child relation */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { - ei_child->d_parent = ei->dentry; - } -} - -/** - * create_dir_dentry - Create a directory dentry for the eventfs_inode - * @pei: The eventfs_inode parent of ei. - * @ei: The eventfs_inode to create the directory for - * @parent: The dentry of the parent of this directory - * - * This creates and attaches a directory dentry to the eventfs_inode @ei. - */ -static struct dentry * -create_dir_dentry(struct eventfs_inode *pei, struct eventfs_inode *ei, - struct dentry *parent) -{ - struct dentry *dentry = NULL; - - WARN_ON_ONCE(!inode_is_locked(parent->d_inode)); - - mutex_lock(&eventfs_mutex); - if (pei->is_freed || ei->is_freed) { - mutex_unlock(&eventfs_mutex); - return NULL; - } - if (ei->dentry) { - /* If the eventfs_inode already has a dentry, use it */ - dentry = ei->dentry; - dget(dentry); - mutex_unlock(&eventfs_mutex); - return dentry; - } - mutex_unlock(&eventfs_mutex); - - dentry = create_dir(ei, parent); - - mutex_lock(&eventfs_mutex); - - if (IS_ERR_OR_NULL(dentry) && !ei->is_freed) { - /* - * When the mutex was released, something else could have - * created the dentry for this e_dentry. In which case - * use that one. - * - * If ei->is_freed is set, the e_dentry is currently on its - * way to being freed. - */ - dentry = ei->dentry; - if (dentry) - dget(dentry); - mutex_unlock(&eventfs_mutex); - return dentry; - } - - if (!ei->dentry && !ei->is_freed) { - ei->dentry = dentry; - eventfs_post_create_dir(ei); - dentry->d_fsdata = ei; - } else { - /* - * Should never happen unless we get here due to being freed. - * Otherwise it means two dentries exist with the same name. - */ - WARN_ON_ONCE(!ei->is_freed); - dentry = NULL; - } - mutex_unlock(&eventfs_mutex); + *e_dentry = dentry; // Remove me return dentry; } @@ -607,79 +462,49 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) { - const struct file_operations *fops; - const struct eventfs_entry *entry; struct eventfs_inode *ei_child; struct tracefs_inode *ti; struct eventfs_inode *ei; - struct dentry *ei_dentry = NULL; - struct dentry *ret = NULL; - struct dentry *d; const char *name = dentry->d_name.name; - umode_t mode; - void *data; - int idx; - int i; - int r; ti = get_tracefs(dir); if (!(ti->flags & TRACEFS_EVENT_INODE)) - return NULL; - - /* Grab srcu to prevent the ei from going away */ - idx = srcu_read_lock(&eventfs_srcu); + return ERR_PTR(-EIO); - /* - * Grab the eventfs_mutex to consistent value from ti->private. - * This s - */ mutex_lock(&eventfs_mutex); - ei = READ_ONCE(ti->private); - if (ei && !ei->is_freed) - ei_dentry = READ_ONCE(ei->dentry); - mutex_unlock(&eventfs_mutex); - if (!ei || !ei_dentry) + ei = ti->private; + if (!ei || ei->is_freed) goto out; - data = ei->data; - - list_for_each_entry_srcu(ei_child, &ei->children, list, - srcu_read_lock_held(&eventfs_srcu)) { + list_for_each_entry(ei_child, &ei->children, list) { if (strcmp(ei_child->name, name) != 0) continue; - ret = simple_lookup(dir, dentry, flags); - if (IS_ERR(ret)) + if (ei_child->is_freed) goto out; - d = create_dir_dentry(ei, ei_child, ei_dentry); - dput(d); + lookup_dir_entry(dentry, ei, ei_child); goto out; } - for (i = 0; i < ei->nr_entries; i++) { - entry = &ei->entries[i]; - if (strcmp(name, entry->name) == 0) { - void *cdata = data; - mutex_lock(&eventfs_mutex); - /* If ei->is_freed, then the event itself may be too */ - if (!ei->is_freed) - r = entry->callback(name, &mode, &cdata, &fops); - else - r = -1; - mutex_unlock(&eventfs_mutex); - if (r <= 0) - continue; - ret = simple_lookup(dir, dentry, flags); - if (IS_ERR(ret)) - goto out; - d = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); - dput(d); - break; - } + for (int i = 0; i < ei->nr_entries; i++) { + void *data; + umode_t mode; + const struct file_operations *fops; + const struct eventfs_entry *entry = &ei->entries[i]; + + if (strcmp(name, entry->name) != 0) + continue; + + data = ei->data; + if (entry->callback(name, &mode, &data, &fops) <= 0) + goto out; + + lookup_file_dentry(dentry, ei, i, mode, data, fops); + goto out; } out: - srcu_read_unlock(&eventfs_srcu, idx); - return ret; + mutex_unlock(&eventfs_mutex); + return NULL; } /* diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index ad4c137b7be9..a24dfa7fcf23 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -495,75 +495,6 @@ struct dentry *tracefs_end_creating(struct dentry *dentry) return dentry; } -/** - * eventfs_start_creating - start the process of creating a dentry - * @name: Name of the file created for the dentry - * @parent: The parent dentry where this dentry will be created - * - * This is a simple helper function for the dynamically created eventfs - * files. When the directory of the eventfs files are accessed, their - * dentries are created on the fly. This function is used to start that - * process. - */ -struct dentry *eventfs_start_creating(const char *name, struct dentry *parent) -{ - struct dentry *dentry; - int error; - - /* Must always have a parent. */ - if (WARN_ON_ONCE(!parent)) - return ERR_PTR(-EINVAL); - - error = simple_pin_fs(&trace_fs_type, &tracefs_mount, - &tracefs_mount_count); - if (error) - return ERR_PTR(error); - - if (unlikely(IS_DEADDIR(parent->d_inode))) - dentry = ERR_PTR(-ENOENT); - else - dentry = lookup_one_len(name, parent, strlen(name)); - - if (!IS_ERR(dentry) && dentry->d_inode) { - dput(dentry); - dentry = ERR_PTR(-EEXIST); - } - - if (IS_ERR(dentry)) - simple_release_fs(&tracefs_mount, &tracefs_mount_count); - - return dentry; -} - -/** - * eventfs_failed_creating - clean up a failed eventfs dentry creation - * @dentry: The dentry to clean up - * - * If after calling eventfs_start_creating(), a failure is detected, the - * resources created by eventfs_start_creating() needs to be cleaned up. In - * that case, this function should be called to perform that clean up. - */ -struct dentry *eventfs_failed_creating(struct dentry *dentry) -{ - dput(dentry); - simple_release_fs(&tracefs_mount, &tracefs_mount_count); - return NULL; -} - -/** - * eventfs_end_creating - Finish the process of creating a eventfs dentry - * @dentry: The dentry that has successfully been created. - * - * This function is currently just a place holder to match - * eventfs_start_creating(). In case any synchronization needs to be added, - * this function will be used to implement that without having to modify - * the callers of eventfs_start_creating(). - */ -struct dentry *eventfs_end_creating(struct dentry *dentry) -{ - return dentry; -} - /* Find the inode that this will use for default */ static struct inode *instance_inode(struct dentry *parent, struct inode *inode) { diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 7d84349ade87..09037e2c173d 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -80,9 +80,6 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); struct dentry *tracefs_end_creating(struct dentry *dentry); struct dentry *tracefs_failed_creating(struct dentry *dentry); struct inode *tracefs_get_inode(struct super_block *sb); -struct dentry *eventfs_start_creating(const char *name, struct dentry *parent); -struct dentry *eventfs_failed_creating(struct dentry *dentry); -struct dentry *eventfs_end_creating(struct dentry *dentry); void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 12:09:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197420 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501735dyb; Tue, 6 Feb 2024 04:28:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IETnQDEGCxV0J00hA7yES7GGdTnXSsu7z2GGWLQHiLFg/rGMqbaNg3DsnzPJUK5YkRPA9k9 X-Received: by 2002:a17:903:2792:b0:1d9:119e:af45 with SMTP id jw18-20020a170903279200b001d9119eaf45mr1251468plb.41.1707222491685; Tue, 06 Feb 2024 04:28:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222491; cv=pass; d=google.com; s=arc-20160816; b=KNobQ/NtCcTUbMd3jLz0J3rWNT0gg53HsnKYO6duy/XgcO1DQ/R5DxK9Jrmjhk6mg9 Y4RkvHAy89k5HkLr0VJs5Qc5CLlGlwuyRfygB9IbM/qNk1zvCXVojJ5dzarTqe2RVYZI 9Gs/3kutI9vjLo9Hl7RtXfL0i9Mkn6Rp/eOFUFp9mOoJtZ1BFlnV9tXQ9JL662wTN9U8 q/hL7hNNWPl/WDqRVQkor8To8kISftbsp0Wj7nORImgxlmofrT4Z00ZzHa+dZCz5rmsq CyeEImUgCQbRfadxU3uv2Eaw4/OBNw4JsXyKEJTyiEJAtk1GdOHwwAk7oTq38FTldX6S Dudw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=5P4MAWSKMmD3/d6RtYJCLwc+pyfvZUI8lTsxddGrfqo=; fh=ESN71XiXU8hbpcqe/TnZIfQ07UGlWpZARTDt5Vi+j0E=; b=tFWfjXFA4hVFdryBrbJwlhiUz0z7M6Wv6oIYbVeccU1nvlxdJhEk8jzRtT51kf84P9 5xaqvJPaST/DqSvSfweIPRy8XNO8cKZRz7nFhRkdrQ7nYVNUH8Dl6/GwzIeDdBOQsKxd Rr8Rmd2u2DKpNlzIDvU/mWRSGgCC3qGsS+UDetu1JwTNkQGo4azcNbhr9HC7fdFOTnfJ ysAJyH2E+a9X/iBL3rE/YofZegEkSB/8Nct7SFNhedBKTkjOiAi/MrNWSGF3qBYWKOt1 cuiISqQIk0CuXm/pko8JFd2qpwo696wPhcRZbZ3vcvvfTGoODwNrQDgg1a/ou0HhT8O4 C2Dg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54925-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54925-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCU+TsUv5czXIb0bFLWU8geevqqhNid4RiprH+Dg832fhUe3clBT7pWZOX7IHr6V81kkjqYhT4pc0Genv/s/oJLi3aOksQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id z6-20020a170903018600b001d8dbb867a5si1576528plg.592.2024.02.06.04.28.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54925-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-54925-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54925-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 780C8283835 for ; Tue, 6 Feb 2024 12:28:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47A32152BE9; Tue, 6 Feb 2024 12:09:42 +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 85E5213B78C; Tue, 6 Feb 2024 12:09:26 +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=1707221366; cv=none; b=IfX9Xk3XubcyC2gexM/2wtfG4EXnczgimHjxMKZgrmY63rQpPTcRZjqoSzvcLGYzMxqBr/ti8dSIL8b80NZ9gwCNPq6rmp/FkNYAAB1Byie1JXOEXAxCCJG9o2330yEJvRUu2e/XkhUuwwblcOOKjlgiuBfEnlsNZ40u/jdQ/Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=WyXLYu467PqbTFP05lGa1iuD6tL0QtugqCd95Pr2/KA=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=cL9DUA+9hhPfrREwbPhGQjPTc2oCnTi/Ld+LZPIkkHHoRn46dvGH7YvoDrKZQa9Y0oF03E28InQtZkBMlfHAcIScPa3SCz7lXoCcsSKm4LAxwdyVjcaphvRRUkNQ5T38P/g0mLL2vpH6QxyTIGXTxlECc+saHJXIT0mlZOnU6M4= 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 62B27C433C7; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bQq-3STz; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.681339731@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:56 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 51/57] eventfs: Remove unused d_parent pointer field References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152531521583944 X-GMAIL-MSGID: 1790152531521583944 From: Linus Torvalds It's never used Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185512.961772428@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 408600be78cdb8c650a97ecc7ff411cb216811b5) --- fs/tracefs/event_inode.c | 4 +--- fs/tracefs/internal.h | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 04c2ab90f93e..16ca8d9759b1 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -680,10 +680,8 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode INIT_LIST_HEAD(&ei->list); mutex_lock(&eventfs_mutex); - if (!parent->is_freed) { + if (!parent->is_freed) list_add_tail(&ei->list, &parent->children); - ei->d_parent = parent->dentry; - } mutex_unlock(&eventfs_mutex); /* Was the parent freed? */ diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 09037e2c173d..932733a2696a 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -36,7 +36,6 @@ struct eventfs_attr { * @name: the name of the directory to create * @children: link list into the child eventfs_inode * @dentry: the dentry of the directory - * @d_parent: pointer to the parent's dentry * @d_children: The array of dentries to represent the files when created * @entry_attrs: Saved mode and ownership of the @d_children * @attr: Saved mode and ownership of eventfs_inode itself @@ -51,7 +50,6 @@ struct eventfs_inode { const char *name; struct list_head children; struct dentry *dentry; /* Check is_freed to access */ - struct dentry *d_parent; struct dentry **d_children; struct eventfs_attr *entry_attrs; struct eventfs_attr attr; From patchwork Tue Feb 6 12:09:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197438 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1507106dyb; Tue, 6 Feb 2024 04:38:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IG0QuRl76L/esx2QrPt8eHz/H0I8Q2l4ioHYCOGSKoRbz2gqH40yqETXeBZm5HCEPAYFkBI X-Received: by 2002:a05:6a20:d90e:b0:19e:9c72:90ab with SMTP id jd14-20020a056a20d90e00b0019e9c7290abmr529864pzb.18.1707223080330; Tue, 06 Feb 2024 04:38:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707223080; cv=pass; d=google.com; s=arc-20160816; b=E5K/LCSvnQ/QD0h6/JTfTXNNz0MYu3/EOtQu1whoUFtI34Te8RTlnQ+wZSdP1HgUhL 4U+vzL9HZDEfoEQKZ/OhkyRMnjLz5yHTIjmVFxoqUDYWIk1o/YW1v04Xi9tgDmpOONwL 9KoDyp/zAfxB3qRnldtppfPGYmbL7YdwTeq9Mp9Zgl+x3nPhMP/5X9eFsqMeDWMC6g6b f6DsriCDmBEDrGOVKeXlONGuZXnMJA1G+W8Uxmjx2yCJoPYpnnzIdQwEKuBWRpG3IVfL rnS+RTUuJ+4MNHPj2xOeeQTRN+xxxPqTGNKWJSuvDUIHppYiwtIYevgqfi0sTtG0LPig Qfhw== 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=rgrAzZUZwjdhZAOBcK/XLdzP90uCuuyLOx0Pcytg8bE=; fh=Ba5oIKrQzZZK0aFMZZddYCisM6cWIkoVxLpeZL8+0TA=; b=Zw8J30pZHbyENXGf3AJHM9dqBI2YZeFKcprtmS5VQwxAreHl6B4EGwB5esoltOy2QF pqkQ5LeWk04K/q61Z3CzeDQBPSiLHsPksDCkwFtFdV/CU0zsrquAN0WoNPUym2omlMuH MQAV3m9OMlUP9fx86SNchPhlYQZd9fol+k1pxuWWggTT543LwP1CehHtZHM2qBeQimOz ht834SR1lrRTubKA7M0aURiAfuKykfUNQZUhBL1ONXV5n1RZVfS3aXaN4mJh2Vx1DNQg ucrLa+e1N9ozJubaDihYImwsfg2/TSVkxjl0LY9Lne3pQ8h1L10O2GfQcPgkVc8f7Lop TgBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWt6uyh5x2VHpo2ZxICREnFjQvWzLkbJ4RrENJFgoE+icxor637DsdK7vj6RATYQjVTMXfLdDTHyq8j3fIvZ26P53qhhA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id e24-20020a631e18000000b005d6a99217dasi1632423pge.403.2024.02.06.04.37.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:38:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54926-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 32D40B285BB for ; Tue, 6 Feb 2024 12:28:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81A83152BF5; Tue, 6 Feb 2024 12:09:42 +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 ADA1D13B792; Tue, 6 Feb 2024 12:09:26 +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=1707221366; cv=none; b=mV/YHiObGIDJE4TOeNC2u3VOiXbtyw4C3hS7AeoakWDBaKcM+v+VUN+oOG33bfNt4FpeDBfm/BAYS4ZTFqCv4dsou3OZPbYR6ZCjqpiXMDWpF9t24fbrIZ3oP411uaIxQ+Uk5w2sItLUPt6Yn/DKIK+gLEp3fThi1zB9FP0m8C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221366; c=relaxed/simple; bh=WKYWs+tozJFf0aESTI4h+kx5amCCXJ1ckyoJFMyYUfI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=sqAJrHS6eBQAiMJnx6P9Dp4qGtmZ60Gp+MFSxqnG3jRwptMEpi10asqFbZVSiIweBungC7KjYM/0u7d1JtB2AOoM7hCVL0TzX5ncsJlStBifF3b4w1AYML0x+8LtlzqXhq+gCeH/Fe5v1FG+R9JvCFlrNrzV9WYrLGR2o7Q+fA4= 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 83C43C43609; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGw-00000006bRL-487S; Tue, 06 Feb 2024 07:09:54 -0500 Message-ID: <20240206120954.845943821@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:57 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 52/57] eventfs: Clean up dentry ops and add revalidate function References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790153148488604574 X-GMAIL-MSGID: 1790153148488604574 From: Linus Torvalds In order for the dentries to stay up-to-date with the eventfs changes, just add a 'd_revalidate' function that checks the 'is_freed' bit. Also, clean up the dentry release to actually use d_release() rather than the slightly odd d_iput() function. We don't care about the inode, all we want to do is to get rid of the refcount to the eventfs data added by dentry->d_fsdata. It would probably be cleaner to make eventfs its own filesystem, or at least set its own dentry ops when looking up eventfs files. But as it is, only eventfs dentries use d_fsdata, so we don't really need to split these things up by use. Another thing that might be worth doing is to make all eventfs lookups mark their dentries as not worth caching. We could do that with d_delete(), but the DCACHE_DONTCACHE flag would likely be even better. As it is, the dentries are all freeable, but they only tend to get freed at memory pressure rather than more proactively. But that's a separate issue. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.124644253@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 8dce06e98c70a7fcbb4bca7d90faf40522e65c58) --- fs/tracefs/event_inode.c | 5 ++--- fs/tracefs/inode.c | 27 ++++++++++++++++++--------- fs/tracefs/internal.h | 3 ++- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 16ca8d9759b1..b2285d5f3fed 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -378,13 +378,12 @@ static void free_ei(struct eventfs_inode *ei) } /** - * eventfs_set_ei_status_free - remove the dentry reference from an eventfs_inode - * @ti: the tracefs_inode of the dentry + * eventfs_d_release - dentry is going away * @dentry: dentry which has the reference to remove. * * Remove the association between a dentry from an eventfs_inode. */ -void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry) +void eventfs_d_release(struct dentry *dentry) { struct eventfs_inode *ei; int i; diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index a24dfa7fcf23..99caf1c3d0c4 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -377,21 +377,30 @@ static const struct super_operations tracefs_super_operations = { .show_options = tracefs_show_options, }; -static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode) +/* + * It would be cleaner if eventfs had its own dentry ops. + * + * Note that d_revalidate is called potentially under RCU, + * so it can't take the eventfs mutex etc. It's fine - if + * we open a file just as it's marked dead, things will + * still work just fine, and just see the old stale case. + */ +static void tracefs_d_release(struct dentry *dentry) { - struct tracefs_inode *ti; + if (dentry->d_fsdata) + eventfs_d_release(dentry); +} - if (!dentry || !inode) - return; +static int tracefs_d_revalidate(struct dentry *dentry, unsigned int flags) +{ + struct eventfs_inode *ei = dentry->d_fsdata; - ti = get_tracefs(inode); - if (ti && ti->flags & TRACEFS_EVENT_INODE) - eventfs_set_ei_status_free(ti, dentry); - iput(inode); + return !(ei && ei->is_freed); } static const struct dentry_operations tracefs_dentry_operations = { - .d_iput = tracefs_dentry_iput, + .d_revalidate = tracefs_d_revalidate, + .d_release = tracefs_d_release, }; static int trace_fill_super(struct super_block *sb, void *data, int silent) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 932733a2696a..4b50a0668055 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -78,6 +78,7 @@ struct dentry *tracefs_start_creating(const char *name, struct dentry *parent); struct dentry *tracefs_end_creating(struct dentry *dentry); struct dentry *tracefs_failed_creating(struct dentry *dentry); struct inode *tracefs_get_inode(struct super_block *sb); -void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry); + +void eventfs_d_release(struct dentry *dentry); #endif /* _TRACEFS_INTERNAL_H */ From patchwork Tue Feb 6 12:09:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1502123dyb; Tue, 6 Feb 2024 04:29:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGYeJzE5I5TkDpDYSRtWrTsfKHtdNb+O/BOxislJNTajqbhfEk1+joPRzGDEstNObU7hu09 X-Received: by 2002:a81:c146:0:b0:604:a09:ea98 with SMTP id e6-20020a81c146000000b006040a09ea98mr1440116ywl.28.1707222540912; Tue, 06 Feb 2024 04:29:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222540; cv=pass; d=google.com; s=arc-20160816; b=0T/F5xeI33XvHkV2qIDixawsn6nFoNMNo8bEB2+Ab5GVN+ojxZbIAtnS3/u4Y5EzBu lxRNDPXgqsppwXYRqaZao4w9H/6Wselay8NjtjC0GsrI450KjL0cl91TM7ggiCi6XfOC BP76jtZRcQj8k9nUlj9fFSwyJ7SF+aiNDSoCGHAPjYoCNilwOBwuTUK4kxu0A+1ui7Qc 8l+NwmcnETfn6VChY8pr+vAFyfgmTRtPERd9D0K3CYIn3tRikxxxsKF86KimOlTzUvyB AHAd2ulk8WKLz1TcBVLNLkXjacKl+GPky1gC+6B5yuekhZl4JcppPQ2Y759dFI2vlsF4 wgWw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=ibplbWfYp5SZrjt6tuasl1pCx5FeUok3G24cS59kGbw=; fh=Q8JfP28HDWuxuPytj+62W37iDxsV0o24OBNA25kFbOE=; b=ECBB3nmatOfXXQWHxtZBCO8OAVXJuEm7eUQpeVFEmO4r52gFy5PHJdowrmwdeo4PVN hQ62LKDJykd4q75JI9zbf+BTkpu4nOAAR6AjirQs9nLi9hUgAUtfa0NwLSG2LkA0kDu+ yn4NySUeDN/OXy5xc/RsBNCFnDgn5hpS2DGldytbdllhQh0BK2N19KX9tdXUzdS5kZYH O2zM3foMQSLq77lTkPGOZeA1Lo8Ox3u7tejW3HwYM+ZZJW1RqHH8xj4AlKS5hG6bxd8U uzXrhKQyo61ywht8GR0n0IGaxgSLP2huDswYgHJvGePVx6YGL+kiX98oXzfVggF0VxXZ 6gtQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54928-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54928-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCUgB8g54OqhNlDTJiQYq3MXrPF3/m9npTjTB4dQAPSXFUnboYOTLYsquSljP7NNeU6mkbfFhBBug6qKlrFI5qZYnXwrjQ== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id o20-20020a05620a229400b00783fb5cf4d6si2107977qkh.614.2024.02.06.04.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:29:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54928-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54928-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54928-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 9DCB81C24447 for ; Tue, 6 Feb 2024 12:29:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6AE6D1534FD; Tue, 6 Feb 2024 12:09:44 +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 076A013B7B8; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=BvD8E+3jHhBmMRX6qE3MIBeQVA4C1BDdaetWjMmGTy2Ck4HEwtImlM3jrBeAHqIb4JI+LI0YKV1WQBBwutgagY6B6X+QWI7iEt2+SKqoMuArJtfBKiThm6butKiWhECwiWKDuH7vKLwvSd2cU29d26rXfiSFfIwDJoXhS67vUhk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=YPpxQFfVye3420wXVrWufA0oagWv//U74Rk3/6Lvtfw=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=TNjwWtwZveY/3levTCrvFR8qO45PKvQCQ7aeO40/iMkeRBYlNyDDPGfilWgpzo5IxEwFmJZG2Yjfszyh+hZs1Lmv+rjEMCLUdr/Z4fKX+mSMXClhB8V52HJ5P+NPYNZT+pIJsGJacZPCm0HZGogUoyTHQ8HAnlRbfKhb8myDS9M= 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 AF5ABC433C7; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bRq-0djP; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.006367557@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:58 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 53/57] eventfs: Get rid of dentry pointers without refcounts References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152583001092040 X-GMAIL-MSGID: 1790152583001092040 From: Linus Torvalds The eventfs inode had pointers to dentries (and child dentries) without actually holding a refcount on said pointer. That is fundamentally broken, and while eventfs tried to then maintain coherence with dentries going away by hooking into the '.d_iput' callback, that doesn't actually work since it's not ordered wrt lookups. There were two reasonms why eventfs tried to keep a pointer to a dentry: - the creation of a 'events' directory would actually have a stable dentry pointer that it created with tracefs_start_creating(). And it needed that dentry when tearing it all down again in eventfs_remove_events_dir(). This use is actually ok, because the special top-level events directory dentries are actually stable, not just a temporary cache of the eventfs data structures. - the 'eventfs_inode' (aka ei) needs to stay around as long as there are dentries that refer to it. It then used these dentry pointers as a replacement for doing reference counting: it would try to make sure that there was only ever one dentry associated with an event_inode, and keep a child dentry array around to see which dentries might still refer to the parent ei. This gets rid of the invalid dentry pointer use, and renames the one valid case to a different name to make it clear that it's not just any random dentry. The magic child dentry array that is kind of a "reverse reference list" is simply replaced by having child dentries take a ref to the ei. As does the directory dentries. That makes the broken use case go away. Link: https://lore.kernel.org/linux-trace-kernel/202401291043.e62e89dc-oliver.sang@intel.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240131185513.280463000@goodmis.org Cc: stable@vger.kernel.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Cc: Greg Kroah-Hartman Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Signed-off-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 43aa6f97c2d03a52c1ddb86768575fc84344bdbb) --- fs/tracefs/event_inode.c | 248 ++++++++++++--------------------------- fs/tracefs/internal.h | 7 +- 2 files changed, 78 insertions(+), 177 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index b2285d5f3fed..515fdace1eea 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -62,6 +62,35 @@ enum { #define EVENTFS_MODE_MASK (EVENTFS_SAVE_MODE - 1) +/* + * eventfs_inode reference count management. + * + * NOTE! We count only references from dentries, in the + * form 'dentry->d_fsdata'. There are also references from + * directory inodes ('ti->private'), but the dentry reference + * count is always a superset of the inode reference count. + */ +static void release_ei(struct kref *ref) +{ + struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + kfree(ei->entry_attrs); + kfree_const(ei->name); + kfree_rcu(ei, rcu); +} + +static inline void put_ei(struct eventfs_inode *ei) +{ + if (ei) + kref_put(&ei->kref, release_ei); +} + +static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei) +{ + if (ei) + kref_get(&ei->kref); + return ei; +} + static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags); @@ -289,7 +318,8 @@ static void update_inode_attr(struct dentry *dentry, struct inode *inode, * directory. The inode.i_private pointer will point to @data in the open() * call. */ -static struct dentry *lookup_file(struct dentry *dentry, +static struct dentry *lookup_file(struct eventfs_inode *parent_ei, + struct dentry *dentry, umode_t mode, struct eventfs_attr *attr, void *data, @@ -302,7 +332,7 @@ static struct dentry *lookup_file(struct dentry *dentry, mode |= S_IFREG; if (WARN_ON_ONCE(!S_ISREG(mode))) - return NULL; + return ERR_PTR(-EIO); inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) @@ -321,9 +351,12 @@ static struct dentry *lookup_file(struct dentry *dentry, ti = get_tracefs(inode); ti->flags |= TRACEFS_EVENT_INODE; + // Files have their parent's ei as their fsdata + dentry->d_fsdata = get_ei(parent_ei); + d_add(dentry, inode); fsnotify_create(dentry->d_parent->d_inode, dentry); - return dentry; + return NULL; }; /** @@ -359,22 +392,29 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, /* Only directories have ti->private set to an ei, not files */ ti->private = ei; - dentry->d_fsdata = ei; - ei->dentry = dentry; // Remove me! + dentry->d_fsdata = get_ei(ei); inc_nlink(inode); d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); - return dentry; + return NULL; } -static void free_ei(struct eventfs_inode *ei) +static inline struct eventfs_inode *alloc_ei(const char *name) { - kfree_const(ei->name); - kfree(ei->d_children); - kfree(ei->entry_attrs); - kfree(ei); + struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL); + + if (!ei) + return NULL; + + ei->name = kstrdup_const(name, GFP_KERNEL); + if (!ei->name) { + kfree(ei); + return NULL; + } + kref_init(&ei->kref); + return ei; } /** @@ -385,39 +425,13 @@ static void free_ei(struct eventfs_inode *ei) */ void eventfs_d_release(struct dentry *dentry) { - struct eventfs_inode *ei; - int i; - - mutex_lock(&eventfs_mutex); - - ei = dentry->d_fsdata; - if (!ei) - goto out; - - /* This could belong to one of the files of the ei */ - if (ei->dentry != dentry) { - for (i = 0; i < ei->nr_entries; i++) { - if (ei->d_children[i] == dentry) - break; - } - if (WARN_ON_ONCE(i == ei->nr_entries)) - goto out; - ei->d_children[i] = NULL; - } else if (ei->is_freed) { - free_ei(ei); - } else { - ei->dentry = NULL; - } - - dentry->d_fsdata = NULL; - out: - mutex_unlock(&eventfs_mutex); + put_ei(dentry->d_fsdata); } /** * lookup_file_dentry - create a dentry for a file of an eventfs_inode * @ei: the eventfs_inode that the file will be created under - * @idx: the index into the d_children[] of the @ei + * @idx: the index into the entry_attrs[] of the @ei * @parent: The parent dentry of the created file. * @name: The name of the file to create * @mode: The mode of the file. @@ -434,17 +448,11 @@ lookup_file_dentry(struct dentry *dentry, const struct file_operations *fops) { struct eventfs_attr *attr = NULL; - struct dentry **e_dentry = &ei->d_children[idx]; if (ei->entry_attrs) attr = &ei->entry_attrs[idx]; - dentry->d_fsdata = ei; // NOTE: ei of _parent_ - lookup_file(dentry, mode, attr, data, fops); - - *e_dentry = dentry; // Remove me - - return dentry; + return lookup_file(ei, dentry, mode, attr, data, fops); } /** @@ -465,6 +473,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct tracefs_inode *ti; struct eventfs_inode *ei; const char *name = dentry->d_name.name; + struct dentry *result = NULL; ti = get_tracefs(dir); if (!(ti->flags & TRACEFS_EVENT_INODE)) @@ -481,7 +490,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, continue; if (ei_child->is_freed) goto out; - lookup_dir_entry(dentry, ei, ei_child); + result = lookup_dir_entry(dentry, ei, ei_child); goto out; } @@ -498,12 +507,12 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, if (entry->callback(name, &mode, &data, &fops) <= 0) goto out; - lookup_file_dentry(dentry, ei, i, mode, data, fops); + result = lookup_file_dentry(dentry, ei, i, mode, data, fops); goto out; } out: mutex_unlock(&eventfs_mutex); - return NULL; + return result; } /* @@ -653,25 +662,10 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode if (!parent) return ERR_PTR(-EINVAL); - ei = kzalloc(sizeof(*ei), GFP_KERNEL); + ei = alloc_ei(name); if (!ei) return ERR_PTR(-ENOMEM); - ei->name = kstrdup_const(name, GFP_KERNEL); - if (!ei->name) { - kfree(ei); - return ERR_PTR(-ENOMEM); - } - - if (size) { - ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); - if (!ei->d_children) { - kfree_const(ei->name); - kfree(ei); - return ERR_PTR(-ENOMEM); - } - } - ei->entries = entries; ei->nr_entries = size; ei->data = data; @@ -685,7 +679,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode /* Was the parent freed? */ if (list_empty(&ei->list)) { - free_ei(ei); + put_ei(ei); ei = NULL; } return ei; @@ -720,28 +714,20 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry if (IS_ERR(dentry)) return ERR_CAST(dentry); - ei = kzalloc(sizeof(*ei), GFP_KERNEL); + ei = alloc_ei(name); if (!ei) - goto fail_ei; + goto fail; inode = tracefs_get_inode(dentry->d_sb); if (unlikely(!inode)) goto fail; - if (size) { - ei->d_children = kcalloc(size, sizeof(*ei->d_children), GFP_KERNEL); - if (!ei->d_children) - goto fail; - } - - ei->dentry = dentry; + // Note: we have a ref to the dentry from tracefs_start_creating() + ei->events_dir = dentry; ei->entries = entries; ei->nr_entries = size; ei->is_events = 1; ei->data = data; - ei->name = kstrdup_const(name, GFP_KERNEL); - if (!ei->name) - goto fail; /* Save the ownership of this directory */ uid = d_inode(dentry->d_parent)->i_uid; @@ -772,7 +758,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry inode->i_op = &eventfs_root_dir_inode_operations; inode->i_fop = &eventfs_file_operations; - dentry->d_fsdata = ei; + dentry->d_fsdata = get_ei(ei); /* directory inodes start off with i_nlink == 2 (for "." entry) */ inc_nlink(inode); @@ -784,72 +770,11 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ei; fail: - kfree(ei->d_children); - kfree(ei); - fail_ei: + put_ei(ei); tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } -static LLIST_HEAD(free_list); - -static void eventfs_workfn(struct work_struct *work) -{ - struct eventfs_inode *ei, *tmp; - struct llist_node *llnode; - - llnode = llist_del_all(&free_list); - llist_for_each_entry_safe(ei, tmp, llnode, llist) { - /* This dput() matches the dget() from unhook_dentry() */ - for (int i = 0; i < ei->nr_entries; i++) { - if (ei->d_children[i]) - dput(ei->d_children[i]); - } - /* This should only get here if it had a dentry */ - if (!WARN_ON_ONCE(!ei->dentry)) - dput(ei->dentry); - } -} - -static DECLARE_WORK(eventfs_work, eventfs_workfn); - -static void free_rcu_ei(struct rcu_head *head) -{ - struct eventfs_inode *ei = container_of(head, struct eventfs_inode, rcu); - - if (ei->dentry) { - /* Do not free the ei until all references of dentry are gone */ - if (llist_add(&ei->llist, &free_list)) - queue_work(system_unbound_wq, &eventfs_work); - return; - } - - /* If the ei doesn't have a dentry, neither should its children */ - for (int i = 0; i < ei->nr_entries; i++) { - WARN_ON_ONCE(ei->d_children[i]); - } - - free_ei(ei); -} - -static void unhook_dentry(struct dentry *dentry) -{ - if (!dentry) - return; - /* - * Need to add a reference to the dentry that is expected by - * simple_recursive_removal(), which will include a dput(). - */ - dget(dentry); - - /* - * Also add a reference for the dput() in eventfs_workfn(). - * That is required as that dput() will free the ei after - * the SRCU grace period is over. - */ - dget(dentry); -} - /** * eventfs_remove_rec - remove eventfs dir or file from list * @ei: eventfs_inode to be removed. @@ -862,8 +787,6 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) { struct eventfs_inode *ei_child; - if (!ei) - return; /* * Check recursion depth. It should never be greater than 3: * 0 - events/ @@ -875,28 +798,12 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) return; /* search for nested folders or files */ - list_for_each_entry_srcu(ei_child, &ei->children, list, - lockdep_is_held(&eventfs_mutex)) { - /* Children only have dentry if parent does */ - WARN_ON_ONCE(ei_child->dentry && !ei->dentry); + list_for_each_entry(ei_child, &ei->children, list) eventfs_remove_rec(ei_child, level + 1); - } - ei->is_freed = 1; - - for (int i = 0; i < ei->nr_entries; i++) { - if (ei->d_children[i]) { - /* Children only have dentry if parent does */ - WARN_ON_ONCE(!ei->dentry); - unhook_dentry(ei->d_children[i]); - } - } - - unhook_dentry(ei->dentry); - - list_del_rcu(&ei->list); - call_srcu(&eventfs_srcu, &ei->rcu, free_rcu_ei); + list_del(&ei->list); + put_ei(ei); } /** @@ -907,22 +814,12 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) */ void eventfs_remove_dir(struct eventfs_inode *ei) { - struct dentry *dentry; - if (!ei) return; mutex_lock(&eventfs_mutex); - dentry = ei->dentry; eventfs_remove_rec(ei, 0); mutex_unlock(&eventfs_mutex); - - /* - * If any of the ei children has a dentry, then the ei itself - * must have a dentry. - */ - if (dentry) - simple_recursive_removal(dentry, NULL); } /** @@ -935,7 +832,11 @@ void eventfs_remove_events_dir(struct eventfs_inode *ei) { struct dentry *dentry; - dentry = ei->dentry; + dentry = ei->events_dir; + if (!dentry) + return; + + ei->events_dir = NULL; eventfs_remove_dir(ei); /* @@ -945,5 +846,6 @@ void eventfs_remove_events_dir(struct eventfs_inode *ei) * sticks around while the other ei->dentry are created * and destroyed dynamically. */ + d_invalidate(dentry); dput(dentry); } diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 4b50a0668055..1886f1826cd8 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -35,8 +35,7 @@ struct eventfs_attr { * @entries: the array of entries representing the files in the directory * @name: the name of the directory to create * @children: link list into the child eventfs_inode - * @dentry: the dentry of the directory - * @d_children: The array of dentries to represent the files when created + * @events_dir: the dentry of the events directory * @entry_attrs: Saved mode and ownership of the @d_children * @attr: Saved mode and ownership of eventfs_inode itself * @data: The private data to pass to the callbacks @@ -45,12 +44,12 @@ struct eventfs_attr { * @nr_entries: The number of items in @entries */ struct eventfs_inode { + struct kref kref; struct list_head list; const struct eventfs_entry *entries; const char *name; struct list_head children; - struct dentry *dentry; /* Check is_freed to access */ - struct dentry **d_children; + struct dentry *events_dir; struct eventfs_attr *entry_attrs; struct eventfs_attr attr; void *data; From patchwork Tue Feb 6 12:09:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501885dyb; Tue, 6 Feb 2024 04:28:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNzj8FMlGFbfg9ExBTKE3KuEgUINZmqXYLkMtgGK2Q9a7afaoWhliEQLYrXA3WJhZ3rcGq X-Received: by 2002:a05:6870:2181:b0:210:96cf:b552 with SMTP id l1-20020a056870218100b0021096cfb552mr2947772oae.23.1707222512781; Tue, 06 Feb 2024 04:28:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222512; cv=pass; d=google.com; s=arc-20160816; b=vqncKZOW8AgzMR4G2q0UUT+weJ1A5pDijEFnrbFHzuXIDXFqHfLNB0gQMwdy2rsoms n8xDWmt31e0Jb3XJsWFreUogPQ4qURHF4TA64e5iQ5UNvHmneKYlVUJklpEIjM1MfMkD yhyoyQtF9X6xmzsXOOe8AcZDjBvqhm4FSZvulyVn2GGSo8y5YZS6sjfLZKLJjoU3ELd+ sd88mas+9sH8I9L+MxvTPa6p4/l9TzjL2fomtC8QnrKjKtxURHu51f6hdPI0truJXLAj rDGo3fDRj+tX5LXC4zKi8mTwBQWHMocwoqKXMXdPiKCKjTKR1i26A0orAVlPPWChGWYa AjhQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Es1r5HTFTxAVE2/80lM01ZTjBkU6nxyuvtLC74Fluw4=; fh=jKDkXlawu1eDdlwexUANHmD4caMCzxPQaBQE8EpSNLI=; b=dLPJPBPl9tFTxt+HEnUoSYnrhjU+G3P0wjp2+bxRQGEfbvwmcIvdt4JxvQbQTJ+NTu fkyh4p4Uq3z2KopPPAP2MRkFqyYNzKQrXfx8ZYjH5j5H36S+2+2MvzXL+aBTV1Tl1HUf y8XABtUWHnIW+fRrW77cm7LkPz46EtbdYiB0RCbV6K/DmhsWCH6UWxo80X+Ck8brR5sS LBBIdG9xLOpMBIXzRaX6XUCjavwKEijn2AkPaD/AiI5vJbfg4T77W5bIKPnTaNfkjrg0 LEzSnudhOlrZrlAlm+/YIeLYopCfiodk/KElT+iV5YY7rh4yt+7fvpKFI0AVghOOuxOK NILg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54929-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54929-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVSI+KKv+0vyZ1uAzOysuiK1BiQL1FCs/OcRIrqJw9rxLyaxGFM555cpf68Xk72+u/cW++RVAkwwa18Yecwil8cH/4G2Q== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f7-20020ac85d07000000b0042bf8e02246si2247240qtx.614.2024.02.06.04.28.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54929-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-54929-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54929-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 80ECE1C24341 for ; Tue, 6 Feb 2024 12:28:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8167152C10; Tue, 6 Feb 2024 12:09:42 +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 0F19613BE82; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=madVwKdpydAolG+Hk4HHDzQjFbMnAZHzdKbz0V47OKeN+iG1uMICistydMskwJxW2gdskAhdHjwzdGj4J9mxyw8I8cCG2BypSUmS5vCrWRAzmoLnY3ivc5C4tqpkuZkbe7Myv1XVyMrQuMN+YAEyOwKRLwt5Yn4wrZCSQsw6e6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=TqvI80mt2ZF0Gnam5nEwnKCPn9ZXmcExO8VO54BJ8Dg=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=e66sEhClnVpO7/FtNIgYch6DT/ROVjWLF2fb4UsZ5m3zIIO0osSt8gZW22LNEMR1UurEpLlrtUXUfQPAA6gIUGY1VQ5pghvqvHfMummGG9dvTAHeAAzRBYAI4lk7tTQfs5+xJEFHt3iqlkaZzIS2LyTJEklP5Mmgyd/vB4y0wyk= 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 D6ADAC43394; Tue, 6 Feb 2024 12:09:26 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bSL-1Jh7; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.173872948@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:59 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 54/57] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152553833528065 X-GMAIL-MSGID: 1790152553833528065 From: "Steven Rostedt (Google)" There should never be a case where an evenfs_inode is being freed without is_freed being set. Add a WARN_ON_ONCE() if it ever happens. That would mean there was one too many put_ei()s. Link: https://lore.kernel.org/linux-trace-kernel/20240201161616.843551963@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 5a49f996046ba947466bc7461e4b19c4d1daf978) --- fs/tracefs/event_inode.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 515fdace1eea..ca7daee7c811 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -73,6 +73,9 @@ enum { static void release_ei(struct kref *ref) { struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + + WARN_ON_ONCE(!ei->is_freed); + kfree(ei->entry_attrs); kfree_const(ei->name); kfree_rcu(ei, rcu); @@ -84,6 +87,14 @@ static inline void put_ei(struct eventfs_inode *ei) kref_put(&ei->kref, release_ei); } +static inline void free_ei(struct eventfs_inode *ei) +{ + if (ei) { + ei->is_freed = 1; + put_ei(ei); + } +} + static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei) { if (ei) @@ -679,7 +690,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode /* Was the parent freed? */ if (list_empty(&ei->list)) { - put_ei(ei); + free_ei(ei); ei = NULL; } return ei; @@ -770,7 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ei; fail: - put_ei(ei); + free_ei(ei); tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } @@ -801,9 +812,8 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) list_for_each_entry(ei_child, &ei->children, list) eventfs_remove_rec(ei_child, level + 1); - ei->is_freed = 1; list_del(&ei->list); - put_ei(ei); + free_ei(ei); } /** From patchwork Tue Feb 6 12:10:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1502092dyb; Tue, 6 Feb 2024 04:28:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHFWT6CKxZUMqDM+Vbqvy2Jh1e2RakHB+u9c92aV5iHAslzR/o81ua5w2WdNJjlJRjCEDzo X-Received: by 2002:a17:906:3ad9:b0:a37:478a:929b with SMTP id z25-20020a1709063ad900b00a37478a929bmr1511701ejd.8.1707222536429; Tue, 06 Feb 2024 04:28:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222536; cv=pass; d=google.com; s=arc-20160816; b=JGH1PjHJF5DDMsXxEfHdXONit4hYQkTM4V/BlUcgTNCp19COuRVfHZBeysczFRAe3g Kw2xJ9iyx+Y5iESbOjnax13zAy+eRxdtHpm4xu/EBpGDtM9bEtZOQoeXHG7GJPsjYvfr M9gSpjd55yffdLMeSuBi9yENnBgVNFmoG5wG4O7TYzr920Bl+SHYpJvoZjLNCJs5XW1a pGUd5hHReU2/tUpwcErTXaoKeu5hxbp6lb4of2wDmCaaJH325aGU09f7mwMxgxxMKMR/ PoRGahM0czmRR3AoVAjlg2r0OT/jZBZcny92SF95Zj9jo7q/u0dOnGhp9OLkFdKUGQlT hmrg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=yQvYu4PlEpv1rOx1zrXjk3aBdiBZnT+MjoFuOI8rBCM=; fh=fi4gwqOVN/O8XiaqR51qoZHTPe73FS9RXefVlSn0v0E=; b=ErMo6snbxdMvU9Ekpr69oF+M1NBGLs7Yk4wpBERegPVeqR/93FHUoiqL4z38xoRHHR 9jH5u492cI011ySvhy7Oe/jMLClRMK+Ka3tH9QHjOeayfs3tyc+z/SPJAY7aOQZZy+cl 3uY4ycu6U5cdsGgXWy7k8HB/RlJYVdzSWrfqA/+ssakPOAvpbmq6SGXvryD3lgiFixNr SE4kPnkhEanyq5lwJ7LRFsUvm1kDEV8KKcC6hLNDrFJ1i9P3nRn+fBY96tTlyoZXtCHG k/jlQg5h9pMRQF/d+CJv4gvq4VjGVLlgbpT0T7feTJcTg4VDGDCd0lRftggxhPbAh9NR 0iYg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54932-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54932-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVSsvayFBuYX+0jkzWYUG57K42j8Oodwk5YabROLZFxwhIi/+SuguYk2E+2z2zahLRfGKLJGleW6kZbf6ZTRaToTVcB3A== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d15-20020a17090648cf00b00a3549e68608si982185ejt.664.2024.02.06.04.28.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54932-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-54932-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54932-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 0AE791F2341E for ; Tue, 6 Feb 2024 12:28:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 07C69152E1F; Tue, 6 Feb 2024 12:09:44 +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 990B913C1CB; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=IU8Ae4sisJwWOg1W9b0ri4pi7j/bLs5QjX/1zqQZKp/uOA6dHZYHOV/44UY4TZ6VlTCZK5aQCK3srFQXDmoIPZcvEC9V9TQR67Yg2IRsAv3M25HN0YKFVi/mt9yQPWoJyaXs9x4vaDPTEqJ0njI8XIiPF1DS1qSjiCGfIy3fUzg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=ovB9zqm93FTVxxBECSNPxdclrmbXtlerbnuNH1s24zo=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=dP0bV3VisWN6AcdQS757tjpt+GNZ8J7Zpy0sjJysZk/gCMmQD0QsiFeiodTbHyvXZw8RXm4KZZbBUx7JIZVH0X+7agN2dBhZvgjeUscSHnYZP13bVo28Cerbgr9E9EGv3oik68eO4vdnWT1pX8zIPBabuQMOoiDkwtbDsnkZm2s= 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 0DD28C43601; Tue, 6 Feb 2024 12:09:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bSq-20U5; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.335266477@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:10:00 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [v6.6][PATCH 55/57] eventfs: Restructure eventfs_inode structure to be more condensed References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152578329903789 X-GMAIL-MSGID: 1790152578329903789 From: "Steven Rostedt (Google)" Some of the eventfs_inode structure has holes in it. Rework the structure to be a bit more condensed, and also remove the no longer used llist field. Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.002321438@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 264424dfdd5cbd92bc5b5ddf93944929fc877fac) --- fs/tracefs/internal.h | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index 1886f1826cd8..beb3dcd0e434 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -32,40 +32,37 @@ struct eventfs_attr { /* * struct eventfs_inode - hold the properties of the eventfs directories. * @list: link list into the parent directory + * @rcu: Union with @list for freeing + * @children: link list into the child eventfs_inode * @entries: the array of entries representing the files in the directory * @name: the name of the directory to create - * @children: link list into the child eventfs_inode * @events_dir: the dentry of the events directory * @entry_attrs: Saved mode and ownership of the @d_children - * @attr: Saved mode and ownership of eventfs_inode itself * @data: The private data to pass to the callbacks + * @attr: Saved mode and ownership of eventfs_inode itself * @is_freed: Flag set if the eventfs is on its way to be freed * Note if is_freed is set, then dentry is corrupted. + * @is_events: Flag set for only the top level "events" directory * @nr_entries: The number of items in @entries + * @ino: The saved inode number */ struct eventfs_inode { - struct kref kref; - struct list_head list; + union { + struct list_head list; + struct rcu_head rcu; + }; + struct list_head children; const struct eventfs_entry *entries; const char *name; - struct list_head children; struct dentry *events_dir; struct eventfs_attr *entry_attrs; - struct eventfs_attr attr; void *data; + struct eventfs_attr attr; + struct kref kref; unsigned int is_freed:1; unsigned int is_events:1; unsigned int nr_entries:30; unsigned int ino; - /* - * Union - used for deletion - * @llist: for calling dput() if needed after RCU - * @rcu: eventfs_inode to delete in RCU - */ - union { - struct llist_node llist; - struct rcu_head rcu; - }; }; static inline struct tracefs_inode *get_tracefs(const struct inode *inode) From patchwork Tue Feb 6 12:10: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: 197422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1501953dyb; Tue, 6 Feb 2024 04:28:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGUB0t1JGXKHrpbWO+I0+39UHftMpM7WBn00DW9A/MT79eJVHICQvZXg0wvnFp5gSKESHkO X-Received: by 2002:a17:906:35d6:b0:a35:7191:d952 with SMTP id p22-20020a17090635d600b00a357191d952mr1641206ejb.53.1707222520110; Tue, 06 Feb 2024 04:28:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222520; cv=pass; d=google.com; s=arc-20160816; b=W4gCtM1B7jqRY3Ab2Wk2dqVNqrkn6Q8acgThYNCaq1+/HsnH6JsYFMVvsD1xFJwd20 KmfOocPihSrDkFO8NaL19wd9cVwuJsNgr7ckq32e6deDnLREcm4wqzBxL8R0/zminP7T S1vH6xueKOQOU7HiNResPCFlQ1ri5t3W3Fh5aeq4L98n15/9b5LAYpcNe121y5mMz5Ow h0oY8v9jBXkl7LCe09yNl5SQ2UAEW2vdGDuyrggqr7kdaXy2qEenl9TsOC77nOWOkj5A Hi9Mj5i9wvCKsjATXwXkGIPsC3a2YO3h+EyMnBkmFJy1qefTrSx3aX3myzqsGqS06pxC Ii6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=//znUvdDCjBcws5msj92W0S44vVgjzgRljeV2BJnUc4=; fh=gThGqSUruJbY6z60+wplBbDwf7HqKD8P/S69vjrZ7gI=; b=JD+OqP6s3HQjHIQvSWia0UClC2ALcBlLP9BGaZY6rWM92zhl1JwtIdQX1bG3YtpYBn OF5+7JV71vhc7yzOzks+S1lz3jXeRF9eATLTcDcm8WmTmiZkJ4VfSZvQRPMusvhJQDQu XKWSJpurk9QiI5y0HDkheTNYAZh+6yGDFPL+elqUVFX8LxdbOXt2KGDM1JTKhwyZ2qbn HLROyoU92M1fFjblTBC79+RellXKhaEnGJxMSvOPSdKMyY2iIr6uSRE9Heal4SfTXVKy 4Ruh3IY+zK8swDSPFY0Va2HxEpfhnvPU7Gkajs6A9F5HQ02e0l1KyrlTxTRvgHqwnrpF 6QBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54930-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54930-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX97PXXGEnPTB74ePhg00h93m2JyumMMYzAeJPfHTyjFgXunpW2wQ7g79Qz9rGa0YKQklHnpVM0cx3rGhHJd0FZuFpo/w== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id rs7-20020a170907036700b00a3633ac23b9si1030599ejb.550.2024.02.06.04.28.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54930-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-54930-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54930-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 B49B91F245CA for ; Tue, 6 Feb 2024 12:28:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 26159152C1E; Tue, 6 Feb 2024 12:09:43 +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 4A94B13BEA8; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=iDedLZV81DB0aW4gB97tnVwrNINqAd2iy1h7ZdYAIS13AhH8nWrh4Ebty+1gHc5/ou12aK54oHxxwVJ4VOORc/G07hmbEbgUICQ6PPyhVdB8OZZzuRJFAx+ID0YtdYwMjmFaggA+xy1CQBUBN6OJd6EaInD19FS+WhtKYlmWU5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=5yqaMUzsL24Xo1kXlS9YCQkGhNmG85TgGVOtLxrgq1g=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=Zww4dqfKknUfiTMIry+SARhCEVqPEwGS08GrtuJX0dUpcBL8GihkBr+BebVe+7/MrOfbCUJOlMBiNATcA35UHWGDWXVsSYtpsmKk4kMCakdy1CBSBRPz3tX2QJu7B/5vxFpjG7G84ac3ln8U4SkvsjZqfvt0zIW0oRZFwxr6iyI= 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 32E20C43390; Tue, 6 Feb 2024 12:09:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bTL-2hfg; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.500466790@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:10:01 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.6][PATCH 56/57] eventfs: Remove fsnotify*() functions from lookup() References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152561125695146 X-GMAIL-MSGID: 1790152561125695146 From: "Steven Rostedt (Google)" The dentries and inodes are created when referenced in the lookup code. There's no reason to call fsnotify_*() functions when they are created by a reference. It doesn't make any sense. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.166973329@goodmis.org Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: a376007917776 ("eventfs: Implement functions to create files and dirs when accessed"); Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) (cherry picked from commit 12d823b31fadf47c8f36ecada7abac5f903cac33) --- fs/tracefs/event_inode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index ca7daee7c811..9e031e5a2713 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -366,7 +366,6 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei, dentry->d_fsdata = get_ei(parent_ei); d_add(dentry, inode); - fsnotify_create(dentry->d_parent->d_inode, dentry); return NULL; }; @@ -408,7 +407,6 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, inc_nlink(inode); d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); - fsnotify_mkdir(dentry->d_parent->d_inode, dentry); return NULL; } From patchwork Tue Feb 6 12:10:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197424 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1502029dyb; Tue, 6 Feb 2024 04:28:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFMGjY6NXl7TiR1rsRgLOzW84MHSJtbMqSSYCLeMdVKYVoJdfcT+2S3JpvlLMVy56kgoC99 X-Received: by 2002:a05:6214:5096:b0:68c:66d4:374e with SMTP id kk22-20020a056214509600b0068c66d4374emr2813460qvb.48.1707222529140; Tue, 06 Feb 2024 04:28:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222529; cv=pass; d=google.com; s=arc-20160816; b=P2RIwj2E7OW+vcof/jPg3CriZ54PCnmHJGGFcbEZc3s0lrFzc0HfS5pw9LvQX0KV2l HyEUEIxIZvRrxnzOQLSPOs4UgH/oC0ETBPmFmxWJwJE4ii3QtO0H3yge2A5ZTuNNxbQ8 qCgIM0GGy/XDs9S4JOL/nUPNAVu4yOW6zQObGRngg+FEimREl7CGvOR8+FyDRu4SXtJ9 AMXQHUc8KaHW3GhkOnjmVknZNvT1231S67u0Yk97ITB62SsNbEQ86IGor09ufHh/ywUP LskQxW/fd/+Qih1uyuTOfJ4Ac9zCP8nK9/+TUrWfSZAcOUVdbKHwoCnxmWnb8E+/wf4b 4hhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=3rg9wT42s0qbZ5O6GIg3gk9NLZhbRpGnQkxTjHAIRpw=; fh=STVGsk3UzsxWDN/vxsRZwcaGBEAOiygLkiqOdSdRYv4=; b=Cs+/qPUy/RYLaa3tm6AEa8rypiPHyTFVBp6RO8Q6n8HgZs48LN8A9BpklsNEDOG3R3 Bm4ZhAlJUGb/Govu9uiaHh6pUQ3mW4EDAj/kW6l0XdeIuzEvwy7lDAEXeAw0OfED6A4N 9VmpEXUy2FN95d1db3WJsFjk3ltgP6Oa76amXIoZ1sN+RCyMQP2Mj0DVSBtDr1umkcGZ ZBEF20LxksqczKjLZr8M4i7/L6ZXXPIuhkZDxkJeBUry/Po8xSM8CRTRUF2nqF6jYO/l ZLukOu6OXQqROeltC3U/27ctML6s9PU2vhJCemGAsqOP1chWxr6d0AFGpVKUi5SIMp6G FYlw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54931-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWbzIUhhTRMhZEAoh76rh15KdX7yroGL2T4S8FC0uGi/Wyp6aGqNyTVLlIJBjpf/WiEiEfNOpb9SU5zj2x2dlgIPEm0nw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id j5-20020a05620a0a4500b007858da6db88si1380477qka.741.2024.02.06.04.28.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:28:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54931-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54931-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 BE3B01C243EF for ; Tue, 6 Feb 2024 12:28:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 72FB4152E02; Tue, 6 Feb 2024 12:09:43 +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 6531F1353F6; Tue, 6 Feb 2024 12:09:27 +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=1707221367; cv=none; b=soyWUGiiqs46RukQ4Po+1fluBQRbtz15mVeq7RjJAFTNURX8MOg+cw3kHYamAsSev2ww0uvgkLVaX+dCGvH3SNJHNEmiWR6VeoJHJjPUqvn7skkHT9M9janw00ExNCl7PnsNplBqbAsEdtxL8lIg1EMKERVKbu2BfQ9W6cj8OAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221367; c=relaxed/simple; bh=K0Ph34GY80unDV6Wcvz0AavqMJytP5uSNCEE07y3Q00=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=vCmHioN24qOTIxnFGZPSjyWnAXfZ4rW9jaErtt49iJDlLZtLiGMegAz65nefRlxcSJZT5O3BABvtVV6MBbIYGNdr15Lh/ZOd3CdLMkar0v1H4FTEWa/fnX8hnKprAF4DMQbSh2wmS2Tyx8UCHgB/NMMsId1SKzRDzIwQ5JSZoOM= 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 50B13C433A6; Tue, 6 Feb 2024 12:09:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGx-00000006bTp-3PR9; Tue, 06 Feb 2024 07:09:55 -0500 Message-ID: <20240206120955.665411833@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:10:02 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [v6.6][PATCH 57/57] eventfs: Keep all directory links at 1 References: <20240206120905.570408983@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790152570820108981 X-GMAIL-MSGID: 1790152570820108981 From: "Steven Rostedt (Google)" The directory link count in eventfs was somewhat bogus. It was only being updated when a directory child was being looked up and not on creation. One solution would be to update in get_attr() the link count by iterating the ei->children list and then adding 2. But that could slow down simple stat() calls, especially if it's done on all directories in eventfs. Another solution would be to add a parent pointer to the eventfs_inode and keep track of the number of sub directories it has on creation. But this adds overhead for something not really worthwhile. The solution decided upon is to keep all directory links in eventfs as 1. This tells user space not to rely on the hard links of directories. Which in this case it shouldn't. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Link: https://lore.kernel.org/linux-trace-kernel/20240201161617.339968298@goodmis.org Cc: stable@vger.kernel.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) (cherry picked from commit ca185770db914869ff9fe773bac5e0e5e4165b83) --- fs/tracefs/event_inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9e031e5a2713..110e8a272189 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -404,9 +404,7 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, dentry->d_fsdata = get_ei(ei); - inc_nlink(inode); d_add(dentry, inode); - inc_nlink(dentry->d_parent->d_inode); return NULL; } @@ -769,9 +767,17 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry dentry->d_fsdata = get_ei(ei); - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); + /* + * Keep all eventfs directories with i_nlink == 1. + * Due to the dynamic nature of the dentry creations and not + * wanting to add a pointer to the parent eventfs_inode in the + * eventfs_inode structure, keeping the i_nlink in sync with the + * number of directories would cause too much complexity for + * something not worth much. Keeping directory links at 1 + * tells userspace not to trust the link number. + */ d_instantiate(dentry, inode); + /* The dentry of the "events" parent does keep track though */ inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); tracefs_end_creating(dentry);