Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp209290lqt; Thu, 18 Apr 2024 12:38:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVWq8iOX5nym32h1o9dnwCOe16o8bgfByoCnIvBU/QoaT0sd+OvSkL5eekU3vQG6sRTSiWzKOojJXeVoOrqB+aOF98RYN6SnkXh6N/ajA== X-Google-Smtp-Source: AGHT+IEkUpYZbk+3lDrl6GfbiYoH0gQzw2CuR3lj3OAGY/6xg3zsAeuZzeB7z5BAJuvBKStEr8M2 X-Received: by 2002:a17:902:db04:b0:1e2:c8f9:4cd7 with SMTP id m4-20020a170902db0400b001e2c8f94cd7mr42385plx.64.1713469097613; Thu, 18 Apr 2024 12:38:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713469097; cv=pass; d=google.com; s=arc-20160816; b=sGC/PcaUny6/nBM1kni61bsAN4mGn7M7h9VzqQTANiOXWVGP2K+YKQgmapAZiawbuK CRZJqIBdbyyluUSydpA/5s4Y2itxeA4fujzhemnmZAKC4YKCzPauj8CCDW/QqxKBT0QY ps+uQMSn0tk82r8vlAiUEJhc5Tysm9Gi46one9vvXmB5Yr1XGnI/tabayp83l24vvZAQ BnjDtxYa9t5w9tqGKyTKQVHdnvelQ5IddcJRUQ1vX70H6LYQXV0ApgfAYUC2B8fw5SGr ZFTIk8wYeN8Pt78HqMAf5VsDGJFoJutyuM106YPmry4a1hc7czhHxSQw1fv1VYqeMJ+Q NO+A== 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=LDw45IBLdxhM9LjWeyHX6+dY7iByC19AmUWN5RO+9ZI=; fh=EoYdeFVbURpuk1hukFBCoUjb8U1TeGiMHimCHVHzLT0=; b=zvHSxdWnH2RR9HFn3ap8UCFG6AJlKfuHgOV/oPIx80CuPbfh/b9HtLFtld01V8/IDi a4UDetLhBw49o4rrSFAg61q4UW6ufeyhfPbVWeOBhvD43HU5u+ow48Rw/m718FiRh6J3 NQ4I6R9JEodKTPZKe21cuXkp7ra/BVpLl9WMnP0T1T25hdE8I2GDWgLQsU4GVoAGJvIj AfZz5vedWYNsRFe0AYpMyC0WlIIu/TyHewGHaRYmeLmgg2HMxA7wg1CfjqlspBxHAZqr /hmqMMPq2NvSAi405FNbReKY+G+RLPDKjJm+f/m8yqov2N9PyvuwqmpdtogYh1qNBK3x uGBw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="necsN8/n"; 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-150677-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150677-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 u10-20020a170903124a00b001e2c6dcbf62si2055467plh.215.2024.04.18.12.38.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 12:38:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150677-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="necsN8/n"; 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-150677-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150677-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 228D22866EB for ; Thu, 18 Apr 2024 19:36:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8A1D1802C6; Thu, 18 Apr 2024 19:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="necsN8/n" Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (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 8DB5B179204 for ; Thu, 18 Apr 2024 19:36:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713468968; cv=none; b=q1MhJARjk87nVJPqmqleUqMbbESJQ/G4wiplmJEaI3Z8f+4LrlJESiRpwxmJnqPueiTuFWyGXPeXS6ICp39I6QF4UhMi4ezcgfpwI0ZKgjbGjjOyvb4pluw3lXqTJl879p89TjFRTsMHzU55xhcR1HwHRaJjE/iK2gMXMsM0fI4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713468968; c=relaxed/simple; bh=4wnmGBPm7QXnFuYr3SnHPxOZEt/EMqUAhmJpVbdQCQY=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UhcdepDtWSxCg2GU33ARyioQqsEwua4/Mvybcg3up6L4jBXjAu5pzmPb94MwmoKQoMkKST53pr9hpvZ7eiUraF4dd87SiJjlAa7Bn8luua3Ch8gb/ZPS1Us01Lcp6774pxYLuDO0MiIDdhXggNPGTWCB96A8gRhvHuwoQa8ahFE= 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=necsN8/n; arc=none smtp.client-ip=209.85.221.181 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-vk1-f181.google.com with SMTP id 71dfb90a1353d-4db27d21a22so352506e0c.3 for ; Thu, 18 Apr 2024 12:36:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713468965; x=1714073765; 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=LDw45IBLdxhM9LjWeyHX6+dY7iByC19AmUWN5RO+9ZI=; b=necsN8/nbNrlCCZ/hWYYg/qlHEzSSUAe2ndDeoK2YUvEoNjFpGYUGIb1Ks+8yz+E4d IybkuIIq/E2x5W7AyKJsXul0NafZ8e3MMYgsMss8gthbxtJpY6qlP5U9+YAekULqwyJp YSMaWZzfvnm2x8IYWItnempkbKuhDYBxcdm3aEXWwt2P7BIgL8J3XY5SPwyiXuGwQ44g RCyGCIhk4ZNEiQ3AATvSL/gywd7E0OsmAOkNybQr7UgdfAclUNZLfRU8C8U1Gmp8iPGr qIlOCRqB1dUIcXnAkGU2yaHeFFk/fDf38bsX20d6jDJBWLP3qPzRhsmpY6TOhSKzeqRJ LQIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713468965; x=1714073765; 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=LDw45IBLdxhM9LjWeyHX6+dY7iByC19AmUWN5RO+9ZI=; b=iQCOQZvQnWoCDAWiC9bF/HgBjVuMYN27pstrzDa2piIswS4uDLOpnwF9dodcQqGAIR A8oLxU8h8DrVURfn1en3MAtJvP8BrRU5DE5XKYtopxBBZxNx377CvisDb4iqkcsPpSur ioNZXUvmcbMSniwrhzNX+21zTl/5zy6EAchNt9wEIqj9epRzmt8EU3w4m3ehKars5jXf WKfsYD4XbElfyGdtMcSPuJ3D+Fi6SAu4htgVXJrC33P49xzzTx335FpiBNs+6sFsRLb5 5TIneTXOXxTXQ9JhHEOA3dt1S9zy4C9i0vpCJGhTPXRlpxZ5BwFqW2GpV+c/s0S/8y+q oYYw== X-Forwarded-Encrypted: i=1; AJvYcCVXmB1S23+D+ar9mXyck3iA9uQ0ZYHICUIiCUMXxlTRwrIzVgzBs2IR+qcN2kV8XB5Sj29b2mST3Ky5r4CLnY4ivBDaFDKKZAGb1QKP X-Gm-Message-State: AOJu0YybwSl5qGgo7X88IrSfVFVGHlWdssBJ+GBZCsOtLN9mC6RiHW4g E6Ax0a80rkXDBTAzsr2H0VLZy4TpIP1RrJMkC1g19EXP0xa8+xWbWtNkYVvngBDFNKTdt0biIh8 tp0tCMjRuTspZzzfB73URvLfV67PHwL/WMtbN X-Received: by 2002:a05:6122:178f:b0:4d1:4e40:bd6f with SMTP id o15-20020a056122178f00b004d14e40bd6fmr4926638vkf.10.1713468965153; Thu, 18 Apr 2024 12:36:05 -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: From: Alice Ryhl Date: Thu, 18 Apr 2024 21:35:53 +0200 Message-ID: Subject: Re: [PATCH v6 3/4] rust: uaccess: add typed accessors for userspace pointers To: Boqun Feng Cc: Benno Lossin , Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook , Alex Gaynor , Wedson Almeida Filho , 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 7:27=E2=80=AFPM Boqun Feng w= rote: > > On Thu, Apr 18, 2024 at 04:23:06PM +0000, Benno Lossin wrote: > > On 18.04.24 15:17, Alice Ryhl wrote: > > > 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 o= f 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 be 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 n= ot have 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 her= e. > > Hmm.. technically, if the interior mutability behaves in a way that each > byte is still initialized during the modification, then it should be > fine for `AsBytes`, for example and `AtomicI32` (implemented by asm > blocks)? Not making any change suggestion, just checking my understand. No, that's UB. When the type is not interior mutable, then any two loads from the same immutable reference may be assumed to return the same value. Changing it with an atomic would violate that since the value changes. Alice