Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ublk: remove ubq checks from ublk_{get,put}_req_ref()

ublk_get_req_ref() and ublk_put_req_ref() currently call
ublk_need_req_ref(ubq) to check whether the ublk device features require
reference counting of its requests. However, all callers already know
that reference counting is required:
- __ublk_check_and_get_req() is only called from
ublk_check_and_get_req() if user copy is enabled, and from
ublk_register_io_buf() if zero copy is enabled
- ublk_io_release() is only called for requests registered by
ublk_register_io_buf(), which requires zero copy
- ublk_ch_read_iter() and ublk_ch_write_iter() only call
ublk_put_req_ref() if ublk_check_and_get_req() succeeded, which
requires user copy to be enabled

So drop the ublk_need_req_ref() check and the ubq argument in
ublk_get_req_ref() and ublk_put_req_ref().

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20250620151008.3976463-14-csander@purestorage.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Caleb Sander Mateos and committed by
Jens Axboe
c9d066eb 1ceeedb5

+11 -24
+11 -24
drivers/block/ublk_drv.c
··· 699 699 refcount_set(&io->ref, UBLK_REFCOUNT_INIT); 700 700 } 701 701 702 - static inline bool ublk_get_req_ref(const struct ublk_queue *ubq, 703 - struct ublk_io *io) 702 + static inline bool ublk_get_req_ref(struct ublk_io *io) 704 703 { 705 - if (ublk_need_req_ref(ubq)) 706 - return refcount_inc_not_zero(&io->ref); 707 - 708 - return true; 704 + return refcount_inc_not_zero(&io->ref); 709 705 } 710 706 711 - static inline void ublk_put_req_ref(const struct ublk_queue *ubq, 712 - struct ublk_io *io, struct request *req) 707 + static inline void ublk_put_req_ref(struct ublk_io *io, struct request *req) 713 708 { 714 - if (ublk_need_req_ref(ubq)) { 715 - if (refcount_dec_and_test(&io->ref)) 716 - __ublk_complete_rq(req); 717 - } else { 709 + if (refcount_dec_and_test(&io->ref)) 718 710 __ublk_complete_rq(req); 719 - } 720 711 } 721 712 722 713 static inline void ublk_sub_req_ref(struct ublk_io *io, struct request *req) ··· 2028 2037 if (current == io->task && io->task_registered_buffers) 2029 2038 io->task_registered_buffers--; 2030 2039 else 2031 - ublk_put_req_ref(ubq, io, rq); 2040 + ublk_put_req_ref(io, rq); 2032 2041 } 2033 2042 2034 2043 static int ublk_register_io_buf(struct io_uring_cmd *cmd, ··· 2050 2059 ret = io_buffer_register_bvec(cmd, req, ublk_io_release, index, 2051 2060 issue_flags); 2052 2061 if (ret) { 2053 - ublk_put_req_ref(ubq, io, req); 2062 + ublk_put_req_ref(io, req); 2054 2063 return ret; 2055 2064 } 2056 2065 ··· 2357 2366 if (!req) 2358 2367 return NULL; 2359 2368 2360 - if (!ublk_get_req_ref(ubq, io)) 2369 + if (!ublk_get_req_ref(io)) 2361 2370 return NULL; 2362 2371 2363 2372 if (unlikely(!blk_mq_request_started(req) || req->tag != tag)) ··· 2371 2380 2372 2381 return req; 2373 2382 fail_put: 2374 - ublk_put_req_ref(ubq, io, req); 2383 + ublk_put_req_ref(io, req); 2375 2384 return NULL; 2376 2385 } 2377 2386 ··· 2487 2496 *off = buf_off; 2488 2497 return req; 2489 2498 fail: 2490 - ublk_put_req_ref(ubq, *io, req); 2499 + ublk_put_req_ref(*io, req); 2491 2500 return ERR_PTR(-EACCES); 2492 2501 } 2493 2502 2494 2503 static ssize_t ublk_ch_read_iter(struct kiocb *iocb, struct iov_iter *to) 2495 2504 { 2496 - struct ublk_queue *ubq; 2497 2505 struct request *req; 2498 2506 struct ublk_io *io; 2499 2507 size_t buf_off; ··· 2503 2513 return PTR_ERR(req); 2504 2514 2505 2515 ret = ublk_copy_user_pages(req, buf_off, to, ITER_DEST); 2506 - ubq = req->mq_hctx->driver_data; 2507 - ublk_put_req_ref(ubq, io, req); 2516 + ublk_put_req_ref(io, req); 2508 2517 2509 2518 return ret; 2510 2519 } 2511 2520 2512 2521 static ssize_t ublk_ch_write_iter(struct kiocb *iocb, struct iov_iter *from) 2513 2522 { 2514 - struct ublk_queue *ubq; 2515 2523 struct request *req; 2516 2524 struct ublk_io *io; 2517 2525 size_t buf_off; ··· 2520 2532 return PTR_ERR(req); 2521 2533 2522 2534 ret = ublk_copy_user_pages(req, buf_off, from, ITER_SOURCE); 2523 - ubq = req->mq_hctx->driver_data; 2524 - ublk_put_req_ref(ubq, io, req); 2535 + ublk_put_req_ref(io, req); 2525 2536 2526 2537 return ret; 2527 2538 }