From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 474AFC4345F for ; Thu, 18 Apr 2024 19:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7E0E6B0089; Thu, 18 Apr 2024 15:36:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B06B46B008C; Thu, 18 Apr 2024 15:36:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97FF26B0092; Thu, 18 Apr 2024 15:36:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 75DA26B0089 for ; Thu, 18 Apr 2024 15:36:08 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2E25681464 for ; Thu, 18 Apr 2024 19:36:08 +0000 (UTC) X-FDA: 82023658416.17.47D611A Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) by imf26.hostedemail.com (Postfix) with ESMTP id 68DE5140002 for ; Thu, 18 Apr 2024 19:36:06 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UC59Qbjl; spf=pass (imf26.hostedemail.com: domain of aliceryhl@google.com designates 209.85.221.175 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713468966; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LDw45IBLdxhM9LjWeyHX6+dY7iByC19AmUWN5RO+9ZI=; b=ktkX80MLUNDHhIj9jKoV1errp36AtJd4MjdroUDdJhHq6NX1HhFotstUYOxVkXixPQSBnq i+pYyk18foxvzTwQqEdTuAhB2AI5pEn6z1v/sjwAjs0MqqquzcVomhSdnIna5ysnQPvDZ7 Bi/iLLLAZOxBITY636KM4GkZeit6HR4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713468966; a=rsa-sha256; cv=none; b=2Um34XFM7YgRvNgWgS63gnPxPKJfxK8F+aCaU2Xc2BBSWd0RCgl2FOXw0JqCzS77H/7+t7 VlUWlwgChg9CLO8wtAwOLXW5HMnqtQSPPzdt7bl9MLplphT+x++rQaGi+RapaNI4jhhZGu sD1GLgvS5CgtCyDNnGhnnf0atGfe3yE= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=UC59Qbjl; spf=pass (imf26.hostedemail.com: domain of aliceryhl@google.com designates 209.85.221.175 as permitted sender) smtp.mailfrom=aliceryhl@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-4dac112e192so348325e0c.1 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=kvack.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=UC59Qbjlen4Dz/xvE79xthbZU2aVEDJ/xrQH4tJTXLgebe+T5NVBrD1iBuKzQuym8Z mrqMTwu/a/DgGsh1DaNDPgDpV5OTjDkFXv39AZT/9cPe8jxmMwn4QutR70l8bzsI49qM f738ZZlbV7OWHpKjQuRT40paR3NnEu4/T+vQvs5sKZ3HzXlSwl+PB/47xtVmEEIAr03I RFLHH4ZAteOrHU2+FuiaETpuolFHjA74bm5obEvxwEHoB33jIYWlg6bBm5NV34CO1tJ1 KHQRXshF7O7A/jCkyQ6YySKs9XF1gkHNgJpOxj08JZbrUUq5WxMm8DGsOjDBbF3CeJ1i YZpQ== 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=BFNrR8xYNzKdTfaskWNhCeVhzU5dZloANJaAinwd1UCfjxAgbS4jLKH/CWP9WLt097 JOxGCeYt8nK6620Kbf8GEHoaLizOLE5WTKovyV6v/6aiojBu5XdSlZ8NNjMBC1bApdHE NsQzvAE7yqOXg4QHwf6wHbj40ZOKFWVe6kzZPre5M7se9b7hIMGxaYVgijRIRMQZa7Oi o5mTIDMKvloLKk4aeAvdarhXSa1xu7bIdKAosRVOBH2vcOgT2USFopYh/Kzh5Aul9oA3 ku++HnQdWGK86AOa4YzJjIYDVdPw+//eQHLN0NRS8tKFvn1pMYRdQodeSeu6s6BIyNaX VdJQ== X-Forwarded-Encrypted: i=1; AJvYcCXu/294tHZRthKYr4J901NRvdaoxwp41C/1BksckzhKZ/KRZ094WhD0Zv0b4GdZzD8YANq0C+vDEUPEOI71X6gMJUM= X-Gm-Message-State: AOJu0YywpXAK4ufIFJPMtMj3UPqpSHV6YxeK0JctIO4h9d7jwXeQWFBx ulOWSb8r6ewS48QGRlUUnB05S9lYuF0hFyOf4W1wpi35iGOUQgA9Kbt/chS9vvTcGtck4EoyYHb HTDemq0nbXWAd7utSzJUBv7s6orWio+KyCq6j X-Google-Smtp-Source: AGHT+IHWSmA+AfhQF9/pyCrR3PIU8inWb525EGlHJDtOQVNbZNkBZXIDGXbngqcol+h71pHrWWwtbSq3HJMU/ZUYWPc= 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) 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 X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 68DE5140002 X-Stat-Signature: apch753k17wbkdux64ntojsmpr4c1xpt X-HE-Tag: 1713468966-152203 X-HE-Meta: U2FsdGVkX1/qkffe2PAdOlm9993a2G1lUApSO5oJwFaN+hlFA+F5gG7zs7E+DNcrr7N9sCAzNHbkgOtQP9jdrFs69QgGvf4rrty88flKKg3InLBA8Gt7ZZIfQ9Yh+TnwqzyzWYEbIkPNsLguIfpI9p2wvehJ4bkZTagxZyKmTrca+m7yfusrO2wXDUKIEPlQixqQ0mW/L2ekxK0b/eKZoEoC+N0vTpqZ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eCpbtEgowQN4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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