blob: f3589cfef4a9c995dc99aa0b480a7d5869b04e46 [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 Begunkovd6e29502024-04-15 13:50:13 +010016
Pavel Begunkov6fe42202024-04-19 12:08:42 +010017 struct io_notif_data *next;
18 struct io_notif_data *head;
19
Pavel Begunkovd6e29502024-04-15 13:50:13 +010020 unsigned account_pages;
Stefan Metzmachere307e662022-10-27 20:34:45 +020021 bool zc_report;
22 bool zc_used;
23 bool zc_copied;
Pavel Begunkoveb42ceb2022-07-12 21:52:38 +010024};
25
Pavel Begunkovb48c3122022-09-01 11:54:04 +010026struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx);
Pavel Begunkov5a569462024-04-19 12:08:41 +010027void io_tx_ubuf_complete(struct sk_buff *skb, struct ubuf_info *uarg,
28 bool success);
Pavel Begunkoveb42ceb2022-07-12 21:52:38 +010029
Pavel Begunkov14b146b2022-07-27 10:30:41 +010030static inline struct io_notif_data *io_notif_to_data(struct io_kiocb *notif)
31{
Stefan Metzmacherf2ccb5a2022-08-11 09:11:15 +020032 return io_kiocb_to_cmd(notif, struct io_notif_data);
Pavel Begunkov14b146b2022-07-27 10:30:41 +010033}
34
Pavel Begunkovbedd20b2022-11-04 10:59:44 +000035static inline void io_notif_flush(struct io_kiocb *notif)
36 __must_hold(&notif->ctx->uring_lock)
37{
38 struct io_notif_data *nd = io_notif_to_data(notif);
39
Pavel Begunkov5a569462024-04-19 12:08:41 +010040 io_tx_ubuf_complete(NULL, &nd->uarg, true);
Pavel Begunkovbedd20b2022-11-04 10:59:44 +000041}
42
Pavel Begunkov14b146b2022-07-27 10:30:41 +010043static inline int io_notif_account_mem(struct io_kiocb *notif, unsigned len)
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010044{
45 struct io_ring_ctx *ctx = notif->ctx;
Pavel Begunkov14b146b2022-07-27 10:30:41 +010046 struct io_notif_data *nd = io_notif_to_data(notif);
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010047 unsigned nr_pages = (len >> PAGE_SHIFT) + 2;
48 int ret;
49
50 if (ctx->user) {
51 ret = __io_account_mem(ctx->user, nr_pages);
52 if (ret)
53 return ret;
Pavel Begunkov14b146b2022-07-27 10:30:41 +010054 nd->account_pages += nr_pages;
Pavel Begunkov6a9ce662022-07-25 10:52:05 +010055 }
56 return 0;
57}