Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1097502lqt; Tue, 19 Mar 2024 12:33:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXKSBH9P8FXBh9BCTih6f4sWBgL4carsRvP8cCx6Bs4sMiax2CjDFEg4ImQQsxxJHwYV0rIccQbyNqtHXsXxJ725DD3tr5Jb8SA0DlVUg== X-Google-Smtp-Source: AGHT+IGlr7XvhEYy5mKRVtMoNp1qBUwQQQoNMjtubd9BP9alqfIa4TlRJ/NSg/lGD/CSgPKgOFci X-Received: by 2002:a67:f848:0:b0:476:5b1b:b109 with SMTP id b8-20020a67f848000000b004765b1bb109mr3171747vsp.17.1710876798190; Tue, 19 Mar 2024 12:33:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710876798; cv=pass; d=google.com; s=arc-20160816; b=ju4mdlTPARbgUQpK6E2Yj/4Fufe0Dmn4XD/VuzbfDOtG9jY6xLjYM4UD0914vE9tcl h4eGI5V+PuuHIZhf0qVrMuwpGFJj9elWwnGvzFzRkCk7OoQ7c2AzAn7LQImqwS+Jxr0K VoDLLNc4rtigq5j0iJiwzc+UNubPgkKLxUp01ydC+919D8nNUG/26sTVOLRaLE9gi4Su 134Qd/qVr5sB5HoQXPlDtXqHqfkqrt8d7xjHA4zybfDujLWjyiqlCw+k15oQWEQ8qacV EGpnaTukp/WA4LtoH4yKi2adm/l07TzhELsk7RAgkwXqLofz+u1Xlon0JSYoyApSN3/g S5iA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:feedback-id:dkim-signature; bh=FYOLOG9hKOFqz5xSRG6U5vM/st2PrJ7TeyrVBhptWm8=; fh=3TB8PB2YEexnQF3akI2+xjcUYH3kJC45FTjspAldr6M=; b=p6OjKQv3Wps9UVjjWRaIY6qXZHqTlg1LvaiR5w27dq1NNX62mxG9JNDwah+SGX94e0 mOl702V9j/Ye+kVKaLJhlpD9KoNJGB0YxWK9HZcpxnY0wjJzIiw2H3PRjRk4LbdyykBb kEL3uwp+9VSUihJOwDcsUbFDIkNTNSifkj6S/hRRh22sIJL6UsfK2KWFdG1NodGY6DhP +BGSOkRbwKRNOnt4zFBAG8NSsWBz+TjT/0n/gJzOpSOz431VVKSlhoHIE0mH76lgmPq9 x+FmERx31Saysgv3JBZnNNnWzb5daRqwuLY+lICa5EB+0WJZygPpoVJyhanBLtHEWcNi cIQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fWv7ep4E; 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-108067-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108067-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id eo6-20020ad45946000000b00696160339bbsi5496257qvb.551.2024.03.19.12.33.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 12:33:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108067-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fWv7ep4E; 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-108067-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108067-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D07511C22ACF for ; Tue, 19 Mar 2024 19:33:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 25E443D0D2; Tue, 19 Mar 2024 19:33:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fWv7ep4E" Received: from mail-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (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 9FFD93B289; Tue, 19 Mar 2024 19:33:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710876789; cv=none; b=n5nkBqaxlcdXDLs/dUb1q8dUjsycdsCjjwlPei+nmgGQwzq10kLlARwXLafu85nRAjXHBrInwzMtfmnN5qllh5czLLrMxhdOkIlQFzFZbbKmwvMjthcQb+BMlRsHPINcAXa6CR0G5SiIGtyjs1j8IgETZlMd9ieoJNJsYVZGAEw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710876789; c=relaxed/simple; bh=4rFd3TVErriJNhhMqeXGwN0oupdCKObtCaZ2O17N7qE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l/XbC9HubXwU7V6cF8bjLUCwZvqGkdZf0bvFptn3KK128xFf0386/hp0nmqYYKYUkap1DsTmrUNo8Knkn/ZeIkaSQbYp1wDJKjd7MhlaSrglBpeO9CclLqWoX+Ck0u6v4Fcu/mkH757iVj+EjsjmHQDE+rkhV95d+5wfpvB0MsM= 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=fWv7ep4E; arc=none smtp.client-ip=209.85.219.174 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-yb1-f174.google.com with SMTP id 3f1490d57ef6-dcc4de7d901so4768419276.0; Tue, 19 Mar 2024 12:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710876786; x=1711481586; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:feedback-id:from:to:cc:subject:date :message-id:reply-to; bh=FYOLOG9hKOFqz5xSRG6U5vM/st2PrJ7TeyrVBhptWm8=; b=fWv7ep4EoFUgpJJ+fPoZcdGGmwjcJTpWd3SgoK3V/DJxMbhdI9Z8eyX2kiBusBZnew 1T/cZQv614spd6VEpMCvam6XLewbMBaowV5g6jJg7/d3uNar30NyN6JJSXbZ0kHLnf23 SXydERphui/JQ6m6h1VsNIoFyDkvNyMzOsTCljh0Qvp6ukYdzB+BUPqYoKhAtPH8tFru CX1JLcojzycBlq8eg+eOY6EeOk0EeZZnrnJiUHDeTPkxsdAjZ+FQCy8iIY0g3ZHKTOlQ YqXmYpc7rn8pDBL8bnqYhe//yZKkOkCZvuKDZvlujdkzMHpLvaEVtdTQoLu+lvezIK3c +wOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710876786; x=1711481586; h=in-reply-to: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=FYOLOG9hKOFqz5xSRG6U5vM/st2PrJ7TeyrVBhptWm8=; b=eAQW3YgfRelddAQr7l43JIcXacrZK0AfEtGITXsogxGYRqfsLMQ5ZBldY6MmuA8Mde Nvp2OV7Kyp+l4hvHdmdxkDe7fszhwx5KYhceuNYFbV5zM+uUx1/BLTHBdd6tt+sXyuj6 /pocqvB+g0clArjY6OkajhPLSXhUXd+qT69orfVDElIXLFNpDNubqcEZPbqywf/f7pI2 AH8ZPzcGVJKR+vylkIfnXdgmdES+CMrqh2PR/zhIyv1CFhOsweiFbj1rf8wrOTdOJ3yL dErWvPf9B5pHrdA66VwxQgAP87xmDe1YPvOQyzNG7k3makyt5eEPDWxEvhESCPl9kBwX eBBg== X-Forwarded-Encrypted: i=1; AJvYcCVKKhXuPc+yn7Oc2Sy14BODWAKXswE3BhfnSXEUwW1xiO+jZ/o/+d76y707OgbsbQuCtbl0N6Lm4sEbkkP9C6oE0BzdTAGbLq4pyiPgr3Le5d0H/cHb8ESYIBE1sMQ3Ht4zmwqXLqNLZ9tVEl8= X-Gm-Message-State: AOJu0YzySy1yeV/351sxyoweZMJgqt955A6IfRN/SP6qleLgSRwroaFr oLLrAAB5cApuNVrq7xkDhaQSIb94pblGCpnLiO3r83w2NLBrDmrH X-Received: by 2002:a25:9388:0:b0:dcd:b034:b504 with SMTP id a8-20020a259388000000b00dcdb034b504mr2781428ybm.27.1710876786538; Tue, 19 Mar 2024 12:33:06 -0700 (PDT) Received: from fauth2-smtp.messagingengine.com (fauth2-smtp.messagingengine.com. [103.168.172.201]) by smtp.gmail.com with ESMTPSA id bv12-20020a05622a0a0c00b00430ef755b74sm639052qtb.27.2024.03.19.12.33.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 12:33:05 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfauth.nyi.internal (Postfix) with ESMTP id EC3721200032; Tue, 19 Mar 2024 15:33:04 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Tue, 19 Mar 2024 15:33:04 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrledtgddutddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomhepuehoqhhu nhcuhfgvnhhguceosghoqhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmqeenucggtffrrg htthgvrhhnpeehudfgudffffetuedtvdehueevledvhfelleeivedtgeeuhfegueeviedu ffeivdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe gsohhquhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdei gedqudejjeekheehhedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfih igmhgvrdhnrghmvg X-ME-Proxy: Feedback-ID: iad51458e:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 19 Mar 2024 15:33:03 -0400 (EDT) Date: Tue, 19 Mar 2024 12:32:50 -0700 From: Boqun Feng To: Alice Ryhl Cc: 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 , Benno Lossin , Andreas Hindborg , Greg Kroah-Hartman , Arve =?iso-8859-1?B?SGr4bm5lduVn?= , Todd Kjos , Martijn Coenen , Joel Fernandes , Carlos Llamas , Suren Baghdasaryan , Arnd Bergmann , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Christian Brauner Subject: Re: [PATCH v3 3/4] rust: uaccess: add typed accessors for userspace pointers Message-ID: References: <20240311-alice-mm-v3-0-cdf7b3a2049c@google.com> <20240311-alice-mm-v3-3-cdf7b3a2049c@google.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240311-alice-mm-v3-3-cdf7b3a2049c@google.com> On Mon, Mar 11, 2024 at 10:47:15AM +0000, Alice Ryhl wrote: > Add safe methods for reading and writing Rust values to and from > userspace pointers. > > The C methods for copying to/from userspace use a function called > `check_object_size` to verify that the kernel pointer is not dangling. > However, this check is skipped when the length is a compile-time > constant, with the assumption that such cases trivially have a correct > kernel pointer. > > In this patch, we apply the same optimization to the typed accessors. > For both methods, the size of the operation is known at compile time to > be size_of of the type being read or written. Since the C side doesn't > provide a variant that skips only this check, we create custom helpers > for this purpose. > > The majority of reads and writes to userspace pointers in the Rust > Binder driver uses these accessor methods. Benchmarking has found that > skipping the `check_object_size` check makes a big difference for the > cases being skipped here. (And that the check doesn't make a difference > for the cases that use the raw read/write methods.) > > This code is based on something that was originally written by Wedson on > the old rust branch. It was modified by Alice to skip the > `check_object_size` check, and to update various comments, including the > notes about kernel pointers in `WritableToBytes`. > > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Alice Ryhl Reviewed-by: Boqun Feng Regards, Boqun > --- > rust/kernel/types.rs | 67 ++++++++++++++++++++++++++++++++++++++++++++ > rust/kernel/uaccess.rs | 75 +++++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 141 insertions(+), 1 deletion(-) [...]