From: Josef Bacik <josef@toxicpanda.com>
To: axboe@kernel.dk, kernel-team@fb.com, linux-block@vger.kernel.org,
peterz@infradead.org, oleg@redhat.com
Subject: [PATCH 5/5] rq-qos: use a mb for got_token
Date: Tue, 16 Jul 2019 16:19:29 -0400 [thread overview]
Message-ID: <20190716201929.79142-6-josef@toxicpanda.com> (raw)
In-Reply-To: <20190716201929.79142-1-josef@toxicpanda.com>
Oleg noticed that our checking of data.got_token is unsafe in the
cleanup case, and should really use a memory barrier. Use a wmb on the
write side, and a rmb() on the read side. We don't need one in the main
loop since we're saved by set_current_state().
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
block/blk-rq-qos.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/block/blk-rq-qos.c b/block/blk-rq-qos.c
index c450b8952eae..3954c0dc1443 100644
--- a/block/blk-rq-qos.c
+++ b/block/blk-rq-qos.c
@@ -202,6 +202,7 @@ static int rq_qos_wake_function(struct wait_queue_entry *curr,
return -1;
data->got_token = true;
+ smp_wmb();
list_del_init(&curr->entry);
wake_up_process(data->task);
return 1;
@@ -246,6 +247,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
prepare_to_wait_exclusive(&rqw->wait, &data.wq, TASK_UNINTERRUPTIBLE);
has_sleeper = !wq_has_single_sleeper(&rqw->wait);
do {
+ /* The memory barrier in set_task_state saves us here. */
if (data.got_token)
break;
if (!has_sleeper && acquire_inflight_cb(rqw, private_data)) {
@@ -256,6 +258,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
* which means we now have two. Put our local token
* and wake anyone else potentially waiting for one.
*/
+ smp_rmb();
if (data.got_token)
cleanup_cb(rqw, private_data);
break;
--
2.17.1
next prev parent reply other threads:[~2019-07-16 20:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-16 20:19 [PATCH 0/5][v3] rq-qos memory barrier shenanigans Josef Bacik
2019-07-16 20:19 ` [PATCH 1/5] wait: add wq_has_single_sleeper helper Josef Bacik
2019-07-16 20:19 ` [PATCH 2/5] rq-qos: fix missed wake-ups in rq_qos_throttle Josef Bacik
2019-07-16 20:19 ` [PATCH 3/5] rq-qos: don't reset has_sleepers on spurious wakeups Josef Bacik
2019-07-16 20:19 ` [PATCH 4/5] rq-qos: set ourself TASK_UNINTERRUPTIBLE after we schedule Josef Bacik
2019-07-16 20:19 ` Josef Bacik [this message]
2019-07-18 15:56 ` [PATCH 0/5][v3] rq-qos memory barrier shenanigans Oleg Nesterov
2019-07-18 16:20 ` 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=20190716201929.79142-6-josef@toxicpanda.com \
--to=josef@toxicpanda.com \
--cc=axboe@kernel.dk \
--cc=kernel-team@fb.com \
--cc=linux-block@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
/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;
as well as URLs for NNTP newsgroup(s).