Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp212640rdb; Thu, 30 Nov 2023 02:51:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPAniKKY+oemM61wC/TMzndyq87G2A18fT223kWYX3Tf1FY5a34arilmzZ5gus+bGavdqJ X-Received: by 2002:a05:6830:3d11:b0:6d8:17ed:60a0 with SMTP id eu17-20020a0568303d1100b006d817ed60a0mr16310565otb.1.1701341505040; Thu, 30 Nov 2023 02:51:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701341505; cv=none; d=google.com; s=arc-20160816; b=GJdc8aqeV2K5dKpTR+V7K1pRIfyUTkUuZoSUSvNjZ6+QQuthd8MPTSiBpJg8rDqUEg WRlkp7H+dXGK9JJmIcAc0p5Uh746SAwBHaoW0Kwe7YI1+j+kZ0k6SWqnOb5qPkg9+m/9 7WVq+xa6Ipj6hCdJ7zdii5kuA3Xw9uDt6fKcoplZR3e8T8TQF62NAO38T5Pyl0flJuwV L0ESK4mwSP7STnF1nIBhvIO/BLSAOFl7mhbn/Mk0UgNb+Rna0+nDoYn8Txy5g1WWBzlq 13MAnXDrCMawcq7k/aQgc9cnIrI2+P32V2KSoCkbBm1wY4FotFTl3EaE4HDkD8SE/2tD MTZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=abbazfD28O1BDRU2vOVdvnJvdFlZx2Onxhy20o9iN3E=; fh=RSd+TZy+/ERHgQwZJxQcFDN6ZwblMaCj09CeqL1TqaM=; b=psElIV7F6nowi/eWfRirF1gftojaL5lAk757H2evGc17QPaWrs6aBd9Xhr9IJUEcB2 7OQB+dQTWq/z6FBbBKAS7e/Wpy3TRfQAeDeA0Y5yOiqSG7Cv4pveQkixIf2wRI8qdRV3 K4Hmrm3IpxGo+ncWSJ0jZ8kRN0ZWP3Oo1NanLS9Jvu0poqR1u4LwLugoR21lY9+L1wjn lADvKcRGfY2Bui3WSH6eVmK5WilKD7R1xyOnRhhZTX3oN9F4/cgROq9PJL3Vu7AblaE1 /sCJr5LQEgFgQdxUE3iwQWXQEsqoCoPeu8Jg2FHLR2UHDk77zGqNgfao6AyW4jW5I76i 6l2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KJKo8nB1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id a11-20020a65640b000000b005859c221c6dsi1102729pgv.221.2023.11.30.02.51.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:51:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KJKo8nB1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 8B3BE826E3B6; Thu, 30 Nov 2023 02:51:41 -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 S1345051AbjK3KvV (ORCPT + 99 others); Thu, 30 Nov 2023 05:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235150AbjK3KvU (ORCPT ); Thu, 30 Nov 2023 05:51:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B31910F3 for ; Thu, 30 Nov 2023 02:51:26 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0024AC433C7; Thu, 30 Nov 2023 10:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701341485; bh=Y4MoSY6O39Ift8abTx8Z8lmCpQSAiFIgx4bR6Skiwa0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KJKo8nB1AQXk6QtYFLkTPwieZ5ML5iWy502wIN/ce8cuJs2/iICs32sz7mj1bU1n3 0NaYA0A6WJ19Z09FYGIzz4aQRtygI7H3LyP8gUCBurnyd8+f36CvekQc6Gbg0fd8+n 5myFa4poG2p3b5gPWomtgtPaFUGPbI0UdY5+uRU/aBh+5pG5N+bAoIHTP+Q4o2i6py 5KdPYLSK2sJbekBJtjNJpQ6pbo8P7w8whUKseINrRKSxs82IfkERnot9Uj7s3AQZTO IDssT1oQayf5MKifeI2Xrlr3fpp9U/inWCkl1kJM5JjVB+pmaHe8MAiq4e9I7EZoiF sjAe6JsiUOVmA== Date: Thu, 30 Nov 2023 11:51:17 +0100 From: Christian Brauner To: Alice Ryhl Cc: a.hindborg@samsung.com, alex.gaynor@gmail.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 Subject: Re: [PATCH 4/7] rust: file: add `FileDescriptorReservation` Message-ID: <20231130-windungen-flogen-7b92c4013b82@brauner> References: <20231130-lernziel-rennen-0a5450188276@brauner> <20231130091756.109655-1-aliceryhl@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20231130091756.109655-1-aliceryhl@google.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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]); Thu, 30 Nov 2023 02:51:41 -0800 (PST) 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.