Split io_import_reg_vec() into: - __io_import_reg_vec(): core logic taking io_mapped_ubuf directly - io_import_reg_vec(): inline wrapper handling buffer lookup and request flags The core function takes 'imu' and 'need_clean' parameters instead of accessing req directly. This allows BPF kfuncs to import vectored buffers without request association, enabling support for multiple buffers per request. Signed-off-by: Ming Lei --- io_uring/rsrc.c | 18 +++++------------- io_uring/rsrc.h | 29 ++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/io_uring/rsrc.c b/io_uring/rsrc.c index ec716e14d467..7eb2c70185e4 100644 --- a/io_uring/rsrc.c +++ b/io_uring/rsrc.c @@ -1476,23 +1476,14 @@ static int io_kern_bvec_size(struct iovec *iov, unsigned nr_iovs, return 0; } -int io_import_reg_vec(int ddir, struct iov_iter *iter, - struct io_kiocb *req, struct iou_vec *vec, - unsigned nr_iovs, unsigned issue_flags) +int __io_import_reg_vec(int ddir, struct iov_iter *iter, + struct io_mapped_ubuf *imu, struct iou_vec *vec, + unsigned nr_iovs, bool *need_clean) { - struct io_rsrc_node *node; - struct io_mapped_ubuf *imu; unsigned iovec_off; struct iovec *iov; unsigned nr_segs; - node = io_find_buf_node(req, issue_flags); - if (!node) - return -EFAULT; - imu = node->buf; - if (!(imu->dir & (1 << ddir))) - return -EFAULT; - iovec_off = vec->nr - nr_iovs; iov = vec->iovec + iovec_off; @@ -1531,7 +1522,8 @@ int io_import_reg_vec(int ddir, struct iov_iter *iter, *vec = tmp_vec; iov = vec->iovec + iovec_off; - req->flags |= REQ_F_NEED_CLEANUP; + if (need_clean) + *need_clean = true; } if (imu->is_kbuf) diff --git a/io_uring/rsrc.h b/io_uring/rsrc.h index 2a29da350727..3203277ac289 100644 --- a/io_uring/rsrc.h +++ b/io_uring/rsrc.h @@ -77,9 +77,32 @@ static inline int io_import_reg_buf(struct io_kiocb *req, struct iov_iter *iter, return -EFAULT; return io_import_fixed(ddir, iter, node->buf, buf_addr, len); } -int io_import_reg_vec(int ddir, struct iov_iter *iter, - struct io_kiocb *req, struct iou_vec *vec, - unsigned nr_iovs, unsigned issue_flags); +int __io_import_reg_vec(int ddir, struct iov_iter *iter, + struct io_mapped_ubuf *imu, struct iou_vec *vec, + unsigned nr_iovs, bool *need_clean); + +static inline int io_import_reg_vec(int ddir, struct iov_iter *iter, + struct io_kiocb *req, struct iou_vec *vec, + unsigned nr_iovs, unsigned issue_flags) +{ + struct io_rsrc_node *node; + struct io_mapped_ubuf *imu; + bool need_clean = false; + int ret; + + node = io_find_buf_node(req, issue_flags); + if (!node) + return -EFAULT; + imu = node->buf; + if (!(imu->dir & (1 << ddir))) + return -EFAULT; + + ret = __io_import_reg_vec(ddir, iter, imu, vec, nr_iovs, &need_clean); + if (need_clean) + req->flags |= REQ_F_NEED_CLEANUP; + return ret; +} + int __io_prep_reg_iovec(struct iou_vec *iv, const struct iovec __user *uvec, size_t uvec_segs, bool compat, bool *need_clean); -- 2.47.0