Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp660283lqt; Mon, 18 Mar 2024 22:29:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVzj4xFv07UJUD6ndPMxBYhaIZ8FznsNNlXbGhxTZA3BSpknZGE7mHIEh366qso00eeo24jUtqt7R0ZtwSuw0zoD7NWCH59n18jjI7J1Q== X-Google-Smtp-Source: AGHT+IFA0F+vtRvDTvoqdHOdosd/F+RY4/GkbgwSQA/YtLtouOH+IQD+c76Owi51kXv8Bazl3nqW X-Received: by 2002:a0c:fe63:0:b0:690:a66b:268e with SMTP id b3-20020a0cfe63000000b00690a66b268emr1439894qvv.57.1710826142440; Mon, 18 Mar 2024 22:29:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710826142; cv=pass; d=google.com; s=arc-20160816; b=JboeIKXqvfyERCY/czm3jXJsjkOaTAGkuBEqoKGre4yr+Hebpbh8hKoO5zwZar55nv fcHMmODuByVoIMGaPX731auZS/HbkEx+/HcuJutn/4w9CZbOaV21lpQCVjSGQJxWb7zx jqckSDiZydNEVHNw0LYL4t0+AmjxmFIN1A4pmyibcNzWrELErTQu/HOIlU14n6bu49cP N58fIVryIvxjpZIzRx2TYmVBydWhcgp1OgB3fUqB18dSSb+TCojPPbqUqCKrYZh4fwNu ihlbIRss3feVgqHfsUyHKfkKW8Mh9tQOmbzVUSE55v8Qyh7IcDeTG+YLCl1Mzb7wRcBk 9xtQ== 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=jtDAYiiHKEo7z1XIeH+DbE76nJx6PwjxTaWNlxP+9zo=; fh=TNyF3oxKIzpm01mnQdLx7Q8Wxal7m82g68bFWMjUqy0=; b=ckjaZVki6antuH1UxCviLVHK9GBqKxSOeR5ODCnIxsBBZpZ21k6Eky4KzNxsoVHQyf MhdRiIzqBvrTDs7lesnVXkfdmhekM61yZm8ay99Gt+ysP4vN3I3S9EHtNUS46smql6tD Ouv54wQjw+RNiyxnEMv6EsKcjnVqTuCOpAsRNWOwZ3T09ezEPyuslMJtximX+EWPE9L+ WruDG5qBvDEMJ+NPD1KphimkdaHH0LmoBw25aIScF+2G7fZBo+O6x0wdGcQzLz+K1MNF 9ZfoqEbOlOyc3Lg+cK0VL6DnHmMcDtBRFPzW61oMczz+irfpHaNvED9SOzvAzlGNVoK3 Qx5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=k4dXykRg; 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-107009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107009-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=me.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jl7-20020ad45e87000000b006918279e149si7784882qvb.112.2024.03.18.22.29.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 22:29:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@me.com header.s=1a1hai header.b=k4dXykRg; 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-107009-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107009-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 30F2E1C217D2 for ; Tue, 19 Mar 2024 05:29:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C6A78446A9; Tue, 19 Mar 2024 05:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=me.com header.i=@me.com header.b="k4dXykRg" Received: from ms11p00im-qufo17281301.me.com (ms11p00im-qufo17281301.me.com [17.58.38.50]) (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 8BFF042062 for ; Tue, 19 Mar 2024 05:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=17.58.38.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710826133; cv=none; b=VD6wLun5tZqnoLGN726PRjPER3pQWTk17b9pqcFXN0bdIWmKoPyb5KNzwxsiXXNYkKP7XxRaKe80zpvtXT/tUmWYK5/4OGxiL11AaOwh6vZovbdU+NxlZOPhXqB3MU6bjtrAd5LL1g8JbnBgapXqzgia06bRwzyYoMZiTIdCZEo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710826133; c=relaxed/simple; bh=GQ69sst6KtWZRI9xIfR8OlxbHRzyV2W310g5+1K6fxg=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=W4Sj3SibBOTbAoUCaUVYlmbZE2n2FhlhvCU65RYmS9OQ7JfYmAowhT8ctrTaEmtyKab2d/3YIS6xF2RooaduPhjg+lNSjMJkj0T/M1bTC3JAvjGsdvt09GyXpQ42EfhAwGU8ABMrvpned9BwGgnBo+J5zII4tWHiOXv4Zvh28hM= 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=k4dXykRg; arc=none smtp.client-ip=17.58.38.50 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=1710826129; bh=jtDAYiiHKEo7z1XIeH+DbE76nJx6PwjxTaWNlxP+9zo=; h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To; b=k4dXykRgixbyPj5jQHYrHy0Oyj/E+OVV9OpR33I95R43Jtb7zwE4xphgzFNEN5rLK 3ZmtWQUzHd6vCOcWexL+Wos3ZV3RzRb4c0OGzuMsY7epNElCLfcCvByXuzDA6zuxZd 5MAIRcEDa5u9KE7abEPH7EQA1L9pgvZcInSf1N6S8mFwEz75HkqEO/c/E+jSODuO1p pJSgRWIwzZgWFnHjrFrCFN7A9+tYWtksglCjzHi70XNls9c3uwQ4b25R50hn/lA3dc hP8SkSOr3AmOWaFNXf8mSC6XR18CH6G7BYnQjEcmjPgEPEfy5cUuofm6+QHw6L2C4x eIoCmvXuAuhvQ== Received: from smtpclient.apple (ms11p00im-dlb-asmtpmailmevip.me.com [17.57.154.19]) by ms11p00im-qufo17281301.me.com (Postfix) with ESMTPSA id D0D40CC0180; Tue, 19 Mar 2024 05:28:47 +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 22:28:35 -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: <3FBC841A-968E-4AC5-83F0-E906C7EE85C3@me.com> References: <20240313230713.987124-1-benno.lossin@proton.me> <93FD9491-7E2D-4324-8443-0884B7CFC6EF@me.com> To: Boqun Feng X-Mailer: Apple Mail (2.3774.500.171.1.1) X-Proofpoint-GUID: JV1TEgZWRV4Q51EWUDIrXol7s29j4YsT X-Proofpoint-ORIG-GUID: JV1TEgZWRV4Q51EWUDIrXol7s29j4YsT 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 spamscore=0 malwarescore=0 phishscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2308100000 definitions=main-2403190041 On Mar 18, 2024, at 9:39=E2=80=AFPM, Boqun Feng = wrote: > On Mon, Mar 18, 2024 at 08:17:07PM -0700, Laine Taffin Altman wrote: >> 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. >>=20 >> Would the following be okay for that purpose? >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >=20 > Yeah, this works for me. Thanks! Great! Should it be re-sent or can the new wording be incorporated upon = merge? Thank, Laine >=20 > Regards, > Boqun >=20 >> Thanks, >> Laine >>=20 >>>=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 >>=20