From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39392) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c15PA-0005bK-J8 for qemu-devel@nongnu.org; Mon, 31 Oct 2016 01:45:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c15P6-00065B-Cg for qemu-devel@nongnu.org; Mon, 31 Oct 2016 01:45:08 -0400 Date: Mon, 31 Oct 2016 16:44:19 +1100 From: David Gibson Message-ID: <20161031054419.GP18226@umbus.fritz.box> References: <1477825928-10803-1-git-send-email-david@gibson.dropbear.id.au> <1477825928-10803-11-git-send-email-david@gibson.dropbear.id.au> <6605d07b-2db6-0e07-75a6-000946c06713@ozlabs.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2uzDqHpccQJpqF2n" Content-Disposition: inline In-Reply-To: <6605d07b-2db6-0e07-75a6-000946c06713@ozlabs.ru> Subject: Re: [Qemu-devel] [RFC 10/17] pseries: Rewrite CAS PVR compatibility logic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexey Kardashevskiy Cc: nikunj@linux.vnet.ibm.com, mdroth@linux.vnet.ibm.com, thuth@redhat.com, lvivier@redhat.com, qemu-ppc@nongnu.org, qemu-devel@nongnu.org --2uzDqHpccQJpqF2n Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 31, 2016 at 04:00:14PM +1100, Alexey Kardashevskiy wrote: > On 30/10/16 22:12, David Gibson wrote: > > During boot, PAPR guests negotiate CPU model support with the > > ibm,client-architecture-support mechanism. The logic to implement this= in > > qemu is very convoluted. This cleans it up to be cleaner, using the new > > ppc_check_compat() call. > >=20 > > The new logic for choosing a compatibility mode is: > > 1. If the guest lists the CPU's real PVR as supported *AND* no > > maximum compatibility mode has been requested on the command line > > then we use "raw" mode - the CPU acts with full capabilities. > > 2. Otherwise, we pick the most recent compatibility mode which is > > both supported by the CPU, and is advertised as supported by the > > guest. > > I think the original code approximated the same thing, but it's hard to= be > > sure, and I think it had some weird edge cases. > >=20 > > Signed-off-by: David Gibson > > --- > > hw/ppc/spapr_hcall.c | 107 +++++++++++++++++--------------------------= -------- > > hw/ppc/trace-events | 2 +- > > 2 files changed, 37 insertions(+), 72 deletions(-) > >=20 > > diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c > > index d93f580..3bd6d06 100644 > > --- a/hw/ppc/spapr_hcall.c > > +++ b/hw/ppc/spapr_hcall.c > > @@ -895,98 +895,63 @@ static void do_set_compat(CPUState *cs, void *arg) > > ppc_set_compat(cpu, s->compat_pvr, &s->err); > > } > > =20 > > -#define get_compat_level(cpuver) ( \ > > - ((cpuver) =3D=3D CPU_POWERPC_LOGICAL_2_05) ? 2050 : \ > > - ((cpuver) =3D=3D CPU_POWERPC_LOGICAL_2_06) ? 2060 : \ > > - ((cpuver) =3D=3D CPU_POWERPC_LOGICAL_2_06_PLUS) ? 2061 : \ > > - ((cpuver) =3D=3D CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0) > > - > > -static void cas_handle_compat_cpu(PowerPCCPUClass *pcc, uint32_t pvr, > > - unsigned max_lvl, unsigned *compat_l= vl, > > - unsigned *compat_pvr) > > -{ > > - unsigned lvl =3D get_compat_level(pvr); > > - bool is205, is206, is207; > > - > > - if (!lvl) { > > - return; > > - } > > - > > - /* If it is a logical PVR, try to determine the highest level */ > > - is205 =3D (pcc->pcr_supported & PCR_COMPAT_2_05) && > > - (lvl =3D=3D get_compat_level(CPU_POWERPC_LOGICAL_2_05)); > > - is206 =3D (pcc->pcr_supported & PCR_COMPAT_2_06) && > > - ((lvl =3D=3D get_compat_level(CPU_POWERPC_LOGICAL_2_06)) || > > - (lvl =3D=3D get_compat_level(CPU_POWERPC_LOGICAL_2_06_PLU= S))); > > - is207 =3D (pcc->pcr_supported & PCR_COMPAT_2_07) && > > - (lvl =3D=3D get_compat_level(CPU_POWERPC_LOGICAL_2_07)); > > - > > - if (is205 || is206 || is207) { > > - if (!max_lvl) { > > - /* User did not set the level, choose the highest */ > > - if (*compat_lvl <=3D lvl) { > > - *compat_lvl =3D lvl; > > - *compat_pvr =3D pvr; > > - } > > - } else if (max_lvl >=3D lvl) { > > - /* User chose the level, don't set higher than this */ > > - *compat_lvl =3D lvl; > > - *compat_pvr =3D pvr; > > - } > > - } > > -} > > - > > -static target_ulong h_client_architecture_support(PowerPCCPU *cpu_, > > +static target_ulong h_client_architecture_support(PowerPCCPU *cpu, > > sPAPRMachineState *s= papr, > > target_ulong opcode, > > target_ulong *args) > > { > > target_ulong list =3D ppc64_phys_to_real(args[0]); > > target_ulong ov_table; > > - PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu_); > > CPUState *cs; > > - bool cpu_match =3D false; > > - unsigned old_compat_pvr =3D cpu_->compat_pvr; > > - unsigned compat_lvl =3D 0, compat_pvr =3D 0; > > - unsigned max_lvl =3D get_compat_level(cpu_->max_compat); > > - int counter; > > + bool explicit_match =3D false; /* Matched the CPU's real PVR */ > > + uint32_t max_compat =3D cpu->max_compat; > > + uint32_t best_compat =3D 0; > > + int i; > > sPAPROptionVector *ov5_guest, *ov5_cas_old, *ov5_updates; > > =20 > > - /* Parse PVR list */ > > - for (counter =3D 0; counter < 512; ++counter) { > > + /* > > + * We scan the supplied table of PVRs looking for two things > > + * 1. Is our real CPU PVR in the list? > > + * 2. What's the "best" listed logical PVR > > + */ > > + for (i =3D 0; i < 512; ++i) { > > uint32_t pvr, pvr_mask; > > =20 > > - pvr_mask =3D ldl_be_phys(&address_space_memory, list); > > - list +=3D 4; > > pvr =3D ldl_be_phys(&address_space_memory, list); >=20 >=20 > LoPAPR: List-entry =3D 4-byte-mask : 4-byte-PVR-value >=20 > This patch changes the order and "cas" fails. Oops, yes, thanks for the catch. --=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 --2uzDqHpccQJpqF2n Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYFtovAAoJEGw4ysog2bOSW5sP/3AcwnItxwfgp0Kr2ZWOihSP PSeIpWCp+W7m/6uSvw0uQbSjAnABZoUIO+zRNR76V2Je/fkF1uCWGjs7Iz6Kfqxm LO7deSco21dtwEzjTkNAFPmeULm7OABqBHd90f2FuNT+sUGRlE+S8lmwI8IMvr7f xnMNi3htNMVU4vhgdRvqqUgMN6akQofIecaqQgipzdbeSO9z4VNePLCIBOzyw0a3 H5TDEkvA7+JPGbCZ0WbebawpN597gUc7LpkGUEg043qd5h0kdmfdXB0Q7J6Kz9jd lKM/sx9oOVbjhD0Q0i5AyxVCWPDoEKfFhYxUJi23Bu4gnld5X7FQEuUIN+UG7vdu vIWYmD3exYiR3PGOycy6uQtmMHo5IL3iRlNExv/0kgJ6PEipF/sh/BOdrHl3U2tC +Kd7W7pOdhn0grKDReeV5Qy5GqiXN0SiOQIHNJAwqCb+74fnzu9Eco8tgPjvw1Up TDMWlGsSOWTSFiFq5Aq1N9xnsXxb4VkSDUXK/aeryG6zQ9BC+ctPcuD4MfvHbdmT jwL8IYLq7axahRY11a/FpE+NTsenUqEFiMvigIZiv7Lay4urJbuPh4dMKhz+hWbu Nvk7ccotISgtvwPS9ut+QFUgf75QLtY52abl3PThVqLST6sOy96EwW31tio+1b4U KsNHo6YexlrO/CT5NWqV =IvYd -----END PGP SIGNATURE----- --2uzDqHpccQJpqF2n--