From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XM9s1-0003hz-JK for qemu-devel@nongnu.org; Tue, 26 Aug 2014 02:04:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XM9ru-0001tu-C4 for qemu-devel@nongnu.org; Tue, 26 Aug 2014 02:04:41 -0400 Date: Tue, 26 Aug 2014 16:02:55 +1000 From: David Gibson Message-ID: <20140826060255.GR9923@voom.redhat.com> References: <20140825134353.2361.52046.stgit@aravindap> <20140825134545.2361.66860.stgit@aravindap> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="VdnGiXwuH6t1Tqzo" Content-Disposition: inline In-Reply-To: <20140825134545.2361.66860.stgit@aravindap> Subject: Re: [Qemu-devel] [PATCH 4/5] target-ppc: Handle ibm, nmi-register RTAS call List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Aravinda Prasad Cc: qemu-ppc@nongnu.org, benh@au1.ibm.com, aik@au1.ibm.com, qemu-devel@nongnu.org, paulus@samba.org --VdnGiXwuH6t1Tqzo Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Aug 25, 2014 at 07:15:45PM +0530, Aravinda Prasad wrote: > This patch adds FWNMI support in qemu for powerKVM > guests by handling the ibm,nmi-register rtas call. > Whenever OS issues ibm,nmi-register RTAS call, the > machine check notification address is saved and the > machine check interrupt vector 0x200 is patched to > issue a private hcall. >=20 > Signed-off-by: Aravinda Prasad > --- > hw/ppc/spapr_rtas.c | 91 ++++++++++++++++++++++++++++++++++++++++++= ++++++ > include/hw/ppc/spapr.h | 8 ++++ > 2 files changed, 98 insertions(+), 1 deletion(-) >=20 > diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c > index 02ddbf9..1135d2b 100644 > --- a/hw/ppc/spapr_rtas.c > +++ b/hw/ppc/spapr_rtas.c > @@ -277,6 +277,91 @@ static void rtas_ibm_set_system_parameter(PowerPCCPU= *cpu, > rtas_st(rets, 0, ret); > } > =20 > +static void rtas_ibm_nmi_register(PowerPCCPU *cpu, > + sPAPREnvironment *spapr, > + uint32_t token, uint32_t nargs, > + target_ulong args, > + uint32_t nret, target_ulong rets) > +{ > + int i; > + uint32_t branch_inst =3D 0x48000002; > + target_ulong guest_machine_check_addr; > + PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); > + /* > + * Trampoline saves r3 in sprg2 and issues private hcall > + * to request qemu to build error log. QEMU builds the > + * error log, copies to rtas-blob and returns the address. > + * The initial 16 bytes in rtas-blob consists of saved srr0 > + * and srr1 which we restore and pass on the actual error > + * log address to OS handled mcachine check notification > + * routine > + */ > + uint32_t trampoline[] =3D { > + 0x7c7243a6, /* mtspr SPRN_SPRG2,r3 */ > + 0x38600000, /* li r3,0 */ > + /* 0xf004 is the KVMPPC_H_REPORT_ERR private HCALL */ You should construct the instruction from the KVMPPC_H_REPORT_ERR constant, otherwise it's an undocumented magic dependency between parts of the code. > + 0x6063f004, /* ori r3,r3,f004 */ > + /* Issue H_CALL */ > + 0x44000022, /* sc 1 */ > + 0x7c9243a6, /* mtspr r4 sprg2 */ > + 0xe8830000, /* ld r4, 0(r3) */ > + 0x7c9a03a6, /* mtspr r4, srr0 */ > + 0xe8830008, /* ld r4, 8(r3) */ > + 0x7c9b03a6, /* mtspr r4, srr1 */ > + 0x38630010, /* addi r3,r3,16 */ > + 0x7c9242a6, /* mfspr r4 sprg2 */ > + 0x48000002, /* Branch to address registered > + * by OS. The branch address is > + * patched below */ > + 0x48000000, /* b . */ > + }; > + int total_inst =3D sizeof(trampoline) / sizeof(uint32_t); > + > + /* Store the system reset and machine check address */ > + guest_machine_check_addr =3D rtas_ld(args, 1); > + > + /* Safety Check */ > + if (sizeof(trampoline) >=3D MC_INTERRUPT_VECTOR_SIZE) { > + fprintf(stderr, "Unable to register ibm,nmi_register: " > + "Trampoline size exceeded\n"); > + rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED); > + return; The guest has absolutely no influence over this, so this should be an assert() rather than returning an rtas error. Or better yet, detect the failure at compile time, since it doesn't depend on anything runtime either. > + } > + > + /* > + * Update the branch instruction in trampoline with the absolute > + * machine check address requested by OS > + */ > + branch_inst |=3D guest_machine_check_addr; Surely there should be some sanity checking of the address here, or it can clobber any part of that branch instruction. > + memcpy(&trampoline[11], &branch_inst, sizeof(branch_inst)); > + > + /* Handle all Host/Guest LE/BE combinations */ > + if ((*pcc->interrupts_big_endian)(cpu)) { > + for (i =3D 0; i < total_inst; i++) { > + trampoline[i] =3D cpu_to_be32(trampoline[i]); > + } > + } else { > + for (i =3D 0; i < total_inst; i++) { > + trampoline[i] =3D cpu_to_le32(trampoline[i]); > + } > + } > + > + /* Patch 0x200 NMI interrupt vector memory area of guest */ > + cpu_physical_memory_write(MC_INTERRUPT_VECTOR, trampoline, > + sizeof(trampoline)); > + > + rtas_st(rets, 0, RTAS_OUT_SUCCESS); > +} > + > +static void rtas_ibm_nmi_interlock(PowerPCCPU *cpu, > + sPAPREnvironment *spapr, > + uint32_t token, uint32_t nargs, > + target_ulong args, > + uint32_t nret, target_ulong rets) > +{ > + rtas_st(rets, 0, RTAS_OUT_SUCCESS); > +} > + This nmi_interlock call isn't described in the commit message. --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --VdnGiXwuH6t1Tqzo Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJT/CMPAAoJEGw4ysog2bOS7oIQAKkYb8UMk7XVvplWhIkr6VAj cOvOFg3borQzrYtLqKWvpzrQM1jIKCDbv0bib683/+uuUwqkLHvHi6gO+gSnoUEn 7ohjzO6O0qVoqQ/vPPa4zopcpj0++JbOIZcC2BT6sku/0zkKSHWSY7fX0MqeH5Hn mVvlRVK2/q7Un2p2bXGHRpNsCtCH/rCehVTAYbgarAXekYiiXC6clHONO4t7e/j4 +1YZLZekjmnOw/55qk52mokmJQpYY+88Zc3CmaumFLuF1dCJz1qeC4iaotcUyQCG sAFJxmjnfQIMqvxHIf5YrDdft2BiB+iiaEFp1F9z+uKT5ExIRnfDJvE2xRuyzNXF Q9kMV8bUSKfrAUQUQGpJwNg+URZwuwUjNuVQXuL5NQmZGl7C1bW/eRwf9qxd6A6N IZEJV0yS+ApAqp/t/bcjE7io1Co7flY9uKq4TUeft9l86ZHO3U4SECFZ6tnReURc YZTlMsSa1QabKa5U11mLDToYL+4N2rRsmoY79PiFJjDmWATLqbXjDkUudv7szXgX J4sey3biAuROoODPMDGEwodHXRy2EM/dBAevV+PKIhfUqBrRkioj8PIV0TXHzaYa tXFxPD8onXusIY/Vj4VJdkVlglPFgdzLGcBoZMkYQxcv/2/N1KpRd0urLx1SCLDM ydPke5ZrJivalwgqMhW3 =nldA -----END PGP SIGNATURE----- --VdnGiXwuH6t1Tqzo--