Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp171054rdb; Thu, 30 Nov 2023 01:18:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgLVUpeW5p8I3IAUEXZ7hAdJqodpK4CLn6LfRZiMMlVGwXsZLTCC/bP+3vCZfkq8res9z2 X-Received: by 2002:a05:6830:16ca:b0:6d8:327c:e0b3 with SMTP id l10-20020a05683016ca00b006d8327ce0b3mr10866200otr.11.1701335896024; Thu, 30 Nov 2023 01:18:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701335895; cv=none; d=google.com; s=arc-20160816; b=MEVayKqUCxh7PuhKjth7eXrtjQ8xiNfacWSBZfO4S7s7m3ZG4g/4gpkQBp8WtpmDG3 kkefqqT9pP4bkpi2mm7gemCyhA5Vw9YMNdutxlMxfUWxhZfvEqEstBPeJ2rHoBBxrwOd svJHlzGtdaiXG42TSmWYpQ3a+5EHqIr4f4jOtC6hJQUy6IIkXBcq+UfI6pivtxUTgPcG jybstbjgQ2v5kDM/TA5w4H74uInYQ0YW7Hvnz0TM7KRgtu+d4NkTL1Yna3RJ5gksU+h+ d942vFbXzader4c7fo+sP+eqzU//gm8tkPG+ZtY+8lSO0DQUihbfhVgU+TMWh21ppM3S +vfg== 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=O12+T4VHs59BbmEd4p1QKD8uv+vZIjQpPLDFbLiopH8=; fh=iehEewRXubtisj4ShmZfjRd9hhpUPlnu/+o8FDS+QQ8=; b=Y4UmpMLkcxw8+vq2kqU/T1ACG4XP6GQ96XcDQxwPAK7psoaaf+C5Y6RViSvfPsrfrh zEzxKXfqeK3tvK9Xrw74m4OHXxkbiytgHhSiedsoIP8jSaDPH5K+7/4ST5GHMoO1HUoO iC6ENvDoo8W3/p0DvYwMnd/RhFJ/i3AXYiRc4WgSpTU+mKqZ4zQWB+14jo4priIrJBSx j18Sfcydz7CKIOxgjq4d6YDE0yU//9QqUaNEn3W48mmAX11gUG81Zk3NAwAuk8t20yc8 ismCImhf4s6/+RM010nGQPCb6qNc62wIK09S4339Q5LreRIJU/0UFr02H939VFH6ti8C l70Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="F/y9wWP4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id y127-20020a636485000000b005acb92781fbsi922359pgb.415.2023.11.30.01.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 01:18:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="F/y9wWP4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 CAF0180C3AA0; Thu, 30 Nov 2023 01:18:12 -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 S235021AbjK3JRy (ORCPT + 99 others); Thu, 30 Nov 2023 04:17:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235005AbjK3JRx (ORCPT ); Thu, 30 Nov 2023 04:17:53 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C9271A8 for ; Thu, 30 Nov 2023 01:18:00 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5d33b70fce8so7508407b3.0 for ; Thu, 30 Nov 2023 01:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701335879; x=1701940679; 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=O12+T4VHs59BbmEd4p1QKD8uv+vZIjQpPLDFbLiopH8=; b=F/y9wWP4HV0Cs8PzAfsCU7uJrkH9qlj1xMQmJwIlr7ExMwwylsCI3LE09vRBZ8WC0t pv/qjMkOn4OC8fQvOFHsHjS/sPZi4KHnsp73E9/yJcihOugDKt8TQ2Ezb+PUxDss+t7U lSj5EUn3iE4oR4dCPqC++yQwpzktZu4dZ7kRCpQl0ITgu5xwinnRGsjRGOmLclWoS3tV Etb6KA/cjAVz6Dew7A946kKLYaoTSx1qKSMySKaxqPExxldT4vx/n+3ZFkVFUSkmRCMy cUKuR9yJ1elKEpGsWrPtaranGSUY2HAah7+LEawhlFQ+QzxCXODv0JR43MTG6vxXNiZK lXJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701335879; x=1701940679; 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=O12+T4VHs59BbmEd4p1QKD8uv+vZIjQpPLDFbLiopH8=; b=dc5tEoSGXv3SDDLV2V3FLE2m5A2A7zEnEFH1k35YJk90Zf2ArtBPxqckQBs5wsx3s2 ujiMsk4P6noMZhquSlBVzVdqkJlmvEzBfmaMtau9V7pi1WKdydg/6oc8ADZhTbFaYrU7 QF+kt+TjmJoTsH4Prw/AF+T5IoK6WOrKVCO8n2bxv976bMepTFpwmj7rMS/2ZWydBNvx lzIW2kBF8hGfmW+J94vhbm13haNhQIdwiu3gdVNUgVRF8IgoiZJhIMgL2qKSgSihgnfx wHFUpggeuWXeQ2+0ISLjHrclaIx28IQoUrBk7+1n87iZ945f/N5W0pISXk5uIM16cCCS J9/w== X-Gm-Message-State: AOJu0Yw0q1goJb47bnqSBvoD2cM0AXGZvsxMA2YZEijBPAZYe5bi3zp6 +WDI3zAs6LA/RKjyeej0L1JUsc+ZAT5pUdc= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a25:d604:0:b0:db5:3b5e:3925 with SMTP id n4-20020a25d604000000b00db53b5e3925mr45069ybg.12.1701335879254; Thu, 30 Nov 2023 01:17:59 -0800 (PST) Date: Thu, 30 Nov 2023 09:17:56 +0000 In-Reply-To: <20231130-lernziel-rennen-0a5450188276@brauner> Mime-Version: 1.0 References: <20231130-lernziel-rennen-0a5450188276@brauner> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Message-ID: <20231130091756.109655-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 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]); Thu, 30 Nov 2023 01:18:13 -0800 (PST) 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. Alice