Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp353513rdb; Thu, 8 Feb 2024 07:48:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX23Z9KTFjMKu/xum6mFmJ4lC1XjAFAvw+4gMoHmUlJwZvMTbQO9PH6CzkVw9shfnnZIwOvZ9T1WS/Kts9CgXATJfdqO5ylbYe7eRPAfw== X-Google-Smtp-Source: AGHT+IHvlVDzcRt1gklUHHY73BvxKwrZuQXQFz6jlCSp9GjUt3WBOCmvaG1yv0Ln0iZCYw/g+fUt X-Received: by 2002:aa7:d5c6:0:b0:55f:8c38:36a9 with SMTP id d6-20020aa7d5c6000000b0055f8c3836a9mr7119861eds.42.1707407332206; Thu, 08 Feb 2024 07:48:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707407332; cv=pass; d=google.com; s=arc-20160816; b=IxjhETYg16n4XQ0Vj7CAYf/Nw9x3P0QT5Bd8KZOpXZL1UsMbYUOCowh+JaNL/fE10A 3zoWbwhXr6TESjc1WFXEgpgDHeavO+bWkfwmnPF3eDSwIA6Ckjf2r9RiRyRulPBQ2d6C etfaHuScq44OCBFlB85mpcHNLzVuZ3Rez6sxuRHjvwGXCApkw7/7bmZ58ADR7l5R54Hh X2ipNvA3U+W2wbZE7p0eJ4qEaHnwMfIsnTOyZ50E5cTOtWevRAvxWspvdE1A/c/AZe4S 2yY7fr/EgvdpWglHESzuZ+pMG94WDHJ2fLrRmLgJ/D3DCdHMxpL4eTTjFqHoVkn1BX2Z dK9A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=zhocXZ6cl9/R8sKVq7H2EWpDfoTTOkJP066TsAIK9Rk=; fh=K/rMLk/RN0lpFqnz8N5R2BffkBq9NJwFSvUGda/os6U=; b=FolVLKoWuBhWJnvgavBTg3TiKJOtfggOQ9xHx3zu39DVnKU73l8N+j3B6nUI5Qn/Ql 3VBKlltO9RyZAZzSwJ7Wc0ShphrPMDhr89uvaY/VZovl/FFXtX2M1eougqk2Zyb8Zetl LJ7/JjAvtjx/uzX29gnWVID3YVEriLA/cjdqABSbzakN67QOhTv5FmdTLviHoLLpjW1P ebeTnra5i+WM0HBb9voQvKzKJfGUz4/88xvh1whl1bgz8nayFl8cb9ZM8w+5PrVKJ2WB KklvV/nXHJeSzxnksHfBWUyt5mAot4KKygSLnNEMsRzuPjAmb5tetxA3AxxH0ol48Atc XRgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nDunHfpW; arc=pass (i=1 spf=pass spfdomain=flex--aliceryhl.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-58300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58300-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCUsCSPA0ppN+afB+eetnhXB7i5MzGl7tPK3GsEQGw3b6JIBaCQIXV/5iss7zHr5RiOFuccWC+sJr++uacNYVbmABJd4K96rLOXY3hDN4g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id cq27-20020a056402221b00b005607fef4549si1032546edb.351.2024.02.08.07.48.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 07:48:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nDunHfpW; arc=pass (i=1 spf=pass spfdomain=flex--aliceryhl.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-58300-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58300-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id C74E51F27F0E for ; Thu, 8 Feb 2024 15:48:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F01457C6EF; Thu, 8 Feb 2024 15:48:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nDunHfpW" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB74C7C0A5 for ; Thu, 8 Feb 2024 15:48:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707407323; cv=none; b=mRgHjwsDXk57IjQmdJSsR8lTylzIntukuahM9SUXBe7oniO/RU7GfaOftLt2+UIxZZpZZn1LBYzOmwNR5cmrg+6nu6K8roBXLm7JA/+H/wy/NzehpU0d9OESaAuvIpF9l9yTwxhYSR0seTzZ2/Bq4yZ0+HaJPL416VNsoRcTOrA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707407323; c=relaxed/simple; bh=p4H6OppwPLzivo83Hr2g72Avg5StT4o8YtOOlH08jJM=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Hrlgbms7WtJbJA7Ra/qAGOviDfIBQRbJAgmKhBblfD4D5I9EH2aCxMvlGCfZGd+7H4+pEViGtxmpMpMgPn2Ez5XPqmaJYX4ki9p1wj5TnmEFlCqfvYSeJpD2ccx93hROZqEnuQL4jkgypuIrrjuNQulmKh1CLOKpXvqZAFVEYpM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nDunHfpW; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6047a047f4cso49165027b3.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=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zhocXZ6cl9/R8sKVq7H2EWpDfoTTOkJP066TsAIK9Rk=; b=nDunHfpWKmH4ezyPpzXmVL9P4d5OG9E/DjVDlFjds0ZeheB0hq6eODt7h/8HZ+tMh0 69FPdmLiu+dwYdHABw5fqxhQvu06uMmjMfvHSH5dsOnuFthckYdKMUBpoFHM+CNake/S 4s2MP8ZIyGNi/UWCvhc64PxGR4vF3TKfwgN1rJJzlHBuavk6+EeMwU3CxyUsrYCbqwyN SiERQx3lBZSjtoQZdShF8f0TsRaVHMqM0qNBBVEjLNOozi8ft1KX0d7fN30ATfiviWVu HetWLtiDlm6GdW/t2Z/GpRZYsFP5TYQW3X8wXEiIzib5FFx5RddtBwpKXn5YOqLdcjuI 65GA== 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=hEzrhCTFJHjHKfepA6jPcOcCZiJtE4C29Tq2GSZnQU3xQ90C2sKATbBfpDFS7RZ/qH dCdBea0g1nzXzTni2t3gwYbalW45rB7EJTL66sEP5wO3zi2hY2qeMWLrKzNYnMcEKbSR Ag6t8SaAJje7MqUgyWvBmK+NaveoOiWrxLRzk//lu3T0Z7NO/zmzR5+oShRF3kYUd+LN Nh+PQAMPxQSdzgaQIWCfybGdTEyiFQRS6y1m99RaAYwiO438Jvuzv02s16s5osz1wnbw 223elyhT/mZbef8Rmhy13TMJMlvOMQccZ0zwQFAxle9tXqkO0cVyNbK/v/83EpY+cyuU GE1Q== X-Forwarded-Encrypted: i=1; AJvYcCWTBI/MRcOAQ5SnL0Xo8LWOyCEQgg1yvL/hfo0FaxfqpepuEW39YYGeglD5+YCI8rRk1S2+Rh6AD0F9k2nIUqtSR3OOTuwqvcDNqpXP X-Gm-Message-State: AOJu0Yym+KwK0yvsNYyD5QS2miKppAQ19qLY1cNyyJ3/oUIcItHri+g5 w1d+0WiPid8MumyvqHQPu7vHtcJUVr65Vl1rFTmuTQjBodiWMkebnM3x/8X+kv42gr8FoYzhhT1 3KLQuG/kDxE4K2A== 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 Content-Type: text/plain; charset="utf-8" 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, -- Alice Ryhl