Skip to content

Commit a8f6028

Browse files
committed
Merge branch 'for-7.1/io_uring' into for-next
* for-7.1/io_uring: io_uring/cmd: set selected buffer index in __io_uring_cmd_done() io_uring/kbuf: export io_ring_buffer_select() io_uring/kbuf: add io_uring_is_kmbuf_ring() io_uring/kbuf: add recycling for kernel managed buffer rings io_uring/kbuf: return buffer id in buffer selection io_uring/kbuf: add buffer ring pinning/unpinning io_uring/kbuf: support kernel-managed buffer rings in buffer selection io_uring/kbuf: add support for kernel-managed buffer rings Signed-off-by: Jens Axboe <axboe@kernel.dk>
2 parents c4ae841 + 3515a2a commit a8f6028

8 files changed

Lines changed: 427 additions & 34 deletions

File tree

include/linux/io_uring/cmd.h

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void io_uring_cmd_issue_blocking(struct io_uring_cmd *ioucmd);
7878

7979
/*
8080
* Select a buffer from the provided buffer group for multishot uring_cmd.
81-
* Returns the selected buffer address and size.
81+
* Returns the selected buffer address, size, and id.
8282
*/
8383
struct io_br_sel io_uring_cmd_buffer_select(struct io_uring_cmd *ioucmd,
8484
unsigned buf_group, size_t *len,
@@ -91,6 +91,21 @@ struct io_br_sel io_uring_cmd_buffer_select(struct io_uring_cmd *ioucmd,
9191
bool io_uring_mshot_cmd_post_cqe(struct io_uring_cmd *ioucmd,
9292
struct io_br_sel *sel, unsigned int issue_flags);
9393

94+
int io_uring_buf_ring_pin(struct io_uring_cmd *cmd, unsigned buf_group,
95+
unsigned issue_flags, struct io_buffer_list **out_bl);
96+
int io_uring_buf_ring_unpin(struct io_uring_cmd *cmd, unsigned buf_group,
97+
unsigned issue_flags);
98+
99+
int io_uring_kmbuf_recycle(struct io_uring_cmd *cmd, unsigned int buf_group,
100+
u64 addr, unsigned int len, unsigned int bid,
101+
unsigned int issue_flags);
102+
103+
bool io_uring_is_kmbuf_ring(struct io_uring_cmd *cmd, unsigned int buf_group,
104+
unsigned int issue_flags);
105+
106+
struct io_br_sel io_ring_buffer_select(struct io_kiocb *req, size_t *len,
107+
struct io_buffer_list *bl,
108+
unsigned int issue_flags);
94109
#else
95110
static inline int
96111
io_uring_cmd_import_fixed(u64 ubuf, unsigned long len, int rw,
@@ -133,6 +148,42 @@ static inline bool io_uring_mshot_cmd_post_cqe(struct io_uring_cmd *ioucmd,
133148
{
134149
return true;
135150
}
151+
static inline int io_uring_buf_ring_pin(struct io_uring_cmd *cmd,
152+
unsigned buf_group,
153+
unsigned issue_flags,
154+
struct io_buffer_list **bl)
155+
{
156+
return -EOPNOTSUPP;
157+
}
158+
static inline int io_uring_buf_ring_unpin(struct io_uring_cmd *cmd,
159+
unsigned buf_group,
160+
unsigned issue_flags)
161+
{
162+
return -EOPNOTSUPP;
163+
}
164+
static inline int io_uring_kmbuf_recycle(struct io_uring_cmd *cmd,
165+
unsigned int buf_group, u64 addr,
166+
unsigned int len, unsigned int bid,
167+
unsigned int issue_flags)
168+
{
169+
return -EOPNOTSUPP;
170+
}
171+
static inline bool io_uring_is_kmbuf_ring(struct io_uring_cmd *cmd,
172+
unsigned int buf_group,
173+
unsigned int issue_flags)
174+
{
175+
return false;
176+
}
177+
static inline struct io_br_sel io_ring_buffer_select(struct io_kiocb *req,
178+
size_t *len,
179+
struct io_buffer_list *bl,
180+
unsigned int issue_flags)
181+
{
182+
struct io_br_sel sel = {
183+
.val = -EOPNOTSUPP,
184+
};
185+
return sel;
186+
}
136187
#endif
137188

138189
static inline struct io_uring_cmd *io_uring_cmd_from_tw(struct io_tw_req tw_req)

include/linux/io_uring_types.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,15 @@ struct io_mapped_region {
9898
*/
9999
struct io_br_sel {
100100
struct io_buffer_list *buf_list;
101-
/*
102-
* Some selection parts return the user address, others return an error.
103-
*/
104101
union {
102+
/* for classic/ring provided buffers */
105103
void __user *addr;
106-
ssize_t val;
104+
/* for kernel-managed buffers */
105+
void *kaddr;
107106
};
107+
ssize_t val;
108+
/* id of the selected buffer */
109+
unsigned buf_id;
108110
};
109111

110112

include/uapi/linux/io_uring.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,29 @@ struct io_uring_buf_ring {
893893
* use of it will consume only as much as it needs. This
894894
* requires that both the kernel and application keep
895895
* track of where the current read/recv index is at.
896+
* IOU_PBUF_RING_KERNEL_MANAGED: If set, kernel allocates and manages the memory
897+
* for the ring and its buffers. The application must set
898+
* the buffer size through reg->buf_size and the size must
899+
* be page-aligned. When the application subsequently calls
900+
* mmap(2) with
901+
* IORING_OFF_PBUF_RING | (bgid << IORING_OFF_PBUF_SHIFT),
902+
* the virtual mapping returned is a contiguous mapping of
903+
* the buffers. If set, IOU_PBUF_RING_MMAP must be set as
904+
* well.
896905
*/
897906
enum io_uring_register_pbuf_ring_flags {
898907
IOU_PBUF_RING_MMAP = 1,
899908
IOU_PBUF_RING_INC = 2,
909+
IOU_PBUF_RING_KERNEL_MANAGED = 4,
900910
};
901911

902912
/* argument for IORING_(UN)REGISTER_PBUF_RING */
903913
struct io_uring_buf_reg {
904-
__u64 ring_addr;
914+
union {
915+
__u64 ring_addr;
916+
/* used if reg->flags & IOU_PBUF_RING_KERNEL_MANAGED */
917+
__u32 buf_size;
918+
};
905919
__u32 ring_entries;
906920
__u16 bgid;
907921
__u16 flags;

0 commit comments

Comments
 (0)