@@ -8414,11 +8414,19 @@ static int io_uring_show_cred(int id, void *p, void *data)
8414
8414
8415
8415
static void __io_uring_show_fdinfo (struct io_ring_ctx * ctx , struct seq_file * m )
8416
8416
{
8417
+ bool has_lock ;
8417
8418
int i ;
8418
8419
8419
- mutex_lock (& ctx -> uring_lock );
8420
+ /*
8421
+ * Avoid ABBA deadlock between the seq lock and the io_uring mutex,
8422
+ * since fdinfo case grabs it in the opposite direction of normal use
8423
+ * cases. If we fail to get the lock, we just don't iterate any
8424
+ * structures that could be going away outside the io_uring mutex.
8425
+ */
8426
+ has_lock = mutex_trylock (& ctx -> uring_lock );
8427
+
8420
8428
seq_printf (m , "UserFiles:\t%u\n" , ctx -> nr_user_files );
8421
- for (i = 0 ; i < ctx -> nr_user_files ; i ++ ) {
8429
+ for (i = 0 ; has_lock && i < ctx -> nr_user_files ; i ++ ) {
8422
8430
struct fixed_file_table * table ;
8423
8431
struct file * f ;
8424
8432
@@ -8430,13 +8438,13 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
8430
8438
seq_printf (m , "%5u: <none>\n" , i );
8431
8439
}
8432
8440
seq_printf (m , "UserBufs:\t%u\n" , ctx -> nr_user_bufs );
8433
- for (i = 0 ; i < ctx -> nr_user_bufs ; i ++ ) {
8441
+ for (i = 0 ; has_lock && i < ctx -> nr_user_bufs ; i ++ ) {
8434
8442
struct io_mapped_ubuf * buf = & ctx -> user_bufs [i ];
8435
8443
8436
8444
seq_printf (m , "%5u: 0x%llx/%u\n" , i , buf -> ubuf ,
8437
8445
(unsigned int ) buf -> len );
8438
8446
}
8439
- if (!idr_is_empty (& ctx -> personality_idr )) {
8447
+ if (has_lock && !idr_is_empty (& ctx -> personality_idr )) {
8440
8448
seq_printf (m , "Personalities:\n" );
8441
8449
idr_for_each (& ctx -> personality_idr , io_uring_show_cred , m );
8442
8450
}
@@ -8451,7 +8459,8 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
8451
8459
req -> task -> task_works != NULL );
8452
8460
}
8453
8461
spin_unlock_irq (& ctx -> completion_lock );
8454
- mutex_unlock (& ctx -> uring_lock );
8462
+ if (has_lock )
8463
+ mutex_unlock (& ctx -> uring_lock );
8455
8464
}
8456
8465
8457
8466
static void io_uring_show_fdinfo (struct seq_file * m , struct file * f )
0 commit comments