From patchwork Mon Feb 3 12:14:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alice Ryhl X-Patchwork-Id: 13957365 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 67989C02192 for ; Mon, 3 Feb 2025 12:21:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFFC0280012; Mon, 3 Feb 2025 07:21:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E895928000F; Mon, 3 Feb 2025 07:21:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CDB58280012; Mon, 3 Feb 2025 07:21:23 -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 A814528000F for ; Mon, 3 Feb 2025 07:21:23 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0A976162DBA for ; Mon, 3 Feb 2025 12:15:20 +0000 (UTC) X-FDA: 83078528400.08.C2DF3F9 Received: from mail-wr1-f73.google.com (mail-wr1-f73.google.com [209.85.221.73]) by imf03.hostedemail.com (Postfix) with ESMTP id 0066120002 for ; Mon, 3 Feb 2025 12:15:17 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XHl2cy8z; spf=pass (imf03.hostedemail.com: domain of 3VLOgZwkKCIEfqnhjw3mqlttlqj.htrqnsz2-rrp0fhp.twl@flex--aliceryhl.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3VLOgZwkKCIEfqnhjw3mqlttlqj.htrqnsz2-rrp0fhp.twl@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=1738584918; 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=HsKBb44x7fv9WNumP7fvjTBcr8RrxO1zg/m2ciN2/Jk=; b=xUC7KDXKvQKgDL29RAJW3nMKGoC9lHcVsXk9T/ef8SNVUdRshdFekMnq28101Vpjvrv4gR 2RUbF3kIzf7UYlnQXw2wN2NCrfzPV9F9rHjFzst7dRLs+KxybeErDMJauaEyAvfmBbKmeC gLM96CsCSyI/VSttP8kSyXY6GoA3K1U= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=XHl2cy8z; spf=pass (imf03.hostedemail.com: domain of 3VLOgZwkKCIEfqnhjw3mqlttlqj.htrqnsz2-rrp0fhp.twl@flex--aliceryhl.bounces.google.com designates 209.85.221.73 as permitted sender) smtp.mailfrom=3VLOgZwkKCIEfqnhjw3mqlttlqj.htrqnsz2-rrp0fhp.twl@flex--aliceryhl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738584918; a=rsa-sha256; cv=none; b=M+hmT7FfqTHi1V/CCyXOyW1zwDy0VFybSTV4l4OmAFVGISIBoqdx+V3RUe0Z9xQIj4VPce y0mwMPW2ONP0b7GoZXe/u0KBtKqekPTcBytE7HwTgeutE1feC2LD0BkQGFKkLZ+zybiziu TqPnrsF0XVsq0yA4JS9XzXtBz4QdeT8= Received: by mail-wr1-f73.google.com with SMTP id ffacd0b85a97d-38c5d9530ebso2468581f8f.1 for ; Mon, 03 Feb 2025 04:15:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738584916; x=1739189716; 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=HsKBb44x7fv9WNumP7fvjTBcr8RrxO1zg/m2ciN2/Jk=; b=XHl2cy8zfpbGyXRB4Hu33fR1+0pYsHT4wODf+3YsXoTcOatUoYcbbkozpVgFiOrSbQ 4VuIfTQqa8irIq416eGBT6Y9ZgwPS7uusJCfXhxqUS/dKJYKdS/oRQ7xPdf4nOOC+qlh KWQtEaFiyL1u8G6SNAGVGYGVjjc65XzE+3DuLHCSFEo4II613bz4CFUY55UIiIq4lkES OFQNgAoEl4xgRa10B9qugJqUpD7w+iRxUldapPuatuH0wW5KGFl/UB3OVBBSuEyy0Cgz tSLUmF3e/Dgm49m8+Z8HW4Q55EOmADY1jzNbMSBzacn7CB1v6EW4zRHDZ3jBT53pW3zl mGTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738584916; x=1739189716; 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=HsKBb44x7fv9WNumP7fvjTBcr8RrxO1zg/m2ciN2/Jk=; b=ZtW5xkwOD7njJ/TOUFD2n7dD7DbEGkubFDFUgfF8d8gAz6YllB2rp7s6QPthItmfi6 MU9XYvELUF/9XEImoQh6CQ/vrCHS+ilqJY/Pr56oRczd1WrNNTcSrsrET6ycPQnBB1Ci h93tkUY1KvkRZLt8/FBZsGM/eY2r62lQvFLqucHh4wKsVKfBDqYttwowz+alvVz6hDLj 2JDTOJ8e9Rzzwx49CbT56iYEjSXLFA1VzhJY9shCfRyIc0nIByubjphZ4e3b/2aUKbii zRAnhynkYM5oS5Lv2gE5N+YsjJC/M/BDcNGScbL//hfiXDHJMngYWCdzb9WuH+/G3VRU q+Xw== X-Forwarded-Encrypted: i=1; AJvYcCVlcXFFdEnwDIinIDLHGL0BfmP9SU2vr2c2gnh3ZeHPruGJFrfnedZtUap1+X1/yJN4ohlK0+VMDg==@kvack.org X-Gm-Message-State: AOJu0YzeZcOuiwQDIN9P1APoOGsXpNkg70i/SvoZmmho65xlasqKWYxZ +faA1pxy46JSOEMYyw/ASFv/JJxUxXIpl0EyJ78RTrsBoisJ7yMFrBhgcg2TQ9O1OrCS56BuYI7 ubJJ1978Qholkzg== X-Google-Smtp-Source: AGHT+IGOresZtCVdJKJ16Ys67mlWuwAfUZhBuPWvVIUcEJB1FfKeHTp8NIO1djUpkZoFwaOzxSKnCdpKbygHPEE= X-Received: from wmbbd13.prod.google.com ([2002:a05:600c:1f0d:b0:436:d819:e4eb]) (user=aliceryhl job=prod-delivery.src-stubby-dispatcher) by 2002:a5d:64e4:0:b0:38a:88b8:99af with SMTP id ffacd0b85a97d-38c51951c62mr17694566f8f.22.1738584916380; Mon, 03 Feb 2025 04:15:16 -0800 (PST) Date: Mon, 03 Feb 2025 12:14:37 +0000 In-Reply-To: <20250203-vma-v13-0-2b998268a396@google.com> Mime-Version: 1.0 References: <20250203-vma-v13-0-2b998268a396@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=11755; i=aliceryhl@google.com; h=from:subject:message-id; bh=/iebTH4KyLdhY2vEuCqOUZUvZGhbmsvxzfHd3W6xGAw=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBnoLNJRZfEeR3BWa35+Ak8WITPcMAAKc+QWrycD kjuKVWdrXCJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZ6CzSQAKCRAEWL7uWMY5 RrjdD/9d3vmLpQxCmf2tyIFTe9dQwpb1iBMSAvRFzmKu4O1tCa5YWfrnaXETZ4zvdhKTX3g2KKb 3ToivU/ExeDSdC3XpbFd2TrTitpNFUSYhuRbE3cVssUotjcfwhhJGblejNUYaxktpljVRyWObMD O5rGkdtaDB1BvhYoKzFlGK/3SwId0AmDQ29cFKVdYh28Uk+edlT8idXS0b46aRkmqvY39kjG2Gt b+HtofyaMg3gqzMGgfIv2avEIm2WGpcxrTMou87zLGpzfbpWknwXhLiOrX9zxtte6CyZPB5gNm6 rht0AEZXCEOPEN2ISN0zBoITZR7B5yrQJmlZ06JaRSzX5wfTObamyJbJmys9FCoLfAI2tQfQG5d 7t98kzkwdYl8XfmEBFT9e/7Kld5Hpa1XzQ+RSkBXYbjY3vmhKti5Ev7eX1YVMx42sGFgO7LvxNv cErtZCKMWoqxs6SfRz8WYi0ES19Ip63L1qWPda2Uu28USt3UBuPHHgxDgq1Vcbj+RmivpQaF/4I C7tBYlQevnitMD7q0YsGC6wMGRlLJ9ZbpVxOcw838c2tMn59KGT35NlRMzhzocKXlvnL9Nc7ndj /6FzQf6+ugL4N3/zCXMT1W1u6AaAoYY0WqgsLPNNQj3F0Prz2+BvJCloJ1aRSlhUBoquwK23CQ6 h5I822DNznDWZSg== X-Mailer: b4 0.13.0 Message-ID: <20250203-vma-v13-2-2b998268a396@google.com> Subject: [PATCH v13 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-Server: rspam07 X-Rspamd-Queue-Id: 0066120002 X-Stat-Signature: 8xm8qkoyuurfxmyp5zbee6o3somyftby X-Rspam-User: X-HE-Tag: 1738584917-6341 X-HE-Meta: U2FsdGVkX19BjSm8jR5Y48fho3R5KK38Rrx+xzAM2Tt8dTIwn2h9SQP75abZjB0u/NHt/EnrsTa1yUChtsMAE+EUYNbcniz56NA6XgwB6SKNCqk97chUv12JFQVJXqohj8fdO3CWFCi5hGHY+j9haM/aSb+85fRdiNoC4Gu+a9I/pmVf0o4DSxb5mRrudjSBFK5L87X0SjVwSOMxN91S4Vj0XiOPdqCDpa9BAgwnvD4edBQeA2mAF13ZxTmOYfb+cwGIbWVTNmkSXF1ZWEzv8v4Fya0H/YXDgNXKxHGzywt/FMmjbw0kfQCbbgCJBOde2eu9JcLMDb8SayTj+QZDk6E2NyFMd/CA/GMKnqoe0XbiDiW2q6zpS/n6n1aZLlp8bsrOVf/56sSpFYpwR8vnbXJXDAAyEzlF/ydGpFw3wQGhxS7Q5JUkIoR/AeakPgv5DYNh1aiJMgGyfvtYYjDu4TBOPs73MSei6PyQGivBe7yy4BM8Mphcj1br5Z/ZlgRsCchMEyjY9KahagOI4fKU7JAtvbxJfRRjqnOMz3rqi3apfmQlHiVG2FccP43An9/JpFU0qhNUoFkYdu4VNGEDubtUbJDCV77dmIg/iHzOnubN1RV48491wMQMmud2OEx8AEAiAvEiITa/T8DVlbLjngIJCyKcHsf9tq1J6ljoP9vwWmjnQURWPQTRaNLNGuxCBAx2YvX6sgSWgyE1FmNxqpQ/QuinZ5UC8ywjMYI04O11blO2hym4p9WQzP+svo+OAHsFtWihss0ZBb0YE3RP/3729ZWrIPBfmlYBOfy9jbgAryvh2iCyVAvH95LJuHDzeRlmQwgS4fKJLo8al7Z/zYJSHQU7YfhG6mD1Y5PD7NGCTxq4KMy2z/i/YEco+l36dw8T7UBOB0Z0YshWJIDBNj+Spxd7zPmK1xGlRllfux78gUgZBNrk/q0puNiAPLRnoE6nogV9yEC/t4uYwWu UZxCUOjR W7j2Wm01iUUuJb6TqigjqUj8C+6ASq+HgIoSz6h3QdCZOfQvSLEuYR6d080SpVz79LygU+B6nuF9LZWjmF2+KQ9nKl0GwQw1mNvPmYDaPOWMLN99ecCXBxWk+eaNG6hP3nAxAFhKOZB2Nr+c34EP0TAEvP5/VOLBYnorzgQCJ7P7MMnQgGfjVdVVyjGg/g9YjAVUdqVJPGtT9vs88ug0524WfMeqs9j2X3Cj3wh0wSUxcH1jnM5gT4atHg4Di8HadOtYzqCK/9zB42mvm/KbwZFlMqY4wmS51rYddB3eiSCvxARbjKSr1wDdLiyiqPMt2kyCnN7Gs8cvLnjCvZbYqck+CpIQjeqwKHlcZ8nAUPDOKTYvptL2tvq1PUoVIdKMO6gn/4KHLJpnOV4xDt7R78y5MgPHxnAxkbhPV13lSqiUNWW5ppUDfTfUw4wbDJJ6r+PK6jvfudO8osbvYxTgx9D+BhcF1qCr+wJq7YzLt5FZojubgTtp3BCJgwplQxvAOkOy55grKA/VunIHT3cAtFNtVlsZ8qUc54LCCEaWs3qHQZPURKQ2SqwOYuBtNp54xDhIJGrMizI80GbUzJEubgmJEbL0M4M1PVcqwYzWMDVWM6lNWC1inGS1/JGmvqzW+Rm0zc+WSnbFJA/bZ/B+kfaTl+4/0O0szGDQSZbrMfGRuUAAnXxGwPu1huVrN4gffkzbppEppgL+X4OwT1wXF8a0uIsIzRPJ/Xj/i X-Bogosity: Ham, tests=bogofilter, spamicity=0.309983, 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 Reviewed-by: Jann Horn Reviewed-by: Andreas Hindborg 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..bd6ff40f106f 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) }; + + 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..dfe147cafdb3 --- /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 } + } + + /// 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 [`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 _; +}