Skip to content

Commit

Permalink
io_uring: return locked and pinned page accounting
Browse files Browse the repository at this point in the history
Locked and pinned memory accounting in io_{,un}account_mem() depends on
having ->sqo_mm, which is NULL after a recent change for non SQPOLL'ed
io_ring. That disables the accounting.

Return ->sqo_mm initialisation back, and do __io_sq_thread_acquire_mm()
based on IORING_SETUP_SQPOLL flag.

Fixes: 8eb06d7 ("io_uring: fix missing ->mm on exit")
Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Pavel Begunkov authored and Jens Axboe committed Jul 24, 2020
1 parent 5dbcad5 commit cbcf721
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,8 @@ static void io_sq_thread_drop_mm(void)
static int __io_sq_thread_acquire_mm(struct io_ring_ctx *ctx)
{
if (!current->mm) {
if (unlikely(!ctx->sqo_mm || !mmget_not_zero(ctx->sqo_mm)))
if (unlikely(!(ctx->flags & IORING_SETUP_SQPOLL) ||
!mmget_not_zero(ctx->sqo_mm)))
return -EFAULT;
kthread_use_mm(ctx->sqo_mm);
}
Expand Down Expand Up @@ -7259,10 +7260,10 @@ static int io_sq_offload_start(struct io_ring_ctx *ctx,
{
int ret;

if (ctx->flags & IORING_SETUP_SQPOLL) {
mmgrab(current->mm);
ctx->sqo_mm = current->mm;
mmgrab(current->mm);
ctx->sqo_mm = current->mm;

if (ctx->flags & IORING_SETUP_SQPOLL) {
ret = -EPERM;
if (!capable(CAP_SYS_ADMIN))
goto err;
Expand Down

0 comments on commit cbcf721

Please sign in to comment.