Commit f9451df2 authored by Mike Rapoport's avatar Mike Rapoport Committed by Jonathan Corbet

docs/vm: userfaultfd.txt: convert to ReST format

Signed-off-by: default avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: default avatarJonathan Corbet <corbet@lwn.net>
parent a5e4da91
= Userfaultfd = .. _userfaultfd:
== Objective == ===========
Userfaultfd
===========
Objective
=========
Userfaults allow the implementation of on-demand paging from userland Userfaults allow the implementation of on-demand paging from userland
and more generally they allow userland to take control of various and more generally they allow userland to take control of various
...@@ -9,7 +14,8 @@ memory page faults, something otherwise only the kernel code could do. ...@@ -9,7 +14,8 @@ memory page faults, something otherwise only the kernel code could do.
For example userfaults allows a proper and more optimal implementation For example userfaults allows a proper and more optimal implementation
of the PROT_NONE+SIGSEGV trick. of the PROT_NONE+SIGSEGV trick.
== Design == Design
======
Userfaults are delivered and resolved through the userfaultfd syscall. Userfaults are delivered and resolved through the userfaultfd syscall.
...@@ -41,7 +47,8 @@ different processes without them being aware about what is going on ...@@ -41,7 +47,8 @@ different processes without them being aware about what is going on
themselves on the same region the manager is already tracking, which themselves on the same region the manager is already tracking, which
is a corner case that would currently return -EBUSY). is a corner case that would currently return -EBUSY).
== API == API
===
When first opened the userfaultfd must be enabled invoking the When first opened the userfaultfd must be enabled invoking the
UFFDIO_API ioctl specifying a uffdio_api.api value set to UFFD_API (or UFFDIO_API ioctl specifying a uffdio_api.api value set to UFFD_API (or
...@@ -101,7 +108,8 @@ UFFDIO_COPY. They're atomic as in guaranteeing that nothing can see an ...@@ -101,7 +108,8 @@ UFFDIO_COPY. They're atomic as in guaranteeing that nothing can see an
half copied page since it'll keep userfaulting until the copy has half copied page since it'll keep userfaulting until the copy has
finished. finished.
== QEMU/KVM == QEMU/KVM
========
QEMU/KVM is using the userfaultfd syscall to implement postcopy live QEMU/KVM is using the userfaultfd syscall to implement postcopy live
migration. Postcopy live migration is one form of memory migration. Postcopy live migration is one form of memory
...@@ -163,7 +171,8 @@ sending the same page twice (in case the userfault is read by the ...@@ -163,7 +171,8 @@ sending the same page twice (in case the userfault is read by the
postcopy thread just before UFFDIO_COPY|ZEROPAGE runs in the migration postcopy thread just before UFFDIO_COPY|ZEROPAGE runs in the migration
thread). thread).
== Non-cooperative userfaultfd == Non-cooperative userfaultfd
===========================
When the userfaultfd is monitored by an external manager, the manager When the userfaultfd is monitored by an external manager, the manager
must be able to track changes in the process virtual memory must be able to track changes in the process virtual memory
...@@ -172,27 +181,30 @@ the same read(2) protocol as for the page fault notifications. The ...@@ -172,27 +181,30 @@ the same read(2) protocol as for the page fault notifications. The
manager has to explicitly enable these events by setting appropriate manager has to explicitly enable these events by setting appropriate
bits in uffdio_api.features passed to UFFDIO_API ioctl: bits in uffdio_api.features passed to UFFDIO_API ioctl:
UFFD_FEATURE_EVENT_FORK - enable userfaultfd hooks for fork(). When UFFD_FEATURE_EVENT_FORK
this feature is enabled, the userfaultfd context of the parent process enable userfaultfd hooks for fork(). When this feature is
is duplicated into the newly created process. The manager receives enabled, the userfaultfd context of the parent process is
UFFD_EVENT_FORK with file descriptor of the new userfaultfd context in duplicated into the newly created process. The manager
the uffd_msg.fork. receives UFFD_EVENT_FORK with file descriptor of the new
userfaultfd context in the uffd_msg.fork.
UFFD_FEATURE_EVENT_REMAP - enable notifications about mremap()
calls. When the non-cooperative process moves a virtual memory area to UFFD_FEATURE_EVENT_REMAP
a different location, the manager will receive UFFD_EVENT_REMAP. The enable notifications about mremap() calls. When the
uffd_msg.remap will contain the old and new addresses of the area and non-cooperative process moves a virtual memory area to a
its original length. different location, the manager will receive
UFFD_EVENT_REMAP. The uffd_msg.remap will contain the old and
UFFD_FEATURE_EVENT_REMOVE - enable notifications about new addresses of the area and its original length.
madvise(MADV_REMOVE) and madvise(MADV_DONTNEED) calls. The event
UFFD_EVENT_REMOVE will be generated upon these calls to madvise. The UFFD_FEATURE_EVENT_REMOVE
uffd_msg.remove will contain start and end addresses of the removed enable notifications about madvise(MADV_REMOVE) and
area. madvise(MADV_DONTNEED) calls. The event UFFD_EVENT_REMOVE will
be generated upon these calls to madvise. The uffd_msg.remove
UFFD_FEATURE_EVENT_UNMAP - enable notifications about memory will contain start and end addresses of the removed area.
unmapping. The manager will get UFFD_EVENT_UNMAP with uffd_msg.remove
containing start and end addresses of the unmapped area. UFFD_FEATURE_EVENT_UNMAP
enable notifications about memory unmapping. The manager will
get UFFD_EVENT_UNMAP with uffd_msg.remove containing start and
end addresses of the unmapped area.
Although the UFFD_FEATURE_EVENT_REMOVE and UFFD_FEATURE_EVENT_UNMAP Although the UFFD_FEATURE_EVENT_REMOVE and UFFD_FEATURE_EVENT_UNMAP
are pretty similar, they quite differ in the action expected from the are pretty similar, they quite differ in the action expected from the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment