Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp646933lqt; Mon, 18 Mar 2024 21:39:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWTO7cqCrZGXkficJN0Pct8lvbiKucrNRv7WLnIWgH4QUq+ME8T87Ql8VtN5PkQs+NPUksgYGAmIP3RTxXZ8tTT3zi5VkpTbI60TNdz6g== X-Google-Smtp-Source: AGHT+IFuPact08Kw6ZBpKnoztJppfH9pPdVywA7caSUno8tweqTY6pnhoTnpDWHiytgx7etZacZh X-Received: by 2002:a17:902:f545:b0:1dc:b16c:63fd with SMTP id h5-20020a170902f54500b001dcb16c63fdmr1914244plf.65.1710823177315; Mon, 18 Mar 2024 21:39:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710823177; cv=pass; d=google.com; s=arc-20160816; b=ieO8Zlc4dSegCrkCNWv7fl3BKmnTuskMApDHAxPnK3yvT6GetWZDJLsNb2cCDbTALp TTCsUdjLah0Qe25mloiYtjusz44k1A6pESUhJLZQA/7cz4AlzckkX0wJeR5YFYKttUU/ ixnVsy+z1fpBlNfARWQK8O1NQ8yhsVepAqv5ozWDySt9L54XmdllefmdpblYJlo9bVeg 5O2UdwiVeITTyuqqGZfHG7clg+/66z4Nv5NGgCpiywM2MJYPnr4b3ViMN8vO1xj3Qxrw pGrFLxzgzsKV9+7iRT07rn/GB4Cdz97S6+J+RcKQO2Mn6kuuqoLL2pGsR2nUGQrDFo82 A79Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=TCcPcWRQCvkbSDI9YFfpJrZ4gRBUtJwDb7Mt4FY2BYo=; fh=sdF/CD9eMdjv7eGsU1m3+4DLAePHQ5T0qmmJA7M9rtE=; b=Uto1TtnQ1X162hb9epasz/8LLXghg4Vwu6bauV0sQgZcsSf6bkr6KbBNsuOL9jHdE6 YhIfnOwjfbcTe/xXZpiRJwIjz4P/CfirhwkCPgbw5ZTcmcUtKbgdv324D7qKbvzdYBzR MovSavTHNZP51vAuQDEJnSwF2N1ffRu80xUz1HW24EMcP6p0nKwR+V0GJRCgRY5KC3sP srwHiZtJ/bNPPLVbfHMY0ZsQbdeSDNHAO4kKOqa/oF85sCiOQynsYlVm+/Rm/NkXoGsr v7D1M17TrS5+HbpgZSM6nhrstYLT3m0hKODHAqc7iae5hpib7LD1PILWpv9zYE38sxO0 mUvg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VmxJF6JK; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-106995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106995-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id e2-20020a170902cf4200b001e00adb94b9si5158242plg.608.2024.03.18.21.39.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 21:39:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VmxJF6JK; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-106995-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106995-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 24C1FB21D51 for ; Tue, 19 Mar 2024 04:39:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6596638FA6; Tue, 19 Mar 2024 04:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VmxJF6JK" Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB9CD2744B; Tue, 19 Mar 2024 04:39:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710823160; cv=none; b=bltRnzgclthUccmZc4jQp0bMYTh4OEjzuCw7N8n8LXvHUrgroHxteFrmBXJp+JgdqTcc6iEgQfh+vfrjXrvSRs0pxu5NaiAiK664SdIKPGPQijQKBIOgGg55et387YMu4E8vC2hfE6i1QdNK1/3SEQwJ4td2F4SMkXIJ7kY0008= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710823160; c=relaxed/simple; bh=EX6GHgLPuSo2ubcFe0HUyPHI95YPFIuR96s31sKY5WE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=qPHV4yc2OKNusOh6qrkGO+MVg/p2x9D/hZF0Vq04PjoPPX6vOceNQSk0yHUnIoFKm+BFMuFdPDcO78Exja0AgFMOXTz1A8EIkl/qLRQb4wxz9Wwh9qHyCeuD17ekiuKDZ2U0paoTytunbsJpvh2K9ZCCu3uSMYMNrsvSbwSpfDs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VmxJF6JK; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-789e5021703so188729885a.0; Mon, 18 Mar 2024 21:39:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710823157; x=1711427957; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=TCcPcWRQCvkbSDI9YFfpJrZ4gRBUtJwDb7Mt4FY2BYo=; b=VmxJF6JKEYKGeVdz3E7CS2rN+xSq6gVFFgm0jkklQTq7F0mpZ4wJXHyZlUIRlbpVOx dKYyV6BOf9I4xGDJSjekeOzFsiu3uPcM0CRKe/LYo//lmOMuyPsj2u8a9OdbovVb7Tax wdDMLDTo/Cs7JpHGXntoLpC+vs/KM18gcBsI/Yq2TuNI0ZJx9V9mW1Upd7miLnl6ZD70 aq6B+ZrDEdV7053YnioEsqp3weGeavFR5ty7ZU0KW4PJNjIgvHu/8wQK6KyXSKqUcoqa dmqTgHFbvR88n1OW/o1GHDJ1BHRtHkiR2+yuWbMe8jYpzTy21Rg/FHJzr0s0ryeHk9F4 r7FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710823157; x=1711427957; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TCcPcWRQCvkbSDI9YFfpJrZ4gRBUtJwDb7Mt4FY2BYo=; b=ny+20ERWjR2tdWUyN810sasfe8/naMf3ePBVl343SQm7r8vA+hEpLfqroSjLDIlV0J rnFmfElw/HKE4ESWpC6+mItpU4+B6En7w/VOWpplshyjz9EY6lu1orpop0Xe+M631aJp gFDghhnf2X5aKJ7fYn3yBRVUy3hhcWb7ZQFPI/Bp2bUFMx+Pa70bgNH+M67HIBkQV7FA mJ/N1AtNPpIYNZqgU/AK3UTbYltVebKDlgEoMk8iZfpFphYJ8rEIKyhmJc6f4O06eQS1 v3cI9O/7eevmTYXXKzNhUCSv74VkCo7OhwpWf2CaBe/++0B9OmuehmgfHYoeQadyAjlZ w8Zg== X-Forwarded-Encrypted: i=1; AJvYcCXTWTk0bsoBQ0BVu6+xPorMRC4se55vBtGTTkbABCRBnbpLj0gcN1GFMfAcznFFuuFh2xC0anEUWsVoKabOEqdhhvzHcqI42LEOCAdMrWzxcLWlXXrcJKqGTAZ+u/HD5bQDVv0UVqbdJoMkByos05FH3t98wtp2YCGnm6JDFbVah2FcID8= X-Gm-Message-State: AOJu0YzafC/gRAG7/YPUBOSFfDVfwAV/grJmPHvX8zQoROhXX4L54knZ kro6Z81819hFTUUd0aizvkbNCnBAWH6AFKFMJw48UeIkJcFpjore X-Received: by 2002:a05:620a:44d1:b0:789:f2fe:4ca1 with SMTP id y17-20020a05620a44d100b00789f2fe4ca1mr2543239qkp.52.1710823157671; Mon, 18 Mar 2024 21:39:17 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id m22-20020ae9e016000000b00789fa326156sm1925414qkk.82.2024.03.18.21.39.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 21:39:17 -0700 (PDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfauth.nyi.internal (Postfix) with ESMTP id 823F71200032; Tue, 19 Mar 2024 00:39:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 19 Mar 2024 00:39:16 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeekgdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtjeenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeegkeegtedtleffkeeftdevleeuieduveejgeeikedvgeekudefteefieei vdeuleenucffohhmrghinhepghhithhhuhgsrdgtohhmnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 19 Mar 2024 00:39:15 -0400 (EDT) Date: Mon, 18 Mar 2024 21:39:14 -0700 From: Boqun Feng To: Laine Taffin Altman Cc: Benno Lossin , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , stable@vger.kernel.org, rust-for-linux@vger.kernel.org, lkml Subject: Re: [PATCH] rust: init: remove impl Zeroable for Infallible Message-ID: References: <20240313230713.987124-1-benno.lossin@proton.me> <93FD9491-7E2D-4324-8443-0884B7CFC6EF@me.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <93FD9491-7E2D-4324-8443-0884B7CFC6EF@me.com> On Mon, Mar 18, 2024 at 08:17:07PM -0700, Laine Taffin Altman wrote: > On Mar 18, 2024, at 10:25 AM, Boqun Feng wrote: > > On Wed, Mar 13, 2024 at 11:09:37PM +0000, Benno Lossin wrote: > >> From: Laine Taffin Altman > >> > >> It is not enough for a type to be a ZST to guarantee that zeroed memory > >> is a valid value for it; it must also be inhabited. Creating a value of > >> an uninhabited type, ZST or no, is immediate UB. > >> Thus remove the implementation of `Zeroable` for `Infallible`, since > >> that type is not inhabited. > >> > >> Cc: stable@vger.kernel.org > >> Fixes: 38cde0bd7b67 ("rust: init: add `Zeroable` trait and `init::zeroed` function") > >> Closes: https://github.com/Rust-for-Linux/pinned-init/pull/13 > >> Signed-off-by: Laine Taffin Altman > >> Signed-off-by: Benno Lossin > > > > I think either in the commit log or in the code comment, there better be > > a link or explanation on "(un)inhabited type". The rest looks good to > > me. > > Would the following be okay for that purpose? > > A type is inhabited if at least one valid value of that type exists; a > type is uninhabited if no valid values of that type exist. The terms > "inhabited" and "uninhabited" in this sense originate in type theory, > a branch of mathematics. > > In Rust, producing an invalid value of any type is immediate undefined > behavior (UB); this includes via zeroing memory. Therefore, since an > uninhabited type has no valid values, producing any values at all for > it is UB. > > The Rust standard library type `core::convert::Infallible` is > uninhabited, by virtue of having been declared as an enum with no > cases, which always produces uninhabited types in Rust. Thus, remove > the implementation of `Zeroable` for `Infallible`, thereby avoiding > the UB. > Yeah, this works for me. Thanks! Regards, Boqun > Thanks, > Laine > > > > > Reviewed-by: Boqun Feng > > > > Regards, > > Boqun > > > >> --- > >> rust/kernel/init.rs | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> > >> diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs > >> index 424257284d16..538e03cfc84a 100644 > >> --- a/rust/kernel/init.rs > >> +++ b/rust/kernel/init.rs > >> @@ -1292,8 +1292,8 @@ macro_rules! impl_zeroable { > >> i8, i16, i32, i64, i128, isize, > >> f32, f64, > >> > >> - // SAFETY: These are ZSTs, there is nothing to zero. > >> - {} PhantomData, core::marker::PhantomPinned, Infallible, (), > >> + // SAFETY: These are inhabited ZSTs, there is nothing to zero and a valid value exists. > >> + {} PhantomData, core::marker::PhantomPinned, (), > >> > >> // SAFETY: Type is allowed to take any value, including all zeros. > >> {} MaybeUninit, > >> > >> base-commit: 768409cff6cc89fe1194da880537a09857b6e4db > >> -- > >> 2.42.0 > >> > >> > >> >