1eb42cebbSPavel Begunkov // SPDX-License-Identifier: GPL-2.0 2eb42cebbSPavel Begunkov 3eb42cebbSPavel Begunkov #include <linux/net.h> 4eb42cebbSPavel Begunkov #include <linux/uio.h> 5eb42cebbSPavel Begunkov #include <net/sock.h> 6eb42cebbSPavel Begunkov #include <linux/nospec.h> 7eb42cebbSPavel Begunkov 86a9ce66fSPavel Begunkov #include "rsrc.h" 96a9ce66fSPavel Begunkov 10eb4a299bSPavel Begunkov #define IO_NOTIF_SPLICE_BATCH 32 11eb4a299bSPavel Begunkov 1214b146b6SPavel Begunkov struct io_notif_data { 1314b146b6SPavel Begunkov struct file *file; 14eb42cebbSPavel Begunkov struct ubuf_info uarg; 156a9ce66fSPavel Begunkov unsigned long account_pages; 16*e307e669SStefan Metzmacher bool zc_report; 17*e307e669SStefan Metzmacher bool zc_used; 18*e307e669SStefan Metzmacher bool zc_copied; 19eb42cebbSPavel Begunkov }; 20eb42cebbSPavel Begunkov 21b48c312bSPavel Begunkov void io_notif_flush(struct io_kiocb *notif); 22b48c312bSPavel Begunkov struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx); 23eb42cebbSPavel Begunkov 2414b146b6SPavel Begunkov static inline struct io_notif_data *io_notif_to_data(struct io_kiocb *notif) 2514b146b6SPavel Begunkov { 26f2ccb5aeSStefan Metzmacher return io_kiocb_to_cmd(notif, struct io_notif_data); 2714b146b6SPavel Begunkov } 2814b146b6SPavel Begunkov 2914b146b6SPavel Begunkov static inline int io_notif_account_mem(struct io_kiocb *notif, unsigned len) 306a9ce66fSPavel Begunkov { 316a9ce66fSPavel Begunkov struct io_ring_ctx *ctx = notif->ctx; 3214b146b6SPavel Begunkov struct io_notif_data *nd = io_notif_to_data(notif); 336a9ce66fSPavel Begunkov unsigned nr_pages = (len >> PAGE_SHIFT) + 2; 346a9ce66fSPavel Begunkov int ret; 356a9ce66fSPavel Begunkov 366a9ce66fSPavel Begunkov if (ctx->user) { 376a9ce66fSPavel Begunkov ret = __io_account_mem(ctx->user, nr_pages); 386a9ce66fSPavel Begunkov if (ret) 396a9ce66fSPavel Begunkov return ret; 4014b146b6SPavel Begunkov nd->account_pages += nr_pages; 416a9ce66fSPavel Begunkov } 426a9ce66fSPavel Begunkov return 0; 436a9ce66fSPavel Begunkov } 44