.\" Copyright, the authors of the Linux man-pages project
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH UFFDIO_RWPROTECT 2const 2026-05-28 "Linux man-pages 6.19"
.SH NAME
UFFDIO_RWPROTECT
\-
read-write-protect or un-protect a userfaultfd-registered memory range
.SH LIBRARY
Standard C library
.RI ( libc ,\~ \-lc )
.SH SYNOPSIS
.nf
.BR "#include <linux/userfaultfd.h>" "  /* Definition of " UFFD* " constants */"
.B #include <sys/ioctl.h>
.P
.BI "int ioctl(int " fd ", UFFDIO_RWPROTECT, struct uffdio_rwprotect *" argp );
.P
.B #include <linux/userfaultfd.h>
.P
.fi
.EX
.B struct uffdio_rwprotect {
.BR "    struct uffdio_range  range;" "  /* Range to change RWP on */"
.BR "    __u64                mode;" "   /* Mode flags */"
.B };
.EE
.SH DESCRIPTION
Read-write-protect or un-protect a userfaultfd-registered memory range
registered with mode
.BR UFFDIO_REGISTER_MODE_RWP .
.P
The following mode bits are supported:
.TP
.B UFFDIO_RWPROTECT_MODE_RWP
When this mode bit is set,
the ioctl installs read-write protection
on every page present in the range specified by
.IR .range .
Otherwise the ioctl removes read-write protection from the range,
which is also how a fault handler resolves an
.B UFFD_PAGEFAULT_FLAG_RWP
notification.
.TP
.B UFFDIO_RWPROTECT_MODE_DONTWAKE
When this mode bit is set,
do not wake up any thread
that waits for page-fault resolution after the operation.
This can be specified only if
.B UFFDIO_RWPROTECT_MODE_RWP
is not specified.
.P
Read-write protection only affects pages
that are currently populated in the range;
unmapped addresses are left untouched.
For anonymous mappings,
protection is preserved across page reclaim
(the marker rides on the swap entry)
and migration.
For shmem and file-backed mappings,
protection is dropped when the backing page is reclaimed.
Callers must also re-arm a range with
.B UFFDIO_RWPROTECT
after any operation that explicitly drops the underlying page:
.B MADV_DONTNEED
on anonymous memory,
hole-punch on shmem,
truncation of a file mapping.
.SH RETURN VALUE
On success,
0 is returned.
On error, \-1 is returned and
.I errno
is set to indicate the error.
.SH ERRORS
.TP
.B EINVAL
The
.I start
or the
.I len
field of the
.I uffdio_range
structure was not a multiple of the system page size,
or
.I len
was zero,
or the specified range was otherwise invalid,
or an invalid mode bit was specified,
or
.B UFFDIO_RWPROTECT_MODE_DONTWAKE
was specified together with
.BR UFFDIO_RWPROTECT_MODE_RWP .
.TP
.B EAGAIN
The process was interrupted;
retry this call.
.TP
.B ENOENT
The range specified in
.I .range
is not valid;
for example, the virtual address does not exist,
or part of the range is not registered with
.BR UFFDIO_REGISTER_MODE_RWP .
.TP
.B EFAULT
Encountered a generic fault during processing.
.SH STANDARDS
Linux.
.SH HISTORY
Linux 7.2.
.SH EXAMPLES
See
.BR userfaultfd (2).
.SH SEE ALSO
.BR ioctl (2),
.BR ioctl_userfaultfd (2),
.BR userfaultfd (2)
.P
.I linux.git/\:Documentation/\:admin\-guide/\:mm/\:userfaultfd.rst
