linux/include/uapi
Kiryl Shutsemau (Meta) 39a7c34ea5 userfaultfd: add UFFDIO_SET_MODE for runtime sync/async toggle
Add an ioctl to toggle async mode at runtime without re-registering the
userfaultfd.  This allows a VMM to switch between sync and async RWP modes
on-the-fly -- for example, starting in async mode for working set
scanning, then switching to sync mode to intercept faults during page
eviction.

UFFDIO_SET_MODE takes an enable/disable bitmask of UFFD_FEATURE_* flags. 
Only UFFD_FEATURE_RWP_ASYNC is toggleable today; the ioctl rejects any
other bit with -EINVAL.  Enabling RWP_ASYNC also requires RWP to have been
negotiated at UFFDIO_API time, mirroring the UFFDIO_API invariant.

Fault-path readers of ctx->features run under mmap_read_lock or a per-VMA
lock; the RMW takes mmap_write_lock and calls vma_start_write() on every
UFFD-armed VMA, so those readers are fully excluded. 
userfaultfd_show_fdinfo(), however, reads ctx->features without any lock,
so the RMW is written as a single WRITE_ONCE and fdinfo reads it with
READ_ONCE.  That keeps the lockless observer from seeing a mid-RMW
intermediate and removes the audit burden when new toggleable bits are
added later.

When switching to async, pending sync waiters are woken so they retry and
auto-resolve under the new mode.

Link: https://lore.kernel.org/20260708111417.173443-14-kirill@shutemov.name
Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org>
Assisted-by: Claude:claude-opus-4-6
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: James Houghton <jthoughton@google.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: SeongJae Park <sj@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-08-04 19:18:39 -07:00
..
asm-generic vfs-7.2-rc1.misc 2026-06-15 03:59:45 +05:30
cxl fwctl/cxl: Fix uuid_t usage in uapi 2025-04-11 20:45:43 -03:00
drm Merge tag 'drm-msm-next-2026-05-30' of https://gitlab.freedesktop.org/drm/msm into drm-next 2026-06-04 06:41:22 +10:00
fwctl fwctl/bnxt_fwctl: Add bnxt fwctl device 2026-03-31 13:33:54 -03:00
linux userfaultfd: add UFFDIO_SET_MODE for runtime sync/async toggle 2026-08-04 19:18:39 -07:00
misc Char/Misc/IIO/Binder changes for 6.18-rc1 2025-10-04 16:26:32 -07:00
mtd
rdma RDMA/uverbs: Expose CoCo DMA bounce requirement to userspace 2026-05-29 20:27:29 -03:00
regulator regulator: uapi: Use UAPI integer type 2025-12-22 09:00:42 +00:00
scsi scsi: fc: Fix typo in fc_els.h 2026-03-27 16:35:04 -04:00
sound ASoC: SOF: ipc4-topology: Add new tokens for pipeline direction 2026-02-04 13:26:05 +00:00
video
xen
Kbuild