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 F2FF3C0015E for ; Tue, 25 Jul 2023 20:58:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbjGYU6Q (ORCPT ); Tue, 25 Jul 2023 16:58:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231370AbjGYU6P (ORCPT ); Tue, 25 Jul 2023 16:58:15 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EDBD1BCD for ; Tue, 25 Jul 2023 13:58:10 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-682eef7d752so1365483b3a.0 for ; Tue, 25 Jul 2023 13:58:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20221208.gappssmtp.com; s=20221208; t=1690318689; x=1690923489; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xLjgmoInhbbVcHSZOX3Dw4HQ4eVDyk2e3GDfp0OqxPo=; b=FDgdx/46xAYnB86wVCldw7axWoUoFVmgUGRSDJzuJq1w4PY0DUSgMdu1b1A3kfCoeF 8SA8wxbzp7SJdIbgPQIKqcxbM3ZDjkDeqDDqGLn4lNV3p7c4mtzUdy7UFzxx5fHMKQ0d q97mkN3cgYFQlKF47ibEPBnce5Q2iRa7CTrMQOPXElTw8tg17Mhi3TNOM2wet+6UHrts vgSCsC97LaeHsBstUBkOoqhYiHTUkoa0737FSUjMunrukKPmDi8uZDa1E2PrCgqHcuAK jvikc6eiw9EnYOwQ92owqAxt/wwdT+7xyPQgnfYUm/z+gkZVZB0zYbvV2FhtHtMddgS4 9+yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690318689; x=1690923489; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xLjgmoInhbbVcHSZOX3Dw4HQ4eVDyk2e3GDfp0OqxPo=; b=AoOiSExD9jRQwAnrKKLlUjXN7fvr/5MNVFyEs9Dt4fZUivE2B1ytyNRsEzzt47Nqkp Zb0asHnH2pMFEV2odY9mrnVxvK39EkB1npR1qNZs+9O2DxGrVlAFi0VlJvGakww74Fum fsK6RPFMDvR9UkziTrJITTaVOdzxqYw4H1nYiblBZAALrssD9gKm2aniNFylswDSzPVM JsABwo+Inju2zV2dRVY0EJ39CIuMppWDOBLzkj4TsBgHVQkVYd24ZABeUZH0KTqDYsy0 xJAfXL5unKoUDKuQvbqk7m2QrB9aI2IfzB/gRGlhagP6Ea3NJLxmnXjEX/8hOLUIcMkF Lq8A== X-Gm-Message-State: ABy/qLYrYnz5uqU5PkRf1os8oei7oYL6o5Ix+HQHMtadGxNf1G2eLHU+ wyAYuV++VvPdgUhtHh69kaAftw== X-Google-Smtp-Source: APBJJlH7WkOeA/IlWsAYgdx+CF7wBOZw7N58vM0ISOT6ZSODeC9qpCk661MZGoaUY42AoMhSBv6ASg== X-Received: by 2002:a05:6a20:3c90:b0:134:d4d3:f0a5 with SMTP id b16-20020a056a203c9000b00134d4d3f0a5mr203635pzj.2.1690318689584; Tue, 25 Jul 2023 13:58:09 -0700 (PDT) Received: from [192.168.1.136] ([198.8.77.157]) by smtp.gmail.com with ESMTPSA id x9-20020a056a00270900b00654228f9e93sm10045855pfv.120.2023.07.25.13.58.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jul 2023 13:58:09 -0700 (PDT) Message-ID: <88806a9b-6b3f-1451-ee55-df7da9445a59@kernel.dk> Date: Tue, 25 Jul 2023 14:58:07 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH] file: always lock position To: Linus Torvalds Cc: Christian Brauner , Christoph Hellwig , Aleksa Sarai , Al Viro , Seth Forshee , linux-fsdevel@vger.kernel.org, stable@vger.kernel.org References: <20230724-vfs-fdget_pos-v1-1-a4abfd7103f3@kernel.org> <20230724-scheren-absegnen-8c807c760ba1@brauner> <20230724-gebessert-wortwahl-195daecce8f0@brauner> <20230724-eckpunkte-melden-fc35b97d1c11@brauner> <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> Content-Language: en-US From: Jens Axboe In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On 7/25/23 2:51?PM, Linus Torvalds wrote: > On Tue, 25 Jul 2023 at 13:41, Jens Axboe wrote: >> >> Right, but what if the original app closes the file descriptor? Now you >> have the io_uring file table still holding a reference to it, but it'd >> just be 1. Which is enough to keep it alive, but you can still have >> multiple IOs inflight against this file. > > Note that fdget_pos() fundamentally only works on file descriptors > that are there - it's literally looking them up in the file table as > it goes along. And it looks at the count of the file description as it > is looked up. So that refcount is guaranteed to exist. > > If the file has been closed, fdget_pos() will just fail because it > doesn't find it. > > And if it's then closed *afterwards*, that's fine and doesn't affect > anything, because the locking has been done and we saved away the > status bit as FDPUT_POS_UNLOCK, so the code knows to unlock even if > the file descriptor in the meantime has turned back to having just a > single refcount. Ah yes good point. If registered with io_uring and closed, then it won't matter how many extra references we hold or grab in the future, it won't be found in the file table. I guess that's obvious... -- Jens Axboe