Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp138742lqt; Thu, 18 Apr 2024 10:27:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUUJoJwC5VCetLxmHDf0sDCZT3oYuTOvVoaOu6Rt70rSYCOhAvn9BPyoPpzBlGO3TwfozIMoaMzl1Zm39x+cr8rtQG3aFoOF9Ptgj1P0w== X-Google-Smtp-Source: AGHT+IGqr2XEZ+ftvRIBF/+NfO/AwiPCGshoo94MvIBUhHkWoGSZfybcP5ILMrrXicQH6fEFIlRv X-Received: by 2002:a2e:9dd0:0:b0:2dc:b4f7:dad9 with SMTP id x16-20020a2e9dd0000000b002dcb4f7dad9mr685093ljj.34.1713461237342; Thu, 18 Apr 2024 10:27:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713461237; cv=pass; d=google.com; s=arc-20160816; b=0EIQSCZ9tjUgyQG2jaD0uh4Hn7tqncbTb7V4yeiK8pqf8BbKehnLt7/ozP76xztNdW vd6RrUd79dNWsnYia9DErpe3pkp5W69Zs1s2rbKJIXFNREPdbxs3lRNSKjvmnXWN8Pac YYS7ZQ4F7XGyU4Ibl6FS+hSMzFXbsQLvrs4TSsvoE4gIp9SqtJHF65A3qSjZDlwKslMV gqeJtqT1f/nBX76Q5GE32bj/OOJXt1ZG5tUUqLHyS52Fgio57zRzLgkhhPh8ujlUIxfK 6bRd+w+gptGuHSKFS/aAN5obe5XOOUozyfbqJLqfinWFVdO7ExLOEJChEEy7LM6mTTW7 PP+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:feedback-id :dkim-signature; bh=lKzOdELtr17UxT9sbgBt88s9IxuTCx7orfaIApRzVA8=; fh=edwgixKx/qsty0V7+SGaa05HGTRCk//CtVJB4oVPwFo=; b=En6MqZRkgdE2UidHXUWSopXL+HuITLFrGoqJNhYAFODlMNR8yM24xSKOiITiaka1xe zt3YAJdz6LofveQlzkI6nbUOPrLS+dyA7we6gup4v84Uo+6EqAK2KUSYfGqbJnapuLjk 7/0NcIfyEwNhCS2dWVIJOcdPh7gIq74Z0J77aWBCj4h32/niXWYJ+K6mgU92waUtDC4e 3wYAi4tJP486b8IOFfLhowWvcazX2k6Bo1X8wqLnjEh3fElPmbLPzXdgYnZ6malhCCFh MPY5xZQljlCCCfyU6DSkINLkSNV7cDgv8Gpqo2Cn6TK3DyI69N1h/qLKxswCACXFQqa7 SWzw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lg0GAjAm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-150569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id t17-20020a50d711000000b00570b5eac86dsi1092031edi.141.2024.04.18.10.27.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 10:27:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-150569-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=@gmail.com header.s=20230601 header.b=lg0GAjAm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-150569-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-150569-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id CB9E51F22A27 for ; Thu, 18 Apr 2024 17:27:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7D68174EF1; Thu, 18 Apr 2024 17:27:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lg0GAjAm" Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (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 5B37B172790; Thu, 18 Apr 2024 17:27:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713461228; cv=none; b=ahjXVxWmlThKI5qQPgHz2u1eGhs32VIrnBBGTgCc8p61j8INWN95jzb81zWUzdivTtk0t0/+FHWq8GvsYwiY6PD+6xmMLy8SBlDYOXeRko7dIVsrUfRmBCWI0DYAaHyHFXjfu6CX1B6VvkisLuOZP6FAM5XmyU+NauiEe2Ecu6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713461228; c=relaxed/simple; bh=rP0Xkz7LY/9paQcIY9KIgH2ieBP45u1ZxnYsJw7BSs8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BcFbfS+FM/cKCeGYRppAbmiaaRwHe4AmhwCJ1Mt1rqlhGJiChBmcStW3k61+UkuGL0Hcnffr9Pf1iOGPerWnS2RJr/7rqT3Sk0WfEuY7mQ3rTMoVQtZNCkpK42Y08P9WwvFXNvXqvI3B+yhUl9OaObGGMyKV+0NBatS6HGafEV0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lg0GAjAm; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-78f049ddd7dso74104485a.1; Thu, 18 Apr 2024 10:27:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713461226; x=1714066026; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:from:to:cc:subject:date:message-id:reply-to; bh=lKzOdELtr17UxT9sbgBt88s9IxuTCx7orfaIApRzVA8=; b=lg0GAjAmQzQeMPryoqa2Sa0BbFcbTt82hSNl50zMplaIioPdXtyGzEN2IW7/7Q4Cu/ eXcyyhcSC80o2bzYHEDAfaZQVHRHS9QyYht6VkHKeYPm52Qijl2LVjeXLUBDIEBcTqIj /nbr8KGa3eYTG+XCe0wbT45pMoKyFojnxNuQEl0t61/lmd2/3vrhDbJXRAsJh43CO4i1 lw/m0Ydx5QSd5MjL9r7jJPipATkiEDPss9S3dKG81LtZKG2nTofx8DAEg/+phQzmghD6 u3Fwv+wXC8xVPtSxIuaEjobcKOE1ky/NT6+g8ajqETrLe6D3DJju5xMh/uU5Sy86ZYz2 odaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713461226; x=1714066026; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :feedback-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lKzOdELtr17UxT9sbgBt88s9IxuTCx7orfaIApRzVA8=; b=RvhAH5ie6MqzarIigxopb44VbcPdnfBIatZvDoLW6UOt8BOBLia8vLsVwImwR8mNsS zTM3IyeAy5z/HDP/sGdJy9lhFn52L8YrpU5ylMdpJs/GgAqTvD3dbFQ2KNYXc8HpjgN+ rMCbuQz0xKycxbKqfefxnIhyixnHOhTuZmVkuHVYSi0ajLliRdOaP9Cv9kz9VFFKihKI /LOPF3ng+cCOA5ngfCvqkdeoxtwgzMxOA2L6D6h0N9fijtNmEDlwRUSo/rD7GD1lH9t/ iyBeCODRtBYeJqVHmvbvSfkekJlsh+8gyLbQOL5xFSsR8aAGIGYbxQnDHowEb3IznFdF QyRg== X-Forwarded-Encrypted: i=1; AJvYcCXGvKE+C3ykYg+W2kcLiUooISvfeCfhV1eVji+TQZjj85AsDndw+bypDWVn1uFTki3XBaBEyHPgjsntaOEPtwKk/7aAYQ5wI5G8y259i5T1q2riB1/m+smMnUQWjbtB3t2ZHcyrVCq98srEgvU= X-Gm-Message-State: AOJu0YxCRbTLYC7Dzlab6p0AyKMQen49vGs7+tNsyzgVb6AJ5WFRmJhx HDuVWEN0VrqUuRg0q5tP15/E6LUIoPP9ZiPU7XPWB5yK7p8xFQLZ X-Received: by 2002:a05:6214:b05:b0:6a0:583b:8cc5 with SMTP id u5-20020a0562140b0500b006a0583b8cc5mr1986476qvj.33.1713461226239; Thu, 18 Apr 2024 10:27:06 -0700 (PDT) Received: from fauth1-smtp.messagingengine.com (fauth1-smtp.messagingengine.com. [103.168.172.200]) by smtp.gmail.com with ESMTPSA id d27-20020a0caa1b000000b0069b1db7b0f8sm819856qvb.23.2024.04.18.10.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 10:27:05 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfauth.nyi.internal (Postfix) with ESMTP id EEB73120007D; Thu, 18 Apr 2024 13:19:52 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Thu, 18 Apr 2024 13:19:52 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudektddgudduudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtjeenucfhrhhomhepueho qhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtf frrghtthgvrhhnpeevgffhueevkedutefgveduuedujeefledthffgheegkeekiefgudek hffggeelfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpegsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeeh tdeigedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmse hfihigmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 18 Apr 2024 13:19:52 -0400 (EDT) Date: Thu, 18 Apr 2024 10:19:28 -0700 From: Boqun Feng To: Benno Lossin Cc: Alice Ryhl , Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook , Alex Gaynor , Wedson Almeida Filho , Gary Guo , =?iso-8859-1?Q?Bj=F6rn?= Roy Baron , Andreas Hindborg , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , 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: References: <20240418-alice-mm-v6-0-cb8f3e5d688f@google.com> <20240418-alice-mm-v6-3-cb8f3e5d688f@google.com> <5fd684d8-d46d-4009-bcf8-134dab342322@proton.me> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 PM 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 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 not 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 here. 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. Regards, Boqun > >> 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]. > > Ahh that makes a lot of sense. > > -- > Cheers, > Benno > >