Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp623374lqt; Mon, 18 Mar 2024 20:17:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWEJHek23r0J1i3WByTa+8Y/Lb0PbOFesrzVU4MST6WNMgQAltbYaoqHKyed8o9+S0y6yMUTdbQ3WJDFu9CAVp7ddzNpL/2agWwsgiHsQ== X-Google-Smtp-Source: AGHT+IGa6catlknylaMolUDrqh43UgrE6SPRBBl5G4CSZq8EDTFgTHjJmV3oNPjW1O9a6LRackjI X-Received: by 2002:a05:6358:9898:b0:17b:f2ae:e561 with SMTP id q24-20020a056358989800b0017bf2aee561mr11546877rwa.30.1710818256350; Mon, 18 Mar 2024 20:17:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710818256; cv=pass; d=google.com; s=arc-20160816; b=TWdj0Fbs2mLaxkG/l9fVg+JXckDmFr67d7mN8pDN/XIHWfXcp20eUjScUWyxi1SwyZ 1opT76+9dfFO2GUntCN+74FmOXvt4IyN1TZm5jWVLAegAOXgd2G7j7WkwKpLnttu1KH8 f2nRXofJFZVpFl4P3t33BU1oLsmoTqJhCvGan8s26kdEoXz9QNdR9k6iNykc93KFKBX5 M/JCOjrDL3NTVn0W5Y6lND6BERXGpIcehFWvJ6+ryjRe3a7MJVeoQsFzyeubM8kew9wH 8/QncH+fS9fLFSZw+/lsRmVTKDhkGAF5hgLIYD6aRyKNwvn6eUvjoalavWwRlG1FPHt1 URZg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=XGDkgB5unVzSxGvf5tmV1LkBUwsiz/E+a+Vzkcg7yZ8=; fh=TNyF3oxKIzpm01mnQdLx7Q8Wxal7m82g68bFWMjUqy0=; b=cCJIAWk/F/3m+ZE+PLNKAbk7DlSKYJtYeJR6Mfodauk2CuaKEi3nco7/hPWyKgAZJv jy3XsVXYeUVgAuVd9aRqIyAz++uoP2vyKE6rCLodcYg13UUGwSl7jqeLkFw7qsRK+wvF YwapK6Ne30wyV2f959gMyvyklwHOHLCssW3IpuI1MdvCrJkaMGWfjrDMeaGGZMpWfm4J hG5zF/9F4YBSNO1CzNsve1HXurlhPkUyF1O2AD8uhuz9mkiIoOS8sYOVNA++xBmbIp06 95RSlAvPA2zeNZu0cI5L4iaAaOF5Ql7WjT6zF467COVtj4ayGqxf6uw27bA90J5Bg8WB pnJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=PvYy4bbC; arc=pass (i=1 spf=pass spfdomain=me.com dkim=pass dkdomain=me.com dmarc=pass fromdomain=me.com); spf=pass (google.com: domain of linux-kernel+bounces-106957-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106957-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id j8-20020a634a48000000b005e49cde1b64si9166020pgl.190.2024.03.18.20.17.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 20:17:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-106957-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=PvYy4bbC; arc=pass (i=1 spf=pass spfdomain=me.com dkim=pass dkdomain=me.com dmarc=pass fromdomain=me.com); spf=pass (google.com: domain of linux-kernel+bounces-106957-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-106957-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 04C3B281E0F for ; Tue, 19 Mar 2024 03:17:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9E7677317D; Tue, 19 Mar 2024 03:17:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b="PvYy4bbC" Received: from mr85p00im-ztdg06021801.me.com (mr85p00im-ztdg06021801.me.com [17.58.23.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5540B7BAE5 for ; Tue, 19 Mar 2024 03:17:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.23.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710818246; cv=none; b=KVFwXuj6c59OVEqLWAmjPDM5oZyg3/8e3NKZjPyyJtRveP/iF2fedeIG7T/HqImxR8yHVIF3bmJ4NvTdVPp5c6knGBGtuf+MSYOPk7sfeC+2HCby4435LIo90nUzwbMaa3LJ54LIHR9wiYj/XTXKws5cM6ca6qcV/+VnIuzir1M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710818246; c=relaxed/simple; bh=zQcc3jxKfVQ2PUuIjCsWgbLI7wBdLmJQ1WeBWFM1saU=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=o4DQCpwu+ziZ3rU+C+8J8K/E9UZOLSQUH85qHt4ka+RxwPlDgsNlajMypDh0Nbf5UZeysgDYvM8VnJwUSVAkJiPwEDvMkIysjj40h1naaku/Omwfpv2jO9JHwwIOCvw/dVJcC9nLQPjen1D+MsxE1DQkLY6y3n/uYH/N7uKdxRQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=me.com; spf=pass smtp.mailfrom=me.com; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b=PvYy4bbC; arc=none smtp.client-ip=17.58.23.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=me.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=me.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1710818244; bh=XGDkgB5unVzSxGvf5tmV1LkBUwsiz/E+a+Vzkcg7yZ8=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; b=PvYy4bbCdIXJWEwsy5MzB3cS6Q2JH23hg2zSzb0wP995crx2HGDsoT5tt0orjuzeW sngf2Sq35dRa8qRBDxYQgnDG7704KtQIxIdUlv8n03bmsM5/LpGSQ+Ig5bA5EebZsF HopdNOzwTsjYEcnI6Kqk5/7IkZB87qlY4EOw24KryPQJiiYIOAhU/RiBjrmt5S7+Qi O1stTmY7I3pf7wyZYw98UeFtLjxy+proH0bLWmzwUcnX0iNjUk4+ZRTUD9SvhP2tzT tk6eeqrRhLsHAaMskdBg2RN6kzXcBrXPqqnsXWFSh+T6/fj5Ic7hOh8a4fYro5Bdvn yPqJk8wSimveQ== Received: from smtpclient.apple (mr38p00im-dlb-asmtp-mailmevip.me.com [17.57.152.18]) by mr85p00im-ztdg06021801.me.com (Postfix) with ESMTPSA id 2527DD001E7; Tue, 19 Mar 2024 03:17:20 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.500.171.1.1\)) Subject: Re: [PATCH] rust: init: remove impl Zeroable for Infallible From: Laine Taffin Altman In-Reply-To: Date: Mon, 18 Mar 2024 20:17:07 -0700 Cc: Benno Lossin , Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Martin Rodriguez Reboredo , stable@vger.kernel.org, rust-for-linux@vger.kernel.org, lkml Content-Transfer-Encoding: quoted-printable Message-Id: <93FD9491-7E2D-4324-8443-0884B7CFC6EF@me.com> References: <20240313230713.987124-1-benno.lossin@proton.me> To: Boqun Feng X-Mailer: Apple Mail (2.3774.500.171.1.1) X-Proofpoint-GUID: 0yLkaEkWSF4_UXEdezHhbfjnJH5PAumf X-Proofpoint-ORIG-GUID: 0yLkaEkWSF4_UXEdezHhbfjnJH5PAumf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-03-18_12,2024-03-18_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 spamscore=0 mlxscore=0 clxscore=1011 adultscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2403190024 On Mar 18, 2024, at 10:25=E2=80=AFAM, Boqun Feng = wrote: > On Wed, Mar 13, 2024 at 11:09:37PM +0000, Benno Lossin wrote: >> From: Laine Taffin Altman >>=20 >> 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. >>=20 >> 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 >=20 > 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. Thanks, Laine >=20 > Reviewed-by: Boqun Feng >=20 > Regards, > Boqun >=20 >> --- >> rust/kernel/init.rs | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >>=20 >> 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, >>=20 >> - // 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, (), >>=20 >> // SAFETY: Type is allowed to take any value, including all = zeros. >> {} MaybeUninit, >>=20 >> base-commit: 768409cff6cc89fe1194da880537a09857b6e4db >> --=20 >> 2.42.0 >>=20 >>=20 >>=20