@@ -697,20 +697,11 @@ static __cold void io_uring_drop_tctx_refs(struct task_struct *task)
697
697
}
698
698
}
699
699
700
- static bool io_cqring_event_overflow (struct io_ring_ctx * ctx , u64 user_data ,
701
- s32 res , u32 cflags , u64 extra1 , u64 extra2 )
700
+ static bool io_cqring_add_overflow (struct io_ring_ctx * ctx ,
701
+ struct io_overflow_cqe * ocqe )
702
702
{
703
- struct io_overflow_cqe * ocqe ;
704
- size_t ocq_size = sizeof (struct io_overflow_cqe );
705
- bool is_cqe32 = (ctx -> flags & IORING_SETUP_CQE32 );
706
-
707
703
lockdep_assert_held (& ctx -> completion_lock );
708
704
709
- if (is_cqe32 )
710
- ocq_size += sizeof (struct io_uring_cqe );
711
-
712
- ocqe = kmalloc (ocq_size , GFP_ATOMIC | __GFP_ACCOUNT );
713
- trace_io_uring_cqe_overflow (ctx , user_data , res , cflags , ocqe );
714
705
if (!ocqe ) {
715
706
struct io_rings * r = ctx -> rings ;
716
707
@@ -728,17 +719,35 @@ static bool io_cqring_event_overflow(struct io_ring_ctx *ctx, u64 user_data,
728
719
atomic_or (IORING_SQ_CQ_OVERFLOW , & ctx -> rings -> sq_flags );
729
720
730
721
}
731
- ocqe -> cqe .user_data = user_data ;
732
- ocqe -> cqe .res = res ;
733
- ocqe -> cqe .flags = cflags ;
734
- if (is_cqe32 ) {
735
- ocqe -> cqe .big_cqe [0 ] = extra1 ;
736
- ocqe -> cqe .big_cqe [1 ] = extra2 ;
737
- }
738
722
list_add_tail (& ocqe -> list , & ctx -> cq_overflow_list );
739
723
return true;
740
724
}
741
725
726
+ static struct io_overflow_cqe * io_alloc_ocqe (struct io_ring_ctx * ctx ,
727
+ u64 user_data , s32 res , u32 cflags ,
728
+ u64 extra1 , u64 extra2 , gfp_t gfp )
729
+ {
730
+ struct io_overflow_cqe * ocqe ;
731
+ size_t ocq_size = sizeof (struct io_overflow_cqe );
732
+ bool is_cqe32 = (ctx -> flags & IORING_SETUP_CQE32 );
733
+
734
+ if (is_cqe32 )
735
+ ocq_size += sizeof (struct io_uring_cqe );
736
+
737
+ ocqe = kmalloc (ocq_size , gfp | __GFP_ACCOUNT );
738
+ trace_io_uring_cqe_overflow (ctx , user_data , res , cflags , ocqe );
739
+ if (ocqe ) {
740
+ ocqe -> cqe .user_data = user_data ;
741
+ ocqe -> cqe .res = res ;
742
+ ocqe -> cqe .flags = cflags ;
743
+ if (is_cqe32 ) {
744
+ ocqe -> cqe .big_cqe [0 ] = extra1 ;
745
+ ocqe -> cqe .big_cqe [1 ] = extra2 ;
746
+ }
747
+ }
748
+ return ocqe ;
749
+ }
750
+
742
751
/*
743
752
* writes to the cq entry need to come after reading head; the
744
753
* control dependency is enough as we're using WRITE_ONCE to
@@ -803,8 +812,12 @@ bool io_post_aux_cqe(struct io_ring_ctx *ctx, u64 user_data, s32 res, u32 cflags
803
812
804
813
io_cq_lock (ctx );
805
814
filled = io_fill_cqe_aux (ctx , user_data , res , cflags );
806
- if (!filled )
807
- filled = io_cqring_event_overflow (ctx , user_data , res , cflags , 0 , 0 );
815
+ if (unlikely (!filled )) {
816
+ struct io_overflow_cqe * ocqe ;
817
+
818
+ ocqe = io_alloc_ocqe (ctx , user_data , res , cflags , 0 , 0 , GFP_ATOMIC );
819
+ filled = io_cqring_add_overflow (ctx , ocqe );
820
+ }
808
821
io_cq_unlock_post (ctx );
809
822
return filled ;
810
823
}
@@ -819,8 +832,11 @@ void io_add_aux_cqe(struct io_ring_ctx *ctx, u64 user_data, s32 res, u32 cflags)
819
832
lockdep_assert (ctx -> lockless_cq );
820
833
821
834
if (!io_fill_cqe_aux (ctx , user_data , res , cflags )) {
835
+ struct io_overflow_cqe * ocqe ;
836
+
837
+ ocqe = io_alloc_ocqe (ctx , user_data , res , cflags , 0 , 0 , GFP_KERNEL );
822
838
spin_lock (& ctx -> completion_lock );
823
- io_cqring_event_overflow (ctx , user_data , res , cflags , 0 , 0 );
839
+ io_cqring_add_overflow (ctx , ocqe );
824
840
spin_unlock (& ctx -> completion_lock );
825
841
}
826
842
ctx -> submit_state .cq_flush = true;
@@ -1425,18 +1441,18 @@ void __io_submit_flush_completions(struct io_ring_ctx *ctx)
1425
1441
*/
1426
1442
if (!(req -> flags & (REQ_F_CQE_SKIP | REQ_F_REISSUE )) &&
1427
1443
unlikely (!io_fill_cqe_req (ctx , req ))) {
1444
+ gfp_t gfp = ctx -> lockless_cq ? GFP_KERNEL : GFP_ATOMIC ;
1445
+ struct io_overflow_cqe * ocqe ;
1446
+
1447
+ ocqe = io_alloc_ocqe (ctx , req -> cqe .user_data , req -> cqe .res ,
1448
+ req -> cqe .flags , req -> big_cqe .extra1 ,
1449
+ req -> big_cqe .extra2 , gfp );
1428
1450
if (ctx -> lockless_cq ) {
1429
1451
spin_lock (& ctx -> completion_lock );
1430
- io_cqring_event_overflow (req -> ctx , req -> cqe .user_data ,
1431
- req -> cqe .res , req -> cqe .flags ,
1432
- req -> big_cqe .extra1 ,
1433
- req -> big_cqe .extra2 );
1452
+ io_cqring_add_overflow (ctx , ocqe );
1434
1453
spin_unlock (& ctx -> completion_lock );
1435
1454
} else {
1436
- io_cqring_event_overflow (req -> ctx , req -> cqe .user_data ,
1437
- req -> cqe .res , req -> cqe .flags ,
1438
- req -> big_cqe .extra1 ,
1439
- req -> big_cqe .extra2 );
1455
+ io_cqring_add_overflow (ctx , ocqe );
1440
1456
}
1441
1457
1442
1458
memset (& req -> big_cqe , 0 , sizeof (req -> big_cqe ));
0 commit comments