From patchwork Fri Nov 22 15:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13883301 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 ADE05E6916C for ; Fri, 22 Nov 2024 15:41:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2BEA28D000A; Fri, 22 Nov 2024 10:41:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 26FE68D0007; Fri, 22 Nov 2024 10:41:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C36A8D000A; Fri, 22 Nov 2024 10:41:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DC97B8D0007 for ; Fri, 22 Nov 2024 10:41:05 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6317B120EBE for ; Fri, 22 Nov 2024 15:41:05 +0000 (UTC) X-FDA: 82814141718.13.41DE50B Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) by imf06.hostedemail.com (Postfix) with ESMTP id 0176C180002 for ; Fri, 22 Nov 2024 15:40:24 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QnkyJAwA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3DqZAZwkKCJ07IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3DqZAZwkKCJ07IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732289926; a=rsa-sha256; cv=none; b=hPDKhVW02rY/JM2Jv8ocdmMKvuIMiGJLNTQsPfuw0ENMjxK7ygk98iCJPj8x+2sjNV04oe SXTmyDjvz4QYhh/vtytHG4F/NRflZRdgFO6gm3JAE+E58Tq0nPNFVu+9L+yOVzeVsAjn/M sRAQJIfuKEwIIgBWawboZg2l7z2/PwE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=QnkyJAwA; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3DqZAZwkKCJ07IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com designates 209.85.128.74 as permitted sender) smtp.mailfrom=3DqZAZwkKCJ07IF9BOVEIDLLDIB.9LJIFKRU-JJHS79H.LOD@flex--aliceryhl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732289926; 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=linYc4PYYa1AalUUZfLW5Qk3D1efJXXgmysKez0fQBc=; b=vxCvZPji6WgPoSIM/ebENSur188E+oc2UcMw48gp5fFo9bKFQdXC5SxnqpToGsYlOye6ZQ WLqWvmlkwuOQRz6H8wMLXZw3c0AQXqoqjWrAtV/1aNpMYhs1unSUxOOXkqtd5lakf/iORI gKlKFYRQ+VfvJja8PlZe30+h7QDvvVk= Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4315eaa3189so19778135e9.1 for ; Fri, 22 Nov 2024 07:41:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732290062; x=1732894862; darn=kvack.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=linYc4PYYa1AalUUZfLW5Qk3D1efJXXgmysKez0fQBc=; b=QnkyJAwA5wgSdsIqZluZo7nT4wJmKrx/cf+T3nMJoz28ZpGXRaD+E2qIiUmgQIo0d0 pwK0PP9hWImNt1JSAoI3P7oGe1XMRYffu197ieuZ5+s1rVhgKm2z/iBRRJSZ10hnARLP vOVKIBVGnTqpfYZCpI/nZ8kOhHJiuCaKzy2W3ira9TOZARSWn0CZ09SvDVi+Kz/ZiqFb eLPrjx5CFzzUp+xztDq1+3FwNT+c8nBTFlehmvKKCKicbGqias2MNzAIHBXwH7bpzvfg 9W2DHEX4v+v+FLf+qxxl9ULSZFmE6ss6T3UelEbjSo8MHbhDc6jx2WjlVpv7cyYta2cV MG+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732290062; x=1732894862; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=linYc4PYYa1AalUUZfLW5Qk3D1efJXXgmysKez0fQBc=; b=gz0Vt8dd1ApaDRQGM3idiaJ89DTzBfcs1pRyBfYT5m92vE3Q/CtTj+J6z2e0rBJnWK uVFDzx+tVkbChJVEkwm0QObaEdR/McQaLG4TWMjnZWMEnkHylhT7+vQlCMh2sV+rOQOj QX3SRdz0zA5jN47DytGX2s0pl1ZIUnMJwHpowaS+lMLBbpY1b5ADQZqDlu7HC8Q8MMWV 7ndYPR6BLghbjx/pmyDXypltMv8a9mWZX9ff68wN89iGuiMpPLOplesG0325HoW25lqJ 5GGXJF6ghUCJz0YUG1IZSx6S+OmoyTJojZV6Lqv4NPoxjz1KcgoQ7ZGBo9XaUQDV/XCz PpmA== X-Forwarded-Encrypted: i=1; AJvYcCUpHWWFGzWWRl2jWwSNOM0PRZgBUUPUpW2N9wiwvapK4/YQXfzZ1lTqMuVt7tEWlpq0PDD8cv93SA==@kvack.org X-Gm-Message-State: AOJu0YzMIbEgm4BNvA0VfcxXZ/aMfaZYyyfUHxvfrdjXF5ZMayvwezoT MXwvM60PKNlTLrcJeGc9xoPUW+cS3C0nzSmtSEBqz9jXpGKSSBoiJBothUjIlR7S5qZPLLkI1iD HJSJoVhgBgVls9g== X-Google-Smtp-Source: AGHT+IEskQOQOnMC5eHBm3np17NWKLLGzeqv77GLRWF8Aq7UDd1Yq+DczJ/rUyix8emN+G0xVynCck2Dy26SqmM= X-Received: from aliceryhl.c.googlers.com ([fda3:e722:ac3:cc00:68:fe9:ac10:f29e]) (user=aliceryhl job=sendgmr) by 2002:a05:600c:510b:b0:430:5487:bb6a with SMTP id 5b1f17b1804b1-433ce4fa384mr291005e9.8.1732290062019; Fri, 22 Nov 2024 07:41:02 -0800 (PST) Date: Fri, 22 Nov 2024 15:40:25 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOqlQGcC/2XRTWrDMBAF4KsErasyo3911XuULiRrlAiauNjFt ATfvXJUGgctn9D3ZmCubKap0MxeDlc20VLmMl5q8E8HNpzC5Ui8pJqZAKHACsmXc+DZAaLPPke pWf35OVEu37eWt/eaT2X+GqefW+mC2+ujX5AjlyIkHWqRI3o9juPxg56H8cy2gkXskW1IVBSiJ O2FTYMMHZJ3VBdsSFaUohlwgJBT8B1SeyQaUhWBx+AsaBeU7JDeI9OQ3pACdBl0IhE7ZP4RAkJ DhgNPzoP00WRt+0l2j1RDtiJAkiI7U++gO+TuCMXfJFcRRYlK6BSMeVxvXddfBZL7yQoCAAA= X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=3620; i=aliceryhl@google.com; h=from:subject:message-id; bh=LUrUd+grGI58KdBLkETRaZnLEYCzFFsAhsPOF2EFoeA=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnQKXyonxh82WaNw5WfTyoJuUa5dGM/xGb3cf4c 7lLrxHjg+yJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ0Cl8gAKCRAEWL7uWMY5 RmfWD/9hYSKnsvnSKhX8pODCL+0H5dx11YhePvsnCPGid0TJ6nnUovNNYLEN09U6T8a9jOtJh9l Mr5Qamp+wY/qDkMoTTxsRkNDxNjWNoH0twR0pncoXnYDkko+zm6tYuIShifLfaSXa/3nM3zB7Qu nvExS6tnpDPGi4ZK1W1EzCf8QX/8EeCc3MVxwec7riAinUXrW/zGmhV9VZIHpI2lvnH+rTsTA7w +cqfCdvJw0hjZpnNBTahHUBvLnf3chIk2nPioxeB02a75xoWVUOcgcRqlwrEsA2KJENDQejY388 gTk1pE5lOvTCcrDmXI9doOCWbFAejc235rbAuAi4oK7E88Q8iT1OPQBCxW240r5i7goeltg8jwq V4nyaqyAftnPrmdDbtQHwNoQoUF5sA2LkQYAgzUfV2NbRZ9s3bMTEGylZBWNaNKHAGR5+gj0rYz BMD3mAN1jB/i44KIomd9AAmaqaLzQLFpMj1WuJM/AugKxFV4tV9c56tJAC0kjZKDWYTO+N3+SPJ 3N6SepYjCXiU4ZHN3y64wE1TZ3zls5eofhAL7erzZkjWUF/sjdJHDg8gcecH1FoKoPWFLzbjeR+ k50WxmKZvqIVuIoKkb8Qu6iejqdHG47kR2IvOm4Ad3XWSDRpBo+RLdywpD5qgX11aatJ+JBlr6w WscCXtBwmJg/EQw== X-Mailer: b4 0.13.0 Message-ID: <20241122-vma-v9-0-7127bfcdd54e@google.com> Subject: [PATCH v9 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 , linux-kernel@vger.kernel.org, linux-mm@kvack.org, rust-for-linux@vger.kernel.org, Alice Ryhl , Andreas Hindborg X-Rspamd-Queue-Id: 0176C180002 X-Stat-Signature: q95rb3gipxds4dm743i4zaiuta4qxyjy X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732290024-396093 X-HE-Meta: U2FsdGVkX1/v9QBlIdvrHugaOW5b9OsOWFHKJJmKVmZDLUQBVqmB6BfUpawijacU+L9Vlgji4Cn2FsqE7u2NKxuWV0h19EhsdCtV4aCn1RnR3c2pwarOy0aDPDzYkJ7rB8V5sAVgj8/yJ/FXtUh40YYWz8AOQ6ehxa3YkG11xqH4VF3VucGkF/j0DBR0z42E3/vxrD/aVKApFi85sfxBU2QN5+Axtb7aAYhYuE2k9P6PUSFUA9THzvnpC+OP1phjDFjjQ0RY+75JqVUTkClOodGOEh4uCYMdH67q1vX8Yq1J0Z4+/LvkjhDnrUpp9ZNsrCaYE8vvAutqGoIqdV/4FcAXQSB2uCuf8iwswtIzUEEtbvk5IfuFHkSKZJYXldU6QpRfOiXLwQkWjU3ogGj7vwT5PskdHdvyri5LBSnqit6HIvUC4P5Z5Z+7RQrkbsicZ0jyIWvWS+cMVaxza1Pn8YvW2FFu+8zp2Ab5sZqtbwq1vTN772n8Xp/ptouh7/353FKEQ31+YXTqRtQyHA6/+vFJrfwr21KGO5JYbtpeU+8hEnyOvN28UVc6jQbP513zizjJnvOrXRNGLjcL6uiO/yj0Yk4HExfCjolzGh6Q1pqUcIhkmpQ4Z+Axss2JZMMmCj0HdL04I5M6If635Ezy9+W7dSySqayL5309HSdfn5If+w1zteX/6x0WFjd1nl481qGljTPlXiPcsGsGrqxWW2RgUvi7WE4Gpaicmce5emcSEuKXm7qcmh0eMsOBmW17wRvB+ipv+PTJIGoaLvZtVYipzNsqLZKqrh+2vuC+I4CS9GksTGIgK7ijRaici135PrCwpuX5JDIu0OoeydaFNmIAIoRDbKFVpcmOPe9wSiqvx12Lh2hxYPZWvtPPEQYpk3u9z3vIaMYHiSE28EQzAvop8g/QGFkfVIh8WA5ADxV8TUPLNCqb4M1FmLyrw/zuMi4qo4ffCL6O80WO6vr VsaDFs2V TuFQW1NP1czfr+RHuwy2HwLcqPl7LPAj2ZB+O3iwFeWMYJYH6H2CbX6xs0Kg5Y6JPcH52TiFEqTe0MCfdq4avTt36zpvbzMS+Oawb4AKB6ZJMMoUalJmR09L1hH197GIyRLs4XiyvoLuT7NG7cTRjyNJv22ytaeeY7B6lpihDGnoRsQegPf8AvgJiveFLIia+zulrV6XElBL3QT+AorA9ldKeVq1MaBImyevGGc638rgSjbzefnElN+frk367hbqveIiio2qNrrasCT99NLtumHmSDvJj3RAHXDvAdTHrsnGQNgc9J8pXW2jBMKf21xXkPOZH0KXUOmbC8W9vBTYWhu7whYkZQWGluHU+M6zCT0RrA9Q0dMD907sFaMFrvtXYWLUbp2miVFSd8/nSL6mZvsRSTCBUNExdwG/mRzjPoR8mx7vRwaNV3I32LwOzlJPlEHmIbJSLJMM346nJJCzHJSXdxAUryl70UW4mIqPCiGxBMkCcGguwjQumd6LlKIjvAbWfC83q6nZUMsyHdmtvF5C8ULXD8o1QHHdYiLGElDogc8bXdb4qG5jZAU4JHPWUGaSWs7RkptfvV2zV+krt6jrtDuqzkrzkI07vG78K9tw9o6gRB3EDs2oASLvFtpYHyJrkhypEnCdti/jtWVF5WD5339lxdTbopNyTLXfetyOZIFZuKNN2bI+SUtPoS3tsTwrOJaADoUcfqfE= 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 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 | 421 ++++++++++++++++++++++++++++++++++++++++++++++ rust/kernel/task.rs | 64 +++++-- 7 files changed, 875 insertions(+), 13 deletions(-) --- base-commit: 8b8379ae7c70734686e98cf7455e6b25e614d593 change-id: 20240723-vma-f80119f9fb35 Best regards,