From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB20FC43334 for ; Tue, 5 Jul 2022 03:50:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234283AbiGEDt6 (ORCPT ); Mon, 4 Jul 2022 23:49:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234235AbiGEDtz (ORCPT ); Mon, 4 Jul 2022 23:49:55 -0400 Received: from zeniv.linux.org.uk (zeniv.linux.org.uk [IPv6:2a03:a000:7:0:5054:ff:fe1c:15ff]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED7C012AB7; Mon, 4 Jul 2022 20:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=linux.org.uk; s=zeniv-20220401; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=WiklvS9k0el8XhEQTp2AsFsJfZTmp2j5g87JdjG5LuY=; b=A6t/lG34n3OcVFs5zHW4rDAgZU dB25v6MxiCdWY7bmdH/wWMwaUIjPEoO1NWhXrC7y6CSmgLDL6bimS/XngJ2GfM7RDrgo98UN/Hj5w phxCr6dVDxHMO5OyImVJNe+pBY/kpdH+uHILtmM5FEJN5dminDlfCj7TB7tUgjynMeYgPLR9ZJLg6 5iq4kIYJ9iFtlCfW/XX9hM6JjSG8RfvMehgbWUy1/mO7jhrbxMHwv6wuVdX66t8kIJebaxLKtFSpY JUWGP8LidNDDQzx7AI81vdD7vBuNViIZtGOuVxRemJ+Jh/b9pHi+7NtjZp1cROsoB+T5lnwoKjDFA yiZQuu/A==; Received: from viro by zeniv.linux.org.uk with local (Exim 4.95 #2 (Red Hat Linux)) id 1o8ZYY-008EUH-Gz; Tue, 05 Jul 2022 03:48:58 +0000 Date: Tue, 5 Jul 2022 04:48:58 +0100 From: Al Viro To: Linus Torvalds Cc: Alexander Potapenko , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev , Linux-MM , linux-arch , Linux Kernel Mailing List , Evgenii Stepanov , Nathan Chancellor , Nick Desaulniers , Segher Boessenkool , Vitaly Buka , linux-toolchains Subject: Re: [PATCH 1/7] __follow_mount_rcu(): verify that mount_lock remains unchanged Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 04, 2022 at 05:06:17PM -0700, Linus Torvalds wrote: > I wonder if the solution might not be to create a new structure like > > struct rcu_dentry { > struct dentry *dentry; > unsigned seq; > }; > > and in fact then we could make __d_lookup_rcu() return one of these > things (we already rely on that "returning a two-word structure is > efficient" elsewhere). > > That would then make that "this dentry goes with this sequence number" > be a very clear thing, and I actually thjink that it would make > __d_lookup_rcu() have a cleaner calling convention too, ie we'd go > from > > dentry = __d_lookup_rcu(parent, &nd->last, &nd->next_seq); > > rto > > dseq = __d_lookup_rcu(parent, &nd->last); > > and it would even improve code generation because it now returns the > dentry and the sequence number in registers, instead of returning one > in a register and one in memory. > > I did *not* look at how it would change some of the other places, but > I do like the notion of "keep the dentry and the sequence number that > goes with it together". > > That "keep dentry as a local, keep the sequence number that goes with > it as a field in the 'nd'" really does seem an odd thing. So I'm > throwing the above out as a "maybe we could do this instead..". I looked into that; turns out to be quite messy, unfortunately. For one thing, the distance between the places where we get the seq count and the place where we consume it is large; worse, there's a bunch of paths where we are in non-RCU mode converging to the same consumer and those need a 0/1/-1/whatever paired with dentry. Gets very clumsy... There might be a clever way to deal with pairs cleanly, but I don't see it at the moment. I'll look into that some more, but... BTW, how good gcc and clang are at figuring out that e.g. static int foo(int n) { if (likely(n >= 0)) return 0; .... } .... if (foo(n)) whatever(); should be treated as if (unlikely(foo(n))) whatever(); They certainly do it just fine if the damn thing is inlined (e.g. all those unlikely(read_seqcount_retry(....)) can and should lose unlikely), but do they manage that for non-inlined functions in the same compilation unit? Relatively recent gcc seems to...