Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4051001rdb; Mon, 11 Dec 2023 07:35:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkWryFZkXyZflIUxl3EjR9aCm+G68IElR0YBLKdq40JOfPGFWENhMvxrlY0E6dHEShUiaL X-Received: by 2002:a05:6a00:3090:b0:6ce:f632:3ca4 with SMTP id bh16-20020a056a00309000b006cef6323ca4mr1329998pfb.23.1702308907687; Mon, 11 Dec 2023 07:35:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702308907; cv=none; d=google.com; s=arc-20160816; b=ZbqyDmg/RRS4W778Zwx9CoSXW1LCW7ZeeK79fO/nP4ZI32Br3I7Lr/wk+fVEbwfnH0 WlRlaO81BFycBPdwvJad5QJwrCwVhuOd8q32/KyRzz8pF5q7OX5by9pr6U1k+TXn4IlS WVD3fLi/c+hCp4xFymVnMlPULvdCKFnfe2HSBb1Suyg3f1Bfhk0lKaxTg95uRpA2lDYy PjtsfkvBObpxJ87OYiFxIPJmCxqspgOYtSheA6RXmOFKT1sWSRqzSClno7/WYIFqBhdT N7GIu+nTXUYjSLaH5ve2o4V94qnmIm9pJo2SSPlbw8GTtr9XoO4692Na90YK/nvfoJZQ nJkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=stu0ZJZ/iLBAZujmR+p0lyyYHMpojeVivEZwAc09IiI=; fh=0N28rIzUFNBR4G6i0VFfK8yvbIIcOQTClwSpqXp6U/Y=; b=aaDWoJaEEAqyQmQ8WNNyxjoTFrFJpaPAnUuRIYNQtrQ2K7WGXMb4FflJuQUx5J96Ox OtiwnIj05vfv4PL8gshdgXPV//ORvAetVXzleSg1rriFwv16WQGJLtD4MrU0fEdqI+15 lZNfvFtqT6wDU6EiQrUPglhW2pcbMc0bE4Y4ZT0Dmj872T7eTNX3yLyJmRLkthSReWwo AhspXl++SV81WpHXneEuMZ+sc1mcg1jBxNXzKg5s6czHJY7U5lTTqQfITkQyE7qgLqaX Atb+fkJSCsdPzWsQ21mEknbc+OnmJ6wNqMT4gmaA/6TDncv8FtXaQUt8bIZ7EkX3XheE K20g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JVOG2RBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id r15-20020a6560cf000000b005c67e7f7917si6165249pgv.409.2023.12.11.07.35.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Dec 2023 07:35:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=JVOG2RBX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id B8F358097287; Mon, 11 Dec 2023 07:35:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344146AbjLKPel (ORCPT + 99 others); Mon, 11 Dec 2023 10:34:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344158AbjLKPeg (ORCPT ); Mon, 11 Dec 2023 10:34:36 -0500 Received: from mail-lf1-x149.google.com (mail-lf1-x149.google.com [IPv6:2a00:1450:4864:20::149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68911114 for ; Mon, 11 Dec 2023 07:34:39 -0800 (PST) Received: by mail-lf1-x149.google.com with SMTP id 2adb3069b0e04-50beec22e48so2546835e87.0 for ; Mon, 11 Dec 2023 07:34:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702308877; x=1702913677; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=stu0ZJZ/iLBAZujmR+p0lyyYHMpojeVivEZwAc09IiI=; b=JVOG2RBXpgkYv28ZrIIeKFc+eDkGGcxdfTjlIh4qJJ25AWuruy/dtD+I2U2Kb6CcVp fht/4jrJi9scxT7Se98ChBYWUy43uuvyyIPzPShVfqCfsDxL1buvpBxP7pnO6l/lPLl9 V3vDz9zzsXJIab5sCi4spx68TzQ41RnGtdarog3PIjgMDsh1CHi0a94MyMsXYin43+UC E23GXFSV3jvIV0KtKoomLUcWZxSJ5AxeZ2cqzzuL+DCuD0QAcKDZ9AzyD4ThD8PW5ROt qbLgHkmRfG+BMlwTjI0zEFWTTcb+g34UJ9148DADPIS/5UmwW23N2z/MTeUMnFoZ/PBh 35RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702308877; x=1702913677; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=stu0ZJZ/iLBAZujmR+p0lyyYHMpojeVivEZwAc09IiI=; b=fOZ/t+1yF833Xv/6+GwNbE/jxE70tGl0tBtvTWqXL4dKkMAC6tLKoBqBSjuHqcmxz3 9Ct8AHxZ7zgc7815iupMMVkIx1z3j+DpmfnJFy0msysInVoHuUMFcTi49FIbUBeA4mmt /bDBGqevpzAPfaiSrdSCHDjC6rv6Ra96dIKvI+yNTuvMN3mfHWanNti//tBqh6zZOA5S 1PRo/do0yZze1upRgSh01ZD8+MwxrcHavAU6acMxsQELLlzfYz69hysEUzm4yLcI7K9S OFNaV5AAfm2ACKuVBUYMUL5ZF+wjRKtAFqmVem1HqIhZgUgn3UFh+tZbLBRBKKHu5uPl Igjw== X-Gm-Message-State: AOJu0Yz/I2Aue46psO0Lu5ilyRacJRaHieNyrOM+cJYInrI+ImtyV7v+ qxlMGytAN5bRg5fkdtZ00QSCPzmb5+l/7z4= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:ac2:4c0a:0:b0:50d:1395:ef0b with SMTP id t10-20020ac24c0a000000b0050d1395ef0bmr77884lfq.4.1702308877536; Mon, 11 Dec 2023 07:34:37 -0800 (PST) Date: Mon, 11 Dec 2023 15:34:35 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231211153435.4162296-1-aliceryhl@google.com> Subject: Re: [PATCH v2 4/7] rust: file: add `FileDescriptorReservation` From: Alice Ryhl To: benno.lossin@proton.me Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, aliceryhl@google.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 Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 11 Dec 2023 07:35:04 -0800 (PST) Benno Lossin writes: > On 12/6/23 12:59, Alice Ryhl wrote: > > + /// Commits the reservation. > > + /// > > + /// The previously reserved file descriptor is bound to `file`. This method consumes the > > + /// [`FileDescriptorReservation`], so it will not be usable after this call. > > + pub fn fd_install(self, file: ARef) { > > + // SAFETY: `self.fd` was previously returned by `get_unused_fd_flags`, and `file.ptr` is > > + // guaranteed to have an owned ref count by its type invariants. > > There is no mention of the requirement that `current` has not changed > (you do mention it on the `_not_send` field, but I think it should also > be in the safety comment here). > > [...] > > +impl Drop for FileDescriptorReservation { > > + fn drop(&mut self) { > > + // SAFETY: `self.fd` was returned by a previous call to `get_unused_fd_flags`. > > Ditto. I'll update this. > > +/// Zero-sized type to mark types not [`Send`]. > > +/// > > +/// Add this type as a field to your struct if your type should not be sent to a different task. > > +/// Since [`Send`] is an auto trait, adding a single field that is `!Send` will ensure that the > > +/// whole type is `!Send`. > > +/// > > +/// If a type is `!Send` it is impossible to give control over an instance of the type to another > > +/// task. This is useful when a type stores task-local information for example file descriptors. > > +pub type NotThreadSafe = PhantomData<*mut ()>; > > This should be in its own commit. > > Then you can also change the usages of `PhantomData<*mut ()>` in > `Guard` and `TaskRef`. > > It would be nice to use `NotThreadSafe` as the value instead of > `PhantomData`, since it is a bit confusing... > I think we might be able to also have a constant with the same name > that is just `pub const NotThreadSafe: NotThreadSafe = PhantomData;`. I was able to get this to work with a `const`, so I will use that. Alice