From patchwork Wed Jan 15 13:35:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13940445 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 C0139C02180 for ; Wed, 15 Jan 2025 13:36:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C43B6B0083; Wed, 15 Jan 2025 08:36:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 44D966B0088; Wed, 15 Jan 2025 08:36:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2790C280001; Wed, 15 Jan 2025 08:36:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id F2C0D6B0083 for ; Wed, 15 Jan 2025 08:36:12 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A32F8C1332 for ; Wed, 15 Jan 2025 13:36:12 +0000 (UTC) X-FDA: 83009784984.22.7166BB7 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf15.hostedemail.com (Postfix) with ESMTP id 81C8FA0006 for ; Wed, 15 Jan 2025 13:36:10 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=clCBJjnf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3ybmHZwkKCJ48JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3ybmHZwkKCJ48JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736948170; 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=Ya/fxaSnf1SEqFKMY4TDHESa1dZdTGioTOn3JAAXwI4=; b=YVF5V2a3qiVZRoJXDkhlqWBQz7DxW0LL1+j8VTbvPD1bd1HPZQcjnQamMVnqfIkC9sojCm 2XDKWivmMg0zKiGnjqOh8JbuvsWi2q85Xjwu7mC/bXc1lDMYvLAkrNRknZYNjhY2+jXAsE iMq604+NQdfzMvtwxtqGy7Z7OvEJNFM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736948170; a=rsa-sha256; cv=none; b=VjTBu91A9j3Bm0xc0UUYRfPtvak77wON2vOvbcuCztis8sRepqlEBZROJ55k/5l9Oiqdds 6PhkE8tL+Hc28Pxd+zGwPxpAf4Myj9FxTTr/JMxf0eO8ZnG4sa7f1vMjfI+MXKvhD9XWOj B3XIz4P6niHCxqs+SaOa70/VFrlYamY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=clCBJjnf; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf15.hostedemail.com: domain of 3ybmHZwkKCJ48JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=3ybmHZwkKCJ48JGACPWFJEMMEJC.AMKJGLSV-KKIT8AI.MPE@flex--aliceryhl.bounces.google.com Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-3862e986d17so2637149f8f.3 for ; Wed, 15 Jan 2025 05:36:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1736948169; x=1737552969; 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=Ya/fxaSnf1SEqFKMY4TDHESa1dZdTGioTOn3JAAXwI4=; b=clCBJjnfEjX7MR8tJNi2H4nx683kBYM4RxyjWb7xW/dl8B2wcRwmcZRx30SeVKFhaV VTcPL2LeQrywsG7N/3s28NdfQXDW3upFzw96PHDs7kDX+ie5LCvGzciVGPG+vZuhRCpc fbxkkGzTX1zXNM78kmccLFLSkC8wy6Bkaa9rCfs9gFn7f57A0yOB7up+26ip03HNLGck 29Cv+oGFDbV6KpRi4DUNCq6Zg1y9ytDRUCxBkZd4TQQnfq2kWM4u2OH+3ueHFh2UzaTb awNtz4fDqmYFJkdvf304/lVPdsKdidiRS0zDpDRYte5VrmhUAIXe68DfBZHNR6aNtRDV Avrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736948169; x=1737552969; 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=Ya/fxaSnf1SEqFKMY4TDHESa1dZdTGioTOn3JAAXwI4=; b=b77wZsj2vPaSRuSp0DZ0bZNXGZqVa/gkFChS2mHg+9N41SMvy47jP61eLGGbyrTz3Y 6fT5h3lVbNltPY1xP+0L26gwvT/RP7kbJWoJNUtPVcCRKa5hANF9XufP1nJUxOjl90Tn ABzrfgZ6Fx4gB41jOpHIw6KaT8QLaqPen9yeC+YwVPHZvuMJv24cMp7nQY6xEIngotaN qjA1Zue5GKi3mxYee8DFrs1Dl2dSSOW6cgFz+t0ZkLUoqeegtxDUvSFSbZwa08HRQvLx gdNTwuuUlLgA8Q5M9OSWM+bEKMSUP5qETEve3lBVGXs6h544afAGFVd3mXOcqsE385Jo HNOw== X-Forwarded-Encrypted: i=1; AJvYcCX67Gfzl7Poq4UQVAS5e1ktn6ATmjGBS+VEq51mycsYJDxK1qHDe9FfUcq03fAQq0JXWXmPUcX47Q==@kvack.org X-Gm-Message-State: AOJu0YywVgxdmp0nU1mHBAYih0RqLe7k0OoCgzga+csig9szbiSH8lGx fP9v+7qspu3bCQsuk5cVEH6rapwphHBGIkDfISHgno27CRtnWlIhQ//fSqHyzbmYNNZGjvWlcIL +AdaQJ94jmyixzw== X-Google-Smtp-Source: AGHT+IEEOUuyOBCf8IcyxS1o5uyy5iTIdNXcjMWrtrUVHUECJs06QuKQ9EcQ4AA8mLcrc83eTJVAQLiN4y8LWyQ= X-Received: from wmbez6.prod.google.com ([2002:a05:600c:83c6:b0:434:fe2b:fea7]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:1acf:b0:385:e2c4:1f8d with SMTP id ffacd0b85a97d-38a87303f90mr22556236f8f.19.1736948169055; Wed, 15 Jan 2025 05:36:09 -0800 (PST) Date: Wed, 15 Jan 2025 13:35:05 +0000 In-Reply-To: <20250115-vma-v12-0-375099ae017a@google.com> Mime-Version: 1.0 References: <20250115-vma-v12-0-375099ae017a@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=11748; i=aliceryhl@google.com; h=from:subject:message-id; bh=QOlRN108XsMWfGHd4EUDmGqdXLByOcXjEpSpb+5Nkxw=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnh7m9WvlRbZQObnak5+wtq7CgBZq7hLM/eCfTF lPZEeBo+IWJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ4e5vQAKCRAEWL7uWMY5 Rm6yD/wP0UVoOG6bmiLYU6Qqhm25x+hZZB6dLvh4LLNZv7LLVM/H3ISW6cX7v8OttgZnVscdXBZ FJczNPPcDy0+wTAt8TScAmi1hE6+c9c4jn0dxHD6uAmwkK4LM1TmHzvZ9Pof6BsAICdqdLO0OtX Ahp+0oMGUjXonkRgsKkxdBb01kIKLJAYbn7F5dU1lcXci7Kigjp17uSrp0zUvLaZQpBATnOscW7 Y0LAEpfiWW/VWokrxjJ7SghmqmTmQb1D+muAUO862QlkMwazGG1VwMHrZqvMiXgi3xA4x3YTDbF iZCUjoG54SpHUs/HEYMBRqFf4Q6pWVBgHwVPlc+9OliIEapK1l+pCfDaRnaCBSCP6oNo4Mejv27 fS0AwXvap2o7b4crb+/HfxWbmQugSDmmeHvGWSU1de0Y+0rBiPx9weLukK6E3MrnJ7bJv+QeVUx +T9f/xdj8GcqK66LTI/YtjWBSEmBQoF0pQ4l5IJLZt+vN7X6y8dJxrNLvhQUe2M2idOSbTuoxSJ lIPgS9Rd5Q1y8VrIpl0tx34H8y0E6CN9Pk/Ks5ZkVT6+E9nBYJhNiYKOMhB9j2JDPzyWtLbON/q tH/fN1d/Dfni4vUv6L3OYcwjEBncMZr03OtqdKlVbSFF9OQVGDdZLxJSZCjrsKqNgCEiNP3qnUM O8kV99e5k87/X0g== X-Mailer: b4 0.13.0 Message-ID: <20250115-vma-v12-2-375099ae017a@google.com> Subject: [PATCH v12 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-Stat-Signature: xpu9pzy9rnq5n94qrh1n515usotc9ipz X-Rspamd-Queue-Id: 81C8FA0006 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736948170-596971 X-HE-Meta: U2FsdGVkX19XhcNE8t9nHuXnTGtbpoxW3TEJ7jwGQrI3VimoTm7tHFOCTs0DQxTi8ru8V+kFcEITQd4w5S2jNDjpggwiAMgtCXeEwb4MaRAKuqZ5oKZua/s4A85btUMWv0F8qmh9aRchpbH+nEePGqtBDkQdEzMOl8h+hSPwJky0N7cDzJJH19mQ2gHiW1p/VCQCuFgfEvzuKZn4tQ3uh/gVtp7IjG6I4+cIKAWH3I4LcU1JJxZ/VkZzgswQUgJaovEY27MQCC3EJ4YLcyWXJI2ZDJNx/AvkF+Vg1uEv2jlcN9E/fhUY2U3Oa9O5JRT20zns/m0WtHrEhgo9nfA28iWOyxjcc+2ERo+TdnBrMyGQQQ6xXvGCIZx+vgKnLFLN+rPW5d658jZLDg1cvE/p17WLkwtZtoO0vqmpDGr8TAybApxwlpG0S8QaVU0hEQDiGZultJfQIn0hwjMF8RASZBY753Yqp4rxV03GRTM2Svv1TYbIwhW/c5oY1YU3crNFdDvs5egBS3OpPIP4PnITu7l4DAkGR2mauquQsTqQgdyadXpsvbI++WZ7je3TDLjapLgywyF/cyHt2nSLFWb2VhNRKKeX1+s3FMkmjLX+IGzyN33VEA3KgWZldEEsi79ouafrgByRwQs2cPP98iCxCxEPRVaDfoJkyIY97ZobfbhRn6hAVdK0ePKIFrsZqKtvRE0JjUkWmRCumj0AmAbMojlTTtswgul7X/Tmxalw+CeQk0gSpoy/vc1PNBCQandeYzlH5e0NHgu5RYBVR1ndN7tp5nq+nMHsHEffyYTH3RRZGhLg4QT3yxtooCZLfbtcuMMoULWhafP5/KBg7yzMNJje+5xiGV697xmG34YXj/Ozi+SnrVgnc2Eyv4QyvmgmvQsaSYkME8UkE8qT48mkmfRkn10IDN71O7Zf7SFshPPUI5WB9WWAl7OlyyyRABUIEvNqUQ3FqSBle5+3cfs yXl9Bfv+ 6pNaPAnbPmRoxHzIj2yl+uBHeoz/XBQbADbQvDf7ktouczo5AqvqxadTxrshPqZXCNyTdcrrO6xivUWnf2HqzkQ/Ri4Tr9maQhj5HSbcYmyZUBxzmRWbjf59R010P4DCdVPSk0SRHobLywRP/7fv+9XjzpH26JWAXkyvBtD7j4l3cgdjAHPvGtD1c23bXx15IMm7Nkm4HNz4UDIgQBHt/sRugKv+TVPKZFmNeRJey9k95wEnPq1LRVjNK047IPCon4uDtlqi1pjwxF5ikJZhNv1aY2WX+Is+Sxg88FAg7nPVfGRiRW04CpYXX1OZ1+jgKfh/5FWNenQTR9HbtxpHZkoWGoXSEJGumIeJoo39V6/jGUyUkSrJ6wHjuP4M/yI51SpLznyc3YvqfXBI5WoIffg2uAaX0cCXvFC7svNHlrWXzX5ZOd6zKsu3F6K//zqSpSD6M4tjAhjeZEMWfPQGmCBxHPEPesRgeSEcfpi9J1Xl353Da/I9/sNz3L4gq9tEEHg2wteb1iYgqCyXg9S6nfjprPodoDTUFeLT0NobaimSmKUpL8BISfG60dSdEVqxpL4Vf2rFBmTiXVkWI5Y1a6otJpGmew26UNBJEIbDS4eGrQPLafWwrpQkSOq1TRtxH5v6SHc+KngVvY6B2EnbOXu/76SnynmN8v3xb+hYKEY/8jZg0cN1vAzTWj/pSDx0g1ueVHKRDHDIWzRw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.177263, 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 VmAreaRef 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 &VmAreaRef 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 (for mm bits) Reviewed-by: Jann Horn Signed-off-by: Alice Ryhl --- rust/helpers/mm.c | 6 ++ rust/kernel/mm.rs | 21 +++++ rust/kernel/mm/virt.rs | 215 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 242 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..ee1a062ec7d7 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,25 @@ 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::VmAreaRef> { + // SAFETY: We hold a reference to the mm, so the pointer must be valid. Any value is okay + // for `vma_addr`. + let vma = unsafe { bindings::vma_lookup(self.mm.as_raw(), vma_addr as _) }; + + if vma.is_null() { + None + } else { + // SAFETY: We just checked that a vma was found, so the pointer is valid. Furthermore, + // the returned area will borrow from this read lock guard, so it can only be used + // while the mmap read lock is still held. + unsafe { Some(virt::VmAreaRef::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..2c7de0460e0a --- /dev/null +++ b/rust/kernel/mm/virt.rs @@ -0,0 +1,215 @@ +// 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. +//! [`VmAreaRef`] 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 VmAreaRef { + 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 VmAreaRef { + /// 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 as _ } + } + + /// 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 as _ } + } + + /// 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 as _ } + } + + /// 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 as _, + size as _, + core::ptr::null_mut(), + ) + }; + } +} + +/// The integer type used for vma flags. +#[doc(inline)] +pub use bindings::vm_flags_t; + +/// All possible flags for [`VmAreaRef`]. +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 _; +}