Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2953345rdh; Wed, 27 Sep 2023 19:45:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8CL1VABJqoKieqgOKS1m62KTSUdmSqEgv2CaYVxw8EEWMAGckcb0I//XkSBQC2fMYd01I X-Received: by 2002:a05:6358:4327:b0:132:d32d:d929 with SMTP id r39-20020a056358432700b00132d32dd929mr4606658rwc.20.1695869111047; Wed, 27 Sep 2023 19:45:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695869111; cv=none; d=google.com; s=arc-20160816; b=jgeA9vK8vyA4Msov9aoyT8CHl3PMVuwDwt/gfz0GHadPd8PwzNNpeJpK6KN8Kr8INI tHTXNm5nO86xB9RquGhRERuSkgVHh0Ax2QV7GwypebPWk0wNapL8CTbD9WPhux1ae1my PPJuhISE8UhmjP8bEfbgk4FRK96AX3BKfnJ8U5wPzm0TVFp9cgzN0pH0AOhrPoOzyLTm cVaFPyY3e7g9N2Ys3GkZpu/hGqfjHqfKnoTRY+ym61OO6a6fu9Suge/wqxv3HWG0F7B5 wt0N5ZJ9kQ2GRik3oZxO3VjaUwTN/EzelD0EbZfSfwrk6Gpowf0D8VJjow+R6z65Jujp +5mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=G8V+lk3a6Cym1PJ0mfiXsEqz7twyU2MgEXEYS1WTIfQ=; fh=ziJSrE0sDvMIhmkBFU1jJK15yvgZkLMOUWuncUnCmvo=; b=kx2eqjba3ve+8+n8NKZ9IEEPsL7kU1/PUtfXgz0fNzSMfErrE9hM2Ak5LffkGpttin WDGf6NI8PQNHYB/xZ9esWk9OilDnIpMlIRygtAMn2XLn5Piv8DOSEVXX7oyKbfA8hrt9 rtbxWWfiheR9f1honT1HnDccmyrlbm5fytCN2bxL+xQul/XqaJoCxcuRITp/r0Tz1nYd 1SiJxA5hDWFNp5hnKeJbsT3J9rBCdKmKEeO1sIQxb7K1JqlxLcDHjiE2NmXf+umn/ZXz JlltMuKY38cC63o9a2AyVVvdtllNT1fQbxjus5UI3PfjK/nungTCvfwbl7lXde7bp2KL 1N4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=T9wMVK3b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id by28-20020a056a02059c00b005702257f332si19686871pgb.21.2023.09.27.19.45.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 19:45:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=T9wMVK3b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id C6FB58128038; Wed, 27 Sep 2023 14:19:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229931AbjI0VS5 (ORCPT + 99 others); Wed, 27 Sep 2023 17:18:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbjI0VSx (ORCPT ); Wed, 27 Sep 2023 17:18:53 -0400 Received: from mail-ed1-x533.google.com (mail-ed1-x533.google.com [IPv6:2a00:1450:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DA9211D for ; Wed, 27 Sep 2023 14:18:52 -0700 (PDT) Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5334f9a56f6so14176813a12.3 for ; Wed, 27 Sep 2023 14:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1695849530; x=1696454330; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=G8V+lk3a6Cym1PJ0mfiXsEqz7twyU2MgEXEYS1WTIfQ=; b=T9wMVK3bnjWmJO7M4kwiaAOm2VnWwbW9DXDejoQgfkvRvF/v80XY7LBZu4zJBwYnvA xri9lI7g/PYEk+OtcMavgWDlxkKriXtUDoBKmpIVBhf9EgSVV9RuhHKR6Q4WR1SFiQE2 VtCC0PP4JAkGz0/6Q4XTi56sxmxOl7yWSTKCo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695849530; x=1696454330; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=G8V+lk3a6Cym1PJ0mfiXsEqz7twyU2MgEXEYS1WTIfQ=; b=TJEfYFzaRonpslFIZCCjEhYesEYbXeNKSlSusEhlxTAC9sGtthyADK6dJ849cxIdUQ ELV4/T9U4bX/1L+S0UHujrXRmBM1QhZ15+4eZTLtwnf/yPIqkTwEoQ52HSIoZM/SU0nk 03xPBfrxoqhQiemE2kykUsrLmXfATyT/Py4+ApW9KEWcjYrIFRZNYa2pf/4I6x/u9ecb sTGjcZmD9d2xgicoYcF0r/qZ71gFEw8WqQMYRlI9YBmUVFdmpLou6OCAd/OrirHsNElV mmHLoEyygbb1JLHa8j/oO44UrywsiE/MsUIrzlntdw/sN8KNh/UsuxZGt9PGU7tiBJfa 5LAQ== X-Gm-Message-State: AOJu0YyLIrleUcsUgkNTcKvlnJBJSAO+i3jH7oFogHyKKaZSU9YkGN7I jCBqN+Rx4+WXftXQv9BPViGS2R2lbMLfvQMKMqVl+w== X-Received: by 2002:a05:6402:1251:b0:51d:9399:4707 with SMTP id l17-20020a056402125100b0051d93994707mr2701851edw.26.1695849530460; Wed, 27 Sep 2023 14:18:50 -0700 (PDT) Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com. [209.85.208.48]) by smtp.gmail.com with ESMTPSA id dm20-20020a05640222d400b0053414427690sm4416962edb.41.2023.09.27.14.18.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Sep 2023 14:18:50 -0700 (PDT) Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5334d78c5f6so14279843a12.2 for ; Wed, 27 Sep 2023 14:18:49 -0700 (PDT) X-Received: by 2002:a05:6402:1652:b0:533:f1c4:5424 with SMTP id s18-20020a056402165200b00533f1c45424mr2803713edx.35.1695849528832; Wed, 27 Sep 2023 14:18:48 -0700 (PDT) MIME-Version: 1.0 References: <20230926162228.68666-1-mjguzik@gmail.com> <20230927-kosmetik-babypuppen-75bee530b9f0@brauner> In-Reply-To: From: Linus Torvalds Date: Wed, 27 Sep 2023 14:18:31 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] vfs: shave work on failed file open To: Mateusz Guzik Cc: Christian Brauner , viro@zeniv.linux.org.uk, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 27 Sep 2023 14:19:09 -0700 (PDT) On Wed, 27 Sept 2023 at 14:06, Mateusz Guzik wrote: > > I think you attached the wrong file, it has next to no changes and in > particular nothing for fd lookup. The fd lookup is already safe. It already does the whole "double-check the file pointer after doing the increment" for other reasons - namely the whole "oh, the file table can be re-allocated under us" thing. So the fd lookup needs rcu, but it does all the checks to make it all work with SLAB_TYPESAFE_BY_RCU. > You may find it interesting that both NetBSD and FreeBSD have been > doing something to that extent for years now in order to provide > lockless fd lookup despite not having an equivalent to RCU (what they > did have at the time is "type stable" -- objs can get reused but the > memory can *never* get freed. utterly gross, but that's old Unix for > you). That kind of "never free'd" thing is indeed gross, but the type-stability is useful. Our SLAB_TYPESAFE_BY_RCU is somewhat widely used, exactly because it's much cheaper than an *actual* RCU delayed free. Of course, it also requires more care, but it so happens that we already have that for other reasons for 'struct file'. > It does work, but I always found it dodgy because it backpedals in a > way which is not free of side effects. Grep around for SLAB_TYPESAFE_BY_RCU and you'll see that we actually have it in multiple places, most notably the sighand_struct. > Note that validating you got the right file bare minimum requires > reloading the fd table pointer because you might have been racing > against close *and* resize. Exactly. See __fget_files_rcu(). Linus