From patchwork Mon Apr 15 07:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13629526 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 93340C4345F for ; Mon, 15 Apr 2024 07:14:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C8136B008A; Mon, 15 Apr 2024 03:14:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 077F86B008C; Mon, 15 Apr 2024 03:14:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5ACD6B0092; Mon, 15 Apr 2024 03:14:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C41286B008A for ; Mon, 15 Apr 2024 03:14:19 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 511E01C093C for ; Mon, 15 Apr 2024 07:14:19 +0000 (UTC) X-FDA: 82010902638.23.66A89A0 Received: from mail-lj1-f202.google.com (mail-lj1-f202.google.com [209.85.208.202]) by imf29.hostedemail.com (Postfix) with ESMTP id 4F509120022 for ; Mon, 15 Apr 2024 07:14:17 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ITnl+ByT; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3xtMcZgkKCBkzA713GN6A5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--aliceryhl.bounces.google.com designates 209.85.208.202 as permitted sender) smtp.mailfrom=3xtMcZgkKCBkzA713GN6A5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--aliceryhl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713165257; 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=4GRRmywA9h466COkiWztO2k7QWi4sp/9u/vk8Vh//Fs=; b=V8m9O300iIzduxLRNXeUN0Qh/9yy4y3vKU9uvKaBPd6CEOUXatHjiRlC+l4xvii6gYVXhO ej7azNXbEvJMOh89fjCojPrPVE/N9jyi0J80xbEw8wakRLjJ76dP2+OlddDa60jnIb6dW6 qPbg8D2CAWTh+FRNvuK7wiiBP0KEgmw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ITnl+ByT; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of 3xtMcZgkKCBkzA713GN6A5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--aliceryhl.bounces.google.com designates 209.85.208.202 as permitted sender) smtp.mailfrom=3xtMcZgkKCBkzA713GN6A5DD5A3.1DBA7CJM-BB9Kz19.DG5@flex--aliceryhl.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713165257; a=rsa-sha256; cv=none; b=1IhJ9snkPTwkXp1PjWSgt3AFWEKNq949YAjdRoCA40Ybj3WgXKAO8iMF51Nq9jLqy+ihEC qt2RPOpl3FW8aN9aOZ8pArkif3sMPK+4rUEOwYOpPyrFk2El3WRbEZZGR44yxIdJZc08Ft vApSfAFlKURGKWTZ71h62CqMKJbMoCw= Received: by mail-lj1-f202.google.com with SMTP id 38308e7fff4ca-2d871dab76aso24903871fa.2 for ; Mon, 15 Apr 2024 00:14:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713165255; x=1713770055; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=4GRRmywA9h466COkiWztO2k7QWi4sp/9u/vk8Vh//Fs=; b=ITnl+ByTN2VwH0ZndJ+wOMQnLgr+VmddFoleD6V/FINOACipKcwTwS9+jns16x/wvA PWOsQo8dKxEN3fp9jl4Kz3UQphyahd/EKUWPrLogyGXfh2wh/uMNJeXuI6PYwJ8AkFm/ 9vAzz74eW/VMv+C6QHPHyacuDCL38FuQQQJUuznHehEqE1TYZLtrrhppaOLFQIzzQ/Qm t75joW1POZBYR5LNx6krwAXZbbZlgLrn5Ai3ijK622DuS0jke06JsG8r+saR/gR0cAor EimhJwvvEwn2xKCV/hGddCLep45h+6M8u1T5hnVidLKTmTRVl08r607SFtEa2r/jgwY/ wtNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713165255; x=1713770055; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4GRRmywA9h466COkiWztO2k7QWi4sp/9u/vk8Vh//Fs=; b=iJk7EEmqxEaTel4UX23yjU5u+/kyQZ6eC/W6pnj4jJXF6pZ0XCY1jJD1pdre+yWSTS 6NV1aTeJF6qfY+LTKIfeqCcHf2RY5YJABtVqHnSHv+o0aDNMMIpUtlINQPWRdOiYZoBM K5CC74P8K5286vchrofYJQWn/Y8THswdcbuYzPDUZtTkLyhroS4bI+yXROGfasGr45mZ M1qFgJBvKjKezIO66bBuztaqqHE7/cgHbsbgVOO2R/xY0yWtljWORDdT1huBWNiWpXF4 Z0Kzkv0jS2STr96ad74LpgRReuw4oWa4Sjo2s8sA8ArVBfJlczf6BOAJofXaApfCNrMh KI1A== X-Forwarded-Encrypted: i=1; AJvYcCVuv3Pyt9y7C7ipKp3ma1w5A8JZmOoFndAEq/Mv1jHbSynvVUxUespNx6Hh/KQcrl9ALXZ8AXwL4UE5v5BeLNdLNRM= X-Gm-Message-State: AOJu0YyLh9f3X1zJhMkwRyF5AA3gdW5y7Trss4rzncxj2YknJknVvEau Y688hESRzgP5ffa7HgN3ImWJajFPX0vWaGASeQ/YdQXFKEuwQX+uFf+fq9KYectW6ohlXkeDP0y 3le5V2E8cCeKmrA== X-Google-Smtp-Source: AGHT+IFP1799A/INBTP1ZJNrG0CuTASrln5KTO4oyjuvBqEvXsF1x0e0IOk1vY1Jk/fFjJUdDNNJnn97kfGjtR8= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a19:e005:0:b0:517:7879:5b8a with SMTP id x5-20020a19e005000000b0051778795b8amr7915lfg.13.1713165254748; Mon, 15 Apr 2024 00:14:14 -0700 (PDT) Date: Mon, 15 Apr 2024 07:13:52 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIALDTHGYC/2XOwQ7CIAwG4FdZOIuB0k305HsYD6zrJokTsxmiM Xt3Oy+bMZz+wveXtxp5iDyqQ/FWA+c4xnSTUG4KRZdw61jHRrICA85a8DpcI7Hue11T6RyWFTF 7Jc/vA7fx+a06nSVf4vhIw+vbnO08nUvQWMClJFttdGNDTUzeEeKxS6m78pZSr+aWDIsEs1qfY ZYeLJRygaH6k26R8vWVdCKpaXe1CyL39CdxkXJWEkXiPngEBGoN/Mhpmj6wdeXSTwEAAA== X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=3730; i=aliceryhl@google.com; h=from:subject:message-id; bh=2e1X85rvz6Dc/ugdTsdRjXFp5/BAFi5T5i940mZmfps=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBmHNO+dW58xo4FQMfR8kYfnMJW1eEv/m7+aySBj faN9axF5O6JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZhzTvgAKCRAEWL7uWMY5 RqgsD/9bR2gcW5Kx64xZTwO+cA3WFov2fLiqMOmd4VlEM+cQvQ5K6wZJKJGim5eoXJbqr0Ygd57 RSaurpgg+TG7q6zK97W7lgmNAuf8sMzPisSJXokZnCFiNIJcLAGLL6WbvaS35BoofR3q9jFQFDV stsO2IKubIwGh8R2k7lBE+kukvNBjspgRgMW2q+WLP6gartfgMiPChR2QzLzkuxH35KLcY+OG37 SG+rSze9LKShYJ+JFBkdylxmPWKyc5Rtuq75+HMP9aDmOd1PqNVSxZfc/J3wiUEePLjlIKNxXYU 4qGI1Zhs+0ktT+2XRwCA0DD2ruJp+Fx6NpBtELI/6EbZhSrs4/hyJTb6qDs8s/nqc0C688v1hHC PfXWl30Zkzbhn+otAQ3m92tFQFIp8bMIl22BEQMgrF7BtR82nABtx4vPFeRYCkms7hE0tZs3PrX UmmPBFFjvyJueHDxgPzEVSEbr35NQ3i9RkGibDHMiDVmyj7rD8MCmqS6UGEy7UNdGW44RPf1Vyr rMm2uZp64T+LfgYi1+qCY24J1YukH8H+nWupUAlndXjin1RDB3PE0S5CMjbaNPhoCPhDn9kcuDL LsDAS8zH3a7XvODIMPrNfaG2bMgto7dRV0oSjPwGU+vKfabSd9sJSzE7j3Dz99FJ+007Pmhg+V/ 0YIJLw3r4Gm6XRQ== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240415-alice-mm-v5-0-6f55e4d8ef51@google.com> Subject: [PATCH v5 0/4] Memory management patches needed by Rust Binder From: Alice Ryhl To: Miguel Ojeda , Matthew Wilcox , Al Viro , Andrew Morton , Kees Cook Cc: Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Greg Kroah-Hartman , " =?utf-8?q?Arve_Hj=C3=B8?= =?utf-8?q?nnev=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-Rspamd-Queue-Id: 4F509120022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: n7zqpn8fbbripomupiica8t3xdtjhcoi X-HE-Tag: 1713165257-19370 X-HE-Meta: U2FsdGVkX1+7UcxTtBuJTV0tKSqml5oYRLXh7h1Fzue1n+vaGdlyDpr2JjZEsSAB4qqtIUIsppo57S4XeJPGsd/w/ifvT2V977fFKZ2UEACDIN1d2Kx9aC1p5510c7m8aElGcdz405l1Qe55hi5QDDbOIcIi9HiFekxdj7S21NZMS71ErLaWlxGeNe1a+WzCTeVVoIHl+aScPhlkxN5TrYPF2Uq5Q6GAHK9r3d7Qle56BDO2IdWkwmGCRiqz4PL5fLS7EbMobHo+5ZVHvQYv3CnNhQmS5JVAnMtAQ4RnX+7yXsEEsD2clXZhqLuUEuOg9YlAIrjlAhALLh8hC5j5EGmHlCyDQhhrmf8iYBjPAGFknvTDKe6sJ5DvIHC1tJmJ6Taw0OaSYH+YTrik/Gj4l1/PT/Ux6cdJmOCsWeWreE6KuN3o32Awj0FHTLv1f8IifQmXAroby9n2z4JYrEKHWZ/SqZbid3WbzfnKq9rcnN1PaL3TjIDT96yXacJ30s/5Bt7qIMcU7JPvD2o+lBTwj3MC7odWZnZCOQmfT1g2fcAyE+SB4nwLva0DVn6HMxG+M0HQsPTAMgJ7WWWCwGsDUg2hToa6uE4+22qeQV7cSKvjtRdhK1O8nptmltxbA+CmGxfT281UbPxRykJs5JSb1GMLPw+Uv3HZFMhpYwa1KlbYiEnuM3FBd7toyf580LoJQhn74AK2QrtMS+jCGVyOH3F/24b8Er3bCa+iO8Hnp+5qitflFpD77Gvf6kR4lRQ3Gfb88pChDs2Tw+mmGIuJl5cJTmMUYKyKhXRnf70B57behMNZZ2Q6urBqJvnngUOt8MvH4VcVSHtl5thW6+UsSnQmJ0sgSxJLkv9nfz7QCg5n6CUtskAVakKI6rfq2eLt+yYERcnkJ7bPattdXKQTp0bAHZ8mTAbsHKN4d8neFWnYJo8nqtr+SrNwReFgPglX6nXgSaHjhNBreZsz6Lu mTmvtCi6 +zML+pynqIrKyHd90Tkcp/JpwL35Ppl2AYvf0+aZyCIKPVBKze5ydZkp0rs2gGv8YNjzKLLJLsc6+K2gGK8iLTo6r+IlZyzsFM+a3NwBbVLAX0TT/hwBiNZuuxm4LA/6fSTXg636RSxBfFByAFjQOXpPr2T0BLD7eNkjogYQ3i4V7UotL9WoW8s1DqtWZ/fPWv20gKUsnp4GGKAf18Jpsa90RCiOtQ2b2T9eKLnOO9e8d6dn9D0JL6T0laoBApMjiWEciO0v1FVYHZeHLvy2IM7cY0cwCd+/c3irXGORk/MovwU0FVymFKaRk5JcjMLVfk9Uj202oq0VkDQxnwS8YQh1XHPQ2rMvEiujSpbzDj1GaB2jHHFsDCMGyXnxT4LkW4TLazvQI0Du4AxGYMUnD1pYlT67WXGPLTTdWlZlinPC/62vzbN306AyZ5b7IVUAFgY/20o//k2CRQnTXncnYLw8HRzUwD7b9n059zfJSyJjOHdbSSpPJuviCPAclTXbmUcvu9n8mN4vFKWdP3SN+Psb+5UJTFbzq41INxtPTwts9Fz8gc5LPZgOh8H3ZUppQxfNaQaY21dUdQkxM62UbDNi8hU1Sezc1a6y4wMvTUm/4RrHlF/7gviS9cE+kycU2MO8k1OEB/HSN+7skmzxIS88IlgDaK+Vt9PiWMA1KE3TfUCc= 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 Links: https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/ [1] Signed-off-by: Alice Ryhl --- Changes in v5: - Fix casts in declarations of PAGE_* constants. - Fix formatting of PAGE_MASK. - Reformat comments at 100 line length. - Minor fixes to safety comments of `read_raw` and `write_slice`. - Link to v4: https://lore.kernel.org/rust-for-linux/20240404-alice-mm-v4-0-49a84242cf02@google.com/ Changes in v4: - Rephrase when we fail with EFAULT. - Remove `pub` from examples. - Use slices for raw uaccess methods. - Fix PAGE_MASK constant. - Rephrase most safety comments in Page abstraction. - Make with_pointer_into_page and with_page_mapped private. - Explain how raw pointers into pages are used correctly. - Other minor doc improvements. - Link to v3: https://lore.kernel.org/rust-for-linux/20240311-alice-mm-v3-0-cdf7b3a2049c@google.com/ Changes in v3: - Fix bug in read_all. - Add missing `#include `. - Mention that the second patch passes CONFIG_TEST_USER_COPY. - Add gfp flags for Page. - Minor documentation adjustments. - Link to v2: https://lore.kernel.org/rust-for-linux/20240208-alice-mm-v2-0-d821250204a6@google.com/ 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/rust-for-linux/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 | 38 ++-- lib/usercopy.c | 30 +--- rust/bindings/bindings_helper.h | 2 + rust/helpers.c | 34 ++++ rust/kernel/lib.rs | 2 + rust/kernel/page.rs | 240 ++++++++++++++++++++++++++ rust/kernel/types.rs | 63 +++++++ rust/kernel/uaccess.rs | 371 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 740 insertions(+), 40 deletions(-) --- base-commit: 4cece764965020c22cff7665b18a012006359095 change-id: 20231128-alice-mm-bc533456cee8 Best regards,