target/s390x: Fix missing clock-comparator interrupts
v2 cover target/s390x: Fix missing clock-comparator interrupts
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
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 | 55 +++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 tests/tcg/s390x/sckc.S
Signature · 1 line
2.51.0
PATCH v2 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 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 v2 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
PATCH v2 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
Re: [PATCH v2 2/3] target/s390x: Fix missing clock-comparator interrupts after reset
In reply to Ilya LeoshkevichHi Ilya!
Quoted 8 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 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.
Can this really happen? Looking at CPUS390XState in target/s390x/cpu.h, the ckc is next to the cregs[] in the start_initial_reset_fields section, so if ckc gets cleared, the cregs get cleared, too. I.e. if ckc gets set to 0 here, there is no way that the clock comparator interrupt could trigger immediately without the guest writing to the control registers first. So I think this patch is not really necessary. Or do I miss something?
Thomas
Quoted 56 lines
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(-)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)
Re: [PATCH v2 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 | 55 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+)create mode 100644
tests/tcg/s390x/sckc.S
Re: [PATCH v2 2/3] target/s390x: Fix missing clock-comparator interrupts after reset
In reply to Thomas HuthQuoted 6 lines · Thomas Huth
Hi Ilya!
Quoted 3 lines · Ilya Leoshkevich
After reset, CKC value is set to 0, so if clock-comparator interrupts are enabled, one should occur very shortly thereafter.
Quoted 7 lines
Quoted 5 lines
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.Can this really happen? Looking at CPUS390XState in
target/s390x/cpu.h, the ckc is next to the cregs[] in thestart_initial_reset_fieldssection, so if ckc gets cleared, the cregs get cleared, too. I.e. if ckc gets set to 0 here, there is no way that the clock comparator interrupt could trigger immediately without the guest writing to the control registers first. So I think this patch is not really necessary. Or do I miss something?
... but it looks like your TCG test is failing without this second patch.
Ok, I think I understood it now: We don't re-arm the CKC timer in case the guest writes to the CR0. So we need to have the timer started during reset already to make the interrupt pending, so that it can fire when the guest changes CR0.
So I guess this patch is fine. Or alternatively you could maybe re-arm the CKC during stctg, would that be better? What do you think?
Thomas