From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08656C6FD1C for ; Fri, 24 Mar 2023 08:39:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231720AbjCXIjv (ORCPT ); Fri, 24 Mar 2023 04:39:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231631AbjCXIjt (ORCPT ); Fri, 24 Mar 2023 04:39:49 -0400 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFE4325E3E for ; Fri, 24 Mar 2023 01:39:47 -0700 (PDT) Date: Fri, 24 Mar 2023 08:39:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1679647185; x=1679906385; bh=I8/f3JO/VA5KWyLN4wKp4hGSRAS0uOmn5BtDka1Qfpo=; 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=e1OidOwma+seobgitoxy4TukCO+qj4IBs36t91OuEhT4JbWavof1KoVj/j28ytLU0 hIbvgvfRf4lbyL0lFIEnuMFSUeNAwvnZWCwHO/QBPBFsX+/8wedn4Cz5slKHxVWbfY rMuc26kQSIHXkdpt4PFYJuY/1+5PyfTNqyEmsqVZUV5A8tO40LQRHUoMvrPIj9ZBpD wxF0758GJJ5aUXpoqqQKpN+23XTPyQg8X5qqPxFZPVQmk4Y4vATeuv2Zj/sKK47viF bgadAFbZJXBRolAEpj33dG0zFGtEed+pV2bPLmMXJ2YrJmg3tvthIaRYwBIh4zWfw3 //uFrPn/NLtew== To: Boqun Feng From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v2 3/5] rust: add pin-init API Message-ID: <15f01078-4756-8f87-fe3c-ab9f433ebe7a@protonmail.com> In-Reply-To: References: <20230321194934.908891-1-y86-dev@protonmail.com> <20230321194934.908891-4-y86-dev@protonmail.com> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: rust-for-linux@vger.kernel.org On 23.03.23 07:30, Boqun Feng wrote: > On Tue, Mar 21, 2023 at 07:50:00PM +0000, Benno Lossin wrote: > [...] >> +/// # Syntax >> +/// >> +/// As already mentioned in the examples above, inside of `pin_init!` a= `struct` initializer with >> +/// the following modifications is expected: >> +/// - Fields that you want to initialize in-place have to use `<-` inst= ead of `:`. >> +/// - In front of the initializer you can write `&this in` to have acce= ss to a [`NonNull`] >> +/// pointer named `this` inside of the initializer. >> +/// >> +/// For instance: >> +/// >> +/// ```rust >> +/// # use kernel::pin_init; >> +/// # use macros::pin_data; >> +/// # use core::{ptr::addr_of_mut, marker::PhantomPinned}; >> +/// #[pin_data] >> +/// struct Buf { >> +/// ptr: *mut u8, >> +/// buf: [u8; 64], > > Say we have an extra field, > > a: u8, > >> +/// #[pin] >> +/// pin: PhantomPinned, >> +/// } >> +/// pin_init!(&this in Buf { >> +/// buf: [0; 64], >> +/// ptr: unsafe { addr_of_mut!((*this.as_ptr()).buf).cast() }, > > And I think we want to disallow: > > a: unsafe { (*addr_of!(*this.as_ptr().buf))[0] } > > , right? Because we don't want `pin_init!` to provide any initialization > order guarantee? If so, maybe add one or two sentences to call it out. > > If not sure, I think we can leave it as it is, until someone really uses > this pattern ;-) The `pin_init!` macro initializes everything in the order specified, so if `a` is the last field you initialize, the code above is fine. I think we could guarantee this. I will add a comment. -- Cheers, Benno