Skip to content

Commit bdd1d82

Browse files
committed
Merge tag 'io_uring-6.5-2023-07-21' of git://git.kernel.dk/linux
Pull io_uring fixes from Jens Axboe: - Fix for io-wq not always honoring REQ_F_NOWAIT, if it was set and punted directly (eg via DRAIN) (me) - Capability check fix (Ondrej) - Regression fix for the mmap changes that went into 6.4, which apparently broke IA64 (Helge) * tag 'io_uring-6.5-2023-07-21' of git://git.kernel.dk/linux: ia64: mmap: Consider pgoff when searching for free mapping io_uring: Fix io_uring mmap() by using architecture-provided get_unmapped_area() io_uring: treat -EAGAIN for REQ_F_NOWAIT as final for io-wq io_uring: don't audit the capability check in io_uring_create()
2 parents 725d444 + 07e9811 commit bdd1d82

File tree

3 files changed

+37
-32
lines changed

3 files changed

+37
-32
lines changed

arch/ia64/kernel/sys_ia64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
6363
info.low_limit = addr;
6464
info.high_limit = TASK_SIZE;
6565
info.align_mask = align_mask;
66-
info.align_offset = 0;
66+
info.align_offset = pgoff << PAGE_SHIFT;
6767
return vm_unmapped_area(&info);
6868
}
6969

arch/parisc/kernel/sys_parisc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@
2727
#include <linux/elf-randomize.h>
2828

2929
/*
30-
* Construct an artificial page offset for the mapping based on the physical
30+
* Construct an artificial page offset for the mapping based on the virtual
3131
* address of the kernel file mapping variable.
32+
* If filp is zero the calculated pgoff value aliases the memory of the given
33+
* address. This is useful for io_uring where the mapping shall alias a kernel
34+
* address and a userspace adress where both the kernel and the userspace
35+
* access the same memory region.
3236
*/
33-
#define GET_FILP_PGOFF(filp) \
34-
(filp ? (((unsigned long) filp->f_mapping) >> 8) \
35-
& ((SHM_COLOUR-1) >> PAGE_SHIFT) : 0UL)
37+
#define GET_FILP_PGOFF(filp, addr) \
38+
((filp ? (((unsigned long) filp->f_mapping) >> 8) \
39+
& ((SHM_COLOUR-1) >> PAGE_SHIFT) : 0UL) \
40+
+ (addr >> PAGE_SHIFT))
3641

3742
static unsigned long shared_align_offset(unsigned long filp_pgoff,
3843
unsigned long pgoff)
@@ -112,7 +117,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
112117
do_color_align = 0;
113118
if (filp || (flags & MAP_SHARED))
114119
do_color_align = 1;
115-
filp_pgoff = GET_FILP_PGOFF(filp);
120+
filp_pgoff = GET_FILP_PGOFF(filp, addr);
116121

117122
if (flags & MAP_FIXED) {
118123
/* Even MAP_FIXED mappings must reside within TASK_SIZE */

io_uring/io_uring.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,14 @@ void io_wq_submit_work(struct io_wq_work *work)
19481948
ret = io_issue_sqe(req, issue_flags);
19491949
if (ret != -EAGAIN)
19501950
break;
1951+
1952+
/*
1953+
* If REQ_F_NOWAIT is set, then don't wait or retry with
1954+
* poll. -EAGAIN is final for that case.
1955+
*/
1956+
if (req->flags & REQ_F_NOWAIT)
1957+
break;
1958+
19511959
/*
19521960
* We can get EAGAIN for iopolled IO even though we're
19531961
* forcing a sync submission from here, since we can't
@@ -3429,8 +3437,6 @@ static unsigned long io_uring_mmu_get_unmapped_area(struct file *filp,
34293437
unsigned long addr, unsigned long len,
34303438
unsigned long pgoff, unsigned long flags)
34313439
{
3432-
const unsigned long mmap_end = arch_get_mmap_end(addr, len, flags);
3433-
struct vm_unmapped_area_info info;
34343440
void *ptr;
34353441

34363442
/*
@@ -3445,32 +3451,26 @@ static unsigned long io_uring_mmu_get_unmapped_area(struct file *filp,
34453451
if (IS_ERR(ptr))
34463452
return -ENOMEM;
34473453

3448-
info.flags = VM_UNMAPPED_AREA_TOPDOWN;
3449-
info.length = len;
3450-
info.low_limit = max(PAGE_SIZE, mmap_min_addr);
3451-
info.high_limit = arch_get_mmap_base(addr, current->mm->mmap_base);
3454+
/*
3455+
* Some architectures have strong cache aliasing requirements.
3456+
* For such architectures we need a coherent mapping which aliases
3457+
* kernel memory *and* userspace memory. To achieve that:
3458+
* - use a NULL file pointer to reference physical memory, and
3459+
* - use the kernel virtual address of the shared io_uring context
3460+
* (instead of the userspace-provided address, which has to be 0UL
3461+
* anyway).
3462+
* For architectures without such aliasing requirements, the
3463+
* architecture will return any suitable mapping because addr is 0.
3464+
*/
3465+
filp = NULL;
3466+
flags |= MAP_SHARED;
3467+
pgoff = 0; /* has been translated to ptr above */
34523468
#ifdef SHM_COLOUR
3453-
info.align_mask = PAGE_MASK & (SHM_COLOUR - 1UL);
3469+
addr = (uintptr_t) ptr;
34543470
#else
3455-
info.align_mask = PAGE_MASK & (SHMLBA - 1UL);
3471+
addr = 0UL;
34563472
#endif
3457-
info.align_offset = (unsigned long) ptr;
3458-
3459-
/*
3460-
* A failed mmap() very likely causes application failure,
3461-
* so fall back to the bottom-up function here. This scenario
3462-
* can happen with large stack limits and large mmap()
3463-
* allocations.
3464-
*/
3465-
addr = vm_unmapped_area(&info);
3466-
if (offset_in_page(addr)) {
3467-
info.flags = 0;
3468-
info.low_limit = TASK_UNMAPPED_BASE;
3469-
info.high_limit = mmap_end;
3470-
addr = vm_unmapped_area(&info);
3471-
}
3472-
3473-
return addr;
3473+
return current->mm->get_unmapped_area(filp, addr, len, pgoff, flags);
34743474
}
34753475

34763476
#else /* !CONFIG_MMU */
@@ -3870,7 +3870,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
38703870
ctx->syscall_iopoll = 1;
38713871

38723872
ctx->compat = in_compat_syscall();
3873-
if (!capable(CAP_IPC_LOCK))
3873+
if (!ns_capable_noaudit(&init_user_ns, CAP_IPC_LOCK))
38743874
ctx->user = get_uid(current_user());
38753875

38763876
/*

0 commit comments

Comments
 (0)