blob: 86d32bd9f856833656de9131179c83be4a08ce59 [file] [log] [blame]
Pavel Begunkoveb42ceb2022-07-12 21:52:38 +01001// SPDX-License-Identifier: GPL-2.0
2
3#include <linux/net.h>
4#include <linux/uio.h>
5#include <net/sock.h>
6#include <linux/nospec.h>
7
Pavel Begunkov6a9ce662022-07-25 10:52:05 +01008#include "rsrc.h"
9
Pavel Begunkov519760d2023-04-15 14:20:08 +010010#define IO_NOTIF_UBUF_FLAGS (SKBFL_ZEROCOPY_FRAG | SKBFL_DONT_ORPHAN)
Pavel Begunkoveb4a2992022-07-12 21:52:39 +010011#define IO_NOTIF_SPLICE_BATCH 32
12
Pavel Begunkov14b146b2022-07-27 10:30:41 +010013struct io_notif_data {
14 struct file *file;
Pavel Begunkoveb42ceb2022-07-12 21:52:38 +010015 struct ubuf_info uarg;
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010016 unsigned long account_pages;
Stefan Metzmachere307e662022-10-27 20:34:45 +020017 bool zc_report;
18 bool zc_used;
19 bool zc_copied;
Pavel Begunkoveb42ceb2022-07-12 21:52:38 +010020};
21
Pavel Begunkovb48c3122022-09-01 11:54:04 +010022struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx);
Pavel Begunkov40725d12022-11-04 10:59:45 +000023void io_notif_set_extended(struct io_kiocb *notif);
Pavel Begunkoveb42ceb2022-07-12 21:52:38 +010024
Pavel Begunkov14b146b2022-07-27 10:30:41 +010025static inline struct io_notif_data *io_notif_to_data(struct io_kiocb *notif)
26{
Stefan Metzmacherf2ccb5a2022-08-11 09:11:15 +020027 return io_kiocb_to_cmd(notif, struct io_notif_data);
Pavel Begunkov14b146b2022-07-27 10:30:41 +010028}
29
Pavel Begunkovbedd20b2022-11-04 10:59:44 +000030static inline void io_notif_flush(struct io_kiocb *notif)
31 __must_hold(&notif->ctx->uring_lock)
32{
33 struct io_notif_data *nd = io_notif_to_data(notif);
34
35 /* drop slot's master ref */
36 if (refcount_dec_and_test(&nd->uarg.refcnt))
Pavel Begunkov8751d152023-04-06 14:20:12 +010037 __io_req_task_work_add(notif, IOU_F_TWQ_LAZY_WAKE);
Pavel Begunkovbedd20b2022-11-04 10:59:44 +000038}
39
Pavel Begunkov14b146b2022-07-27 10:30:41 +010040static inline int io_notif_account_mem(struct io_kiocb *notif, unsigned len)
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010041{
42 struct io_ring_ctx *ctx = notif->ctx;
Pavel Begunkov14b146b2022-07-27 10:30:41 +010043 struct io_notif_data *nd = io_notif_to_data(notif);
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010044 unsigned nr_pages = (len >> PAGE_SHIFT) + 2;
45 int ret;
46
47 if (ctx->user) {
48 ret = __io_account_mem(ctx->user, nr_pages);
49 if (ret)
50 return ret;
Pavel Begunkov14b146b2022-07-27 10:30:41 +010051 nd->account_pages += nr_pages;
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010052 }
53 return 0;
54}