target/s390x: Fix missing clock-comparator interrupts
PATCH 2/3 target/s390x: Fix missing clock-comparator interrupts after reset
In reply to Ilya LeoshkevichAfter reset, both TOD and CKC values are set to 0, so if clock-comparator interrupts are enabled, one should occur shortly thereafter.
Currently the code does not set tod_timer, so this does not happen.
Fix by adding a tcg_s390_tod_updated() call. Initialize TOD clock before CPUs in order to ensure that the respective object exists during the CPU reset.
--- hw/s390x/s390-virtio-ccw.c | 6 +++--- target/s390x/cpu.c | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-)
hw/s390x/s390-virtio-ccw.c +3 -3
@@ -286,6 +286,9 @@ static void ccw_init(MachineState *machine)/* init memory + setup max page size. Required for the CPU model */ s390_memory_init (machine); +/* init the TOD clock */ +s390_init_tod (); +/* init CPUs (incl. CPU model) early so s390_has_feature() works */ s390_init_cpus (machine);
@@ -332,9 +335,6 @@ static void ccw_init(MachineState *machine)s390_create_sclpconsole (ms->sclp,"sclplmconsole" ,serial_hd (1 )); } -/* init the TOD clock */ -s390_init_tod (); -/* init SCLP event Control-Program Identification */ if (s390mc->use_cpi) {s390_create_sclpcpi (ms->sclp);
target/s390x/cpu.c +8 -0
@@ -40,6 +40,7 @@#include "system/reset.h" #endif #include "hw/s390x/cpu-topology.h" +#include "tcg/tcg_s390x.h" #define CR0_RESET 0xE0UL#define CR14_RESET 0xC2000000UL;
@@ -215,6 +216,13 @@ static void s390_cpu_reset_hold(Object *obj, ResetType type)break ; } } + +#ifndef CONFIG_USER_ONLY +if (tcg_enabled ()) { +/* Rearm the CKC timer if necessary */ +tcg_s390_tod_updated (CPU (cpu),RUN_ON_CPU_NULL ); + } +#endif }static void s390_cpu_disas_set_info (CPUState *cpu,disassemble_info *info)
Signature · 1 line
2.51.0
PATCH 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 | 53 +++++++++++++++++++++++++ 2 files changed, 54 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 +53 -0
53 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH 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
cover target/s390x: Fix missing clock-comparator interrupts
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
hw/s390x/s390-virtio-ccw.c | 6 +-- target/s390x/cpu.c | 8 ++++ target/s390x/tcg/misc_helper.c | 12 ++++-- tests/tcg/s390x/Makefile.softmmu-target | 1 + tests/tcg/s390x/sckc.S | 53 +++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 tests/tcg/s390x/sckc.S
Signature · 1 line
2.51.0
Re: [PATCH 3/3] tests/tcg/s390x: Test SET CLOCK COMPARATOR
In reply to Ilya LeoshkevichQuoted 9 lines · Ilya Leoshkevich
Add a small test to prevent regressions.
Signed-off-by Ilya Leoshkevich <[email protected]>---
tests/tcg/s390x/Makefile.softmmu-target | 1 +
tests/tcg/s390x/sckc.S | 53
+++++++++++++++++++++++++2 files changed, 54 insertions(+)create mode 100644
tests/tcg/s390x/sckc.S
[...]
Quoted 24 lines
tests/tcg/s390x/sckc.S new file +18
-0@@ -0,0 +1,53 @@ +/* + * Test clock comparator. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + .org 0x130 +ext_old_psw: + .org 0x1b0 +ext_new_psw: + .quad 0x180000000, _ext /* 64-bit mode */ + .org 0x200 /* lowcore padding */ + + .globl _start +_start: + lpswe start31_psw +_start31: + stctg %c0,%c0,c0 + oi c0+6,8 /* set clock-comparator
Quoted 5 lines
subclass mask */
+ lctlg %c0,%c0,c0
+0:
+ cghsi ext_counter,0x1000
+ jnz 0b
It's better to move this check to the interrupt handler, otherwise there is a risk we get two interrupts and the counter moves from 0xfff to 0x1001, causing an infinite loop. I will fix this in v2.
Quoted 8 lines
+ lpswe
success_pswtests/tcg/s390x/sckc.S new file +7
-0+ +_ext: + stg %r0,ext_saved_r0 + + lg %r0,ext_counter + aghi %r0,1 + stg %r0,ext_counter
[...]
Re: [PATCH 2/3] target/s390x: Fix missing clock-comparator interrupts after reset
In reply to Ilya LeoshkevichQuoted 1 line · Ilya Leoshkevich
After reset, both TOD and CKC values are set to 0, so if
^^^
This is inaccurate, only the TOD programmable register is set to 0. I will fix this in v2.
Quoted 14 lines
clock-comparator interrupts are enabled, one should occur shortly thereafter.
Currently the code does not set
tod_timer, so this does not happen.Fix by adding a
tcg_s390_tod_updated()call. Initialize TOD clock before CPUs in order to ensure that the respective object exists during the CPU reset.Signed-off-by Ilya Leoshkevich <[email protected]>---
hw/s390x/s390-virtio-ccw.c | 6 +++---
target/s390x/cpu.c | 8 ++++++++2 files changed, 11 insertions(+), 3 deletions(-)
[...]
Quoted 8 lines · Ilya Leoshkevich
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.
Quoted 7 lines
Best regards,
IlyaIlya 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
Are these worth to have in qemu stable series?
(And please don't forget to add Cc: qemu-stable@ to other future changes which are also good to have in stable series).
Thanks,
/mjt
Re: [PATCH 1/3] target/s390x: Fix missing interrupts for small CKC values
In reply to Ilya LeoshkevichQuoted 28 lines · Ilya Leoshkevich
Suppose TOD clock value is
0x1111111111111111and 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.Signed-off-by Ilya Leoshkevich <[email protected]>--- target/s390x/tcg/misc_helper.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)target/s390x/tcg/misc_helper.c +4
-2@@ -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 */
target/s390x/tcg/misc_helper.c static void update_ckc_timer(CPUS390XState *env) · line 213
Quoted 10 lines
target/s390x/tcg/misc_helper.c +4
-2+ time = env->ckc - td->base.low; -/* nanoseconds */ - time =tod2time (time); +/* nanoseconds */ + time =tod2time (time); + }timer_mod (env->tod_timer, time); }
Yes, this looks right.