io_uring: kill extra io_uring_types.h includes
[platform/kernel/linux-starfive.git] / io_uring / msg_ring.c
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/errno.h>
4 #include <linux/file.h>
5 #include <linux/slab.h>
6 #include <linux/io_uring.h>
7
8 #include <uapi/linux/io_uring.h>
9
10 #include "io_uring.h"
11 #include "msg_ring.h"
12
13 struct io_msg {
14         struct file                     *file;
15         u64 user_data;
16         u32 len;
17 };
18
19 int io_msg_ring_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
20 {
21         struct io_msg *msg = io_kiocb_to_cmd(req);
22
23         if (unlikely(sqe->addr || sqe->rw_flags || sqe->splice_fd_in ||
24                      sqe->buf_index || sqe->personality))
25                 return -EINVAL;
26
27         msg->user_data = READ_ONCE(sqe->off);
28         msg->len = READ_ONCE(sqe->len);
29         return 0;
30 }
31
32 int io_msg_ring(struct io_kiocb *req, unsigned int issue_flags)
33 {
34         struct io_msg *msg = io_kiocb_to_cmd(req);
35         struct io_ring_ctx *target_ctx;
36         int ret;
37
38         ret = -EBADFD;
39         if (!io_is_uring_fops(req->file))
40                 goto done;
41
42         ret = -EOVERFLOW;
43         target_ctx = req->file->private_data;
44         if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, 0))
45                 ret = 0;
46
47 done:
48         if (ret < 0)
49                 req_set_fail(req);
50         io_req_set_res(req, ret, 0);
51         /* put file to avoid an attempt to IOPOLL the req */
52         io_put_file(req->file);
53         req->file = NULL;
54         return IOU_OK;
55 }