docs: filesystems: update mmap_prepare docs for discontig kernel pgs

Describe the newly introduced discontiguous kernel page mapping mechanism,
detailing how to use it sensibly and how the API looks.

Explicitly detail the various discontiguous actions available and how to
use them.

Link: https://lore.kernel.org/20261013-b4-mmap-prepare-vma-flag-sanify-v6-9-1aa3c9b139f9@kernel.org
Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Acked-by: David Hildenbrand (Arm) <david@kernel.org>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Jann Horn <jannh@google.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Paul Moore <paul@paul-moore.com>
Cc: Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: Zi Yan <ziy@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Nico Pache <nico.pache@linux.dev>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Kiryl Shutsemau <kas@kernel.org>
Cc: Doug Gilbert <dgilbert@interlog.com>
Cc: James Bottomley <james.bottomley@hansenpartnership.com>
Cc: Martin K. Petersen <mkp@kernel.org>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: Helge Deller <deller@gmx.de>
Cc: Sebastian Reichel <sre@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Harry Yoo <harry@kernel.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Will Deacon <will@kernel.org>
Cc: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Oliver Upton <oupton@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Anup Patel <anup@brainfault.org>
Cc: Paul Walmsley <pjw@kernel.org>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Rakie Kim <rakie.kim@sk.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Gregory Price <gourry@gourry.net>
Cc: Ying Huang <ying.huang@linux.alibaba.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: Nhat Pham <nphamcs@gmail.com>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Youngjun Park <youngjun.park@lge.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Qi Zheng <qi.zheng@linux.dev>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: Wei Xu <weixugc@google.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Cc: Xu Xin <xu.xin@linux.dev>
Cc: Ihor Solodrai <ihor.solodrai@linux.dev>
Cc: Bert Karwatzki <spasswolf@web.de>
This commit is contained in:
Lorenzo Stoakes (ARM) 2026-10-13 16:04:49 +01:00 committed by Andrew Morton
parent b7b4d8f37a
commit ae60723abb

View File

@ -164,5 +164,86 @@ pointer. These are:
sufficient entries in the page array to cover the entire range of the
described VMA.
* mmap_action_map_discontig_kernel_pages() - Maps a discontiguous range of
`struct page` pointers over the VMA. They must span from the start of the VMA,
but may terminate prior to the end (leaving the remainder unmapped).
**NOTE:** The ``action`` field should never normally be manipulated directly,
rather you ought to use one of these helpers.
Discontiguous Actions
=====================
Some actions can be performed across discontiguous ranges.
Map kernel pages
----------------
To map kernel pages discontiguously, you must provide hooks using ``struct
discontig_kernel_page_ops``:
.. code-block:: C
struct discontig_kernel_page_ops {
int (*init)(void *vm_private_data, void **private);
int (*get)(struct discontig_kernel_page_state *state);
};
The ``init`` hook is optional and allows state to be established before the
operation starts, for instance taking a reference count. Nothing is invoked
after the operation, so ``init`` must not leave locks held, and state that must
be released once the mapping goes away should be released in
``vm_ops->close``.
The ``init`` hook, if provided, is invoked prior to the operation starting. It
may update what is pointed to by ``vm_private_data`` and/or ``private``. If an
error is returned, then the operation is aborted. The ``private`` field can be
reassigned.
**NOTE:** The operation may sleep between invocations of ``get``, so locks
needed to stabilise state must be taken and released within each hook.
The ``get`` handler is the key means through which the operation is
executed. The current state of the operation is provided through ``struct
discontig_kernel_page_state``:
.. code-block:: C
struct discontig_kernel_page_state {
/* Map state. */
unsigned long start; /* Start address of VMA. */
unsigned long end; /* End address of VMA. */
unsigned long addr; /* The current address to be mapped. */
pgoff_t pgoff; /* The current pgoff to be mapped. */
unsigned long nr_pages_mapped; /* The number of pages mapped. */
unsigned long nr_pages_remain; /* The number of pages remaining. */
/* User-defined state. */
void *vm_private_data; /* VMA private data. */
void *private; /* Mapping private data. */
/* Users should not touch these, use discontig_kernel_map_*() helpers. */
... internal fields ...
};
With ``private`` being an additional user-controllable state variable,
initialised via ``mmap_action_map_discontig_kernel_pages()``, and
``vm_private_data`` being equal to the ``desc->private_data`` field set in
the ``mmap_prepare()`` hook.
In the ``get`` hook, the user must choose how to map kernel pages:
* ``discontig_kernel_map_abort()`` - Call this to abort the operation, whatever
has been mapped so far will be retained, the rest of the mapping will SIGBUS
if accessed.
* ``discontig_kernel_map_page()`` - Maps a single page, correctly handling
compound pages (if the compound page is bigger than the remaining pages in the
VMA, then only those pages that fit will be mapped). For a compound page, the
head page must be passed.
* ``discontig_kernel_map_pages()`` - Map an array of pages of a specified
size. As with a compound page, if more pages are specified than remain in
the VMA then only those that fit will be mapped.
If an error arises after ``init`` succeeded, the core unmaps the VMA, invoking
``vm_ops->close`` if set, which is therefore the place to release any state
that ``init`` established.