Skip to content

Commit 90175f3

Browse files
isilenceaxboe
authored andcommitted
io_uring/kbuf: remove pbuf ring refcounting
struct io_buffer_list refcounting was needed for RCU based sync with mmap, now we can kill it. Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/4a9cc54bf0077bb2bf2f3daf917549ddd41080da.1732886067.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent 78fda3d commit 90175f3

File tree

3 files changed

+7
-18
lines changed

3 files changed

+7
-18
lines changed

io_uring/kbuf.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ static int io_buffer_add_list(struct io_ring_ctx *ctx,
4848
* always under the ->uring_lock, but lookups from mmap do.
4949
*/
5050
bl->bgid = bgid;
51-
atomic_set(&bl->refs, 1);
5251
guard(mutex)(&ctx->mmap_lock);
5352
return xa_err(xa_store(&ctx->io_bl_xa, bgid, bl, GFP_KERNEL));
5453
}
@@ -385,12 +384,10 @@ static int __io_remove_buffers(struct io_ring_ctx *ctx,
385384
return i;
386385
}
387386

388-
void io_put_bl(struct io_ring_ctx *ctx, struct io_buffer_list *bl)
387+
static void io_put_bl(struct io_ring_ctx *ctx, struct io_buffer_list *bl)
389388
{
390-
if (atomic_dec_and_test(&bl->refs)) {
391-
__io_remove_buffers(ctx, bl, -1U);
392-
kfree(bl);
393-
}
389+
__io_remove_buffers(ctx, bl, -1U);
390+
kfree(bl);
394391
}
395392

396393
void io_destroy_buffers(struct io_ring_ctx *ctx)
@@ -804,10 +801,8 @@ struct io_buffer_list *io_pbuf_get_bl(struct io_ring_ctx *ctx,
804801

805802
bl = xa_load(&ctx->io_bl_xa, bgid);
806803
/* must be a mmap'able buffer ring and have pages */
807-
if (bl && bl->flags & IOBL_MMAP) {
808-
if (atomic_inc_not_zero(&bl->refs))
809-
return bl;
810-
}
804+
if (bl && bl->flags & IOBL_MMAP)
805+
return bl;
811806

812807
return ERR_PTR(-EINVAL);
813808
}
@@ -817,7 +812,7 @@ int io_pbuf_mmap(struct file *file, struct vm_area_struct *vma)
817812
struct io_ring_ctx *ctx = file->private_data;
818813
loff_t pgoff = vma->vm_pgoff << PAGE_SHIFT;
819814
struct io_buffer_list *bl;
820-
int bgid, ret;
815+
int bgid;
821816

822817
lockdep_assert_held(&ctx->mmap_lock);
823818

@@ -826,7 +821,5 @@ int io_pbuf_mmap(struct file *file, struct vm_area_struct *vma)
826821
if (IS_ERR(bl))
827822
return PTR_ERR(bl);
828823

829-
ret = io_uring_mmap_pages(ctx, vma, bl->buf_pages, bl->buf_nr_pages);
830-
io_put_bl(ctx, bl);
831-
return ret;
824+
return io_uring_mmap_pages(ctx, vma, bl->buf_pages, bl->buf_nr_pages);
832825
}

io_uring/kbuf.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ struct io_buffer_list {
3535
__u16 mask;
3636

3737
__u16 flags;
38-
39-
atomic_t refs;
4038
};
4139

4240
struct io_buffer {
@@ -83,7 +81,6 @@ void __io_put_kbuf(struct io_kiocb *req, int len, unsigned issue_flags);
8381

8482
bool io_kbuf_recycle_legacy(struct io_kiocb *req, unsigned issue_flags);
8583

86-
void io_put_bl(struct io_ring_ctx *ctx, struct io_buffer_list *bl);
8784
struct io_buffer_list *io_pbuf_get_bl(struct io_ring_ctx *ctx,
8885
unsigned long bgid);
8986
int io_pbuf_mmap(struct file *file, struct vm_area_struct *vma);

io_uring/memmap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ static void *io_uring_validate_mmap_request(struct file *file, loff_t pgoff,
383383
if (IS_ERR(bl))
384384
return bl;
385385
ptr = bl->buf_ring;
386-
io_put_bl(ctx, bl);
387386
return ptr;
388387
}
389388
case IORING_MAP_OFF_PARAM_REGION:

0 commit comments

Comments
 (0)