From patchwork Tue Feb 6 11:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197336 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1480013dyb; Tue, 6 Feb 2024 03:47:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGST2bNW0MSic0CMakrlsbRiZ6GMAcshYjYL97lTWxy0aN8AxnIc05sr59QfMIiKpVW5GWd X-Received: by 2002:a17:906:3718:b0:a38:47b5:efe7 with SMTP id d24-20020a170906371800b00a3847b5efe7mr202266ejc.2.1707220023242; Tue, 06 Feb 2024 03:47:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220023; cv=pass; d=google.com; s=arc-20160816; b=CJ+eVypZ7rqE7+7A/ofgyXiZKEIilvqK3beKa9HpXVFNUH1/v5h5nM33xyHkrIUhEq WViQFxrLSLOKdnuaWCslYQNUuLInKTzlCnxp7yqzninvZtCrUjnYbYfUtK0ifptQGN/n +EC2PGyVlJqQXKQpbDFYMLWd6DWsQfVnvdBGxM/m8tEC2+slnSiC7Gg6cbrzVxNyebu6 ALmBaZjQNirwimuDmXZCeIX8SLiycG7nger6bLkx72ccDaoSKc9T44uwAu8j8tZ/rv27 WsGDIUqRf5+a4RpOBKOeTb+K+L2ow9aSJ8Vyq5/kxKSQ+I1o2U4MqA7pPrNfrjd52AvG smDA== 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=Vfa0+vs+phltZ3eJfYQwTgeYlRMN2P/oaxI95UkvYQk=; b=ODIwM4mMPw5GDJTKaOBuEu9NEVIUuGWzhluQB4H4WZnsQZG1yXA01JURTyo9X9kiTy MIeQ93IW+YgpMkRg4/Wgh+KdQsbtB0uy4x1hapFILEAJL9/9F3yKnohWksnGJEOpUQUr XDx2FzERER+sEyxqtRbSiVckj9CuBObFPVPsRE08Nv0vW+imfsd8OSEooLsOjkzHdwr2 GOIAQbwmHSZd49cmZZnxZm3X7zmKnnWV7FkMWmiWfjuUnwniUN+nO6NxXx/eVAtH/GIt Cage7Yw5kz2XTcJRCexdHAGgs4thxHZ1UcknSwFQ1gvQ7sRCSZPVmcVo1yIhucwmUtlf gIwA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54793-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCW2CxwbFARb3ODPUIyJESD9PooR2bU4fz8zs1uUUeUqVCtbjtvqj5foScKJi+JuAfYCBPDW7XR+C5FhBA9jNBvlbTqHhw== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dt15-20020a170906b78f00b00a37bc6b8154si1014899ejb.439.2024.02.06.03.47.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:47:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54793-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-54793-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54793-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 C56601F21BCF for ; Tue, 6 Feb 2024 11:47:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F37A7135A52; Tue, 6 Feb 2024 11:33: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 3706C133980; Tue, 6 Feb 2024 11:33:30 +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=1707219211; cv=none; b=ZqzBA6vIrI10RRV5CODRgnrtyuprFJuZM+bk4Wr4/GUhPiccX7/anuER+iKb97UiH2jsf+naEDjMiiR0a4PND06tHId+wCf+SLxoKVadQGHArn+TeZNh48dOWMtkRHRLkhtLA2lWBJJ9djnSz/t+51+kzLyNY40bmtsIuOIxWwM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=msUlAhKaN43vF7JsX1xwBfcdPGlDn+EyYYaBimHJa/8=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=EXN0IfK9sgLcsgKLzAA0b4mlAZJTHTXCe4zr4n5AvFbYoOFxT4bTi0PtgxTtkBNFowPY6gstlCzmvwhJu6VmSZBvSum8uGghhMf2dFxM8zTNSXj/XTCAxbm8QHKP8Vp9DielsrQXLOO2t3HBxff+GHDOyyUjLsHbbCm6ei0DOHo= 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 CC1D4C433B1; Tue, 6 Feb 2024 11:33:30 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aJL-0sJS; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.062398719@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:04 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH v2 06/23] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240206113158.822006147@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: 1790149942947702990 X-GMAIL-MSGID: 1790149942947702990 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;