The barrier in vcpu_context_saved() is specifically about the clearing of
->is_running. It isn't needed when we don't clear the flag.
Furthermore, one side of the barrier being in common code, the other would
better be, too. This way, all architectures are covered (beyond any
specific needs they may have).
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -333,17 +333,7 @@ void sync_local_execstate(void)
void sync_vcpu_execstate(struct vcpu *v)
{
- /*
- * We don't support lazy switching.
- *
- * However the context may have been saved from a remote pCPU so we
- * need a barrier to ensure it is observed before continuing.
- *
- * Per vcpu_context_saved(), the context can be observed when
- * v->is_running is false (the caller should check it before calling
- * this function).
- */
- smp_rmb();
+ /* Nothing to do -- no lazy switching */
}
#define NEXT_ARG(fmt, args) \
--- a/xen/common/sched/core.c
+++ b/xen/common/sched/core.c
@@ -956,6 +956,9 @@ void vcpu_sleep_sync(struct vcpu *v)
while ( !vcpu_runnable(v) && v->is_running )
cpu_relax();
+ /* Sync state /after/ observing the running flag clear. */
+ smp_rmb();
+
sync_vcpu_execstate(v);
}
@@ -2308,11 +2311,13 @@ static struct sched_unit *do_schedule(st
static void vcpu_context_saved(struct vcpu *vprev, struct vcpu *vnext)
{
- /* Clear running flag /after/ writing context to memory. */
- smp_wmb();
-
if ( vprev != vnext )
+ {
+ /* Clear running flag /after/ writing context to memory. */
+ smp_wmb();
+
vprev->is_running = false;
+ }
}
static void unit_context_saved(struct sched_resource *sr)
On 2/5/26 12:33 PM, Jan Beulich wrote:
> The barrier in vcpu_context_saved() is specifically about the clearing of
> ->is_running. It isn't needed when we don't clear the flag.
>
> Furthermore, one side of the barrier being in common code, the other would
> better be, too. This way, all architectures are covered (beyond any
> specific needs they may have).
Don't we want then move ...
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- a/xen/arch/arm/domain.c
> +++ b/xen/arch/arm/domain.c
> @@ -333,17 +333,7 @@ void sync_local_execstate(void)
>
> void sync_vcpu_execstate(struct vcpu *v)
> {
> - /*
> - * We don't support lazy switching.
> - *
> - * However the context may have been saved from a remote pCPU so we
> - * need a barrier to ensure it is observed before continuing.
> - *
> - * Per vcpu_context_saved(), the context can be observed when
> - * v->is_running is false (the caller should check it before calling
> - * this function).
> - */
> - smp_rmb();
> + /* Nothing to do -- no lazy switching */
> }
... to common code with ability to re-define sync_vcpu_execstate() by arch
as only x86 does something inside this function?
~ Oleksii
On 06.02.2026 13:57, Oleksii Kurochko wrote:
>
> On 2/5/26 12:33 PM, Jan Beulich wrote:
>> The barrier in vcpu_context_saved() is specifically about the clearing of
>> ->is_running. It isn't needed when we don't clear the flag.
>>
>> Furthermore, one side of the barrier being in common code, the other would
>> better be, too. This way, all architectures are covered (beyond any
>> specific needs they may have).
>
> Don't we want then move ...
>
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>
>> --- a/xen/arch/arm/domain.c
>> +++ b/xen/arch/arm/domain.c
>> @@ -333,17 +333,7 @@ void sync_local_execstate(void)
>>
>> void sync_vcpu_execstate(struct vcpu *v)
>> {
>> - /*
>> - * We don't support lazy switching.
>> - *
>> - * However the context may have been saved from a remote pCPU so we
>> - * need a barrier to ensure it is observed before continuing.
>> - *
>> - * Per vcpu_context_saved(), the context can be observed when
>> - * v->is_running is false (the caller should check it before calling
>> - * this function).
>> - */
>> - smp_rmb();
>> + /* Nothing to do -- no lazy switching */
>> }
>
> ... to common code with ability to re-define sync_vcpu_execstate() by arch
> as only x86 does something inside this function?
Indeed this was considered already, as a possible next step.
Jan
On 05.02.26 12:33, Jan Beulich wrote: > The barrier in vcpu_context_saved() is specifically about the clearing of > ->is_running. It isn't needed when we don't clear the flag. > > Furthermore, one side of the barrier being in common code, the other would > better be, too. This way, all architectures are covered (beyond any > specific needs they may have). > > Signed-off-by: Jan Beulich <jbeulich@suse.com> Reviewed-by: Juergen Gross <jgross@suse.com> Juergen
© 2016 - 2026 Red Hat, Inc.