summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2019-07-16 16:19:29 -0400
committerJens Axboe <axboe@kernel.dk>2019-07-18 12:20:14 -0400
commitac38297f7038cd5b80d66f8809c7bbf5b70031f3 (patch)
tree2144d14a14682be1c068249731f6edcfda9e4ff4
parentd14a9b389a86a5154b704bc88ce8dd37c701456a (diff)
rq-qos: use a mb for got_token
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(). Reviewed-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--block/blk-rq-qos.c3
1 files changed, 3 insertions, 0 deletions
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,
202 return -1; 202 return -1;
203 203
204 data->got_token = true; 204 data->got_token = true;
205 smp_wmb();
205 list_del_init(&curr->entry); 206 list_del_init(&curr->entry);
206 wake_up_process(data->task); 207 wake_up_process(data->task);
207 return 1; 208 return 1;
@@ -246,6 +247,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
246 prepare_to_wait_exclusive(&rqw->wait, &data.wq, TASK_UNINTERRUPTIBLE); 247 prepare_to_wait_exclusive(&rqw->wait, &data.wq, TASK_UNINTERRUPTIBLE);
247 has_sleeper = !wq_has_single_sleeper(&rqw->wait); 248 has_sleeper = !wq_has_single_sleeper(&rqw->wait);
248 do { 249 do {
250 /* The memory barrier in set_task_state saves us here. */
249 if (data.got_token) 251 if (data.got_token)
250 break; 252 break;
251 if (!has_sleeper && acquire_inflight_cb(rqw, private_data)) { 253 if (!has_sleeper && acquire_inflight_cb(rqw, private_data)) {
@@ -256,6 +258,7 @@ void rq_qos_wait(struct rq_wait *rqw, void *private_data,
256 * which means we now have two. Put our local token 258 * which means we now have two. Put our local token
257 * and wake anyone else potentially waiting for one. 259 * and wake anyone else potentially waiting for one.
258 */ 260 */
261 smp_rmb();
259 if (data.got_token) 262 if (data.got_token)
260 cleanup_cb(rqw, private_data); 263 cleanup_cb(rqw, private_data);
261 break; 264 break;