Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2117269rdh; Tue, 26 Sep 2023 13:02:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxj/SeNLfjf1l5Q9s+VziUpAEPtpyz6u78mI5+9AG8OX15S1RRLboU9SiiqL0xOwA2eol/ X-Received: by 2002:a17:90b:3588:b0:274:b4ce:7049 with SMTP id mm8-20020a17090b358800b00274b4ce7049mr7981822pjb.34.1695758527309; Tue, 26 Sep 2023 13:02:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695758527; cv=none; d=google.com; s=arc-20160816; b=H9GX8s8N2sQbZnGJ6KzQfUgzxygbSYh4lDy8E6fre1/cEWzNhn2lC3uY8E18XneAiP y4QqH3r6U9ePlS3yiebCm949QDYJdaaFeNq2B0Z7wn3oAIxftUXKbaDtYcQ34XKSq568 Xp8fZXjXLgVXBmW4we97X+wXueC/RbFvJldyqd+p1rsO8b+QBc09N5/VNTEEGoQGQDcn JOICBRosNrD5tPYI60dZKZMyIyahjNRyfsY0Bp/RnfqnD4P+e33hMOr7b8fagCyjQ6fQ hqfzwl6xJ3e2pUADLk0OmiS1Dx6t0bsB+Mxr7F4ONhZRTejLOqB72Ku0OCR1Im3uIUSu cuUQ== 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=s173qssf1hSEtheDxpw+ukvaF+2Io1KlydoI9zAe+yM=; fh=5wDaTOOkKDW8XlaZJr9m0tFj6TYMyd4HGVYq1GXq97Q=; b=Tat+R7/vFAeqr3AkyI+ftUzp00NMcflF6nrFW5z9GudFlFi4q8HZg54cyP3J1o4h+d dt0bRZPz3/Qg21scFabjHrb2/2soZjlcNix5xE1PEAAOsqsiu1+j9q3PYjeYBZfsycEt apOIB4bApf4TNnkUUi8rtBDnqxSLarp8Y5zwJUFImD8q3Gdgwzlvse9MN4mvxX1m1Ech vGkL03HEf9RQiRpBRXZMPtaotz3hK5/oHpcRo3syvNj6fCJFj8sa7Jf0qt00jp8zK+iO 00jIWaXrhHyD5w+A6Etw/X6N7XfMsgV47U/ggXuFEbPNAN4olFva8bNb0f7zXPglY43c AjNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=NdB0fWLW; 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 c3-20020a170902d90300b001c0cbaf6970si12388273plz.501.2023.09.26.13.02.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 13:02:07 -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=NdB0fWLW; 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 48E5C8098BB4; Tue, 26 Sep 2023 12:00:37 -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 S235711AbjIZTAe (ORCPT + 99 others); Tue, 26 Sep 2023 15:00:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235679AbjIZTAd (ORCPT ); Tue, 26 Sep 2023 15:00:33 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B47B11A5 for ; Tue, 26 Sep 2023 12:00:25 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-99c3d3c3db9so1140195466b.3 for ; Tue, 26 Sep 2023 12:00:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1695754824; x=1696359624; 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=s173qssf1hSEtheDxpw+ukvaF+2Io1KlydoI9zAe+yM=; b=NdB0fWLWqvnDRGVXRW45jYQQWDHubZLk3lIgLI4HStAfFV1nqNd2X2NckC/MZB0e1/ Hh6erFWTvdrj+rxRunraPdGflV4Qrfs2OusWlceFgMYjffV4z0iiyP6IuCahbV7vo0F9 GGoGdvwxIZVf3rLG/AcHTuLDl3+aShR3l1TBM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695754824; x=1696359624; 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=s173qssf1hSEtheDxpw+ukvaF+2Io1KlydoI9zAe+yM=; b=Lcx67Yx435UEEzvWQ+IIaRigU4B2X5NZJ08+2Zg1HLRSolRN9LYoKnQQlbTJr7zIhh TrUa73J4QPe4fsWLDRZy4gGz9Zv4Blrzc9iyA+VUIOAFE0uiCNvyOq6WrVVR9pmnCJUg ZD9rsBhLygj6uICq1ro5pTjjBTmsyUld/CaSmjqaFyDkUv3MXQzFCaJd/f2uehzihpYX R5A5wkemee298fBj5om79elj0mLsxGFVe/RQDK0WsFOl7Oym/O/GUwk2NAiu0lNIGTwJ w1Ciy1TxMZXF1oBM56mw0v00L4xZ5JPoUUC1QYG1sk/sq/0mFPQZ+in8+N6M4saIfYUg HV1A== X-Gm-Message-State: AOJu0YzrUFG00IgLy5NP39RcB3KxLvroRg1E2qBkg6GXWWJXWWTxDhZv 8gq8LHQm41R4XTwwCr1uOLFbaQi69Kt5iAN533gJpw== X-Received: by 2002:a17:907:86a1:b0:9a5:a701:2b90 with SMTP id qa33-20020a17090786a100b009a5a7012b90mr11041996ejc.40.1695754823901; Tue, 26 Sep 2023 12:00:23 -0700 (PDT) Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com. [209.85.208.46]) by smtp.gmail.com with ESMTPSA id n19-20020a170906165300b009a1c05bd672sm8029499ejd.127.2023.09.26.12.00.23 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 26 Sep 2023 12:00:23 -0700 (PDT) Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-52fe27898e9so11449661a12.0 for ; Tue, 26 Sep 2023 12:00:23 -0700 (PDT) X-Received: by 2002:a05:6402:22cd:b0:534:5e2a:d443 with SMTP id dm13-20020a05640222cd00b005345e2ad443mr2604911edb.29.1695754822856; Tue, 26 Sep 2023 12:00:22 -0700 (PDT) MIME-Version: 1.0 References: <20230926162228.68666-1-mjguzik@gmail.com> In-Reply-To: <20230926162228.68666-1-mjguzik@gmail.com> From: Linus Torvalds Date: Tue, 26 Sep 2023 12:00:05 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] vfs: shave work on failed file open To: Mateusz Guzik Cc: brauner@kernel.org, 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]); Tue, 26 Sep 2023 12:00:37 -0700 (PDT) On Tue, 26 Sept 2023 at 09:22, Mateusz Guzik wrote: > > +void fput_badopen(struct file *file) > +{ > + if (unlikely(file->f_mode & (FMODE_BACKING | FMODE_OPENED))) { > + fput(file); > + return; > + } I don't understand. Why the FMODE_BACKING test? The only thing that sets FMODE_BACKING is alloc_empty_backing_file(), and we know that isn't involved, because the file that is free'd is file = alloc_empty_file(op->open_flag, current_cred()); so that test makes no sense. It might make sense as another WARN_ON_ONCE(), but honestly, why even that? Why worry about FMODE_BACKING? Now, the FMODE_OPENED check makes sense to me, in that it most definitely can be set, and means we need to call the ->release() callback and a lot more. Although I get the feeling that this test would make more sense in the caller, since path_openat() _already_ checks for FMODE_OPENED in the non-error path too. > + if (WARN_ON_ONCE(atomic_long_cmpxchg(&file->f_count, 1, 0) != 1)) { > + fput(file); > + return; > + } Ok, I kind of see why you'd want this safety check. I don't see how f_count could be validly anything else, but that's what the WARN_ON_ONCE is all about. Anyway, I think I'd be happier about this if it was more of a "just the reverse of alloc_empty_file()", and path_openat() literally did just if (likely(file->f_mode & FMODE_OPENED)) release_empty_file(file); else fput(file); instead of having this fput_badopen() helper that feels like it needs to care about other cases than alloc_empty_file(). Don't take this email as a NAK, though. I don't hate the patch. I just feel it could be more targeted, and more clearly "this is explicitly avoiding the cost of 'fput()' in just path_openat() if we never actually filled things in". Linus