History

io_uring: add register/unregister napi function

This adds an api to register and unregister the napi for io-uring. If the arg value is specified when unregistering, the current napi setting for the busy poll timeout is copied into the user structure. If this is not required, NULL can be passed as the arg value.

Stefan Roesch committed 3 years ago

Commit ef1186c1 parent ff183d44 files · +88 −0Browse files

Unified · Split

4 files
  1. include/uapi/linux/io_uring.h +12 −0
  2. io_uring/napi.c +52 −0
  3. io_uring/napi.h +11 −0
  4. io_uring/register.c +13 −0
include/uapi/linux/io_uring.h+12−0
@@ -571,6 +571,10 @@ enum { · 570 unmodified lines
571571 /* return status information for a buffer group */
572572 IORING_REGISTER_PBUF_STATUS = 26,
573573
574+ /* set/clear busy poll settings */
575+ IORING_REGISTER_NAPI = 27,
576+ IORING_UNREGISTER_NAPI = 28,
577+
574578 /* this goes last */
575579 IORING_REGISTER_LAST,
576580
@@ -704,6 +708,14 @@ struct io_uring_buf_status { · 127 unmodified lines
704708 __u32 resv[8];
705709 };
706710
711+/* argument for IORING_(UN)REGISTER_NAPI */
712+struct io_uring_napi {
713+ __u32 busy_poll_to;
714+ __u8 prefer_busy_poll;
715+ __u8 pad[3];
716+ __u64 resv;
717+};
718+
707719 /*
708720 * io_uring_restriction->opcode values
709721 */
io_uring/napi.c+52−0
@@ -207,6 +207,58 @@ void io_napi_free(struct io_ring_ctx *ctx) · 206 unmodified lines
207207 spin_unlock(&ctx->napi_lock);
208208 }
209209
210+/*
211+ * io_napi_register() - Register napi with io-uring
212+ * @ctx: pointer to io-uring context structure
213+ * @arg: pointer to io_uring_napi structure
214+ *
215+ * Register napi in the io-uring context.
216+ */
217+int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
218+{
219+ const struct io_uring_napi curr = {
220+ .busy_poll_to = ctx->napi_busy_poll_to,
221+ .prefer_busy_poll = ctx->napi_prefer_busy_poll
222+ };
223+ struct io_uring_napi napi;
224+
225+ if (copy_from_user(&napi, arg, sizeof(napi)))
226+ return -EFAULT;
227+ if (napi.pad[0] || napi.pad[1] || napi.pad[2] || napi.resv)
228+ return -EINVAL;
229+
230+ WRITE_ONCE(ctx->napi_busy_poll_to, napi.busy_poll_to);
231+ WRITE_ONCE(ctx->napi_prefer_busy_poll, !!napi.prefer_busy_poll);
232+
233+ if (copy_to_user(arg, &curr, sizeof(curr)))
234+ return -EFAULT;
235+
236+ return 0;
237+}
238+
239+/*
240+ * io_napi_unregister() - Unregister napi with io-uring
241+ * @ctx: pointer to io-uring context structure
242+ * @arg: pointer to io_uring_napi structure
243+ *
244+ * Unregister napi. If arg has been specified copy the busy poll timeout and
245+ * prefer busy poll setting to the passed in structure.
246+ */
247+int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
248+{
249+ const struct io_uring_napi curr = {
250+ .busy_poll_to = ctx->napi_busy_poll_to,
251+ .prefer_busy_poll = ctx->napi_prefer_busy_poll
252+ };
253+
254+ if (arg && copy_to_user(arg, &curr, sizeof(curr)))
255+ return -EFAULT;
256+
257+ WRITE_ONCE(ctx->napi_busy_poll_to, 0);
258+ WRITE_ONCE(ctx->napi_prefer_busy_poll, false);
259+ return 0;
260+}
261+
210262 /*
211263 * __io_napi_adjust_timeout() - Add napi id to the busy poll list
212264 * @ctx: pointer to io-uring context structure
io_uring/napi.h+11−0
@@ -12,6 +12,9 @@ · 11 unmodified lines
1212 void io_napi_init(struct io_ring_ctx *ctx);
1313 void io_napi_free(struct io_ring_ctx *ctx);
1414
15+int io_register_napi(struct io_ring_ctx *ctx, void __user *arg);
16+int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
17+
1518 void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
1619
1720 void __io_napi_adjust_timeout(struct io_ring_ctx *ctx,
@@ -68,6 +71,14 @@ static inline void io_napi_init(struct io_ring_ctx *ctx) · 50 unmodified lines
6871 static inline void io_napi_free(struct io_ring_ctx *ctx)
6972 {
7073 }
74+static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
75+{
76+ return -EOPNOTSUPP;
77+}
78+static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
79+{
80+ return -EOPNOTSUPP;
81+}
7182 static inline bool io_napi(struct io_ring_ctx *ctx)
7283 {
7384 return false;
io_uring/register.c+13−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include "register.h"
2727 #include "cancel.h"
2828 #include "kbuf.h"
29+#include "napi.h"
2930
3031 #define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
3132 IORING_REGISTER_LAST + IORING_OP_LAST)
@@ -550,6 +551,18 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, · 518 unmodified lines
550551 break;
551552 ret = io_register_pbuf_status(ctx, arg);
552553 break;
554+ case IORING_REGISTER_NAPI:
555+ ret = -EINVAL;
556+ if (!arg || nr_args != 1)
557+ break;
558+ ret = io_register_napi(ctx, arg);
559+ break;
560+ case IORING_UNREGISTER_NAPI:
561+ ret = -EINVAL;
562+ if (nr_args != 1)
563+ break;
564+ ret = io_unregister_napi(ctx, arg);
565+ break;
553566 default:
554567 ret = -EINVAL;
555568 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t