From: Thomas Gleixner <tglx@linutronix.de>
To: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Crystal Wood <swood@redhat.com>
Cc: John Keeping <john@metanate.com>,
linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: rtmutex, pi_blocked_on, and blk_flush_plug()
Date: Mon, 20 Feb 2023 10:49:26 +0100 [thread overview]
Message-ID: <87k00cr7ix.ffs@tglx> (raw)
In-Reply-To: <Y+47FVJ+hI+NA2In@linutronix.de>
On Thu, Feb 16 2023 at 15:17, Sebastian Andrzej Siewior wrote:
> On 2023-02-09 22:31:57 [-0600], Crystal Wood wrote:
>> It is possible for blk_flush_plug() to be called while
>> current->pi_blocked_on is set, in the process of trying to acquire an rwsem.
>> If the block flush blocks trying to acquire some lock, then it appears that
>> current->pi_blocked_on will be overwritten, and then set to NULL once that
>> lock is acquired, even though the task is still blocked on the original
>> rwsem. Am I missing something that deals with this situation? It seems
>> like the lock types that are supposed to call blk_flush_plug() should do so
>> before calling task_blocks_on_rt_mutex().
>
> Do you experience a problem in v6.1-RT?
>
>> I originally noticed this while investigating a related issue on an older
>> RHEL kernel where task_blocked_on_mutex() has a BUG_ON if entered with
>> current->pi_blocked_on non-NULL. Current kernels lack this check.
>
> The logic is different but the deadlock should be avoided:
> - mutex_t and rw_semaphore invoke schedule() while blocking on a lock.
> As part of schedule() sched_submit_work() is invoked.
> This is the same in RT and !RT so I don't expect any dead lock since
> the involved locks are the same.
Huch?
xlog_cil_commit()
down_read(&cil->xc_ctx_lock)
__rwbase_read_lock()
__rt_mutex_slowlock()
current->pi_blocked_on = ...
schedule()
__blk_flush_plug()
dd_insert_requests()
rt_spin_lock()
WARN_ON(current->pi_blocked_on);
So something like the below is required. But that might not cut it
completely. wq_worker_sleeping() is fine, but I'm not convinced that
io_wq_worker_sleeping() is safe. That needs some investigation.
Thanks,
tglx
---
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -6666,6 +6666,9 @@ static inline void sched_submit_work(str
*/
SCHED_WARN_ON(current->__state & TASK_RTLOCK_WAIT);
+ if (current->pi_blocked_on)
+ return;
+
/*
* If we are going to sleep and we have plugged IO queued,
* make sure to submit it to avoid deadlocks.
next prev parent reply other threads:[~2023-02-20 9:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-10 4:31 rtmutex, pi_blocked_on, and blk_flush_plug() Crystal Wood
2023-02-16 14:17 ` Sebastian Andrzej Siewior
2023-02-16 15:05 ` Sebastian Andrzej Siewior
2023-02-20 9:49 ` Thomas Gleixner [this message]
2023-02-20 11:04 ` Sebastian Andrzej Siewior
2023-02-20 11:42 ` Sebastian Andrzej Siewior
2023-02-20 18:21 ` Thomas Gleixner
2023-03-05 5:39 ` Crystal Wood
2023-03-22 16:41 ` Sebastian Andrzej Siewior
2023-03-23 14:50 ` Sebastian Andrzej Siewior
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=87k00cr7ix.ffs@tglx \
--to=tglx@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=john@metanate.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=swood@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.