static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
{
	mutex_lock(&ctx->uring_lock);
	percpu_ref_kill(&ctx->refs);
	mutex_unlock(&ctx->uring_lock);

	/*
	 * Wait for sq thread to idle, if we have one. It won't spin on new
	 * work after we've killed the ctx ref above. This is important to do
	 * before we cancel existing commands, as the thread could otherwise
	 * be queueing new work post that. If that's work we need to cancel,
	 * it could cause shutdown to hang.
	 */
	while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait))
		cpu_relax();

	io_kill_timeouts(ctx);
	io_poll_remove_all(ctx);

	if (ctx->io_wq)
		io_wq_cancel_all(ctx->io_wq);

	io_iopoll_reap_events(ctx);
	/* if we failed setting up the ctx, we might not have any rings */
	if (ctx->rings)
		io_cqring_overflow_flush(ctx, true);
	idr_for_each(&ctx->personality_idr, io_remove_personalities, ctx);
	wait_for_completion(&ctx->completions[0]);
	io_ring_ctx_free(ctx);
}
static void io_ring_ctx_wait_and_kill(struct io_ring_ctx *ctx)
{
	mutex_lock(&ctx->uring_lock);
	percpu_ref_kill(&ctx->refs);
	mutex_unlock(&ctx->uring_lock);

	 
	while (ctx->sqo_thread && !wq_has_sleeper(&ctx->sqo_wait))
		cpu_relax();

	io_kill_timeouts(ctx);
	io_poll_remove_all(ctx);

	if (ctx->io_wq)
		io_wq_cancel_all(ctx->io_wq);

	io_iopoll_reap_events(ctx);
	 
	if (ctx->rings)
		io_cqring_overflow_flush(ctx, true);
	idr_for_each(&ctx->personality_idr, io_remove_personalities, ctx);
	wait_for_completion(&ctx->completions[0]);
	io_ring_ctx_free(ctx);
}