Unverified Commit 4bba4dd1 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!2095 io_uring: ensure IOPOLL locks around deferred work

parents c61a6ef7 560773de
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -1521,6 +1521,8 @@ static void io_kill_timeout(struct io_kiocb *req, int status)

static void io_queue_deferred(struct io_ring_ctx *ctx)
{
	lockdep_assert_held(&ctx->completion_lock);

	while (!list_empty(&ctx->defer_list)) {
		struct io_defer_entry *de = list_first_entry(&ctx->defer_list,
						struct io_defer_entry, list);
@@ -1572,14 +1574,24 @@ static void __io_commit_cqring_flush(struct io_ring_ctx *ctx)
		io_queue_deferred(ctx);
}

static inline void io_commit_cqring(struct io_ring_ctx *ctx)
static inline bool io_commit_needs_flush(struct io_ring_ctx *ctx)
{
	return ctx->off_timeout_used || ctx->drain_active;
}

static inline void __io_commit_cqring(struct io_ring_ctx *ctx)
{
	if (unlikely(ctx->off_timeout_used || ctx->drain_active))
		__io_commit_cqring_flush(ctx);
	/* order cqe stores with ring update */
	smp_store_release(&ctx->rings->cq.tail, ctx->cached_cq_tail);
}

static inline void io_commit_cqring(struct io_ring_ctx *ctx)
{
	if (unlikely(io_commit_needs_flush(ctx)))
		__io_commit_cqring_flush(ctx);
	__io_commit_cqring(ctx);
}

static inline bool io_sqring_full(struct io_ring_ctx *ctx)
{
	struct io_rings *r = ctx->rings;
@@ -2509,7 +2521,12 @@ static void io_iopoll_complete(struct io_ring_ctx *ctx, unsigned int *nr_events,
			io_req_free_batch(&rb, req, &ctx->submit_state);
	}

	io_commit_cqring(ctx);
	if (io_commit_needs_flush(ctx)) {
		spin_lock(&ctx->completion_lock);
		__io_commit_cqring_flush(ctx);
		spin_unlock(&ctx->completion_lock);
	}
	__io_commit_cqring(ctx);
	io_cqring_ev_posted_iopoll(ctx);
	io_req_free_batch_finish(ctx, &rb);
}