Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1298826lqb; Thu, 18 Apr 2024 06:12:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXaJCuo6T6RVQnH45oGnZsJT8cyUsxgRsPp7ISU7zVaIcCJyHuM5DnxmJ7c0hR9ufWwrOpmnq4RFaRJaiHclFJpBLw5iPRTmQiISXF/jw== X-Google-Smtp-Source: AGHT+IHLwd/8F041JRM8q24YQoo5/Jq7IGMrMGTRF5Z5/U6LEb96/vNfqNSGDSAs/F50xJfogDTG X-Received: by 2002:a05:651c:2006:b0:2d8:dd28:878e with SMTP id s6-20020a05651c200600b002d8dd28878emr1541009ljo.2.1713445946596; Thu, 18 Apr 2024 06:12:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713445946; cv=pass; d=google.com; s=arc-20160816; b=MdATS2tookN/gzcTtbNUF4bsa/ARoljjZ4PpeQYP+ioyDY2pSad/vinRjW0G5+9ixA 8VBuwvoGXY1YDMYt8G9sMp/atWNwzppkX+dMTwnYVRJ1paip43uvkQzEJEk6NPNQqrhJ maVV0K8ze7V1VGi7d/sJIEgmaU38MWWYRS93EdgSW+XfPC8pANL30YD+uAEUOIhjPvkP Sm83A5Ge3+zLOYfWZUa5+3hF6omlqX7wa1xpVwb2PHdfV4Xz64cn3hLJklaAQobAyJfJ AQsrwLjGJAEsWDJJ7mMdb+jebySZ5DeKVctinslboUAx0w58HqZbfDPPWV6nYNB7m1MU yo4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=ABmUIlM/+0TTsmSAW6kea20HyxX5pv8vg2oi+dkTWWw=; fh=OhM5+xg1Q9xej/VyWqJ5MGdpM1PY0h2j8mGGtn6u/ZU=; b=TGKA/IiNuctoZ4aITiucN6qGRw6jMD+YGAqI1vXC4+4AQQFZfo2h8LM2qKkQ6YRE98 UhIlEaaF/Yi9WAuX1H/7dqHKlKSGUk19dXUa3JnP9DNUqwhx7G0vKqRLcxvIju93MpR5 eebzbvkJnzN1dt8JK/xlt2KdnfdQhmKLef6khzOz4tPgldXne6s/9aF2NBtLhO6Pj/CQ B/dHVJmSc27i7sRqnV2ZTgTABwwRc07qT0+aMA781KxsDGgbzPPifR7b8l7llG8mz5sW RTNoTRWH378i8qRrWpeV+0iBSPobwb3Z+dbPyrm9nIyRDBV2dI4GhBQWUbfmTnjkaF7M QNXg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=RpVqEyPH; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-150126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b9-20020aa7d489000000b0056fdac47fa2si880291edr.80.2024.04.18.06.12.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 06:12:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=RpVqEyPH; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-150126-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150126-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 737CD1F25CA8 for ; Thu, 18 Apr 2024 13:04:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E612160790; Thu, 18 Apr 2024 13:02:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="RpVqEyPH" Received: from mail-40134.protonmail.ch (mail-40134.protonmail.ch [185.70.40.134]) (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 095F315DBD6; Thu, 18 Apr 2024 13:02:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713445341; cv=none; b=mPzAnEVGs6EQxc2YLWVmVLgzhXfFMR+Mvz7C8iqpnsnanKPs+NTQ9WTf0t3AGt9q7ZhILJjk/mFFfWSSUet9GpMPY+uG4QER8NlYca0+6NdzrM8pmqhulDsDDLj2CL5rVKUAX46wqKwgAQkk3gxa0xe4weJuFaSYdRbEsPM5qHQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713445341; c=relaxed/simple; bh=wNhnXhJl0BimI0FnxrFsan2/eQTs5jA8t+ECKzsx8yI=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RCDeFAdOxb0UnixZqfamW51HZPAMcnr0hX1GznqBnvq88f0zYy6NX5hTANw5nQsfr1RralHXegsMKQ02YHGszpwJknydUJ4fod6O+Kzmj37IE+omNgFpKOrMKgmwJW44rTahGm1UvwiwJc9LRcHj+Moe4q5T8qND9Z7eMf8YpXI= 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=RpVqEyPH; arc=none smtp.client-ip=185.70.40.134 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1713445325; x=1713704525; bh=ABmUIlM/+0TTsmSAW6kea20HyxX5pv8vg2oi+dkTWWw=; 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=RpVqEyPHGYdAeCCRn9WA4rKt34/0xi/epM4XaGUJRiThGqiJiC0GMruCZ2ZZOPAw1 l7ul+FmMjMNDUNdqq98y7CfOnwxfG4dHaiUvUXhjQyiSf6sUeYldhxnUdVL9doS5DD 3lS4z/zMb6f2frGgts8W1QFMvgKrrkZtwR5NPL+Pw47KNGWpSIBirIGKmiyvGvmaGF slX5qCs83Kgm4bkQrDQ7mh29h8FwC9wpkhb82MtJ6oxt3Ac5qWtwCVbAzBJvhVoSGN TSKzko6TxoCYdmqNSc2clKK/lI+IBIN4Q5tloLfaTo37hhCmABoLD2s9I/1YqFdGIh GUivWSumPFT0A== Date: Thu, 18 Apr 2024 13:01:20 +0000 To: Alice Ryhl , Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook From: Benno Lossin Cc: Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Arnd Bergmann , Trevor Gross , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Christian Brauner Subject: Re: [PATCH v6 3/4] rust: uaccess: add typed accessors for userspace pointers Message-ID: <5fd684d8-d46d-4009-bcf8-134dab342322@proton.me> In-Reply-To: <20240418-alice-mm-v6-3-cb8f3e5d688f@google.com> References: <20240418-alice-mm-v6-0-cb8f3e5d688f@google.com> <20240418-alice-mm-v6-3-cb8f3e5d688f@google.com> Feedback-ID: 71780778:user:proton X-Pm-Message-ID: 73974adc566aff94727dc6833659914e59314d2f 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-Transfer-Encoding: quoted-printable On 18.04.24 10:59, Alice Ryhl wrote: > diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs > index 8fad61268465..9c57c6c75553 100644 > --- a/rust/kernel/types.rs > +++ b/rust/kernel/types.rs > @@ -409,3 +409,67 @@ pub enum Either { > /// Constructs an instance of [`Either`] containing a value of type = `R`. > Right(R), > } > + > +/// Types for which any bit pattern is valid. > +/// > +/// Not all types are valid for all values. For example, a `bool` must b= e either zero or one, so > +/// reading arbitrary bytes into something that contains a `bool` is not= okay. > +/// > +/// It's okay for the type to have padding, as initializing those bytes = has no effect. > +/// > +/// # Safety > +/// > +/// All bit-patterns must be valid for this type. This type must not hav= e interior mutability. What is the reason for disallowing interior mutability here? I agree that it is necessary for `AsBytes`, but I don't think we need it here. For example it is fine to convert `u8` to `UnsafeCell`. Niches also should not be a problem, since eg `Option>>` already fails the "All bit-patterns must be valid for this type". --=20 Cheers, Benno > +pub unsafe trait FromBytes {} > + > +// SAFETY: All bit patterns are acceptable values of the types below. > +unsafe impl FromBytes for u8 {} > +unsafe impl FromBytes for u16 {} > +unsafe impl FromBytes for u32 {} > +unsafe impl FromBytes for u64 {} > +unsafe impl FromBytes for usize {} > +unsafe impl FromBytes for i8 {} > +unsafe impl FromBytes for i16 {} > +unsafe impl FromBytes for i32 {} > +unsafe impl FromBytes for i64 {} > +unsafe impl FromBytes for isize {}