qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: David Gibson <david@gibson.dropbear.id.au>
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
Subject: Re: [Qemu-devel] [RFC 11/17] ppc: Add ppc_set_compat_all()
Date: Wed, 9 Nov 2016 16:18:20 +1100	[thread overview]
Message-ID: <dc7d6af9-f82f-265c-c569-8fe59a120a52@ozlabs.ru> (raw)
In-Reply-To: <20161109035229.GD427@umbus.fritz.box>

[-- Attachment #1: Type: text/plain, Size: 7349 bytes --]

On 09/11/16 14:52, David Gibson wrote:
> On Wed, Nov 09, 2016 at 12:27:47PM +1100, Alexey Kardashevskiy wrote:
>> On 08/11/16 16:18, David Gibson wrote:
>>> On Fri, Nov 04, 2016 at 03:01:40PM +1100, Alexey Kardashevskiy wrote:
>>>> On 30/10/16 22:12, David Gibson wrote:
>>>>> Once a compatiblity mode is negotiated with the guest,
>>>>> h_client_architecture_support() uses run_on_cpu() to update each CPU to
>>>>> the new mode.  We're going to want this logic somewhere else shortly,
>>>>> so make a helper function to do this global update.
>>>>>
>>>>> We put it in target-ppc/compat.c - it makes as much sense at the CPU level
>>>>> as it does at the machine level.  We also move the cpu_synchronize_state()
>>>>> into ppc_set_compat(), since it doesn't really make any sense to call that
>>>>> without synchronizing state.
>>>>>
>>>>> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
>>>>> ---
>>>>>  hw/ppc/spapr_hcall.c | 31 +++++--------------------------
>>>>>  target-ppc/compat.c  | 36 ++++++++++++++++++++++++++++++++++++
>>>>>  target-ppc/cpu.h     |  3 +++
>>>>>  3 files changed, 44 insertions(+), 26 deletions(-)
>>>>>
>>>>> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
>>>>> index 3bd6d06..4eaf9a6 100644
>>>>> --- a/hw/ppc/spapr_hcall.c
>>>>> +++ b/hw/ppc/spapr_hcall.c
>>>>> @@ -881,20 +881,6 @@ static target_ulong h_set_mode(PowerPCCPU *cpu, sPAPRMachineState *spapr,
>>>>>      return ret;
>>>>>  }
>>>>>  
>>>>> -typedef struct {
>>>>> -    uint32_t compat_pvr;
>>>>> -    Error *err;
>>>>> -} SetCompatState;
>>>>> -
>>>>> -static void do_set_compat(CPUState *cs, void *arg)
>>>>> -{
>>>>> -    PowerPCCPU *cpu = POWERPC_CPU(cs);
>>>>> -    SetCompatState *s = arg;
>>>>> -
>>>>> -    cpu_synchronize_state(cs);
>>>>> -    ppc_set_compat(cpu, s->compat_pvr, &s->err);
>>>>> -}
>>>>> -
>>>>>  static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
>>>>>                                                    sPAPRMachineState *spapr,
>>>>>                                                    target_ulong opcode,
>>>>> @@ -902,7 +888,6 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
>>>>>  {
>>>>>      target_ulong list = ppc64_phys_to_real(args[0]);
>>>>>      target_ulong ov_table;
>>>>> -    CPUState *cs;
>>>>>      bool explicit_match = false; /* Matched the CPU's real PVR */
>>>>>      uint32_t max_compat = cpu->max_compat;
>>>>>      uint32_t best_compat = 0;
>>>>> @@ -949,18 +934,12 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
>>>>>  
>>>>>      /* Update CPUs */
>>>>>      if (cpu->compat_pvr != best_compat) {
>>>>> -        CPU_FOREACH(cs) {
>>>>> -            SetCompatState s = {
>>>>> -                .compat_pvr = best_compat,
>>>>> -                .err = NULL,
>>>>> -            };
>>>>> +        Error *local_err = NULL;
>>>>>  
>>>>> -            run_on_cpu(cs, do_set_compat, &s);
>>>>> -
>>>>> -            if (s.err) {
>>>>> -                error_report_err(s.err);
>>>>> -                return H_HARDWARE;
>>>>> -            }
>>>>> +        ppc_set_compat_all(best_compat, &local_err);
>>>>> +        if (local_err) {
>>>>> +            error_report_err(local_err);
>>>>> +            return H_HARDWARE;
>>>>>          }
>>>>>      }
>>>>>  
>>>>> diff --git a/target-ppc/compat.c b/target-ppc/compat.c
>>>>> index 1059555..0b12b58 100644
>>>>> --- a/target-ppc/compat.c
>>>>> +++ b/target-ppc/compat.c
>>>>> @@ -124,6 +124,8 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp)
>>>>>          pcr = compat->pcr;
>>>>>      }
>>>>>  
>>>>> +    cpu_synchronize_state(CPU(cpu));
>>>>> +
>>>>>      cpu->compat_pvr = compat_pvr;
>>>>>      env->spr[SPR_PCR] = pcr & pcc->pcr_mask;
>>>>>  
>>>>> @@ -136,6 +138,40 @@ void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp)
>>>>>      }
>>>>>  }
>>>>>  
>>>>> +#if !defined(CONFIG_USER_ONLY)
>>>>> +typedef struct {
>>>>> +    uint32_t compat_pvr;
>>>>> +    Error *err;
>>>>> +} SetCompatState;
>>>>> +
>>>>> +static void do_set_compat(CPUState *cs, void *arg)
>>>>> +{
>>>>> +    PowerPCCPU *cpu = POWERPC_CPU(cs);
>>>>> +    SetCompatState *s = arg;
>>>>> +
>>>>> +    ppc_set_compat(cpu, s->compat_pvr, &s->err);
>>>>> +}
>>>>> +
>>>>> +void ppc_set_compat_all(uint32_t compat_pvr, Error **errp)
>>>>> +{
>>>>> +    CPUState *cs;
>>>>> +
>>>>> +    CPU_FOREACH(cs) {
>>>>> +        SetCompatState s = {
>>>>> +            .compat_pvr = compat_pvr,
>>>>> +            .err = NULL,
>>>>> +        };
>>>>> +
>>>>> +        run_on_cpu(cs, do_set_compat, &s);
>>>>> +
>>>>> +        if (s.err) {
>>>>> +            error_propagate(errp, s.err);
>>>>> +            return;
>>>>> +        }
>>>>> +    }
>>>>> +}
>>>>> +#endif
>>>>> +
>>>>>  int ppc_compat_max_threads(PowerPCCPU *cpu)
>>>>>  {
>>>>>      const CompatInfo *compat = compat_by_pvr(cpu->compat_pvr);
>>>>> diff --git a/target-ppc/cpu.h b/target-ppc/cpu.h
>>>>> index 91e8be8..201a655 100644
>>>>> --- a/target-ppc/cpu.h
>>>>> +++ b/target-ppc/cpu.h
>>>>> @@ -1317,6 +1317,9 @@ static inline int cpu_mmu_index (CPUPPCState *env, bool ifetch)
>>>>>  bool ppc_check_compat(PowerPCCPU *cpu, uint32_t compat_pvr,
>>>>>                        uint32_t min_compat_pvr, uint32_t max_compat_pvr);
>>>>>  void ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr, Error **errp);
>>>>> +#if !defined(CONFIG_USER_ONLY)
>>>>> +void ppc_set_compat_all(uint32_t compat_pvr, Error **errp);
>>>>> +#endif
>>>>
>>>> I would put all ppc*compat*() under #if defined(CONFIG_USER_ONLY) &&
>>>> defined(TARGET_PPC64) (or even moved this to target-ppc/Makefile.objs).
>>>
>>> I was originally going to do that, but decided against it.
>>>
>>>> Otherwise, functions like ppc_check_compat() have #if
>>>> !defined(CONFIG_USER_ONLY) which suggests that the rest of
>>>> ppc_check_compat() can actually be executed in ppc64-linux-user (while it
>>>> cannot, can it?).
>>>
>>> It won't be, but there's no theoretical reason they couldn't be.  User
>>> mode, like spapr, doesn't execute hypervisor privilege code, and so
>>> the PCR isn't owned by the "guest" (if you can call the user mode
>>> executable that).  Which means it could make sense to set it from the
>>> outside, although that's not something we currently do.
>>
>> Compatibility modes are designed to disable sets of instructions to keep
>> working old userspace software which relies on some opcodes to be invalid.
>>
>> linux-user is TCG, right? The user can pick any CPU he likes if there is
>> need to run such an old software, why on earth would anyone bother with
>> this compat mode in linux-user?
> 
> True, I can't really see any reason to do that.
> 
> On the other hand, compat mode does at least make theoretical sense,
> whereas, for example, compat mode on powernv is fundamentally
> nonsense.  At this point I'm not terribly include to take away the
> (token) user-only support unless there's a compelling reason *not* to
> include it.

What would make a compelling reason? :)

This will make makefile simpler and will reduce number of #ifdef, and in
fact it is not supported now anyway, it has not even been tried.



-- 
Alexey


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 839 bytes --]

  reply	other threads:[~2016-11-09  5:18 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
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 [this message]
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=dc7d6af9-f82f-265c-c569-8fe59a120a52@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=david@gibson.dropbear.id.au \
    --cc=lvivier@redhat.com \
    --cc=mdroth@linux.vnet.ibm.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).