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.

io_uring: separate out file table handling code

Signed-off-by: Jens Axboe <axboe@kernel.dk>

+117 -93
+1 -1
io_uring/Makefile
··· 3 3 # Makefile for io_uring 4 4 5 5 obj-$(CONFIG_IO_URING) += io_uring.o xattr.o nop.o fs.o splice.o \ 6 - sync.o advise.o 6 + sync.o advise.o filetable.o 7 7 obj-$(CONFIG_IO_WQ) += io-wq.o
+57
io_uring/filetable.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <linux/kernel.h> 3 + #include <linux/errno.h> 4 + #include <linux/file.h> 5 + #include <linux/mm.h> 6 + #include <linux/slab.h> 7 + #include <linux/io_uring.h> 8 + 9 + #include <uapi/linux/io_uring.h> 10 + 11 + #include "io_uring_types.h" 12 + #include "io_uring.h" 13 + 14 + int io_file_bitmap_get(struct io_ring_ctx *ctx) 15 + { 16 + struct io_file_table *table = &ctx->file_table; 17 + unsigned long nr = ctx->nr_user_files; 18 + int ret; 19 + 20 + do { 21 + ret = find_next_zero_bit(table->bitmap, nr, table->alloc_hint); 22 + if (ret != nr) 23 + return ret; 24 + 25 + if (!table->alloc_hint) 26 + break; 27 + 28 + nr = table->alloc_hint; 29 + table->alloc_hint = 0; 30 + } while (1); 31 + 32 + return -ENFILE; 33 + } 34 + 35 + bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files) 36 + { 37 + table->files = kvcalloc(nr_files, sizeof(table->files[0]), 38 + GFP_KERNEL_ACCOUNT); 39 + if (unlikely(!table->files)) 40 + return false; 41 + 42 + table->bitmap = bitmap_zalloc(nr_files, GFP_KERNEL_ACCOUNT); 43 + if (unlikely(!table->bitmap)) { 44 + kvfree(table->files); 45 + return false; 46 + } 47 + 48 + return true; 49 + } 50 + 51 + void io_free_file_tables(struct io_file_table *table) 52 + { 53 + kvfree(table->files); 54 + bitmap_free(table->bitmap); 55 + table->files = NULL; 56 + table->bitmap = NULL; 57 + }
+58
io_uring/filetable.h
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #ifndef IOU_FILE_TABLE_H 3 + #define IOU_FILE_TABLE_H 4 + 5 + struct io_ring_ctx; 6 + 7 + /* 8 + * FFS_SCM is only available on 64-bit archs, for 32-bit we just define it as 0 9 + * and define IO_URING_SCM_ALL. For this case, we use SCM for all files as we 10 + * can't safely always dereference the file when the task has exited and ring 11 + * cleanup is done. If a file is tracked and part of SCM, then unix gc on 12 + * process exit may reap it before __io_sqe_files_unregister() is run. 13 + */ 14 + #define FFS_NOWAIT 0x1UL 15 + #define FFS_ISREG 0x2UL 16 + #if defined(CONFIG_64BIT) 17 + #define FFS_SCM 0x4UL 18 + #else 19 + #define IO_URING_SCM_ALL 20 + #define FFS_SCM 0x0UL 21 + #endif 22 + #define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG|FFS_SCM) 23 + 24 + struct io_fixed_file { 25 + /* file * with additional FFS_* flags */ 26 + unsigned long file_ptr; 27 + }; 28 + 29 + struct io_file_table { 30 + struct io_fixed_file *files; 31 + unsigned long *bitmap; 32 + unsigned int alloc_hint; 33 + }; 34 + 35 + bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files); 36 + void io_free_file_tables(struct io_file_table *table); 37 + int io_file_bitmap_get(struct io_ring_ctx *ctx); 38 + 39 + static inline void io_file_bitmap_clear(struct io_file_table *table, int bit) 40 + { 41 + __clear_bit(bit, table->bitmap); 42 + table->alloc_hint = bit; 43 + } 44 + 45 + static inline void io_file_bitmap_set(struct io_file_table *table, int bit) 46 + { 47 + WARN_ON_ONCE(test_bit(bit, table->bitmap)); 48 + __set_bit(bit, table->bitmap); 49 + table->alloc_hint = bit + 1; 50 + } 51 + 52 + static inline struct io_fixed_file * 53 + io_fixed_file_slot(struct io_file_table *table, unsigned i) 54 + { 55 + return &table->files[i]; 56 + } 57 + 58 + #endif
-86
io_uring/io_uring.c
··· 146 146 struct io_uring_cqe cqe; 147 147 }; 148 148 149 - /* 150 - * FFS_SCM is only available on 64-bit archs, for 32-bit we just define it as 0 151 - * and define IO_URING_SCM_ALL. For this case, we use SCM for all files as we 152 - * can't safely always dereference the file when the task has exited and ring 153 - * cleanup is done. If a file is tracked and part of SCM, then unix gc on 154 - * process exit may reap it before __io_sqe_files_unregister() is run. 155 - */ 156 - #define FFS_NOWAIT 0x1UL 157 - #define FFS_ISREG 0x2UL 158 - #if defined(CONFIG_64BIT) 159 - #define FFS_SCM 0x4UL 160 - #else 161 - #define IO_URING_SCM_ALL 162 - #define FFS_SCM 0x0UL 163 - #endif 164 - #define FFS_MASK ~(FFS_NOWAIT|FFS_ISREG|FFS_SCM) 165 - 166 - struct io_fixed_file { 167 - /* file * with additional FFS_* flags */ 168 - unsigned long file_ptr; 169 - }; 170 - 171 149 struct io_rsrc_put { 172 150 struct list_head list; 173 151 u64 tag; ··· 3961 3983 return __io_openat_prep(req, sqe); 3962 3984 } 3963 3985 3964 - static int io_file_bitmap_get(struct io_ring_ctx *ctx) 3965 - { 3966 - struct io_file_table *table = &ctx->file_table; 3967 - unsigned long nr = ctx->nr_user_files; 3968 - int ret; 3969 - 3970 - do { 3971 - ret = find_next_zero_bit(table->bitmap, nr, table->alloc_hint); 3972 - if (ret != nr) 3973 - return ret; 3974 - 3975 - if (!table->alloc_hint) 3976 - break; 3977 - 3978 - nr = table->alloc_hint; 3979 - table->alloc_hint = 0; 3980 - } while (1); 3981 - 3982 - return -ENFILE; 3983 - } 3984 - 3985 3986 /* 3986 3987 * Note when io_fixed_fd_install() returns error value, it will ensure 3987 3988 * fput() is called correspondingly. ··· 6789 6832 io_req_task_queue_fail(req, ret); 6790 6833 } 6791 6834 6792 - static inline struct io_fixed_file *io_fixed_file_slot(struct io_file_table *table, 6793 - unsigned i) 6794 - { 6795 - return &table->files[i]; 6796 - } 6797 - 6798 6835 static inline struct file *io_file_from_index(struct io_ring_ctx *ctx, 6799 6836 int index) 6800 6837 { ··· 7883 7932 fail: 7884 7933 io_rsrc_data_free(data); 7885 7934 return ret; 7886 - } 7887 - 7888 - static bool io_alloc_file_tables(struct io_file_table *table, unsigned nr_files) 7889 - { 7890 - table->files = kvcalloc(nr_files, sizeof(table->files[0]), 7891 - GFP_KERNEL_ACCOUNT); 7892 - if (unlikely(!table->files)) 7893 - return false; 7894 - 7895 - table->bitmap = bitmap_zalloc(nr_files, GFP_KERNEL_ACCOUNT); 7896 - if (unlikely(!table->bitmap)) { 7897 - kvfree(table->files); 7898 - return false; 7899 - } 7900 - 7901 - return true; 7902 - } 7903 - 7904 - static void io_free_file_tables(struct io_file_table *table) 7905 - { 7906 - kvfree(table->files); 7907 - bitmap_free(table->bitmap); 7908 - table->files = NULL; 7909 - table->bitmap = NULL; 7910 - } 7911 - 7912 - static inline void io_file_bitmap_set(struct io_file_table *table, int bit) 7913 - { 7914 - WARN_ON_ONCE(test_bit(bit, table->bitmap)); 7915 - __set_bit(bit, table->bitmap); 7916 - table->alloc_hint = bit + 1; 7917 - } 7918 - 7919 - static inline void io_file_bitmap_clear(struct io_file_table *table, int bit) 7920 - { 7921 - __clear_bit(bit, table->bitmap); 7922 - table->alloc_hint = bit; 7923 7935 } 7924 7936 7925 7937 static void __io_sqe_files_unregister(struct io_ring_ctx *ctx)
+1 -6
io_uring/io_uring_types.h
··· 5 5 #include <linux/task_work.h> 6 6 7 7 #include "io-wq.h" 8 + #include "filetable.h" 8 9 9 10 struct io_uring { 10 11 u32 head ____cacheline_aligned_in_smp; ··· 121 120 struct eventfd_ctx *cq_ev_fd; 122 121 unsigned int eventfd_async: 1; 123 122 struct rcu_head rcu; 124 - }; 125 - 126 - struct io_file_table { 127 - struct io_fixed_file *files; 128 - unsigned long *bitmap; 129 - unsigned int alloc_hint; 130 123 }; 131 124 132 125 struct io_ring_ctx {