Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp2443269rdg; Mon, 14 Aug 2023 02:41:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEVMNTXRYJZN1FebEzEtpF3ur08NZKDkELRdr73UXsb2xa6Ji7xLEGFRmDkt6o3M3UV20tZ X-Received: by 2002:a17:907:b1b:b0:99b:cf57:11e3 with SMTP id h27-20020a1709070b1b00b0099bcf5711e3mr7439804ejl.59.1692006080550; Mon, 14 Aug 2023 02:41:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692006080; cv=none; d=google.com; s=arc-20160816; b=PXf6ZGh/A8Ufxv/4no2N8zP+k29fmHP5vzRifzduIuxeeEu9FSvyA0ORS3r33QRTbJ bZjPOwcjg+AksOFej9t9XbK0y69wNoUxW7+grs6FU2W/IyJ06OXOef5Riop2zmSGyV+I aLvYjvIbOreU+7gMkVymSNXV1ZRW/U7te9SWYNlPoj63TENSYaTsq2Qc8chNgtytasb0 x0aDseOkFVfi96JG4mvLctYLNHD6Cs2ieOaKEhSJ54VZe1w2A2jt8KaAW6YtlWQO5u2y atDpnZ6W4D8nZESGZvvopNcjz/1Zw7HFIGTNbUGoV6jUPZ+EGJ3NvE05c5xvUcRRan3B Bw/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :dkim-signature:date; bh=RmXK6p609GEJrLnFk9jfesnOhQMMA5F6nnV0NJXuXV4=; fh=TE4onW3Du2FQ1EsedDK8TzgRHOYndfJXYpOtlseWrM0=; b=SiPOK4gH6Qpkr1wAkem4RXem+rpndHnhAJ0BV1Jk/a0x763HFvcDh00gJHdvNFTydl czYcfZmtt39Agk3ZLhkP9darQFc0DvJxdjVOE/2/yQEx0uqmov5duy6kDSqevqebdyn+ nYYU9pGO+hyHb77xG//NOv2jO0T0ZlvkzvLc1EAx9keieY+42uZjWpDtGVy2LXRmwF57 00EBvP5u2f4ts7SFaHcu5/uWMx+oZZDN0TUURSBIIti4GGHP5TRQNEzg3rm3Q1ZCRygt M5UW4wavf9uPaEPUBQ3To9Br+ubBB9Uohx6f5b337HFu7OJ2wneMj0/UTd7rWWzUvKW6 adfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=BtvXsbft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k8-20020a170906054800b0099bcb3ad52dsi7235029eja.805.2023.08.14.02.40.56; Mon, 14 Aug 2023 02:41:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=BtvXsbft; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235086AbjHNIsc (ORCPT + 99 others); Mon, 14 Aug 2023 04:48:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235074AbjHNIr5 (ORCPT ); Mon, 14 Aug 2023 04:47:57 -0400 Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C9E1737; Mon, 14 Aug 2023 01:47:51 -0700 (PDT) Date: Mon, 14 Aug 2023 08:47:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1692002870; x=1692262070; bh=RmXK6p609GEJrLnFk9jfesnOhQMMA5F6nnV0NJXuXV4=; 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=BtvXsbftFR8N1LTgE1UOZEG9t4qE9EuuVvtX+vYczOwYQTDCI6do7dB9Oe+P+mXvC vO0kWckuR+N7GqoP1Mg1O2VQ4DL2GP6nmCsdCdiprbCXpVa6Ye7ySV0wRp216IV3TK 5vr/VEITqjSoZSiuxuvzygMTNeH5nDNVpkS4dBuuRf15eGe+vpTcNi6iF1HvltYKBw Rdbq5L3pndnFSRvAsvD8gA0FYBfhXin9XUlaV2f8RfixAcdl2OXBrBrjWFRoCpSteq 3eKTzrZ/Nh+Ffvxz30ouhZQUijNWuR9lSNqnyvsKOPx5UF2g7jfF3/0EhabGZXN6E0 UzN7Us8ciVtTw== To: Miguel Ojeda , Wedson Almeida Filho , Alex Gaynor From: Benno Lossin Cc: Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Alice Ryhl , Andreas Hindborg , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Martin Rodriguez Reboredo Subject: [PATCH v4 10/13] rust: init: implement `Zeroable` for `UnsafeCell` and `Opaque` Message-ID: <20230814084602.25699-11-benno.lossin@proton.me> In-Reply-To: <20230814084602.25699-1-benno.lossin@proton.me> References: <20230814084602.25699-1-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org `UnsafeCell` and `T` have the same layout so if `T` is `Zeroable` then so should `UnsafeCell` be. This allows using the derive macro for `Zeroable` on types that contain an `UnsafeCell`. Since `Opaque` contains a `MaybeUninit`, all bytes zero is a valid bit pattern for that type. Reviewed-by: Gary Guo Reviewed-by: Martin Rodriguez Reboredo Signed-off-by: Benno Lossin --- v3 -> v4: - added Reviewed-by's from Gary and Martin. v2 -> v3: - also implement Zeroable for `UnsafeCell` when `T: Zeroable`, - use `impl_zeroable!` instead of `derive(Zeroable)`. rust/kernel/init.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index b54f32017d00..f91ecd3b1edf 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -212,11 +212,12 @@ use crate::{ error::{self, Error}, sync::UniqueArc, - types::ScopeGuard, + types::{Opaque, ScopeGuard}, }; use alloc::boxed::Box; use core::{ alloc::AllocError, + cell::UnsafeCell, convert::Infallible, marker::PhantomData, mem::MaybeUninit, @@ -1159,6 +1160,11 @@ macro_rules! impl_zeroable { =20 // SAFETY: Type is allowed to take any value, including all zeros. {} MaybeUninit, + // SAFETY: Type is allowed to take any value, including all zeros. + {} Opaque, + + // SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`. + {} UnsafeCell, =20 // SAFETY: All zeros is equivalent to `None` (option layout optimizati= on guarantee). Option, Option, Option, Option, --=20 2.41.0