sched: flush plug in schedule_preempt_disabled() to prevent deadlock#821
Open
blktests-ci[bot] wants to merge 1 commit into
Open
sched: flush plug in schedule_preempt_disabled() to prevent deadlock#821blktests-ci[bot] wants to merge 1 commit into
blktests-ci[bot] wants to merge 1 commit into
Conversation
Author
|
Upstream branch: aa54b1d |
b1870f6 to
ca57796
Compare
Author
|
Upstream branch: 70eda68 |
e74b757 to
523d6b3
Compare
ca57796 to
c1feb59
Compare
Author
|
Upstream branch: 8bc67e4 |
523d6b3 to
bd4d898
Compare
c1feb59 to
ea833a1
Compare
Author
|
Upstream branch: 6779b50 |
bd4d898 to
aa3e5bf
Compare
ea833a1 to
7af85d1
Compare
Author
|
Upstream branch: 79bd2dd |
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
Both reported deadlocks involve mutex/rwsem slowpaths, which are the
primary callers of schedule_preempt_disabled() with non-running task
state.
Fix by flushing the plug in schedule_preempt_disabled() while
preemption is still disabled. This ensures the plug is empty before the
preemption window opens.
Fixes: 73c1010 ("block: initial patch for on-stack per-task plugging")
Reported-by: Michael Wu <michael@allwinnertech.com>
Tested-by: Michael Wu <michael@allwinnertech.com>
Reported-by: Xiaosen He <xiaosen.he@oss.qualcomm.com>
Link: https://lore.kernel.org/linux-block/20260417082744.30124-1-michael@allwinnertech.com/
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
aa3e5bf to
4264563
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: sched: flush plug in schedule_preempt_disabled() to prevent deadlock
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1093387