From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: David Gibson <david@gibson.dropbear.id.au>,
nikunj@linux.vnet.ibm.com, aik@ozlabs.ru
Cc: thuth@redhat.com, lvivier@redhat.com, qemu-ppc@nongnu.org,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC 10/17] pseries: Rewrite CAS PVR compatibility logic
Date: Thu, 10 Nov 2016 11:54:13 -0600 [thread overview]
Message-ID: <20161110175413.32249.77477@loki> (raw)
In-Reply-To: <1477825928-10803-11-git-send-email-david@gibson.dropbear.id.au>
Quoting David Gibson (2016-10-30 06:12:01)
> 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.
>
> 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.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> hw/ppc/spapr_hcall.c | 107 +++++++++++++++++----------------------------------
> hw/ppc/trace-events | 2 +-
> 2 files changed, 37 insertions(+), 72 deletions(-)
>
> 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);
> }
>
> -#define get_compat_level(cpuver) ( \
> - ((cpuver) == CPU_POWERPC_LOGICAL_2_05) ? 2050 : \
> - ((cpuver) == CPU_POWERPC_LOGICAL_2_06) ? 2060 : \
> - ((cpuver) == CPU_POWERPC_LOGICAL_2_06_PLUS) ? 2061 : \
> - ((cpuver) == CPU_POWERPC_LOGICAL_2_07) ? 2070 : 0)
> -
> -static void cas_handle_compat_cpu(PowerPCCPUClass *pcc, uint32_t pvr,
> - unsigned max_lvl, unsigned *compat_lvl,
> - unsigned *compat_pvr)
> -{
> - unsigned lvl = get_compat_level(pvr);
> - bool is205, is206, is207;
> -
> - if (!lvl) {
> - return;
> - }
> -
> - /* If it is a logical PVR, try to determine the highest level */
> - is205 = (pcc->pcr_supported & PCR_COMPAT_2_05) &&
> - (lvl == get_compat_level(CPU_POWERPC_LOGICAL_2_05));
> - is206 = (pcc->pcr_supported & PCR_COMPAT_2_06) &&
> - ((lvl == get_compat_level(CPU_POWERPC_LOGICAL_2_06)) ||
> - (lvl == get_compat_level(CPU_POWERPC_LOGICAL_2_06_PLUS)));
> - is207 = (pcc->pcr_supported & PCR_COMPAT_2_07) &&
> - (lvl == 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 <= lvl) {
> - *compat_lvl = lvl;
> - *compat_pvr = pvr;
> - }
> - } else if (max_lvl >= lvl) {
> - /* User chose the level, don't set higher than this */
> - *compat_lvl = lvl;
> - *compat_pvr = pvr;
> - }
> - }
> -}
> -
> -static target_ulong h_client_architecture_support(PowerPCCPU *cpu_,
> +static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
> sPAPRMachineState *spapr,
> target_ulong opcode,
> target_ulong *args)
> {
> target_ulong list = ppc64_phys_to_real(args[0]);
> target_ulong ov_table;
> - PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu_);
> CPUState *cs;
> - bool cpu_match = false;
> - unsigned old_compat_pvr = cpu_->compat_pvr;
> - unsigned compat_lvl = 0, compat_pvr = 0;
> - unsigned max_lvl = get_compat_level(cpu_->max_compat);
> - int counter;
> + bool explicit_match = false; /* Matched the CPU's real PVR */
> + uint32_t max_compat = cpu->max_compat;
> + uint32_t best_compat = 0;
> + int i;
> sPAPROptionVector *ov5_guest, *ov5_cas_old, *ov5_updates;
>
> - /* Parse PVR list */
> - for (counter = 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 = 0; i < 512; ++i) {
> uint32_t pvr, pvr_mask;
>
> - pvr_mask = ldl_be_phys(&address_space_memory, list);
> - list += 4;
> pvr = ldl_be_phys(&address_space_memory, list);
> - list += 4;
> -
> - trace_spapr_cas_pvr_try(pvr);
> - if (!max_lvl &&
> - ((cpu_->env.spr[SPR_PVR] & pvr_mask) == (pvr & pvr_mask))) {
> - cpu_match = true;
> - compat_pvr = 0;
> - } else if (pvr == cpu_->compat_pvr) {
> - cpu_match = true;
> - compat_pvr = cpu_->compat_pvr;
> - } else if (!cpu_match) {
> - cas_handle_compat_cpu(pcc, pvr, max_lvl, &compat_lvl, &compat_pvr);
> - }
> - /* Terminator record */
> + pvr_mask = ldl_be_phys(&address_space_memory, list + 4);
> + list += 8;
> +
> if (~pvr_mask & pvr) {
> - break;
> + break; /* Terminator record */
> }
> +
> + if ((cpu->env.spr[SPR_PVR] & pvr_mask) == (pvr & pvr_mask)) {
> + explicit_match = true;
The previous code only did this check if max_lvl/max_compat was set. I'm
not sure if it's possible in practice, but in theory this PVR might also
happen to be the next best_compat PVR, but since we test positive here
we may not not set best_compat accordingly.
> + } else {
> + if (ppc_check_compat(cpu, pvr, best_compat, max_compat)) {
> + best_compat = pvr;
> + }
> + }
> + }
> +
> + if (!max_compat && explicit_match) {
> + /* If the guest explicitly supports the CPU, *and* user hasn't
> + * requested a compatibility mode, use "raw" mode */
> + best_compat = 0;
> + } else if (best_compat == 0) {
> + /* Didn't find any supported compat modes */
> + /* FIXME: what's the right error here? */
> + return H_HARDWARE;
> }
>
> /* Parsing finished */
> - trace_spapr_cas_pvr(cpu_->compat_pvr, cpu_match,
> - compat_pvr, pcc->pcr_mask);
> + trace_spapr_cas_pvr(cpu->compat_pvr, explicit_match, best_compat);
>
> /* Update CPUs */
> - if (old_compat_pvr != compat_pvr) {
> + if (cpu->compat_pvr != best_compat) {
> CPU_FOREACH(cs) {
> SetCompatState s = {
> - .compat_pvr = compat_pvr,
> + .compat_pvr = best_compat,
> .err = NULL,
> };
>
> diff --git a/hw/ppc/trace-events b/hw/ppc/trace-events
> index 2297ead..604ac92 100644
> --- a/hw/ppc/trace-events
> +++ b/hw/ppc/trace-events
> @@ -15,7 +15,7 @@ spapr_cas_continue(unsigned long n) "Copy changes to the guest: %ld bytes"
>
> # hw/ppc/spapr_hcall.c
> spapr_cas_pvr_try(uint32_t pvr) "%x"
> -spapr_cas_pvr(uint32_t cur_pvr, bool cpu_match, uint32_t new_pvr, uint64_t pcr) "current=%x, cpu_match=%u, new=%x, compat flags=%"PRIx64
> +spapr_cas_pvr(uint32_t cur_pvr, bool explicit_match, uint32_t new_pvr) "current=%x, explicit_match=%u, new=%x"
>
> # hw/ppc/spapr_iommu.c
> spapr_iommu_put(uint64_t liobn, uint64_t ioba, uint64_t tce, uint64_t ret) "liobn=%"PRIx64" ioba=0x%"PRIx64" tce=0x%"PRIx64" ret=%"PRId64
> --
> 2.7.4
>
next prev parent reply other threads:[~2016-11-10 17:54 UTC|newest]
Thread overview: 75+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-30 11:11 [Qemu-devel] [RFC 00/17] Clean up compatibility mode handling David Gibson
2016-10-30 11:11 ` [Qemu-devel] [RFC 01/17] ppc: Remove some stub POWER6 models David Gibson
2016-10-31 7:38 ` Thomas Huth
2016-10-31 8:37 ` David Gibson
2016-11-08 3:40 ` David Gibson
2016-10-30 11:11 ` [Qemu-devel] [RFC 02/17] powernv: CPU compatibility modes don't make sense for powernv David Gibson
2016-10-31 7:46 ` Thomas Huth
2016-10-31 8:38 ` David Gibson
2016-10-31 10:35 ` Greg Kurz
2016-10-30 11:11 ` [Qemu-devel] [RFC 03/17] pseries: Always use core objects for CPU construction David Gibson
2016-11-03 8:11 ` Alexey Kardashevskiy
2016-11-04 9:51 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-11-08 5:34 ` David Gibson
2016-10-30 11:11 ` [Qemu-devel] [RFC 04/17] pseries: Make cpu_update during CAS unconditional David Gibson
2016-11-03 8:24 ` Alexey Kardashevskiy
2016-11-04 10:45 ` Thomas Huth
2016-11-08 3:44 ` David Gibson
2016-10-30 11:11 ` [Qemu-devel] [RFC 05/17] ppc: Clean up and QOMify hypercall emulation David Gibson
2016-11-03 8:50 ` Alexey Kardashevskiy
2016-10-30 11:11 ` [Qemu-devel] [RFC 06/17] ppc: Rename cpu_version to compat_pvr David Gibson
2016-11-04 2:26 ` Alexey Kardashevskiy
2016-11-08 3:48 ` David Gibson
2016-11-04 10:51 ` Thomas Huth
2016-10-30 11:11 ` [Qemu-devel] [RFC 07/17] ppc: Rewrite ppc_set_compat() David Gibson
2016-11-04 2:57 ` Alexey Kardashevskiy
2016-11-08 3:49 ` David Gibson
2016-10-30 11:11 ` [Qemu-devel] [RFC 08/17] ppc: Rewrite ppc_get_compat_smt_threads() David Gibson
2016-11-04 3:37 ` Alexey Kardashevskiy
2016-11-08 5:13 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 09/17] ppc: Validate compatibility modes when setting David Gibson
2016-10-31 5:55 ` Alexey Kardashevskiy
2016-10-31 8:39 ` David Gibson
2016-11-04 3:45 ` Alexey Kardashevskiy
2016-11-08 5:14 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 10/17] pseries: Rewrite CAS PVR compatibility logic David Gibson
2016-10-31 5:00 ` Alexey Kardashevskiy
2016-10-31 5:44 ` David Gibson
2016-11-10 17:54 ` Michael Roth [this message]
2016-11-10 23:50 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 11/17] ppc: Add ppc_set_compat_all() David Gibson
2016-11-04 4:01 ` Alexey Kardashevskiy
2016-11-08 5:18 ` David Gibson
2016-11-09 1:27 ` Alexey Kardashevskiy
2016-11-09 3:52 ` David Gibson
2016-11-09 5:18 ` Alexey Kardashevskiy
2016-11-10 3:13 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 12/17] ppc: Migrate compatibility mode David Gibson
2016-11-04 5:58 ` Alexey Kardashevskiy
2016-11-08 5:19 ` David Gibson
2016-11-08 5:51 ` Alexey Kardashevskiy
2016-11-10 1:59 ` David Gibson
2016-11-10 23:55 ` Michael Roth
2016-11-14 1:15 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 13/17] pseries: Move CPU compatibility property to machine David Gibson
2016-11-04 7:43 ` Alexey Kardashevskiy
2016-11-08 5:26 ` David Gibson
2016-11-08 5:56 ` Alexey Kardashevskiy
2016-11-09 4:41 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 14/17] pseries: Reset CPU compatibility mode David Gibson
2016-11-04 7:50 ` Alexey Kardashevskiy
2016-10-30 11:12 ` [Qemu-devel] [RFC 15/17] ppc: Check that CPU model stays consistent across migration David Gibson
2016-11-04 7:54 ` Alexey Kardashevskiy
2016-11-08 5:29 ` David Gibson
2016-11-08 6:03 ` Alexey Kardashevskiy
2016-11-09 4:24 ` David Gibson
2016-11-09 6:06 ` Alexey Kardashevskiy
2016-11-09 6:40 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 16/17] ppc: Remove counter-productive "sanity checks" in migration David Gibson
2016-11-04 5:52 ` Alexey Kardashevskiy
2016-11-08 5:31 ` David Gibson
2016-11-11 18:13 ` [Qemu-devel] [Qemu-ppc] " Greg Kurz
2016-11-14 2:34 ` Alexey Kardashevskiy
2016-11-14 6:08 ` David Gibson
2016-10-30 11:12 ` [Qemu-devel] [RFC 17/17] pseries: Default to POWER8 compatibility mode David Gibson
2016-10-30 11:58 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161110175413.32249.77477@loki \
--to=mdroth@linux.vnet.ibm.com \
--cc=aik@ozlabs.ru \
--cc=david@gibson.dropbear.id.au \
--cc=lvivier@redhat.com \
--cc=nikunj@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).