diff options
author | Jens Axboe <axboe@kernel.dk> | 2024-09-11 22:54:32 +0300 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2024-09-11 22:54:32 +0300 |
commit | bfc0aa7a512f9a4462a88ca7352b00b83f8d68fd (patch) | |
tree | 24b4a25e54a354cdc67a9827f6c8e0d72534c08c /io_uring/rsrc.c | |
parent | 021b153f7d4115d99efa0d57ae2da6de1228295d (diff) | |
download | linux-bfc0aa7a512f9a4462a88ca7352b00b83f8d68fd.tar.xz |
io_uring/rsrc: add reference count to struct io_mapped_ubuf
Currently there's a single ring owner of a mapped buffer, and hence the
reference count will always be 1 when it's torn down and freed. However,
in preparation for being able to link io_mapped_ubuf to different spots,
add a reference count to manage the lifetime of it.
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'io_uring/rsrc.c')
-rw-r--r-- | io_uring/rsrc.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index d42114845fac..28f98de3c304 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -116,6 +116,8 @@ static void io_buffer_unmap(struct io_ring_ctx *ctx, struct io_mapped_ubuf **slo *slot = NULL; if (imu != &dummy_ubuf) { + if (!refcount_dec_and_test(&imu->refs)) + return; for (i = 0; i < imu->nr_bvecs; i++) unpin_user_page(imu->bvec[i].bv_page); if (imu->acct_pages) @@ -990,6 +992,7 @@ static int io_sqe_buffer_register(struct io_ring_ctx *ctx, struct iovec *iov, imu->folio_shift = data.folio_shift; imu->folio_mask = ~((1UL << data.folio_shift) - 1); } + refcount_set(&imu->refs, 1); off = (unsigned long) iov->iov_base & ~imu->folio_mask; *pimu = imu; ret = 0; |