Add UBLK_F_AUTO_BUF_REG for supporting to register buffer automatically to local io_uring context with provided buffer index. Add UAPI structure `struct ublk_auto_buf_reg` for holding user parameter to register request buffer automatically, one 'flags' field is defined, and there is still 32bit available for future extension, such as, adding one io_ring FD field for registering buffer to external io_uring. `struct ublk_auto_buf_reg` is populated from ublk uring_cmd's sqe->addr, and all existing ublk commands are data-less, so it is just fine to reuse sqe->addr for this purpose.
Showing the changes to include/uapi/linux (1 of 2 files). Show all
Unified · Split
| @@ -219,6 +219,29 @@ · 218 unmodified lines | |||
| 219 | */ | 219 | */ |
| 220 | #define UBLK_F_UPDATE_SIZE (1ULL << 10) | 220 | #define UBLK_F_UPDATE_SIZE (1ULL << 10) |
| 221 | 221 | ||
| 222 | /* | ||
| 223 | * request buffer is registered automatically to uring_cmd's io_uring | ||
| 224 | * context before delivering this io command to ublk server, meantime | ||
| 225 | * it is un-registered automatically when completing this io command. | ||
| 226 | * | ||
| 227 | * For using this feature: | ||
| 228 | * | ||
| 229 | * - ublk server has to create sparse buffer table | ||
| 230 | * | ||
| 231 | * - ublk server passes auto buf register data via uring_cmd's sqe->addr, | ||
| 232 | * `struct ublk_auto_buf_reg` is populated from sqe->addr, please see | ||
| 233 | * the definition of ublk_sqe_addr_to_auto_buf_reg() | ||
| 234 | * | ||
| 235 | * - pass buffer index from `ublk_auto_buf_reg.index` | ||
| 236 | * | ||
| 237 | * - all reserved fields in `ublk_auto_buf_reg` need to be zeroed | ||
| 238 | * | ||
| 239 | * This way avoids extra cost from two uring_cmd, but also simplifies backend | ||
| 240 | * implementation, such as, the dependency on IO_REGISTER_IO_BUF and | ||
| 241 | * IO_UNREGISTER_IO_BUF becomes not necessary. | ||
| 242 | */ | ||
| 243 | #define UBLK_F_AUTO_BUF_REG (1ULL << 11) | ||
| 244 | |||
| 222 | /* device state */ | 245 | /* device state */ |
| 223 | #define UBLK_S_DEV_DEAD 0 | 246 | #define UBLK_S_DEV_DEAD 0 |
| 224 | #define UBLK_S_DEV_LIVE 1 | 247 | #define UBLK_S_DEV_LIVE 1 |
| @@ -339,6 +362,47 @@ static inline __u32 ublksrv_get_flags(const struct ublksrv_io_desc *iod) · 114 unmodified lines | |||
| 339 | return iod->op_flags >> 8; | 362 | return iod->op_flags >> 8; |
| 340 | } | 363 | } |
| 341 | 364 | ||
| 365 | struct ublk_auto_buf_reg { | ||
| 366 | /* index for registering the delivered request buffer */ | ||
| 367 | __u16 index; | ||
| 368 | __u16 reserved0; | ||
| 369 | |||
| 370 | /* | ||
| 371 | * io_ring FD can be passed via the reserve field in future for | ||
| 372 | * supporting to register io buffer to external io_uring | ||
| 373 | */ | ||
| 374 | __u32 reserved1; | ||
| 375 | }; | ||
| 376 | |||
| 377 | /* | ||
| 378 | * For UBLK_F_AUTO_BUF_REG, auto buffer register data is carried via | ||
| 379 | * uring_cmd's sqe->addr: | ||
| 380 | * | ||
| 381 | * - bit0 ~ bit15: buffer index | ||
| 382 | * - bit24 ~ bit31: reserved0 | ||
| 383 | * - bit32 ~ bit63: reserved1 | ||
| 384 | */ | ||
| 385 | static inline struct ublk_auto_buf_reg ublk_sqe_addr_to_auto_buf_reg( | ||
| 386 | __u64 sqe_addr) | ||
| 387 | { | ||
| 388 | struct ublk_auto_buf_reg reg = { | ||
| 389 | .index = sqe_addr & 0xffff, | ||
| 390 | .reserved0 = (sqe_addr >> 16) & 0xffff, | ||
| 391 | .reserved1 = sqe_addr >> 32, | ||
| 392 | }; | ||
| 393 | |||
| 394 | return reg; | ||
| 395 | } | ||
| 396 | |||
| 397 | static inline __u64 | ||
| 398 | ublk_auto_buf_reg_to_sqe_addr(const struct ublk_auto_buf_reg *buf) | ||
| 399 | { | ||
| 400 | __u64 addr = buf->index | (__u64)buf->reserved0 << 16 | | ||
| 401 | (__u64)buf->reserved1 << 32; | ||
| 402 | |||
| 403 | return addr; | ||
| 404 | } | ||
| 405 | |||
| 342 | /* issued to ublk driver via /dev/ublkcN */ | 406 | /* issued to ublk driver via /dev/ublkcN */ |
| 343 | struct ublksrv_io_cmd { | 407 | struct ublksrv_io_cmd { |
| 344 | __u16 q_id; | 408 | __u16 q_id; |