@@ -680,8 +680,6 @@ struct io_op_def {
680
680
unsigned needs_mm : 1 ;
681
681
/* needs req->file assigned */
682
682
unsigned needs_file : 1 ;
683
- /* needs req->file assigned IFF fd is >= 0 */
684
- unsigned fd_non_neg : 1 ;
685
683
/* hash wq insertion if file is a regular file */
686
684
unsigned hash_reg_file : 1 ;
687
685
/* unbound wq insertion if file is a non-regular file */
@@ -784,8 +782,6 @@ static const struct io_op_def io_op_defs[] = {
784
782
.needs_file = 1 ,
785
783
},
786
784
[IORING_OP_OPENAT ] = {
787
- .needs_file = 1 ,
788
- .fd_non_neg = 1 ,
789
785
.file_table = 1 ,
790
786
.needs_fs = 1 ,
791
787
},
@@ -799,8 +795,6 @@ static const struct io_op_def io_op_defs[] = {
799
795
},
800
796
[IORING_OP_STATX ] = {
801
797
.needs_mm = 1 ,
802
- .needs_file = 1 ,
803
- .fd_non_neg = 1 ,
804
798
.needs_fs = 1 ,
805
799
.file_table = 1 ,
806
800
},
@@ -837,8 +831,6 @@ static const struct io_op_def io_op_defs[] = {
837
831
.buffer_select = 1 ,
838
832
},
839
833
[IORING_OP_OPENAT2 ] = {
840
- .needs_file = 1 ,
841
- .fd_non_neg = 1 ,
842
834
.file_table = 1 ,
843
835
.needs_fs = 1 ,
844
836
},
@@ -5368,15 +5360,6 @@ static void io_wq_submit_work(struct io_wq_work **workptr)
5368
5360
io_steal_work (req , workptr );
5369
5361
}
5370
5362
5371
- static int io_req_needs_file (struct io_kiocb * req , int fd )
5372
- {
5373
- if (!io_op_defs [req -> opcode ].needs_file )
5374
- return 0 ;
5375
- if ((fd == -1 || fd == AT_FDCWD ) && io_op_defs [req -> opcode ].fd_non_neg )
5376
- return 0 ;
5377
- return 1 ;
5378
- }
5379
-
5380
5363
static inline struct file * io_file_from_index (struct io_ring_ctx * ctx ,
5381
5364
int index )
5382
5365
{
@@ -5414,14 +5397,11 @@ static int io_file_get(struct io_submit_state *state, struct io_kiocb *req,
5414
5397
}
5415
5398
5416
5399
static int io_req_set_file (struct io_submit_state * state , struct io_kiocb * req ,
5417
- int fd , unsigned int flags )
5400
+ int fd )
5418
5401
{
5419
5402
bool fixed ;
5420
5403
5421
- if (!io_req_needs_file (req , fd ))
5422
- return 0 ;
5423
-
5424
- fixed = (flags & IOSQE_FIXED_FILE );
5404
+ fixed = (req -> flags & REQ_F_FIXED_FILE ) != 0 ;
5425
5405
if (unlikely (!fixed && req -> needs_fixed_file ))
5426
5406
return - EBADF ;
5427
5407
@@ -5798,7 +5778,7 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
5798
5778
struct io_submit_state * state , bool async )
5799
5779
{
5800
5780
unsigned int sqe_flags ;
5801
- int id , fd ;
5781
+ int id ;
5802
5782
5803
5783
/*
5804
5784
* All io need record the previous position, if LINK vs DARIN,
@@ -5850,8 +5830,10 @@ static int io_init_req(struct io_ring_ctx *ctx, struct io_kiocb *req,
5850
5830
IOSQE_ASYNC | IOSQE_FIXED_FILE |
5851
5831
IOSQE_BUFFER_SELECT | IOSQE_IO_LINK );
5852
5832
5853
- fd = READ_ONCE (sqe -> fd );
5854
- return io_req_set_file (state , req , fd , sqe_flags );
5833
+ if (!io_op_defs [req -> opcode ].needs_file )
5834
+ return 0 ;
5835
+
5836
+ return io_req_set_file (state , req , READ_ONCE (sqe -> fd ));
5855
5837
}
5856
5838
5857
5839
static int io_submit_sqes (struct io_ring_ctx * ctx , unsigned int nr ,
@@ -7360,11 +7342,9 @@ static int io_uring_release(struct inode *inode, struct file *file)
7360
7342
static void io_uring_cancel_files (struct io_ring_ctx * ctx ,
7361
7343
struct files_struct * files )
7362
7344
{
7363
- struct io_kiocb * req ;
7364
- DEFINE_WAIT (wait );
7365
-
7366
7345
while (!list_empty_careful (& ctx -> inflight_list )) {
7367
- struct io_kiocb * cancel_req = NULL ;
7346
+ struct io_kiocb * cancel_req = NULL , * req ;
7347
+ DEFINE_WAIT (wait );
7368
7348
7369
7349
spin_lock_irq (& ctx -> inflight_lock );
7370
7350
list_for_each_entry (req , & ctx -> inflight_list , inflight_entry ) {
@@ -7404,15 +7384,16 @@ static void io_uring_cancel_files(struct io_ring_ctx *ctx,
7404
7384
*/
7405
7385
if (refcount_sub_and_test (2 , & cancel_req -> refs )) {
7406
7386
io_put_req (cancel_req );
7387
+ finish_wait (& ctx -> inflight_wait , & wait );
7407
7388
continue ;
7408
7389
}
7409
7390
}
7410
7391
7411
7392
io_wq_cancel_work (ctx -> io_wq , & cancel_req -> work );
7412
7393
io_put_req (cancel_req );
7413
7394
schedule ();
7395
+ finish_wait (& ctx -> inflight_wait , & wait );
7414
7396
}
7415
- finish_wait (& ctx -> inflight_wait , & wait );
7416
7397
}
7417
7398
7418
7399
static int io_uring_flush (struct file * file , void * data )
@@ -7761,7 +7742,8 @@ static int io_uring_get_fd(struct io_ring_ctx *ctx)
7761
7742
return ret ;
7762
7743
}
7763
7744
7764
- static int io_uring_create (unsigned entries , struct io_uring_params * p )
7745
+ static int io_uring_create (unsigned entries , struct io_uring_params * p ,
7746
+ struct io_uring_params __user * params )
7765
7747
{
7766
7748
struct user_struct * user = NULL ;
7767
7749
struct io_ring_ctx * ctx ;
@@ -7853,6 +7835,14 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p)
7853
7835
p -> cq_off .overflow = offsetof(struct io_rings , cq_overflow );
7854
7836
p -> cq_off .cqes = offsetof(struct io_rings , cqes );
7855
7837
7838
+ p -> features = IORING_FEAT_SINGLE_MMAP | IORING_FEAT_NODROP |
7839
+ IORING_FEAT_SUBMIT_STABLE | IORING_FEAT_RW_CUR_POS |
7840
+ IORING_FEAT_CUR_PERSONALITY | IORING_FEAT_FAST_POLL ;
7841
+
7842
+ if (copy_to_user (params , p , sizeof (* p ))) {
7843
+ ret = - EFAULT ;
7844
+ goto err ;
7845
+ }
7856
7846
/*
7857
7847
* Install ring fd as the very last thing, so we don't risk someone
7858
7848
* having closed it before we finish setup
@@ -7861,9 +7851,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p)
7861
7851
if (ret < 0 )
7862
7852
goto err ;
7863
7853
7864
- p -> features = IORING_FEAT_SINGLE_MMAP | IORING_FEAT_NODROP |
7865
- IORING_FEAT_SUBMIT_STABLE | IORING_FEAT_RW_CUR_POS |
7866
- IORING_FEAT_CUR_PERSONALITY | IORING_FEAT_FAST_POLL ;
7867
7854
trace_io_uring_create (ret , ctx , p -> sq_entries , p -> cq_entries , p -> flags );
7868
7855
return ret ;
7869
7856
err :
@@ -7879,7 +7866,6 @@ static int io_uring_create(unsigned entries, struct io_uring_params *p)
7879
7866
static long io_uring_setup (u32 entries , struct io_uring_params __user * params )
7880
7867
{
7881
7868
struct io_uring_params p ;
7882
- long ret ;
7883
7869
int i ;
7884
7870
7885
7871
if (copy_from_user (& p , params , sizeof (p )))
@@ -7894,14 +7880,7 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params)
7894
7880
IORING_SETUP_CLAMP | IORING_SETUP_ATTACH_WQ ))
7895
7881
return - EINVAL ;
7896
7882
7897
- ret = io_uring_create (entries , & p );
7898
- if (ret < 0 )
7899
- return ret ;
7900
-
7901
- if (copy_to_user (params , & p , sizeof (p )))
7902
- return - EFAULT ;
7903
-
7904
- return ret ;
7883
+ return io_uring_create (entries , & p , params );
7905
7884
}
7906
7885
7907
7886
SYSCALL_DEFINE2 (io_uring_setup , u32 , entries ,
0 commit comments