From patchwork Fri Nov 29 16:32:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13888841 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 2DDF3D729E9 for ; Fri, 29 Nov 2024 16:32:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B5026B0083; Fri, 29 Nov 2024 11:32:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 765146B0085; Fri, 29 Nov 2024 11:32:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62D736B008C; Fri, 29 Nov 2024 11:32:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4222D6B0083 for ; Fri, 29 Nov 2024 11:32:56 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E9256C1200 for ; Fri, 29 Nov 2024 16:32:55 +0000 (UTC) X-FDA: 82839676500.12.0259DCE Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf10.hostedemail.com (Postfix) with ESMTP id 3FCF2C0013 for ; Fri, 29 Nov 2024 16:32:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3hpiAKg6; spf=pass (imf10.hostedemail.com: domain of 3tOxJZwkKCPUXifZboveidlldib.Zljifkru-jjhsXZh.lod@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3tOxJZwkKCPUXifZboveidlldib.Zljifkru-jjhsXZh.lod@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=1732897968; 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:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=AdDkek5Yx0fnCo6dzbffEiVWl75Uo6GigWomprG1zsw=; b=fx3ptS/mlAij7h+3DaeUL1vRCaB3x3Sh8jl0h4bRo2Ev2Q8Aqp0zW4Pz/RedkwOxa1bkfL 96jzzR6TEawrc8RhB3bcOrAUJZIeaibdpFNgifciXtt1B8MDF39cP5RI9vRuaNwvBwhupk 6676HNhGsCYGBQ7982yqg1ReOmi46qA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3hpiAKg6; spf=pass (imf10.hostedemail.com: domain of 3tOxJZwkKCPUXifZboveidlldib.Zljifkru-jjhsXZh.lod@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3tOxJZwkKCPUXifZboveidlldib.Zljifkru-jjhsXZh.lod@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732897968; a=rsa-sha256; cv=none; b=xIziWTawkrOITIaWtDQFkXwoe8dF+2FE8/0tBLPsro+7DiqGvGKOQwow8NbGdpp+t+LubK +NmpAsD9r3f3w6hdP5O7KGH4Fr04aOhR2IQWfj8fknRZtkgLPiyJ+EuCmHc5yEkwryh1BG Xnj/vMLJeszFKvEW9EfQKOw7ZxhGD0A= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-434a467e970so15513555e9.2 for ; Fri, 29 Nov 2024 08:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732897972; x=1733502772; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=AdDkek5Yx0fnCo6dzbffEiVWl75Uo6GigWomprG1zsw=; b=3hpiAKg6oExr2Na0lavJYbGD8PRPdXYMyjPYjz0pFGi9suwze3PU7CFON884BAXJqh 89HKN2917lFaRjD5EJ05sGXopdPTShT04ppTdJ1oooYr5a+8yVyrkzvF6C7LFWBXP55n vzYvvfZpGntZi/2a3cfL3+VVfIPqQoxXg04rOlTvdh615L6HbfwmiS6Hz5NQrNdIGj/r LWYJzLLNSG/K3C05wnrLSwUCjjah76JIHho3niPsLraNiUYZbZlLRhBluNf+lwv+A+kk /sF2Mlv5bfBTq6SK6/UkpWUVcQNB4YZFSq01P1IL57iXxvh4xm2CJhq5bR1RRTAV11dQ BjTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732897972; x=1733502772; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AdDkek5Yx0fnCo6dzbffEiVWl75Uo6GigWomprG1zsw=; b=nd6ZOx+QaBeYrKISwlGf6TZJ/nkmYrlK+UwnHwyIuJ6Qfsq4C/LzWhMXB9U0CHxpIg aG72fZFtQpiUJ/E7n8LZtlU5H2Jl6529VoNOKV+Gx4ZMh/XTmgoaZc+KajRi8ESK6bJj tbCzCb8osdQpks7JxUqXxYxLQj+ZAGGe4mFn9gEC7tkRRpw0pDoH8r/i8t7jmCHGC4KC kvd7Ix4KTd9sYEwhutjKeSDK9UcwKmHnf3K8FsO79tOAMP2mKADA8E6Bu7jh6+ltfoud xoNY1D2cJ9R65D6/OBBgIsUTRmiJmrC7hJeADQ77A5HqL0JSQUhEV4MEsqyA7zkkzqZX iwYw== X-Forwarded-Encrypted: i=1; AJvYcCUWw0lw0VXweeTHQlzipzvxVRot4NhwPyv7ewZL+cZaMRJFB/82pV8wE3B8Xx538PgXRuwAtEEvrA==@kvack.org X-Gm-Message-State: AOJu0YyAUP4nPT/1SJ7kI/28zOT2wHEiycRUHUmu92Yqj5sYkPMQ5MIi 6FI4vaykCDvcXGM8P7Kl5ZxIyEY12M32sLnEkHTuzztuZey7+2+XbzxEZfKv+BPpkFMZL4dZAM+ O3eUxbi37l/bBGA== X-Google-Smtp-Source: AGHT+IEd+WeP0yZPx6J5QdCs2EPuOVY/vOZYlux3Z8lhvwvQCPBdFiPz2BckCfzrfuurfyRG73I1GeoSZAi/JkA= X-Received: from wmlm17.prod.google.com ([2002:a7b:ca51:0:b0:434:a72c:1d0a]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3146:b0:434:9fac:b158 with SMTP id 5b1f17b1804b1-434a9dbbc0bmr100391565e9.1.1732897972554; Fri, 29 Nov 2024 08:32:52 -0800 (PST) Date: Fri, 29 Nov 2024 16:32:33 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAKLsSWcC/2XRzWrDMAwH8FcpPs9Dkr932nuMHezYbgNrU5IRN krefWpT1hQfJfz7S1gXMZWxL5N4213EWOZ+6ocTFwgvO9Ed4mlfZJ+5IQhIgyMl52OU1QNiqKE mZQS/PI+l9j+3mI9Prg/99D2Mv7fUGa/dZz+jRKkoZhM5yJfyvh+G/Vd57YajuAbMtEVuRcQoJ lVMIJc7FRukHogXXJFilJPtsINYcwwN0ltEK9KMIGD0DoyPWjXIbJFdkbkiDegrmFwoNcj+IwS EFVkJMvsAKiRbjWsnuS3SK3KMAIui6i3fwTTIPxDSfZJnVJJCTSZHa9v1whbdPyIwckgu1S5no 5/vtCzLH5ewly5AAgAA X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=4766; i=aliceryhl@google.com; h=from:subject:message-id; bh=Kn//SnjqmXMSPKs0UN6ocZ4BEFE/v6XXxAVCGEr9Q0k=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnSeyl5zS+M35OT/I2nUtC5L2kfh5ODjaiYGuDP cYtEamZs3mJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ0nspQAKCRAEWL7uWMY5 RjNXD/926bt9DrrkSPThowHNLR4dvULvxmEsBsqNJWOKCjgb1e+sCbIbxmDab8B5298zQHoojoV TIt5vCE0Ns8381mWLefOOD6Qkgn1TaxqtqzilRyWSJqWognLKQHj65DEugaccCX4yE6mh2tu4LL 6c3JgfuHm1bzXxKhSbn7DkeqUzAGOTg1rA4nZY6Uv7mBg+Ep49IetCM5Q+AuaDHdxqAkKePOHhw VQN0Vb3CFDLGURmw8CAGx/Qb/eYkYTxcRAGcMJRt/dMPWScDwiXeVuucaoSfeoqbLFp5aXqBcCx J3MBSS0NLrm7CK7VytCXJhZMQ3oqXkcvdCzMht04wt3NDQoPNDrEvvQGhmpUZCKq/ZTU+NOEeZ8 rhQ9b79gqq/SaraLvMi0S/Jn/H0jmQy4J7daYRKv75ssP9bq5ClfZz+btMvKX38cJvUBu6oa6vp gSh7+3pGk/t2CdL1CRX4SibQ5Il+U1SlfWYPwzNOjrZo88pBrnD22W04Vg7Baonw+DY1BNVn8Ik JjwexJD3jjIfvdn24Iy7frXkW42L9tdYv2HlO1kb5cuxLW3u7d5/gQ8B1NunOfqwVoaEs1BnR+6 /R8aTjt5V+VWRF0tWqA2MY2etjcpfV7mNNuKKtsZ+bgHQIWLAqnLVyVQZ1UsqynaaVIF2+Mn6vZ O84lAa0QaplKDMQ== X-Mailer: b4 0.13.0 Message-ID: <20241129-vma-v10-0-4dfff05ba927@google.com> Subject: [PATCH v10 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 , Christian Brauner , 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: rspam05 X-Stat-Signature: cntbewu7me1jm16s49on6y8g8ofjj7ut X-Rspamd-Queue-Id: 3FCF2C0013 X-Rspam-User: X-HE-Tag: 1732897969-289042 X-HE-Meta: U2FsdGVkX1996Hf2+P3z16Ecr89fM/+wHapJne6/IUalTS3tb7LiQJJBvDEzj4dGJFrDUaGZGD2/0pUE4qRSeiUlnEuwI6N0lxVcEahyD6KStwve5lxvZUusi4J+B6engkukZ70T/sbRYWvk7wg3utXoH1YMC1wisS+nLnZku6NVEuKL3JlFOf3gr8MU89dAHUQKYEOwHY4B/Pz3hX2Rbi6X0SljE6z4eOavo2EtOZjgp/yC2VkC/SQy967LmX7otWjR7EXUa/FieOCYPrKuLvcogN/VEqDgdLgpuwLToh2k1GyoGeODo11AYGiIbZaJdOAWukUnKOOOO5fG4Hg7zdlBapTdAxoxxXM7qtpEQA+rlDLZVre0O28OX7Bb8yFiMRcPYh79gdeIirWP8sdsdq4VqOfwwRxxfAlwIxBDJbsDM5oTzqepEk6to6NFVBds9vJ5o0+DrdiDCUjS6Oz5zUaVSZWBuwUbw+76kIsyj84fZNKti/Ktu9HvloxBgoWzOd14XXBwq3zh6xuEpxC2aJVy3X0uIMa+xempRjQgVKtXAbPCedb7Efi32rT/fIZt6jCgG8ykJ225zkHVlDzYKFlNcid9WPtEsSR6i0PW9CQdrqYu8RC0ab6Com+3LFyBC4j7hZj6o5Trekct2MX9J5NOwkowddOaXUmjIwAMob2sSSnE6q//YWEHHXTwRrShifCVGRAwsoIpzsqy7LKMtYb1eEWdenkNVcG5ZmbDQQPoQuVjMBqAA9GcpxEzg9oufpaWazinUus+guLIPLaM/A3WqpOt5v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xgHz5H58kmThBCC/hM69K2/BcTFo+iMETEXiSNjHZA+GTrBh/ziN9ufDczJftZ767jTCPmjJRtA/lmYKL7ZZAXW4ivSPEzKWGqp6nlIR vY/7DarW Bc6MnsRnrU+hy/8sjfs8XpjEUI3Ic+1yKtn+SEQVYwDNYfO1hE5Yny+MADHn8H8RiMd2qzAp1wHbjvpKiFaDKN/Ju0mMVU3zJWVCjU37e3g1LTxS4gxADBx+yXFbwOqdlGK82zXuZWZu2xeqEX5eiOrZFaFbpN4I 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 depends on several PULLs that have landed / are landing during the currently ongoing merge window. To: Miguel Ojeda To: Matthew Wilcox To: Lorenzo Stoakes To: Vlastimil Babka To: John Hubbard To: Liam R. Howlett To: Andrew Morton To: Greg Kroah-Hartman To: Arnd Bergmann To: Christian Brauner To: Jann Horn To: Suren Baghdasaryan Cc: Alex Gaynor Cc: Boqun Feng Cc: Gary Guo Cc: Björn Roy Baron Cc: Benno Lossin Cc: Andreas Hindborg Cc: Trevor Gross Cc: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org Cc: rust-for-linux@vger.kernel.org Cc: Alice Ryhl 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 | 28 +++ rust/kernel/mm.rs | 323 ++++++++++++++++++++++++++++++++++ rust/kernel/mm/virt.rs | 429 ++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/task.rs | 284 +++++++++++++++++------------- 7 files changed, 999 insertions(+), 117 deletions(-) --- base-commit: a62eb7bdef0b0009d1e141198e790fbc588ad0a1 change-id: 20240723-vma-f80119f9fb35 Best regards,