From patchwork Thu Feb 1 15:34: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: 195390 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp270148dyb; Thu, 1 Feb 2024 08:20:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IGn8/awOEmuGkoNFqaO+lPDIe43nOCxP6S77JAo31J1XVihBTCdBf+6aYY+eVXQAFuKqFCk X-Received: by 2002:a05:6402:34c3:b0:55f:301b:14cd with SMTP id w3-20020a05640234c300b0055f301b14cdmr3307371edc.25.1706804458327; Thu, 01 Feb 2024 08:20:58 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706804458; cv=pass; d=google.com; s=arc-20160816; b=qzkgVO/W5vINV+pI0S3tF0tpNe+1Gb3NStzPo8ypzxZQli5qoVczIjqeX2QFZtKPlA haG6/LsJGmP8cnI9aMp0HrGMDS1h8WrdG1O20l2BqYZ+otFYALf10XNlwlYZCakvS4xq xpz68ZkGTRFN+vRV9Qvlbhf1UebwoX0zVdOMi+vuYiAPYsr/dKmNMpmLG2/xfQVxZcn1 r0CT2ZXhU4VhrH6v/utyBu2JICQs8vTkNnTtgi2aoXebM/GgO9+A+Not1CWc8O1fmCqt bOKfLXLSeW+yJLN5ukLJ4TIlzosZ9t2+m0SxREd08YjL76n0qhwqVfF8hcm5Xh1e360e x/CA== 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=KXAqDTnlm0DO1DdjCTEjqXM6jS6xVsGTaBngp6Vll60=; fh=nuYD5cJW25J1JOUSVVd7gStSleJak9e/0Hp0y2oPHcQ=; b=uEa+r3FGd2qaZHVuVyxvtQo2PgwstXUP1q6Y9iB019bosLNf9UXCjQEh3uEqWL0xJc kq92/tSmteRnv1m3va8B0oXgbDsfWirTxhxURtMeB4/XjBRFIMMhEF1jLTZ6euEN+4A4 H9e37inSnfNIr9cGXG5gcGCb3aL9NpfOMibA3auAlWq0l4HEvl9yqt/su/eNBHAB+ZcH KKFvz6eokWE4ZlkPW9N/rAcEnyLh5uxMi5XU5bV7MMX5OQv0TX3Qp/j9L2qZqzXOiPNF Udonz7rmQed/4Xwz4+Z9QlXIcE5gVCGFUsTLaEQ9SpTN3mydWwT3MgppWTVQflNhgpvk Fj9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48503-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48503-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCVh/mMBfJG6VkvUFTbCU6Uk7Ca8eGKhA7+ZtxzU+SViZnFTHm/eK3b2SUZBjTAUbj7sDRsUTzSUvITUa2Sc00MB3Zoc8g== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id fj16-20020a0564022b9000b0055a3abbbfaesi7010887edb.323.2024.02.01.08.20.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 08:20:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48503-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-48503-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48503-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 EB0581F2296A for ; Thu, 1 Feb 2024 16:20:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AD2F15D5C6; Thu, 1 Feb 2024 16:16:02 +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 A6F29160895; Thu, 1 Feb 2024 16:16:00 +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=1706804160; cv=none; b=S0JyU8S9o6z6tPLawayfje7KS9T8ZDoEekuyrq1mlON/7bmTUdT59N7Xvda+IkbcMFaq0H3UwbbzWRwZm1pQxRRrP6GShoDLEQnUqMYeqdf9k/Uc6qx+ZVBlKsN8rpcRIoQmDftff2xOZhkBE5v1IaQz935c2Ed1VZtyWQ4mm0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=lNtIhhFDOlXg3opQxPWZoYHwa0F4HyqlbB3ETO/rgP4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aBEJMUw4SW44XD7MVs2b6xj4GJUq4mL+NiGGs6jimyT1mJBEXwTLCNmwj2jm+SbbqX4wuBXbY4mWAiF2jENI2l5ekdKYenxSck7bwCTNQpwGqZcQEYtupiwKF5FcuGWWbt51y4LvXNTqpWkg7Xtz8IGBHzC9J34/kq5M3HvnhHs= 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 4B97EC43390; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005Tji-1JJ6; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.166973329@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:49 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , stable@vger.kernel.org, Al Viro Subject: [PATCH 3/6] eventfs: Remove fsnotify*() functions from lookup() References: <20240201153446.138990674@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789714191778415647 X-GMAIL-MSGID: 1789714191778415647 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/ Cc: stable@vger.kernel.org Fixes: a376007917776 ("eventfs: Implement functions to create files and dirs when accessed"); Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index ca7daee7c811..9e031e5a2713 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -366,7 +366,6 @@ static struct dentry *lookup_file(struct eventfs_inode *parent_ei, dentry->d_fsdata = get_ei(parent_ei); d_add(dentry, inode); - fsnotify_create(dentry->d_parent->d_inode, dentry); return NULL; }; @@ -408,7 +407,6 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, inc_nlink(inode); d_add(dentry, inode); inc_nlink(dentry->d_parent->d_inode); - fsnotify_mkdir(dentry->d_parent->d_inode, dentry); return NULL; } From patchwork Thu Feb 1 15:34: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: 195397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp299119dyb; Thu, 1 Feb 2024 09:03:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IFvqBX6v7sgypZUtSaNWsyTNiSP+8TVfyhkeAqUUe0oPVXGHW/+Fzt9lyYhiP9z84rYRglQ X-Received: by 2002:a17:903:26d5:b0:1d9:4643:65b6 with SMTP id jg21-20020a17090326d500b001d9464365b6mr2880342plb.1.1706807025400; Thu, 01 Feb 2024 09:03:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706807025; cv=pass; d=google.com; s=arc-20160816; b=YQ4DvuN2ZbqTEv8NkhK4BCy8PnHhf36Cv8eYQm+HSVtEM6Poqjua60vZP/+SZPMXOx LM/pd//xLcYDvnDVj/KwyZLuC5SspAT4MMBYohxKoT+rUWRigIBLjWSZWnotfQsoItu8 lg04TJBsUCLh58c6MLR203eRJvvJmML2D9dvkjKbzpND4erfRBjL5gxqeraIC99+KwB4 5twbEj/8u2vr9Tgm2+OY8ldMlesFDE2y3n/T3mdyIEPO/zbuZNQgP6zyrVv3iPYnAs65 pIXarqhQS94EZDaJ/XwABGok3/ZcMR6tpECbqWDXpkUYKmM1iuV1Vjv8PpaBjr+dYzAE iMjg== 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=r5Z1FqaXl8/gr59fvr5vlw2KNofRCpUUOX4Vr/5tKdE=; fh=jQeHReCxMvqfp4PWEpreRLKQ+UF5yoUhI6sVXiqtGR4=; b=MFMlwqDmsGxRPnA97DoiU8FD70FFWzETsEl2iq2n/hiCkCxjyL9vH4tLVWI4xEDISO LOchucXBOCrrV4KaC2pa4AVyYyM1eXFLDOrVBgDKpNaabDl/TqaFnSEJ4vkhbdVje+WB q+JJy+9NdToxqGAbEo70yD3WX3qPhOhypIkGVFg/gabrAXdlmutTEEQSykSOa1AtLVVr saivmPouzb6Ke7BOYfuW6IehjOzLZ1O6eg/FqSoKPVF6HTM0xQIznw8jCFtHm3Vr5PS5 lQtkCz0Lci3Z7P/8zamo643qELMLJ3ffzHfCF1chDvdyT2UAGXd3busWDBXKhgFOuiz6 lSyQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48504-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWjuHGqn2UNEATalQN94mAd0Cmnt3hg974HVYzsBWHBU37ZF04mqVeEqRS+ETGbNLKkCH/A2nP/c37tqIuef38vRGrnZA== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id v12-20020a170902f0cc00b001d88b4759c5si117135pla.19.2024.02.01.09.03.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:03:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48504-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-48504-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48504-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 A6AB7B2C00E for ; Thu, 1 Feb 2024 16:21:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3F5D7DC85; Thu, 1 Feb 2024 16:16:02 +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 A5865160894; Thu, 1 Feb 2024 16:16:00 +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=1706804160; cv=none; b=GDVjlxYkZtc+HS4w0BAJNhXQa3XTlLft+OApsQLoAfYs2pX4OPGY2DhFWGK696fE8ix0OnLujqS3W3KnAUEgAmQLUPT7k7Ko3wQStPXBFBkqTk0swp2Pto6B9gy+e3PCNdpyg+s9SatOv3DWv6Kqt1dQlKKhU8nfZANOvvxpbxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=aYQmR4grRcJrLfjdmABWmdW24Zibr5d0HrWyIDxBXt8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=L+4y6w0Y2Ydtbi02X7/i10xoUKaeoj3ZxuXjzsvUnS8d1Bndiek7CWxdsZY3TGeLZOaPndXuh3HbGePzk0GwqSpS8DXx/CLWDbQaGjPE5ZVMsjjibROye0fC7h11ZCDn+r2YfUbEpVnm93sSGeos+B874kqFimQlXLwujkstqUU= 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 56772C43141; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005TkC-20gX; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.339968298@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:50 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , stable@vger.kernel.org, Al Viro Subject: [PATCH 4/6] eventfs: Keep all directory links at 1 References: <20240201153446.138990674@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789716883508561961 X-GMAIL-MSGID: 1789716883508561961 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/ Cc: stable@vger.kernel.org Fixes: c1504e510238 ("eventfs: Implement eventfs dir creation functions") Suggested-by: Al Viro Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 9e031e5a2713..110e8a272189 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -404,9 +404,7 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, dentry->d_fsdata = get_ei(ei); - inc_nlink(inode); d_add(dentry, inode); - inc_nlink(dentry->d_parent->d_inode); return NULL; } @@ -769,9 +767,17 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry dentry->d_fsdata = get_ei(ei); - /* directory inodes start off with i_nlink == 2 (for "." entry) */ - inc_nlink(inode); + /* + * Keep all eventfs directories with i_nlink == 1. + * Due to the dynamic nature of the dentry creations and not + * wanting to add a pointer to the parent eventfs_inode in the + * eventfs_inode structure, keeping the i_nlink in sync with the + * number of directories would cause too much complexity for + * something not worth much. Keeping directory links at 1 + * tells userspace not to trust the link number. + */ d_instantiate(dentry, inode); + /* The dentry of the "events" parent does keep track though */ inc_nlink(dentry->d_parent->d_inode); fsnotify_mkdir(dentry->d_parent->d_inode, dentry); tracefs_end_creating(dentry); From patchwork Thu Feb 1 15:34: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: 195399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp301577dyb; Thu, 1 Feb 2024 09:06:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRXDw296Z0zgzzL7kK3rcnSMg41+/acbfPYmDwdPr5l3KWXLSXECEmKGmNlqRSwNFF+Mz6 X-Received: by 2002:a17:903:2a84:b0:1d8:fc65:b601 with SMTP id lv4-20020a1709032a8400b001d8fc65b601mr3121597plb.38.1706807187101; Thu, 01 Feb 2024 09:06:27 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706807187; cv=pass; d=google.com; s=arc-20160816; b=Z3AKEgcpzLMM8GS8Ykh5rDhipDCaUxeACfAPgxwNz+2UqiJHA64IdzMhWqiotbvsZo 6wpLfMtzUMk+jBYBjlLwT5m4ev1QoYQgccH8DmQPX6jv3SL0HA1kLvlCMgVgFgsVwecI 5acuJwCJMZ5lbOZOpxmhcJwkt5EUAzXE+nod7kMVmtJ5ME++OnFbWSht2CM0f7CQhQh4 4cm2VTWEgHldkoIZasU/sYGBPBvzYazT8dWA5SmB7PZmc9Hye9US3pc1jkech0tsU2iD ujD0Lcfu9OQ00da41rR6XWI+G89BoD6JKm/CIY5WwboYB5GytVEDx3qNGFaMw5HbaYJT 3Y3w== 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=qBEhJQgbKU5rjcjasZEypzSiXTxSzrkaP1LV6r35Mgc=; fh=TmwqJtlfSddKDt/8JznN4P0RBNGyW5FUvohB8omhT/M=; b=ugsdh6IDU3xlTGr0MHlQEfw8C5DtVqzfVBfLCx5tnvh1ODW6Z607L4rW0sDG0EdwWR LYwRdSh44aFe+DvY4Yvbu+0G58dcvMO1qYAXOqBKJtIC0xEgapZw+Jc8S1uydzlgd6Vs NYf+tYbdV0jtvglGXURnGSPL5cecOk3dD746R6wrgCXRjowD89YYd3q1kkTQyd+7B0ez zkErpFfOq/90/s7u7Mj/GxeM2knkvxlECmjgRdP2f4izZbqotNu2BKbF2o4sxlMbLRbc RTx669vjy+9OqrC0FGd9iN54axI68vk5n/WhWzB8A8Rq09l80WSW+lOcMUpbYPO46Rha A10Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48506-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX2Zlp5zedtppjQXp2qBhJnbRsPKyw2tpFQfCD3stjPaE46XBF0AZDbuZusIbun4mOvv/be1KiR6lIgjuLYg2uGqzmpJw== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id n2-20020a1709026a8200b001d4891f73f0si66649plk.549.2024.02.01.09.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 09:06:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48506-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-48506-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48506-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 701C9B2C45B for ; Thu, 1 Feb 2024 16:21:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1F0D37DCB9; Thu, 1 Feb 2024 16:16:04 +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 D885D161B59; Thu, 1 Feb 2024 16:16:00 +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=1706804160; cv=none; b=Mno0Fl39F0v3qA8PQ9EBSz1pJw9vulVwqRLlYPBEfEmGeVOBIzX42mIraN4Vh9MrLmcnFLo3WJetwMiKRTsLVTgO6rXJsLm/mPB+bXW5YQns5Z/b4GDp4bAIwkaJ4mHxKP2xqswZnQfDuR/sRiS+FM6NAEp7c2at0tlv7c96yCA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=3+ZSFsB8n+3f4GqZyRsq0vWj2Y9oAbKeKdikbNmaVQ4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=FHYgZ6NObH+udnYmPxfXvRnGMvRHvdJ/LZOlNWuXCQkzCJ3e2MMVtAqGGC7cuC7XLAmfJOdlbAYBJ22m8b4w3oiOEqrkS0aI8q72omPmI8Hqq4UdwGtRFuhoS4W15anb80Cv2DAfHfvm5wowTZTkSgm9sw355qkdneWopfzyobE= 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 97DE6C43330; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005Tkg-2gF8; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.499712009@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:51 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher , Al Viro Subject: [PATCH 5/6] eventfs: Add WARN_ON_ONCE() to checks in eventfs_root_lookup() References: <20240201153446.138990674@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789717053305231291 X-GMAIL-MSGID: 1789717053305231291 From: "Steven Rostedt (Google)" There's a couple of if statements in eventfs_root_lookup() that should never be true. Instead of removing them, add WARN_ON_ONCE() around them. One is a tracefs_inode not being for eventfs. The other is a child being freed but still on the parent's children list. When a child is freed, it is removed from the list under the same mutex that is held during the iteration. Link: https://lore.kernel.org/linux-trace-kernel/20240201002719.GS2087318@ZenIV/ Reported-by: Al Viro Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 110e8a272189..1a831ba1042b 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -483,7 +483,7 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, struct dentry *result = NULL; ti = get_tracefs(dir); - if (!(ti->flags & TRACEFS_EVENT_INODE)) + if (WARN_ON_ONCE!(ti->flags & TRACEFS_EVENT_INODE))) return ERR_PTR(-EIO); mutex_lock(&eventfs_mutex); @@ -495,7 +495,8 @@ static struct dentry *eventfs_root_lookup(struct inode *dir, list_for_each_entry(ei_child, &ei->children, list) { if (strcmp(ei_child->name, name) != 0) continue; - if (ei_child->is_freed) + /* A child is freed and removed from the list at the same time */ + if (WARN_ON_ONCE(ei_child->is_freed)) goto out; result = lookup_dir_entry(dentry, ei, ei_child); goto out; From patchwork Thu Feb 1 15:34: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: 195392 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2719:b0:106:209c:c626 with SMTP id hl25csp273647dyb; Thu, 1 Feb 2024 08:26:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF5VgHCGtL4sbaEDAT/LnMzzX272ED0bCp/zEi94Sir7Mf9am+CpDMPwFApZfg6t0Qe/HdS X-Received: by 2002:a17:90b:3555:b0:295:fe86:ad1f with SMTP id lt21-20020a17090b355500b00295fe86ad1fmr4261915pjb.46.1706804768725; Thu, 01 Feb 2024 08:26:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706804768; cv=pass; d=google.com; s=arc-20160816; b=ebW/GU20ed9nAXGHkRKzhl8RNSBOrnyLSvQX7A1xh9Voh2wVxTQTLkfZfoy3ruVpQd 0oLBwQkDEkIvrSawu0rhcQI8jG8Ok41C81SBTbtv1Lug9dg41O6F9r+1rZL60lnhE2S0 ziK2YRQex2kFzw31p+D2U9FxU9AOfIGw8X4tolSnnpjpe3OXuZUuc9QqjC/1TSjC2bJc 3gli5LK4CYwc4p8cADEVuMRAIoN9+0/tIGUd1H0wv8e7CpbNvZEliiNfA8qTev1QuvMw Peb+/tKIrjeVYw2vy8FzRLBbLqJmNYUuadzEonRXcVFXl9wRTE1Lx9s61SHxjkqDMQOu p3BQ== 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=h5PeeVnruYM6GCNxsaFwAUXfYiwycBHir/IgjQ4Fv8w=; fh=ipnE+k3/UyBSxjLi/s1BjTfKge68MX+NXvlwRJk9m7A=; b=QMDeqUhjOEqj9JGNAcFaxe1psO17s2HnC3OSJO0yJCHXcmH2mNwb5os6I/n98Rs9Ji iqA1N/XmyQ0lAxG1yTEkQFxqH4LAwnNUPSP5YrpgEsjXVfDy3Fy4GhBB5J0JXVs93UvD lpWSeR9Vg+g21TbZmKTn3OB3lQS3k9EjlTqRqQpITmqvoXiKVZ6F+6TuuOPfn5Ltpy8C IdoNXX+6oFR7DHB9hjPX66AsIainHz0Nw8mEwF5SssxjoaiG96cp3yfsWBjoffds9NyS DwO+asPTxDPYQOrNzw1zHevYApI/8ClMSHbgWcIW6z8vH+h5/J8BaoTPFOSJyUKp2DmU v22A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-48505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48505-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWJ9HNy89+2HilEeMyfeCOVPC0cNuaTx8F90baqXTn4DnlkDYR5EZ0j9osiS/zc6pPZxR495sVew30yUwH4zL0lzHC4KA== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e5-20020a17090a728500b00295e171ceebsi3939266pjg.68.2024.02.01.08.26.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 08:26:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48505-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-48505-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48505-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 928352861C1 for ; Thu, 1 Feb 2024 16:21:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 48B427DCB7; Thu, 1 Feb 2024 16:16:04 +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 DA164161B5A; Thu, 1 Feb 2024 16:16:00 +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=1706804160; cv=none; b=VB8ysJzuZqpiRNu5wDwSEVM69UmeC57KQZuwsfTvqcGO8jeNiaCdVzUXPwsP4RC8Ruy2c5HMC/jRCxQiX2Ty6EtKR21qjyAY5yYfGkYa4ZL4zoGL9/eXtw6wlPy1nN7hj4BPzorSr4g4qOEAF8Mwbf7ulnf4ykNWpwFB2iyLn2c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706804160; c=relaxed/simple; bh=TwXMBgsYj3cjkDRxSyydgTaD5Knftq7Y2tB5Ttzmt/o=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=aMcvm0WCz0C/QiDVpqjkRugXULfZ6vYDjO8AM+gB36+R+xEOlOeCxMCCMdgaHER5K5Q/gDcoY+/r7cngwLRZHzB1OQ0TBw5oYAqDWpg1wMg4UflApcPXxjDWyYUiT3E6KOB3RwevXJDiVZt4EhYFg/rT/43KHN4vbEIBcXs2+gU= 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 A0DDFC4166C; Thu, 1 Feb 2024 16:16:00 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVZjd-00000005TlA-3MFD; Thu, 01 Feb 2024 11:16:17 -0500 Message-ID: <20240201161617.658992558@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 10:34:52 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Christian Brauner , Al Viro , Ajay Kaher Subject: [PATCH 6/6] eventfs: Create eventfs_root_inode to store dentry References: <20240201153446.138990674@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789714517122553024 X-GMAIL-MSGID: 1789714517122553024 From: "Steven Rostedt (Google)" Only the root "events" directory stores a dentry. There's no reason to hold a dentry pointer for every eventfs_inode as it is never set except for the root "events" eventfs_inode. Create a eventfs_root_inode structure that holds the events_dir dentry. The "events" eventfs_inode *is* special, let it have its own descriptor. Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 65 +++++++++++++++++++++++++++++++++------- fs/tracefs/internal.h | 2 -- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 1a831ba1042b..c50d089c9a7f 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -35,6 +35,17 @@ static DEFINE_MUTEX(eventfs_mutex); /* Choose something "unique" ;-) */ #define EVENTFS_FILE_INODE_INO 0x12c4e37 +struct eventfs_root_inode { + struct eventfs_inode ei; + struct dentry *events_dir; +}; + +static struct eventfs_root_inode *get_root_inode(struct eventfs_inode *ei) +{ + WARN_ON_ONCE(!ei->is_events); + return container_of(ei, struct eventfs_root_inode, ei); +} + /* Just try to make something consistent and unique */ static int eventfs_dir_ino(struct eventfs_inode *ei) { @@ -73,12 +84,18 @@ enum { static void release_ei(struct kref *ref) { struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + struct eventfs_root_inode *rei; WARN_ON_ONCE(!ei->is_freed); kfree(ei->entry_attrs); kfree_const(ei->name); - kfree_rcu(ei, rcu); + if (ei->is_events) { + rei = get_root_inode(ei); + kfree_rcu(rei, ei.rcu); + } else { + kfree_rcu(ei, rcu); + } } static inline void put_ei(struct eventfs_inode *ei) @@ -408,19 +425,43 @@ static struct dentry *lookup_dir_entry(struct dentry *dentry, return NULL; } +static inline struct eventfs_inode *init_ei(struct eventfs_inode *ei, const char *name) +{ + ei->name = kstrdup_const(name, GFP_KERNEL); + if (!ei->name) + return NULL; + kref_init(&ei->kref); + return ei; +} + static inline struct eventfs_inode *alloc_ei(const char *name) { struct eventfs_inode *ei = kzalloc(sizeof(*ei), GFP_KERNEL); + struct eventfs_inode *result; if (!ei) return NULL; - ei->name = kstrdup_const(name, GFP_KERNEL); - if (!ei->name) { + result = init_ei(ei, name); + if (!result) kfree(ei); + + return result; +} + +static inline struct eventfs_inode *alloc_root_ei(const char *name) +{ + struct eventfs_root_inode *rei = kzalloc(sizeof(*rei), GFP_KERNEL); + struct eventfs_inode *ei; + + if (!rei) return NULL; - } - kref_init(&ei->kref); + + rei->ei.is_events = 1; + ei = init_ei(&rei->ei, name); + if (!ei) + kfree(rei); + return ei; } @@ -710,6 +751,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry int size, void *data) { struct dentry *dentry = tracefs_start_creating(name, parent); + struct eventfs_root_inode *rei; struct eventfs_inode *ei; struct tracefs_inode *ti; struct inode *inode; @@ -722,7 +764,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry if (IS_ERR(dentry)) return ERR_CAST(dentry); - ei = alloc_ei(name); + ei = alloc_root_ei(name); if (!ei) goto fail; @@ -731,10 +773,11 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry goto fail; // Note: we have a ref to the dentry from tracefs_start_creating() - ei->events_dir = dentry; + rei = get_root_inode(ei); + rei->events_dir = dentry; + ei->entries = entries; ei->nr_entries = size; - ei->is_events = 1; ei->data = data; /* Save the ownership of this directory */ @@ -845,13 +888,15 @@ void eventfs_remove_dir(struct eventfs_inode *ei) */ void eventfs_remove_events_dir(struct eventfs_inode *ei) { + struct eventfs_root_inode *rei; struct dentry *dentry; - dentry = ei->events_dir; + rei = get_root_inode(ei); + dentry = rei->events_dir; if (!dentry) return; - ei->events_dir = NULL; + rei->events_dir = NULL; eventfs_remove_dir(ei); /* diff --git a/fs/tracefs/internal.h b/fs/tracefs/internal.h index beb3dcd0e434..15c26f9aaad4 100644 --- a/fs/tracefs/internal.h +++ b/fs/tracefs/internal.h @@ -36,7 +36,6 @@ struct eventfs_attr { * @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 - * @events_dir: the dentry of the events directory * @entry_attrs: Saved mode and ownership of the @d_children * @data: The private data to pass to the callbacks * @attr: Saved mode and ownership of eventfs_inode itself @@ -54,7 +53,6 @@ struct eventfs_inode { struct list_head children; const struct eventfs_entry *entries; const char *name; - struct dentry *events_dir; struct eventfs_attr *entry_attrs; void *data; struct eventfs_attr attr;