target/s390x: Fix missing clock-comparator interrupts
PATCH v3 3/3 tests/tcg/s390x: Test SET CLOCK COMPARATOR
In reply to Ilya LeoshkevichAdd a small test to prevent regressions.
--- tests/tcg/s390x/Makefile.softmmu-target | 1 + tests/tcg/s390x/sckc.S | 55 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/tcg/s390x/sckc.S
tests/tcg/s390x/Makefile.softmmu-target +1 -0
@@ -28,6 +28,7 @@ ASM_TESTS = \ mc \ per \ precise-smc-softmmu \ + sckc \ ssm-early \ stosm-early \ stpq \
tests/tcg/s390x/sckc.S new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH v3 1/3 target/s390x: Fix missing interrupts for small CKC values
In reply to Ilya LeoshkevichSuppose TOD clock value is 0x1111111111111111 and clock-comparator value is 0, in which case clock-comparator interruption should occur immediately.
With the current code, tod2time(env->ckc - td->base.low) ends up being a very large number, so this interruption never happens.
Fix by firing the timer immediately if env->ckc < td->base.low.
--- target/s390x/tcg/misc_helper.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
target/s390x/tcg/misc_helper.c +8 -4
@@ -199,11 +199,15 @@ static void update_ckc_timer(CPUS390XState *env)return ; } -/* difference between origins */ - time = env->ckc - td->base.low; +if (env->ckc < td->base.low) { + time =0 ; + }else { +/* difference between origins */ + time = env->ckc - td->base.low; -/* nanoseconds */ - time =tod2time (time); +/* nanoseconds */ + time =tod2time (time); + }timer_mod (env->tod_timer, time); }
Signature · 1 line
2.51.0
v3 cover target/s390x: Fix missing clock-comparator interrupts
v2: https://lore.kernel.org/qemu-devel/[email protected]/
v2 -> v3: Rearm the timer on control register load (Thomas).
Add Thomas' R-b to the test.
v1: https://lore.kernel.org/qemu-devel/[email protected]/
v1 -> v2: Add Thomas' R-b.
Cc: stable (Michael).
Improve formatting, commit messages, and test (Ilya).
Hi,
While trying to (so far unsuccessfully) reproduce [1], I found two bugs in the clock comparator handling. This series fixes both and adds a test.
[1] https://lore.kernel.org/lkml/[email protected]/
Best regards,
Ilya
Ilya Leoshkevich (3):
target/s390x: Fix missing interrupts for small CKC values target/s390x: Fix missing clock-comparator interrupts after reset tests/tcg/s390x: Test SET CLOCK COMPARATOR
target/s390x/tcg/mem_helper.c | 11 ++++- target/s390x/tcg/misc_helper.c | 12 ++++-- tests/tcg/s390x/Makefile.softmmu-target | 1 + tests/tcg/s390x/sckc.S | 55 +++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 tests/tcg/s390x/sckc.S
Signature · 1 line
2.51.0
PATCH v3 2/3 target/s390x: Fix missing clock-comparator interrupts after reset
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.
--- target/s390x/tcg/mem_helper.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
target/s390x/tcg/mem_helper.c +10 -1
@@ -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 );
Signature · 1 line
2.51.0
Re: [PATCH v3 2/3] target/s390x: Fix missing clock-comparator interrupts after reset
Quoted 7 lines · Ilya Leoshkevich
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)
Quoted 26 lines
Suggested-by Thomas Huth <[email protected]>Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/tcg/mem_helper.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)target/s390x/tcg/mem_helper.c +4
-0@@ -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);
target/s390x/tcg/mem_helper.c void HELPER(lctl)(CPUS390XState *env, uint32_t r1, uint64_t a2, uint32_t r3) · line 2004
Quoted 10 lines
target/s390x/tcg/mem_helper.c +6
-1+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!