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
571 /* return status information for a buffer group */571 /* return status information for a buffer group */
572 IORING_REGISTER_PBUF_STATUS = 26,572 IORING_REGISTER_PBUF_STATUS = 26,
573 573
574 /* set/clear busy poll settings */
575 IORING_REGISTER_NAPI = 27,
576 IORING_UNREGISTER_NAPI = 28,
577
574 /* this goes last */578 /* this goes last */
575 IORING_REGISTER_LAST,579 IORING_REGISTER_LAST,
576 580
@@ -704,6 +708,14 @@ struct io_uring_buf_status { · 127 unmodified lines
704 __u32 resv[8];708 __u32 resv[8];
705};709};
706 710
711/* argument for IORING_(UN)REGISTER_NAPI */
712struct io_uring_napi {
713 __u32 busy_poll_to;
714 __u8 prefer_busy_poll;
715 __u8 pad[3];
716 __u64 resv;
717};
718
707/*719/*
708 * io_uring_restriction->opcode values720 * io_uring_restriction->opcode values
709 */721 */
io_uring/napi.c+52−0
@@ -207,6 +207,58 @@ void io_napi_free(struct io_ring_ctx *ctx) · 206 unmodified lines
207 spin_unlock(&ctx->napi_lock);207 spin_unlock(&ctx->napi_lock);
208}208}
209 209
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 */
217int 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 */
247int 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
210/*262/*
211 * __io_napi_adjust_timeout() - Add napi id to the busy poll list263 * __io_napi_adjust_timeout() - Add napi id to the busy poll list
212 * @ctx: pointer to io-uring context structure264 * @ctx: pointer to io-uring context structure
io_uring/napi.h+11−0
@@ -12,6 +12,9 @@ · 11 unmodified lines
12void io_napi_init(struct io_ring_ctx *ctx);12void io_napi_init(struct io_ring_ctx *ctx);
13void io_napi_free(struct io_ring_ctx *ctx);13void io_napi_free(struct io_ring_ctx *ctx);
14 14
15int io_register_napi(struct io_ring_ctx *ctx, void __user *arg);
16int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg);
17
15void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);18void __io_napi_add(struct io_ring_ctx *ctx, struct socket *sock);
16 19
17void __io_napi_adjust_timeout(struct io_ring_ctx *ctx,20void __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
68static inline void io_napi_free(struct io_ring_ctx *ctx)71static inline void io_napi_free(struct io_ring_ctx *ctx)
69{72{
70}73}
74static inline int io_register_napi(struct io_ring_ctx *ctx, void __user *arg)
75{
76 return -EOPNOTSUPP;
77}
78static inline int io_unregister_napi(struct io_ring_ctx *ctx, void __user *arg)
79{
80 return -EOPNOTSUPP;
81}
71static inline bool io_napi(struct io_ring_ctx *ctx)82static inline bool io_napi(struct io_ring_ctx *ctx)
72{83{
73 return false;84 return false;
io_uring/register.c+13−0
@@ -26,6 +26,7 @@ · 25 unmodified lines
26#include "register.h"26#include "register.h"
27#include "cancel.h"27#include "cancel.h"
28#include "kbuf.h"28#include "kbuf.h"
29#include "napi.h"
29 30
30#define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \31#define IORING_MAX_RESTRICTIONS (IORING_RESTRICTION_LAST + \
31 IORING_REGISTER_LAST + IORING_OP_LAST)32 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
550 break;551 break;
551 ret = io_register_pbuf_status(ctx, arg);552 ret = io_register_pbuf_status(ctx, arg);
552 break;553 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;
553 default:566 default:
554 ret = -EINVAL;567 ret = -EINVAL;
555 break;568 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