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 ED02EC54E71 for ; Tue, 19 Mar 2024 19:33:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 06C916B007B; Tue, 19 Mar 2024 15:33:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F37C36B0082; Tue, 19 Mar 2024 15:33:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D8A556B0083; Tue, 19 Mar 2024 15:33:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C34706B007B for ; Tue, 19 Mar 2024 15:33:09 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8CEF1407A7 for ; Tue, 19 Mar 2024 19:33:09 +0000 (UTC) X-FDA: 81914786898.04.19C8C8F Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) by imf19.hostedemail.com (Postfix) with ESMTP id 7C2E91A0003 for ; Tue, 19 Mar 2024 19:33:07 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hZJKSR58; spf=pass (imf19.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710876787; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FYOLOG9hKOFqz5xSRG6U5vM/st2PrJ7TeyrVBhptWm8=; b=WS9PMj5oiktHcN/J7W255G9ACUnVTcn9vrRvV6WR91YXy6ITcY3ZBtqgAjw3Y0TgcIDyhP Iwuci8fyxYWUEBVj38AvuDdQ3+czto3H/4ACscbOfB+edUYmHmZqzidLKwzp2q19wLvBKp Y64XeSLti+RvE3JyUvZddentKaav9Rg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710876787; a=rsa-sha256; cv=none; b=03k92uQbC2mGiQYXbkXTWGw1nAhLZ+kcnFoAt+QSYDouBaiNmbH+SVh9gq1aQjmakREaGM xI+iR6DO8d8+aSACMM5bvvOuK1Uj2zPupeQJNeFfJoNVfHSxe7JcKQtv2qonSEGFcvmz1M p+rnSZxrzVBvSKX1dT11Zxayl99I3Fw= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hZJKSR58; spf=pass (imf19.hostedemail.com: domain of boqun.feng@gmail.com designates 209.85.219.172 as permitted sender) smtp.mailfrom=boqun.feng@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dcbd1d4904dso5896926276.3 for ; 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=kvack.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=hZJKSR58FK5Cf4zH7idsTOZvMB6hHWc7wcIkxxrryYZ7jDn2tQ7PdMGIbFVQYGxMxi 2YOei7/cnhpcomIomyRxEKUiqkyWCkpOWU1JjoOe8VDLkXoL4wfapkER3p1UiG+nDi6c NpfPMy/rMr+BtpSGXnC6Bbiucg9bkxXcx54lSgjE1KBFf3bXOUXBHMO/r9TMtyBPZS3r r1WT08SL6n2ircZQ5d9iM6vQfd91bcmWKzK7PC3kfZtb6zviC+kNtxkL4F/w2H9VcJKW e51TtTzOhTGOkMVTBElFgOOTrbMZkqY+Roha93kzz+nZkT7YUeci210cknDY7mB1RKNh CfEQ== 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=Va0M6Dbcr1Qx1HwFKNwEaYrSENAi3bt2H1f4TSiMdsDUkZeLv3mgvqHr6XraJ5SA6C ZIDtpkZC86tQCPTiWJfsKKMxWfow6x323osINwFMhYl3V7hOJwkDPPkiuqoLdLFCEkz3 EdJ7MvHlnlKCac9efM4TFqtvqGCJAz5sw6/a8KnQT6Su6X3swVnZYhdsAByY/e5vmBYu HeiNLTGGMroqLfj0GJiB2yPVQfRo+su/X6yNgiaN2CRju//2XvrQACBLIXgWErzdVAzH GclYT4qL/kwblmXHwPSPfTSTggkdkLxmjnKTKvhWv6yVmiBIoaxPF8KU9s2AXM39f7HQ effQ== X-Forwarded-Encrypted: i=1; AJvYcCV9JLmls5KAVAmHBTgcBGkBHmxoIQnHdv+96xnrzT2wi/S/uabXbXojJ0kE5AP8ljY4yBrotkfy1Ci6V1CScbRK5uU= X-Gm-Message-State: AOJu0Yw9vFt5x9pY6bXenMo+/Qrnmu1BuuE9HX3ixs+rkC1yY955Cu0I ry74l6NsNGt9AIoNBe1uHAMg3LyucW8HfS+s/RelNy/LyTVmQinm X-Google-Smtp-Source: AGHT+IGyhzzuzo2fbeyEEutYpQHNHgNytYw/2oxy6RUhbTVX4Hwu18JQfDCF7UAcyT+VipOhCoHWnw== 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> 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> X-Stat-Signature: bykoaakby46uiftwqyosro5yzsr6ngf3 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7C2E91A0003 X-Rspam-User: X-HE-Tag: 1710876787-403893 X-HE-Meta: U2FsdGVkX1+70zEshdH6N0eyWtofTlLAh3jJe6TU6Yr+8GVTkq3Gaf+oGZczjfY0sw2Yq53CPVbzxAoaTUGuI8xFB5JJSaJUBznsmaIsZK3J7dZ6ljB9bd+QR6gHYVjyGwNb8xs4husQW4rGZPresmB2uBZxY7OVTmIpzzewBMi5CZvvoeX1099w3vVVcqEJoK/Fe5r5wHjfvBJrYHaoAbpmk8myLTzvhEmA/efogRgsXIBXfBLIIRRxjcBWPpWO8Tgz3kdddBm/Q5lL9fmPwJA94KBvBBlTnQWSelRdxICyCa38969LfT45yjypB2lt8g7/0yX51LTmjI4NZcgYSJpRc+YVYDjrqde0iDRy/yAflYFSde6VOGUl2bE2ifbUZwynjl3+1rJqCgjjuJl0W9VNVKHFIEBBqHPgLVXgFn1/PyKprsbRnlPwgv80Zdn6hfegrKK4dj8u30FnAbqbyb16yOGuioi1QW5htzNji2zrLVYXQehby7jQkhJi/gaRwhkkIPEM86elDtzt/ZcosPNiBSWQHrCySLaUhBMCML/251/tad/vlOwAR7C3v3LRjLQ8zZ7j1w90FLxUfO9EXywEye4lsmnngN8Vkh1AwKCN0v17ToSSIeMiq3J6145E2q8pU4RNI663MKmKK1LCDodxRr1wBjvtv6+L29Vi0yVoecME92U2/qR3t9dXh7xtp0JiHyX3QmDt0Tdgv86aIiOdm+Hw0QXaA5bNHdJ6p16kSL+nJfhIH4rAsDNwb21BP9TJH8R3NpYZKGOo4jlrbxKTSVaO6vtLtvsqxf2DmJYkivDJlwX2NuWxSjSUa3X3frSOEPA2yiX2P+0USlGieyADNkefKBtrJ7cIrWNly+1uzrf0IfjtwFN1fJCxPlrNx9E9ZRj8MeyzialRiKGNqAQ84JN0dzJXLlux4SekIf2QCcc9cmQmCZi+HIJZO8UWi8N3Fzo/7bgj56eURXo 4Xdl2lps 95414kPWqpsTNQHwNHelF1nIyJ16cGNTTCoLEDbm4ke+LDdNNpKcH5N4wahIyrTp3tQukXE3lMQJ2StEfZIoj+gvbMtWUM1LnAMQTK7COpsLpSGSIb2Pv72TrWBUu0jjV0zQxsKirU8cE2uxq1d2uDecg1SAtjq5hJ/f84i9X4EAw0W0= 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 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(-) [...]