userfaultfd man page updates
v2 cover userfaultfd man page updates
This series includes only the remaining patches not applied from v1, with review comments addressed. This series is based on the "contrib" branch.
Changelog:
v1->v2:
- In patch 1 (patch 5 in v1), change "after" to "since" for consistency and to be clear that we mean 4.11+ (inclusive).
- In patch 2 (patch 7 in v1), reorder error codes alphabetically (EINVAL then EPERM).
- In patch 3 (patch 8 in v1), resolve conflicts with earlier review comments.
Original cover letter:
Various updates for userfaultfd man pages. To summarize the changes:
- Correctly / fully describe the two-step feature support handshake process.
- Describe new UFFDIO_POISON ioctl.
- Other small improvements (missing ioctls, error codes, etc).
Axel Rasmussen (5):
ioctl_userfaultfd.2: describe two-step feature handshake ioctl_userfaultfd.2: correct and update UFFDIO_API ioctl error codes ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on
error
ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list ioctl_userfaultfd.2: document new UFFDIO_POISON ioctl
man2/ioctl_userfaultfd.2 | 226 +++++++++++++++++++++++++++++++-------- 1 file changed, 181 insertions(+), 45 deletions(-)
--
2.42.0.609.gbb76f46606-goog
PATCH v2 1/5 ioctl_userfaultfd.2: describe two-step feature handshake
Fully describe how UFFDIO_API can be used to perform a two-step feature handshake, and also note the case where this isn't necessary (programs which don't depend on any extra features).
This lets us clean up an old FIXME asking for this to be described.
--- man2/ioctl_userfaultfd.2 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
man2/ioctl_userfaultfd.2 +21 -16
@@ -82,7 +82,6 @@ struct uffdio_api { The .I api field denotes the API version requested by the application. -.PP The kernel verifies that it can support the requested API version, and sets the .I features
@@ -92,6 +91,25 @@ fields to bit masks representing all the available features and the generic .BR ioctl (2) operations available. .PP +Since Linux 4.11, +applications should use the +.I features +field to perform a two-step handshake. +First, +.BR UFFDIO_API +is called with the +.I features +field set to zero. +The kernel responsds by setting all supported feature bits. +.PP +Applications which do not require any specific features +can begin using the userfaultfd immediately. +Applications which do need specific features +should call +.BR UFFDIO_API +again with a subset of the reported feature bits set +to enable those features. +.PP Before Linux 4.11, the .I features field must be initialized to zero before the call to
@@ -101,24 +119,11 @@ and zero (i.e., no feature bits) is placed in the field by the kernel upon return from .BR ioctl (2). .PP -Starting from Linux 4.11, the -.I features -field can be used to ask whether particular features are supported -and explicitly enable userfaultfd features that are disabled by default. -The kernel always reports all the available features in the -.I features -field. -.PP -To enable userfaultfd features the application should set -a bit corresponding to each feature it wants to enable in the -.I features -field. -If the kernel supports all the requested features it will enable them. -Otherwise it will zero out the returned +If the application sets unsupported feature bits, +the kernel will zero out the returned .I uffdio_api structure and return .BR EINVAL . -.\" FIXME add more details about feature negotiation and enablement .PP The following feature bits may be set: .TP
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Alejandro Colomar
maintainerRe: [PATCH v2 1/5] ioctl_userfaultfd.2: describe two-step feature handshake
Quoted 7 lines · Axel Rasmussen
Fully describe how
UFFDIO_APIcan be used to perform a two-step feature handshake, and also note the case where this isn't necessary (programs which don't depend on any extra features).This lets us clean up an old FIXME asking for this to be described.
Signed-off-by Axel Rasmussen <[email protected]>
Patch applied.
Thanks,
Alex
Quoted 72 lines
--- man2/ioctl_userfaultfd.2 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)man2/ioctl_userfaultfd.2 +21
-16@@ -82,7 +82,6 @@ struct uffdio_api { The .I api field denotes the API version requested by the application. -.PP The kernel verifies that it can support the requested API version, and sets the .I features@@ -92,6 +91,25 @@ fields to bit masks representing all the available features and the generic .BR ioctl (2) operations available. .PP +Since Linux 4.11, +applications should use the +.I features +field to perform a two-step handshake. +First, +.BR UFFDIO_API +is called with the +.I features +field set to zero. +The kernel responsds by setting all supported feature bits. +.PP +Applications which do not require any specific features +can begin using the userfaultfd immediately. +Applications which do need specific features +should call +.BR UFFDIO_API +again with a subset of the reported feature bits set +to enable those features. +.PP Before Linux 4.11, the .I features field must be initialized to zero before the call to@@ -101,24 +119,11 @@ and zero (i.e., no feature bits) is placed in the field by the kernel upon return from .BR ioctl (2). .PP -Starting from Linux 4.11, the -.I features -field can be used to ask whether particular features are supported -and explicitly enable userfaultfd features that are disabled by default. -The kernel always reports all the available features in the -.I features -field. -.PP -To enable userfaultfd features the application should set -a bit corresponding to each feature it wants to enable in the -.I features -field. -If the kernel supports all the requested features it will enable them. -Otherwise it will zero out the returned +If the application sets unsupported feature bits, +the kernel will zero out the returned .I uffdio_api structure and return .BR EINVAL . -.\" FIXME add more details about feature negotiation and enablement .PP The following feature bits may be set: .TPSignature · 1 line
2.42.0.609.gbb76f46606-goog
Signature · 1 line
<https://www.alejandro-colomar.es/>
PATCH v2 2/5 ioctl_userfaultfd.2: correct and update UFFDIO_API ioctl error codes
In reply to Axel RasmussenFirst, it is not correct that repeated UFFDIO_API calls result in EINVAL. This is true *if both calls enable features*, but in the case where we're doing a two-step feature detection handshake, the kernel explicitly expects 2 calls (one with no features set). So, correct this description.
Then, some new error cases have been added to the kernel recently, and the man page wasn't updated to note these. So, add in descriptions of these new error cases.
--- man2/ioctl_userfaultfd.2 | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)
man2/ioctl_userfaultfd.2 +19 -5
@@ -256,17 +256,31 @@ refers to an address that is outside the calling process's accessible address space. .TP .B EINVAL -The userfaultfd has already been enabled by a previous -.B UFFDIO_API -operation. -.TP -.B EINVAL The API version requested in the .I api field is not supported by this kernel, or the .I features field passed to the kernel includes feature bits that are not supported by the current kernel version. +.TP +.B EINVAL +A previous +.B UFFDIO_API +call already enabled one or more features for this userfaultfd. +Calling +.B UFFDIO_API +twice, +the first time with no features set, +is explicitly allowed +as per the two-step feature detection handshake. +.TP +.B EPERM +The +.B UFFD_FEATURE_EVENT_FORK +feature was enabled, +but the calling process doesn't have the +.B CAP_SYS_PTRACE +capability. .\" FIXME In the above error case, the returned 'uffdio_api' structure is .\" zeroed out. Why is this done? This should be explained in the manual page. .\"
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Alejandro Colomar
maintainerRe: [PATCH v2 2/5] ioctl_userfaultfd.2: correct and update UFFDIO_API ioctl error codes
Hi Axel,
Quoted 11 lines · Axel Rasmussen
First, it is not correct that repeated
UFFDIO_APIcalls result in EINVAL. This is true *if both calls enable features*, but in the case where we're doing a two-step feature detection handshake, the kernel explicitly expects 2 calls (one with no features set). So, correct this description.Then, some new error cases have been added to the kernel recently, and the man page wasn't updated to note these. So, add in descriptions of these new error cases.
Signed-off-by Axel Rasmussen <[email protected]>
Patch applied.
Thanks,
Alex
Quoted 48 lines
--- man2/ioctl_userfaultfd.2 | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-)man2/ioctl_userfaultfd.2 +19
-5@@ -256,17 +256,31 @@ refers to an address that is outside the calling process's accessible address space. .TP .B EINVAL -The userfaultfd has already been enabled by a previous -.B UFFDIO_API -operation. -.TP -.B EINVAL The API version requested in the .I api field is not supported by this kernel, or the .I features field passed to the kernel includes feature bits that are not supported by the current kernel version. +.TP +.B EINVAL +A previous +.B UFFDIO_API +call already enabled one or more features for this userfaultfd. +Calling +.B UFFDIO_API +twice, +the first time with no features set, +is explicitly allowed +as per the two-step feature detection handshake. +.TP +.B EPERM +The +.B UFFD_FEATURE_EVENT_FORK +feature was enabled, +but the calling process doesn't have the +.B CAP_SYS_PTRACE +capability. .\" FIXME In the above error case, the returned 'uffdio_api' structure is .\" zeroed out. Why is this done? This should be explained in the manual page. .\"Signature · 1 line
2.42.0.609.gbb76f46606-goog
Signature · 1 line
<https://www.alejandro-colomar.es/>
PATCH v2 3/5 ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error
In reply to Axel RasmussenThe old FIXME noted that the zeroing was done to differentiate the two EINVAL cases. It's possible something like this was true historically, but in current Linux we zero it in *both* EINVAL cases, so this is at least no longer true.
After reading the code, I can't determine any clear reason why we zero it in some cases but not in others. So, some simple advice we can give userspace is: if an error occurs, treat the contents of the structure as unspecified. Just re-initialize it before retrying UFFDIO_API again.
--- man2/ioctl_userfaultfd.2 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
man2/ioctl_userfaultfd.2 +8 -8
@@ -248,6 +248,14 @@ operation returns 0 on success. On error, \-1 is returned and .I errno is set to indicate the error. +If an error occurs, +the kernel may zero the provided +.I uffdio_api +structure. +The caller should treat its contents as unspecified, +and reinitialize it before re-attempting another +.B UFFDIO_API +call. Possible errors include: .TP .B EFAULT
@@ -281,14 +289,6 @@ feature was enabled, but the calling process doesn't have the .B CAP_SYS_PTRACE capability. -.\" FIXME In the above error case, the returned 'uffdio_api' structure is -.\" zeroed out. Why is this done? This should be explained in the manual page. -.\" -.\" Mike Rapoport: -.\" In my understanding the uffdio_api -.\" structure is zeroed to allow the caller -.\" to distinguish the reasons for -EINVAL. -.\" .SS UFFDIO_REGISTER (Since Linux 4.3.) Register a memory address range with the userfaultfd object.
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Alejandro Colomar
maintainerRe: [PATCH v2 3/5] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error
Hi Axel,
Quoted 36 lines · Axel Rasmussen
The old FIXME noted that the zeroing was done to differentiate the two EINVAL cases. It's possible something like this was true historically, but in current Linux we zero it in *both* EINVAL cases, so this is at least no longer true.
After reading the code, I can't determine any clear reason why we zero it in some cases but not in others. So, some simple advice we can give userspace is: if an error occurs, treat the contents of the structure as unspecified. Just re-initialize it before retrying
UFFDIO_APIagain.Signed-off-by Axel Rasmussen <[email protected]>--- man2/ioctl_userfaultfd.2 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)man2/ioctl_userfaultfd.2 +8
-0@@ -248,6 +248,14 @@ operation returns 0 on success. On error, \-1 is returned and .I errno is set to indicate the error. +If an error occurs, +the kernel may zero the provided +.I uffdio_api +structure. +The caller should treat its contents as unspecified, +and reinitialize it before re-attempting another +.B UFFDIO_API +call. Possible errors include: .TP .B EFAULT@@ -281,14 +289,6 @@ feature was enabled, but the calling process doesn't have the
man2/ioctl_userfaultfd.2 feature was enabled, · line 291
Quoted 10 lines
man2/ioctl_userfaultfd.2 +0
-8.B CAP_SYS_PTRACE capability. -.\" FIXME In the above error case, the returned 'uffdio_api' structure is -.\" zeroed out. Why is this done? This should be explained in the manual page. -.\" -.\" Mike Rapoport: -.\" In my understanding the uffdio_api -.\" structure is zeroed to allow the caller -.\" to distinguish the reasons for -EINVAL. -.\"
I've added Mike to the thread in case he wants to comment.
Thanks,
Alex
Quoted 6 lines
man2/ioctl_userfaultfd.2 +0
-0.SS UFFDIO_REGISTER (Since Linux 4.3.) Register a memory address range with the userfaultfd object.Signature · 1 line
2.42.0.609.gbb76f46606-goog
Signature · 1 line
<https://www.alejandro-colomar.es/>
Re: [PATCH v2 3/5] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error
Quoted 43 lines · Alejandro Colomar
Hi Axel,
Quoted 40 lines · Axel Rasmussen
The old FIXME noted that the zeroing was done to differentiate the two EINVAL cases. It's possible something like this was true historically, but in current Linux we zero it in *both* EINVAL cases, so this is at least no longer true.
After reading the code, I can't determine any clear reason why we zero it in some cases but not in others. So, some simple advice we can give userspace is: if an error occurs, treat the contents of the structure as unspecified. Just re-initialize it before retrying
UFFDIO_APIagain.Signed-off-by Axel Rasmussen <[email protected]>--- man2/ioctl_userfaultfd.2 | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)man2/ioctl_userfaultfd.2 +8
-2@@ -248,6 +248,14 @@ operation returns 0 on success. On error, \-1 is returned and .I errno is set to indicate the error. +If an error occurs, +the kernel may zero the provided +.I uffdio_api +structure. +The caller should treat its contents as unspecified, +and reinitialize it before re-attempting another +.B UFFDIO_API +call. Possible errors include: .TP .B EFAULT@@ -281,14 +289,6 @@ feature was enabled, but the calling process doesn't have the .B CAP_SYS_PTRACE capability. -.\" FIXME In the above error case, the returned 'uffdio_api' structure is -.\" zeroed out. Why is this done? This should be explained in the manual page.
Quoted 8 lines
man2/ioctl_userfaultfd.2 feature was enabled, · line 291
Quoted 6 lines
man2/ioctl_userfaultfd.2 +0
-6-.\" -.\" Mike Rapoport: -.\" In my understanding the uffdio_api -.\" structure is zeroed to allow the caller -.\" to distinguish the reasons for -EINVAL. -.\"I've added Mike to the thread in case he wants to comment.
Thanks, Alex!
It looks like I reviewed v1 of the patchset though :)
Quoted 12 lines
Thanks,
AlexQuoted 6 lines
man2/ioctl_userfaultfd.2 +0
-0.SS UFFDIO_REGISTER (Since Linux 4.3.) Register a memory address range with the userfaultfd object.Signature · 1 line
2.42.0.609.gbb76f46606-googSignature · 1 line
<https://www.alejandro-colomar.es/>
Signature · 2 lines
Sincerely yours, Mike.
PATCH v2 4/5 ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list
In reply to Axel RasmussenThe list of error codes in the man page was out of date with respect to the current state of the kernel. Some errors were partially / incorrectly described.
Update the error code listing, so it matches the current state of the kernel, and correctly describes all the errors.
--- man2/ioctl_userfaultfd.2 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
man2/ioctl_userfaultfd.2 +21 -16
@@ -388,12 +388,6 @@ On error, \-1 is returned and .I errno is set to indicate the error. Possible errors include: -.\" FIXME Is the following error list correct? -.\" -.TP -.B EBUSY -A mapping in the specified range is registered with another -userfaultfd object. .TP .B EFAULT .I argp
@@ -408,21 +402,32 @@ field; or the field was zero. .TP .B EINVAL -There is no mapping in the specified address range. -.TP -.B EINVAL +The specified address range was invalid. +More specifically, +no mapping exists in the given range, +or the mapping that exists there is invalid +(e.g. unsupported type of memory), +or the range values ( .I range.start or .I range.len -is not a multiple of the system page size; or, +) are not multiples of the relevant page size, +or .I range.len -is zero; or these fields are otherwise invalid. +is zero. .TP -.B EINVAL -There as an incompatible mapping in the specified address range. -.\" Mike Rapoport: -.\" ENOMEM if the process is exiting and the -.\" mm_struct has gone by the time userfault grabs it. +.B ENOMEM +The process is exiting, +and its address space has already been torn down +when userfaultfd attempts to reference it. +.TP +.B EPERM +The userfaultfd would allow writing to a file backing the mapping, +but the calling process lacks such write permissions. +.TP +.B EBUSY +A mapping in the specified range is registered with another +userfaultfd object. .SS UFFDIO_UNREGISTER (Since Linux 4.3.) Unregister a memory address range from userfaultfd.
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Alejandro Colomar
maintainerRe: [PATCH v2 4/5] ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list
Hi Axel,
Quoted 32 lines · Axel Rasmussen
The list of error codes in the man page was out of date with respect to the current state of the kernel. Some errors were partially / incorrectly described.
Update the error code listing, so it matches the current state of the kernel, and correctly describes all the errors.
Signed-off-by Axel Rasmussen <[email protected]>--- man2/ioctl_userfaultfd.2 | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)man2/ioctl_userfaultfd.2 +0
-6@@ -388,12 +388,6 @@ On error, \-1 is returned and .I errno is set to indicate the error. Possible errors include: -.\" FIXME Is the following error list correct? -.\" -.TP -.B EBUSY -A mapping in the specified range is registered with another -userfaultfd object. .TP .B EFAULT .I argp@@ -408,21 +402,32 @@ field; or the field was zero. .TP
man2/ioctl_userfaultfd.2 field; or the · line 410
Quoted 10 lines
man2/ioctl_userfaultfd.2 +6
-3.B EINVAL -There is no mapping in the specified address range. -.TP -.B EINVAL +The specified address range was invalid. +More specifically, +no mapping exists in the given range, +or the mapping that exists there is invalid +(e.g. unsupported type of memory), +or the range values (
This produces some unwanted space. Please apply the following fix to your patch.
man2/ioctl_userfaultfd.2 +4 -4
@@ -432,11 +432,11 @@ .SS UFFDIO_REGISTER no mapping exists in the given range, or the mapping that exists there is invalid (e.g. unsupported type of memory), -or the range values ( -.I range.start +or the range values +.IR ( range.start or -.I range.len -) are not multiples of the relevant page size, +.IR range.len ) +are not multiples of the relevant page size, or .I range.len is zero.
Quoted 17 lines
man2/ioctl_userfaultfd.2 +5
-7.I range.start or .I range.len -is not a multiple of the system page size; or, +) are not multiples of the relevant page size, +or .I range.len -is zero; or these fields are otherwise invalid. +is zero. .TP -.B EINVAL -There as an incompatible mapping in the specified address range. -.\" Mike Rapoport: -.\" ENOMEM if the process is exiting and the -.\" mm_struct has gone by the time userfault grabs it. +.B ENOMEM +The process is exiting,
man2/ioctl_userfaultfd.2 field; or the · line 430
Quoted 10 lines
man2/ioctl_userfaultfd.2 +10
-0+and its address space has already been torn down +when userfaultfd attempts to reference it. +.TP +.B EPERM +The userfaultfd would allow writing to a file backing the mapping, +but the calling process lacks such write permissions. +.TP +.B EBUSY +A mapping in the specified range is registered with another +userfaultfd object.
Why would you move EBUSY to the end? Do you see any reasons to order it that way?
Thanks,
Alex
Quoted 6 lines
man2/ioctl_userfaultfd.2 +0
-0.SS UFFDIO_UNREGISTER (Since Linux 4.3.) Unregister a memory address range from userfaultfd.Signature · 1 line
2.42.0.609.gbb76f46606-goog
Signature · 1 line
<https://www.alejandro-colomar.es/>
Re: [PATCH v2 4/5] ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list
Hi!
Quoted 8 lines · Alejandro Colomar
This produces some unwanted space. Please apply the following fix to your patch.
man2/ioctl_userfaultfd.2 +0
-0
man2/ioctl_userfaultfd.2 .SS UFFDIO_REGISTER · line 436
Quoted 7 lines
man2/ioctl_userfaultfd.2 +2
-2@@ -432,11 +432,11 @@ .SS UFFDIO_REGISTER no mapping exists in the given range, or the mapping that exists there is invalid (e.g. unsupported type of memory), -or the range values ( -.I range.start +or the range values +.IR ( range.start
I think you meant «.RI» here?
man2/ioctl_userfaultfd.2 .SS UFFDIO_REGISTER · line 442
Quoted 9 lines
man2/ioctl_userfaultfd.2 +2
-2or -.I range.len -) are not multiples of the relevant page size, +.IR range.len ) +are not multiples of the relevant page size, or .I range.len is zero.
Regards,
Guillem
Alejandro Colomar
maintainerRe: [PATCH v2 4/5] ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list
Hi Guillem!
Quoted 6 lines · Guillem Jover
Hi!
Quoted 3 lines · Alejandro Colomar
This produces some unwanted space. Please apply the following fix to your patch.
Quoted 14 lines
man2/ioctl_userfaultfd.2 .SS UFFDIO_REGISTER · line 436
Quoted 12 lines
man2/ioctl_userfaultfd.2 +2
-2@@ -432,11 +432,11 @@ .SS UFFDIO_REGISTER no mapping exists in the given range, or the mapping that exists there is invalid (e.g. unsupported type of memory), -or the range values ( -.I range.start +or the range values +.IR ( range.startI think you meant «.RI» here?
Yup! Good catch.
Cheers,
Alex
Quoted 13 lines
man2/ioctl_userfaultfd.2 .SS UFFDIO_REGISTER · line 442
Quoted 10 lines
man2/ioctl_userfaultfd.2 +2
-2or -.I range.len -) are not multiples of the relevant page size, +.IR range.len ) +are not multiples of the relevant page size, or .I range.len is zero.Regards,
Guillem
Signature · 1 line
<https://www.alejandro-colomar.es/>
Re: [PATCH v2 4/5] ioctl_userfaultfd.2: fix / update UFFDIO_REGISTER error code list
Quoted 25 lines · Alejandro Colomar
Hi Guillem!
Quoted 6 lines · Guillem Jover
Hi!
Quoted 3 lines · Alejandro Colomar
This produces some unwanted space. Please apply the following fix to your patch.
Quoted 14 lines
man2/ioctl_userfaultfd.2 .SS UFFDIO_REGISTER · line 436
Quoted 12 lines
man2/ioctl_userfaultfd.2 +2
-2@@ -432,11 +432,11 @@ .SS UFFDIO_REGISTER no mapping exists in the given range, or the mapping that exists there is invalid (e.g. unsupported type of memory), -or the range values ( -.I range.start +or the range values +.IR ( range.startI think you meant «.RI» here?
Quoted 1 line
Yup! Good catch.
Thanks, I'll apply this change in a v3.
Quoted 17 lines
Cheers,
AlexQuoted 13 lines
man2/ioctl_userfaultfd.2 .SS UFFDIO_REGISTER · line 442
Quoted 10 lines
man2/ioctl_userfaultfd.2 +2
-2or -.I range.len -) are not multiples of the relevant page size, +.IR range.len ) +are not multiples of the relevant page size, or .I range.len is zero.Regards,
Guillem
Regarding the -EBUSY ordering, I did it this way because that's the order in which the conditions are checked in the code. But, I agree that isn't very obvious / useful to any reader of the man page :) and alphabetical order is preferred. I'll correct that in v3.
Quoted 3 lines
PATCH v2 5/5 ioctl_userfaultfd.2: document new UFFDIO_POISON ioctl
In reply to Axel RasmussenThis is a new feature recently added to the kernel. So, document the new ioctl the same way we do other UFFDIO_* ioctls.
Also note the corresponding new ioctl flag we can return in reponse to a UFFDIO_REGISTER call.
--- man2/ioctl_userfaultfd.2 | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
man2/ioctl_userfaultfd.2 +112 -0
@@ -380,6 +380,11 @@ operation is supported. The .B UFFDIO_CONTINUE operation is supported. +.TP +.B 1 << _UFFDIO_POISON +The +.B UFFDIO_POISON +operation is supported. .PP This .BR ioctl (2)
@@ -890,6 +895,113 @@ The faulting process has exited at the time of a .B UFFDIO_CONTINUE operation. .\" +.SS UFFDIO_POISON +(Since Linux 6.6.) +Mark an address range as "poisoned". +Future accesses to these addresses will raise a +.B SIGBUS +signal. +Unlike +.B MADV_HWPOISON +this works by installing page table entries, +rather than "really" poisoning the underlying physical pages. +This means it only affects this particular address space. +.PP +The +.I argp +argument is a pointer to a +.I uffdio_continue +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_poison { + struct uffdio_range range; + /* Range to install poison PTE markers in */ + __u64 mode; /* Flags controlling the behavior of poison */ + __s64 updated; /* Number of bytes poisoned, or negated error */ +}; +.EE +.in +.PP +The following value may be bitwise ORed in +.I mode +to change the behavior of the +.B UFFDIO_POISON +operation: +.TP +.B UFFDIO_POISON_MODE_DONTWAKE +Do not wake up the thread that waits for page-fault resolution. +.PP +The +.I updated +field is used by the kernel +to return the number of bytes that were actually poisoned, +or an error in the same manner as +.BR UFFDIO_COPY . +If the value returned in the +.I updated +field doesn't match the value that was specified in +.IR range.len , +the operation fails with the error +.BR EAGAIN . +The +.I updated +field is output-only; +it is not read by the +.B UFFDIO_POISON +operation. +.PP +This +.BR ioctl (2) +operation returns 0 on success. +In this case, +the entire area was poisoned. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EAGAIN +The number of bytes mapped +(i.e., the value returned in the +.I updated +field) +does not equal the value that was specified in the +.I range.len +field. +.TP +.B EINVAL +Either +.I range.start +or +.I range.len +was not a multiple of the system page size; or +.I range.len +was zero; or the range specified was invalid. +.TP +.B EINVAL +An invalid bit was specified in the +.I mode +field. +.TP +.B EEXIST +One or more pages were already mapped in the given range. +.TP +.B ENOENT +The faulting process has changed its virtual memory layout simultaneously with +an outstanding +.B UFFDIO_POISON +operation. +.TP +.B ENOMEM +Allocating memory for page table entries failed. +.TP +.B ESRCH +The faulting process has exited at the time of a +.B UFFDIO_POISON +operation. +.\" .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORS
Signature · 1 line
2.42.0.609.gbb76f46606-goog
Alejandro Colomar
maintainerRe: [PATCH v2 5/5] ioctl_userfaultfd.2: document new UFFDIO_POISON ioctl
Hi Axel,
Quoted 112 lines · Axel Rasmussen
This is a new feature recently added to the kernel. So, document the new ioctl the same way we do other UFFDIO_* ioctls.
Also note the corresponding new ioctl flag we can return in reponse to a
UFFDIO_REGISTERcall.Signed-off-by Axel Rasmussen <[email protected]>--- man2/ioctl_userfaultfd.2 | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)man2/ioctl_userfaultfd.2 +86
-0@@ -380,6 +380,11 @@ operation is supported. The .B UFFDIO_CONTINUE operation is supported. +.TP +.B 1 << _UFFDIO_POISON +The +.B UFFDIO_POISON +operation is supported. .PP This .BR ioctl (2)@@ -890,6 +895,113 @@ The faulting process has exited at the time of a .B UFFDIO_CONTINUE operation. .\" +.SS UFFDIO_POISON +(Since Linux 6.6.) +Mark an address range as "poisoned". +Future accesses to these addresses will raise a +.B SIGBUS +signal. +Unlike +.B MADV_HWPOISON +this works by installing page table entries, +rather than "really" poisoning the underlying physical pages. +This means it only affects this particular address space. +.PP +The +.I argp +argument is a pointer to a +.I uffdio_continue +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_poison { + struct uffdio_range range; + /* Range to install poison PTE markers in */ + __u64 mode; /* Flags controlling the behavior of poison */ + __s64 updated; /* Number of bytes poisoned, or negated error */ +}; +.EE +.in +.PP +The following value may be bitwise ORed in +.I mode +to change the behavior of the +.B UFFDIO_POISON +operation: +.TP +.B UFFDIO_POISON_MODE_DONTWAKE +Do not wake up the thread that waits for page-fault resolution. +.PP +The +.I updated +field is used by the kernel +to return the number of bytes that were actually poisoned, +or an error in the same manner as +.BR UFFDIO_COPY . +If the value returned in the +.I updated +field doesn't match the value that was specified in +.IR range.len , +the operation fails with the error +.BR EAGAIN . +The +.I updated +field is output-only; +it is not read by the +.B UFFDIO_POISON +operation. +.PP +This +.BR ioctl (2) +operation returns 0 on success. +In this case, +the entire area was poisoned. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EAGAIN +The number of bytes mapped +(i.e., the value returned in the +.I updated +field) +does not equal the value that was specified in the +.I range.len +field. +.TP +.B EINVAL +Either +.I range.start +or +.I range.len
man2/ioctl_userfaultfd.2 The faulting process has exited at the time of a · line 988
Quoted 10 lines
man2/ioctl_userfaultfd.2 +10
-0+was not a multiple of the system page size; or +.I range.len +was zero; or the range specified was invalid. +.TP +.B EINVAL +An invalid bit was specified in the +.I mode +field. +.TP +.B EEXIST
Any reasons for this order, or should we use alphabetic order?
Thanks,
Alex
Quoted 22 lines
man2/ioctl_userfaultfd.2 +16
-0+One or more pages were already mapped in the given range. +.TP +.B ENOENT +The faulting process has changed its virtual memory layout simultaneously with +an outstanding +.B UFFDIO_POISON +operation. +.TP +.B ENOMEM +Allocating memory for page table entries failed. +.TP +.B ESRCH +The faulting process has exited at the time of a +.B UFFDIO_POISON +operation. +.\" .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORSSignature · 1 line
2.42.0.609.gbb76f46606-goog
Signature · 1 line
<https://www.alejandro-colomar.es/>
Re: [PATCH v2 5/5] ioctl_userfaultfd.2: document new UFFDIO_POISON ioctl
Quoted 120 lines · Alejandro Colomar
Hi Axel,
Quoted 116 lines · Axel Rasmussen
This is a new feature recently added to the kernel. So, document the new ioctl the same way we do other UFFDIO_* ioctls.
Also note the corresponding new ioctl flag we can return in reponse to a
UFFDIO_REGISTERcall.Signed-off-by Axel Rasmussen <[email protected]>--- man2/ioctl_userfaultfd.2 | 112 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)man2/ioctl_userfaultfd.2 +90
-0@@ -380,6 +380,11 @@ operation is supported. The .B UFFDIO_CONTINUE operation is supported. +.TP +.B 1 << _UFFDIO_POISON +The +.B UFFDIO_POISON +operation is supported. .PP This .BR ioctl (2)@@ -890,6 +895,113 @@ The faulting process has exited at the time of a .B UFFDIO_CONTINUE operation. .\" +.SS UFFDIO_POISON +(Since Linux 6.6.) +Mark an address range as "poisoned". +Future accesses to these addresses will raise a +.B SIGBUS +signal. +Unlike +.B MADV_HWPOISON +this works by installing page table entries, +rather than "really" poisoning the underlying physical pages. +This means it only affects this particular address space. +.PP +The +.I argp +argument is a pointer to a +.I uffdio_continue +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_poison { + struct uffdio_range range; + /* Range to install poison PTE markers in */ + __u64 mode; /* Flags controlling the behavior of poison */ + __s64 updated; /* Number of bytes poisoned, or negated error */ +}; +.EE +.in +.PP +The following value may be bitwise ORed in +.I mode +to change the behavior of the +.B UFFDIO_POISON +operation: +.TP +.B UFFDIO_POISON_MODE_DONTWAKE +Do not wake up the thread that waits for page-fault resolution. +.PP +The +.I updated +field is used by the kernel +to return the number of bytes that were actually poisoned, +or an error in the same manner as +.BR UFFDIO_COPY . +If the value returned in the +.I updated +field doesn't match the value that was specified in +.IR range.len , +the operation fails with the error +.BR EAGAIN . +The +.I updated +field is output-only; +it is not read by the +.B UFFDIO_POISON +operation. +.PP +This +.BR ioctl (2) +operation returns 0 on success. +In this case, +the entire area was poisoned. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EAGAIN +The number of bytes mapped +(i.e., the value returned in the +.I updated +field) +does not equal the value that was specified in the +.I range.len +field. +.TP +.B EINVAL +Either +.I range.start +or +.I range.len +was not a multiple of the system page size; or +.I range.len +was zero; or the range specified was invalid. +.TP
Quoted 8 lines
man2/ioctl_userfaultfd.2 The faulting process has exited at the time of a · line 988
Quoted 6 lines
man2/ioctl_userfaultfd.2 +6
-0+.B EINVAL +An invalid bit was specified in the +.I mode +field. +.TP +.B EEXISTAny reasons for this order, or should we use alphabetic order?
This is the order the conditions are checked in code, but I agree alphabetic order is better. :) I'll send a v3.
Quoted 29 lines
Thanks,
AlexQuoted 20 lines
man2/ioctl_userfaultfd.2 +16
-1+One or more pages were already mapped in the given range. +.TP +.B ENOENT +The faulting process has changed its virtual memory layout simultaneously with +an outstanding +.B UFFDIO_POISON +operation. +.TP +.B ENOMEM +Allocating memory for page table entries failed. +.TP +.B ESRCH +The faulting process has exited at the time of a +.B UFFDIO_POISON +operation. +.\" .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORS --Quoted 2 lines
2.42.0.609.gbb76f46606-goog
Alejandro Colomar
maintainerHi Axel,
Quoted 2 lines · Axel Rasmussen
This series includes only the remaining patches not applied from v1, with review comments addressed. This series is based on the "contrib" branch.
Thanks. For the next revision, I've moved the contrib branch to my personal repo, since it's more of a personal branch. You can find it here:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/log/?h=contrib>
Cheers,
Alex
Quoted 32 lines
Changelog:
v1->v2:
- In patch 1 (patch 5 in v1), change "after" to "since" for consistency and to be clear that we mean 4.11+ (inclusive).
- In patch 2 (patch 7 in v1), reorder error codes alphabetically (EINVAL then EPERM).
- In patch 3 (patch 8 in v1), resolve conflicts with earlier review comments.Original cover letter:
Various updates for userfaultfd man pages. To summarize the changes:
- Correctly / fully describe the two-step feature support handshake process.
- Describe newUFFDIO_POISONioctl.
- Other small improvements (missing ioctls, error codes, etc).Axel Rasmussen (5):
ioctl_userfaultfd.2: describe two-step feature handshake ioctl_userfaultfd.2: correct and updateUFFDIO_APIioctl error codes ioctl_userfaultfd.2: clarify the state of theuffdio_apistructure on
error
ioctl_userfaultfd.2: fix / updateUFFDIO_REGISTERerror code list ioctl_userfaultfd.2: document newUFFDIO_POISONioctlman2/ioctl_userfaultfd.2 | 226 +++++++++++++++++++++++++++++++-------- 1 file changed, 181 insertions(+), 45 deletions(-)--
2.42.0.609.gbb76f46606-goog
Signature · 1 line
<https://www.alejandro-colomar.es/>