Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp4753622rwb; Tue, 8 Aug 2023 13:19:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiiCwnOK2aR+iXku28Tu4clKRIjsd7gw55M+fvFSMa+5ymdRDPxuE9xP5iN+CU0wryaGRM X-Received: by 2002:aa7:c743:0:b0:522:bbc1:a343 with SMTP id c3-20020aa7c743000000b00522bbc1a343mr662318eds.6.1691525948010; Tue, 08 Aug 2023 13:19:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691525947; cv=none; d=google.com; s=arc-20160816; b=VJ4dB90UF/69VRReo8KVYX/rf2veWyfpHkbeMV3eWctBM/AexTPTgyuiJzE3qVAuLB SdeqeBV/fjcI8o61wYW+7Uddqf2Bgh5PojeCYB+j3Vqx7W7CZsmeAFMhgbTZjltkpsBe gcmNpJcvYNeAJ842ZZ8JqNXmh5Z2YFRBJLri6hiwKb4WVNeIRqgPA1uV4006U6HYWCFz T5z32AmOs5ZQK2Hw8dvgCvGi/L4CrG06mGt9b7F4YlqmmA6t80IHH5JjegPxaeuwp8zh SzwHSzdST0Lz/FtD1o9M4hsgKOCD6JIMABi5JrgX0VaOve03+PoZ49t0eLTO80cWYy+w qsxg== 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=q0vkAwW5QpFto/3iZxXs952JhEe8qRWUMMxPi+R76PM=; fh=P7Xg+XJbmnS0xsftk6NikU87ijfePwingkG9+v/zF0g=; b=nUm/NhRkuVQMC7DZOXy2mSL+aPdWq+wvV1HYPeUTxoOVZz1v06rhMXdejSxK9fAjo/ Xk/koi12DoyBz9nk2txPZDxN6shMgvrxfymh8FVaSCJ71xGb6ifH92unbqtrk6K9YMV5 pVS+rR7bzzpvbFCHL/IWIvjul4R3+mQErSFjaaaYVGIcHYNzh0nj3O22UOP6VoHxCgDc Gp3obGG9VULNfinJYAkUZ+Awc3F4RfDQDpZ2zJD1mKuIZJ+2zY+s+Zq64nzyDZJHL31W lbUuUGSZFt+/8VYA7TIP1PjHy/GwjRXjINmEbWeQ1gob34LSJq9OEKjTGFDSDmlcs2ia oa0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Ti59RVSc; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z26-20020aa7cf9a000000b0052329110943si5739206edx.95.2023.08.08.13.18.42; Tue, 08 Aug 2023 13:19:07 -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-foundation.org header.s=google header.b=Ti59RVSc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230013AbjHHSsl (ORCPT + 99 others); Tue, 8 Aug 2023 14:48:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbjHHSsW (ORCPT ); Tue, 8 Aug 2023 14:48:22 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCE74134DDA for ; Tue, 8 Aug 2023 09:57:24 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2b9bf52cd08so91792841fa.2 for ; Tue, 08 Aug 2023 09:57:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1691513843; x=1692118643; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=q0vkAwW5QpFto/3iZxXs952JhEe8qRWUMMxPi+R76PM=; b=Ti59RVScMXl0b2HRtWL9NR9N3UiedxQG42PHAAGR0PGFWlQQUt+tGNRI0X9mu+n40h G3Ndk39+FM1fHRD5fDeUqSdHgN56hQ+v26g+yWm8KCcZ/4WtnYhkDbL91yXA7zNfcOcr 5m2DaGGEVY22xXcLuyTBDsgQ0bKK0PO8/2th4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691513843; x=1692118643; 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=q0vkAwW5QpFto/3iZxXs952JhEe8qRWUMMxPi+R76PM=; b=LYqMLV3gujjLf6/VzQU+RawRbMuBYRHhK3NzSoTwCexFpFTw1RIObg9AK0Ki47nUw+ b5o3wqOZ9jWZZdwnZKWMB4Y+rIBK/6lqwcHvpU3MkEaw48a1t1fLjGEZ5Tjo+9Nj+o4v 80jBwDf+XYwNP9FGWh94Ud1zR+mCAZM72cySOWCd7tE/SoFUTZ0ZrjGfn//404mXoyW3 v3A1fbrYGGMHbZ6/GHy01sDg6M4rK2JJd4y1o98R08lpJenTWu228EK2VEuwzpQEcllo eCyO4Ffioy9LqRmJyCkCgBhyLcmaKIQoG7PiZQcf4GMXclaQPAj0ZpgS0fehz31ClI4X 6qYA== X-Gm-Message-State: AOJu0Yx7Ggh849i5kXo5ZYJUB1tmZBcSQFIJ3+9B05qNoXBmtmyMtpIn GyeGJjp3StmQT9uxdndhj02GJhKfZqYG9DuvGWcV/w== X-Received: by 2002:a2e:9c91:0:b0:2b5:9f54:e290 with SMTP id x17-20020a2e9c91000000b002b59f54e290mr101252lji.0.1691513842706; Tue, 08 Aug 2023 09:57:22 -0700 (PDT) Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com. [209.85.167.51]) by smtp.gmail.com with ESMTPSA id p3-20020a2ea403000000b002b9db7df0dasm2362398ljn.8.2023.08.08.09.57.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Aug 2023 09:57:21 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-4fe10f0f4d1so9760853e87.0 for ; Tue, 08 Aug 2023 09:57:21 -0700 (PDT) X-Received: by 2002:a05:6512:3b21:b0:4f8:e4e9:499e with SMTP id f33-20020a0565123b2100b004f8e4e9499emr79202lfv.12.1691513841300; Tue, 08 Aug 2023 09:57:21 -0700 (PDT) MIME-Version: 1.0 References: <20230806230627.1394689-1-mjguzik@gmail.com> <87o7jidqlg.fsf@email.froward.int.ebiederm.org> In-Reply-To: <87o7jidqlg.fsf@email.froward.int.ebiederm.org> From: Linus Torvalds Date: Tue, 8 Aug 2023 09:57:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] fs: use __fput_sync in close(2) To: "Eric W. Biederman" Cc: Mateusz Guzik , viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, oleg@redhat.com, Matthew Wilcox , Christian Brauner Content-Type: multipart/mixed; boundary="000000000000a6196606026c4195" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 --000000000000a6196606026c4195 Content-Type: text/plain; charset="UTF-8" On Mon, 7 Aug 2023 at 22:57, Eric W. Biederman wrote: > > Taking a quick look at the history it appears that fput was always > synchronous [..] Indeed. Synchronous used to be the only case. The reason it's async now is because several drivers etc do the final close from nasty contexts, so 'fput()' needed to be async for the general case. > All 3 issues taken together says that a synchronous fput is a > loaded foot gun that must be used very carefully. That said > close(2) does seem to be a reliably safe place to be synchronous. Yes. That said, I detest Mateusz' patch. I hate these kinds of "do different things based on flags" interfaces. Particularly when it spreads out like this. So I do like having close() be synchronous, because we actually do have correctness issues wrt the close having completed properly by the time we return to user space, so we have that "task_work_add()" there that will force the synchronization anyway before we return. So the system call case is indeed a special case. Arguably close_range() could be too, but honestly, once you start doing ranges of file descriptors, you are (a) doint something fairly unusual, and (b) the "queue them up on the task work" might actually be a *good* thing. It's definitely not a good thing for the single-fd-close case, though. But even if we want to do this - and I have absolutely no objections to it conceptually as per above - we need to be a lot more surgical about it, and not pass stupid flags around. Here's a TOTALLY UNTESTED(!) patch that I think effectively does what Mateusz wants done, but does it all within just fs/open.c and only for the obvious context of the close() system call itself. All it needs is to just split out the "flush" part from filp_close(), and we already had all the other infrastructure for this operation. Mateusz, two questions: (a) does this patch work for you? (b) do you have numbers for this all? and if it all looks good I have no problems with this kind of much more targeted and obvious patch. Again: TOTALLY UNTESTED. It looks completely obvious, but mistakes happen. Linus --000000000000a6196606026c4195 Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_ll2jn96d0 IGZzL29wZW4uYyB8IDIyICsrKysrKysrKysrKysrKysrKystLS0KIDEgZmlsZSBjaGFuZ2VkLCAx OSBpbnNlcnRpb25zKCspLCAzIGRlbGV0aW9ucygtKQoKZGlmZiAtLWdpdCBhL2ZzL29wZW4uYyBi L2ZzL29wZW4uYwppbmRleCBlNmVhZDBmMTk5NjQuLjVmZTQyN2U4Njg1YyAxMDA2NDQKLS0tIGEv ZnMvb3Blbi5jCisrKyBiL2ZzL29w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