From: Peter Zijlstra <peterz@infradead.org>
To: Ming Lei <tom.leiming@gmail.com>
Cc: Tejun Heo <tj@kernel.org>, Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Michael Wu <michael@allwinnertech.com>,
Xiaosen He <xiaosen.he@oss.qualcomm.com>,
Thomas Gleixner <tglx@kernel.org>
Subject: Re: [PATCH] sched: flush plug in schedule_preempt_disabled() to prevent deadlock
Date: Wed, 13 May 2026 09:30:39 +0200 [thread overview]
Message-ID: <20260513073039.GG1889694@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <agPcx_vuO3ZYbAy1@fedora>
On Wed, May 13, 2026 at 10:07:03AM +0800, Ming Lei wrote:
> On Tue, May 12, 2026 at 07:16:36AM -1000, Tejun Heo wrote:
> > Hello, Ming.
> >
> > On Tue, May 12, 2026 at 11:45:14PM +0800, Ming Lei wrote:
> > > On Tue, May 12, 2026 at 02:40:21PM +0200, Peter Zijlstra wrote:
> > > > On Tue, May 12, 2026 at 02:04:32PM +0200, Peter Zijlstra wrote:
> > > > > On Tue, May 12, 2026 at 04:59:39PM +0800, Ming Lei wrote:
> > > > > > On preemptible kernels, a deadlock can occur when a task with plugged IO
> > > > > > calls schedule_preempt_disabled():
> > > > > >
> > > > > > schedule_preempt_disabled()
> > > > > > sched_preempt_enable_no_resched() // preemption now enabled
> > > > > > schedule() // <-- preemption can happen here
> > > > > > sched_submit_work()
> > > > > > blk_flush_plug()
> > > > > >
> > > > > > After sched_preempt_enable_no_resched() re-enables preemption, the task
> > > > > > can be preempted (e.g., by a higher-priority RT task) before reaching
> > > > > > blk_flush_plug() in sched_submit_work(). Since the task's state is
> > > > > > already TASK_UNINTERRUPTIBLE (set by the mutex/rwsem slowpath caller),
> > > > > > requests in current->plug remain unflushed for an unbounded time.
> > > > > >
> > > > > > If another task depends on those plugged requests to make progress (e.g.,
> > > > > > to release a lock the sleeping task needs), a deadlock results:
> > > > > >
> > > > > > - Task A (writeback worker): holds plugged IO, preempted before
> > > > > > flushing, stuck on run queue behind higher-priority work
> > > > > > - Task B: waiting for IO completion from Task A's plug, holds a lock
> > > > > > that Task A needs to be woken up
> >
> > My memory is hazy around io_schedule but the above reads really weird to me.
> > A task, regardless of its current state stays on the runqueue when
> > preempted, so the condition is temporary. As soon as the preempted task can
> > get CPU, it should unwind the situation. That's not a deadlock. Is the
> > problem that there can be preemption-induced delay in flushing the plugs?
>
> IMO, preempting a `!TASK_RUNNING` task can be thought as effective sleep,
No it cannot be. Preemption ignores task state.
next prev parent reply other threads:[~2026-05-13 7:30 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 8:59 [PATCH] sched: flush plug in schedule_preempt_disabled() to prevent deadlock Ming Lei
2026-05-12 12:04 ` Peter Zijlstra
2026-05-12 12:40 ` Peter Zijlstra
2026-05-12 15:45 ` Ming Lei
2026-05-12 16:49 ` Peter Zijlstra
2026-05-12 16:53 ` Peter Zijlstra
2026-05-12 17:16 ` Tejun Heo
2026-05-13 2:07 ` Ming Lei
2026-05-13 7:30 ` Peter Zijlstra [this message]
2026-05-13 8:08 ` Ming Lei
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=20260513073039.GG1889694@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=axboe@kernel.dk \
--cc=juri.lelli@redhat.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michael@allwinnertech.com \
--cc=mingo@redhat.com \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=tom.leiming@gmail.com \
--cc=vincent.guittot@linaro.org \
--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