From nobody Mon Apr 29 06:14:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1522056206515739.9408071353974; Mon, 26 Mar 2018 02:23:26 -0700 (PDT) Received: from localhost ([::1]:55417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0OLd-0000Qk-Nc for importer@patchew.org; Mon, 26 Mar 2018 05:23:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0OJ0-0007BV-Qw for qemu-devel@nongnu.org; Mon, 26 Mar 2018 05:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0OIx-0006P1-LF for qemu-devel@nongnu.org; Mon, 26 Mar 2018 05:20:42 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37108 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0OIx-0006Oh-FI; Mon, 26 Mar 2018 05:20:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14C80401DECF; Mon, 26 Mar 2018 09:20:39 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-84.ams2.redhat.com [10.36.117.84]) by smtp.corp.redhat.com (Postfix) with ESMTP id 937AD2166BAE; Mon, 26 Mar 2018 09:20:37 +0000 (UTC) From: David Hildenbrand To: qemu-s390x@nongnu.org Date: Mon, 26 Mar 2018 11:20:36 +0200 Message-Id: <20180326092036.12780-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 26 Mar 2018 09:20:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 26 Mar 2018 09:20:39 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH RFC] s390x/kvm: call cpu_synchronize_state() on every kvm_arch_handle_exit() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , David Hildenbrand , Cornelia Huck , Alexander Graf , qemu-devel@nongnu.org, Christian Borntraeger , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Manually having to use cpu_synchronize_state() is error prone. I don't think that the performance impact is that huge if we simply synchronize the state on every kvm_arch_handle_exit() call. This makes the code easier to maintain. We now also call it (although not neded) for - KVM_EXIT_S390_RESET -> s390_reipl_request() - KVM_EXIT_DEBUG -> kvm_arch_handle_debug_exit() - unmanagable/unimplemented intercepts - ICPT_WAITPSW -> s390_handle_wait() -> cpu gets halted - ICPT_CPU_STOP -> do_stop_interrupt() -> cpu gets halted - Scenarios where we inject an operation exception - handle_sigp() on the source CPU - handle_stsi() I don't think any of these are performance critical. Especially as we have all information directly contained in kvm_run, there are no additional IOCTLs to issue on modern kernels. Remaining places (for s390x) are in - target/s390x/sigp.c, on the target CPU - target/s390x/cpu.c:s390_cpu_get_crash_info() Signed-off-by: David Hildenbrand --- hw/s390x/s390-pci-inst.c | 8 -------- target/s390x/kvm.c | 20 ++------------------ 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c index 3fcc330fe3..02a815fd31 100644 --- a/hw/s390x/s390-pci-inst.c +++ b/hw/s390x/s390-pci-inst.c @@ -155,8 +155,6 @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_= t ra) S390pciState *s =3D s390_get_phb(); int i; =20 - cpu_synchronize_state(CPU(cpu)); - if (env->psw.mask & PSW_MASK_PSTATE) { s390_program_interrupt(env, PGM_PRIVILEGED, 4, ra); return 0; @@ -389,8 +387,6 @@ int pcilg_service_call(S390CPU *cpu, uint8_t r1, uint8_= t r2, uintptr_t ra) uint32_t fh; uint8_t pcias; =20 - cpu_synchronize_state(CPU(cpu)); - if (env->psw.mask & PSW_MASK_PSTATE) { s390_program_interrupt(env, PGM_PRIVILEGED, 4, ra); return 0; @@ -487,8 +483,6 @@ int pcistg_service_call(S390CPU *cpu, uint8_t r1, uint8= _t r2, uintptr_t ra) uint32_t fh; uint8_t pcias; =20 - cpu_synchronize_state(CPU(cpu)); - if (env->psw.mask & PSW_MASK_PSTATE) { s390_program_interrupt(env, PGM_PRIVILEGED, 4, ra); return 0; @@ -620,8 +614,6 @@ int rpcit_service_call(S390CPU *cpu, uint8_t r1, uint8_= t r2, uintptr_t ra) S390IOTLBEntry entry; hwaddr start, end; =20 - cpu_synchronize_state(CPU(cpu)); - if (env->psw.mask & PSW_MASK_PSTATE) { s390_program_interrupt(env, PGM_PRIVILEGED, 4, ra); return 0; diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c index f570896dc1..7de861ab34 100644 --- a/target/s390x/kvm.c +++ b/target/s390x/kvm.c @@ -1081,7 +1081,6 @@ static int kvm_sclp_service_call(S390CPU *cpu, struct= kvm_run *run, uint32_t code; int r =3D 0; =20 - cpu_synchronize_state(CPU(cpu)); sccb =3D env->regs[ipbh0 & 0xf]; code =3D env->regs[(ipbh0 & 0xf0) >> 4]; =20 @@ -1101,8 +1100,6 @@ static int handle_b2(S390CPU *cpu, struct kvm_run *ru= n, uint8_t ipa1) int rc =3D 0; uint16_t ipbh0 =3D (run->s390_sieic.ipb & 0xffff0000) >> 16; =20 - cpu_synchronize_state(CPU(cpu)); - switch (ipa1) { case PRIV_B2_XSCH: ioinst_handle_xsch(cpu, env->regs[1], RA_IGNORED); @@ -1248,7 +1245,6 @@ static int kvm_stpcifc_service_call(S390CPU *cpu, str= uct kvm_run *run) uint8_t ar; =20 if (s390_has_feat(S390_FEAT_ZPCI)) { - cpu_synchronize_state(CPU(cpu)); fiba =3D get_base_disp_rxy(cpu, run, &ar); =20 return stpcifc_service_call(cpu, r1, fiba, ar, RA_IGNORED); @@ -1266,7 +1262,6 @@ static int kvm_sic_service_call(S390CPU *cpu, struct = kvm_run *run) uint16_t mode; int r; =20 - cpu_synchronize_state(CPU(cpu)); mode =3D env->regs[r1] & 0xffff; isc =3D (env->regs[r3] >> 27) & 0x7; r =3D css_do_sic(env, isc, mode); @@ -1297,7 +1292,6 @@ static int kvm_pcistb_service_call(S390CPU *cpu, stru= ct kvm_run *run) uint8_t ar; =20 if (s390_has_feat(S390_FEAT_ZPCI)) { - cpu_synchronize_state(CPU(cpu)); gaddr =3D get_base_disp_rsy(cpu, run, &ar); =20 return pcistb_service_call(cpu, r1, r3, gaddr, ar, RA_IGNORED); @@ -1313,7 +1307,6 @@ static int kvm_mpcifc_service_call(S390CPU *cpu, stru= ct kvm_run *run) uint8_t ar; =20 if (s390_has_feat(S390_FEAT_ZPCI)) { - cpu_synchronize_state(CPU(cpu)); fiba =3D get_base_disp_rxy(cpu, run, &ar); =20 return mpcifc_service_call(cpu, r1, fiba, ar, RA_IGNORED); @@ -1401,7 +1394,6 @@ static int handle_hypercall(S390CPU *cpu, struct kvm_= run *run) CPUS390XState *env =3D &cpu->env; int ret; =20 - cpu_synchronize_state(CPU(cpu)); ret =3D s390_virtio_hypercall(env); if (ret =3D=3D -EINVAL) { kvm_s390_program_interrupt(cpu, PGM_SPECIFICATION); @@ -1416,7 +1408,6 @@ static void kvm_handle_diag_288(S390CPU *cpu, struct = kvm_run *run) uint64_t r1, r3; int rc; =20 - cpu_synchronize_state(CPU(cpu)); r1 =3D (run->s390_sieic.ipa & 0x00f0) >> 4; r3 =3D run->s390_sieic.ipa & 0x000f; rc =3D handle_diag_288(&cpu->env, r1, r3); @@ -1429,7 +1420,6 @@ static void kvm_handle_diag_308(S390CPU *cpu, struct = kvm_run *run) { uint64_t r1, r3; =20 - cpu_synchronize_state(CPU(cpu)); r1 =3D (run->s390_sieic.ipa & 0x00f0) >> 4; r3 =3D run->s390_sieic.ipa & 0x000f; handle_diag_308(&cpu->env, r1, r3, RA_IGNORED); @@ -1440,8 +1430,6 @@ static int handle_sw_breakpoint(S390CPU *cpu, struct = kvm_run *run) CPUS390XState *env =3D &cpu->env; unsigned long pc; =20 - cpu_synchronize_state(CPU(cpu)); - pc =3D env->psw.addr - sw_bp_ilen; if (kvm_find_sw_breakpoint(CPU(cpu), pc)) { env->psw.addr =3D pc; @@ -1493,8 +1481,6 @@ static int kvm_s390_handle_sigp(S390CPU *cpu, uint8_t= ipa1, uint32_t ipb) int ret; uint8_t order; =20 - cpu_synchronize_state(CPU(cpu)); - /* get order code */ order =3D decode_basedisp_rs(env, ipb, NULL) & SIGP_ORDER_MASK; =20 @@ -1556,7 +1542,6 @@ static int handle_oper_loop(S390CPU *cpu, struct kvm_= run *run) CPUState *cs =3D CPU(cpu); PSW oldpsw, newpsw; =20 - cpu_synchronize_state(cs); newpsw.mask =3D ldq_phys(cs->as, cpu->env.psa + offsetof(LowCore, program_new_psw)); newpsw.addr =3D ldq_phys(cs->as, cpu->env.psa + @@ -1609,7 +1594,6 @@ static int handle_intercept(S390CPU *cpu) break; case ICPT_WAITPSW: /* disabled wait, since enabled wait is handled in kernel */ - cpu_synchronize_state(cs); s390_handle_wait(cpu); r =3D EXCP_HALTED; break; @@ -1651,8 +1635,6 @@ static int handle_tsch(S390CPU *cpu) struct kvm_run *run =3D cs->kvm_run; int ret; =20 - cpu_synchronize_state(cs); - ret =3D ioinst_handle_tsch(cpu, cpu->env.regs[1], run->s390_tsch.ipb, RA_IGNORED); if (ret < 0) { @@ -1778,6 +1760,8 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run= *run) =20 qemu_mutex_lock_iothread(); =20 + cpu_synchronize_state(CPU(cpu)); + switch (run->exit_reason) { case KVM_EXIT_S390_SIEIC: ret =3D handle_intercept(cpu); --=20 2.14.3