From patchwork Mon Oct 14 09:29:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13834511 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 84312CFC52C for ; Mon, 14 Oct 2024 09:30:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A7076B0085; Mon, 14 Oct 2024 05:30:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 056E36B0088; Mon, 14 Oct 2024 05:30:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E60C16B0089; Mon, 14 Oct 2024 05:30:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id CA08C6B0085 for ; Mon, 14 Oct 2024 05:30:14 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DBC48140C3F for ; Mon, 14 Oct 2024 09:30:06 +0000 (UTC) X-FDA: 82671686622.04.1E73A0E Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf11.hostedemail.com (Postfix) with ESMTP id D80FD40003 for ; Mon, 14 Oct 2024 09:30:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=12UDGgtA; spf=pass (imf11.hostedemail.com: domain of 3o-QMZwkKCN4ALICERYHLGOOGLE.COMLINUX-MMKVACK.ORG@flex--aliceryhl.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3o-QMZwkKCN4ALICERYHLGOOGLE.COMLINUX-MMKVACK.ORG@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=1728898070; 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=0iJkEGvsoK5hcpHtL67ZHm4We9Hvjnd+4MuIc6M0BiU=; b=qaVe/RV6bexgnFe3xs1BJ+N2SyWPWrfxtKHAb+UR7edRRg2VCw56w4le15W7fmvmgq7o88 r7S7og73pOy3vtrva3jpIYpyq4YMkI64wxPmcpT8IDGmEvHfqd3MKh2epk2MOhJKObHZfD IUQFOqVDerWFTGtVlB8k3MfEbNOlaG0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728898070; a=rsa-sha256; cv=none; b=QC6DTqlJPt5L/VaCosKpkbmbfM9qNbN5YxrKsY+RzN0Mq9LmOXMf1ZRW6CQVtYuRnsrwua 2bdcLywYzGvv/ArC+O2UArtETQOesELWvUyZZ9YN6MmPMP9P2n5ruDWoESFUkn0dFh9V+3 s4e8bQISitiaSAkLhn8X9XonQrULSfE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=12UDGgtA; spf=pass (imf11.hostedemail.com: domain of 3o-QMZwkKCN4ALICERYHLGOOGLE.COMLINUX-MMKVACK.ORG@flex--aliceryhl.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3o-QMZwkKCN4ALICERYHLGOOGLE.COMLINUX-MMKVACK.ORG@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e000d68bb1so55778967b3.1 for ; Mon, 14 Oct 2024 02:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728898211; x=1729503011; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=0iJkEGvsoK5hcpHtL67ZHm4We9Hvjnd+4MuIc6M0BiU=; b=12UDGgtAt9Z8VECk0lep/vk8snIHEk8tAIsumIKx0HDoQXlxWvW6BSqRJo1+JmsA6P abppRVA7oNl8vP5tJWPgGZpYLTK0j92eopzXVg0iE3+b12vE1GNNyh9022/PrgQEnpwI 2sVqBDz7mjcdRbcJHc4Ot2tLnOfuprm599CWROrtycWjS0wLLYEkGgc8SvoQzWk+aAAb 2d33nQ463nW9fij5dUkCHljLSPXLum16rexYe7SrLmg6IcqtLOO1HqadRePVd38Lnloc nQSwEyNY6qT8QM0Gr7Knz6imrtDkZCF93cn5opnrlMB40q0/lKGGWmgORDX2ejX8iCkj Tj2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728898211; x=1729503011; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=0iJkEGvsoK5hcpHtL67ZHm4We9Hvjnd+4MuIc6M0BiU=; b=OVK8ANWbuZatgXi1Nv5sQOhWSO9KlhGF7AGoXSdKS/YUuujgBkqERto9wTBacsWM/a iDtaQ0/jrt1FGmRFkPNiQlTThow+taylmV/YtvZk+lMmBxXenqp6awNW6TDDXPZtyk9r KTmeii/i0KjIPFJQgWy4emcUfLBDiZNvdU5WWMjRDsoE+tq+CuahRmX8KqKLZgAsrDYS Nog+klcJ8jJwQJpFF557vq6MpSzTNk5e79a+si0hVg+t+Vkmvbc1Xx4fLaunKhwuIZ4u ryVA8jG9j63ja13rOtf+iDiGBj3URHDqg88pdoivgi7gTtVaH7gX5PAqHq77c8TJlLhC Ihdg== X-Forwarded-Encrypted: i=1; AJvYcCVOaMa8Gdc97y1vXSTDoOkhFwDBy+4itypoahlOpRju05ZPJ+9r9zishDswyDBSZlGhZdSagNIvbQ==@kvack.org X-Gm-Message-State: AOJu0YxuOxE4/P+amKstJ2eh3onAQP73zBiydAbfYeXoB8epoHdUjcmY suqkbgw4rk4qsY2xvDYPZJTypJTSrwKJ/cEnxq8D13bRC70d+bAehPkaR144XFp6YGJBlQT0OGc 5k4X37bizvib30A== X-Google-Smtp-Source: AGHT+IFwXQ1X6dy8pYShptQ2LDtPPnqmooRTc0Xq3ILRYcs4f/0Ul1hHs5Lr+vRsdjgMRGuqjHlTTGnR89Tn4+k= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:35bd]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:1349:b0:e20:2da6:ed77 with SMTP id 3f1490d57ef6-e2918421de9mr103466276.5.1728898211372; Mon, 14 Oct 2024 02:30:11 -0700 (PDT) Date: Mon, 14 Oct 2024 09:29:50 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAI7kDGcC/2XOy07DMBAF0F+pvMZoxm+z4j8QCz9TS7RGCbJAV f4dp5YgVZZ3NOfO3MiS5pIW8nK6kTm1spR67UE/nUg4u+uUaIk9EwZMgGactouj2QCizTZ7Lkn f/JxTLt/3lrf3ns9l+arzz7204TZ99A0pUs5clK4XmZRep1qnj/Qc6oVsBY3tkR6IdeQ8T9IyH QN3B8T/UX9wIN5R9CpgAJejswck9ogNJDoCi85okMYJfkByj9RAckMC0GSQMTF/QOoPISAMpCj QaCxw61WW+vHSuq6/d4kzh6ABAAA= X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=2590; i=aliceryhl@google.com; h=from:subject:message-id; bh=L+BrUmFZG6coCaN6vjYiTwSGbPWblzWyjGISzbq8GQ8=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnDOScqrVsEORZcGk7VjQ60QCLyfj+s9M2lAQyq 2MfNYCRwtmJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZwzknAAKCRAEWL7uWMY5 RvVpEACbFLL+7SM1I8M7MYHkZ37J9Ht+dM441ZT+0/12QSvTk1IH31bseOF9hH7aSTkrJ4CqyM1 LyR+Auei1Nbj1jhjyuvT63Ekqiifj7+0nRxTlphN2g8KdHmyQj9Tns1H51s/fqJbrBtom8QMTg+ 9mDeC7j+8ZWIuDy/pvH2ptiTs16EuKqVuvsLgvHiDTee09XD0LesfLqUGo7qFwZUn6T6jdT9xfq OkSZ3lITJCUjizoBspzv8CscpRHaqa5U3QupWq6kNhpl76id7xKo+uQDr766sKW1WMLPRfWdQxW 2Vk1V5Sp7nbOfAGgKpKUxt7IoEn4AwXR+iEaMYmKMTdiIo6ZwbIneW/zhElxAxo5saC99+iYQUd 5ymK0h5twwNMANJIM1unDaZwXoCMfThzLSFpD1em8h4O8aaRy2O5XsnYmFkuq5TQ6DFfA1dgniR NAJGNrdy18pekvn9JsQp6aEMmaYsxoLON3clEFZfmAQpcb63osUbroKvAoBB4JYCVRcJdEipLvk cVe2SmT+pFTm2fd1WBNVRzRdrBsET7vEQ0mk0Wul0jQdJ46Q/3w9U7q/jFMi0BM57N4kzWX3d9+ tBTgbpb+gWejsmpE5mJWzrnahTKvLZJI8ZaREmQex1p/3zJ9tjA1aA9BDpbYKFuuhga4MuW2w8y iUeZYAMwegwU+zQ== X-Mailer: b4 0.13.0 Message-ID: <20241014-vma-v7-0-01e32f861195@google.com> Subject: [PATCH v7 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D80FD40003 X-Stat-Signature: 6m3pcztcjipkdeejn4uxuruszwyceqxz X-HE-Tag: 1728898205-675784 X-HE-Meta: U2FsdGVkX1/O2KKRiXktI9LYNhyuJ1xJmZT75H5xxO9nw2nkIZWPRxVq5l9BjIbxI6FQw6gEROTtHzX6axQ/mceefE05ew8hxvX3yjIW4zUgM3XJOWeS/nuWmo9L7EIgezsDstUy4gdY47BHvZiyxCYy0MpKd4DyLRw8XyPq3ab94rdwmnaZ4AZfC0zIydObMLjB5XX+kEAaoZCex6JOBn0wIuK8MBFeuYd6EafuNGmSd5xKaQ62/Kd6UDW45j5yqAzdqho5BH88OXF1TKAqAq1gVwXN44bLXb/hMOiHE0fP5wOTYoeT972TI07hnC6T8vtHMApJSURHM61t8Hk8ZogGQMTConkeF4O5PiyyAyIPjhf1g8N1RJnKhu2zyD5fNaCxnHGG9hgQ20qvmFGiVrqeONcNwNxwTOn8+vCGxwq6qrLredtT4K5X05Prw3i/SSVtTYhY+NH2wXM7rW6r1VdJdOF2vrEmNfxqvCP2tOXL+AZ6tw/NZQhjrgZwZJnoXCj6H/bMtBp5STSJuY5oc3xIOWA/O62qpKBFHm09BvJiqEmwfZNrH+mExAWwcqqqGCRye8fgSQuHtNrq/P46cE0lroyPi8k4olKGZrGMfWu0fNlrhKcVqZQ6XxjRQkQpb9jr+A207ob+BdDW5M8coLuWjVhe1r2T7LGvVGr2VHGbVOCMPgl13CtAJW/ChKlbzsdyiy6b8xJ19kq+RZBdaj/yu8EUcfRbazk7I0aPKud7NVcR5bZ5BgiRnH41F/xGGxaQUdZ3fLCLQ6rJOFa73I6zAUANGurPDFsQEWb6r3Ztb7u2M7v6G5wrr2azNl6MKpn7KDb5t477Lb9OCmMAtlwX2R+fnbUpr+yORfAujAVWRv3xQ1UytB+ZfkkKuGahC5bHUzdNW1zQ6AFGHadUs4gM2wmX1PPCVdSey1q/o5/oQFtvaWDmbqnbfKVlqc257b29NDrzsPMPIrBv9rh B43l8sGB KtJpQJH8+OUKTRU/yipV7Rk3Sw0K3ng8KDxSMNwluxmnlrouLpa8I9mOYUSstR6B+bUfzEx0DQck+KdL8gvJgDsDxXzYXaPGw6GPqlxdl3GWEf+rAhUCN6xAizjLLhJHRZaY/7ddo9zcnp73gBdqkVeiLEE0mStR+Kcv1I7kqEfbzE8lr6HAD+sf1FPQkyl5nvRGkMGyoHqvPipqWoSonam8dWmnT3MxgS9Kdi3V6UsE6ZE4p3QYln8sEXLyJMCa9gZXldtk3whC1czrQPuj5o+wljKaMM4y1wSMa/UNZ/EUFIyc+of2I1WH+4LH6aXYTqidezLVow9ei0oM5nZAHkZkEJ9naNBDlG/LH5JjQaGf/Fzx+yE23sFb44vU3JLF+Qse+GGBh2FAk5ZnAs3wfmGk4Yl+RklRVXEW7K/9JjTAG29zbFBC0yJMMYMx7LDTlT2TaOch1CBjwt1Fk1cyq5H2xzou1VMcrHKmX7iqtWV8AsruBzwCPiFDudtT4peNCANXJtgZeRNDCsWoyXZr5bc6EPTy7gQoAYF6HJIdxbhxDIi7nYmNItQPHVDnVVbfD4FtwH1nAKPvvqpDL/Ho4KDXioxNgFdxKaUlmZ33/1uZVeOTY0xcZFboSpO6xB26xGgnmlvCwPh4xygiD99XV7Rd7CLcVPCOU/75/DcA+2YhZcrKBHiA5lSwqiNB7AMY92FEMYt80vj/IoPI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, 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. The first patch in this series depends on vfs.rust.file for NotThreadSafe. The second patch in this series depends on char-misc-next for the base miscdevice implementation. --- 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 (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 | 357 ++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/mm/virt.rs | 264 ++++++++++++++++++++++++++++++++++ 6 files changed, 702 insertions(+) --- base-commit: 2d424646119f28780f3963811025c05ea848b85f change-id: 20240723-vma-f80119f9fb35 Best regards,