Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3107022rdh; Thu, 28 Sep 2023 02:53:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHaLrEu3x7Te5DHwki4e3xaj+Fu3ct6ahtH+BbnToVVzNf4nBAWQa6lep/N/prj46Fm4zKD X-Received: by 2002:a05:6358:785:b0:142:f9dd:5aa with SMTP id n5-20020a056358078500b00142f9dd05aamr831887rwj.0.1695894788081; Thu, 28 Sep 2023 02:53:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695894788; cv=none; d=google.com; s=arc-20160816; b=VSDXRhL88geG2UJ/WHdJuFB7tH1lVemEiNDkA7C+tPe/JmZeqhClBkMmuEa3pd6ANO ALTBxWaSU7gvqjBOqTBu7Tu/k0bh7HZDqqOO83is0+iUL/KUkk+qQv1NJ29zhXOCBtn8 ThCP3y5wpdyDAEcv9W7f04Zae7rfM3kfZKOS9lx9B6EjjEVHshhGUVxlopTJ0fv/sYlA kx3+urhWxvO29grJGHN1vZ4PJO8AlsRCp2e+fLhn52cT0jsYOMCQtQfuq4GgjsQTUhZG zA377Syzy/t1uHzwrTk18RTrmX75agYtmHGGnikPbUWGblfJy8DorOi2qXk/s72ZhugK nr+w== 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:references :in-reply-to:mime-version:dkim-signature; bh=p/N9J8xP2hV+7YKX8oU/ArvVYv9CGsvu0WM88Yr0OGM=; fh=3fuGkk6t8rL4T2AilM3pBZQt6nXcfYvg3/GrJ/UWcNc=; b=A5IWNQCbz4WyiwTrhxfj+PEG567oZVVEhUVvrM6YgDqKM20lNA/kXLx9tLaqeAcHF+ 5b29FdaPbLvnSx3P/GQJqlPf/h3L1Pzh+sU20LDYxVmFvvLfiKTzIS8DEX7ABFUgNCv2 Mmj5eJxLoEnZpbJjArBy9n6K3FmpIDGwderYhii6pA7FjQZ8kCWgTCKLkR051dxBIgJ1 gxettx6tpXhqba7aGGt5jaBoIfeC6rYTnxB2oNJOeBJy/8Sk0wCvxpC9mvqCIpIOjPf1 3gilzh2IkaoZ0BZyyCZ06Ea4lOq5nEGTqZOabbPDY/jK5rJP7mq1Aov3ufMsyA+wxHWU szqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TQglbpGf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bt16-20020a056a00439000b0068fb4615f09si17716974pfb.328.2023.09.28.02.53.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 02:53:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=TQglbpGf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E6C368060CBD; Wed, 27 Sep 2023 14:07:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229458AbjI0VHA (ORCPT + 99 others); Wed, 27 Sep 2023 17:07:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjI0VG7 (ORCPT ); Wed, 27 Sep 2023 17:06:59 -0400 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5078FD6; Wed, 27 Sep 2023 14:06:55 -0700 (PDT) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-57bab4e9e1aso4581927eaf.3; Wed, 27 Sep 2023 14:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695848814; x=1696453614; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=p/N9J8xP2hV+7YKX8oU/ArvVYv9CGsvu0WM88Yr0OGM=; b=TQglbpGf7yhciphrpm7NZkQL5uH6TO/S4TmwlbnflsHbiABuVpBm0/H5B8PGj+Qs6c Gfui2O7uPgMc6MT2InHp9FnO7kzJ63wyITLQx2SWBbvXQ45eRf2mgef9eJp+nH9dfBrs oGHEB9UNFS2HAVjI8I6BC1U/EH0YL45+JLnpTU7dLD8hFEBjY0TAur4GRPmzscs7l0AV efT/qKSFB4dmSgScp+L5ELPcKiu7jKDKMcyY+6QRz5wB8jG4tSy1ujChqE+Fgh1YYxpR e/nxSoV0HRaxarYA+CVm43T/ujS3RGCY88FCNRp+KXpEHy3oRPqxIxUY/0AZQO+O3eA9 cPGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695848814; x=1696453614; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p/N9J8xP2hV+7YKX8oU/ArvVYv9CGsvu0WM88Yr0OGM=; b=S1lR3l0uFIzYJzcMCSNSlAz0iY/6FWFsaXklhFNhiJBrBKaqNDMAem2IyMqr/sB7QZ sR58AjKEO6/VqckA+f/9fA0cD8C1RAydfd5L5ev4A5TofKcJifXq0lqDEiLcpJGMGMpT mW4Eei1qkDUMLDPBhlwcCfQjF1spOroAALICcas5az9cmsGoDRN79BtFzN2qSu088Q22 GE2MYbrW+u6vW83/wDurLw7bmAdlXgVIVDZUDaCE5cIuEz4mVaOhNb3MgWSqp/ZCRqTz CafSeiXAWdy7zEEHX3N0E8tyn2NYjQdclmwBREzQcsb20f0Thuo4w598hIBZArwTtUmQ a2eg== X-Gm-Message-State: AOJu0Yxl3wO3l8Rn6BOWKJmwEfjNtf9G7bb7Cq7+24fJgk5z5nkKfARw QLfkypvUhbvdcZskg1Z288DEfTp14ovlLDslkhEZMQvD X-Received: by 2002:a4a:7319:0:b0:57b:eee7:4a40 with SMTP id s25-20020a4a7319000000b0057beee74a40mr3350538ooc.7.1695848814536; Wed, 27 Sep 2023 14:06:54 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6802:1b45:b0:4f0:1250:dd51 with HTTP; Wed, 27 Sep 2023 14:06:53 -0700 (PDT) In-Reply-To: References: <20230926162228.68666-1-mjguzik@gmail.com> <20230927-kosmetik-babypuppen-75bee530b9f0@brauner> From: Mateusz Guzik Date: Wed, 27 Sep 2023 23:06:53 +0200 Message-ID: Subject: Re: [PATCH v2] vfs: shave work on failed file open To: Linus Torvalds 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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 27 Sep 2023 14:07:05 -0700 (PDT) On 9/27/23, Linus Torvalds wrote: > Btw, I think we could get rid of the RCU freeing of 'struct file *' > entirely. > > The way to fix it is > > (a) make sure all f_count accesses are atomic ops (the one special > case is the "0 -> X" initialization, which is ok) > > (b) make filp_cachep be SLAB_TYPESAFE_BY_RCU > > because then get_file_rcu() can do the atomic_long_inc_not_zero() > knowing it's still a 'struct file *' while holding the RCU read lock > even if it was just free'd. > > And __fget_files_rcu() will then re-check that it's the *right* > 'struct file *' and do a fput() on it and re-try if it isn't. End > result: no need for any RCU freeing. > > But the difference is that a *new* 'struct file *' might see a > temporary atomic increment / decrement of the file pointer because > another CPU is going through that __fget_files_rcu() dance. > I think you attached the wrong file, it has next to no changes and in particular nothing for fd lookup. 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). It does work, but I always found it dodgy because it backpedals in a way which is not free of side effects. 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. -- Mateusz Guzik