Skip to contentSkip to conversation

io_uring: Fix io_uring mmap() by using architecture-provided get_unmapped_area()

PATCH Applied Helge Deller 3 participants 6 messages Jul 21, 2023 – Jul 24, 2023

Subsystems (2)
lore
Share & tools
lore

Helge Deller

author maintainer
#0 lore raw

cover io_uring: Fix io_uring mmap() by using architecture-provided get_unmapped_area()

Fix io_uring on IA64 (and x86-32?) which was broken since commit d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements").
The fix is to switch back to the get_unmapped_area() which is provided by each architecture.

Patch 1 switches io_uring back to use per-arch get_unmapped_area(). Patch 2 (for IA64) is an independend cleanup.

Helge

Helge Deller (2):
io_uring: Fix io_uring mmap() by using architecture-provided
get_unmapped_area()
ia64: mmap: Consider pgoff when searching for free mapping

 arch/ia64/kernel/sys_ia64.c     |  2 +-
 arch/parisc/kernel/sys_parisc.c | 15 ++++++++----
 io_uring/io_uring.c             | 42 +++++++++++++--------------------
 3 files changed, 28 insertions(+), 31 deletions(-)

--
2.41.0

author maintainer
#1 lore raw

PATCH 1/2 io_uring: Fix io_uring mmap() by using architecture-provided get_unmapped_area()

The io_uring testcase is broken on IA-64 since commit d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements").

The reason is, that this commit introduced an own architecture independend get_unmapped_area() search algorithm which finds on IA-64 a memory region which is outside of the regular memory region used for shared userspace mappings and which can't be used on that platform due to aliasing.

To avoid similar problems on IA-64 and other platforms in the future, it's better to switch back to the architecture-provided get_unmapped_area() function and adjust the needed input parameters before the call. Beside fixing the issue, the function now becomes easier to understand and maintain.

This patch has been successfully tested with the io_uring testcase on physical x86-64, ppc64le, IA-64 and PA-RISC machines. On PA-RISC the LTP mmmap testcases did not report any regressions.

Cc Jens Axboe <[email protected]>
Fixes d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements")
---
 arch/parisc/kernel/sys_parisc.c | 15 ++++++++----
 io_uring/io_uring.c             | 42 +++++++++++++--------------------
 2 files changed, 27 insertions(+), 30 deletions(-)
arch/parisc/kernel/sys_parisc.c +10 -5
index 39acccabf2ed..465b7cb9d44f 100644
@@ -26,12 +26,17 @@
 #include <linux/compat.h>
 
 /*
- * Construct an artificial page offset for the mapping based on the physical
+ * Construct an artificial page offset for the mapping based on the virtual
  * address of the kernel file mapping variable.
+ * If filp is zero the calculated pgoff value aliases the memory of the given
+ * address. This is useful for io_uring where the mapping shall alias a kernel
+ * address and a userspace adress where both the kernel and the userspace
+ * access the same memory region.
  */
-#define GET_FILP_PGOFF(filp)		\
-	(filp ? (((unsigned long) filp->f_mapping) >> 8)	\
-		 & ((SHM_COLOUR-1) >> PAGE_SHIFT) : 0UL)
+#define GET_FILP_PGOFF(filp, addr)		\
+	((filp ? (((unsigned long) filp->f_mapping) >> 8)	\
+		 & ((SHM_COLOUR-1) >> PAGE_SHIFT) : 0UL)	\
+	  + (addr >> PAGE_SHIFT))
 
 static unsigned long shared_align_offset(unsigned long filp_pgoff,
 					 unsigned long pgoff)
@@ -111,7 +116,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
 	do_color_align = 0;
 	if (filp || (flags & MAP_SHARED))
 		do_color_align = 1;
-	filp_pgoff = GET_FILP_PGOFF(filp);
+	filp_pgoff = GET_FILP_PGOFF(filp, addr);
 
 	if (flags & MAP_FIXED) {
 		/* Even MAP_FIXED mappings must reside within TASK_SIZE */
io_uring/io_uring.c +17 -25

57 lines not on this page · raw message

--
2.41.0

Tested-by on v1 1/2
#2 lore raw
Quoted 15 lines · Helge Deller

The io_uring testcase is broken on IA-64 since commit d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements").

The reason is, that this commit introduced an own architecture independend get_unmapped_area() search algorithm which finds on IA-64 a memory region which is outside of the regular memory region used for shared userspace mappings and which can't be used on that platform due to aliasing.

To avoid similar problems on IA-64 and other platforms in the future, it's better to switch back to the architecture-provided get_unmapped_area() function and adjust the needed input parameters before the call. Beside fixing the issue, the function now becomes easier to understand and maintain.

Quoted 8 lines

This patch has been successfully tested with the io_uring testcase on physical x86-64, ppc64le, IA-64 and PA-RISC machines. On PA-RISC the LTP mmmap testcases did not report any regressions.

Cc Jens Axboe <[email protected]>
Fixes d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements")

thanks,

Signature · 2 lines
js
suse labs
author maintainer
#3 lore raw

PATCH 2/2 ia64: mmap: Consider pgoff when searching for free mapping

In reply to Helge Deller

IA64 is the only architecture which does not consider the pgoff value when searching for a possible free memory region with vm_unmapped_area(). Adding this seems to have no negative side effect on IA64, so add it now to make IA64 consistent with all other architectures.

---
 arch/ia64/kernel/sys_ia64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/ia64/kernel/sys_ia64.c +1 -1
index 6e948d015332..eb561cc93632 100644
@@ -63,7 +63,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
 	info.low_limit = addr;
 	info.high_limit = TASK_SIZE;
 	info.align_mask = align_mask;
-	info.align_offset = 0;
+	info.align_offset = pgoff << PAGE_SHIFT;
 	return vm_unmapped_area(&info);
 }
 

--
2.41.0

maintainer
#4 lore raw
In reply to Helge Deller
Quoted 8 lines · Helge Deller

Fix io_uring on IA64 (and x86-32?) which was broken since commit d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements").
The fix is to switch back to the get_unmapped_area() which is provided by each architecture.

Patch 1 switches io_uring back to use per-arch get_unmapped_area(). Patch 2 (for IA64) is an independend cleanup.

Let's get this queued up - I marked it for stable as well, for 6.4. Thanks for taking care of this!

Signature · 1 line
Jens Axboe
maintainer Applied
#5 lore raw
In reply to Helge Deller
Quoted 10 lines · Helge Deller

Fix io_uring on IA64 (and x86-32?) which was broken since commit d808459b2e31 ("io_uring: Adjust mapping wrt architecture aliasing requirements").
The fix is to switch back to the get_unmapped_area() which is provided by each architecture.

Patch 1 switches io_uring back to use per-arch get_unmapped_area(). Patch 2 (for IA64) is an independend cleanup.

[...]

Applied, thanks!

[1/2] io_uring: Fix io_uring mmap() by using architecture-provided get_unmapped_area()

      commit: 32832a407a7178eec3215fad9b1a3298c14b0d69
[2/2] ia64: mmap: Consider pgoff when searching for free mapping
      commit: 07e981137f17e5275b6fa5fd0c28b0ddb4519702

Best regards,

Signature · 1 line
Jens Axboe