Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp381283lqb; Sat, 16 Mar 2024 07:57:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVo+p7+CcwtYWigqW9euOEKGh/6TsAL2N9VLlYGszAez/DzvJSKimxsrlfkpVNia1pfE8R7EtmfARP3a4H/NIVjEaDBx4+6fUuGzlIkVw== X-Google-Smtp-Source: AGHT+IE/qxPr/XPmdz2jL82qg6s0qjkNGHxeY3Fbm0Hrk0QZOGRFLt/FLditYEUJMjuqEUC+Fnok X-Received: by 2002:a0c:abcf:0:b0:691:826c:2d97 with SMTP id k15-20020a0cabcf000000b00691826c2d97mr3733999qvb.14.1710601023355; Sat, 16 Mar 2024 07:57:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710601023; cv=pass; d=google.com; s=arc-20160816; b=s0AnrXZCK6FT1RXTsJlmLYKPSXkDGlWJHRsgl/ac+N7WIpPJmVrYvGxjW7m7Eh4oRA /Ge6wtfxbCCosW6+N6e8U0VzTo0OSkV8W6B4ca6c9Y8tNK14tMvsYIdYw4NmwxOnY9gA KtmQuvmDdfkQ60Q2esdIhCdGQl+UmTnP1RGYgAeuzUfA4tolV2z5WqIQbAokp6+EUJtW mTqkVlfOQU0F2gO/Y+JcVfpd3PLtKjzvNAFF+BwVK6i3lyiL3C70Q2cdiwm5cXfr4P48 cSDALm0P/r3kulbclOZwhRAikxLyqEr8AzoOM6kwnOMtp598Bkr1zbGhNnGqBX1eDV/g 6bxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:feedback-id:references :in-reply-to:message-id:subject:cc:from:to:date:dkim-signature; bh=aR8hRTDJ4hTgIYaydeSVXJDQzHAYa1X6w7iYETfJq50=; fh=aoT+X9RCAbIKa0qlkF90qoXBUnZoMuoqwPMFy3qYmW4=; b=r8i6KmqEOPen63hXYiF+0UBqn6/GzPQfu5WlzlQihAkOXtl3sgFVF5U2C8GKzBmXRH Rz24BXMVLQFnUmENlXixS1oab7ZPXF6zO+BysA69f865xf+jBPy3/zuT9ZFicaHZJrD/ hXosiG+whIxg9M+PMzf0zK+hxCMT3C0KnSCuTWPBqmGHpU+rairvAyVd0pdss3bIJVIr J9F3CHnRhH0q4NrKh892/GExyplsT+OhlskKFvujeaznIzcSv//u/O421bmVhYoqMVYX 2as0vaxXRyLRgx1MA9dVZzuCB9pZ/muCa8HGgm1eaJPrTdA7Kq4qVyQGRNaaMgIVXu9Q SoNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="m/VKuASJ"; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-105205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105205-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id fv1-20020a056214240100b006903c85415dsi5190428qvb.126.2024.03.16.07.57.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Mar 2024 07:57:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105205-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=@proton.me header.s=protonmail header.b="m/VKuASJ"; arc=pass (i=1 spf=pass spfdomain=proton.me dkim=pass dkdomain=proton.me dmarc=pass fromdomain=proton.me); spf=pass (google.com: domain of linux-kernel+bounces-105205-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105205-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 173EE1C20ABF for ; Sat, 16 Mar 2024 14:57:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6D5A61B59A; Sat, 16 Mar 2024 14:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b="m/VKuASJ" Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D235D29B for ; Sat, 16 Mar 2024 14:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.70.40.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710601018; cv=none; b=ieCY1TOSZVbSBqT8dwt4Jf1rlvSRc8Ei26zdsmKN/myacAP7x22mubYuzMjJhZnwZ97iUY7H7zDInMUH+ZdareHp47lpytBaZsCFXcKm+52OlrQ/tqypHI3xXX6ys2qnFPd9ZhTOduFPcDsBCjATae4IfLI2EkisF/W8iUakcuo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710601018; c=relaxed/simple; bh=aR8hRTDJ4hTgIYaydeSVXJDQzHAYa1X6w7iYETfJq50=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=kxhxxImmZnmQ/4mT4K6zAHpov7KalwyXfg7aImqIJDTcYg5dM7JffN3HyU5xydKJG9WWhyLXBRomApe92oL993tCsVLUXy/mOMs/kmcg3I2vT4tYegWw3EUr0X1/IDXYU7artgzjqkrsUiTaXlhjHVaQ1ZFGDc0K4aaRPKFRgMI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me; spf=pass smtp.mailfrom=proton.me; dkim=pass (2048-bit key) header.d=proton.me header.i=@proton.me header.b=m/VKuASJ; arc=none smtp.client-ip=185.70.40.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=proton.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=proton.me DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1710601009; x=1710860209; bh=aR8hRTDJ4hTgIYaydeSVXJDQzHAYa1X6w7iYETfJq50=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=m/VKuASJXwwnVqQACEPvl18cZBFzaSKlB7sM8uH/j5gY4nw5E9hGRK+T0vKQfpu3G 6VOvMXwJWTXqW4CamNaSMUey+ourE9ltMlhWEPG1RJSGsAKb9Gyr99Op0/3hW6gTpq C+GnYPz6qtNtXRH6k7E/C9oINuE0zroL3rHy7zK9SqHnOlPdFkIU+X38coCCzs1kmr W0PzA4yIDnvXmq+RgatQ+oykFs+gLlUYE4HAMP+1HEYkjC9SiGFjEGuDXgo3uy7jAc rhR9TyuaUdhtN9Lvu+k/wehKRFRBJ9lX9oeh7RuzM2q7rJA3YwfGjhvvi2gA9z1mWf hziN79QEGz18A== Date: Sat, 16 Mar 2024 14:56:20 +0000 To: Alice Ryhl , Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook From: Benno Lossin Cc: Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Greg Kroah-Hartman , =?utf-8?Q?Arve_Hj=C3=B8nnev=C3=A5g?= , 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: In-Reply-To: <20240311-alice-mm-v3-3-cdf7b3a2049c@google.com> References: <20240311-alice-mm-v3-0-cdf7b3a2049c@google.com> <20240311-alice-mm-v3-3-cdf7b3a2049c@google.com> Feedback-ID: 71780778:user:proton 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-Transfer-Encoding: quoted-printable On 3/11/24 11:47, Alice Ryhl wrote: > Add safe methods for reading and writing Rust values to and from > userspace pointers. >=20 > 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. >=20 > 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. >=20 > 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.) >=20 > 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`. >=20 > Co-developed-by: Wedson Almeida Filho > Signed-off-by: Wedson Almeida Filho > Signed-off-by: Alice Ryhl Reviewed-by: Benno Lossin