diff --git a/fs/io_uring.c b/fs/io_uring.c index 0f0c052aea49a5004730550dd03860f07304dbd5..6b13efe414bcda9c4137e943b94faed035137182 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2931,6 +2931,14 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode, { int ret; + /* + * We're inside the ring mutex, if the ref is already dying, then + * someone else killed the ctx or is already going through + * io_uring_register(). + */ + if (percpu_ref_is_dying(&ctx->refs)) + return -ENXIO; + percpu_ref_kill(&ctx->refs); /*