xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] xen/arm: Ensure the vCPU context is seen before clearing the _VPF_down
@ 2021-02-26 20:51 Julien Grall
  2021-02-27  1:58 ` Stefano Stabellini
  0 siblings, 1 reply; 13+ messages in thread
From: Julien Grall @ 2021-02-26 20:51 UTC (permalink / raw)
  To: xen-devel
  Cc: bertrand.marquis, ash.j.wilding, Julien Grall,
	Stefano Stabellini, Julien Grall, Volodymyr Babchuk

From: Julien Grall <jgrall@amazon.com>

A vCPU can get scheduled as soon as _VPF_down is cleared. As there is
currently not ordering guarantee in arch_set_info_guest(), it may be
possible that flag can be observed cleared before the new values of vCPU
registers are observed.

Add an smp_mb() before the flag is cleared to prevent re-ordering.

Signed-off-by: Julien Grall <jgrall@amazon.com>

---

Barriers should work in pair. However, I am not entirely sure whether to
put the other half. Maybe at the beginning of context_switch_to()?

The issues described here is also quite theoritical because there are
hundreds of instructions executed between the time a vCPU is seen
runnable and scheduled. But better be safe than sorry :).
---
 xen/arch/arm/domain.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index bdd3d3e5b5d5..2b705e66be81 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -914,7 +914,14 @@ int arch_set_info_guest(
     v->is_initialised = 1;
 
     if ( ctxt->flags & VGCF_online )
+    {
+        /*
+         * The vCPU can be scheduled as soon as _VPF_down is cleared.
+         * So clear the bit *after* the context was loaded.
+         */
+        smp_mb();
         clear_bit(_VPF_down, &v->pause_flags);
+    }
     else
         set_bit(_VPF_down, &v->pause_flags);
 
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-04-22 20:34 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-26 20:51 [PATCH] xen/arm: Ensure the vCPU context is seen before clearing the _VPF_down Julien Grall
2021-02-27  1:58 ` Stefano Stabellini
2021-02-27 14:30   ` Julien Grall
2021-03-20  0:01     ` Stefano Stabellini
2021-03-20 11:47       ` Julien Grall
2021-04-01 15:09         ` Julien Grall
2021-04-13 22:43         ` Stefano Stabellini
2021-04-16 18:21           ` Julien Grall
2021-04-20 19:38             ` Stefano Stabellini
2021-04-20 20:47               ` Julien Grall
2021-04-21  0:38                 ` Stefano Stabellini
2021-04-21 12:33                   ` Julien Grall
2021-04-22 20:33                     ` Stefano Stabellini

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).