From patchwork Wed Jan 15 13:35:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13940443 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 5718CC02180 for ; Wed, 15 Jan 2025 13:36:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B533A6B007B; Wed, 15 Jan 2025 08:36:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ADBEC6B0082; Wed, 15 Jan 2025 08:36:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92E4B280001; Wed, 15 Jan 2025 08:36:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6FC856B007B for ; Wed, 15 Jan 2025 08:36:08 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DF01BB068C for ; Wed, 15 Jan 2025 13:36:07 +0000 (UTC) X-FDA: 83009784774.17.E8B5A09 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf17.hostedemail.com (Postfix) with ESMTP id F37DE4001E for ; Wed, 15 Jan 2025 13:36:05 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=sINXotbj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3xLmHZwkKCJk3EB57KRAE9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3xLmHZwkKCJk3EB57KRAE9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--aliceryhl.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736948166; a=rsa-sha256; cv=none; b=WTfTfOMruCSJ8B4Czhf7JmQ/Q4GTAny1/F/4en3ly7XlwiPqruwG8mU6e5cEdBpQFbki+p zSmI/ljwRqBEc5Q66k6kiyIxmR6oKuDKQ9g9kkjJ+SDWwgAVJqScoeAb4MN0y1cxV2TV6u iPdxWhIKUVyQVuctZv2pH4W5zIVa7FY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=sINXotbj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3xLmHZwkKCJk3EB57KRAE9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3xLmHZwkKCJk3EB57KRAE9HH9E7.5HFEBGNQ-FFDO35D.HK9@flex--aliceryhl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736948166; 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=QJt0NwnF+zEPIT7s9Z05/9x45r5eY4ar9nsfpGZZ6/4=; b=qgSh3m+tBxKgSIwnMlaR6L1Qkq+sYWN4Z18Ns38Ging9GiUtfXGF9JNwJLvwEScdABW0Va x7Lo8PL0LFYHDhkd1ckCoHu1uMKHW9v6tQfHUf+vCybro1zT/Ab1XPj3BVPfRLLJmpBTy/ rN0aDllC1aEaRMmKlWtBAu8ISrYdb1E= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-436723bf7ffso28581915e9.3 for ; Wed, 15 Jan 2025 05:36:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736948164; x=1737552964; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=QJt0NwnF+zEPIT7s9Z05/9x45r5eY4ar9nsfpGZZ6/4=; b=sINXotbj58y4cKii4qkl9pvAU0Z7XIahtTOyROLZ9HI61JqrCDzi7FYVXIc4VGvwId bJECDje1uTcyO8l+YogHJ2M5sEFIKyhugzsYDSRfqH4N6Z1kPMaOk9jnVFcyyJ8Els9f OhhSZOHLVPTRmdy2fjOI7olBqhWpCX1LOlMAGn/uyzB7xRF37ocvVtXb4UzoGKPz1pcH lktMoxURmZYKEE13PkpjZrI/fOMYCDvZxQ/Tqa1pzXNxME1A18SzIq60QUfrLb/6w6Ch jbPmmQry9bs5lD/q5d4v3BzY13t86if7YgMyYbMk7YFYIVznzSOtfpEA6na20Z23w4fu mPqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948164; x=1737552964; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QJt0NwnF+zEPIT7s9Z05/9x45r5eY4ar9nsfpGZZ6/4=; b=WxZgJPWAeWEOn73Gpndzr6yqR/MKeUAaLLlbdB0helMxTTiPVWvOsWNkjWVLOzJRa6 Ls4ejqPN1hSh7Ztq2HxmF5don9kwy8zrIuRI2ZF9UkYzycrNBZXkaPQjp94Ws+mUJRAQ IAS2RZ16pQltwvVOD2At5h9RN+RUX6mGrooUWs3FWsqu0EUeDMC9RgV4JcxM48MY8ie8 YkmotjuF87yv3PePgx13qHwfI6S1x232XNni0XeyVSC0hFCKU7hgMXjNuAVvcxBvdIIP Mhv0wLsz1FV990Nnb+DsaKc77HbdsL3rxSPX6f3aev+ExDM/tKxUdEAka+4isxbnTee7 M2Tg== X-Forwarded-Encrypted: i=1; AJvYcCVxsc7UkPVuyl6YVX4m89U0B/cSXh/nKjLE1lVc1hKTmFHhm3wC+f4N5JpV6Nq+la/Rjx58XmaFDQ==@kvack.org X-Gm-Message-State: AOJu0YyvnRtMWLVfbWCKeLgdbOvpXY4+6S2nl3zGoRTh8m4NnLr4AxOL jEsNUIzhaZiUoG/n7Hc56bgmtrutfzQlPsRDv6OYgxQmXeLISjq9JbWRSgy6fWMWWDEozoLIdet tmXdFpmd84FmGKQ== X-Google-Smtp-Source: AGHT+IGK1xZTOtHdTgRlhLDWD+ToXxEeoqzsoT3aptOIZ7komuwsaBRBJNe5QrfIeGYwbIsagNZ6Ds4T0K+ARh4= X-Received: from wmbfk15.prod.google.com ([2002:a05:600c:ccf:b0:435:dde5:2c3b]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:1987:b0:434:fddf:5c0c with SMTP id 5b1f17b1804b1-436e2679e05mr275323325e9.4.1736948164552; Wed, 15 Jan 2025 05:36:04 -0800 (PST) Date: Wed, 15 Jan 2025 13:35:03 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAIe5h2cC/2XSzW7DIAwH8FepOI/JNt877T2mHSBAG2ltqmSKN lV997lNtKbihED8jOU/FzGVsS+TeNtdxFjmfuqHE2+QXnaiO8TTvsg+84EgIA2OlJyPUVYPiKG GmpQRfPM8ltr/3Mt8fPL+0E/fw/h7rzrj7fTZzyhRKorZRC7kS3nfD8P+q7x2w1HcCsy0RW5Bx CgmVUwglzsVG6QeiBtckGKUk+2wg1hzDA3SW0QL0owgYPQOjI9aNchskV2QuSEN6CuYXCg1yP4 jBIQFWQky+wAqJFuNa19yW6QX5BgBFkXVW87BNMg/ENL6kmdUkkJNJkdr2/bCFq2DCIwckku1y 9noNieErQprutye1LlWnkSKnFbLHp8CCdeoeGVmrdWgydfueRjX6/UPCdAc6q4CAAA= X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=5088; i=aliceryhl@google.com; h=from:subject:message-id; bh=Vm4YeMs1sTGWonvj+6yAEU1SHf+sI2+UBVeCMDhl7q4=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnh7mXx5k0dTMzrixzQLfhcBrHgnBgjhc8I71tE XISPleDzzKJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ4e5lwAKCRAEWL7uWMY5 RvY4D/97j/AY3Cb9bMxXhA8VWbU1gQuoE+LTkDzBYjjw/YhPkUUC3lOSNwEzLWe7mU+gnO7Yamm PKqfYJR6B6vExINgT6GedzLsLeYFU5F25C4HJb/1rp72hzTQZjjVnlyYC++MkqHH1ellZIxDVRw c3qqW2pzroTxGnmrr74253bfU8YMaRQ9MyejixpAzzNAtB5MkQ6qx/WTzAlXNrqFCSl0gc8kX/M ULLqdwjFxVSXuLfG+xzuDarYvJ6JsdbxlsYvmRaFA3h5TjpTjd/119njvINJ5+BUx9EYDasVlXl ZtOZnTdSDamkf+wXl7b3v1OTs2h3QZlHvefMW0TcThqc215Zxedd060BamISqBEAfSLDoBCTzag jO5wqbxmKBbDDJLRLk/GzQNawga3cGhzj2pFIjDUM1NNRwW1u50DwiWkuvMJe+v+TDd1hrVxJpL hgOYmHlaHeRcVd47cwool0h7cH9orvaH9eIStkJo914On0HRoY6pDj6LCccZ3rSa1+nrAXI1pWs h+FR6s7U8zG+22dqvINnvWvl04+813qW+X/NO115f9sxD1GxEGpb/7+yZpkGVf8c0USxCKmMVw9 9nFXQhim7uY4EpKryrPdcIggkAw7ei3gUekABuGxQk23IM1Qo66C3UOVcnv9wyTyZT+YYxDjODC S5AM3yOpgY9CZ0A== X-Mailer: b4 0.13.0 Message-ID: <20250115-vma-v12-0-375099ae017a@google.com> Subject: [PATCH v12 0/8] Rust support for mm_struct, vm_area_struct, and mmap From: Alice Ryhl To: Miguel Ojeda , Matthew Wilcox , Lorenzo Stoakes , Vlastimil Babka , John Hubbard , "Liam R. Howlett" , Andrew Morton , Greg Kroah-Hartman , Arnd Bergmann , Jann Horn , Suren Baghdasaryan Cc: Alex Gaynor , Boqun Feng , Gary Guo , " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " , Benno Lossin , Andreas Hindborg , Trevor Gross , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org, Alice Ryhl X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: F37DE4001E X-Stat-Signature: nn45dqhngoihzgrkiwgy1ma8x38dmc7o X-Rspam-User: X-HE-Tag: 1736948165-514383 X-HE-Meta: U2FsdGVkX18MnWZQe+1kUvCmA0eKZy4ipxcuAEyAknFl0EkcePLYxdkjEe9JbotV2fiiEQuIBJRE6uL4+6MBLziIvvLmMymntA8CDPLyby/Nk0+D0Fe6YAHjhMrybx/jXx6k2SM+LYWZHtE8O9SgoCKDMpT5wb7vBACx2G/Ysc63bk3zvr16ZqrfHeODRx3KCH5bvRRMe5DTUdfeteCL1u993RyRdzhnrX2Dz0dxufTo/bB+JjgEG/iRZKOCk33DtSeLIoaqWeRPKmBcWZyREREecn0y3nGWzQ/ikux4UfVM2jdYlgyx/zZfNgESvEnOz8KGzR/PkjwpK/C0Lmt2cMHH5N5JOQ09OMpRz6NV9zJxF/fPqbY6gLYLY8DIhLQHHsGJpwrRM1PkM2TYeR3vltnl50uiZPOElMwOnypAfOcZzZwc2v7FRuqH96t1uFTi7+tlMPz5vUstBmDqcdpVY1RYID2uUeq5WdghK0YvgulVjfnb5RaTtHTa0zu8MkjPvy6F+WkHT7rsSJogK+NM64Db/rh5lJKOdP0A3/Cc5wZ867l3Z4Y3qHgtEP9hjcpVbCp/y29Zw4lgwpAtPP3uaIH+DtlVL7b5d8+VHWjyCRA3PCod/y0EaK3Xt/S9aEi5FXY6H/DO3a7iovTJDHRNfZ/qqTEjnMSPIw5hCBHe7F21hOiaoOqk2tDZwVYGfpGCJPYJQV3OJq56tBMiInLCQ7uQnqOTRQ2Za1/80genLadRJsGq6GewnH1mkHR9S2ug/STP0jNzbK6cO3dWfP7JzC1Cq9w8Ct/kBEspRu4Yr1IWnnWsJu4osPYSjaa2H8DFhnh92lf8OhlPnagEvthATlp5C5AbD/nFRranevtN9+fQwn7ThzZILN5Gy6R3ZiCpBHjzV662YWUXvNelh4OORuLuEnFw8oj86AH9NvxOiXJAkTsuAiuwF3V77SP7cC5wUgHfp72v8Guxox3xJab gDw4t5y6 ne/2OjQ828WVVeKlIrJ+1v/Nnq5VmYk8PAFgf/7dGOvf2VHjyzfuz7qWE25FStzA3tyVsuH38nKumLAZ/yQ1iK1lFnhr8xPVERRg4xXm5cNpbvxgC8Sy6RE+3bR+0oxGEeeTyBI/+tItxRhmd0qkrcrELOqOXjHf1BgCVe0lnKCF3IT7LwTmj3Knu6BpZSOLHPwcdDbIJn+ItkhgKIs3vNBEtzrwimg9+hHxlBtALCB6cDabZwYR702B7+JDedBlJ14oc7ggWiMH1Es/rK/eZA1xGsLS0naPjDYGAtq85J4gVxlaJJnyPtktj96WCLvi1rqiNcAsMu0C+VjpVEJkc2u3kLwe2WWlmSocahYoT1aNVJvQZVQXumeAALbWfcPN49icOlQniro15u883P5x5LVI35G9/M7d7B1BUYEHPbG0uT0paExHNfNp0UynQad/YThHGQEZBFlzA0ULyGVy7tAWT5i7vSVcjRHFVG6xBwRfW0KEN22BFepauXw3x9vSJKzhi8Id7Uu/OibyV5ZKglql6EjnTVqKXuDCH+5uPICUmmZuTW4L/NW2tUsiYDVRxdFBDmMOXlWVDI/9zX6LdF1N/Cl/yErFIU99U7BviwjGRIMNYGanYNCtGaGLUe9BotKUSvCy63+2GEvcH220ePxCN1mMykK76OO1xpOizYpFJ7wPjNOKGCHjU/+cdpmGMW3jKbMeeBOKSn78= X-Bogosity: Ham, tests=bogofilter, spamicity=0.418531, 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 updates the vm_area_struct support to use the approach we discussed at LPC where there are several different Rust wrappers for vm_area_struct depending on the kind of access you have to the vma. Each case allows a different set of operations on the vma. Signed-off-by: Alice Ryhl --- Changes in v12: - Add additional documentation to modules at the top of mm.rs and virt.rs. - Explain why the name Mm is used in commit message of patch 1. - Expand zap_page_range_single with docs suggested by Lorenzo. - Update safety comment in vm_insert_page - Mention that VmAreaMixedMap is identical to VmAreaRef except for VM_MIXEDMAP. - Update docs for as_mixedmap_vma. - Add additional docs for VmAreaNew struct. - Rename `get_read` -> `readable` and equivalent for write/exec. - Use mut pointers for `from_raw` for VMAs. - Update safety comment for fops_mmap. - Add additional docs for MiscDevice::mmap. - Don't introduce and immediately delete mmgrab_current. - Reduce active_pid_ns comment at Andreas's suggestion and link to get_pid_ns. - Fix documentation test in rust/kernel/task.rs. - Fix warning about unused variables in lock_vma_under_rcu when CONFIG_PER_VMA_LOCK=n. - Fix minor typos. - Link to v11: https://lore.kernel.org/r/20241211-vma-v11-0-466640428fc3@google.com Changes in v11: - Add accessor for the vm_mm field of vm_area_struct. - Pass the file to MiscDevice::mmap for consistency with https://lore.kernel.org/r/20241210-miscdevice-file-param-v3-1-b2a79b666dc5@google.com - Link to v10: https://lore.kernel.org/r/20241129-vma-v10-0-4dfff05ba927@google.com Changes in v10: - Update docs for `set_io`. - Check address in `zap_page_range_single`. - Completely redo the last patch. - Link to v9: https://lore.kernel.org/r/20241122-vma-v9-0-7127bfcdd54e@google.com Changes in v9: - Be more explicit about VmAreaNew being used with f_ops->mmap(). - Point out that clearing VM_MAYWRITE is irreversible. - Use __vm_flags to set the flags. - Use as_ and into_ prefixes for conversions. - Update lock_vma_under_rcu docs and commit msg - Mention that VmAreaRef::end is exclusive. - Reword docs for zap_page_range_single. - Minor fixes to flag docs. - Add way to access current->mm without a refcount increment. - Link to v8: https://lore.kernel.org/r/20241120-vma-v8-0-eb31425da66b@google.com Changes in v8: - Split series into more commits to ease review. - Improve read locks based on Lorenzo's doc: either the mmap or vma lock can be used. - Get rid of mmap write lock because it's possible to avoid the need for it. - Do not allow invalid flag combinations on VmAreaNew. - Link to v7: https://lore.kernel.org/r/20241014-vma-v7-0-01e32f861195@google.com Changes in v7: - Make the mmap read/write lock guards respect strict owner semantics. - Link to v6: https://lore.kernel.org/r/20241010-vma-v6-0-d89039b6f573@google.com 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 (8): mm: rust: add abstraction for struct mm_struct mm: rust: add vm_area_struct methods that require read access mm: rust: add vm_insert_page mm: rust: add lock_vma_under_rcu mm: rust: add mmput_async support mm: rust: add VmAreaNew for f_ops->mmap() rust: miscdevice: add mmap support task: rust: rework how current is accessed rust/helpers/helpers.c | 1 + rust/helpers/mm.c | 50 +++++ rust/kernel/lib.rs | 1 + rust/kernel/miscdevice.rs | 45 +++++ rust/kernel/mm.rs | 339 +++++++++++++++++++++++++++++++++ rust/kernel/mm/virt.rs | 476 ++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/task.rs | 247 ++++++++++++------------ 7 files changed, 1041 insertions(+), 118 deletions(-) --- base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4 change-id: 20240723-vma-f80119f9fb35 Best regards,