}
 
 /* Returns true if there are no backlogged entries after the flush */
-static bool __io_cqring_overflow_flush(struct io_ring_ctx *ctx, bool force)
+static void io_cqring_overflow_kill(struct io_ring_ctx *ctx)
+{
+       struct io_overflow_cqe *ocqe;
+       LIST_HEAD(list);
+
+       io_cq_lock(ctx);
+       list_splice_init(&ctx->cq_overflow_list, &list);
+       clear_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq);
+       io_cq_unlock(ctx);
+
+       while (!list_empty(&list)) {
+               ocqe = list_first_entry(&list, struct io_overflow_cqe, list);
+               list_del(&ocqe->list);
+               kfree(ocqe);
+       }
+}
+
+/* Returns true if there are no backlogged entries after the flush */
+static bool __io_cqring_overflow_flush(struct io_ring_ctx *ctx)
 {
        bool all_flushed;
        size_t cqe_size = sizeof(struct io_uring_cqe);
 
-       if (!force && __io_cqring_events(ctx) == ctx->cq_entries)
+       if (__io_cqring_events(ctx) == ctx->cq_entries)
                return false;
 
        if (ctx->flags & IORING_SETUP_CQE32)
                struct io_uring_cqe *cqe = io_get_cqe_overflow(ctx, true);
                struct io_overflow_cqe *ocqe;
 
-               if (!cqe && !force)
+               if (!cqe)
                        break;
                ocqe = list_first_entry(&ctx->cq_overflow_list,
                                        struct io_overflow_cqe, list);
-               if (cqe)
-                       memcpy(cqe, &ocqe->cqe, cqe_size);
-               else
-                       io_account_cq_overflow(ctx);
-
+               memcpy(cqe, &ocqe->cqe, cqe_size);
                list_del(&ocqe->list);
                kfree(ocqe);
        }
                /* iopoll syncs against uring_lock, not completion_lock */
                if (ctx->flags & IORING_SETUP_IOPOLL)
                        mutex_lock(&ctx->uring_lock);
-               ret = __io_cqring_overflow_flush(ctx, false);
+               ret = __io_cqring_overflow_flush(ctx);
                if (ctx->flags & IORING_SETUP_IOPOLL)
                        mutex_unlock(&ctx->uring_lock);
        }
        check_cq = READ_ONCE(ctx->check_cq);
        if (unlikely(check_cq)) {
                if (check_cq & BIT(IO_CHECK_CQ_OVERFLOW_BIT))
-                       __io_cqring_overflow_flush(ctx, false);
+                       __io_cqring_overflow_flush(ctx);
                /*
                 * Similarly do not spin if we have not informed the user of any
                 * dropped CQE.
                __io_sqe_buffers_unregister(ctx);
        if (ctx->file_data)
                __io_sqe_files_unregister(ctx);
-       if (ctx->rings)
-               __io_cqring_overflow_flush(ctx, true);
+       io_cqring_overflow_kill(ctx);
        io_eventfd_unregister(ctx);
        io_alloc_cache_free(&ctx->apoll_cache, io_apoll_cache_free);
        io_alloc_cache_free(&ctx->netmsg_cache, io_netmsg_cache_free);
         * as nobody else will be looking for them.
         */
        do {
+               if (test_bit(IO_CHECK_CQ_OVERFLOW_BIT, &ctx->check_cq)) {
+                       mutex_lock(&ctx->uring_lock);
+                       io_cqring_overflow_kill(ctx);
+                       mutex_unlock(&ctx->uring_lock);
+               }
+
                if (ctx->flags & IORING_SETUP_DEFER_TASKRUN)
                        io_move_task_work_from_local(ctx);
 
 
        mutex_lock(&ctx->uring_lock);
        percpu_ref_kill(&ctx->refs);
-       if (ctx->rings)
-               __io_cqring_overflow_flush(ctx, true);
        xa_for_each(&ctx->personalities, index, creds)
                io_unregister_personality(ctx, index);
        if (ctx->rings)