Skip to content

Commit 81b4d1a

Browse files
calebsanderaxboe
authored andcommitted
ublk: update UBLK_F_SUPPORT_ZERO_COPY comment in UAPI header
UBLK_F_SUPPORT_ZERO_COPY has a very old comment describing the initial idea for how zero-copy would be implemented. The actual implementation added in commit 1f6540e ("ublk: zc register/unregister bvec") uses io_uring registered buffers rather than shared memory mapping. Remove the inaccurate remarks about mapping ublk request memory into the ublk server's address space and requiring 4K block size. Replace them with a description of the current zero-copy mechanism. Signed-off-by: Caleb Sander Mateos <[email protected]> Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 67caa52 commit 81b4d1a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

include/uapi/linux/ublk_cmd.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,28 @@
135135
#define UBLKSRV_IO_BUF_TOTAL_SIZE (1ULL << UBLKSRV_IO_BUF_TOTAL_BITS)
136136

137137
/*
138-
* zero copy requires 4k block size, and can remap ublk driver's io
139-
* request into ublksrv's vm space
138+
* ublk server can register data buffers for incoming I/O requests with a sparse
139+
* io_uring buffer table. The request buffer can then be used as the data buffer
140+
* for io_uring operations via the fixed buffer index.
141+
* Note that the ublk server can never directly access the request data memory.
142+
*
143+
* To use this feature, the ublk server must first register a sparse buffer
144+
* table on an io_uring instance.
145+
* When an incoming ublk request is received, the ublk server submits a
146+
* UBLK_U_IO_REGISTER_IO_BUF command to that io_uring instance. The
147+
* ublksrv_io_cmd's q_id and tag specify the request whose buffer to register
148+
* and addr is the index in the io_uring's buffer table to install the buffer.
149+
* SQEs can now be submitted to the io_uring to read/write the request's buffer
150+
* by enabling fixed buffers (e.g. using IORING_OP_{READ,WRITE}_FIXED or
151+
* IORING_URING_CMD_FIXED) and passing the registered buffer index in buf_index.
152+
* Once the last io_uring operation using the request's buffer has completed,
153+
* the ublk server submits a UBLK_U_IO_UNREGISTER_IO_BUF command with q_id, tag,
154+
* and addr again specifying the request buffer to unregister.
155+
* The ublk request is completed when its buffer is unregistered from all
156+
* io_uring instances and the ublk server issues UBLK_U_IO_COMMIT_AND_FETCH_REQ.
157+
*
158+
* Not available for UBLK_F_UNPRIVILEGED_DEV, as a ublk server can leak
159+
* uninitialized kernel memory by not reading into the full request buffer.
140160
*/
141161
#define UBLK_F_SUPPORT_ZERO_COPY (1ULL << 0)
142162

0 commit comments

Comments
 (0)