Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1303971lqb; Thu, 18 Apr 2024 06:19:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV0U9xx/m7LfCmb10QeQBvwgz9qkn2Ie50DpsP2IUKDxw82/fRFurBobArPSNR39lwFdwQ5bDUMpooO+qioZ6y6uSgmF2ZaTkQsVxhETA== X-Google-Smtp-Source: AGHT+IGnN4sfi9WsBMiizpZ62KVdaF4cvWy3pRfuEoNKdqjQLr+hBDRuSMV5yN5tc5dwOJkD2+9D X-Received: by 2002:a05:6870:2308:b0:229:ec0e:7348 with SMTP id w8-20020a056870230800b00229ec0e7348mr3357307oao.46.1713446363137; Thu, 18 Apr 2024 06:19:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713446363; cv=pass; d=google.com; s=arc-20160816; b=mCedzFSWJzu3k9ehlzbfwuZ3VgRtn6WF3dLKWSUhzkaaWNyp9AVqreNLg7Sok6fGQf zj6CbHlqRkeRQfKZJDbbV+XTWLo5nyLr+YBtJqhKFC+W4y9yFnQ/lMxoqIS2zPTiphHs zDrxW4ctb135/gPccYydKwMvzPPqS9lZWirr/4IMXZ/7Ye6RQjT4yTGOGj0ElPxYRihg 0ckYZYAV+8+AxTiYOMmxmwdcjNop8FN6PEwNKl8JkC2mfgVXc07wKWx4McmUzlCwCyhA R8RuB7ym5Z+fp7eibDHHy4GKQ9+8I9VRQVlWNnNjZsPMA2ahfCncq+Mtatq4ivp3+M5p VUpw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=TNRbWAZ6Q5MqN+iLHn0qNU1jdPOPQHBoqFwuo6lZ8Oc=; fh=Gs2CYjaWqTqcAL1t4MDBAQUXd1HLL4emXRL1PGLJglw=; b=gJQq3q8UVs9k/9AKUj+Sluw+if74Q4A03ELp5xHdnDb1/CqA/UaYvf7mxNxWwwVjib RPKCzkGkxQ4BSsrDooYGMOVX57zpthdx7BsVlMVB3GvXkTvNJI9WRC7tZ2KauG79r2UU z0YtCfl9mDE3XyehVGrYMCyrGmfTGOgaCWpFUEDFEU6+nqwn7MIVIsOLdal3QU6M6eEC 4IR3js1c5deQHQmowtchoE1d14bkwUBu1vQ7wucFP7n9fpC6/jBwpnU2HzxwS3qCc63l JHNR3LxrZwNWU+b78nMvJ6kkAma8OMXqC87dOeuwHH4pBlo8RHpa973pbxGV8i5iunfy kLsw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tFyHH5p3; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u32-20020a632360000000b005dc855c40a4si1373430pgm.645.2024.04.18.06.19.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 06:19:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=tFyHH5p3; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-150149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 4E7DA2849C9 for ; Thu, 18 Apr 2024 13:18:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 880FF15FD0D; Thu, 18 Apr 2024 13:18:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tFyHH5p3" Received: from mail-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 AC96215FA6B for ; Thu, 18 Apr 2024 13:18:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713446286; cv=none; b=XPSL3vGx/y6RdThUVtwwJxGa3BtrKUCeMH2FbBFGX0hDPrsOVtyhKvR8etmhnw9s404zPSeadmstA+XacGBbEPcUdab/tqDd5RK9cxZXi0GVzlcCCzn4hsF3enlm4kUCqaBJciE+ctItIpLJrpj8IUAp0ubffrXDAUvYQXevaxw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713446286; c=relaxed/simple; bh=g0lDcg5sk4wjgWLkv294Wu+ievcxVOJOIGYTzRJialY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SepEtUH30itq2Cc0uU8iDJwNUbT2SsN4YDbISJEV+PGmBu7/e709bZkMtPHowT3xPuxrNPGcnqZ2rbv0fZ+OXvI7NkbvAiaYAW2o1a3yfjLnueOX7eDkxr4cuHN8WYp0Pcl8fbhGvn/AliVI+L8SiXEJ63Qs30ePhwSwuJbvWzE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tFyHH5p3; arc=none smtp.client-ip=209.85.128.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-618769020bcso9053447b3.3 for ; Thu, 18 Apr 2024 06:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713446284; x=1714051084; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TNRbWAZ6Q5MqN+iLHn0qNU1jdPOPQHBoqFwuo6lZ8Oc=; b=tFyHH5p3JQxDb9pVBlV7RW8DnMEMtJSJTzWVUaWoBUQYgmr9G8wovoubNwfsbK1od3 1Efg2QnShvFAC+csWW+nG7Zyq8/PfKJ5YQ4h/7GAkjF7RLdbqgc4OACUHzfOYYrw52DH /ZTqmcSzosWRqRdtUha3/eu3dnfB8z/UrS47uv/wiuHZdYz8BqcaJSHxcLrhIwL56mDD rH3w2zUdGC9yQLridnhBrOc1TAhUqCe2u0o9GGsdIYmVSLRW72J1wrPwcVrVLPkDIkNP MJczmmgYwVeM+J8zOCnmmS4hlDEeMaTo5c5VaVfsh6jwvVirJ2a23U/2yYDLfkPRtcL1 bczQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713446284; x=1714051084; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TNRbWAZ6Q5MqN+iLHn0qNU1jdPOPQHBoqFwuo6lZ8Oc=; b=TjcGUO8ini1EvGNBIOe41nnioQrYMVOijHCMC/PSXvGp+Z39/UYT2zX8KqLvrxmnbN zrDJCyetDfebwDyDrEr+k4ZznyLzZTlF+S9XFqap+ZpUq+mV3Vnn1Wl5O4dTJVnnz80/ RtqNeErcDRn0DPOv0dzGD8Kk4g1vQdzjljGb6yqmIDdrKkkTabkyxJwNt2oEW0y0U2ij CC8OMxq2B6zmchvx7IhqMb5YSXPP0eiKlxB11TQzipZcZ9IRnEz6mOvIFnccHC6wndx4 yvfEWoo4dD8LqXFBoJXIA0/LcGVYmNEmg6aHJwcWqJ8HqhAOPJgbTD+vsfDBmRUVpXtT v+zg== X-Forwarded-Encrypted: i=1; AJvYcCXdG85MlIi1SNszc6VXKXVXK4pmKYVtX4IOcALfOx1k0feUkWvXfOrttSdmNucS5eHXGG8+kWAPUMwy1MwuR6/02Z1oTNFCGa6lncNK X-Gm-Message-State: AOJu0Yw65UrNme+yf31mvW6koM7BS3Up2RU5rY8mI8bVfTREjpzhvuh8 FmAH4tamsvIwQDocpqLtTLPNrcS0a588HukGmuLbTo0eIKvHsvbwonfcO8dP2L+h3ba2qJWi4h0 reaSxmL+ha2B6Wg5WlP7No6z6clhCJ+uXuyW3 X-Received: by 2002:a05:690c:6206:b0:61b:1be9:bbcb with SMTP id hl6-20020a05690c620600b0061b1be9bbcbmr3057153ywb.44.1713446283553; Thu, 18 Apr 2024 06:18:03 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240418-alice-mm-v6-0-cb8f3e5d688f@google.com> <20240418-alice-mm-v6-3-cb8f3e5d688f@google.com> <5fd684d8-d46d-4009-bcf8-134dab342322@proton.me> In-Reply-To: <5fd684d8-d46d-4009-bcf8-134dab342322@proton.me> From: Alice Ryhl Date: Thu, 18 Apr 2024 15:17:51 +0200 Message-ID: Subject: Re: [PATCH v6 3/4] rust: uaccess: add typed accessors for userspace pointers To: Benno Lossin Cc: Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?UTF-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Greg Kroah-Hartman , =?UTF-8?B?QXJ2ZSBIasO4bm5ldsOlZw==?= , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 18, 2024 at 3:02=E2=80=AFPM Benno Lossin wrote: > > 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 typ= e `R`. > > Right(R), > > } > > + > > +/// Types for which any bit pattern is valid. > > +/// > > +/// Not all types are valid for all values. For example, a `bool` must= be either zero or one, so > > +/// reading arbitrary bytes into something that contains a `bool` is n= ot okay. > > +/// > > +/// It's okay for the type to have padding, as initializing those byte= s has no effect. > > +/// > > +/// # Safety > > +/// > > +/// All bit-patterns must be valid for this type. This type must not h= ave 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". If T: FromBytes allows transmuting &[u8; size_of::] into &T, then it would be a problem as you could then use it to modify the original &[u8]. Alice