From patchwork Wed Dec 11 10:37:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13903321 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 98E6FE7717D for ; Wed, 11 Dec 2024 10:37:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F2D506B010E; Wed, 11 Dec 2024 05:37:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EB6546B0112; Wed, 11 Dec 2024 05:37:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2FFA6B0113; Wed, 11 Dec 2024 05:37:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B0A006B010E for ; Wed, 11 Dec 2024 05:37:36 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 62319A0C46 for ; Wed, 11 Dec 2024 10:37:36 +0000 (UTC) X-FDA: 82882326198.30.EA8CD01 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf24.hostedemail.com (Postfix) with ESMTP id 72B27180015 for ; Wed, 11 Dec 2024 10:37:31 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AvXWIfQz; spf=pass (imf24.hostedemail.com: domain of 3bGtZZwkKCOkLWTNPcjSWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--aliceryhl.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3bGtZZwkKCOkLWTNPcjSWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@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=1733913430; 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=T2QnY3nqUlMVid18sCVnINWo37cTCiIN8hI1LuQ+kCo=; b=qqDk9t9mI89/0nB6TqzVs5YqYxDalsoIs3CJ7YoKF3aBtINUq+3Z5oHL5pncdEMLQU5pUI KUBdAbV5DoD2mUSI17qFX9DBJCojZn7nZMQqDKuzGvoegjVkomoetb+kiiR8b76DtK1Fnn Iyd+JjyXb0QUPkMk9PwLJVkCsrRrR1w= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733913430; a=rsa-sha256; cv=none; b=CBLxK0ymqvSkRpG/GliHUn8DQC/nhJJFV8d8w8tvbUU9YvGGZfe4hTdDIgGFHRiMK5QVPL jpvpWIKw3W/ZCvMz4w87x7hDYS071lSvLnifjV6l0HUQJ7soIDpmcq7O/q0odd0JBqmNNW n58ZK/YfTwUa/RAU2/IYfIxLea5WkZ0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=AvXWIfQz; spf=pass (imf24.hostedemail.com: domain of 3bGtZZwkKCOkLWTNPcjSWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--aliceryhl.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3bGtZZwkKCOkLWTNPcjSWRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-385df115300so3478721f8f.2 for ; Wed, 11 Dec 2024 02:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1733913453; x=1734518253; 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=T2QnY3nqUlMVid18sCVnINWo37cTCiIN8hI1LuQ+kCo=; b=AvXWIfQzJJ5d+wHHEgMPOQmKebo0ATHDNJMrdHNygO4OQDol+1UjMNbkXew+v3wAUQ 0IHSK7nDfdE7GgqlZ8tfUp1d+FhinsAFpfXXPyv9c6V7o0kBcBEJKyCi7RirTM9r1SCQ +daXJec1AYxNr0ZO5Ptb0umdcRUkDYVxqXDqwaYhsve+UyzJVFwU98Bq9zxG/Dm2RMQU xXK1k//iME5Wot6/Qb3AM9NMqXrIwVVsSMfED4KYGqns0zBwGcGqgp4tVCXKamFix6Zn oCWY7oqaHkh9Af40CPwSZw7TYeXMwqGj+TivmObNDlBLGHoFjuUKmhWNyQGs8j77/UmW Z1yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733913453; x=1734518253; 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=T2QnY3nqUlMVid18sCVnINWo37cTCiIN8hI1LuQ+kCo=; b=YS1KIxxctipLVWVkw06ixUchUuDqWRvRIwafphjszeIG16ev+Sd5cmD/1hxG3qRHLf VCMqoEkKxTh2TGVZjATIw9T8ZY97mb66Cm19CmMbbQN/dymueQXoMdxhFuBEQH/xOMvl biLoKuARaRcDLenFlx4uVRYGTqoqGZntsuULne6kTCGVLwRejjdc1hOwoPrTihxfPCk1 rlxh0pkP7EVyLnkp2zKdMi9S78AN9ZQaB8xAeBX1BBkWW7BJRQJ8j5alflPJutV8KAlf wBbrd24EHUAXY+iypR97SLsAM8IHnmd59wkhEzobpLMq/oxy0Q+JP7QJHQ6woTsgAxBY N0KQ== X-Forwarded-Encrypted: i=1; AJvYcCXrXFCPVnNcMH//wWjGyoCsVJcK0FjxMen5Njt3u8vTgOP6GeXkmEEwhrJoFazlPpgrl/cfCVbqNQ==@kvack.org X-Gm-Message-State: AOJu0YxA2hMUCgy6G4GeZ2861D+Yi1g3FVAOJZU62L5wmPOWXkiPSLqf 7CAFjm57kAgEHAKG6vjwIubEFR09Oznir1/A3soIcsQ9bAuxDnlinNb4reYNRGXNQJRms6B+UHi EwUMyqQr/OdvF8Q== X-Google-Smtp-Source: AGHT+IH/c3Iu+nJ9Nv0o3TiAxZrdEhPU30LKeX5h/Df7IZ4hvGTeYRO+lhCWtq/FRJTRbo1Jx+ZfHKRQsIVq+/M= X-Received: from wmfx19.prod.google.com ([2002:a05:600c:2d13:b0:434:9fab:eb5]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:178b:b0:385:f092:e16 with SMTP id ffacd0b85a97d-3864ceab3f6mr1868994f8f.55.1733913452975; Wed, 11 Dec 2024 02:37:32 -0800 (PST) Date: Wed, 11 Dec 2024 10:37:04 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAFFrWWcC/2XRzWrDMAwH8FcpPs9Dkr932nuMHezYbgNrU5IRN krefWpT1hQfLfz7S0gXMZWxL5N4213EWOZ+6ocTPxBfdqI7xNO+yD5zQRCQBkdKzscoqwfEUEN Nygj+eR5L7X9uMR+f/D700/cw/t5SZ7xWn/2MEqWimE3kIF/K+34Y9l/ltRuO4how0xa5FRGjm FQxgVzuVGyQeiAecEWKUU62ww5izTE0SG8RrUgzgoDROzA+atUgs0V2ReaKNKCvYHKh1CD7jxA QVmQlyOwDqJBsNa7t5LZIr8gxAiyKqrd8B9Mg/0BI906eUUkKNZkcrW3HC1t0X0Rg5JBcql3OR rd3QtiqcL8ujyd1rpU3kSJf64kty/IHUn8w3XcCAAA= X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=5009; i=aliceryhl@google.com; h=from:subject:message-id; bh=11pTYMTSjcFgpGSBp79ExVExpqHUXRE/LVnE2f2asAg=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnWWtXaB+TtU9GC9bEJlYbOkV7yAW44AYxwLIdY kJilAsBWqmJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ1lrVwAKCRAEWL7uWMY5 RjoGD/9T86lVgm8PmdgyLpmX6TmenyGZJpOCn0Cb4+gZotZqvrSsTbfQ6KPYx34pC+cxJfgRXdx dzpY89pK8NNBBPTXDNMaqeDyHNDwHP0O9j5Sjh46nKmaCWP/cvLiuAhLA7EVCwXhQ1aPbAlYPRz rEvNzID+2rpmPE15edL/ZSJ8/2GS0AMLiR37yz5rCPxzR6HSbfiyn1u9V1wqEXR5VNxeaokJ1qD sd3tbTQAbuTtoOoi4T+RvnYheWntd5IVj6lSciZL0ELx8Heyc1saGtIBBhDr9/r+zq7FK3RnZv3 IflhXZ0Ug2J/WPnPHzBlvnR7G6HlzkhAAbu+wFOZtq6tcDQauEztnxgsT/4Cy7N2uYnczyYit/o 8MM/xesLQ7lp+Y5b2jyzQ9DrfxbWRkws6fkpYLdmHhPmtCbW49m880OnFsRuJjoaxzAsPs3b3o6 YVyPuoK9BAUTUoBqCGqY56sL9i0ZX8SXqtgnlDT2wim7oqwsergdivAtxiOn5Ujv6dmDaJ0L09c o2lJTr374LTbqsBORd/4pQRF6ayPSklTCH3h6PmHTGiX54ZYRZJLoWoZBoWRjykknEqOcfT2VZg czosFNO0er/Eot5wxASryeyBgrvKY2TD48DCdI/2b1VwG6fQ56VDBxAXGP3x9Eefm3XskJbZpjX TXFZkuvd4BacsLQ== X-Mailer: b4 0.13.0 Message-ID: <20241211-vma-v11-0-466640428fc3@google.com> Subject: [PATCH v11 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-Queue-Id: 72B27180015 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: zhrfa157jejsbkjtet4abef4pzbytkia X-HE-Tag: 1733913451-972060 X-HE-Meta: U2FsdGVkX1+9Vv30XibhpqYYdAQkzOP6A9BJBrTc1iJ+HrOTQq2PYwm70ss8ZSctrB7Pg22jC68rpeUKvrFo9qGzdnIBy0SkaUR11RcAtdBiLfCm4XCEgtIc82NuRzw7Us8ptPgzbH1bWmcTDUK1taz64xO1cKJLQaIQ0DuB6VCkT2/ORSXkymTaYKfINItwSulsuMBmzEWJtrTXg0CMBMPES9iNx4q5AyHxLibIsUPq1E3Xj7PH7r0hUAuqWhamCcO3Eblys+bGGLJT/QqIeI5vlEhLu3mEYpMSMedOjA/a1B8BO7TG6tkAJanwSKU1RXsM4vXMQS+x/G4pVAvRsuaWUPHSbYee5VYiXnGVCfCXPbfXlksroYg7dF78Bl8svRTh27xcbqTVSTCEXBdx8xpz7fVoXo/59pZtXM5v5q8wIT2ndbArUTkUZinEOpul25uQ+CxcJJpLn8YaC0bVrg+dIL0uVMR/6WNSsF9k4tTtLKcnE72d35qE80+nByfnvFjUlcZSIAWYfGboSBwgktuGYJiAymdjJHjjLtoYtnlahJfPKTN8VyAhx3nBx+gNoH5J75dPoDhPKUhQsh1T2VHg1yg25Hws/rLQFSpLjePy/BfWaK7I1KuCQ4A1SlwVJbnos8ejlUKC+/Ya6mKIUAe357xu+umJukF+neQml3h2ZOHXdZUv7O6IlBApHG8unBg9Ltpvd8Q3vajAO2bSNFJoFA+++MCIFF/2CJ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FmkYcUl42MKv/J9vWrk5oOubnUNWhwSAPurhqeRh2eqW+1aTt+Blu9ASHdlqJvNqFGptTZTrEF3fqFjCqEqWHPcTHzrTmMRfZN+DdV9L8aHH9SEINpkjCaxQamk14S5tRW7XTzPuvPjshpp4myclFvQC FMSh3yvh EaSnj5gESxEWOWI65E7CKUeaKs1V3AqWF3yAzHT9RXPXW/t+j7ctJxfoftc47c6jjMsAVaHfv4rcyF1VEdfPJ0PKT61Kgusrtqx1f6GN7pv7XEmrVDT/FSMrM6ue5fhwbUu8Hy+Nr4ajLaPKgR6uGAEZ4vUNxTin X-Bogosity: Unsure, tests=bogofilter, spamicity=0.497339, 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. Patch 8 in particular could use review. 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 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 | 37 ++++ rust/kernel/mm.rs | 323 ++++++++++++++++++++++++++++++++++ rust/kernel/mm/virt.rs | 439 ++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/task.rs | 284 ++++++++++++++++++------------ 7 files changed, 1018 insertions(+), 117 deletions(-) --- base-commit: fac04efc5c793dccbd07e2d59af9f90b7fc0dca4 change-id: 20240723-vma-f80119f9fb35 Best regards,