[PATCH v3 2/3] target/s390x: Fix missing clock-comparator interrupts after reset

Ilya Leoshkevich posted 3 patches 4 weeks, 1 day ago
Maintainers: Richard Henderson <richard.henderson@linaro.org>, David Hildenbrand <david@redhat.com>, Ilya Leoshkevich <iii@linux.ibm.com>, Thomas Huth <thuth@redhat.com>
There is a newer version of this series
[PATCH v3 2/3] target/s390x: Fix missing clock-comparator interrupts after reset
Posted by Ilya Leoshkevich 4 weeks, 1 day ago
After reset, CKC value is set to 0, so if clock-comparator interrupts
are enabled, one should occur very shortly thereafter.

Currently the code that loads the respective control register does not
set tod_timer, so this does not happen.

Fix by adding a tcg_s390_tod_updated() call to LCTL and LCTLG.

Cc: qemu-stable@nongnu.org
Suggested-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 target/s390x/tcg/mem_helper.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c
index f1acb1618f7..24675fc818d 100644
--- a/target/s390x/tcg/mem_helper.c
+++ b/target/s390x/tcg/mem_helper.c
@@ -1959,6 +1959,10 @@ void HELPER(lctlg)(CPUS390XState *env, uint32_t r1, uint64_t a2, uint32_t r3)
         if (env->cregs[i] != val && i >= 9 && i <= 11) {
             PERchanged = true;
         }
+        if (i == 0 && !(env->cregs[i] & CR0_CKC_SC) && (val & CR0_CKC_SC)) {
+            BQL_LOCK_GUARD();
+            tcg_s390_tod_updated(env_cpu(env), RUN_ON_CPU_NULL);
+        }
         env->cregs[i] = val;
         HELPER_LOG("load ctl %d from 0x%" PRIx64 " == 0x%" PRIx64 "\n",
                    i, src, val);
@@ -1989,10 +1993,15 @@ void HELPER(lctl)(CPUS390XState *env, uint32_t r1, uint64_t a2, uint32_t r3)
 
     for (i = r1;; i = (i + 1) % 16) {
         uint32_t val = cpu_ldl_data_ra(env, src, ra);
+        uint64_t val64 = deposit64(env->cregs[i], 0, 32, val);
         if ((uint32_t)env->cregs[i] != val && i >= 9 && i <= 11) {
             PERchanged = true;
         }
-        env->cregs[i] = deposit64(env->cregs[i], 0, 32, val);
+        if (i == 0 && !(env->cregs[i] & CR0_CKC_SC) && (val64 & CR0_CKC_SC)) {
+            BQL_LOCK_GUARD();
+            tcg_s390_tod_updated(env_cpu(env), RUN_ON_CPU_NULL);
+        }
+        env->cregs[i] = val64;
         HELPER_LOG("load ctl %d from 0x%" PRIx64 " == 0x%x\n", i, src, val);
         src += sizeof(uint32_t);
 
-- 
2.51.0
Re: [PATCH v3 2/3] target/s390x: Fix missing clock-comparator interrupts after reset
Posted by Thomas Huth 4 weeks, 1 day ago
On 16/10/2025 14.07, Ilya Leoshkevich wrote:
> After reset, CKC value is set to 0, so if clock-comparator interrupts
> are enabled, one should occur very shortly thereafter.
> 
> Currently the code that loads the respective control register does not
> set tod_timer, so this does not happen.
> 
> Fix by adding a tcg_s390_tod_updated() call to LCTL and LCTLG.

(I just realized that I mixed up store and load in my previous mail to this 
patch in v2, sorry for the confusion)

> Cc: qemu-stable@nongnu.org
> Suggested-by: Thomas Huth <thuth@redhat.com>
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>   target/s390x/tcg/mem_helper.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/target/s390x/tcg/mem_helper.c b/target/s390x/tcg/mem_helper.c
> index f1acb1618f7..24675fc818d 100644
> --- a/target/s390x/tcg/mem_helper.c
> +++ b/target/s390x/tcg/mem_helper.c
> @@ -1959,6 +1959,10 @@ void HELPER(lctlg)(CPUS390XState *env, uint32_t r1, uint64_t a2, uint32_t r3)
>           if (env->cregs[i] != val && i >= 9 && i <= 11) {
>               PERchanged = true;
>           }
> +        if (i == 0 && !(env->cregs[i] & CR0_CKC_SC) && (val & CR0_CKC_SC)) {
> +            BQL_LOCK_GUARD();
> +            tcg_s390_tod_updated(env_cpu(env), RUN_ON_CPU_NULL);
> +        }
>           env->cregs[i] = val;
>           HELPER_LOG("load ctl %d from 0x%" PRIx64 " == 0x%" PRIx64 "\n",
>                      i, src, val);
> @@ -1989,10 +1993,15 @@ void HELPER(lctl)(CPUS390XState *env, uint32_t r1, uint64_t a2, uint32_t r3)
>   
>       for (i = r1;; i = (i + 1) % 16) {
>           uint32_t val = cpu_ldl_data_ra(env, src, ra);
> +        uint64_t val64 = deposit64(env->cregs[i], 0, 32, val);
>           if ((uint32_t)env->cregs[i] != val && i >= 9 && i <= 11) {
>               PERchanged = true;
>           }
> -        env->cregs[i] = deposit64(env->cregs[i], 0, 32, val);
> +        if (i == 0 && !(env->cregs[i] & CR0_CKC_SC) && (val64 & CR0_CKC_SC)) {
> +            BQL_LOCK_GUARD();
> +            tcg_s390_tod_updated(env_cpu(env), RUN_ON_CPU_NULL);
> +        }
> +        env->cregs[i] = val64;

That looks nicer to me, indeed, thanks!

Reviewed-by: Thomas Huth <thuth@redhat.com>