From patchwork Thu Oct 10 12:56:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13830071 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 3A06BCF11E9 for ; Thu, 10 Oct 2024 12:57:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C12746B008C; Thu, 10 Oct 2024 08:57:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC10B6B0092; Thu, 10 Oct 2024 08:57:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A61986B0093; Thu, 10 Oct 2024 08:57:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 896606B008C for ; Thu, 10 Oct 2024 08:57:12 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 6A759802D8 for ; Thu, 10 Oct 2024 12:57:09 +0000 (UTC) X-FDA: 82657693104.21.CD26550 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf14.hostedemail.com (Postfix) with ESMTP id EE54410000D for ; Thu, 10 Oct 2024 12:57:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3bU3oK9b; spf=pass (imf14.hostedemail.com: domain of 3Jc8HZwkKCCI8JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Jc8HZwkKCCI8JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@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=1728564892; 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=DOhG2lII0b1XV2Pvd8Pm4xtK1qOLGqdV7w9S0Zd2Ryk=; b=vxuSpzvCjP23VNTvzQP1Q3Ize5YMza7SsbvmQbGglQkcRe+3IZaer/1soKUBMWp8f/hehQ OLO4f6qjZOpo9mYTs6rqhfds42rdAcoineUbY/5PCzLULKiM6QsdOGqzDJRUTZn39ioGi4 /SCaHCMn52G+y2vL718z0p292K6xnlo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728564892; a=rsa-sha256; cv=none; b=sTLQPhXZYIvZy2bGFlclvOsimgfPStHjGxQXVgNSuvoh1/0r4VgVKWaCKlu+WLf9xwCTkJ OyAQ6uWQwviLTb0jyswUf1tNvU+WKyVdv7P6LSb/IgNcTAA5H7P09X99V9J8hbjqrrO8kz UQhHw9EvU9MGlE598uvKWiXZm8SNLu0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3bU3oK9b; spf=pass (imf14.hostedemail.com: domain of 3Jc8HZwkKCCI8JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Jc8HZwkKCCI8JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e1fbe2a6b1so15764757b3.2 for ; Thu, 10 Oct 2024 05:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728565029; x=1729169829; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DOhG2lII0b1XV2Pvd8Pm4xtK1qOLGqdV7w9S0Zd2Ryk=; b=3bU3oK9b1MfYzQgJCWWUDf9/KaFSFaE7/8Ljyy36jxo7sVS5jgduM3CoasrU6YG9qd t1KZF7hug4049qBNSzHhk7prxjPcmCOU1TcuO1Fy2WnjtFeFyJTo9cSxSthbgqXDk+5E 88ayDELVSSU+z+GaOeyN6wuoYlt9hPJT7OrrlWLAdaPFRF1Xfrl7QxsefOwrrG2azlxU CblikMiazMUBdlh9LiyGhG6+02dJn+nyeksqMWVnXI89OAGOhedc3j1sOEvCO4n+613t GeTqKA5Br0hiiPgFT0fgamejpa8VLipm8yiyGinQnEeOy2joSqEalW75uBomwC396X/6 pKXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728565029; x=1729169829; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DOhG2lII0b1XV2Pvd8Pm4xtK1qOLGqdV7w9S0Zd2Ryk=; b=Fkx4SEoUubNkC5+jrDUDWOEAxCQHWVIfH1Xvpjy9+uYMQq6zzlBCoJNE3mVPbAn6pN LOYRnrHHH9Bl/5YdKr7v//c1MNCq4hAouf2ebkA7Hto9RXCORMC7LpPFZKMbcbAY8aee H4caVppBeejWu1iht5cx+uDh3SyGYhJoiTRYClLPb62YbtYniGhiuV/ZMHKHrPUSB26E Gm2FzYJ4IyN1JPlo0WKzGzEqR667ljk8+T7Z4xGvAFTR26NA7J/IYzD4Lp9y4mIuxb/J ipoGmdAxTWrAzzezi28AIod0BHDR4XJSFOjD4EWRA2SGAOf7FGozDBq3rcUieS/W+HhB PsrA== X-Forwarded-Encrypted: i=1; AJvYcCV8hVl4VrN2ABnz/wyPtEzglFPgR7J6eJigtV3IHJCzzHVmj6lJeN9uVKlEiQ1hLT6DhWn4eX1x+A==@kvack.org X-Gm-Message-State: AOJu0YxwWfmu9ZXmG9p4R00EzDjo6rEka2ApVWh+A5lOPhCYvoYJvImZ hU7N6lb4HH0QST3mDQEVwGBFimDxYBBjd7ZKrfj9U2EtFGSKe5rvMkREd9sultA9OLa5+AVLfy5 IcFDCBT6xIvh9VQ== X-Google-Smtp-Source: AGHT+IFnN4NiKROer/bhYUK3vmbJ0WzRy9Z6ly5mrAMMM7hZC0uCRREmQ6LL+Xht/BsVZC1c7cKNRgHPb8oUo5I= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:35bd]) (user=aliceryhl job=sendgmr) by 2002:a25:103:0:b0:e0b:af9b:fb79 with SMTP id 3f1490d57ef6-e28fe346f12mr108404276.3.1728565029274; Thu, 10 Oct 2024 05:57:09 -0700 (PDT) Date: Thu, 10 Oct 2024 12:56:34 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAALPB2cC/2XOQW7DIBCF4atErEsFA9jQVe9RdTGGwUFqQmRXq FXku3ccL+rIyzfi+8VdzDQVmsXb6S4mamUu9cqjezmJeMbrSLIk3gIUWNWDke2CMnuldcghD8Y JfnmbKJefR+Xjk/e5zN91+n1Em16vz75pqaUBTA455Inex1rHL3qN9SLWQIM96jcEjHAw5AL0K Ro8IPOP+IMbMozS0EUdFeaE4YDsHsGGLCMVNPpeOY/WHJDbo25DbkVWaZ+VSwTDE1qW5Q+0caX QawEAAA== X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2391; i=aliceryhl@google.com; h=from:subject:message-id; bh=OblR90xVpQ3uxMqRXP8BWxnDSHKdVQMnE4obNvo1stQ=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnB88XawLv1JPH9Yp7lgHZ3+4WXZQrNW3dTUC7J CsNSWB2nwOJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZwfPFwAKCRAEWL7uWMY5 RhFOD/9Wi46kNqF/PhA72INQt/WYgFCKYjm6ixQ4fxU4f/KfewJOEhjWEUPiWMxICagP/QfIdVP foJFdIjRtk6x+oidLD3IsU96jidqNV5kPw3jYU7vbwSyKNxFeZtdyu3HUXvI1dl/54i4Ku6N2q1 PuoaHJ9ovsv/tO39bdAhhesIddykQ7dZRrJ6n7xuF+IGHc+7/2sUy7ssRB95TOKpJJeahbOz5xM sIi5Lg6NmU9OnpbkmM07C5ZxWQyk4aod8Wccmc7uz9Ue7fCM9yTpf/w79bmUIeNL7AtTsjwhNYb C4xJAbGKp0cY2Q3PRtQsJMZKozAk8HuSk17nT2RF5xNsIbQjpOC00jLxoQz66nZp84WY7Sk+vYq KvAjSU5lOavfic0QbdUeYvPinGMzoCWhJcnHBVibOBeiSJFv5dfyRBnmvs2BQ2kt9KLiuFaomK1 Dol0yFuBmMN6LvCDD9WdCSMRkgjk4c3Sy2bbGGFQ7Yd/+tvQmboaz5WhmkppDb0MEKTaVnCv4KY VyY2DjbFM4DoDbTiI2g/AVKHrfI/5sDuw26chHxy8M6d+9veC0ofEMbMOD6veoFxrg4AL4Lkdgn fEKXjb8nEm3+CWHven01aTubTguh/3L4vdqONQhH3KiKCqE42Hd0tfaOcxZZvPFWPCuuNsThyg3 flADVaXqU1yl2aA== X-Mailer: b4 0.13.0 Message-ID: <20241010-vma-v6-0-d89039b6f573@google.com> Subject: [PATCH v6 0/2] Rust support for mm_struct, vm_area_struct, and mmap for miscdevice From: Alice Ryhl To: Miguel Ojeda , Matthew Wilcox , Lorenzo Stoakes , Vlastimil Babka , John Hubbard , "Liam R. Howlett" , Andrew Morton , Greg Kroah-Hartman , Arnd Bergmann Cc: Alex Gaynor , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org, Alice Ryhl , Andreas Hindborg , Wedson Almeida Filho X-Stat-Signature: o8rf8rs7q17x33sr4ew58b3gbqg4kqt3 X-Rspamd-Queue-Id: EE54410000D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1728565028-630062 X-HE-Meta: U2FsdGVkX1/O4o0vEuefT5Jv0QVmHdNUU1Xtt9gnpqZ+6Mz7ueHlzEXJnsqU5n4Ky+HHilmZTIhdP5YFH+lCY8Nu/sERuw/dlwlyLcs7luumNfBqxG+NiZZ4pMq0WWRRjghd81ueO5vCEbeXHutYFXcOSGG/+LRKm+gHmDab8vI/K0WRhDl7sRRSLRjqDQrI2Idvw55cf5kidgHaBV2SuL+UIOhshjS80rZ47OBvAJmxMraxZsJXPdDI5ydKVeVm89EvlyCdSWsb+ljhZBk4RrTv9TXwica1Bgh3NWEEJrrYtX0mDCnouub03+F7e7sEMpvpGTLxF74YvpoQ5Y7hiFkQ4GEgpuZrMN8lJU0tLeLraOA/+al/PH6Jn3Pr0EW526oAW0D+HXLx+J3qwskga4RErPGj4Rq31/FmjurQJOLW8WDlAjNO1gZy569s4crQK9S37Ib+A9v8zg2rL44EEu4eF0pfTlq9oX2Ns9o4R1f2As60V4wFyb2mgVuD65FLpgEyrzR8h7nuVhg/ORwC2nIPtli8OSequN8zg7lexdzBhJ2smrE50jajQfCb3JU2TOv5l8FTx0S/wGRcjhdHuXwyUW3UWa4vQ73xMXLUIJ0UlSKBsZUf7VhPxUqXBv25I5ffxTCzPZmjl5xEBlY2zOceBqHYfXVWUec4TcL7HgmUrFT6jyeMNCr9O104zzF0l48WFBN44K9J2URO2WiwCqX0sTQbVUMQp2AjTpcdVBp5lEp7/dVFalIZvYw9zhw9aotH4hB05pGOZPACDdSYPQKizJdxUZqQgmEJlR7bBbK2MViRREyo4idLtILewXek/D/250FNe8XSzmFVvnovc2LgFv4WI+M3t1pv5qjqgxoBtvj2FREJ/alTO5agLuafaQnS50N56MlS0bCIHSTMTym0JlJRcMRYp8j8mYNbGnazSKAEzFtPnodBWyQCQFJPM1RBkqf8dApi843u+mO oWB9vduO 5y9+wmLD92VsExKUwhjuI+uwfVfeWOlXwf/t6Wa0P1JFiLUQL71B1jPOlPWK9ezSczNUJEkjjshpjAVfzVTyzVrKRvmJnDMpRkDmpcrZJX76oG0GSqIXFJUGMA1je/J8GyqMrNySqBBQ0LEDI+ts6ilu5ux98bk8MaxUGz3k8I98UbhaleJOaE7Va646tSGt92m80bWs6bJxykTPVPX/yN66yQ4qqZmk/NGidF8O5nRzUbYwajcdu+ArNqTIfH9QH0Cfnd8ZnjSj+ceCCb401kS8kRPVGvarfttKmywSDU0CKuBIlNvjgD+H0ZMFaiWAzmgzEqobyZVOvFHE+ieXBLi4j7UAec57jAmWHIRD97A2ubldrbwanCdTKuJYFlEC7naaoOHbHXIY5J7fQA7jyASFveVmUw0ZpdsSZvplQDdU2KiRG2KSJMdxdRAZJcP0lA58esqJh6tShnAcffDS5SB5GqsGWD2LxcFKlneXjD199dMrfVDt+5ti+an7KCy0QCFBSw3z9t/9jVSmUetmZqLM/eVKKXXQvhWCuKTEc/lheQvAG4px66+NCNbsFkXiZwWZlEzUtWB9AG9Pn/pBC4Ui41EbGsfagSwlkqEPsJ0DtC0S8ZqqxZN/MxLLjr5siu28xroT8ZWNzLUbLc+W39XNg9tR8cGNtg373hg+nKZu6R3T1IuVM4XhgD6v07XoI6XlXOrSQtIymuCg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.004883, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The first patch introduces mm_struct and vm_area_struct abstractions, and the second patch uses them for miscdevice. This updates the vm_area_struct support to use the approach we discussed at LPC where there are three different types depending on the kind of access you have to the vma. You either have read access, write access, or you are initializing it. Each case allows a larger set of operations on the vma. This is based on top of char-misc-next for the base miscdevice abstractions. That said, the first patch in the series also applies on v6.12-rc2. --- Changes in v6: - Introduce VmArea{Ref,Mut,New} distinction. - Add a second patchset for miscdevice. - Rebase on char-misc-next (currently on v6.12-rc2). - Link to v5: https://lore.kernel.org/r/20240806-vma-v5-1-04018f05de2b@google.com Changes in v5: - Rename VmArea::from_raw_vma to from_raw. - Use Pin for mutable VmArea references. - Go through `ARef::from` in `mmgrab_current`. - Link to v4: https://lore.kernel.org/r/20240802-vma-v4-1-091a87058a43@google.com Changes in v4: - Pull out ARef::into_raw into a separate patch. - Update invariants and struct documentation. - Rename from_raw_mm to from_raw. - Link to v3: https://lore.kernel.org/r/20240801-vma-v3-1-db6c1c0afda9@google.com Changes in v3: - Reorder entries in mm.rs. - Use ARef for mmput_async helper. - Clarify that VmArea requires you to hold the mmap read or write lock. - Link to v2: https://lore.kernel.org/r/20240727-vma-v2-1-ab3e5927dc3a@google.com Changes in v2: - mm.rs is redesigned from scratch making use of AsRef - Add notes about whether destructors may sleep - Rename Area to VmArea - Link to v1: https://lore.kernel.org/r/20240723-vma-v1-1-32ad5a0118ee@google.com --- Alice Ryhl (2): rust: mm: add abstractions for mm_struct and vm_area_struct rust: miscdevice: add mmap support rust/helpers/helpers.c | 1 + rust/helpers/mm.c | 55 ++++++++ rust/kernel/lib.rs | 1 + rust/kernel/miscdevice.rs | 24 ++++ rust/kernel/mm.rs | 344 ++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/mm/virt.rs | 264 +++++++++++++++++++++++++++++++++++ 6 files changed, 689 insertions(+) --- base-commit: f893691e742688ae21ad597c5bba13bef54706cd change-id: 20240723-vma-f80119f9fb35 Best regards,