From patchwork Thu Feb 13 11:04:01 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13973103 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 0E6DFC021A0 for ; Thu, 13 Feb 2025 11:04:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 983E26B008A; Thu, 13 Feb 2025 06:04:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 90D8A6B008C; Thu, 13 Feb 2025 06:04:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C3266B0092; Thu, 13 Feb 2025 06:04:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 4979E6B008A for ; Thu, 13 Feb 2025 06:04:45 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0CB8D1C7F06 for ; Thu, 13 Feb 2025 11:04:45 +0000 (UTC) X-FDA: 83114638530.09.C9C2462 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf19.hostedemail.com (Postfix) with ESMTP id 12C331A0008 for ; Thu, 13 Feb 2025 11:04:42 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bVCOcHNH; spf=pass (imf19.hostedemail.com: domain of 3ydGtZwkKCGgGROIKXeNRMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--aliceryhl.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3ydGtZwkKCGgGROIKXeNRMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739444683; a=rsa-sha256; cv=none; b=wP6zZzbjPCfYUBrn2pgS2ohmkx3g63V7S/Lr/8nmH2APRr7Gy37QwNa3Ysbu9+4fuuP2Ru n+c3FEwekv72BaI6m/dbnfV/b2L/okWN9/RC9ACxHgz+uAVQqZ7tXfcx5w1yDUZIZ+fHzE 859ZF0Z8/+SDC4pCZ0g+CU7QyOPU6ro= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bVCOcHNH; spf=pass (imf19.hostedemail.com: domain of 3ydGtZwkKCGgGROIKXeNRMUUMRK.IUSROTad-SSQbGIQ.UXM@flex--aliceryhl.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3ydGtZwkKCGgGROIKXeNRMUUMRK.IUSROTad-SSQbGIQ.UXM@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=1739444683; 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:in-reply-to:references:references:dkim-signature; bh=za3474x0ZF8AMlWXSEpyVL59vkrxbiA4YbQOJZDWTjE=; b=LK1pOLmZne18Jg/sNJ9fc4Yy90RuaHl/iRGfPBn9UqpJ++Yxokq7h8dzI/AxEs+qUpnKVj 4Drt7AVT7pi418tP5xzJG6nwkDFOX0KWKroD/9uQhFkZUxudk6WF1ST/wx5hhGWifg7hCQ mQt6oNLpm40ZXfcyvIp5GkzgsD70kJY= Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38de11a0002so689564f8f.3 for ; Thu, 13 Feb 2025 03:04:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1739444681; x=1740049481; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=za3474x0ZF8AMlWXSEpyVL59vkrxbiA4YbQOJZDWTjE=; b=bVCOcHNHOn6/AVkttOo8R8aHQ6TCMxNN/mdf94tQp2yGFgRZI1T5j17K2z02J3rXxH UZmVVDUlxFN7V7fya+LTSJyOzwCdyU4pXBNpcYk2D9R2EpTlbGZbKqzBRxT8gyzEVoRG UiEXUjy4G41IiVMvM+8eM+Rom9+L5XFvsaJtrcbUEpBQgtnJv0wYc06X4YkbtMZNS5aM bJ+0g0ZRl4wAbq0GZVZftr27xaT+9vK29S94gTlHA9RY5qxb3Yf3yRqhq/XIerqiQ5Jw 0zYfD4OqxbgHXlpvnAtoWUpVS3k/GhJTCDP37q20vgDEOD/j6sE9UjFwa3JxnuTmfH+I lL6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739444681; x=1740049481; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=za3474x0ZF8AMlWXSEpyVL59vkrxbiA4YbQOJZDWTjE=; b=bd9F9pHR3zfbh2eaJrUH1vrCA7zv3plAEe64Rl6Ar1EP3Dl/4GjAlHcsbEZMDSnBMG AuL88YYLa1zKbEouuUGl93kj6WoltyvfSJm82KPtnItI2P4cSH0yYDtzCdiN8OzqI4LN YjI5rBHsR5FVnwPtdJee5K9nkC09qFJ15CXctT26fJB7vaTKyb+iyJURVV/7fBTAAI3r bSf2CdAGmyl+v2TpVgtlpvt3i2o/r1rcmVjqbGStEoKuwtTpJMn0X2Q558qPxlxbkQVZ XUow/4CZWXsvprPlIVyLx452TDD7bawwgjGE/oCfKQODa0rdSpJxHjupOXGJf/HKLXlb kodA== X-Forwarded-Encrypted: i=1; AJvYcCVYHCZT6nIemfEjAA2RaTic+c8tHM+xMi1asTDDXwbkwBe3dZmnHzn4Dz7bVNMuQRzHffZN+eHyzA==@kvack.org X-Gm-Message-State: AOJu0YzZJmt1UdpNSX9CgsHDFE0FhJbs5NgbIab513TeF9Xlg+hHXqEH lbvL0qAAEOCb7uR0AsKU+9NMLR1UrFM4EyDPE27q63/aSO9mP2HRdqu9DDn0YDjiMJ6li9/gEGG A+zSl3wVnTGjJWw== X-Google-Smtp-Source: AGHT+IFqQez3BgoQ7uNF4wdhzNnxr+PJ45L8RFg6wDi/c48ndpBoPVBo6FJ8W7vBko0MJMPWmUUseOsLeSI1Ix8= X-Received: from wmbhg21.prod.google.com ([2002:a05:600c:5395:b0:438:e219:3af5]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:6d02:0:b0:38d:e092:3d18 with SMTP id ffacd0b85a97d-38dea2fa0bemr6387327f8f.50.1739444681571; Thu, 13 Feb 2025 03:04:41 -0800 (PST) Date: Thu, 13 Feb 2025 11:04:01 +0000 In-Reply-To: <20250213-vma-v14-0-b29c47ab21f5@google.com> Mime-Version: 1.0 References: <20250213-vma-v14-0-b29c47ab21f5@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=11820; i=aliceryhl@google.com; h=from:subject:message-id; bh=Q0RIStyPwKILnX2Vrxa7XEF9eaYk5DS6vlU3U+wI2SI=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnrdG+2HO72aNkovdBvp3nh2Z3b2jBiNHTe+tqw Gxn7dLgjsyJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ63RvgAKCRAEWL7uWMY5 RhIKD/4whgGT2Jm8XqQ/u4jOaeumFx8NScl5ogOyGNK8zZE+jXjy8Oz+TgqxjHe7H+HRKfu8i28 aWz7Dyts7C3Lv2/bxafa2+6D5UZXQJ9cCjCp+iv0sExbz481iaIgCOQRrv+avMXzxfg+UYOo6ze WukLXyjJP6Xmj1kCLPJL9g95WYH/mAR3r36vfW5RmHGX5m5hjfXglA5NE1sguHGUat+pOZxv8qM VMDq3nbd4/O7WNNJVmc613d2m4I6FotyyRKP0PN2N/7IVeQoZ6vyZkHR6CjI6eYaXRSTsYy2XzY LybS//m56IDMY2S2M0Z3yhwdGQG41gk7xTPOP2ELlCnUE0nKaaKaWV2y1tcV7dBNVOj4ZTNaspE 5i0UBvdaGyalGeYgXIPuTZJZXNR/oN+PHQgl1Dw6gPlyUqo3tP7gvH8Ce2fm0ai4wLD86dSSwp/ X3T1BTVLHbciDkzEUIiifAQrcKGJrdrh3f06rdAia4sozXdSuy4dyC5Bvl/qKhpGCQGKHCzycSO xEulzrYlQ3LLIOlIZDm7FlBg5gCj3zvHr00N8MoPCHaRqVsZUCwIkIEunqQVmQHMtyoYK6GZVcA 8Y6w0K0NXKvzaAEnSiIDTYMm2Euiwq2Otr7WgG1rPyYYp6zpPNAH8meEf2gXp/zC2VMziO3GutN eonf2T4A+n0jtbw== X-Mailer: b4 0.13.0 Message-ID: <20250213-vma-v14-2-b29c47ab21f5@google.com> Subject: [PATCH v14 2/8] mm: rust: add vm_area_struct methods that require read access From: Alice Ryhl To: Miguel Ojeda , Matthew Wilcox , Lorenzo Stoakes , Vlastimil Babka , John Hubbard , "Liam R. Howlett" , Andrew Morton , Greg Kroah-Hartman , Arnd Bergmann , 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: 12C331A0008 X-Stat-Signature: xofjr711i87ps5shipy1p9kdifzxmkqi X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1739444682-16115 X-HE-Meta: U2FsdGVkX1+A3VP4yNHsj381pI0XzagWndD1BMSCXQ6ROiajWDg1lzB1rc3sDxAe+ALPrtBkKAheKZzYj0LortXu7hWhuK4Zkn0pFS7bKoncNnW3ltvVE78ZTWY+qnrkZTLysK5LBPe1LVcc0wHcjlF2ei83Sh5swRw1JgjZJBVp6/waP4oHoxBkJ1C+vmU6E8JNRxqOMMcpwDqAmWDrGzrwGFFZTvAnJkETtYaa6sBd4jkYZagr7S4IUI+E+2QDV8l3cphSa0/EqmKYztFNRPgAfHSOxkoqLZUr7ySIM3s05/TkQ5X8eq4blzcCmZEQFR4DDRB2mgYJVW6vlvTh3h+2lcyvYx1V6ylkUpGzRmChVCWx04ei1bgc1IUXHGbeH3v54FIUO0R8K56A9LTtMo+WKGocQFFRWj8o1ICquQ+JxlQMl7o5O1ylpmsDYmSe/Bx2jQTxEZTczdEV846qbsFqj0r8fRHo4DZ6z1IoicxGmjEosWrC6IBt8uRTbrGZLoWEopB/jVgDb4olm076q95yXSN8qNk4vc4Q8oAnu6kPJpNi3Gli0QhRZxRWwNppf/NS4AcYd6PjAoG4yPc61nC6QYDwFjoa6aN27GPD06rWmwbQ05K1vfIZuZwERrEPBgFMft2jxAdBHZJv8re04Cf/90zyhRRTvPq/JVDS7+pIKvUYhI7K4Yt5k6ICAwMmkNT7q6wjQTVZO2wEsiK0E6pLCqVT0k5tsCWduwWvkWgZ1wbpiS/3S/IPBKgYHIaRQEjeSv0LJrxKCpnOhShWDGi+CXliDBfa+PL6WfeVfcY1GGOLpOLGdjKOsr5Lj3Bt2aoMuYqIL4nicIY7wnYkFwWOc8EGZM2PXkoRIQhNaCiUMsEX7mauww6P48xe/FsFer+9+A2c58VfkJV1e0EL5aXyTdkxpMvf4tcyRboqv7ScNIHGK8ZR2JDMbwwvuFJQUonXobH/8zeVRYrbjJO sjwCj2/F yCUyFaBjnmFIvzwe6ib+hhIcUpDyKeabxSQhLto/tp3ID9wHKH+YmFIk4zApZ9YbpqkIP6nFXuXiUxdL5uciRFi5jQHHWkttUilMty3eTrHF1np9tx13fQbyZ5JL/XfnO3J26gyZ5dEXBNgscY83JgKs5C9f0KXYpEgJSoSwcQn9A62ITjBD+PyvJQJVSd5d65VZIQQovHh+LQO3iUjT8yvw0emxzlSiN7S8IIdbO9QiWUCAJ2p8GihrmfBflJhv7myPAQ7McnYKH4ORhZCcBPRd1gmuO7pR6bTsMLCExxqWsXFRUWShyNYewIr0R2jiYIz3d5+IKvIcsS9ohv9tI4dYHlrKXLdJBvS71Jbz+lFmmBK2/kwWYW9RNH+lTS7Tb38ZYwRAslk2FpadFFwD9LUHyYrP6xQ14IXKZ1JnwAT+SndxSEDPvfA9MdOq8jmrisQK4pgwWTov6b3AcITDrvRmicAaegYRR3/Cdiij5ETt3r6t4KG66hHVDJXSRjN2XnZgnBOb0LU3g+FJWrc3do/KZXcxvCKD6JpANqO50i1vmUx7uK7jJ5LxWo7+OQ/NQC1nUH0WlyNCjCs2vh3V/jFS0s/mUqmOtgWPmMHm39S/2t1xMZV+ZmcKgcAMPUtyvfWx5IHdIgoIQR8jX3xnw/LhhK9U0p4yMxQd6qJ/9VhlC3p8hC3dHICcJz0FxkKDq29RbWDYT8mPGWDcUdSA6wx4WWGtsmm9ia0ty X-Bogosity: Ham, tests=bogofilter, spamicity=0.224880, 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 adds a type called VmaRef which is used when referencing a vma that you have read access to. Here, read access means that you hold either the mmap read lock or the vma read lock (or stronger). Additionally, a vma_lookup method is added to the mmap read guard, which enables you to obtain a &VmaRef in safe Rust code. This patch only provides a way to lock the mmap read lock, but a follow-up patch also provides a way to just lock the vma read lock. Acked-by: Lorenzo Stoakes Reviewed-by: Jann Horn Reviewed-by: Andreas Hindborg Signed-off-by: Alice Ryhl Reviewed-by: Gary Guo --- rust/helpers/mm.c | 6 ++ rust/kernel/mm.rs | 23 ++++++ rust/kernel/mm/virt.rs | 210 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 239 insertions(+) diff --git a/rust/helpers/mm.c b/rust/helpers/mm.c index 7201747a5d31..7b72eb065a3e 100644 --- a/rust/helpers/mm.c +++ b/rust/helpers/mm.c @@ -37,3 +37,9 @@ void rust_helper_mmap_read_unlock(struct mm_struct *mm) { mmap_read_unlock(mm); } + +struct vm_area_struct *rust_helper_vma_lookup(struct mm_struct *mm, + unsigned long addr) +{ + return vma_lookup(mm, addr); +} diff --git a/rust/kernel/mm.rs b/rust/kernel/mm.rs index 2fb5f440af60..8b19dde24978 100644 --- a/rust/kernel/mm.rs +++ b/rust/kernel/mm.rs @@ -17,6 +17,8 @@ }; use core::{ops::Deref, ptr::NonNull}; +pub mod virt; + /// A wrapper for the kernel's `struct mm_struct`. /// /// This represents the address space of a userspace process, so each process has one `Mm` @@ -200,6 +202,27 @@ pub struct MmapReadGuard<'a> { _nts: NotThreadSafe, } +impl<'a> MmapReadGuard<'a> { + /// Look up a vma at the given address. + #[inline] + pub fn vma_lookup(&self, vma_addr: usize) -> Option<&virt::VmaRef> { + // SAFETY: By the type invariants we hold the mmap read guard, so we can safely call this + // method. Any value is okay for `vma_addr`. + let vma = unsafe { bindings::vma_lookup(self.mm.as_raw(), vma_addr) }; + + if vma.is_null() { + None + } else { + // SAFETY: We just checked that a vma was found, so the pointer references a valid vma. + // + // Furthermore, the returned vma is still under the protection of the read lock guard + // and can be used while the mmap read lock is still held. That the vma is not used + // after the MmapReadGuard gets dropped is enforced by the borrow-checker. + unsafe { Some(virt::VmaRef::from_raw(vma)) } + } + } +} + impl Drop for MmapReadGuard<'_> { #[inline] fn drop(&mut self) { diff --git a/rust/kernel/mm/virt.rs b/rust/kernel/mm/virt.rs new file mode 100644 index 000000000000..a66be649f0b8 --- /dev/null +++ b/rust/kernel/mm/virt.rs @@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 + +// Copyright (C) 2024 Google LLC. + +//! Virtual memory. +//! +//! This module deals with managing a single VMA in the address space of a userspace process. Each +//! VMA corresponds to a region of memory that the userspace process can access, and the VMA lets +//! you control what happens when userspace reads or writes to that region of memory. +//! +//! The module has several different Rust types that all correspond to the C type called +//! `vm_area_struct`. The different structs represent what kind of access you have to the VMA, e.g. +//! [`VmaRef`] is used when you hold the mmap or vma read lock. Using the appropriate struct +//! ensures that you can't, for example, accidentally call a function that requires holding the +//! write lock when you only hold the read lock. + +use crate::{bindings, mm::MmWithUser, types::Opaque}; + +/// A wrapper for the kernel's `struct vm_area_struct` with read access. +/// +/// It represents an area of virtual memory. +/// +/// # Invariants +/// +/// The caller must hold the mmap read lock or the vma read lock. +#[repr(transparent)] +pub struct VmaRef { + vma: Opaque, +} + +// Methods you can call when holding the mmap or vma read lock (or stronger). They must be usable +// no matter what the vma flags are. +impl VmaRef { + /// Access a virtual memory area given a raw pointer. + /// + /// # Safety + /// + /// Callers must ensure that `vma` is valid for the duration of 'a, and that the mmap or vma + /// read lock (or stronger) is held for at least the duration of 'a. + #[inline] + pub unsafe fn from_raw<'a>(vma: *const bindings::vm_area_struct) -> &'a Self { + // SAFETY: The caller ensures that the invariants are satisfied for the duration of 'a. + unsafe { &*vma.cast() } + } + + /// Returns a raw pointer to this area. + #[inline] + pub fn as_ptr(&self) -> *mut bindings::vm_area_struct { + self.vma.get() + } + + /// Access the underlying `mm_struct`. + #[inline] + pub fn mm(&self) -> &MmWithUser { + // SAFETY: By the type invariants, this `vm_area_struct` is valid and we hold the mmap/vma + // read lock or stronger. This implies that the underlying mm has a non-zero value of + // `mm_users`. + unsafe { MmWithUser::from_raw((*self.as_ptr()).vm_mm) } + } + + /// Returns the flags associated with the virtual memory area. + /// + /// The possible flags are a combination of the constants in [`flags`]. + #[inline] + pub fn flags(&self) -> vm_flags_t { + // SAFETY: By the type invariants, the caller holds at least the mmap read lock, so this + // access is not a data race. + unsafe { (*self.as_ptr()).__bindgen_anon_2.vm_flags } + } + + /// Returns the (inclusive) start address of the virtual memory area. + #[inline] + pub fn start(&self) -> usize { + // SAFETY: By the type invariants, the caller holds at least the mmap read lock, so this + // access is not a data race. + unsafe { (*self.as_ptr()).__bindgen_anon_1.__bindgen_anon_1.vm_start } + } + + /// Returns the (exclusive) end address of the virtual memory area. + #[inline] + pub fn end(&self) -> usize { + // SAFETY: By the type invariants, the caller holds at least the mmap read lock, so this + // access is not a data race. + unsafe { (*self.as_ptr()).__bindgen_anon_1.__bindgen_anon_1.vm_end } + } + + /// Zap pages in the given page range. + /// + /// This clears page table mappings for the range at the leaf level, leaving all other page + /// tables intact, and freeing any memory referenced by the VMA in this range. That is, + /// anonymous memory is completely freed, file-backed memory has its reference count on page + /// cache folio's dropped, any dirty data will still be written back to disk as usual. + /// + /// It may seem odd that we clear at the leaf level, this is however a product of the page + /// table structure used to map physical memory into a virtual address space - each virtual + /// address actually consists of a bitmap of array indices into page tables, which form a + /// hierarchical page table level structure. + /// + /// As a result, each page table level maps a multiple of page table levels below, and thus + /// span ever increasing ranges of pages. At the leaf or PTE level, we map the actual physical + /// memory. + /// + /// It is here where a zap operates, as it the only place we can be certain of clearing without + /// impacting any other virtual mappings. It is an implementation detail as to whether the + /// kernel goes further in freeing unused page tables, but for the purposes of this operation + /// we must only assume that the leaf level is cleared. + #[inline] + pub fn zap_page_range_single(&self, address: usize, size: usize) { + let (end, did_overflow) = address.overflowing_add(size); + if did_overflow || address < self.start() || self.end() < end { + // TODO: call WARN_ONCE once Rust version of it is added + return; + } + + // SAFETY: By the type invariants, the caller has read access to this VMA, which is + // sufficient for this method call. This method has no requirements on the vma flags. The + // address range is checked to be within the vma. + unsafe { + bindings::zap_page_range_single(self.as_ptr(), address, size, core::ptr::null_mut()) + }; + } +} + +/// The integer type used for vma flags. +#[doc(inline)] +pub use bindings::vm_flags_t; + +/// All possible flags for [`VmaRef`]. +pub mod flags { + use super::vm_flags_t; + use crate::bindings; + + /// No flags are set. + pub const NONE: vm_flags_t = bindings::VM_NONE as _; + + /// Mapping allows reads. + pub const READ: vm_flags_t = bindings::VM_READ as _; + + /// Mapping allows writes. + pub const WRITE: vm_flags_t = bindings::VM_WRITE as _; + + /// Mapping allows execution. + pub const EXEC: vm_flags_t = bindings::VM_EXEC as _; + + /// Mapping is shared. + pub const SHARED: vm_flags_t = bindings::VM_SHARED as _; + + /// Mapping may be updated to allow reads. + pub const MAYREAD: vm_flags_t = bindings::VM_MAYREAD as _; + + /// Mapping may be updated to allow writes. + pub const MAYWRITE: vm_flags_t = bindings::VM_MAYWRITE as _; + + /// Mapping may be updated to allow execution. + pub const MAYEXEC: vm_flags_t = bindings::VM_MAYEXEC as _; + + /// Mapping may be updated to be shared. + pub const MAYSHARE: vm_flags_t = bindings::VM_MAYSHARE as _; + + /// Page-ranges managed without `struct page`, just pure PFN. + pub const PFNMAP: vm_flags_t = bindings::VM_PFNMAP as _; + + /// Memory mapped I/O or similar. + pub const IO: vm_flags_t = bindings::VM_IO as _; + + /// Do not copy this vma on fork. + pub const DONTCOPY: vm_flags_t = bindings::VM_DONTCOPY as _; + + /// Cannot expand with mremap(). + pub const DONTEXPAND: vm_flags_t = bindings::VM_DONTEXPAND as _; + + /// Lock the pages covered when they are faulted in. + pub const LOCKONFAULT: vm_flags_t = bindings::VM_LOCKONFAULT as _; + + /// Is a VM accounted object. + pub const ACCOUNT: vm_flags_t = bindings::VM_ACCOUNT as _; + + /// Should the VM suppress accounting. + pub const NORESERVE: vm_flags_t = bindings::VM_NORESERVE as _; + + /// Huge TLB Page VM. + pub const HUGETLB: vm_flags_t = bindings::VM_HUGETLB as _; + + /// Synchronous page faults. (DAX-specific) + pub const SYNC: vm_flags_t = bindings::VM_SYNC as _; + + /// Architecture-specific flag. + pub const ARCH_1: vm_flags_t = bindings::VM_ARCH_1 as _; + + /// Wipe VMA contents in child on fork. + pub const WIPEONFORK: vm_flags_t = bindings::VM_WIPEONFORK as _; + + /// Do not include in the core dump. + pub const DONTDUMP: vm_flags_t = bindings::VM_DONTDUMP as _; + + /// Not soft dirty clean area. + pub const SOFTDIRTY: vm_flags_t = bindings::VM_SOFTDIRTY as _; + + /// Can contain `struct page` and pure PFN pages. + pub const MIXEDMAP: vm_flags_t = bindings::VM_MIXEDMAP as _; + + /// MADV_HUGEPAGE marked this vma. + pub const HUGEPAGE: vm_flags_t = bindings::VM_HUGEPAGE as _; + + /// MADV_NOHUGEPAGE marked this vma. + pub const NOHUGEPAGE: vm_flags_t = bindings::VM_NOHUGEPAGE as _; + + /// KSM may merge identical pages. + pub const MERGEABLE: vm_flags_t = bindings::VM_MERGEABLE as _; +}