Skip to contentSkip to conversation

ioctl_userfaultfd.2: add UFFD_FEATURE_EXACT_ADDRESS

PATCH In review Nadav Amit 3 participants 10 messages Mar 7, 2022 – Jun 2, 2023 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore

Nadav Amit

author
#0 lore raw

PATCH 1/2 ioctl_userfaultfd.2: add UFFD_FEATURE_EXACT_ADDRESS

From: Nadav Amit <[email protected]>

Describe the new UFFD_FEATURE_EXACT_ADDRESS API feature.

---
 man2/ioctl_userfaultfd.2 | 8 ++++++++
 1 file changed, 8 insertions(+)
man2/ioctl_userfaultfd.2 +8 -0
index 504f61d4b..94480158e 100644
@@ -214,6 +214,14 @@ memory accesses to the regions registered with userfaultfd.
 If this feature bit is set,
 .I uffd_msg.pagefault.feat.ptid
 will be set to the faulted thread ID for each page-fault message.
+.TP
+.BR UFFD_FEATURE_EXACT_ADDRESS " (since Linux 5.18)"
+If this feature bit is set,
+.I uffd_msg.pagefault.address
+will be set to the exact page-fault address that was reported by the hardware,
+and will not mask the offset within the page.
+Note that old Linux versions might indicate the exact address as well,
+even though the feature bit is not set.
 .PP
 The returned
 .I ioctls
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/2 userfaultfd.2: fix userfaultfd_demo output

From: Nadav Amit <[email protected]>

A bug in the kernel caused in recent version a different output (masked offset). Update the output of the demo program accordingly.

---
 man2/userfaultfd.2 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
man2/userfaultfd.2 +3 -3
index cee7c01d2..779ff8817 100644
@@ -648,7 +648,7 @@ Address returned by mmap() = 0x7fd30106c000
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106c00f in main(): A
 Read address 0x7fd30106c40f in main(): A
@@ -657,7 +657,7 @@ Read address 0x7fd30106cc0f in main(): A
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106d00f in main(): B
 Read address 0x7fd30106d40f in main(): B
@@ -666,7 +666,7 @@ Read address 0x7fd30106dc0f in main(): B
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106e00f in main(): C
 Read address 0x7fd30106e40f in main(): C
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 2/2] userfaultfd.2: fix userfaultfd_demo output

Hi Nadav,

Quoted 4 lines · Nadav Amit

From: Nadav Amit <[email protected]>

A bug in the kernel caused in recent version a different output (masked offset). Update the output of the demo program accordingly.

Please add to the commit message some info about the bug, especially some links to LKML discussions and the patch set that fixes it.

Thanks,

Alex

Quoted 37 lines
---
 man2/userfaultfd.2 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
man2/userfaultfd.2 +3 -3
index cee7c01d2..779ff8817 100644
@@ -648,7 +648,7 @@ Address returned by mmap() = 0x7fd30106c000
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106c00f in main(): A
 Read address 0x7fd30106c40f in main(): A
@@ -657,7 +657,7 @@ Read address 0x7fd30106cc0f in main(): A
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106d00f in main(): B
 Read address 0x7fd30106d40f in main(): B
@@ -666,7 +666,7 @@ Read address 0x7fd30106dc0f in main(): B
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106e00f in main(): C
 Read address 0x7fd30106e40f in main(): C
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#3 lore raw

Re: [PATCH 2/2] userfaultfd.2: fix userfaultfd_demo output

In reply to Nadav Amit

Hi Nadav,

Quoted 4 lines · Nadav Amit

From: Nadav Amit <[email protected]>

A bug in the kernel caused in recent version a different output (masked offset). Update the output of the demo program accordingly.

I'd like to have some more information about this in the commit message. I don't really understand it. When was the bug introduced? When was it fixed? Was the example in the page created in a buggy version?

Thanks,
Alex

Quoted 37 lines
---
 man2/userfaultfd.2 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
man2/userfaultfd.2 +3 -3
index cee7c01d2..779ff8817 100644
@@ -648,7 +648,7 @@ Address returned by mmap() = 0x7fd30106c000
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106c000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106c00f in main(): A
 Read address 0x7fd30106c40f in main(): A
@@ -657,7 +657,7 @@ Read address 0x7fd30106cc0f in main(): A
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106d000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106d00f in main(): B
 Read address 0x7fd30106d40f in main(): B
@@ -666,7 +666,7 @@ Read address 0x7fd30106dc0f in main(): B
 
 fault_handler_thread():
     poll() returns: nready = 1; POLLIN = 1; POLLERR = 0
-    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e00f
+    UFFD_EVENT_PAGEFAULT event: flags = 0; address = 7fd30106e000
         (uffdio_copy.copy returned 4096)
 Read address 0x7fd30106e00f in main(): C
 Read address 0x7fd30106e40f in main(): C
Signature · 2 lines
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
#4 lore raw

Re: [PATCH 2/2] userfaultfd.2: fix userfaultfd_demo output

Quoted 6 lines · Alejandro Colomar

Hi Nadav,

On 3/7/22 19:48, Nadav Amit wrote:

Quoted 8 lines
Quoted 4 lines

From: Nadav Amit <[email protected]>

A bug in the kernel caused in recent version a different output (masked offset). Update the output of the demo program accordingly.

I'd like to have some more information about this in the commit message. I don't really understand it. When was the bug introduced? When was it fixed? Was the example in the page created in a buggy version?

Hi Alex,

Sorry for the late response.

