Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp797554imw; Mon, 4 Jul 2022 20:52:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uZT/oKf8zN2rX5A2WtiKiEAcg+dmHR+252wNEmNW/vfaT7Sr05Z/vFhKGQ03MVx1j3kaLx X-Received: by 2002:a05:6402:3305:b0:435:8b1a:8fa1 with SMTP id e5-20020a056402330500b004358b1a8fa1mr44038484eda.32.1656993142609; Mon, 04 Jul 2022 20:52:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656993142; cv=none; d=google.com; s=arc-20160816; b=mYRViEeECiY/VIFa12EyNmLQGyld1LU2hCvmOhcXsqIw0tecEJMJmZKWr1YAv8tstA EG1MrJNN2UuKzwyAEIRLZz44RTCgHF6j8kjrAqex/xBzCzGrB8+eddr3ymsiE6TtZNFo 42rKVQa2iufXsCG9a/ried5adoRwPs1ITwO/+rsfmjapShycjaM/fSMpRS8lMoncm9g4 rANBgB7LZfgmquXmlSXQKlj3S0n4lydj5+TD2gG9YksO9fml+Qx3xI/DWnmy5bIzfPoF i8JHU3QRL1f9qIIVBit6fSgyRhigaEn59ujBNFJ1nKn6hVJv6ALvXdElXsPOZxYEKCDv 7PLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=WiklvS9k0el8XhEQTp2AsFsJfZTmp2j5g87JdjG5LuY=; b=BsWwvnMh6hip24Z1BqyG/PCTXyhBT7eYndgpTpUqQFODvj7F/n+fMifEowpFmYJdE4 J82vztPfFU1Dk/m26DbFiQHOTfqoh5eLCJoqIdQm2jgfyXSyKBu8K4SP0x2m3BNoPLKx P1Fhr20KuhqBFlIqp/wcGxTOJGkrMi8eyu40s7hhCkBd81eLaZU5Jj3SAnkIg62qzSTU ELrGYZAWqaEv/Ivg+RX4bcKnQLtm70R3TQEfAUtW2s3akkVWS9m38CcC9IAhn4fw/cxW 0fur2yCyJUU2oVRJf2zo8FWFXPyls/dSHiRo3gQ57E+OeKf0goHi/caUDZOCknodfNDG /gvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="A6t/lG34"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz1-20020a1709072ce100b006ff03a0cdf6si13314899ejc.951.2022.07.04.20.51.58; Mon, 04 Jul 2022 20:52:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.org.uk header.s=zeniv-20220401 header.b="A6t/lG34"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zeniv.linux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234299AbiGEDt6 (ORCPT + 99 others); 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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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...