From: John Ogness <john.ogness@linutronix.de>
To: Jens Axboe <axboe@kernel.dk>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Thomas Gleixner <tglx@linutronix.de>,
linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] block: remove retry loop in ioc_release_fn()
Date: Fri, 19 Jun 2020 17:23:18 +0206 [thread overview]
Message-ID: <20200619151718.22338-3-john.ogness@linutronix.de> (raw)
In-Reply-To: <20200619151718.22338-1-john.ogness@linutronix.de>
The reverse-order double lock dance in ioc_release_fn() is using a
retry loop. This is a problem on PREEMPT_RT because it could preempt
the task that would release q->queue_lock and thus live lock in the
retry loop.
RCU is already managing the freeing of the request queue and icq. If
the trylock fails, use RCU to guarantee that the request queue and
icq are not freed and re-acquire the locks in the correct order,
allowing forward progress.
Signed-off-by: John Ogness <john.ogness@linutronix.de>
---
block/blk-ioc.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/block/blk-ioc.c b/block/blk-ioc.c
index 5dbcfa1b872e..57299f860d41 100644
--- a/block/blk-ioc.c
+++ b/block/blk-ioc.c
@@ -107,9 +107,23 @@ static void ioc_release_fn(struct work_struct *work)
ioc_destroy_icq(icq);
spin_unlock(&q->queue_lock);
} else {
- spin_unlock_irq(&ioc->lock);
- cpu_relax();
- spin_lock_irq(&ioc->lock);
+ /* Make sure q and icq cannot be freed. */
+ rcu_read_lock();
+
+ /* Re-acquire the locks in the correct order. */
+ spin_unlock(&ioc->lock);
+ spin_lock(&q->queue_lock);
+ spin_lock(&ioc->lock);
+
+ /*
+ * The icq may have been destroyed when the ioc lock
+ * was released.
+ */
+ if (!(icq->flags & ICQ_DESTROYED))
+ ioc_destroy_icq(icq);
+
+ spin_unlock(&q->queue_lock);
+ rcu_read_unlock();
}
}
--
2.20.1
next prev parent reply other threads:[~2020-06-19 15:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 15:17 [PATCH 0/2] block: remove retry loop John Ogness
2020-06-19 15:17 ` [PATCH 1/2] block: remove unnecessary ioc nested locking John Ogness
2020-06-23 11:50 ` Daniel Wagner
2020-06-19 15:17 ` John Ogness [this message]
2020-06-23 14:30 ` [PATCH 2/2] block: remove retry loop in ioc_release_fn() Daniel Wagner
2020-07-16 16:23 ` [PATCH 0/2] block: remove retry loop Jens Axboe
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=20200619151718.22338-3-john.ogness@linutronix.de \
--to=john.ogness@linutronix.de \
--cc=axboe@kernel.dk \
--cc=bigeasy@linutronix.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®