From patchwork Tue May 28 14:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13676936 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 CB428C25B78 for ; Tue, 28 May 2024 14:58:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 505326B009A; Tue, 28 May 2024 10:58:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B5276B009C; Tue, 28 May 2024 10:58:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 37C1C6B009D; Tue, 28 May 2024 10:58:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1EB4D6B009A for ; Tue, 28 May 2024 10:58:18 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C077E1A05C6 for ; Tue, 28 May 2024 14:58:17 +0000 (UTC) X-FDA: 82168110234.09.A11150E Received: from mail-lf1-f73.google.com (mail-lf1-f73.google.com [209.85.167.73]) by imf08.hostedemail.com (Postfix) with ESMTP id ADBA9160011 for ; Tue, 28 May 2024 14:58:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FSexjEdU; spf=pass (imf08.hostedemail.com: domain of 3BfFVZgkKCHgWheYanudhckkcha.Ykihejqt-iigrWYg.knc@flex--aliceryhl.bounces.google.com designates 209.85.167.73 as permitted sender) smtp.mailfrom=3BfFVZgkKCHgWheYanudhckkcha.Ykihejqt-iigrWYg.knc@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=1716908295; 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=xLfLKzdeYSLpodZjM1TmVnfFmup+gWezC6j62g1XHPU=; b=5Yj8J4PcicfPk1WL+E0KKGYMG2P4GMsdvAoXdE3c8rupdZ9nJIxadlbe4cAHJ9eLLoKi2e 4r98tTaIgLU/oO07Lrr+Q+c9mcBxK3wOI+ZfQDQ+ibxDki/WthN04ATEun9wazylGbjss4 Cauuszn1LILjFJ975dfEx1ieTmlWvEU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=FSexjEdU; spf=pass (imf08.hostedemail.com: domain of 3BfFVZgkKCHgWheYanudhckkcha.Ykihejqt-iigrWYg.knc@flex--aliceryhl.bounces.google.com designates 209.85.167.73 as permitted sender) smtp.mailfrom=3BfFVZgkKCHgWheYanudhckkcha.Ykihejqt-iigrWYg.knc@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716908295; a=rsa-sha256; cv=none; b=wFLTECJ0pS9Rt59hL33XkV/0Oazn3M2oqSzxFY1pDKB6WlZHa2MVZXS7q5b8I0s6XwOSIi 12v79epS++XJ68qWn9nvctArtcEMnNf82+uTaT9pYN8NsgLNwx2/zPGmRXX2qyXZ5SrQYH LieYkCE4VS0/jNbLsFJ8u7XM4BKAiuk= Received: by mail-lf1-f73.google.com with SMTP id 2adb3069b0e04-523b4b04fa2so757943e87.1 for ; Tue, 28 May 2024 07:58:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716908294; x=1717513094; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=xLfLKzdeYSLpodZjM1TmVnfFmup+gWezC6j62g1XHPU=; b=FSexjEdUUTdmC0TCLHUywDhNxGY1CnImct5paMiEyzRLjxqjaY/87RmW+6lGyyF6ME 0zw17mh/eO0NfSmLTxdKUucDMHbBmn3WC3uEo7IJUfCQXzvBgimphVd9GAagZ40KI+lB aCQs5Yb+6PcEq9IvjVXSsCC8jgWyPzNle8qiR4eebLT3GzPGyqEu6j1t0WfZbQMQJR1f 43uL9rpMjNbHDDGL0h3v/KN2Ug4kNpSk2I8aiuJyXvw78T0czlfBfpHS9BMtvvyAYou6 FNvPCpvfA3KCuF8O1aR6YzzCYRBPIfbYok7Ra9kFS9YluFSF69sK9BQig9i6sJreIcAl eMVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716908294; x=1717513094; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xLfLKzdeYSLpodZjM1TmVnfFmup+gWezC6j62g1XHPU=; b=qsBsUsAJuQD0n6EFScF+u5h0jV46+smlEkgJ5CNPL/p2Q/oj0gXoyxn6BjNcJv0AYk xti3XeMUca02DiOX8l0fIUDlCluQx1UQOvtD3wuP8dYdM/UQddBBiFlEW2VknNb85NNG pfUHkhB7s9lYUnNxI85gJ2fu5Q3LWRkuTWaHxeYVHxNy1b6uBLv1hLsaW4oVJXTIo5Dm lgkEwa9cXXk6ey4qzZAmMflB7hWA6d72mxP/me7LyP2BBiX/Q01RgsG6VwDItFjlbJiX HI2D0lUrXRS+adyBMPk35viv+si2fBuq6KFmGyU103wYKBWULoBrDrJmbYmg8BwYNq5V +xOw== X-Forwarded-Encrypted: i=1; AJvYcCVH7tjJXHd2pGQbZbFRMndBXbbmn1ifFmtjG+pR8tmcBOqvlPHqGgaa6ycMaiB+HETS8PMf1Djz4bzgdNvnYjkJUBE= X-Gm-Message-State: AOJu0Yw+292oPRzNmn0uWWSchM+Ln/4GeIu0r8H84u+eUx6S3Bzg3io1 fKNI+dhJhRdKhidwi1VaY91FkTNiLRQdh+w0OWcnXs0HVTr8UyEQcVInkEFLdp50nR1EBnesmQs DyVK8Ui9PnS6sqg== X-Google-Smtp-Source: AGHT+IG5oCwliI55QSm/nlB6Lw5lzzQdTvktowkRPiBa6vXNuKdy+E+CON0y6SPl/fSx7Q5eHzfvSrmI1t/i15A= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6512:2c86:b0:529:b6cf:cd0c with SMTP id 2adb3069b0e04-529b6cfcebemr3146e87.2.1716908293547; Tue, 28 May 2024 07:58:13 -0700 (PDT) Date: Tue, 28 May 2024 14:58:01 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPnwVWYC/2XPQW7DIBAF0KtErEsFw0BIV71H1QUeDw5SHFd2Z bWKfPcO2ZjKYvWB9xkeauG58KLeTg8181qWMt0lnF9Oiq7pPrAuvWQFBpy1EHW6FWI9jroj7xz 6QMxRyfWvmXP5eVZ9fEq+luV7mn+fzautu7UEjQXcS1arje5t6ogpOkJ8H6ZpuPErTaOqLSvsE kzz/ApVRrDg5QBTOEi3Sxm9kU4k9fncuSTyQgeJu5TVSBSJlxQRECgbOEjfSOsb6UWG7D1jHzl 7e5Chle0/Q522i9mx70OM+Z/ctu0PVYM4psMBAAA= X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=5369; i=aliceryhl@google.com; h=from:subject:message-id; bh=UGSUXvJPMuX9Bkae/WPEm6A6AVU8nmv5zPwgw0bs7/Y=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBmVfD/kk+kkk74MgEVp2uFripge2b1MUFf9QTh8 lMpBFLiVYqJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZlXw/wAKCRAEWL7uWMY5 RjK4D/9tsWpL60+RGj9Xb+y1ietr1OB2e/gUpbdzbfoK8fTqVGvkw1xvetxbsGyDjHtkhrB/Qou uzTgJBqVbbBBXK6Udk7MXKirnMOpoW3L05zP9fDm8p4JRFvwX69B5p0d+9YplqWmjEFBPg3Qv+I kvW4YcV4gq0LP9wYQDHoE9CoIUq5vR9gmtxRz2xPRjSGUXiJJCTquL23dOaJ1AVPRoeZTi0xde4 0NPm/CAPEXCye1BY/G/favUIfvl3jPSQjPdETIwpv9jEJ/ASp5Hgwr78ij/lzl25FxVEqjRloaQ Ob5pcTDrxJ+5porJkDPaHxsKXVVqunRKepKIyrL/xEe2Ykd5upy/kQR+3CBeZMd5WPy6UTqYzJP rEXlKc+ha895BR8UMiCbd2ezCpBy7Si5u3oJvoBR/E2ZVESfzu1uWghhsVUs6KA1IMo2iwHJzgm d2XAJJcHCRHHuvJt4OqXqP7gXEDeJ/JGZ2sVCV2GLcn+7TUc1ibp10BySSlCWgolC6Yxtz/HLO3 SZAGc7hvjI4okhSdcXOFf8Qnc5JNodCoFX4fL237/v/Z/nXXgN2yu5dDsnnPToW+d6qSXkSs6RG NppAJvA0n53Rpn1pMIGQNXCTf0+YpZSGgAKobh3c3CrSsPfYTQK4JSlHWDFrV77nw4vwCVS/Vwd uanXNPTOk0FEDKA== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240528-alice-mm-v7-0-78222c31b8f4@google.com> Subject: [PATCH v7 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 , Trevor Gross , linux-mm@kvack.org, linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org, Alice Ryhl , Christian Brauner X-Stat-Signature: kh7rwc5ii3jccacxxs4x95qhh8h731hh X-Rspamd-Queue-Id: ADBA9160011 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1716908295-882017 X-HE-Meta: U2FsdGVkX1+tSc2T7WnQ59QwjLIaLqmhCOjcrQOWb3QzYOizuEXciVfRJRgsFD3Wp07Lz/0bl2MUo6OpcrwuxfCq7fGFxak/k/sXbwc+K2ArqfUI76kStqMhu80nNh7bJ8sJBBaAZVUkmgqQQyRystKqaKhWih3JDbyuHKNB+mKUGTeXoP3x8yYg7AttuUGGMoqleRk+pKsRrIW9mKW+xh/AE0Udtdi6/oF0xkleiqr1UQYTYWH/vuq9w1kWNzbyhSC9UaJXb3v5zKQkRDW9RspcDpIHiDACn28HMVPIbxx1L8RS1TEf4f7z+TwNkL3GRwB7FW/7VffFM0kVfk8apjnT7doRuTpuZUNZWaAkn7FwrzOqdZDj0yBXXNSaP3267yJvy+NjayzARSHYpow3/7703FsNX9kY9Vvawi+47BGVl6AmjEI5sNODJiRIhRnPhhxR8uz79DYqw4baglwkMLrg5Z8BEuDUjkQX5gNFrvGLGlOnpaiDjbCx3sQY+eqIXQxDxraWadu/VSee2HJ+Jevxv3cR7Vli2KMDZrD5BaNtUXnEghLScoV1LZgPhFPkMaXZtMoA6gm0gR6jh0EHcBFNOWiAvYsLVR5ZeVLAf+lp2fv76RgszB4bLk/aWMRB0Hg4+6HhLtgq1CAHADpL2K9qY847FHw/9JSOFTCRjxSm974XIIGj0nJZuD3m0qSMrffL2bnjQNkPxEv7/z9VWvi749oZokrEcnBBbpNuQi0R/x4iNuzrkDY/nzE9Pxi1GHsBOdmUoOnPPiZiowUX9yzFSln1rm349DjFpDt3sJeytz3XJSSeFCAEQVNLG8o6nG6u+o3e5HaUTSx+LJC00wKB3aT+9xHeX5se2s5s8b0KJNNYrS1ZGzQTdki2qJ+1sivuAQ94knP9TSNNTINAFKdbbO3m56ktCaIJO9WFp4mI8QjNzUsPgotO3cLYxcfRm5dK1GCWJtqjOVWJ9uR P/UjLtPe 1Ymsy5liQxr0DKbIV1NwgKQ97uTEyVREdQk7rI9AiBpNOvAbU3TMs7S2f/HHxwSAUeNhVYuwcQHyzZGJei+CKOLtRHq+0TfQJlCIANEA2LkjtTD10O9dOW6PhQAagl5wGylJPtF5Rfecr/jh4sg9vklNTI5b/zyL+/dIlZKBveMsNzdYALe9TeszY9gyAq5Sk72OHChJEusoObGJdl5fsQhPPYWwCfd3BdOZoogFTox6nHlchMvk8IY377itE6wohPr8GoV5vlolXb3nv1BkNx92cPiGAvRepMP3NPu2HxuLQg2caxW7z/2piJbuzUkP4U/XX034PN7qJVXv3d/20qnjzMViX+4onlp9pagRwjpEIB8JJQ2sRFqWNd1hNOQsv+fTA2IjlNp87HdqVnIqb5GYlk4izBaH93RX+/hw5gxr86I0jvBRkXBaMWyTeG9ESzT0kM0PmW6HVEnM6cXfHHjC75Rx3jaF6Mk2uvh4CWS2BC/6lS8c9HFqdXLqC4MYKkCrZXVYD973t6haXkeKQTIkONXvfVyRiz9APPemyNKSptkka0ZLQu9IiANLVx5AYF1kakqUTqBOlJvnfU4SMk3N/gCTmKeUKeaJMEhkbvYWt/4/8NFDuSb9O/HWJDUC8cl7OFKpGVc3tIrwLvxeANQklyoXuWcPjKJqYHBDp0GGooJSihusNDIxXNT1Y+dGmy1h/6PWnTwuMWhmAigUqhbj+0Xe6r8NbTzEC+hQOJlp+AO5eUSwIFz7D3J58HmxbwmvnsWMkR4MOCOg= 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 v7: - Fix call to `reserve` under `make rusttest`. - Add comment on _inline_copy_from_user. - Add Reviewed-by tags. - Link to v6: https://lore.kernel.org/r/20240418-alice-mm-v6-0-cb8f3e5d688f@google.com Changes in v6: - Base on top of Wedson's Allocation APIs patchset. - Do not define my own gfp flags, instead use the ones that are now available in `kernel::alloc`. - Add gfp flags to `read_all` methods instead of always using GFP_KERNEL. - The __GFP_HIGHMEM flag is not provided by the Allocation APIs patchset, and I do not add it here. I will send a separate patchset for adding it. - Use usize instead of void pointer for userspace address. - Add _raw suffix to `fill_zero` and `copy_from_user_slice`. - Do not allow interior mutability in AsBytes/FromBytes. - Doc changes: - Mention that validity of user slices is checked at read/write time, not in the constructor of the user slice. - Mention that methods can also return EFAULT if a bounds check fails. - Mention that methods may have partially copied data even if they return EFAULT. - Add link from `read_raw` to `read_slice`. - Move comment about initialized memory on `read_raw` to `# Guarantees` section. - Add examples for `Page::alloc_page`. - A previous version renamed UserSlicePtr to UserSlice but forgot to update that in the commit message. Commit message fixed in this version. - Add Reviewed-by tags submitted on v5. - Link to v5: https://lore.kernel.org/rust-for-linux/20240415-alice-mm-v5-0-6f55e4d8ef51@google.com/ 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 | 46 +++-- lib/usercopy.c | 30 +--- rust/bindings/bindings_helper.h | 1 + rust/helpers.c | 34 ++++ rust/kernel/alloc.rs | 7 + rust/kernel/lib.rs | 2 + rust/kernel/page.rs | 250 ++++++++++++++++++++++++++ rust/kernel/types.rs | 64 +++++++ rust/kernel/uaccess.rs | 388 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 782 insertions(+), 40 deletions(-) --- base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0 change-id: 20231128-alice-mm-bc533456cee8 Best regards,