From patchwork Fri Feb 2 02:30:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 195534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp165444dyc; Thu, 1 Feb 2024 18:32:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjTeLF4h0mEtg8iJ8RHurszDUWnq2Fxf5ZNSGYBtIdLVfWbDTQOO/7vtrG4SEik2E+921+ X-Received: by 2002:a05:620a:108d:b0:783:9953:a02d with SMTP id g13-20020a05620a108d00b007839953a02dmr4448391qkk.66.1706841158766; Thu, 01 Feb 2024 18:32:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706841158; cv=pass; d=google.com; s=arc-20160816; b=HD5IvZBX1Pa8ECBwxPlFzUQcCOgyZHrqjUy9n21iZmrjsGVSY2Ho2hBmgiVjZx6DGU 4VOSzWnAWZ2yoErNdFL0LhvSx/ES1thgOoAdMsyAhr4cIn4OyglulcDf3qX8hpb2IAtu n78eujWz2j8ASq9DGbFbquTlARSFBmuzljse3w/5oBXzT4MRmaydMU66Q3DAONbq1c1s VZD+/sL84voJsX6yU0IkVTW+3LXaT9WET3vHB7MGEzfauRncVqd8oOgk33RlGq/rrnUg c6YDZz2J9YPdkmoARZxOuDxUrz8oI5VTW/Emb+Qc93WHSDX9edFo3zv091svcK8IatJ6 hSlg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Z0tluB0AlM/xl4gpfRjrJde9FCeKqB9q1rVWFbwkCwE=; fh=rtZjtFaYQxdbKNGGEEinbFN52McDsC+54nNuVZhNUWQ=; b=pPqrKhVUVWG2GkYq05BWHsjtalhOgjRRQBAkmDLxwjVqh6PwWWF82Ci1ZUvCxdUxqx /yE6Rvf5t8FUKHgs7dOKqQaQf4hiPTepJ90J8fRcBRa6axpU/IFLOojG6yp6DVXkjz6o ju3zGOrG8j4PN0dfWRm/7T5qTE8U8RpsQ6K9oFW5R4uXh6UsUikIA/QHz03usmyoPhfQ mwwdcnSlfTu+gSgRn7UnrgqJOxgyM8SZUOdoOgmZlH8ie4MCjznxHAwBfWxTrp92W5SZ N6JuF8gqJ6tWaFw9IZ52k6UTTrFPsupUWErLGiAHaKY3lsiRADK0RnjgARI5x3GELD3i 2u/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWBtKK/2zR4LqqCGYmJmILplbQxbCHP3yqiR2rUWjLkm3OKRKx1Wwqstr2qGRdoz3OQHMa8Xfa0Yw7fOznuxJeP+YuvDw== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pe18-20020a05620a851200b00785466d67ecsi978491qkn.66.2024.02.01.18.32.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 18:32:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-49103-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8D52D1C23865 for ; Fri, 2 Feb 2024 02:32:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E206179B0; Fri, 2 Feb 2024 02:30:09 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A3719EAFB for ; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; cv=none; b=bhgowyBESenmgL4XlXCD+Jbea/pnTBTQDjwbalAqlIVN6XIJWmO99gVD8tS9f5sq5tl/Wa/HhHntwXK53VzK8AhnKTot8cqDuaZwANvEjCLD5h8vO7CLisvdNQuIHuXWbWXMFJ6KuOnvdjELJtQDeiutqO+L4Tz73zKVtv4w9j4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706841005; c=relaxed/simple; bh=bzFVFZX6ZxTI6abHrIBPqY91OKE0skzJprX6xWIWAm4=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=UE5OrY9dgpRb9mdx61g19Y/NjqWQJRXz2iIMItkhdj4qU9DRouqEx7SdUYqSsT/URFOAE/1jf59N0xObuIiwAhqbkEja6U2uurUEiHg3jSn8qf1bCmAkap4RDGLBjBO+NaisYwv95dELm7Mi9Clv3A/Jh1VaoB0vx8dB4bRnWLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84E8DC43601; Fri, 2 Feb 2024 02:30:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rVjJv-00000005kAa-2jFi; Thu, 01 Feb 2024 21:30:23 -0500 Message-ID: <20240202023023.512233945@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 01 Feb 2024 21:30:09 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Linus Torvalds , Christian Brauner , Al Viro , Ajay Kaher Subject: [for-linus][PATCH 10/13] eventfs: Warn if an eventfs_inode is freed without is_freed being set References: <20240202022959.515961549@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789752674916236777 X-GMAIL-MSGID: 1789752674916236777 From: "Steven Rostedt (Google)" There should never be a case where an evenfs_inode is being freed without is_freed being set. Add a WARN_ON_ONCE() if it ever happens. That would mean there was one too many put_ei()s. Link: https://lore.kernel.org/linux-trace-kernel/20240201161616.843551963@goodmis.org Cc: Linus Torvalds Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Christian Brauner Cc: Al Viro Cc: Ajay Kaher Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index 515fdace1eea..ca7daee7c811 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -73,6 +73,9 @@ enum { static void release_ei(struct kref *ref) { struct eventfs_inode *ei = container_of(ref, struct eventfs_inode, kref); + + WARN_ON_ONCE(!ei->is_freed); + kfree(ei->entry_attrs); kfree_const(ei->name); kfree_rcu(ei, rcu); @@ -84,6 +87,14 @@ static inline void put_ei(struct eventfs_inode *ei) kref_put(&ei->kref, release_ei); } +static inline void free_ei(struct eventfs_inode *ei) +{ + if (ei) { + ei->is_freed = 1; + put_ei(ei); + } +} + static inline struct eventfs_inode *get_ei(struct eventfs_inode *ei) { if (ei) @@ -679,7 +690,7 @@ struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode /* Was the parent freed? */ if (list_empty(&ei->list)) { - put_ei(ei); + free_ei(ei); ei = NULL; } return ei; @@ -770,7 +781,7 @@ struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry return ei; fail: - put_ei(ei); + free_ei(ei); tracefs_failed_creating(dentry); return ERR_PTR(-ENOMEM); } @@ -801,9 +812,8 @@ static void eventfs_remove_rec(struct eventfs_inode *ei, int level) list_for_each_entry(ei_child, &ei->children, list) eventfs_remove_rec(ei_child, level + 1); - ei->is_freed = 1; list_del(&ei->list); - put_ei(ei); + free_ei(ei); } /**