From a0c6a9c878a809504d71d36e963e57f554d574d8 Mon Sep 17 00:00:00 2001 From: Collin Walling Date: Fri, 13 Nov 2020 17:10:22 -0500 Subject: [PATCH 8/8] s390/kvm: fix diag318 propagation and reset functionality The Control Program Name Code (CPNC) portion of the diag318 info must be set within the SIE block of each VCPU in the configuration. The handler will iterate through each VCPU and dirty the diag318_info reg to be synced with KVM on a subsequent sync_regs call. Additionally, the diag318 info resets must be handled via userspace. As such, QEMU will reset this value for each VCPU during a modified clear, load normal, and load clear reset event. Fixes: fabdada9357b ("s390: guest support for diagnose 0x318") Signed-off-by: Collin Walling Message-Id: <20201113221022.257054-1-walling@linux.ibm.com> Reviewed-by: Thomas Huth Reviewed-by: Janosch Frank Signed-off-by: Cornelia Huck --- hw/s390x/s390-virtio-ccw.c | 4 ++++ target/s390x/cpu.c | 7 +++++++ target/s390x/cpu.h | 1 + target/s390x/kvm-stub.c | 4 ++++ target/s390x/kvm.c | 22 +++++++++++++++++----- target/s390x/kvm_s390x.h | 1 + 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c index d3edeef0ad..16a5b9b0d4 100644 --- a/hw/s390x/s390-virtio-ccw.c +++ b/hw/s390x/s390-virtio-ccw.c @@ -357,6 +357,10 @@ static void s390_machine_reset(MachineState *machine) default: g_assert_not_reached(); } + + CPU_FOREACH(t) { + run_on_cpu(t, s390_do_cpu_set_diag318, RUN_ON_CPU_HOST_ULONG(0)); + } s390_ipl_clear_reset_request(); } diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c index 3abe7e80fd..3d36a4782a 100644 --- a/target/s390x/cpu.c +++ b/target/s390x/cpu.c @@ -444,6 +444,13 @@ void s390_enable_css_support(S390CPU *cpu) kvm_s390_enable_css_support(cpu); } } + +void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg) +{ + if (kvm_enabled()) { + kvm_s390_set_diag318(cs, arg.host_ulong); + } +} #endif static gchar *s390_gdb_arch_name(CPUState *cs) diff --git a/target/s390x/cpu.h b/target/s390x/cpu.h index 1924f0faaa..b54e9b9bad 100644 --- a/target/s390x/cpu.h +++ b/target/s390x/cpu.h @@ -767,6 +767,7 @@ int s390_set_memory_limit(uint64_t new_limit, uint64_t *hw_limit); void s390_set_max_pagesize(uint64_t pagesize, Error **errp); void s390_cmma_reset(void); void s390_enable_css_support(S390CPU *cpu); +void s390_do_cpu_set_diag318(CPUState *cs, run_on_cpu_data arg); int s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch_id, int vq, bool assign); #ifndef CONFIG_USER_ONLY diff --git a/target/s390x/kvm-stub.c b/target/s390x/kvm-stub.c index 5152e2bdf1..ba19cf56df 100644 --- a/target/s390x/kvm-stub.c +++ b/target/s390x/kvm-stub.c @@ -107,3 +107,7 @@ void kvm_s390_stop_interrupt(S390CPU *cpu) void kvm_s390_restart_interrupt(S390CPU *cpu) { } + +void kvm_s390_set_diag318(CPUState *cs, uint64_t diag318_info) +{ +} diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index ab9c1d67d4..dcd7cdcd71 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -1535,10 +1535,23 @@ static int handle_sw_breakpoint(S390CPU *cpu, struct kvm_run *run) return -ENOENT; } +void kvm_s390_set_diag318(CPUState *cs, uint64_t diag318_info) +{ + CPUS390XState *env = &S390_CPU(cs)->env; + + /* Feat bit is set only if KVM supports sync for diag318 */ + if (s390_has_feat(S390_FEAT_DIAG_318)) { + env->diag318_info = diag318_info; + cs->kvm_run->s.regs.diag318 = diag318_info; + cs->kvm_run->kvm_dirty_regs |= KVM_SYNC_DIAG318; + } +} + static void handle_diag_318(S390CPU *cpu, struct kvm_run *run) { uint64_t reg = (run->s390_sieic.ipa & 0x00f0) >> 4; uint64_t diag318_info = run->s.regs.gprs[reg]; + CPUState *t; /* * DIAG 318 can only be enabled with KVM support. As such, let's @@ -1546,13 +1559,12 @@ static void handle_diag_318(S390CPU *cpu, struct kvm_run *run) */ if (!s390_has_feat(S390_FEAT_DIAG_318)) { kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION); + return; } - cpu->env.diag318_info = diag318_info; - - if (can_sync_regs(CPU(cpu), KVM_SYNC_DIAG318)) { - run->s.regs.diag318 = diag318_info; - run->kvm_dirty_regs |= KVM_SYNC_DIAG318; + CPU_FOREACH(t) { + run_on_cpu(t, s390_do_cpu_set_diag318, + RUN_ON_CPU_HOST_ULONG(diag318_info)); } } diff --git a/target/s390x/kvm_s390x.h b/target/s390x/kvm_s390x.h index caf985955b..3801816708 100644 --- a/target/s390x/kvm_s390x.h +++ b/target/s390x/kvm_s390x.h @@ -40,5 +40,6 @@ void kvm_s390_set_max_pagesize(uint64_t pagesize, Error **errp); void kvm_s390_crypto_reset(void); void kvm_s390_restart_interrupt(S390CPU *cpu); void kvm_s390_stop_interrupt(S390CPU *cpu); +void kvm_s390_set_diag318(CPUState *cs, uint64_t diag318_info); #endif /* KVM_S390X_H */ -- 2.25.1