Skip to contentSkip to conversation

userfaultfd.2: Update to latest

PATCH Superseded Peter Xu 2 participants 6 messages May 31, 2022 – Jun 3, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

cover userfaultfd.2: Update to latest

Add the two missing pieces till latest 5.19-rc1: the UFFD_USER_MODE_ONLY flag, and also the recent wr-protect support on shmem and hugetlbfs.

Please review, thanks.

Peter Xu (2):
userfaultfd.2: Add section for UFFD_USER_MODE_ONLY userfaultfd.2: Update on write-protection support

 man2/userfaultfd.2 | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
Signature · 1 line
2.32.0
author
#1 lore raw

PATCH 1/2 userfaultfd.2: Add section for UFFD_USER_MODE_ONLY

Add a paragraph for UFFD_USER_MODE_ONLY flag that was introduced in Linux 5.11.

---
 man2/userfaultfd.2 | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
man2/userfaultfd.2 +12 -2
index cee7c01d2..0928a76d2 100644
@@ -29,8 +29,9 @@
 userfaultfd \- create a file descriptor for handling page faults in user space
 .SH SYNOPSIS
 .nf
-.BR "#include <fcntl.h>" "            /* Definition of " O_* " constants */"
-.BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
+.BR "#include <fcntl.h>" "             /* Definition of " O_* " constants */"
+.BR "#include <sys/syscall.h>" "       /* Definition of " SYS_* " constants */"
+.BR "#include <linux/userfaultfd.h>" " /* Definition of " UFFD_* " constants */"
 .B #include <unistd.h>
 .PP
 .BI "int syscall(SYS_userfaultfd, int " flags );
@@ -76,6 +77,15 @@ See the description of the
 .BR O_NONBLOCK
 flag in
 .BR open (2).
+.TP
+.BR UFFD_USER_MODE_ONLY
+This is an userfaultfd specific flag that was introduced since Linux 5.11.
+When set, the userfaultfd object will only be able to handle page faults
+originated from the userspace on the registered regions.
+When a kernel originated fault was triggered on the registered range with
+this userfaultfd, a
+.BR SIGBUS
+signal will be delivered.
 .PP
 When the last file descriptor referring to a userfaultfd object is closed,
 all memory ranges that were registered with the object are unregistered
Signature · 1 line
2.32.0
author
#4 lore raw

PATCH 2/2 userfaultfd.2: Update on write-protection support

In reply to Peter Xu

The shmem/hugetlbfs memory types are supported for write-protection messages very lately. Update the man page to reflect that.

---
 man2/userfaultfd.2 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
man2/userfaultfd.2 +5 -3
index 0928a76d2..99aae8b50 100644
@@ -273,13 +273,17 @@ Since Linux 4.11,
 userfaultfd can be also used with hugetlbfs and shared memory mappings.
 .\"
 .SS Userfaultfd write-protect mode (since 5.7)
-Since Linux 5.7, userfaultfd supports write-protect mode.
+Since Linux 5.7, userfaultfd supports write-protect mode for anonymous memory.
 The user needs to first check availability of this feature using
 .B UFFDIO_API
 ioctl against the feature bit
 .B UFFD_FEATURE_PAGEFAULT_FLAG_WP
 before using this feature.
 .PP
+Since Linux 5.19, the write-protection mode was also supported on shmem and hugetlbfs
+memory types. It can be detected with the feature bit
+.BR UFFD_FEATURE_WP_HUGETLBFS_SHMEM .
+.PP
 To register with userfaultfd write-protect mode, the user needs to initiate the
 .B UFFDIO_REGISTER
 ioctl with mode
@@ -330,8 +334,6 @@ ioctl, whose
 should have the flag
 .B UFFDIO_WRITEPROTECT_MODE_WP
 cleared upon the faulted page or range.
-.PP
-Write-protect mode supports only private anonymous memory.
 .SS Reading from the userfaultfd structure
 Each
 .BR read (2)
Signature · 1 line
2.32.0
#2 lore raw

Re: [PATCH 1/2] userfaultfd.2: Add section for UFFD_USER_MODE_ONLY

In reply to Peter Xu

Hi Peter,

Quoted 4 lines · Peter Xu

Add a paragraph for UFFD_USER_MODE_ONLY flag that was introduced in Linux 5.11.

See some minor comments below.

Cheers,

Alex

Quoted 21 lines
---
  man2/userfaultfd.2 | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)
man2/userfaultfd.2 +3 -2
index cee7c01d2..0928a76d2 100644
@@ -29,8 +29,9 @@
  userfaultfd \- create a file descriptor for handling page faults in user space
  .SH SYNOPSIS
  .nf
-.BR "#include <fcntl.h>" "            /* Definition of " O_* " constants */"
-.BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
+.BR "#include <fcntl.h>" "             /* Definition of " O_* " constants */"
+.BR "#include <sys/syscall.h>" "       /* Definition of " SYS_* " constants */"
+.BR "#include <linux/userfaultfd.h>" " /* Definition of " UFFD_* " constants */"
  .B #include <unistd.h>
  .PP
  .BI "int syscall(SYS_userfaultfd, int " flags );

man2/userfaultfd.2 See the description of the · line 81

Quoted 5 lines
man2/userfaultfd.2 +2 -0
@@ -76,6 +77,15 @@ See the description of the
  .BR O_NONBLOCK
  flag in
  .BR open (2).
+.TP
+.BR UFFD_USER_MODE_ONLY

s/BR/B/

see groff_man(7):

[
[...]

.B [text]
Set text in bold. If the macro is given no argu‐ ments, the text of the next input line is set in bold.

[...]

.BR bold‐text roman‐text ...
Set each argument in bold and roman, alternately.
]

