xen/sched: Add missing memory barrier in vcpu_block()
authorJulien Grall <jgrall@amazon.com>
Sat, 20 Feb 2021 19:22:34 +0000 (19:22 +0000)
committerJulien Grall <jgrall@amazon.com>
Fri, 26 Feb 2021 09:47:23 +0000 (09:47 +0000)
commit109e8177fd4a225e7025c4c17d2c9537b550b4ed
treeb40b7b54cf85d9468fa4287c595042c0f6d01fcd
parent79b6574f8ecea39c14557bdd7049c7e2d21ddcbd
xen/sched: Add missing memory barrier in vcpu_block()

The comment in vcpu_block() states that the events should be checked
/after/ blocking to avoids wakeup waiting race. However, from a generic
perspective, set_bit() doesn't prevent re-ordering. So the following
could happen:

CPU0  (blocking vCPU A)         |   CPU1 ( unblock vCPU A)
                                |
A <- read local events          |
                                |   set local events
                                |   test_and_clear_bit(_VPF_blocked)
                                |       -> Bail out as the bit if not set
                                |
set_bit(_VFP_blocked)           |
                                |
check A                         |

The variable A will be 0 and therefore the vCPU will be blocked when it
should continue running.

vcpu_block() is now gaining an smp_mb__after_atomic() to prevent the CPU
to read any information about local events before the flag _VPF_blocked
is set.

Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Ash Wilding <ash.j.wilding@gmail.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
Acked-by: Dario Faggioli <dfaggioli@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
xen/common/sched/core.c