From patchwork Thu Feb 8 15:47:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13549980 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 902C2C48260 for ; Thu, 8 Feb 2024 15:48:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25F976B007D; Thu, 8 Feb 2024 10:48:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 20F5A6B007E; Thu, 8 Feb 2024 10:48:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D7E26B0080; Thu, 8 Feb 2024 10:48:43 -0500 (EST) 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 F0F4D6B007D for ; Thu, 8 Feb 2024 10:48:42 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C5042A0F58 for ; Thu, 8 Feb 2024 15:48:42 +0000 (UTC) X-FDA: 81769069284.30.243D78F Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf01.hostedemail.com (Postfix) with ESMTP id E4AF24001D for ; Thu, 8 Feb 2024 15:48:40 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QuKbgv6V; spf=pass (imf01.hostedemail.com: domain of 31_fEZQkKCBAq1ysu7Ex1w44w1u.s421y3AD-220Bqs0.47w@flex--aliceryhl.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=31_fEZQkKCBAq1ysu7Ex1w44w1u.s421y3AD-220Bqs0.47w@flex--aliceryhl.bounces.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=1707407320; 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: references:dkim-signature; bh=zhocXZ6cl9/R8sKVq7H2EWpDfoTTOkJP066TsAIK9Rk=; b=oipAJT2dLu0hyS59sqifxBcdWT2xyqizlQUUQ0/5/d/FjGjmS5cFQ+C0I2+m7CREORC2Np zO4nNKt7TozF7NNo9L3KK4agnXIxeCep3RKS3x2UTK+92kiTqSVe1bUkYaoGWfA2HaoL96 tDvD0gn04UE+QBzwQeJiF0p931VSk2c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707407320; a=rsa-sha256; cv=none; b=sma/1It2WiqjcOuyNDBU6ydXnObeaNXhFgKoo/zyprUNu/DgGltTrr6pJ/NItWdu14s/Vn tyggiMw/kY+0x21RgOLkv7V4g/1111I/WECjf0o7FInDdC0n2bs19YMMhbAToTEQ3gImnj IzlP2DlIQtah3PsGp3cU0/LBsS1KdlU= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QuKbgv6V; spf=pass (imf01.hostedemail.com: domain of 31_fEZQkKCBAq1ysu7Ex1w44w1u.s421y3AD-220Bqs0.47w@flex--aliceryhl.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=31_fEZQkKCBAq1ysu7Ex1w44w1u.s421y3AD-220Bqs0.47w@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6047a047f4cso49165037b3.3 for ; Thu, 08 Feb 2024 07:48:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707407320; x=1708012120; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zhocXZ6cl9/R8sKVq7H2EWpDfoTTOkJP066TsAIK9Rk=; b=QuKbgv6V1pwXXUXy3/uICmg1yCPSizJPiQQVwfwHb40rElud3Ae3Qy5jSg3vPnMWJT PTDCOsAJGtxtoKnaMCCfpatnYiKoI5IyIAmiIoepUb6XCbp5BqOponfjWZsw2+JOnBlQ Wx9FJ1fV2bldp7GodWvf1dLfLqdW8MjVnbqLasNw6cQnghCQNRPDXsDu0QlgrsoSdIgR mKAtYyY5ixHoOMcji+Pptdx4XUKWv4Wwb+EaWNsifXI10/nnJdk9I0XHvgGV5xLLazbf ax5QSsn88Zb/4NrcaK1dACdKh/ltnoQ4fclh6hCal52aN5aqTfztIPl/UAOrA/bO6pWw /SvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707407320; x=1708012120; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zhocXZ6cl9/R8sKVq7H2EWpDfoTTOkJP066TsAIK9Rk=; b=Pw1NuJgVUeRQxNkVNW/MLzm+7YCgZOveXx7XB2If+AbuokXoml2njDC3JJUjO3RQby /oDbKfXWBZghzRWFHF1pvhOwMS/wYym8TiWUn8OebQ7PMn4IdQGzIf/VDbiIpFe5s+DW a0wuHCXey61nF82PWjKJkKU7ztkWZ+MPMolMJEY0TbkHoEvS4km4zbpZDVR7toXBpvTy jE0vtlEU5tTCXflLN8q78ceMavHbuop72xHJuOb9j7H3GE2jopAa7uBtm24Ujkk6Lj85 83NIUyFIxTSk4x5AWiVehxNdU0E5sAVVdR5g+TtDM5Klo3RBb0QetZZp2XUZ21APgYge Sj2g== X-Forwarded-Encrypted: i=1; AJvYcCXx83oq89V/lvIiHmCw9IcxKA8tNJWdBFVHglNLvty5lXFl5+rlUhUa/RgKF61o5D3YQWdRa4tghuAL03lqsiwOdL4= X-Gm-Message-State: AOJu0YwcIjY1vFT6WxJz8cag4qNvFT7/ZNYAtoZlxXy7X7lIrXH/kf90 O7+IQoud4FvmhHHInNIT/dn5SEUgkDobgoCa3LUiE7vrc2EfSxamCbW2Yb/Je73XBh9+5VlUtza 93Oak4uXSk09bgg== X-Google-Smtp-Source: AGHT+IGB69IIhFNwxRPtvZcnZuA13Du//6/DSbGdfYAKGD+kDxJ1iEF81gU+wMSoEaws5eDyArLbmGlsrf6877I= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a81:9ac5:0:b0:5fc:d439:4936 with SMTP id r188-20020a819ac5000000b005fcd4394936mr1831732ywg.8.1707407319906; Thu, 08 Feb 2024 07:48:39 -0800 (PST) Date: Thu, 08 Feb 2024 15:47:50 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKb3xGUC/0XMQQqDMBCF4avIrJviJLFIV72HuIjjVAeMKUmRF sndG910+T8e3w6Jo3CCe7VD5E2ShLWEvlRAs1snVjKWBl1rg6hb5RYhVt6rgRpjbHMj5hbK/RX 5KZ+T6vrSs6R3iN9T3vBYD8TWqO0f2VDVakQ3EFNryNrHFMK08JWChz7n/AO+yW7goQAAAA== X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2872; i=aliceryhl@google.com; h=from:subject:message-id; bh=p4H6OppwPLzivo83Hr2g72Avg5StT4o8YtOOlH08jJM=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlxPfP5S5v2aYkxsj2q/BsmpS4ZQZHpliZ9Y9nN zdV3J5MPXeJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZcT3zwAKCRAEWL7uWMY5 Ro/ND/4l4hC9FDoEPydpei/6vNJcR8jmD06FC/VgU+GAa3Q5g4EziSs6o6T9aaQah9bAW2TRkQb Xx4btpXW8yE641R6Vtn9DwIHFgF0DsBPknXyUI3KANWo4QcJ8mt7moHllQyX/8Kh/nTv71rOTUH JD6SWPgSvqFEfS4BB81C7ypAlPPQB8GX0j/V5Hp9tI+4F/Lt1mtdo74KiB/h8d5mbb6ZJNByHDi 5Gx0qj4kldEFqb1f5n38/mRuVYDJdarqTmNr+Qk2lEw3E36d43Hab0hietJGpsmzF9lQlPnT0O9 gM0CgHV8aduedSp/wOb6OaYNmmW4rB3Qic+IkTyf6vdnSW1HA+eysjDPZnA5r+5He9mqDeEtkDN 22NQ7SajRh4JF59ueakxKXHs5nFef68LYntvHg4dyqKLVXX+31uqqUPbijmhFlRUYwGMd/aqRKm vjshrpPeZ+1v1LfsUoZWKvMlb+eN+nNZqAlR3wsdUz/WaXs1tjL3EvVRrwfN94bnOW6PFt3MTK0 DEvuw8hzkjMfSglFQa3zilwIZkGF+oDYg7YQwBit4xw4vTRTGlXzi7FSBYHjDyG23HtE6+QDZo6 lquy26SR5FxigoHSo9F5gJN7RkKarjuHd0a1wcpvAxqnuYF3fxlaOkcunuedbGO9yYsJVX615tI doaejU59PxEaQRw== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240208-alice-mm-v2-0-d821250204a6@google.com> Subject: [PATCH v2 0/4] Memory management patches needed by Rust Binder From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Kees Cook , Al Viro , Andrew Morton Cc: Greg Kroah-Hartman , " =?utf-8?q?Arve_Hj?= =?utf-8?q?=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, Alice Ryhl , Christian Brauner X-Stat-Signature: 71ytuqmc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G9tx3IVr6 SbQEbYFK VvCPgIOMhPVOtjT5pjvaaNwzNcPSt/y69X4swqntjqls6/YV3kFbZWVLr9bQkRjYkLL/ZTKy/9U1Ew36Gder4HYVaHKk8yzC4KT8xwleBRdXG5l+DOlQcGdLFf2wbhM5XpExFQCWFaLd7TvwFvGjiDiwUw0f/2mjYWNgJPc+jPCaMWYfzWJJq8ojiL2Uc+7/AIQ3GSnRI/MCVvjfAZA6RicukgPm9WfKTiMro4qMasOxeO8SbgfcdON9XtLzjI0wll/E636CUs6KeXEBQb46+xiwxRc6cla63O5gH759h+B7Camn+2A0qa+8Bnsxoj8hB4aFWlydAxba3aTe7un82YQIkIyc1McXjX0L/9rP6ziu2muqbG1j9YKKFML4ysKSgGPsZ1aDnTPzQG3RQhMB2Qprs/51RBuJ40HMoD5X5XU/50dheTI+xz4ahy3wYQIC93vmF3Y/V18K4gAOiu/4fuXgNr0ZMRL00VSS3sVbb+I26/qTFzqRjEqHndyFbjYl3VDlGVZuem38M6dLRS1VHO9oE2EHOAopC0p4qFtQxPQCZ8p05WApleXTd9leW7dIfgqQw8uDkBSABbQYVuLtjT6tc+yEnF5jhQ6OBYI4Sz81HoNozbt61yC1j0mvwX+FJMf1yp/6aBWMngtSGYiBnfQIp4eoF1jVJ3y/N1ZGJAA7/PzIvvz7tzyCp517MqyV/2EL3y81ca3wKulxPc95DP7mlk+K1rrM6aKy1VRUzuXN0yI0Oa7irzDmLGEvzIRQZsHNq 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: This patchset contains some abstractions needed by the Rust implementation of the Binder driver for passing data between userspace, kernelspace, and directly into other processes. These abstractions do not exactly match what was included in the Rust Binder RFC - I have made various improvements and simplifications since then. Nonetheless, please see the Rust Binder RFC [1] to get an understanding for how this will be used: Users of "rust: add userspace pointers" and "rust: add typed accessors for userspace pointers": rust_binder: add binderfs support to Rust binder rust_binder: add threading support rust_binder: add nodes and context managers rust_binder: add oneway transactions rust_binder: add death notifications rust_binder: send nodes in transactions rust_binder: add BINDER_TYPE_PTR support rust_binder: add BINDER_TYPE_FDA support rust_binder: add process freezing Users of "rust: add abstraction for `struct page`": rust_binder: add oneway transactions rust_binder: add vma shrinker Especially the second patch with typed accessors needs review. It contains a Rust analogy for when the C-side skips `check_object_size`, and I would be very happy to receive feedback about whether I am going about this in a reasonable way. Links: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/ [1] Signed-off-by: Alice Ryhl --- Changes in v2: - Rename user_ptr module to uaccess. - Use srctree-relative links. - Improve documentation. - Rename UserSlicePtr to UserSlice. - Make read_to_end append to the buffer. - Use named fields for uaccess types. - Add examples. - Use _copy_from/to_user to skip check_object_size. - Rename traits and move to kernel::types. - Remove PAGE_MASK constant. - Rename page methods to say _raw. - Link to v1: https://lore.kernel.org/r/20240124-alice-mm-v1-0-d1abcec83c44@google.com --- Alice Ryhl (2): rust: uaccess: add typed accessors for userspace pointers rust: add abstraction for `struct page` Arnd Bergmann (1): uaccess: always export _copy_[from|to]_user with CONFIG_RUST Wedson Almeida Filho (1): rust: uaccess: add userspace pointers include/linux/uaccess.h | 37 ++-- lib/usercopy.c | 30 +--- rust/bindings/bindings_helper.h | 1 + rust/helpers.c | 34 ++++ rust/kernel/lib.rs | 2 + rust/kernel/page.rs | 209 ++++++++++++++++++++++ rust/kernel/types.rs | 67 +++++++ rust/kernel/uaccess.rs | 387 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 727 insertions(+), 40 deletions(-) --- base-commit: f090f0d0eea9666a96702b29bc9a64cbabee85c5 change-id: 20231128-alice-mm-bc533456cee8 Best regards,