[PATCH v2 16/16] xen/riscv: implement sync_vcpu_execstate()

Oleksii Kurochko posted 16 patches 2 weeks, 3 days ago
[PATCH v2 16/16] xen/riscv: implement sync_vcpu_execstate()
Posted by Oleksii Kurochko 2 weeks, 3 days ago
The scheduler may call this function to force synchronization of given
vCPU's state. Although RISC-V does not support lazy context switching,
a full memory barrier is still required to order observation of the
saved context correctly.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in v2:
 - New patch.
---
 xen/arch/riscv/domain.c | 18 ++++++++++++++++++
 xen/arch/riscv/stubs.c  |  5 -----
 2 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/xen/arch/riscv/domain.c b/xen/arch/riscv/domain.c
index 1458902aff82..48ba7584acaa 100644
--- a/xen/arch/riscv/domain.c
+++ b/xen/arch/riscv/domain.c
@@ -259,3 +259,21 @@ void sync_local_execstate(void)
 {
     /* Nothing to do -- no lazy switching */
 }
+
+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).
+     *
+     * Note this is a full barrier to also prevent update of the context
+     * to happen before it was observed.
+     */
+    smp_mb();
+}
diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c
index c912d46f1e42..26434166acc6 100644
--- a/xen/arch/riscv/stubs.c
+++ b/xen/arch/riscv/stubs.c
@@ -91,11 +91,6 @@ void continue_running(struct vcpu *same)
     BUG_ON("unimplemented");
 }
 
-void sync_vcpu_execstate(struct vcpu *v)
-{
-    BUG_ON("unimplemented");
-}
-
 void startup_cpu_idle_loop(void)
 {
     BUG_ON("unimplemented");
-- 
2.52.0
Re: [PATCH v2 16/16] xen/riscv: implement sync_vcpu_execstate()
Posted by Jan Beulich 4 days, 17 hours ago
On 22.01.2026 17:47, Oleksii Kurochko wrote:
> --- a/xen/arch/riscv/domain.c
> +++ b/xen/arch/riscv/domain.c
> @@ -259,3 +259,21 @@ void sync_local_execstate(void)
>  {
>      /* Nothing to do -- no lazy switching */
>  }
> +
> +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).
> +     *
> +     * Note this is a full barrier to also prevent update of the context
> +     * to happen before it was observed.
> +     */
> +    smp_mb();
> +}

Where's the counterpart of this barrier (going to be)?

Jan
Re: [PATCH v2 16/16] xen/riscv: implement sync_vcpu_execstate()
Posted by Oleksii Kurochko 3 days, 11 hours ago
On 2/4/26 11:49 AM, Jan Beulich wrote:
> On 22.01.2026 17:47, Oleksii Kurochko wrote:
>> --- a/xen/arch/riscv/domain.c
>> +++ b/xen/arch/riscv/domain.c
>> @@ -259,3 +259,21 @@ void sync_local_execstate(void)
>>   {
>>       /* Nothing to do -- no lazy switching */
>>   }
>> +
>> +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).
>> +     *
>> +     * Note this is a full barrier to also prevent update of the context
>> +     * to happen before it was observed.
>> +     */
>> +    smp_mb();
>> +}
> Where's the counterpart of this barrier (going to be)?

As it is mentioned in the comment it is invcpu_context_saved(). ~ Oleksii
Re: [PATCH v2 16/16] xen/riscv: implement sync_vcpu_execstate()
Posted by Jan Beulich 3 days, 11 hours ago
On 05.02.2026 17:51, Oleksii Kurochko wrote:
> 
> On 2/4/26 11:49 AM, Jan Beulich wrote:
>> On 22.01.2026 17:47, Oleksii Kurochko wrote:
>>> --- a/xen/arch/riscv/domain.c
>>> +++ b/xen/arch/riscv/domain.c
>>> @@ -259,3 +259,21 @@ void sync_local_execstate(void)
>>>   {
>>>       /* Nothing to do -- no lazy switching */
>>>   }
>>> +
>>> +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).
>>> +     *
>>> +     * Note this is a full barrier to also prevent update of the context
>>> +     * to happen before it was observed.
>>> +     */
>>> +    smp_mb();
>>> +}
>> Where's the counterpart of this barrier (going to be)?
> 
> As it is mentioned in the comment it is invcpu_context_saved(). ~ Oleksii

You may have seen the Arm side changes to this, as I did Cc you. From that
I think you should understand the background of the question.

Jan