mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
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>
atomics: introduce smp_mb__[after|before]_atomic() barriers
When using atomic variables for synchronization barriers are needed
to ensure proper data serialization. Introduce smp_mb__before_atomic()
and smp_mb__after_atomic() as in the Linux kernel for that purpose.
Use the same definitions as in the Linux kernel.
Suggested-by: Jan Beulich <jbeulich@suse.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <jgrall@amazon.com>
master commit: 109e8177fd
master date: 2021-02-26 09:47:23 +0000
master commit: c301211a51
master date: 2020-03-26 12:42:19 +0100
This commit is contained in:
1 parent
a4c4fc0de3
commit
8384641f6b
3 files changed
+8
No files matched your search
@@ -1366,6 +1366,8 @@ void vcpu_block(void)
|
||||
|
||||
set_bit(_VPF_blocked, &v->pause_flags);
|
||||
|
||||
smp_mb__after_atomic();
|
||||
|
||||
arch_vcpu_block(v);
|
||||
|
||||
/* Check for events /after/ blocking: avoids wakeup waiting race. */
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
|
||||
#define smp_wmb() dmb(ishst)
|
||||
|
||||
#define smp_mb__before_atomic() smp_mb()
|
||||
#define smp_mb__after_atomic() smp_mb()
|
||||
|
||||
/*
|
||||
* This is used to ensure the compiler did actually allocate the register we
|
||||
* asked it for some inline assembly sequences. Apparently we can't trust
|
||||
|
||||
@@ -233,6 +233,9 @@ static always_inline unsigned long __xadd(
|
||||
#define set_mb(var, value) do { xchg(&var, value); } while (0)
|
||||
#define set_wmb(var, value) do { var = value; smp_wmb(); } while (0)
|
||||
|
||||
#define smp_mb__before_atomic() do { } while (0)
|
||||
#define smp_mb__after_atomic() do { } while (0)
|
||||
|
||||
/**
|
||||
* array_index_mask_nospec() - generate a mask that is ~0UL when the
|
||||
* bounds check succeeds and 0 otherwise
|
||||
|
||||