Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1599311rdb; Sat, 2 Dec 2023 02:17:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVmAYxkUuMEW2DGDfforHNKoCQojhVbBcYCVIFwKbrQ2P2pUPBHpPiClyKkdcjTZJVOEsv X-Received: by 2002:a05:6a20:42a1:b0:159:c07d:66f0 with SMTP id o33-20020a056a2042a100b00159c07d66f0mr1103385pzj.6.1701512227586; Sat, 02 Dec 2023 02:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701512227; cv=none; d=google.com; s=arc-20160816; b=tN4a3Z/EHFwi8mBwVRH24Kisw8SlnzQjoWVWyXEmgR6A2ZROBedBMPztnEf81yy862 ZB0MTS2KpV5amoJ7txjmNEtsUrbarD+lyGlR0KMVjhhGZDg7Oz3dkZEEcz2OcYagdvui KtEBEu6Q0+p4Gja130DrB5MIDUNRiWZ6GGOU9X/CtN6swyMm9l182GOy1AOvd+Yb30/r s4zM6vcl0CvInKc8qk8pHMGryO6D2BKAe+gZzF5diZ+8qr0r7zpyt6T/pQ3X81iVO2V4 NOmbtn9IvdWkDMc7rRTPz3YMWuE+rt4oabH+koUG91EhVP8XzVHhRZ/A52Xqv/YeQ/t9 AcpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=EUYoWzRb2VtFg0qFU9eJFRQEz1z2lKS3+4nXPhxD9cc=; fh=DCKQjgAWIxA3NWI9O2VzOBHopifTgFJfTsi5maunsFk=; b=ApWcyztjnFxB5zJFrdbPbkGpUWmvgfrYuTX2E3P0F4vIjs3c7BEFft8SwNhIxr0V8N Wz8OtZ5bEdYExSV6x9byiNYUF95ZMFYum9R5fjH6SlTu/xapJpp7Z11rjodoxtcwSVXp QX9VlWnjqR2RYkTFG8PlWEEmsNdvsvRfvCYlQr1VQMTcLbCKRUbDtFe9+F7qBkeRh8R6 Jpt240imU5yuh2rpLKfFA/1NAvSCwIEOUa8+iY7JNF9Rorh3QOXbpdBPEgazR8VAF59c 0Q69eUvHLDfHvZWftp330hQJu/3+g6TuyC3qMN2vFfLf0VSXScgz2/aJ25rKZg5pina0 AsvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ICKWZrBO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id w10-20020a056a0014ca00b006cdec0a1c79si4679805pfu.272.2023.12.02.02.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Dec 2023 02:17:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=ICKWZrBO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 37F978042C14; Sat, 2 Dec 2023 02:17:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbjLBKQv (ORCPT + 99 others); Sat, 2 Dec 2023 05:16:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbjLBKQt (ORCPT ); Sat, 2 Dec 2023 05:16:49 -0500 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CC1BF1; Sat, 2 Dec 2023 02:16:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1701512213; x=1701771413; bh=EUYoWzRb2VtFg0qFU9eJFRQEz1z2lKS3+4nXPhxD9cc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ICKWZrBOiGZPy9i9e5mo+Xc0KA0Pgfj8HHU9nqvqiwdvXZAxbLc4NwpLv8IDz86Od Sd+6gz0BfDUaC/V/rFYJ8WMmaqjLbg0dS7eus4ygZDQdugCkiK25SiMJcp8NXudLfs 5XKpsTTuloyw+ryvqsNjLAHNZpSA6WDshKGfMefYMF0ExT7ichsjE+IwBNMYEqsTSY 5YsX/soqXn6/LhJU1kbnWHArxDOmXKRTCt3G9yTeP1R0CcdhzsztDStDX+XUDPhoVm UzK5zs/bwI38TYvNYq8LvVwvcLE+5+h4PHD9a9pULzylc31agMoZUskJWrqjH+fGLI eIDK4+9uEiYsA== Date: Sat, 02 Dec 2023 10:16:36 +0000 To: Alice Ryhl From: Benno Lossin Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, arve@android.com, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, brauner@kernel.org, cmllamas@google.com, dan.j.williams@intel.com, dxu@dxuuu.xyz, gary@garyguo.net, gregkh@linuxfoundation.org, joel@joelfernandes.org, keescook@chromium.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, maco@android.com, ojeda@kernel.org, peterz@infradead.org, rust-for-linux@vger.kernel.org, surenb@google.com, tglx@linutronix.de, tkjos@android.com, viro@zeniv.linux.org.uk, wedsonaf@gmail.com, willy@infradead.org Subject: Re: [PATCH 6/7] rust: file: add `DeferredFdCloser` Message-ID: In-Reply-To: <20231201113538.2202170-1-aliceryhl@google.com> References: <20231201113538.2202170-1-aliceryhl@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Sat, 02 Dec 2023 02:17:05 -0800 (PST) On 12/1/23 12:35, Alice Ryhl wrote: > Benno Lossin writes: >>> + // SAFETY: The `inner` pointer points at a valid and fully ini= tialized task work that is >>> + // ready to be scheduled. >>> + unsafe { bindings::task_work_add(current, inner, TWA_RESUME) }= ; >> >> I am a bit confused, when does `do_close_fd` actually run? Does >> `TWA_RESUME` mean that `inner` is scheduled to run after the current >> task has been completed? >=20 > When the current syscall returns to userspace. What happens when I use `DeferredFdCloser` outside of a syscall? Will it never run? Maybe add some documentation about that? >>> + // SAFETY: This function is an implementation detail of `close_fd`= , so its safety comments >>> + // should be read in extension of that method. >>> + unsafe extern "C" fn do_close_fd(inner: *mut bindings::callback_he= ad) { >>> + // SAFETY: In `close_fd` we use this method together with a po= inter that originates from a >>> + // `Box`, and we have just been given o= wnership of that allocation. >>> + let inner =3D unsafe { Box::from_raw(inner as *mut DeferredFdC= loserInner) }; >> >> In order for this call to be sound, `inner` must be an exclusive >> pointer (including any possible references into the `callback_head`). >> Is this the case? >=20 > Yes, when this is called, it's been removed from the linked list of task > work. That's why we can kfree it. Please add this to the SAFETY comment. --=20 Cheers, Benno