From nobody Wed Oct 29 20:26:47 2025 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; dkim=fail; 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 1525329055035844.836602190577; Wed, 2 May 2018 23:30:55 -0700 (PDT) Received: from localhost ([::1]:54232 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fE7lU-0006Hj-C3 for importer@patchew.org; Thu, 03 May 2018 02:30:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fE7dL-0007cH-U8 for qemu-devel@nongnu.org; Thu, 03 May 2018 02:22:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fE7dH-0002bQ-82 for qemu-devel@nongnu.org; Thu, 03 May 2018 02:22:27 -0400 Received: from ozlabs.org ([203.11.71.1]:40159) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fE7dG-0002ZI-JI; Thu, 03 May 2018 02:22:23 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 40c4mY5HVsz9s47; Thu, 3 May 2018 16:21:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1525328509; bh=/Ryi3PIrpIC+SGjFlZHGEmcHxvAnR6f7Cge1NZiZFOk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G/jQCqA1vgf9YA2IrmelTzZaUrIr862zriRarvvW6F+8SXaMTE50wOHeZLu35iBZ0 abY5nYL5khYhqsFseXBEsgx1MhldfMb5Nw1kMrYPyVekJTYNRMPukMjvZx3iIKX7Zw gPDiyvYG/PUVgfdCB1oFSzJ9JUq59emUxEr2mnIc= From: David Gibson To: groug@kaod.org, clg@kaod.org Date: Thu, 3 May 2018 16:21:39 +1000 Message-Id: <20180503062145.17899-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180503062145.17899-1-david@gibson.dropbear.id.au> References: <20180503062145.17899-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 203.11.71.1 Subject: [Qemu-devel] [PATCH 2/8] spapr: Clean up rtas_start_cpu() & rtas_stop_self() 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: lvivier@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This makes several minor cleanups to these functions: * Follow usual convention of an early exit on error, rather than having most of the body in an if * Clearer naming of cpu and cpu_. Now callcpu is the cpu from which the RTAS call is invoked, newcpu is the cpu which we're starting * Use cpu_synchronize_state() instead of kvm_cpu_synchronize_state() directly * Remove pointless comment describing what cpu_synchronize_state() does * Use ppc_store_lpcr() instead of directly writing the register field Signed-off-by: David Gibson Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Greg Kurz --- hw/ppc/spapr_rtas.c | 66 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index 0ec5fa4cfe..b251c130cb 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -32,7 +32,7 @@ #include "hw/qdev.h" #include "sysemu/device_tree.h" #include "sysemu/cpus.h" -#include "sysemu/kvm.h" +#include "sysemu/hw_accel.h" =20 #include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" @@ -45,6 +45,7 @@ #include "qemu/cutils.h" #include "trace.h" #include "hw/ppc/fdt.h" +#include "target/ppc/mmu-hash64.h" =20 static void rtas_display_character(PowerPCCPU *cpu, sPAPRMachineState *spa= pr, uint32_t token, uint32_t nargs, @@ -140,13 +141,15 @@ static void spapr_cpu_set_endianness(PowerPCCPU *cpu) } } =20 -static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, +static void rtas_start_cpu(PowerPCCPU *callcpu, sPAPRMachineState *spapr, uint32_t token, uint32_t nargs, target_ulong args, uint32_t nret, target_ulong rets) { target_ulong id, start, r3; - PowerPCCPU *cpu; + PowerPCCPU *newcpu; + CPUPPCState *env; + PowerPCCPUClass *pcc; =20 if (nargs !=3D 3 || nret !=3D 1) { rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); @@ -157,41 +160,37 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMac= hineState *spapr, start =3D rtas_ld(args, 1); r3 =3D rtas_ld(args, 2); =20 - cpu =3D spapr_find_cpu(id); - if (cpu !=3D NULL) { - CPUState *cs =3D CPU(cpu); - CPUPPCState *env =3D &cpu->env; - PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + newcpu =3D spapr_find_cpu(id); + if (!newcpu) { + /* Didn't find a matching cpu */ + rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + return; + } =20 - if (!cs->halted) { - rtas_st(rets, 0, RTAS_OUT_HW_ERROR); - return; - } + env =3D &newcpu->env; + pcc =3D POWERPC_CPU_GET_CLASS(newcpu); =20 - /* This will make sure qemu state is up to date with kvm, and - * mark it dirty so our changes get flushed back before the - * new cpu enters */ - kvm_cpu_synchronize_state(cs); + if (!CPU(newcpu)->halted) { + rtas_st(rets, 0, RTAS_OUT_HW_ERROR); + return; + } =20 - env->msr =3D (1ULL << MSR_SF) | (1ULL << MSR_ME); + cpu_synchronize_state(CPU(newcpu)); =20 - /* Enable Power-saving mode Exit Cause exceptions for the new CPU = */ - env->spr[SPR_LPCR] |=3D pcc->lpcr_pm; + env->msr =3D (1ULL << MSR_SF) | (1ULL << MSR_ME); + spapr_cpu_set_endianness(newcpu); + spapr_cpu_update_tb_offset(newcpu); + /* Enable Power-saving mode Exit Cause exceptions for the new CPU */ + ppc_store_lpcr(newcpu, env->spr[SPR_LPCR] | pcc->lpcr_pm); =20 - env->nip =3D start; - env->gpr[3] =3D r3; - cs->halted =3D 0; - spapr_cpu_set_endianness(cpu); - spapr_cpu_update_tb_offset(cpu); + env->nip =3D start; + env->gpr[3] =3D r3; =20 - qemu_cpu_kick(cs); + CPU(newcpu)->halted =3D 0; =20 - rtas_st(rets, 0, RTAS_OUT_SUCCESS); - return; - } + qemu_cpu_kick(CPU(newcpu)); =20 - /* Didn't find a matching cpu */ - rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + rtas_st(rets, 0, RTAS_OUT_SUCCESS); } =20 static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMachineState *spapr, @@ -203,13 +202,12 @@ static void rtas_stop_self(PowerPCCPU *cpu, sPAPRMach= ineState *spapr, CPUPPCState *env =3D &cpu->env; PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); =20 - cs->halted =3D 1; - qemu_cpu_kick(cs); - /* Disable Power-saving mode Exit Cause exceptions for the CPU. * This could deliver an interrupt on a dying CPU and crash the * guest */ - env->spr[SPR_LPCR] &=3D ~pcc->lpcr_pm; + ppc_store_lpcr(cpu, env->spr[SPR_LPCR] & ~pcc->lpcr_pm); + cs->halted =3D 1; + qemu_cpu_kick(cs); } =20 static inline int sysparm_st(target_ulong addr, target_ulong len, --=20 2.17.0