From mboxrd@z Thu Jan 1 00:00:00 1970 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 F15E51DFD6 for ; Thu, 4 Jan 2024 20:31:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57C6DC433C7; Thu, 4 Jan 2024 20:31:58 +0000 (UTC) Date: Thu, 4 Jan 2024 15:33:04 -0500 From: Steven Rostedt To: Linus Torvalds Cc: linux-kernel@vger.kernel.org, Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Ajay Kaher , Al Viro , Christian Brauner Subject: Re: [for-next][PATCH 2/3] eventfs: Stop using dcache_readdir() for getdents() Message-ID: <20240104153304.79e607c8@gandalf.local.home> In-Reply-To: References: <20240104164703.808999991@goodmis.org> <20240104164738.483305222@goodmis.org> <20240104140246.688a3966@gandalf.local.home> <20240104150500.38b15a62@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 4 Jan 2024 12:18:06 -0800 Linus Torvalds wrote: > On Thu, 4 Jan 2024 at 12:04, Steven Rostedt wrote: > > > > Also, I just realized it breaks if we update the 'c--' before the callback. :-/ > > > > I have to put this check *after* the callback check. > > What? No. > > > Reason being, the callback can say "this event doesn't get this file" and > > return 0, which tells eventfs to skip this file. > > So yes, there seems to be a bug there, in that ctx->pos is only > updated for successful callbacks (and not for "ignored entry"). OK, I wasn't sure if it was OK to update the ctx->pos for something we didn't add, so I avoided doing so. > > But that just means that you should always update 'ctx->pos' as you > 'continue' the loop. > > The logical place to do that would be in the for-loop itself, which > actually is very natural for the simple case, ie you should just do > > for (i = 0; i < ei->nr_entries; i++, ctx->pos++) { Well, we don't want to do that and c-- at the same time. But of course, if we do the shortcut, we can have: for (i = c; i < ei->nr_entries; i++, ctx->pos++) { which would be OK. And better if we move it before the ei->children list walk. > > but in the list_for_each_entry_srcu() case the 'update' part of the > for-loop isn't actually accessible, so it would have to be at the > 'continue' point(s). > > Which is admittedly a bit annoying. But not really an issue as we just have: list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { if (c > 0) { c--; continue; } ctx->pos++; > > Looking at that I'm actually surprised that I don't recall that we'd > have hit that issue with our 'for_each_xyz()' loops before. > > The update for our "for_each_xyz()" helpers are all hardcoded to just > do the "next iterator" thing, and there's no nice way to take > advantage of the normal for-loop semantics of "do this at the end of > the loop" Anyway, if I do count ctx->pos++ for every iteration, whether it added something or not, it appears to work. I'll write up a couple of patches to handle this. Thanks, -- Steve