Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at 4563243edeeb3dc17355a80ec16bbfdc675702cb 145 lines 4.0 kB view raw
1// SPDX-License-Identifier: GPL-2.0 2#ifndef IOU_RSRC_H 3#define IOU_RSRC_H 4 5#define IO_NODE_ALLOC_CACHE_MAX 32 6 7#define IO_RSRC_TAG_TABLE_SHIFT (PAGE_SHIFT - 3) 8#define IO_RSRC_TAG_TABLE_MAX (1U << IO_RSRC_TAG_TABLE_SHIFT) 9#define IO_RSRC_TAG_TABLE_MASK (IO_RSRC_TAG_TABLE_MAX - 1) 10 11enum { 12 IORING_RSRC_FILE = 0, 13 IORING_RSRC_BUFFER = 1, 14}; 15 16struct io_rsrc_put { 17 u64 tag; 18 union { 19 void *rsrc; 20 struct file *file; 21 struct io_mapped_ubuf *buf; 22 }; 23}; 24 25struct io_rsrc_data { 26 struct io_ring_ctx *ctx; 27 28 u64 **tags; 29 unsigned int nr; 30 u16 rsrc_type; 31 bool quiesce; 32}; 33 34struct io_rsrc_node { 35 struct io_ring_ctx *ctx; 36 int refs; 37 bool empty; 38 u16 type; 39 struct list_head node; 40 struct io_rsrc_put item; 41}; 42 43struct io_mapped_ubuf { 44 u64 ubuf; 45 unsigned int len; 46 unsigned int nr_bvecs; 47 unsigned int folio_shift; 48 refcount_t refs; 49 unsigned long acct_pages; 50 struct bio_vec bvec[] __counted_by(nr_bvecs); 51}; 52 53struct io_imu_folio_data { 54 /* Head folio can be partially included in the fixed buf */ 55 unsigned int nr_pages_head; 56 /* For non-head/tail folios, has to be fully included */ 57 unsigned int nr_pages_mid; 58 unsigned int folio_shift; 59}; 60 61void io_rsrc_node_ref_zero(struct io_rsrc_node *node); 62void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *ref_node); 63struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx); 64int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx, void *rsrc); 65 66int io_import_fixed(int ddir, struct iov_iter *iter, 67 struct io_mapped_ubuf *imu, 68 u64 buf_addr, size_t len); 69 70int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg); 71void __io_sqe_buffers_unregister(struct io_ring_ctx *ctx); 72int io_sqe_buffers_unregister(struct io_ring_ctx *ctx); 73int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg, 74 unsigned int nr_args, u64 __user *tags); 75void __io_sqe_files_unregister(struct io_ring_ctx *ctx); 76int io_sqe_files_unregister(struct io_ring_ctx *ctx); 77int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg, 78 unsigned nr_args, u64 __user *tags); 79 80int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg, 81 unsigned nr_args); 82int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg, 83 unsigned size, unsigned type); 84int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg, 85 unsigned int size, unsigned int type); 86 87static inline void io_put_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node) 88{ 89 lockdep_assert_held(&ctx->uring_lock); 90 91 if (node && !--node->refs) 92 io_rsrc_node_ref_zero(node); 93} 94 95static inline void io_charge_rsrc_node(struct io_ring_ctx *ctx, 96 struct io_rsrc_node *node) 97{ 98 node->refs++; 99} 100 101static inline void __io_req_set_rsrc_node(struct io_kiocb *req, 102 struct io_ring_ctx *ctx) 103{ 104 lockdep_assert_held(&ctx->uring_lock); 105 req->rsrc_node = ctx->rsrc_node; 106 io_charge_rsrc_node(ctx, ctx->rsrc_node); 107} 108 109static inline void io_req_set_rsrc_node(struct io_kiocb *req, 110 struct io_ring_ctx *ctx, 111 unsigned int issue_flags) 112{ 113 if (!req->rsrc_node) { 114 io_ring_submit_lock(ctx, issue_flags); 115 __io_req_set_rsrc_node(req, ctx); 116 io_ring_submit_unlock(ctx, issue_flags); 117 } 118} 119 120static inline u64 *io_get_tag_slot(struct io_rsrc_data *data, unsigned int idx) 121{ 122 unsigned int off = idx & IO_RSRC_TAG_TABLE_MASK; 123 unsigned int table_idx = idx >> IO_RSRC_TAG_TABLE_SHIFT; 124 125 return &data->tags[table_idx][off]; 126} 127 128static inline int io_rsrc_init(struct io_ring_ctx *ctx) 129{ 130 ctx->rsrc_node = io_rsrc_node_alloc(ctx); 131 return ctx->rsrc_node ? 0 : -ENOMEM; 132} 133 134int io_files_update(struct io_kiocb *req, unsigned int issue_flags); 135int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe); 136 137int __io_account_mem(struct user_struct *user, unsigned long nr_pages); 138 139static inline void __io_unaccount_mem(struct user_struct *user, 140 unsigned long nr_pages) 141{ 142 atomic_long_sub(nr_pages, &user->locked_vm); 143} 144 145#endif