notif.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/net.h>
  3. #include <linux/uio.h>
  4. #include <net/sock.h>
  5. #include <linux/nospec.h>
  6. #include "rsrc.h"
  7. #define IO_NOTIF_UBUF_FLAGS (SKBFL_ZEROCOPY_FRAG | SKBFL_DONT_ORPHAN)
  8. #define IO_NOTIF_SPLICE_BATCH 32
  9. struct io_notif_data {
  10. struct file *file;
  11. struct ubuf_info uarg;
  12. struct io_notif_data *next;
  13. struct io_notif_data *head;
  14. unsigned account_pages;
  15. bool zc_report;
  16. bool zc_used;
  17. bool zc_copied;
  18. };
  19. struct io_kiocb *io_alloc_notif(struct io_ring_ctx *ctx);
  20. void io_tx_ubuf_complete(struct sk_buff *skb, struct ubuf_info *uarg,
  21. bool success);
  22. static inline struct io_notif_data *io_notif_to_data(struct io_kiocb *notif)
  23. {
  24. return io_kiocb_to_cmd(notif, struct io_notif_data);
  25. }
  26. static inline void io_notif_flush(struct io_kiocb *notif)
  27. __must_hold(&notif->ctx->uring_lock)
  28. {
  29. struct io_notif_data *nd = io_notif_to_data(notif);
  30. io_tx_ubuf_complete(NULL, &nd->uarg, true);
  31. }
  32. static inline int io_notif_account_mem(struct io_kiocb *notif, unsigned len)
  33. {
  34. struct io_ring_ctx *ctx = notif->ctx;
  35. struct io_notif_data *nd = io_notif_to_data(notif);
  36. unsigned nr_pages = (len >> PAGE_SHIFT) + 2;
  37. int ret;
  38. if (ctx->user) {
  39. ret = __io_account_mem(ctx->user, nr_pages);
  40. if (ret)
  41. return ret;
  42. nd->account_pages += nr_pages;
  43. }
  44. return 0;
  45. }