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 A6295C41513 for ; Wed, 26 Jul 2023 12:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233273AbjGZMy5 (ORCPT ); Wed, 26 Jul 2023 08:54:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234452AbjGZMxS (ORCPT ); Wed, 26 Jul 2023 08:53:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F100E10B; Wed, 26 Jul 2023 05:53:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8DA886173F; Wed, 26 Jul 2023 12:53:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11A3AC433C9; Wed, 26 Jul 2023 12:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690375996; bh=sJaZr1EtZGmMfy8pOqJTpEvOTmMp/9ov8PWPEb9SnFk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XszFAHj6mkRDzhEtllc9G12deNNS7xO33I0rufGCstmhQVUZwrGCezcpojynELGnw 9P6Hwx1z9UiVVq06rc2uEnIIjVyVTs7KOq8/k0A+uyXcLWtGchHJ9TX9A4b5jS3jU3 y0Oqsk5j2Hg3HCpKSiNklD9Akhh6pnfppJbeB3NP5BIsFa4bAG3r9bf5XZAnFT3g/i CaqRV5fZfk6fsPX0OngwbZ56SdWSNLRamo8VzP09ReYERoqdJP42ZCurUMJXI1SDVV FLkrKDQfuc0EAca1YTu3iHIn/hIwAuLMngBSVoZK6z7q6kxp9C1tUhPtNoGFnSmarV +mtgJFYWoH44g== Date: Wed, 26 Jul 2023 14:53:11 +0200 From: Christian Brauner To: David Laight Cc: Linus Torvalds , Jens Axboe , Christoph Hellwig , Aleksa Sarai , Al Viro , Seth Forshee , "linux-fsdevel@vger.kernel.org" , "stable@vger.kernel.org" Subject: Re: [PATCH] file: always lock position Message-ID: <20230726-wehmut-komodowaran-1e45910515b4@brauner> References: <790fbcff-9831-e5cf-2aaf-1983d9c2cffe@kernel.dk> <20230724-geadelt-nachrangig-07e431a2f3a4@brauner> <4b382446-82b6-f31a-2f22-3e812273d45f@kernel.dk> <8d1069bf-4c0b-22be-e4c4-5f2b1eb1f7e8@kernel.dk> <20230726-antik-abwinken-87647ff63ec8@brauner> <081f95b2428049999cc2c0f55a46075f@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <081f95b2428049999cc2c0f55a46075f@AcuMS.aculab.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org On Wed, Jul 26, 2023 at 10:31:07AM +0000, David Laight wrote: > From: Christian Brauner > > Sent: 26 July 2023 09:37 > ... > > Yes, and to summarize which I tried in my description for the commit. > > The getdents support patchset would have introduced a bug because the > > patchset copied the fdget_pos() file_count(file) > 1 optimization into > > io_uring. > > > > That works fine as long as the original file descriptor used to register > > the fixed file is kept. The locking will work correctly as > > file_count(file) > 1 and no races are possible neither via getdent calls > > using the original file descriptor nor via io_uring using the fixed file > > or even mixing both. > > > > But as soon as the original file descriptor is closed the f_count for > > the file drops back to 1 but continues to be usable from io_uring via > > the fixed file. Now the optimization that the patchset wanted to copy > > over would cause bugs as multiple racing getdent requests would be > > possible using the fixed file. > > Could the io_uring code grab two references? > That would stop the optimisation without affecting any > normal code paths? io_uring doesn't use fdget variants and can't for it's purposes as fdget is for short term references while io_uring holds on to the file. This whole thing was about the logic that was copied in a patchset not the actual helper itself. I thought that was clear from "copied the [...] optimization into io_uring". It should just not do that.