~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/io_uring/rsrc.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 
 11 enum {
 12         IORING_RSRC_FILE                = 0,
 13         IORING_RSRC_BUFFER              = 1,
 14 };
 15 
 16 struct io_rsrc_put {
 17         u64 tag;
 18         union {
 19                 void *rsrc;
 20                 struct file *file;
 21                 struct io_mapped_ubuf *buf;
 22         };
 23 };
 24 
 25 typedef void (rsrc_put_fn)(struct io_ring_ctx *ctx, struct io_rsrc_put *prsrc);
 26 
 27 struct io_rsrc_data {
 28         struct io_ring_ctx              *ctx;
 29 
 30         u64                             **tags;
 31         unsigned int                    nr;
 32         u16                             rsrc_type;
 33         bool                            quiesce;
 34 };
 35 
 36 struct io_rsrc_node {
 37         struct io_ring_ctx              *ctx;
 38         int                             refs;
 39         bool                            empty;
 40         u16                             type;
 41         struct list_head                node;
 42         struct io_rsrc_put              item;
 43 };
 44 
 45 struct io_mapped_ubuf {
 46         u64             ubuf;
 47         u64             ubuf_end;
 48         unsigned int    nr_bvecs;
 49         unsigned long   acct_pages;
 50         struct bio_vec  bvec[] __counted_by(nr_bvecs);
 51 };
 52 
 53 void io_rsrc_node_ref_zero(struct io_rsrc_node *node);
 54 void io_rsrc_node_destroy(struct io_ring_ctx *ctx, struct io_rsrc_node *ref_node);
 55 struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx);
 56 int io_queue_rsrc_removal(struct io_rsrc_data *data, unsigned idx, void *rsrc);
 57 
 58 int io_import_fixed(int ddir, struct iov_iter *iter,
 59                            struct io_mapped_ubuf *imu,
 60                            u64 buf_addr, size_t len);
 61 
 62 void __io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
 63 int io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
 64 int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
 65                             unsigned int nr_args, u64 __user *tags);
 66 void __io_sqe_files_unregister(struct io_ring_ctx *ctx);
 67 int io_sqe_files_unregister(struct io_ring_ctx *ctx);
 68 int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
 69                           unsigned nr_args, u64 __user *tags);
 70 
 71 int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
 72                              unsigned nr_args);
 73 int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
 74                             unsigned size, unsigned type);
 75 int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
 76                         unsigned int size, unsigned int type);
 77 
 78 static inline void io_put_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
 79 {
 80         lockdep_assert_held(&ctx->uring_lock);
 81 
 82         if (node && !--node->refs)
 83                 io_rsrc_node_ref_zero(node);
 84 }
 85 
 86 static inline void io_charge_rsrc_node(struct io_ring_ctx *ctx,
 87                                        struct io_rsrc_node *node)
 88 {
 89         node->refs++;
 90 }
 91 
 92 static inline void __io_req_set_rsrc_node(struct io_kiocb *req,
 93                                           struct io_ring_ctx *ctx)
 94 {
 95         lockdep_assert_held(&ctx->uring_lock);
 96         req->rsrc_node = ctx->rsrc_node;
 97         io_charge_rsrc_node(ctx, ctx->rsrc_node);
 98 }
 99 
100 static inline void io_req_set_rsrc_node(struct io_kiocb *req,
101                                         struct io_ring_ctx *ctx,
102                                         unsigned int issue_flags)
103 {
104         if (!req->rsrc_node) {
105                 io_ring_submit_lock(ctx, issue_flags);
106                 __io_req_set_rsrc_node(req, ctx);
107                 io_ring_submit_unlock(ctx, issue_flags);
108         }
109 }
110 
111 static inline u64 *io_get_tag_slot(struct io_rsrc_data *data, unsigned int idx)
112 {
113         unsigned int off = idx & IO_RSRC_TAG_TABLE_MASK;
114         unsigned int table_idx = idx >> IO_RSRC_TAG_TABLE_SHIFT;
115 
116         return &data->tags[table_idx][off];
117 }
118 
119 static inline int io_rsrc_init(struct io_ring_ctx *ctx)
120 {
121         ctx->rsrc_node = io_rsrc_node_alloc(ctx);
122         return ctx->rsrc_node ? 0 : -ENOMEM;
123 }
124 
125 int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
126 int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
127 
128 int __io_account_mem(struct user_struct *user, unsigned long nr_pages);
129 
130 static inline void __io_unaccount_mem(struct user_struct *user,
131                                       unsigned long nr_pages)
132 {
133         atomic_long_sub(nr_pages, &user->locked_vm);
134 }
135 
136 #endif
137 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php