Linux block layer
 help / color / mirror / Atom feed
From: Ming Lei <tom.leiming@gmail.com>
To: Xiaosen <xiaosen.he@oss.qualcomm.com>
Cc: Jens Axboe <axboe@kernel.dk>,
	linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	Michael Wu <michael@allwinnertech.com>
Subject: Re: [PATCH] sched: disable preemption around blk_flush_plug in sched_submit_work
Date: Tue, 12 May 2026 16:07:11 +0800	[thread overview]
Message-ID: <agLfr9kPHJUrZUex@fedora> (raw)
In-Reply-To: <5660795d-87de-46f5-add4-7729a02225ef@oss.qualcomm.com>

On Tue, May 12, 2026 at 01:56:55PM +0800, Xiaosen wrote:
> There is another deadlock caused by preemption during calling
> blk_flush_plug() in sched_submit_work().
> blk_mq_dispatch_list
>   percpu_ref_get(&this_hctx->queue->q_usage_counter)
>     percpu_ref_get_many(ref, 1);
>           rcu_read_lock()
>             __rcu_read_lock()
>             rcu_lock_acquire
>                   lock_acquire
>                     preempt_schedule_irq  --> writeback worker got
> preempted here and be scheduled out in D state
> 
> 1. task kworker/u32:6 had dirty pages from f2fs node inode submitted to
> block layer and the corresponding request was added to plug list of the
> current task.
> 2. task snpe-net-run acquired gc_lock waiting for the request that
> contained page from node inode to be completed.
> 3. task kworker/u32:6 needed to acquire gc_lock to perform foreground
> GC, since the gc_lock had already been acquired by task snpe-net-run, so
> it called blk_flush_plug() in sched_submit_work() before sleeping to
> avoid deadlocks, but task kworker/u32:6 got preempted in RCU critical
> section before running hw queue to issue plugged requests. so the
> plugged requests were pending in local request list. task kworker/u32:6
> was scheduled out waiting to be woken up by the release of gc_lock.
> 4. so, there is a deadlock to cause RCU STALL.
> 
> I think task kworker/u32:6 should not be scheduled out before returning
> from blk_flush_plug(), and I think this patch should be able to fix such
> deadlocks.

This patch isn't enough, because the current task could be preempted
anytime before calling into blk_flush_plug(), even before schedule().

One quick way is to fix schedule_preempt_disabled(), I will prepare one
formal patch later.

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b8871449d3c6..18ef6ed71b4f 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7336,6 +7336,7 @@ asmlinkage __visible void __sched schedule_user(void)
  */
 void __sched schedule_preempt_disabled(void)
 {
+       blk_flush_plug(current->plug, true);
        sched_preempt_enable_no_resched();
        schedule();
        preempt_disable();


Thanks,
Ming

      reply	other threads:[~2026-05-12  8:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-23 12:55 [PATCH] sched: disable preemption around blk_flush_plug in sched_submit_work Ming Lei
2026-05-12  5:56 ` Xiaosen
2026-05-12  8:07   ` Ming Lei [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=agLfr9kPHJUrZUex@fedora \
    --to=tom.leiming@gmail.com \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@allwinnertech.com \
    --cc=xiaosen.he@oss.qualcomm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox