From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-10628.protonmail.ch (mail-10628.protonmail.ch [79.135.106.28]) (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 1CFBB224236 for ; Mon, 7 Apr 2025 20:18:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.135.106.28 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744057116; cv=none; b=QMNCQxv/xjbBdVYuAPZZjHGrY/wNO/cyYfCsQLWEcYkcuP8TR+KH95fFWJp1kxp3qP279QEylofEw4uOlMi29d5JDn3l8wIzGQ4K/yGLuGhbXrxyY09MNemMvtJ+Z951C3J828tQKuYxL6sXLdnHwxNgiDyO7/xJx5JIOPcUcdY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744057116; c=relaxed/simple; bh=pokdKQsoUfnHlCVbA/BSywoVD9+PRKu7nsKM8bDuwE0=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XrVdey5tbycmQlSAgulfChAySqCR9CKlRVfoT6IEh1Z3UJ8/Pz8jjM4wUg0EDDy32lzWZNHclfjj1rjsi10RqIHWTpOmlVSqSQksA6mWAoqRAXj64ZgIs1UQiCPI5fII+Wg72t5QqvaKErLyka0j4r4OLuWoisPLtegTzNrmYeM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=FlsLcZua; arc=none smtp.client-ip=79.135.106.28 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="FlsLcZua" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1744057106; x=1744316306; bh=snP7gjeU3YyTTNo+TLTC0FBLFD/vHl4orLCkPUeZL/E=; 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:List-Unsubscribe:List-Unsubscribe-Post; b=FlsLcZuaGEuaWUe0PL5wi854eOh8FJJN2ySPbXr4wOCHLW6i7W1cGp9Bkd3PcywF7 EwJh+0A/NRYRJsc0zqaCQVWB8obQIkosoaget0F76DGeHbIP8o5z7pLJ/ks/AUh8fs aC3CS8FRu2yzbS69DziJjFL3+DSgq2nV/uuUwkKaU9nYjEXKJtNXB2kRyaa9m3wnTc 974DAEPNOOOKhujhsBBop1NUHfTZmVA4Q5tmqUk/u9kdFzCGChioT2Lqn9vMe3IlT2 2Qsc+orVStcTQGLkzOJXGMu4Q6BkIQgz+qRDJHU6s604EiVd1fMlpaCMmSiZeA6j7C pHvKst7UjDHJQ== Date: Mon, 07 Apr 2025 20:18:21 +0000 To: Benno Lossin , Miguel Ojeda , Alex Gaynor , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Fiona Behrens From: Benno Lossin Cc: stable@vger.kernel.org, rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] rust: pin-init: alloc: restrict `impl ZeroableOption` for `Box` to `T: Sized` Message-ID: <20250407201755.649153-2-benno.lossin@proton.me> In-Reply-To: <20250407201755.649153-1-benno.lossin@proton.me> References: <20250407201755.649153-1-benno.lossin@proton.me> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 47c13476485a5c2e470f2c3ccb770f4ab4d68301 Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Miguel Ojeda Similar to what was done for `Zeroable>` in commit df27cef15360 ("rust: init: fix `Zeroable` implementation for `Option>` and `Option>`"), the latest Rust documentation [1] says it guarantees that `transmute::<_, Option>([0u8; size_of::()])` is sound and produces `Option::::None` only in some cases. In particular, it says: `Box` (specifically, only `Box`) when `U: Sized` Thus restrict the `impl` to `Sized`, and use similar wording as in that commit too. Link: https://doc.rust-lang.org/stable/std/option/index.html#representation= [1] Signed-off-by: Miguel Ojeda Link: https://github.com/Rust-for-Linux/pin-init/pull/32/commits/a6007cf555= e5946bcbfafe93a6468c329078acd8 Fixes: 9b2299af3b92 ("rust: pin-init: add `std` and `alloc` support from th= e user-space version") Cc: stable@vger.kernel.org [ Adjust mentioned commit to the one from the kernel. - Benno ] Signed-off-by: Benno Lossin --- rust/pin-init/src/alloc.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/rust/pin-init/src/alloc.rs b/rust/pin-init/src/alloc.rs index e16baa3b434e..5017f57442d8 100644 --- a/rust/pin-init/src/alloc.rs +++ b/rust/pin-init/src/alloc.rs @@ -17,11 +17,9 @@ =20 pub extern crate alloc; =20 -// SAFETY: All zeros is equivalent to `None` (option layout optimization g= uarantee). -// -// In this case we are allowed to use `T: ?Sized`, since all zeros is the = `None` variant and there -// is no problem with a VTABLE pointer being null. -unsafe impl ZeroableOption for Box {} +// SAFETY: All zeros is equivalent to `None` (option layout optimization g= uarantee: +// = ). +unsafe impl ZeroableOption for Box {} =20 /// Smart pointer that can initialize memory in-place. pub trait InPlaceInit: Sized { --=20 2.48.1