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 09D4CC433EF for ; Mon, 4 Jul 2022 19:17:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234629AbiGDTRD (ORCPT ); Mon, 4 Jul 2022 15:17:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbiGDTQ4 (ORCPT ); Mon, 4 Jul 2022 15:16:56 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D69AD1E1 for ; Mon, 4 Jul 2022 12:16:55 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id i17so7290412ljj.12 for ; Mon, 04 Jul 2022 12:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MM4ez9sq6uBjf7T2AcL2UYNl+8nxT4N2iGuYkE53QQE=; b=hM6KgRdJckBe4bzC+IcRSC7lVdxBNHuWzTR9qbdyHQUEx0yLi33qBKXpEulNeapiqS laTzHjtCEdg71do6SFrzgzbtUfLzBDw03llXfnRTZmsFTWrIjKyDT8wyKG57tf5X4led nsoUHxFpJGeHUekjMViMmo8mgjNaTgaoZFXcI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MM4ez9sq6uBjf7T2AcL2UYNl+8nxT4N2iGuYkE53QQE=; b=kijsUZZoArQspWJ+dKRgit/tepCylaAW7oyOrPQ2NusCLb0v6nNPFNGl3V2cg5+hOC H32sdxqKeAMBuCTTZ60dPwolaAIgYhvWFfJ6ALj3UN98e/Ix4nzgcAAQPnK0FwF4tAvY awNfyFB15nEBd0hMIJEFpsHOXyn/Tj7EVLjQxEMLhf0zoOGCB1+Pd0B0XJiNbOwEd6zG JSluDfnVyj0o1IuOrwQDIB+87DkZb0D0RfgwgTbFdm+yIox5+gEmYTxvM42RIa0Yz4hS oI4eJczw+sBCCVD0creWuYEQp2BQHgFq9NoMwzPqmD9Jw9mSb5yxdqLRv8JK+DIjPcwc Rrmg== X-Gm-Message-State: AJIora8vpXBxKMMWPtDIAU0jxK2j24DxArgxZiaM7t0rtGZwHneNgy1E UbWKEJs+iMWodphM484G91eWg0o95DpgBLQLWoc= X-Google-Smtp-Source: AGRyM1vP3YST+to1/RaphHGc3NhZdnPMQQKUyzeNoBBMnt1+Dan6peu+IpTEUdinJcEIlE6g6K2FCA== X-Received: by 2002:a2e:8804:0:b0:25a:7158:328d with SMTP id x4-20020a2e8804000000b0025a7158328dmr17373366ljh.217.1656962213943; Mon, 04 Jul 2022 12:16:53 -0700 (PDT) Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com. [209.85.208.172]) by smtp.gmail.com with ESMTPSA id q17-20020ac246f1000000b00478ee191091sm5261282lfo.153.2022.07.04.12.16.51 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Jul 2022 12:16:53 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id a39so12045694ljq.11 for ; Mon, 04 Jul 2022 12:16:51 -0700 (PDT) X-Received: by 2002:a5d:64e7:0:b0:21b:ad72:5401 with SMTP id g7-20020a5d64e7000000b0021bad725401mr27236387wri.442.1656962200967; Mon, 04 Jul 2022 12:16:40 -0700 (PDT) MIME-Version: 1.0 References: <20220701142310.2188015-1-glider@google.com> <20220701142310.2188015-44-glider@google.com> In-Reply-To: From: Linus Torvalds Date: Mon, 4 Jul 2022 12:16:24 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v4 43/45] namei: initialize parameters passed to step_into() To: Al Viro 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 4, 2022 at 12:03 PM Al Viro wrote: > > Anyway, I've thrown a mount_lock check in there, running xfstests to > see how it goes... So my reaction had been that it would be good to just do something like this: diff --git a/fs/namei.c b/fs/namei.c index 1f28d3f463c3..25c4bcc91142 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1493,11 +1493,18 @@ static bool __follow_mount_rcu(struct n... if (flags & DCACHE_MOUNTED) { struct mount *mounted = __lookup_mnt(path->mnt, dentry); if (mounted) { + struct dentry *old_dentry = dentry; + unsigned old_seq = *seqp; + path->mnt = &mounted->mnt; dentry = path->dentry = mounted->mnt.mnt_root; nd->state |= ND_JUMPED; *seqp = read_seqcount_begin(&dentry->d_seq); *inode = dentry->d_inode; + + if (read_seqcount_retry(&old_dentry->d_seq, old_seq)) + return false; + /* * We don't need to re-check ->d_seq after this * ->d_inode read - there will be an RCU delay but the above is just whitespace-damaged random monkey-scribbling by yours truly. More like a "shouldn't we do something like this" than a serious patch, in other words. IOW, it has *NOT* had a lot of real thought behind it. Purely a "shouldn't we always clearly check the old sequence number after we've picked up the new one?" Linus