The bug was introduced in 1a29d85eb0f1 ("mm: use vmf->address instead of of vmf->virtual_address”) which is circa 2016. It was introduced shortly after userfaultfd, so it was determined that no users are likely to rely on the intended correct behavior that was documented in the man page, but there might be users who relied on the wrong behavior, which was in the code for several years.

More information is available in the patch of the fix:

https://lore.kernel.org/all/[email protected]/

Let me know if it answers you questions, and whether you want me to send an updated patch for the man page.

#5 lore raw

Re: [PATCH 2/2] userfaultfd.2: fix userfaultfd_demo output

Hi!

Quoted 26 lines · Nadav Amit
Quoted 6 lines · Alejandro Colomar

Hi Nadav,

On 3/7/22 19:48, Nadav Amit wrote:

Quoted 8 lines
Quoted 4 lines

From: Nadav Amit <[email protected]>

A bug in the kernel caused in recent version a different output (masked offset). Update the output of the demo program accordingly.

I'd like to have some more information about this in the commit message. I don't really understand it. When was the bug introduced? When was it fixed? Was the example in the page created in a buggy version?

Hi Alex,

Sorry for the late response.

The bug was introduced in 1a29d85eb0f1 ("mm: use vmf->address instead of of vmf->virtual_address”) which is circa 2016. It was introduced shortly after userfaultfd, so it was determined that no users are likely to rely on the intended correct behavior that was documented in the man page, but there might be users who relied on the wrong behavior, which was in the code for several years.

Quoted 6 lines

More information is available in the patch of the fix:

https://lore.kernel.org/all/[email protected]/

Let me know if it answers you questions, and whether you want me to send an updated patch for the man page.

Yes, please, a patch including all this response in the message would be useful.

Thanks!
Alex

Quoted 1 line
Signature · 2 lines
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
#6 lore raw
In reply to Nadav Amit

Hi Nadav,

Quoted 6 lines · Nadav Amit

From: Nadav Amit <[email protected]>

Describe the new UFFD_FEATURE_EXACT_ADDRESS API feature.

---

LGTM. Please ping when it's added to Linus's tree, and add a comment with the commit message that added it.

Thanks,

Alex

Quoted 22 lines
 man2/ioctl_userfaultfd.2 | 8 ++++++++
 1 file changed, 8 insertions(+)
man2/ioctl_userfaultfd.2 +8 -0
index 504f61d4b..94480158e 100644
@@ -214,6 +214,14 @@ memory accesses to the regions registered with userfaultfd.
 If this feature bit is set,
 .I uffd_msg.pagefault.feat.ptid
 will be set to the faulted thread ID for each page-fault message.
+.TP
+.BR UFFD_FEATURE_EXACT_ADDRESS " (since Linux 5.18)"
+If this feature bit is set,
+.I uffd_msg.pagefault.address
+will be set to the exact page-fault address that was reported by the hardware,
+and will not mask the offset within the page.
+Note that old Linux versions might indicate the exact address as well,
+even though the feature bit is not set.
 .PP
 The returned
 .I ioctls
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/
#7 lore raw

Hi Nadav,

Quoted 5 lines · Alejandro Colomar (man-pages)

Hi Nadav,

Quoted 2 lines · Nadav Amit

From: Nadav Amit <[email protected]>

Quoted 7 lines
Quoted 4 lines

Describe the new UFFD_FEATURE_EXACT_ADDRESS API feature.

---

LGTM. Please ping when it's added to Linus's tree, and add a comment with the commit message that added it.

I've checked that this was finally added to the kernel. Should I apply the patch as is, or is there anything that was changed?

Cheers,

Alex

Quoted 28 lines

Thanks,

Alex

Quoted 22 lines
 man2/ioctl_userfaultfd.2 | 8 ++++++++
 1 file changed, 8 insertions(+)
man2/ioctl_userfaultfd.2 +8 -0
index 504f61d4b..94480158e 100644
@@ -214,6 +214,14 @@ memory accesses to the regions registered with userfaultfd.
 If this feature bit is set,
 .I uffd_msg.pagefault.feat.ptid
 will be set to the faulted thread ID for each page-fault message.
+.TP
+.BR UFFD_FEATURE_EXACT_ADDRESS " (since Linux 5.18)"
+If this feature bit is set,
+.I uffd_msg.pagefault.address
+will be set to the exact page-fault address that was reported by the hardware,
+and will not mask the offset within the page.
+Note that old Linux versions might indicate the exact address as well,
+even though the feature bit is not set.
 .PP
 The returned
 .I ioctls
Signature · 2 lines
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5
#8 lore raw
Quoted 14 lines · Alejandro Colomar

Hi Nadav,

Quoted 7 lines · Alejandro Colomar (man-pages)

Hi Nadav,

Quoted 4 lines · Nadav Amit

From: Nadav Amit <[email protected]>

Describe the new UFFD_FEATURE_EXACT_ADDRESS API feature.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

---

LGTM. Please ping when it's added to Linus's tree, and add a comment with the commit message that added it.

I've checked that this was finally added to the kernel. Should I apply the patch as is, or is there anything that was changed?

Thanks for following up. Nothing to change, just apply it as is.

Regards,
Nadav

#9 lore raw

Hi Nadav,

Quoted 17 lines · Nadav Amit
Quoted 17 lines · Alejandro Colomar

Hi Nadav,

Quoted 10 lines · Alejandro Colomar (man-pages)

Hi Nadav,

Quoted 6 lines · Nadav Amit

From: Nadav Amit <[email protected]>

Describe the new UFFD_FEATURE_EXACT_ADDRESS API feature.

---

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

LGTM. Please ping when it's added to Linus's tree, and add a comment with the commit message that added it.

I've checked that this was finally added to the kernel. Should I apply the patch as is, or is there anything that was changed?

Thanks for following up. Nothing to change, just apply it as is.

Thanks! I applied patch 1/2.

Cheers,
Alex

Quoted 3 lines

Regards,
Nadav

Signature · 2 lines
<http://www.alejandro-colomar.es/>
GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5