Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp244780rdb; Thu, 30 Nov 2023 03:55:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IGTOKR7Tcbaao9s06bdIZm8pgr9gB2Mwi3GcKkkqnyS25UbwhiIsb9btPs6F5kgTBWIRpMn X-Received: by 2002:a05:6a20:9e4d:b0:14c:c511:387d with SMTP id mt13-20020a056a209e4d00b0014cc511387dmr24156957pzb.9.1701345328330; Thu, 30 Nov 2023 03:55:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701345328; cv=none; d=google.com; s=arc-20160816; b=Gdj5WRXttFjuesuEcY97MCxeap5hhopmksMQ+8zpRfaStWMXXu78+KrR/JjbLWx/cy LjbUPz9KSuvQli14oFPAbIDaJkrbfSLQHz4llhF6XO0SzMDzUGQx0WUc8If1wRBVIuyW z7YtnSjlJ+H4RsfV1gmoCmdtpSfpe73xuTeKM+tZGsbx3wfqTascEoHtGoC//p2gHte2 +rNvGstUnEM22XdEJ66MFFh9vfsapczU9/HNlWmhqsnGFRGGjUakywqGPrExMffJ5u+G s5Ik6nikH0237rRUtmWWVG4fNWUnMNXPcZRO+q9LFt8BnZHkTwd4VZaf88O4wg521Mca 6njg== 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=/Ea0g+hjygDzgDj1GEwYp4lup/QhGtb9KeZIVW/xhfo=; fh=iehEewRXubtisj4ShmZfjRd9hhpUPlnu/+o8FDS+QQ8=; b=D7LOXvGH1UBYbuxPBcXBhmC8OZPXvjrPj5dZaNU/sG0Vga74hw90joF/XlQkUUSZZh 1rtHmmY4AQo17llMdsY6T1lmcmIAxubx53G2bLnJbMfj1AJumCvkODkW3cgpX/IWqrUA UK2WDZkcKDMVlRXkAmacKv+0AMvjn72gSO2xKDX4B8TLtofFneQDStpcrMbxYVRjkZuo CE1hmJaJBfGJnHJnVJGklrGyFcdiDB2Wk970r1Y9ThpaCTAlmmSS3VyO/bHG4BqWQM4C 3HYcT8f5eMZeqUQtKL56ZP4BTzu4bxDohUFcl13PzW/82SczOpyjQ/7/t+/RA6SFfoE1 ouWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MVcHwtKJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id c23-20020a6566d7000000b005be1e55546esi1209392pgw.51.2023.11.30.03.55.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 03:55:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=MVcHwtKJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 02AFE802F567; Thu, 30 Nov 2023 03:55:05 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231837AbjK3Lyu (ORCPT + 99 others); Thu, 30 Nov 2023 06:54:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbjK3Lyt (ORCPT ); Thu, 30 Nov 2023 06:54:49 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E2D110C9 for ; Thu, 30 Nov 2023 03:54:55 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-db5416d0fccso328997276.1 for ; Thu, 30 Nov 2023 03:54:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701345294; x=1701950094; 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=/Ea0g+hjygDzgDj1GEwYp4lup/QhGtb9KeZIVW/xhfo=; b=MVcHwtKJGkifbVfZNTWt7zcAl4ic2U4b7sU0jjyroRa+fxELpaFRl9lKmttwQo+83H wpMIeoWBtCwVD12k2eIsbNnTVHv8cGt1FutYoeaFtvoMH5NrU6l/ajd0Y76A30G74aBE r0EwwaEGlEjW0ZrgManBcbH12x3mTR8l5rHlQ8CNutHwqtpyCdkCbKNg0ddwSSqtm801 nJKjqVh5im95NuFp4nUk0UkL7AxND37n0MQ6kCSfDY7HKJIq4C82jEBE3NMgRsSB+KIT 1D9exUN62iZei44+0jnB8TttxiKrWaginfNq3Sb0GGSB3bs4uYsnhbLd6X1JWNYPDN1P kDzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701345294; x=1701950094; 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=/Ea0g+hjygDzgDj1GEwYp4lup/QhGtb9KeZIVW/xhfo=; b=GugZDIobYgMSZV2HUzLvQXtDtznUSzcKo1qt437DNbnZxnmnS1WM+NpitF4OdR+jkH hwHtHmFGBzijxgrILCE8wEaLyBbTPipSySkShJYGsQtZDlJ5Z1zN0ztrbDyJAoRY4IeX TCcxnblrbxMYxVdoaLlTgGk5uFqvI6zSOdNiGMX9LU3SHVqN7u39VPuv+db12aBN11c8 nK77q3UOdQ0ewa+ktj+DaPRB+YdRXo6P/7oykFa8h86a175jGHnzIT827RA0vE99QEku DXut7cT6EvH3iLEzQEFKEUtZTs3SATLCybaTAX2/xn+wqgqkkJF2kIZHqGKOvxjCHyuI tLfQ== X-Gm-Message-State: AOJu0YykW1Hzy8g3KlEGFaViU1FdgUKZx9e3T9bGtAgDC07VpFGEJ09W WlmOdCbfLnCF8yNH2JAh0V/nuIZtRMlMBLg= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a25:d74f:0:b0:da0:c49a:5feb with SMTP id o76-20020a25d74f000000b00da0c49a5febmr600980ybg.4.1701345294581; Thu, 30 Nov 2023 03:54:54 -0800 (PST) Date: Thu, 30 Nov 2023 11:54:51 +0000 In-Reply-To: <20231130-windungen-flogen-7b92c4013b82@brauner> Mime-Version: 1.0 References: <20231130-windungen-flogen-7b92c4013b82@brauner> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231130115451.138496-1-aliceryhl@google.com> Subject: Re: [PATCH 4/7] rust: file: add `FileDescriptorReservation` From: Alice Ryhl To: brauner@kernel.org Cc: a.hindborg@samsung.com, alex.gaynor@gmail.com, aliceryhl@google.com, arve@android.com, benno.lossin@proton.me, bjorn3_gh@protonmail.com, boqun.feng@gmail.com, 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 03:55:05 -0800 (PST) Christian Brauner writes: > On Thu, Nov 30, 2023 at 09:17:56AM +0000, Alice Ryhl wrote: >> Christian Brauner writes: >>>>>> + /// Prevent values of this type from being moved to a different task. >>>>>> + /// >>>>>> + /// This is necessary because the C FFI calls assume that `current` is set to the task that >>>>>> + /// owns the fd in question. >>>>>> + _not_send_sync: PhantomData<*mut ()>, >>>>> >>>>> I don't fully understand this. Can you explain in a little more detail >>>>> what you mean by this and how this works? >>>> >>>> Yeah, so, this has to do with the Rust trait `Send` that controls >>>> whether it's okay for a value to get moved from one thread to another. >>>> In this case, we don't want it to be `Send` so that it can't be moved to >>>> another thread, since current might be different there. >>>> >>>> The `Send` trait is automatically applied to structs whenever *all* >>>> fields of the struct are `Send`. So to ensure that a struct is not >>>> `Send`, you add a field that is not `Send`. >>>> >>>> The `PhantomData` type used here is a special zero-sized type. >>>> Basically, it says "pretend this struct has a field of type `*mut ()`, >>>> but don't actually add the field". So for the purposes of `Send`, it has >>>> a non-Send field, but since its wrapped in `PhantomData`, the field is >>>> not there at runtime. >>> >>> This probably a stupid suggestion, question. But while PhantomData gives >>> the right hint of what is happening I wouldn't mind if that was very >>> explicitly called NoSendTrait or just add the explanatory comment. Yes, >>> that's a lot of verbiage but you'd help us a lot. >> >> I suppose we could add a typedef: >> >> type NoSendTrait = PhantomData<*mut ()>; >> >> and use that as the field type. The way I did it here is the "standard" >> way of doing it, and if you look at code outside the kernel, you will >> also find them using `PhantomData` like this. However, I don't mind >> adding the typedef if you think it is helpful. > > I'm fine with just a comment as well. I just need to be able to read > this a bit faster. I'm basically losing half a day just dealing with > this patchset and that's not realistic if I want to keep up with other > patches that get sent. > > And if you resend and someone else review you might have to answer the > same question again. What do you think about this wording? /// Prevent values of this type from being moved to a different task. /// /// This field has the type `PhantomData<*mut ()>`, which does not /// implement the Send trait. By adding a field with this property, we /// ensure that the `FileDescriptorReservation` struct will not /// implement the Send trait either. This has the consequence that the /// compiler will prevent you from moving values of type /// `FileDescriptorReservation` into a different task, which we want /// because other tasks might have a different value of `current`. We /// want to avoid that because `fd_install` assumes that the value of /// `current` is unchanged since the call to `get_unused_fd_flags`. /// /// The `PhantomData` type has size zero, so the field does not exist at /// runtime. Alice