[PATCH] xen/riscv: fix sstc init to write vstimecmp instead of stimecmp

Baptiste Le Duc posted 1 patch 4 days, 4 hours ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/1779205126.8631fc262581453bbf619ec5b2062170.19e40e3b9da000f373@vates.tech
There is a newer version of this series
xen/arch/riscv/time.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] xen/riscv: fix sstc init to write vstimecmp instead of stimecmp
Posted by Baptiste Le Duc 4 days, 4 hours ago
Commit <25e03273069036f5b46e14bbdf396ac79805d07e> mistakenly wrote to
CSR_STIMECMP during sstc initialization instead of CSR_VSTIMECMP.

CSR_VSTIMECMP is the VS-level timer comparator: the hardware fires a
VS-timer interrupt whenever (time + htimedelta) >= vstimecmp. Writing
to CSR_STIMECMP leaves CSR_VSTIMECMP uninitialized, so its reset value
may immediately satisfy this condition, generating spurious VS-timer
interrupts before any guest has programmed the timer.

Fix this by writing the ULONG_MAX value to CSR_VSTIMECMP as intended.

Signed-off-by: Baptiste Le Duc <baptiste.le-duc@vates.tech>
---
 xen/arch/riscv/time.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c
index 8769709e52..10b7e35f13 100644
--- a/xen/arch/riscv/time.c
+++ b/xen/arch/riscv/time.c
@@ -101,6 +101,6 @@ void __init preinit_xen_time(void)
          * Thereby to avoid spurious VS-timer irqs set vstimecmp CSR to
          * ULONG_MAX.
          */
-        csr_write64(CSR_STIMECMP, ULONG_MAX);
+        csr_write64(CSR_VSTIMECMP, ULONG_MAX);
     }
 }
-- 
2.54.0
Re: [PATCH] xen/riscv: fix sstc init to write vstimecmp instead of stimecmp
Posted by Oleksii Kurochko 4 days, 4 hours ago

On 5/19/26 5:38 PM, Baptiste Le Duc wrote:
> Commit <25e03273069036f5b46e14bbdf396ac79805d07e> mistakenly wrote to
> CSR_STIMECMP during sstc initialization instead of CSR_VSTIMECMP.

It doesn't too much sense to write this as ...
> 
> CSR_VSTIMECMP is the VS-level timer comparator: the hardware fires a
> VS-timer interrupt whenever (time + htimedelta) >= vstimecmp. Writing
> to CSR_STIMECMP leaves CSR_VSTIMECMP uninitialized, so its reset value
> may immediately satisfy this condition, generating spurious VS-timer
> interrupts before any guest has programmed the timer.

It could be just "According to the comment above initializing of 
CSR_STIMECMP CSR_VSTIMECMP should be used instead of CSR_STIMECMP" or 
something like that as what is mentioned here is mentioned in the 
comment above csr_write64(CSR_STIMECMP, ULONG_MAX).

> 
> Fix this by writing the ULONG_MAX value to CSR_VSTIMECMP as intended.
> 
With what I mentioned above this could be dropped.

... it should be here:
   Fixes: 25e0327306903 ("xen/riscv: allow Xen to use SSTC while hiding 
it from guests").

> Signed-off-by: Baptiste Le Duc <baptiste.le-duc@vates.tech>
> ---
>   xen/arch/riscv/time.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/arch/riscv/time.c b/xen/arch/riscv/time.c
> index 8769709e52..10b7e35f13 100644
> --- a/xen/arch/riscv/time.c
> +++ b/xen/arch/riscv/time.c
> @@ -101,6 +101,6 @@ void __init preinit_xen_time(void)
>            * Thereby to avoid spurious VS-timer irqs set vstimecmp CSR to
>            * ULONG_MAX.
>            */
> -        csr_write64(CSR_STIMECMP, ULONG_MAX);
> +        csr_write64(CSR_VSTIMECMP, ULONG_MAX);
>       }
>   }

The change itself looks good to me.

Thanks.

~ Oleksii
Re: [PATCH] xen/riscv: fix sstc init to write vstimecmp instead of stimecmp
Posted by Andrew Cooper 4 days, 4 hours ago
On 19/05/2026 4:38 pm, Baptiste Le Duc wrote:
> Commit <25e03273069036f5b46e14bbdf396ac79805d07e> mistakenly wrote to
> CSR_STIMECMP during sstc initialization instead of CSR_VSTIMECMP.

Thankyou for the patch.  We have a standard pattern for referring to
other commits.

For the referencing things in the main text, you want to write it as:

Commit 25e032730690 ("xen/riscv: allow Xen to use SSTC while hiding it
from guests") mistakenly ...

Specifically, git log --abbrev=12 --pretty=format:'commit %h ("%s") and
adjust the capitalisation as necessary.

> CSR_VSTIMECMP is the VS-level timer comparator: the hardware fires a
> VS-timer interrupt whenever (time + htimedelta) >= vstimecmp. Writing
> to CSR_STIMECMP leaves CSR_VSTIMECMP uninitialized, so its reset value
> may immediately satisfy this condition, generating spurious VS-timer
> interrupts before any guest has programmed the timer.
>
> Fix this by writing the ULONG_MAX value to CSR_VSTIMECMP as intended.

For bugfixes, we also have an explicit tag here just above you SoB

Fixes: 25e032730690 ("xen/riscv: allow Xen to use SSTC while hiding it
from guests")

This helps us identify patches for backport.

> Signed-off-by: Baptiste Le Duc <baptiste.le-duc@vates.tech>