From patchwork Wed Nov 20 14:49:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13881311 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 ACB5DD711A5 for ; Wed, 20 Nov 2024 14:56:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DF1E6B008A; Wed, 20 Nov 2024 09:56:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 28EB56B0092; Wed, 20 Nov 2024 09:56:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1300C6B0095; Wed, 20 Nov 2024 09:56:19 -0500 (EST) 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 E39286B008A for ; Wed, 20 Nov 2024 09:56:18 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8E8BCA0AAA for ; Wed, 20 Nov 2024 14:56:18 +0000 (UTC) X-FDA: 82806771390.03.62C7F2B Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf21.hostedemail.com (Postfix) with ESMTP id EA4FC1C0007 for ; Wed, 20 Nov 2024 14:54:38 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2c80yE+M; spf=pass (imf21.hostedemail.com: domain of 3j_g9ZwkKCLgYjgacpwfjemmejc.amkjglsv-kkitYai.mpe@flex--aliceryhl.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3j_g9ZwkKCLgYjgacpwfjemmejc.amkjglsv-kkitYai.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=1732114426; 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=iHHs841g6FN7yTueS7BUd1kUsp73KLDPPhCP6P2iTMY=; b=GiAOxPsZXEriOuQthMZLB++VUjUbQ1ngmPZO3bthVEdP4rg9VDHo784RIGWoVQ5iJS4vQC isGA+GEWSSIZLjGvBhgouy1qrgVfWnD23LwZnHdTQV9vL4mu8yV7sBk+cfmSGWdY7WkgzS VhLOjjune9A0xWhMkM5KaUy5MlgV2yQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732114426; a=rsa-sha256; cv=none; b=wzbmWCpxlxdAsT1ylPvip+KNdPyir+7aQ1hZ7dn7uWhUXH0guOg66Z+uchfi3ELqq7Dl8F 9iOVLNzh1hpZ4pudSvHJIBEg9RcrPCbDmRkp7rVzvR+O63zrTSzsfn57QYSznT26l6Erku MjpOVNP6ebMbUcMHqjmBfe24KSNLfk8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=2c80yE+M; spf=pass (imf21.hostedemail.com: domain of 3j_g9ZwkKCLgYjgacpwfjemmejc.amkjglsv-kkitYai.mpe@flex--aliceryhl.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3j_g9ZwkKCLgYjgacpwfjemmejc.amkjglsv-kkitYai.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-6eeb889aeecso27430837b3.3 for ; Wed, 20 Nov 2024 06:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732114576; x=1732719376; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=iHHs841g6FN7yTueS7BUd1kUsp73KLDPPhCP6P2iTMY=; b=2c80yE+MUTXHhQRKnU+Y3pif+3LwPT+93KffIu+qcbIG21pMOFJovmn4dB4IKGZqem 40UxxxvMzrC7nSi5d2nznWsVMeT/HqA0op8jVm0Hyy9om6B4oOBCKSPZKlwz3x381nQ5 zkdlIxFLE9xjI6/qIV6LUL9Ne7mkKru0k7Jz9+b5RfKLonBmzIOSzBz8/MmFvA+Hit5D mxQsCLnpe5HoTt78AX1lSwm2KFmCtHBjprtmIhkRNM/dyAPpP0x1mTFHPPqPXS5PozcO FJeywYq7t2Kxde90D7HdlqvvwkDHXlpNRtHk4QqHa6pYuM7NwBK4LCF60VYwhp5HBdNv Mg+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732114576; x=1732719376; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=iHHs841g6FN7yTueS7BUd1kUsp73KLDPPhCP6P2iTMY=; b=IzJozyByNw2o+IT3v2D+n63UK0RR/8JY8hCf+uxr3u6z+2kUj+rw7ftp3IXB4vPRge 0Xmk7I2GYDFmDSHSpDOHL0w16/olH9q0NspKw07sQ5dsJW8xLhkVNecEehUzaQV0NmOE IJjL9HCqtVHUBWpej6BE4gmmbrpxddaUMZzvLs7qpYJfwVSJsFSFQPrnb9BPj1Bfi7In oSMdOl6Ic9Ez/UfEI7PloAXbmmXRwkbRD/LpeeWe5KF2uR21LvhVXeFInBbdWMhmwiY0 Q2I1h9HXm2HxlQUQLo/P2COs8VyEmmZEn9ytJVejRqxyvCdZlcggJVEVkY3p8vYg0YLZ xBtw== X-Forwarded-Encrypted: i=1; AJvYcCXIvoRko2PeveE74Ssrl5B4HbOeu5SkPLFAXuE4+BOqXd/mRfXzbgpfrNhWoWiy6zJc9HeqebobeQ==@kvack.org X-Gm-Message-State: AOJu0YxmNUFr1sO7zoB8uoJssMyz+G42OY6MtoQBGcGG2iE83WGYJ0T3 0cV6m6B8BZqh/MJb3Qnr+OTZci1lWdsPhNCAgaENPLwM5eQWCSLjU60Oo2eZ33cGKDzYbCwuPGl uCmlUmjwbaBwL9A== X-Google-Smtp-Source: AGHT+IH8MrrXVPZZuDuLH+xVKdoXCMLFK6Gn+/sxLCB228YDJMNSgRxGu7HWs9RTHvIoY8xY3Lm8XRbkj18WCBk= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f29e]) (user=aliceryhl job=sendgmr) by 2002:a81:ad16:0:b0:62c:f976:a763 with SMTP id 00721157ae682-6eebd0c2111mr172127b3.1.1732114575699; Wed, 20 Nov 2024 06:56:15 -0800 (PST) Date: Wed, 20 Nov 2024 14:49:54 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIABL3PWcC/2XRTWrEMAwF4KsMXtdF8r+76j1KF04sZwydSUlKa Bly9ypjaDNk+YS/J4NuYqap0ixeTjcx0VLnOl45hKeT6M/pOpCsmbNQoAx4peVySbIEQIwllk5 bwS8/Jyr1+97y9s75XOevcfq5ly64TR/9ghKlVinbxEWB6HUYx+GDnvvxIraCRe2Rb0gxSp0mG 5XPvU4HpP8Rf7AhzSh3rsceUskpHpDZI9WQYQQRU/BgQzL6gOweuYbshgxgKGAzqe6A3B9CQGj ISZA5RNCxc8X64ya/R6YhzwiQtCrB8R3sA1rX9ReHdt8+1QEAAA== X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2963; i=aliceryhl@google.com; h=from:subject:message-id; bh=dT7Zkr+UIC4q/j6ipR4QBx4F66YP/oG6Xz0KcH1wcTE=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnPfh4SY8iEVd1Q0QPBJyy1bHyLIkOtvQvSBL9x 38z3ZROFj2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZz34eAAKCRAEWL7uWMY5 RkSZEAC0WX4fMT+IHnG7zNw/4rDQeAuCEzBqeNoDJ5m2kCr4TtPdsSfOPasI/kkB2enSi9V45aN F39b47+uzd17RtTxK3pK5M4Z48MKfDkLkM3shieJPdbsbmkoYfHX0S30lFMbFM1yepGTyxSILVi 5mdp75tOU1qRdWdrANz0ITas85x4TvdIrBAr/6BmXh7bF0KJPrq+DycAMy/JnJi/y0IIRkkVwb8 UuMC4PFOPHtJt7LUdsmpfS46Y3rZT3EAksgz+OvU20f78lDCSoViB/+EFN3xmCEv3fgIT/E0zNr tXLJ/PQ+nC2kdSuUDc3vUG8m4dxR19ojnJZzLORerAiQzYIES1cMItXFlj58PT8KH91d9Uga3x1 3zltJ0fjTanM6lesx68GLBPzqBBRrRnYDbgniCZyeUHOqK8vPm4eDoDneTskU1Y29+hNgL71c64 JKjL2fbO8ejnLujNijLkHzcN5w0AJ9hRonfdx4rDsCj37kacU1AGhiyxMnZ/f8niTqZEZV49p2H RQZhldSXsTF0WPDe99V9e3OM3UyJFgVL3NcxTIKhZ9cGjnT7pDA5h48x9muxdADV2OkHyy9d8uN Qs1OBhXFBHNiohASDBuLDejMDmEI9cgXcWVTbSsRTThTUL4LKYh6jZ7uvxoy4OIDgxCb8cG3NTO GM6NWL9oeWQmBQw== X-Mailer: b4 0.13.0 Message-ID: <20241120-vma-v8-0-eb31425da66b@google.com> Subject: [PATCH v8 0/7] 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 , Christian Brauner 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 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: EA4FC1C0007 X-Stat-Signature: 1wsqyk4ax5uwgw4jy7xjsok9z36e1y49 X-HE-Tag: 1732114478-921207 X-HE-Meta: U2FsdGVkX19oRYD/ZZQjr3A8OJzaNYaRpC3ykRScNAr4aa2vfj5nnBu+0s+iaDSt2kg5a5WLmouZfiL6iUb362IshcQSjHYgwyvM2iVV+Cal+2TXmfp8hSvWbR6bkGvNGlqnb7h61gYDeGe0Pony/DBdygpsvSYOHXF84Skz8jhSRkj8/ZB8J9K6OpGAh5pBu3ZkWb5d6XEpoCoLbUb15ABnR5n+BYvsrbwG/Lt6TqZH/eI+5vB+xSFPmaukVLsLPVvis7FQDHsQXJ2/OKdXL9m28w7i469MChvdGyYCNlC6qsMBPCk/ORdf7F5ZAgWVpv8Com7PK2eH6n0I78+cEgxAhzGxGU0nio2wwBjgeXcGAsQRdocVk4hKrBrVRnDEztpZOnRTb3eDhHZqEtJm+8WN0lozB40I90AuOd7QVG76wYTjdZ/sqqkKbsJiV8vRS+UnvcOYTjJQZI5anJ2pN+ak8mWx4/uC9vsyDba3Afu4DwJSvyzT5is16riyfVBmXcbaLDIrSZKY/hjGVl8+65qp5sA2bNDqL/zY+CdjH9H1RXd/g3TXvzfUYHE8o46AMKDa4XSJFgbGztvesVfnoH8areHJ2Ah87lewAh/T9iUGL9DLorsP80IuPv0fgDrH4jmwFdKI+PAWyFToIxz4frD0ZyL1eHF43c8Vg5fhl7obB++IwgIcFQUJZbd/58MIR7r8UEvDBMS8EQPiGa2HH+aaBcLp0KvdUDxnUslXmsA/BqIpJJ22GqryHKZsJWPlRWI34jzmTPlDMigddLNNownscCejpmNz1haBHjP4MDzX6seUjYzMmRkjl5I3qapMARud68SejK9/lU5zBsktdaT4a5nVmFDUK1PRjE2L9R5iQiCevD+CJLQE224+REBu/6BY/VBAKI/LK+FPqs0PdvXIaM+E8GXlBKlGHyNzMxxevCtbLFUZLstfzLQXcbwGMscI050SWUJjfM7qmbE vuVRg4kS EuIouJu2ox7pNaYXFYb3XB4u5gzgRxphws9OfWyzONULYyDk63i32aqOjno6CWcfzfqJncpXlWwI0SVKiL+hs9omdfYa5B2ZDO4Oa98qNXai8i2bPgNRAdF0M8GSFqPrDwCmcqF+rXXELpTyyWoqMQvmw7ONyObqz9kF91sZj4ksFCqgJk3g+z6RWVahcCcHk693j5toKKT0tjU9P+gwzLpwzF15tK4P1KJkvptfrMnnODIHBkKEG3yvXppa3vwFaif5K4RYUx8kI1OX5UH65V1IVa1ToYr5TxQM9m3Gv6U88AW2NdXuViTkkH/RMkrnODgQB/Ehf/4kUOZRT4qoOFmKunsB0r9U6LRQaZyP08aPyqVNCVRFeSQeoAQRxm/DRqrwlrWW9tHcnISZvqXgmo4XojOjVvjeLoAmH0zj2vxfnOdjk3lvwe4hYzoeAGFgDflQnxkIP9J7TAKTfR7+aaEFZyIpSc8bmF0fXSl0+9ujOk+KQaqgb8QBplOj9n5TmaazdK8fhhd8yTYJAyXeg7xj5zinq59RynmBgWy1FbXn0CYtFXkzklpq1HV1RTQ2M7DVrivYc5ucp2c5D41fpiu4IL+iqKOvItHIDc9gR7ucKtkjrqVUNX+MSFE64LdGHnkmRPtAM/4c1zFFe7C6WZmtjgiK/GpFpU2j6IEhX1rRx4wW8YuQOBxb3A0/q7KVrvh6jxje4YmkEAP0= 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 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. This series depends on vfs.rust.file and char-misc-next which are scheduled to land upstream in the current merge window. --- 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 (7): 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 rust: miscdevice: add mmap support rust/helpers/helpers.c | 1 + rust/helpers/mm.c | 50 ++++++ rust/kernel/lib.rs | 1 + rust/kernel/miscdevice.rs | 28 ++++ rust/kernel/mm.rs | 345 +++++++++++++++++++++++++++++++++++++++ rust/kernel/mm/virt.rs | 404 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 829 insertions(+) --- base-commit: 7f219f5002eb0ce2b12562127aeb0521bbf2146e change-id: 20240723-vma-f80119f9fb35 Best regards,