Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp669685rwl; Fri, 31 Mar 2023 00:10:53 -0700 (PDT) X-Google-Smtp-Source: AKy350aJzOrhQj1QP1mswbkZYhQIrRY4/Hx8QlT7XmpWEUGiHfcZRjW/1Iffs2PqAePtBMAf52vd X-Received: by 2002:aa7:8b1a:0:b0:628:630:a374 with SMTP id f26-20020aa78b1a000000b006280630a374mr24229666pfd.2.1680246653387; Fri, 31 Mar 2023 00:10:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680246653; cv=none; d=google.com; s=arc-20160816; b=DhEqn++1LHnYYASGGuXjICFiLL4SowtXLfSUSUXnWVJDtxpAMtgqN6ub/O9X1f8FTE DPjvEGoqo7QLW9CVG6SA2UoH6YG3XzDOPZm/sm5qjxHDsnDi2IsHfS5EE8qfhndBU6B3 FyKIXk1Ld5g89EBgp+eoVmBVQWlhU9/4L34RW7gSrKb+KG0wLl9+hGYE7RJAwrkaiwfR X0fyrZLzXn4GV2C3xXAC6/UbwhvA6zQfky79Jr0I4DG38y2PJX98ym7VVCM5WCmDLV5U f3gZi/gx9N3mKZlst6IjkF/JA0I95VUJBRag+kp9V+6UFvFuhjjMWZotQbl7u25ZK567 i01g== 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=yc7pszNaS5MbnHhdKhl5ZeYs5tmQLP8mPSrXEB1Pfk4=; b=KoTjb69UTG9+qoL+pxwCB9sB9edSf+r/KowUmJPD6hgmJYYtJPTX49kIYRAQ1lzXdh v9vzTRzMAH4T23kXhaWhfKoj+I+KkXcOsJAUMTVYxZvNubq8I9dDuFF3YzujnriU8lDQ IsA4zbi0rj8/78B5rX0888dMr8BlnQdWXWEJTYBo6x+CQRl8U05y9O9+WUXhTcrBTExI 8WiIROE38nkVQ6nhtzQ9ZJoWqi9dVwD2/I/mysXnBSuWVN3QAhtjpQ3fKsKyQJU/BImf jQ+vD0PUMxHyssJnhFKjvf3nc9+GPfn1MRLJLhQDlSWjWjGRzWRXWPKiYY6n+Jiaa5cJ 7+4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=P77Mw4qM; 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=protonmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a63e604000000b005023dfa3c68si1816188pgh.145.2023.03.31.00.10.39; Fri, 31 Mar 2023 00:10:53 -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=@protonmail.com header.s=protonmail3 header.b=P77Mw4qM; 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=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230466AbjCaHJt (ORCPT + 99 others); Fri, 31 Mar 2023 03:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230449AbjCaHJl (ORCPT ); Fri, 31 Mar 2023 03:09:41 -0400 Received: from mail-4322.protonmail.ch (mail-4322.protonmail.ch [185.70.43.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54B5DCDCF for ; Fri, 31 Mar 2023 00:09:40 -0700 (PDT) Date: Fri, 31 Mar 2023 07:09:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1680246578; x=1680505778; bh=yc7pszNaS5MbnHhdKhl5ZeYs5tmQLP8mPSrXEB1Pfk4=; 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=P77Mw4qMdqZYI2RdWmjZNTsGKTQyZ77FieQWyPBpdBBmiAqwn7bM0hYslj+c7jbPc 4/UkSxuVIWihc8PVv+QsXkBOkSiQhk9IDPczy8+kO/AYbK3ZG1ZEFCB9qkr5iMgixU jrW4bSSBPQwEc1Ck3bTBS9YAk/qI9HTraRRN9o0vSsOnbhAQGQARKE6r8OuMmKCiAh afZlEO2dX17N/zaQKYEbO+XfQ65sfB6FswvnGw/6da6+cgIgsn5u/SDPSX4QYDPwQR xlaQm3ZYPwI7ItkJ0SUqanHEc7cxGns7nzWfu13woHHx9sKmh2MGBlKCmtaWOh6TMJ A8BIO+WjxIqkw== To: Alice Ryhl , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= From: Benno Lossin Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, patches@lists.linux.dev Subject: Re: [PATCH v3 09/13] rust: init: add `Zeroable` trait and `init::zeroed` function Message-ID: <06e72e1f-af49-d952-7dd5-c80b9e3f27ee@protonmail.com> In-Reply-To: <19db6213-297b-a33d-7331-3c1a5b72fad9@ryhl.io> References: <20230329223239.138757-10-y86-dev@protonmail.com> <19db6213-297b-a33d-7331-3c1a5b72fad9@ryhl.io> Feedback-ID: 40624463:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_MSPIKE_H2, SPF_HELO_PASS,SPF_PASS autolearn=unavailable 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 On 31.03.23 00:40, Alice Ryhl wrote: > On 3/30/23 00:33, y86-dev@protonmail.com wrote: >> From: Benno Lossin >> >> Add the `Zeroable` trait which marks types that can be initialized by >> writing `0x00` to every byte of the type. Also add the `init::zeroed` >> function that creates an initializer for a `Zeroable` type that writes >> `0x00` to every byte. >> >> Signed-off-by: Benno Lossin >> --- >> +// SAFETY: `null` pointer is valid. >> +unsafe impl Zeroable for *mut T {} >> +unsafe impl Zeroable for *const T {} > > Actually, I just realized that this is not ok for unsized types. When T > is unsized, the raw pointer is a fat pointer with a vtable, and the > vtable part is not necessarily zeroable. > > However, it would be ok to do it for `*const [T]` since the fat part of > the pointer is just the length in this case, and a length of zero is fine= . > > See more here: > https://github.com/Lokathor/bytemuck/blob/8391afa876ba2e99dffb0c991cc7fa7= 75287d106/src/zeroable.rs#L56-L65 Wow I forgot about fat pointers completely! Good catch! -- Cheers, Benno