From patchwork Sun Feb 4 01:16: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: 196383 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp147331dyb; Sat, 3 Feb 2024 17:19:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2dhUUVdTKI4cEl+eBMYnTOk5HD1Sc3x01+xoKW34my/ynHlvw4q3BV4sz2SQO6DxLW+lO X-Received: by 2002:a05:6358:d592:b0:176:302b:addf with SMTP id ms18-20020a056358d59200b00176302baddfmr12020037rwb.11.1707009572336; Sat, 03 Feb 2024 17:19:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707009572; cv=pass; d=google.com; s=arc-20160816; b=AD8XVetm2YJZadDIs+UykK94A5dFpvTpregRrF4Rvzx9/paHKY2fZE9GJeEaajn8tM 9wcS0v8lj7cZoA1P+uAHqJorJTZ2xGQqiwTFnFbLk/jCQbW5NJky/eAP+TWfBAr2dJ9c dN/OFs8bhOfOAILSu4P3AwRX/XQh4Eeq8tJefZ++sMEeqARinA32716OCioBqDFaED/J D5lZ7FmEIeHyvxOd4d9lkNvtWmEIMwwqTQsaEno5hvpDMNUyF6YmCLP2gXlEnXmPTXCH sLRhoXyQ7ASB0HZJrG2ftXW8k1I5LIUBhJ/CxEFaTXZeFABVH10RrxhflMOuLLwx3jQ/ gAww== 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=+Iu3NRUooZKj5Akt5qgA83cQX3PY7XYlAwqwf6MKS6g=; fh=NmuWRW0uJWdMFnHPoWZRG2qoYr6YlSLpAurTy7sumqw=; b=bizoFkSRW9eOBl+anIsckZ6GySnwr0onLM0HD+UFIeT5jlLXl1F+IuTimC6d7qpqy9 iuI++fjNI0oyNf7tiCt/wDeHNVDyTlIywj4PiJ8xDLg4VP76SnP9YwzlxkpzTMMrvBu0 z5h5vnaPfkV41ERotJkeRCD2mFJvZSOlgHgB8B3tre3z5C7I49Cl8L+feZyJz1IMU6W6 yQcbbYC9ZJNGCYN0ahxmZoe4HXjRpF1Emg/hrvk7Y3AadLZ0BtuvFdQLfeAcqmnF9RVB n+jhYvo36C/XqAzacSmy2hN7l0tl4RTJhxpgr1Ymo0C80mXKC1A+xtbHyotj56lrNeUv RQvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-51340-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51340-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWQNaGE0NGVNEnn2Bz6YJTC9nDRUjQwtSqi5s0dFqu9aLNMoycH/L/gcNJ+jJL2UyFY0xH9dGErVH/LC+46gTijySI16g== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g3-20020aa79dc3000000b006e02672acafsi1139780pfq.38.2024.02.03.17.19.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 17:19:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-51340-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-51340-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-51340-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 195CC284474 for ; Sun, 4 Feb 2024 01:19:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 81ED5BA56; Sun, 4 Feb 2024 01:18:07 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A56D51C3D; Sun, 4 Feb 2024 01:18: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=1707009485; cv=none; b=sMixlXe2yy6/Xc+43/lYndK0qyLLttv9e9ty3l/JFj+6E5YenBm3EvQ9dMaeB/rxXoakO6HQ14x/eIrzQFPX3EMzHIUWGA+l0B62n73FZIXMJMdzJ2gMjLUxGSyLif+eEWs2pu7hg+WKOdZFtiVca6ZtbwKGAClyL4OMuaZA3nQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009485; c=relaxed/simple; bh=457Nek55iCxNWFMYlAJ4La72v4encx2620jX8BgfCwU=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=ppv2WxcK3l39+RjEeJYk6HTCReSJ5sUbPqokwPR8i5c1FCyYMAqvUyRCklXH+sFiYoXJufNMi/yVsgtDnwcdPKe88mBuxwISVd1Q2xaLew5pSSkBjLjI3KB3mOvBOuKJExuKsoijWcy6uBopBf6BSgaS9KgJsfc9kjAVXS9FO0o= 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 60A43C4167E; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006OnN-00lz; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011827.860926069@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16: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 , Al Viro , Christian Brauner Subject: [v6.7][PATCH 06/23] eventfs: Read ei->entries before ei->children in eventfs_iterate() References: <20240204011615.703023949@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: 1789929268861544812 X-GMAIL-MSGID: 1789929268861544812 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) --- 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;