From: Josef Bacik <jo...@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().

Reviewed-by: Oleg Nesterov <o...@redhat.com>
Signed-off-by: Josef Bacik <jo...@toxicpanda.com>
Signed-off-by: Jens Axboe <ax...@kernel.dk>

Changes when porting to vz7:
- original patch is patching block/blk-rq-qos.c:rq_qos_wait, but in vz7
  similar hunk is in block/blk-wbt.c:__wbt_wait
- also original patch is patching rq_qos_wake_function, but in vz7
  similar hunk is in wbt_wake_function

https://jira.sw.ru/browse/PSBM-141883
(cherry picked from commit ac38297f7038cd5b80d66f8809c7bbf5b70031f3)
Signed-off-by: Pavel Tikhomirov <ptikhomi...@virtuozzo.com>
---
 block/blk-wbt.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/block/blk-wbt.c b/block/blk-wbt.c
index 4c5b6899db71..099678cd0d04 100644
--- a/block/blk-wbt.c
+++ b/block/blk-wbt.c
@@ -541,6 +541,7 @@ static int wbt_wake_function(struct __wait_queue *curr, 
unsigned int mode,
                return -1;
 
        data->got_token = true;
+       smp_wmb();
        list_del_init(&curr->task_list);
        wake_up_process(data->task);
        return 1;
@@ -573,6 +574,7 @@ static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags 
wb_acct,
        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;
 
@@ -585,6 +587,7 @@ static void __wbt_wait(struct rq_wb *rwb, enum wbt_flags 
wb_acct,
                         * which means we now have two. Put our local token
                         * and wake anyone else potentially waiting for one.
                         */
+                       smp_rmb();
                        if (data.got_token)
                                wbt_rqw_done(rwb, rqw, wb_acct);
                        break;
-- 
2.37.1

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to