1 // SPDX-License-Identifier: GPL-2.0
6 #include <linux/nospec.h>
10 #define IO_NOTIF_SPLICE_BATCH 32
11 #define IORING_MAX_NOTIF_SLOTS (1U << 10)
13 struct io_notif_data {
15 struct ubuf_info uarg;
16 unsigned long account_pages;
19 struct io_notif_slot {
21 * Current/active notifier. A slot holds only one active notifier at a
22 * time and keeps one reference to it. Flush releases the reference and
23 * lazily replaces it with a new notifier.
25 struct io_kiocb *notif;
28 * Default ->user_data for this slot notifiers CQEs
32 * Notifiers of a slot live in generations, we create a new notifier
33 * only after flushing the previous one. Track the sequential number
34 * for all notifiers and copy it into notifiers's cqe->cflags
39 int io_notif_register(struct io_ring_ctx *ctx,
40 void __user *arg, unsigned int size);
41 int io_notif_unregister(struct io_ring_ctx *ctx);
43 void io_notif_slot_flush(struct io_notif_slot *slot);
44 struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx,
45 struct io_notif_slot *slot);
47 static inline struct io_notif_data *io_notif_to_data(struct io_kiocb *notif)
49 return io_kiocb_to_cmd(notif, struct io_notif_data);
52 static inline struct io_kiocb *io_get_notif(struct io_ring_ctx *ctx,
53 struct io_notif_slot *slot)
56 slot->notif = io_alloc_notif(ctx, slot);
60 static inline struct io_notif_slot *io_get_notif_slot(struct io_ring_ctx *ctx,
62 __must_hold(&ctx->uring_lock)
64 if (idx >= ctx->nr_notif_slots)
66 idx = array_index_nospec(idx, ctx->nr_notif_slots);
67 return &ctx->notif_slots[idx];
70 static inline void io_notif_slot_flush_submit(struct io_notif_slot *slot,
71 unsigned int issue_flags)
73 io_notif_slot_flush(slot);
76 static inline int io_notif_account_mem(struct io_kiocb *notif, unsigned len)
78 struct io_ring_ctx *ctx = notif->ctx;
79 struct io_notif_data *nd = io_notif_to_data(notif);
80 unsigned nr_pages = (len >> PAGE_SHIFT) + 2;
84 ret = __io_account_mem(ctx->user, nr_pages);
87 nd->account_pages += nr_pages;