man2/userfaultfd.2 See the description of the · line 87

Quoted 6 lines
man2/userfaultfd.2 +6 -0
+This is an userfaultfd specific flag that was introduced since Linux 5.11.
+When set, the userfaultfd object will only be able to handle page faults
+originated from the userspace on the registered regions.
+When a kernel originated fault was triggered on the registered range with
+this userfaultfd, a
+.BR SIGBUS

s/BR/B/

Quoted 4 lines
man2/userfaultfd.2 +1 -0
+signal will be delivered.
  .PP
  When the last file descriptor referring to a userfaultfd object is closed,
  all memory ranges that were registered with the object are unregistered
Signature · 2 lines
Alejandro Colomar
<http://www.alejandro-colomar.es/>
#5 lore raw

Re: [PATCH 2/2] userfaultfd.2: Update on write-protection support

In reply to Peter Xu

Hi Peter,

Quoted 4 lines · Peter Xu

The shmem/hugetlbfs memory types are supported for write-protection messages very lately. Update the man page to reflect that.

Please see some source formatting comments below.

Cheers,

Alex

Quoted 12 lines
---
  man2/userfaultfd.2 | 8 +++++---
  1 file changed, 5 insertions(+), 3 deletions(-)
man2/userfaultfd.2 +0 -0
index 0928a76d2..99aae8b50 100644
@@ -273,13 +273,17 @@ Since Linux 4.11,
  userfaultfd can be also used with hugetlbfs and shared memory mappings.
  .\"
  .SS Userfaultfd write-protect mode (since 5.7)

man2/userfaultfd.2 Since Linux 4.11, · line 284

Quoted 10 lines
man2/userfaultfd.2 +3 -1
-Since Linux 5.7, userfaultfd supports write-protect mode.
+Since Linux 5.7, userfaultfd supports write-protect mode for anonymous memory.
  The user needs to first check availability of this feature using
  .B UFFDIO_API
  ioctl against the feature bit
  .B UFFD_FEATURE_PAGEFAULT_FLAG_WP
  before using this feature.
  .PP
+Since Linux 5.19, the write-protection mode was also supported on shmem and hugetlbfs
+memory types. It can be detected with the feature bit

See man-pages(7):

[
Use semantic newlines
In the source of a manual page, new sentences should be started on new lines, and long sentences should be split into lines at clause breaks (commas, semicolons, colons, and so on). This convention, sometimes known as "seman‐ tic newlines", makes it easier to see the effect of patches, which often operate at the level of individual sentences or sentence clauses.
]

Quoted 14 lines
man2/userfaultfd.2 +2 -2
+.BR UFFD_FEATURE_WP_HUGETLBFS_SHMEM .
+.PP
  To register with userfaultfd write-protect mode, the user needs to initiate the
  .B UFFDIO_REGISTER
  ioctl with mode
@@ -330,8 +334,6 @@ ioctl, whose
  should have the flag
  .B UFFDIO_WRITEPROTECT_MODE_WP
  cleared upon the faulted page or range.
-.PP
-Write-protect mode supports only private anonymous memory.
  .SS Reading from the userfaultfd structure
  Each
  .BR read (2)
Signature · 2 lines
Alejandro Colomar
<http://www.alejandro-colomar.es/>
author
#3 lore raw

Re: [PATCH 1/2] userfaultfd.2: Add section for UFFD_USER_MODE_ONLY

In reply to Alejandro Colomar
Quoted 60 lines · Alejandro Colomar

Hi Peter,

Quoted 4 lines · Peter Xu

Add a paragraph for UFFD_USER_MODE_ONLY flag that was introduced in Linux 5.11.

See some minor comments below.

Cheers,

Alex

Quoted 21 lines
---
  man2/userfaultfd.2 | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)
man2/userfaultfd.2 +3 -2
index cee7c01d2..0928a76d2 100644
@@ -29,8 +29,9 @@
  userfaultfd \- create a file descriptor for handling page faults in user space
  .SH SYNOPSIS
  .nf
-.BR "#include <fcntl.h>" "            /* Definition of " O_* " constants */"
-.BR "#include <sys/syscall.h>" "      /* Definition of " SYS_* " constants */"
+.BR "#include <fcntl.h>" "             /* Definition of " O_* " constants */"
+.BR "#include <sys/syscall.h>" "       /* Definition of " SYS_* " constants */"
+.BR "#include <linux/userfaultfd.h>" " /* Definition of " UFFD_* " constants */"
  .B #include <unistd.h>
  .PP
  .BI "int syscall(SYS_userfaultfd, int " flags );

man2/userfaultfd.2 See the description of the · line 81

Quoted 5 lines
man2/userfaultfd.2 +2 -0
@@ -76,6 +77,15 @@ See the description of the
  .BR O_NONBLOCK
  flag in
  .BR open (2).
+.TP
+.BR UFFD_USER_MODE_ONLY

s/BR/B/

see groff_man(7):

[
[...]

.B [text]
Set text in bold. If the macro is given no argu‐ ments, the text of the next input line is set in bold.

[...]

.BR bold‐text roman‐text ...
Set each argument in bold and roman, alternately.
]

Quoted 8 lines

man2/userfaultfd.2 See the description of the · line 87

Quoted 6 lines
man2/userfaultfd.2 +6 -0
+This is an userfaultfd specific flag that was introduced since Linux 5.11.
+When set, the userfaultfd object will only be able to handle page faults
+originated from the userspace on the registered regions.
+When a kernel originated fault was triggered on the registered range with
+this userfaultfd, a
+.BR SIGBUS

s/BR/B/

Thanks Alex, I'll fix and repost the patchset soon.

Signature · 1 line
Peter Xu