spapr: Cleanups to PAPR mode setup
cover spapr: Cleanups to PAPR mode setup
This series contains a number of cleanups to the way we set up and start a guest in PAPR mode.
Applies on top of my ppc-for-2.13 branch.
David Gibson (10):
spapr: Avoid redundant calls to spapr_cpu_reset()
spapr: Remove support for PowerPC 970 with pseries machine type target/ppc: Remove unnecessary initialization of LPCR_UPRT
spapr: Set compatibility mode before the rest of spapr_cpu_reset()
spapr: Move PAPR mode register initialization to spapr code target/ppc: Add ppc_store_lpcr() helper
spapr: Make a helper to set up cpu entry point state
spapr: Clean up handling of LPCR power-saving exit bits target/ppc: Don't bother with MSR_EP in cpu_ppc_set_papr()
spapr: Move PAPR specific cpu logic to pseries machine type
hw/ppc/spapr.c | 71 ++++++++++++++--------------------------- hw/ppc/spapr_cpu_core.c | 71 +++++++++++++++++++++++++++++++---------- hw/ppc/spapr_rtas.c | 10 ++---- include/hw/ppc/spapr_cpu_core.h | 5 +++ target/ppc/cpu.h | 2 +- target/ppc/kvm.c | 40 +++-------------------- target/ppc/kvm_ppc.h | 6 ---- target/ppc/mmu-hash64.c | 15 ++++++--- target/ppc/mmu-hash64.h | 3 +- target/ppc/translate_init.c | 71 +++-------------------------------------- 10 files changed, 109 insertions(+), 185 deletions(-)
Signature · 1 line
2.14.3
PATCH 1/10 spapr: Avoid redundant calls to spapr_cpu_reset()
af81cf323c1 "spapr: CPU hotplug support" added a direct call to spapr_cpu_reset() in spapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.
However, this change means that spapr_cpu_reset() gets called twice for normal cold-plugged cpus: once from spapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.
So, we remove the reset call from spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.
--- hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)
hw/ppc/spapr.c +4 -2
@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,if (hotplugged) {/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);spapr_hotplug_req_add_by_index (drc); }else {spapr_drc_reset (drc);
hw/ppc/spapr_cpu_core.c +12 -1
@@ -70,7 +70,6 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr));qemu_register_reset (spapr_cpu_reset, cpu); -spapr_cpu_reset (cpu); }/*
@@ -208,6 +207,18 @@ err:error_propagate (errp, local_err); } +void spapr_cpu_core_reset (sPAPRCPUCore *sc) +{ +CPUCore *cc =CPU_CORE (sc); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +PowerPCCPU *cpu = sc->threads[i]; + +spapr_cpu_reset (cpu); + } +} +static Property spapr_cpu_core_properties[] = {DEFINE_PROP_INT32 ("node-id" , sPAPRCPUCore, node_id,CPU_UNSET_NUMA_NODE_ID ),DEFINE_PROP_END_OF_LIST ()
include/hw/ppc/spapr_cpu_core.h +2 -0
@@ -38,4 +38,6 @@ typedef struct sPAPRCPUCoreClass { } sPAPRCPUCoreClass;const char *spapr_get_cpu_core_type (const char *cpu_type); +void spapr_cpu_core_reset (sPAPRCPUCore *sc); +#endif
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 01/10] spapr: Avoid redundant calls to spapr_cpu_reset()
Quoted 12 lines · On Tue, 17 Apr 2018 17:17:13 +1000 David Gibson <[email protected]>…
af81cf323c1"spapr: CPU hotplug support" added a direct call tospapr_cpu_reset()inspapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.However, this change means that
spapr_cpu_reset()gets called twice for normal cold-plugged cpus: once fromspapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.
Quoted 5 lines
So, we remove the reset call from
spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.Signed-off-by David Gibson <[email protected]>---
I had sent a tentative patch to do something similar earlier this year:
https://patchwork.ozlabs.org/patch/862116/
but it got nacked for several reasons, one of them being you were "always wary of using the hotplugged parameter, because what qemu means by it often doesn't line up with what PAPR means by it."
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3371
Quoted 12 lines
hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,if (hotplugged) {
... but you rely on it here. Can you explain why it is okay now ?
Also, if QEMU is started with -incoming and the CPU core is hotplugged before migration begins, the following will return false:
static inline bool spapr_drc_hotplugged(DeviceState *dev)
{
return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE);
}and the CPU core won't be reset.
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3377
Quoted 8 lines
hw/ppc/spapr.c +4
-2/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);
spapr_cpu_reset() also sets the compat mode, which is used to set some properties in the DT, ie, this should be called before spapr_populate_hotplug_cpu_dt().
hw/ppc/spapr_cpu_core.c static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, · line 73
Quoted 12 lines
hw/ppc/spapr.c +0
-0spapr_hotplug_req_add_by_index (drc); }else {spapr_drc_reset (drc);hw/ppc/spapr_cpu_core.c +0
-1@@ -70,7 +70,6 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr));qemu_register_reset (spapr_cpu_reset, cpu); -spapr_cpu_reset (cpu);
spapr_cpu_reset() also sets cs->halted to 1, to let the guest start non-boot CPUs with an RTAS call. With this change, a hotplugged CPU is started right away and may run in the guest before the hotplug path could even reset it.
Not sure how to handle that other than setting halted to 1 in spapr_cpu_init() as well, but you already nacked that approach because it would mean "poking specifics in a CPU that hasn't already been set to a known state by a reset"...
Quoted 33 lines
hw/ppc/spapr_cpu_core.c +12
-0}/* @@ -208,6 +207,18 @@ err:error_propagate (errp, local_err); } +void spapr_cpu_core_reset (sPAPRCPUCore *sc) +{ +CPUCore *cc =CPU_CORE (sc); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +PowerPCCPU *cpu = sc->threads[i]; + +spapr_cpu_reset (cpu); + } +} +static Property spapr_cpu_core_properties[] = {DEFINE_PROP_INT32 ("node-id" , sPAPRCPUCore, node_id,CPU_UNSET_NUMA_NODE_ID ),DEFINE_PROP_END_OF_LIST ()include/hw/ppc/spapr_cpu_core.h +2
-0@@ -38,4 +38,6 @@ typedef struct sPAPRCPUCoreClass { } sPAPRCPUCoreClass;const char *spapr_get_cpu_core_type (const char *cpu_type); +void spapr_cpu_core_reset (sPAPRCPUCore *sc); +#endif
Re: [Qemu-devel] [PATCH for-2.13 01/10] spapr: Avoid redundant calls to spapr_cpu_reset()
Quoted 21 lines · Greg Kurz
Quoted 12 lines · On Tue, 17 Apr 2018 17:17:13 +1000 David Gibson <[email protected]>…
af81cf323c1"spapr: CPU hotplug support" added a direct call tospapr_cpu_reset()inspapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.However, this change means that
spapr_cpu_reset()gets called twice for normal cold-plugged cpus: once fromspapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.Quoted 5 lines
So, we remove the reset call from
spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.Signed-off-by David Gibson <[email protected]>---
Quoted 7 lines
I had sent a tentative patch to do something similar earlier this year:
https://patchwork.ozlabs.org/patch/862116/
but it got nacked for several reasons, one of them being you were "always wary of using the hotplugged parameter, because what qemu means by it often doesn't line up with what PAPR means by it."
Yeah, I was and am wary of that, but convinced myself it was correct in this case (which doesn't really interact with the PAPR meaning of hotplug).
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
Quoted 4 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3371
Quoted 1 line
hw/ppc/spapr.c +0
-0if (hotplugged) {... but you rely on it here. Can you explain why it is okay now ?
So the value I actually need here is "wasn't present at the last system reset" (with false positives being mostly harmless, but not false negatives).
Quoted 10 lines
Also, if QEMU is started with -incoming and the CPU core is hotplugged before migration begins, the following will return false:
static inline bool
spapr_drc_hotplugged(DeviceState *dev){ return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); }and the CPU core won't be reset.
Uh... spapr_dtc_hotplugged() would definitely be wrong here, which is why I'm not using it.
Quoted 10 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3377
Quoted 9 lines
hw/ppc/spapr.c +4
-2/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);
Quoted 3 lines
spapr_cpu_reset()also sets the compat mode, which is used to set some properties in the DT, ie, this should be called beforespapr_populate_hotplug_cpu_dt().
Good point. I've moved the reset to fix that.
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c +0
-0spapr_hotplug_req_add_by_index (drc); }else {spapr_drc_reset (drc);hw/ppc/spapr_cpu_core.c +0
-0@@ -70,7 +70,6 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr));
Quoted 7 lines
hw/ppc/spapr_cpu_core.c static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, · line 73
Quoted 2 lines
hw/ppc/spapr_cpu_core.c +0
-1qemu_register_reset (spapr_cpu_reset, cpu); -spapr_cpu_reset (cpu);
spapr_cpu_reset()also setscs->haltedto 1, to let the guest start non-boot CPUs with an RTAS call. With this change, a hotplugged CPU is started right away and may run in the guest before the hotplug path could even reset it.
Uh.. I was assuming the plug path (the qemu side, obviously, not the guest side) would be completed before the cpu could execute. If that's not the case I'll definitely have to rethink this.
Quoted 4 lines
Not sure how to handle that other than setting halted to 1 in
spapr_cpu_init()as well, but you already nacked that approach because it would mean "poking specifics in a CPU that hasn't already been set to a known state by a reset"...
Yeah.. I may have been off base with that comment. Bear in mind that at the time I didn't see a specific reason to avoid the double reset - now I do.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH for-2.13 01/10] spapr: Avoid redundant calls to spapr_cpu_reset()
Quoted 45 lines · On Fri, 20 Apr 2018 16:34:37 +1000 David Gibson <[email protected]>…
Quoted 21 lines · Greg Kurz
Quoted 12 lines · On Tue, 17 Apr 2018 17:17:13 +1000 David Gibson <[email protected]>…
af81cf323c1"spapr: CPU hotplug support" added a direct call tospapr_cpu_reset()inspapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.However, this change means that
spapr_cpu_reset()gets called twice for normal cold-plugged cpus: once fromspapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.Quoted 5 lines
So, we remove the reset call from
spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.Signed-off-by David Gibson <[email protected]>---
Quoted 7 lines
I had sent a tentative patch to do something similar earlier this year:
https://patchwork.ozlabs.org/patch/862116/
but it got nacked for several reasons, one of them being you were "always wary of using the hotplugged parameter, because what qemu means by it often doesn't line up with what PAPR means by it."
Yeah, I was and am wary of that, but convinced myself it was correct in this case (which doesn't really interact with the PAPR meaning of hotplug).
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
Quoted 9 lines
Quoted 4 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3371
Quoted 1 line
hw/ppc/spapr.c +0
-0if (hotplugged) {... but you rely on it here. Can you explain why it is okay now ?
So the value I actually need here is "wasn't present at the last system reset" (with false positives being mostly harmless, but not false negatives).
Hmm... It is rather the other way around, sth like "will be caught by the initial machine reset".
Quoted 9 lines
Quoted 9 lines
Also, if QEMU is started with -incoming and the CPU core is hotplugged before migration begins, the following will return false:
static inline bool
spapr_drc_hotplugged(DeviceState *dev){ return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); }
Quoted 5 lines
Quoted 1 line
and the CPU core won't be reset.
Uh...
spapr_dtc_hotplugged()would definitely be wrong here, which is why I'm not using it.
This is how hotplugged is set in spapr_core_plug():
bool hotplugged = spapr_drc_hotplugged(dev);
but to detect the "will be caught by the initial machine reset" condition, we only need to check dev->hotplugged actually.
Quoted 35 lines
Quoted 10 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3377
Quoted 9 lines
hw/ppc/spapr.c +4
-2/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);Quoted 3 lines
spapr_cpu_reset()also sets the compat mode, which is used to set some properties in the DT, ie, this should be called beforespapr_populate_hotplug_cpu_dt().Good point. I've moved the reset to fix that.
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c +0
-0spapr_hotplug_req_add_by_index (drc); }else {spapr_drc_reset (drc);hw/ppc/spapr_cpu_core.c +0
-0@@ -70,7 +70,6 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr));Quoted 7 lines
hw/ppc/spapr_cpu_core.c static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, · line 73
Quoted 2 lines
hw/ppc/spapr_cpu_core.c +0
-1qemu_register_reset (spapr_cpu_reset, cpu); -spapr_cpu_reset (cpu);
spapr_cpu_reset()also setscs->haltedto 1, to let the guest start non-boot CPUs with an RTAS call. With this change, a hotplugged CPU is started right away and may run in the guest before the hotplug path could even reset it.
Quoted 4 lines
Uh.. I was assuming the plug path (the qemu side, obviously, not the guest side) would be completed before the cpu could execute. If that's not the case I'll definitely have to rethink this.
It isn't the case unless @halted is set.
Quoted 9 lines
Quoted 4 lines
Not sure how to handle that other than setting halted to 1 in
spapr_cpu_init()as well, but you already nacked that approach because it would mean "poking specifics in a CPU that hasn't already been set to a known state by a reset"...Yeah.. I may have been off base with that comment. Bear in mind that at the time I didn't see a specific reason to avoid the double reset - now I do.
Fair enough :)
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 01/10] spapr: Avoid redundant calls to spapr_cpu_reset()
Quoted 76 lines · On Fri, 20 Apr 2018 11:15:01 +0200 Greg Kurz <[email protected]> wrote:
Quoted 45 lines · On Fri, 20 Apr 2018 16:34:37 +1000 David Gibson <[email protected]>…
Quoted 21 lines · Greg Kurz
Quoted 12 lines · On Tue, 17 Apr 2018 17:17:13 +1000 David Gibson <[email protected]>…
af81cf323c1"spapr: CPU hotplug support" added a direct call tospapr_cpu_reset()inspapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.However, this change means that
spapr_cpu_reset()gets called twice for normal cold-plugged cpus: once fromspapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.Quoted 5 lines
So, we remove the reset call from
spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.Signed-off-by David Gibson <[email protected]>---
Quoted 7 lines
I had sent a tentative patch to do something similar earlier this year:
https://patchwork.ozlabs.org/patch/862116/
but it got nacked for several reasons, one of them being you were "always wary of using the hotplugged parameter, because what qemu means by it often doesn't line up with what PAPR means by it."
Yeah, I was and am wary of that, but convinced myself it was correct in this case (which doesn't really interact with the PAPR meaning of hotplug).
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Quoted 9 lines
Quoted 4 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3371
Quoted 1 line
hw/ppc/spapr.c +0
-0if (hotplugged) {... but you rely on it here. Can you explain why it is okay now ?
So the value I actually need here is "wasn't present at the last system reset" (with false positives being mostly harmless, but not false negatives).
Hmm... It is rather the other way around, sth like "will be caught by the initial machine reset".
Quoted 9 lines
Quoted 9 lines
Also, if QEMU is started with -incoming and the CPU core is hotplugged before migration begins, the following will return false:
static inline bool
spapr_drc_hotplugged(DeviceState *dev){ return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); }Quoted 5 lines
Quoted 1 line
and the CPU core won't be reset.
Uh...
spapr_dtc_hotplugged()would definitely be wrong here, which is why I'm not using it.
Quoted 23 lines
This is how hotplugged is set in
spapr_core_plug():bool hotplugged = spapr_drc_hotplugged(dev);but to detect the "will be caught by the initial machine reset" condition, we only need to check
dev->hotpluggedactually.Quoted 16 lines
Quoted 10 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3377
Quoted 9 lines
hw/ppc/spapr.c +4
-2/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);Quoted 3 lines
spapr_cpu_reset()also sets the compat mode, which is used to set some properties in the DT, ie, this should be called beforespapr_populate_hotplug_cpu_dt().Good point. I've moved the reset to fix that.
Thinking of it again: since cold-plugged devices reach this before machine reset, we would then attach to the DRC a DT blob based on a non-reset CPU :-\
Instead of registering a reset handler for each individual CPUs, maybe we should rather register it a the CPU core level. The handler would first reset all CPUs in the core and then setup the DRC for new cores only, like it is done currently in spapr_core_plug().
spapr_core_plug() would then just need to register the reset handler, and call it only for hotplugged cores.
I've tweaked your patch to implement this, and could do some basic plug/unplug tests without seeing anything wrong. But I'll be on vacation next week (currently packing), so I inline it below as food for thought.
-----------------------------------------------------------------------------------
hw/ppc/spapr.c | 62 ++++++++++++++++++++++++++++----------- hw/ppc/spapr_cpu_core.c | 27 +++++++++++------ include/hw/ppc/spapr_cpu_core.h | 2 + 3 files changed, 64 insertions(+), 27 deletions(-)
hw/ppc/spapr.c +45 -17
@@ -3388,6 +3388,36 @@ static void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset,return fdt; } +static void spapr_core_reset (void *opaque) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); +DeviceState *dev =DEVICE (opaque); +CPUCore *cc =CPU_CORE (dev); +sPAPRCPUCore *sc =SPAPR_CPU_CORE (dev); +CPUState *cs =CPU (sc->threads[0 ]); +sPAPRDRConnector *drc; + +spapr_cpu_core_reset (sc); + + drc =spapr_drc_by_id (TYPE_SPAPR_DRC_CPU , +spapr_vcpu_id (spapr, cc->core_id)); + +assert (drc); + +if (!drc->dev) { +void *fdt; +int fdt_offset; + + fdt =spapr_populate_hotplug_cpu_dt (cs, &fdt_offset, spapr); + +spapr_drc_attach (drc, dev, fdt, fdt_offset, &error_abort); + +if (!spapr_drc_hotplugged (dev)) { +spapr_drc_reset (drc); + } + } +} +/* Callback to be called during DRC release. */ void spapr_core_release (DeviceState *dev) {
@@ -3395,9 +3425,9 @@ void spapr_core_release(DeviceState *dev)sPAPRMachineClass *smc =SPAPR_MACHINE_GET_CLASS (ms);CPUCore *cc =CPU_CORE (dev);CPUArchId *core_slot =spapr_find_cpu_slot (ms, cc->core_id,NULL ); +sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev));if (smc->pre_2_10_has_unused_icps) { -sPAPRCPUCore *sc =SPAPR_CPU_CORE (OBJECT (dev));int i;for (i =0 ; i < cc->nr_threads; i++) {
@@ -3407,6 +3437,8 @@ void spapr_core_release(DeviceState *dev) } } +qemu_unregister_reset (spapr_core_reset, sc); +assert (core_slot); core_slot->cpu =NULL ;object_unparent (OBJECT (dev));
@@ -3448,12 +3480,9 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,sPAPRMachineClass *smc =SPAPR_MACHINE_CLASS (mc);sPAPRCPUCore *core =SPAPR_CPU_CORE (OBJECT (dev));CPUCore *cc =CPU_CORE (dev); -CPUState *cs =CPU (core->threads[0 ]);sPAPRDRConnector *drc; -Error *local_err =NULL ;CPUArchId *core_slot;int index; -bool hotplugged =spapr_drc_hotplugged (dev); core_slot =spapr_find_cpu_slot (MACHINE (hotplug_dev), cc->core_id, &index);if (!core_slot) {
@@ -3467,32 +3496,31 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,g_assert (drc || !mc->has_hotpluggable_cpus);if (drc) { -void *fdt; -int fdt_offset; - - fdt =spapr_populate_hotplug_cpu_dt (cs, &fdt_offset, spapr); - -spapr_drc_attach (drc, dev, fdt, fdt_offset, &local_err); -if (local_err) { -g_free (fdt); -error_propagate (errp, local_err); -return ; +/* The boot core and any core specified on the command line will +* be reset during the initial machine reset. Filter them out based +* on @hotplugged which is set to false in this case. Another case +* is when a core is added after the machine was shutdown: no need +* to reset here since a system reset is needed to restart the machine. +*/ +if (dev->hotplugged && !runstate_check (RUN_STATE_SHUTDOWN )) { +spapr_core_reset (core); } -if (hotplugged) { +if (spapr_drc_hotplugged (dev)) {/* * Send hotplug notification interrupt to the guest only * in case of hotplugged CPUs. */ spapr_hotplug_req_add_by_index (drc); - }else { -spapr_drc_reset (drc); } } +qemu_register_reset (spapr_core_reset, core); + core_slot->cpu =OBJECT (dev);if (smc->pre_2_10_has_unused_icps) { +CPUState *cs =CPU (core->threads[0 ]);int i;for (i =0 ; i < cc->nr_threads; i++) {
hw/ppc/spapr_cpu_core.c +17 -10
@@ -22,9 +22,8 @@#include "sysemu/hw_accel.h" #include "qemu/error-report.h" -static void spapr_cpu_reset (void *opaque) +static void spapr_cpu_reset (PowerPCCPU *cpu) { -PowerPCCPU *cpu = opaque;CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);
@@ -50,11 +49,6 @@ static void spapr_cpu_reset(void *opaque) } -static void spapr_cpu_destroy (PowerPCCPU *cpu) -{ -qemu_unregister_reset (spapr_cpu_reset, cpu); -} -static void spapr_cpu_init (sPAPRMachineState *spapr,PowerPCCPU *cpu,Error **errp) {
@@ -66,8 +60,10 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,/* Enable PAPR mode in TCG or KVM */ cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr)); -qemu_register_reset (spapr_cpu_reset, cpu); -spapr_cpu_reset (cpu); +/* All CPUs start halted. CPU0 is unhalted from the machine level +* reset code and the rest are explicitly started up by the guest +* using an RTAS call */ +CPU (cpu)->halted =1 ; }/*
@@ -101,7 +97,6 @@ static void spapr_cpu_core_unrealizefn(DeviceState *dev, Error **errp)CPUState *cs =CPU (dev);PowerPCCPU *cpu =POWERPC_CPU (cs); -spapr_cpu_destroy (cpu);object_unparent (cpu->intc);cpu_remove_sync (cs);object_unparent (obj);
@@ -205,6 +200,18 @@ err:error_propagate (errp, local_err); } +void spapr_cpu_core_reset (sPAPRCPUCore *sc) +{ +CPUCore *cc =CPU_CORE (sc); +int i; + +for (i =0 ; i < cc->nr_threads; i++) { +PowerPCCPU *cpu = sc->threads[i]; + +spapr_cpu_reset (cpu); + } +} +static Property spapr_cpu_core_properties[] = {DEFINE_PROP_INT32 ("node-id" , sPAPRCPUCore, node_id,CPU_UNSET_NUMA_NODE_ID ),DEFINE_PROP_END_OF_LIST ()
include/hw/ppc/spapr_cpu_core.h +2 -0
@@ -38,4 +38,6 @@ typedef struct sPAPRCPUCoreClass { } sPAPRCPUCoreClass;const char *spapr_get_cpu_core_type (const char *cpu_type); +void spapr_cpu_core_reset (sPAPRCPUCore *sc); +#endif
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 01/10] spapr: Avoid redundant calls to spapr_cpu_reset()
Quoted 106 lines · Greg Kurz
Quoted 76 lines · On Fri, 20 Apr 2018 11:15:01 +0200 Greg Kurz <[email protected]> wrote:
Quoted 45 lines · On Fri, 20 Apr 2018 16:34:37 +1000 David Gibson <[email protected]>…
Quoted 21 lines · Greg Kurz
Quoted 12 lines · On Tue, 17 Apr 2018 17:17:13 +1000 David Gibson <[email protected]>…
af81cf323c1"spapr: CPU hotplug support" added a direct call tospapr_cpu_reset()inspapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.However, this change means that
spapr_cpu_reset()gets called twice for normal cold-plugged cpus: once fromspapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.Quoted 5 lines
So, we remove the reset call from
spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.Signed-off-by David Gibson <[email protected]>---
Quoted 7 lines
I had sent a tentative patch to do something similar earlier this year:
https://patchwork.ozlabs.org/patch/862116/
but it got nacked for several reasons, one of them being you were "always wary of using the hotplugged parameter, because what qemu means by it often doesn't line up with what PAPR means by it."
Yeah, I was and am wary of that, but convinced myself it was correct in this case (which doesn't really interact with the PAPR meaning of hotplug).
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Quoted 9 lines
Quoted 4 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3371
Quoted 1 line
hw/ppc/spapr.c +0
-0if (hotplugged) {... but you rely on it here. Can you explain why it is okay now ?
So the value I actually need here is "wasn't present at the last system reset" (with false positives being mostly harmless, but not false negatives).
Hmm... It is rather the other way around, sth like "will be caught by the initial machine reset".
Quoted 9 lines
Quoted 9 lines
Also, if QEMU is started with -incoming and the CPU core is hotplugged before migration begins, the following will return false:
static inline bool
spapr_drc_hotplugged(DeviceState *dev){ return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); }Quoted 5 lines
Quoted 1 line
and the CPU core won't be reset.
Uh...
spapr_dtc_hotplugged()would definitely be wrong here, which is why I'm not using it.Quoted 23 lines
This is how hotplugged is set in
spapr_core_plug():bool hotplugged = spapr_drc_hotplugged(dev);but to detect the "will be caught by the initial machine reset" condition, we only need to check
dev->hotpluggedactually.Quoted 16 lines
Quoted 10 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3377
Quoted 9 lines
hw/ppc/spapr.c +4
-2/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);Quoted 3 lines
spapr_cpu_reset()also sets the compat mode, which is used to set some properties in the DT, ie, this should be called beforespapr_populate_hotplug_cpu_dt().Good point. I've moved the reset to fix that.
Thinking of it again: since cold-plugged devices reach this before machine reset, we would then attach to the DRC a DT blob based on a non-reset CPU :-\
Quoted 7 lines
Instead of registering a reset handler for each individual CPUs, maybe we should rather register it a the CPU core level. The handler would first reset all CPUs in the core and then setup the DRC for new cores only, like it is done currently in
spapr_core_plug().
spapr_core_plug()would then just need to register the reset handler, and call it only for hotplugged cores.
Handling the resets via the core level might be a good idea anyway, but I don't think it can address the problem we're hitting here.
I've investigated further and I'm pretty sure we can't fix this without generic code changes. cpu_common_realizefn() (which is called by our ppc cpu realize hook via the parent_realize chain) contains this:
if (dev->hotplugged) {
cpu_synchronize_post_init(cpu);
cpu_resume(cpu);
}So, as soon as the hotplugged cpu is realized, it's running, which means by the time we call the plug() hotplug handler we're too late to do any reset initialization.
I think there are two ways to look at this:
1) The reset handlers are specifically about *system* reset, not device reset, and so we shoudln't really expect them to be called for hotplugged devices. If we want to share reset initialization with "initial" initialization, we should explicitly call the reset handler from the (realize time) init code.. which is what we do now.
2) Common core realize should _not_ activate the cpu. Instead that should be the plug() handler's job. This would require changing the x86 cpu plug handler (and whatever else) to kick off the cpu after realization.
For now I'm inclined to just let it stay at (1).
The problem I had which I thought required this, doesn't after all. I came up with a different solution that involves moving the spapr caps initialization earlier, instead of the cpu reset later. That turned out to be substantially easier than I first thought, and regardless of what we do above long term, I think it's a better way to handle the caps.
Signature · 4 lines
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
Greg Kurz
Reviewed-by Eduardo HabkostRe: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 01/10] spapr: Avoid redundant calls to spapr_cpu_reset()
Quoted 123 lines · On Mon, 18 Jun 2018 13:42:37 +1000 David Gibson <[email protected]>…
Quoted 106 lines · Greg Kurz
Quoted 76 lines · On Fri, 20 Apr 2018 11:15:01 +0200 Greg Kurz <[email protected]> wrote:
Quoted 45 lines · On Fri, 20 Apr 2018 16:34:37 +1000 David Gibson <[email protected]>…
Quoted 21 lines · Greg Kurz
Quoted 12 lines · On Tue, 17 Apr 2018 17:17:13 +1000 David Gibson <[email protected]>…
af81cf323c1"spapr: CPU hotplug support" added a direct call tospapr_cpu_reset()inspapr_cpu_init(), as well as registering it as a reset callback. That was in order to make sure that the reset function got called for a newly hotplugged cpu, which would miss the global machine reset.However, this change means that
spapr_cpu_reset()gets called twice for normal cold-plugged cpus: once fromspapr_cpu_init(), then again during the system reset. As well as being ugly in its redundancy, the first call happens before the machine reset calls have happened, which will cause problems for some things we're going to want to add.Quoted 5 lines
So, we remove the reset call from
spapr_cpu_init(). We instead put an explicit reset call in the hotplug specific path.Signed-off-by David Gibson <[email protected]>---
Quoted 7 lines
I had sent a tentative patch to do something similar earlier this year:
https://patchwork.ozlabs.org/patch/862116/
but it got nacked for several reasons, one of them being you were "always wary of using the hotplugged parameter, because what qemu means by it often doesn't line up with what PAPR means by it."
Yeah, I was and am wary of that, but convinced myself it was correct in this case (which doesn't really interact with the PAPR meaning of hotplug).
Quoted 11 lines
Quoted 11 lines
hw/ppc/spapr.c | 6 ++++-- hw/ppc/spapr_cpu_core.c | 13 ++++++++++++- include/hw/ppc/spapr_cpu_core.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-)hw/ppc/spapr.c +0
-0@@ -3370,9 +3370,11 @@ static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev,Quoted 9 lines
Quoted 4 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3371
Quoted 1 line
hw/ppc/spapr.c +0
-0if (hotplugged) {... but you rely on it here. Can you explain why it is okay now ?
So the value I actually need here is "wasn't present at the last system reset" (with false positives being mostly harmless, but not false negatives).
Hmm... It is rather the other way around, sth like "will be caught by the initial machine reset".
Quoted 9 lines
Quoted 9 lines
Also, if QEMU is started with -incoming and the CPU core is hotplugged before migration begins, the following will return false:
static inline bool
spapr_drc_hotplugged(DeviceState *dev){ return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); }Quoted 5 lines
Quoted 1 line
and the CPU core won't be reset.
Uh...
spapr_dtc_hotplugged()would definitely be wrong here, which is why I'm not using it.Quoted 23 lines
This is how hotplugged is set in
spapr_core_plug():bool hotplugged = spapr_drc_hotplugged(dev);but to detect the "will be caught by the initial machine reset" condition, we only need to check
dev->hotpluggedactually.Quoted 16 lines
Quoted 10 lines
hw/ppc/spapr.c static void spapr_core_plug(HotplugHandler *hotplug_dev, DeviceState *dev, · line 3377
Quoted 9 lines
hw/ppc/spapr.c +4
-2/* -* Send hotplug notification interrupt to the guest only -* in case of hotplugged CPUs. +* For hotplugged CPUs, we need to reset them (they missed +* out on the system reset), and send the guest a +* notification */ +spapr_cpu_core_reset (core);Quoted 3 lines
spapr_cpu_reset()also sets the compat mode, which is used to set some properties in the DT, ie, this should be called beforespapr_populate_hotplug_cpu_dt().Good point. I've moved the reset to fix that.
Thinking of it again: since cold-plugged devices reach this before machine reset, we would then attach to the DRC a DT blob based on a non-reset CPU :-\
Quoted 7 lines
Instead of registering a reset handler for each individual CPUs, maybe we should rather register it a the CPU core level. The handler would first reset all CPUs in the core and then setup the DRC for new cores only, like it is done currently in
spapr_core_plug().
spapr_core_plug()would then just need to register the reset handler, and call it only for hotplugged cores.Handling the resets via the core level might be a good idea anyway, but I don't think it can address the problem we're hitting here.
I've investigated further and I'm pretty sure we can't fix this without generic code changes.
cpu_common_realizefn()(which is called by our ppc cpu realize hook via theparent_realizechain) contains this:
Quoted 5 lines
if (dev->hotplugged) {
cpu_synchronize_post_init(cpu);
cpu_resume(cpu);
}Yes, these come from:
commit 13eed94ed5617b98e657163490584dc2a0cc4b32
Author: Igor Mammedov <[email protected]> Date: Tue Apr 23 10:29:36 2013 +0200
cpu: Call cpu_synchronize_post_init() from DeviceClass::realize()
If hotplugged, synchronize CPU state to KVM.
and
commit 6afb4721f3e45da727110470a61aafcd6682395e
Author: Igor Mammedov <[email protected]> Date: Tue Apr 23 10:29:38 2013 +0200
cpu: Resume CPU from DeviceClass::realize() if hot-plugged
Quoted 12 lines
So, as soon as the hotplugged cpu is realized, it's running, which means by the time we call the
plug()hotplug handler we're too late to do any reset initialization.I think there are two ways to look at this:
1) The reset handlers are specifically about *system* reset, not device reset, and so we shoudln't really expect them to be called for hotplugged devices. If we want to share reset initialization with "initial" initialization, we should explicitly call the reset handler from the (realize time) init code.. which is what we do now.
Quoted 7 lines
2) Common core realize should _not_ activate the cpu. Instead that should be the
plug()handler's job. This would require changing the x86 cpu plug handler (and whatever else) to kick off the cpu after realization.For now I'm inclined to just let it stay at (1).
Maybe Igor and Eduardo (now Cc'd) can provide a hint about 2) ?
Quoted 7 lines
The problem I had which I thought required this, doesn't after all. I came up with a different solution that involves moving the spapr caps initialization earlier, instead of the cpu reset later. That turned out to be substantially easier than I first thought, and regardless of what we do above long term, I think it's a better way to handle the caps.
PATCH 2/10 spapr: Remove support for PowerPC 970 with pseries machine type
In reply to David GibsonCurrent POWER cpus allow for a VRMA, a special mapping which describes a guest's view of memory when in real mode (MMU off, from the guest's point of view). Older cpus didn't have that which meant that to support a guest a special host-contiguous region of memory was needed to give the guest its Real Mode Area (RMA).
This was useful in the early days of KVM on Power to allow it to be tested on PowerPC 970 chips as used in Macintosh G5 machines. Now, however, those machines are so old as to be irrelevant, and the host kernel has long since dropped support for this mode. It hasn't been tested in ages either.
So, to simplify the code, drop the support from qemu as well.
As well as the code for handling contiguous RMAs, we can remove some code to set the HIOR register, which existed on 970 but not on the current and supported CPUs.
--- hw/ppc/spapr.c | 61 +++++++++++++++---------------------------------- hw/ppc/spapr_cpu_core.c | 2 -- target/ppc/kvm.c | 36 ----------------------------- target/ppc/kvm_ppc.h | 6 ----- 4 files changed, 19 insertions(+), 86 deletions(-)
hw/ppc/spapr.c +19 -42
@@ -2376,9 +2376,6 @@ static void spapr_machine_init(MachineState *machine)int i;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 ); -MemoryRegion *rma_region; -void *rma =NULL ; -hwaddr rma_alloc_size;hwaddr node0_size =spapr_node0_size (machine);long load_limit, fw_size;char *filename;
@@ -2417,40 +2414,28 @@ static void spapr_machine_init(MachineState *machine)exit (1 ); } -/* Allocate RMA if necessary */ - rma_alloc_size =kvmppc_alloc_rma (&rma); + spapr->rma_size = node0_size; -if (rma_alloc_size ==-1 ) { -error_report ("Unable to create RMA" ); -exit (1 ); +/* With KVM, we don't actually know whether KVM supports an +* unbounded RMA (PR KVM) or is limited by the hash table size (HV +* KVM using VRMA), so we always assume the latter +* +* In that case, we also limit the initial allocations for RTAS +* etc... to 256M since we have no way to know what the VRMA size +* is going to be as it depends on the size of the hash table +* isn't determined yet. +*/ +if (kvm_enabled ()) { + spapr->vrma_adjust =1 ; + spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); } -if (rma_alloc_size && (rma_alloc_size < node0_size)) { - spapr->rma_size = rma_alloc_size; - }else { - spapr->rma_size = node0_size; - -/* With KVM, we don't actually know whether KVM supports an -* unbounded RMA (PR KVM) or is limited by the hash table size -* (HV KVM using VRMA), so we always assume the latter -* -* In that case, we also limit the initial allocations for RTAS -* etc... to 256M since we have no way to know what the VRMA size -* is going to be as it depends on the size of the hash table -* isn't determined yet. -*/ -if (kvm_enabled ()) { - spapr->vrma_adjust =1 ; - spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); - } - -/* Actually we don't support unbounded RMA anymore since we -* added proper emulation of HV mode. The max we can get is -* 16G which also happens to be what we configure for PAPR -* mode so make sure we don't do anything bigger than that -*/ - spapr->rma_size =MIN (spapr->rma_size,0x400000000ull ); - } +/* Actually we don't support unbounded RMA anymore since we +* added proper emulation of HV mode. The max we can get is +* 16G which also happens to be what we configure for PAPR +* mode so make sure we don't do anything bigger than that +*/ + spapr->rma_size =MIN (spapr->rma_size,0x400000000ull );if (spapr->rma_size > node0_size) { error_report("Numa node 0 has to span the RMA (%#08"HWADDR_PRIx")",
@@ -2508,14 +2493,6 @@ static void spapr_machine_init(MachineState *machine) machine->ram_size);memory_region_add_subregion (sysmem,0 , ram); -if (rma_alloc_size && rma) { - rma_region =g_new (MemoryRegion,1 ); -memory_region_init_ram_ptr (rma_region,NULL ,"ppc_spapr.rma" , - rma_alloc_size, rma); -vmstate_register_ram_global (rma_region); -memory_region_add_subregion (sysmem,0 , rma_region); - } -/* initialize hotplug memory address space */ if (machine->ram_size < machine->maxram_size) {ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size;
hw/ppc/spapr_cpu_core.c +0 -2
@@ -36,8 +36,6 @@ static void spapr_cpu_reset(void *opaque)* using an RTAS call */ cs->halted =1 ; - env->spr[SPR_HIOR ] =0 ; -/* Disable Power-saving mode Exit Cause exceptions for the CPU. * This can cause issues when rebooting the guest if a secondary * is awaken */
target/ppc/kvm.c +0 -36
@@ -2159,42 +2159,6 @@ void kvmppc_hint_smt_possible(Error **errp)#ifdef TARGET_PPC64 -off_t kvmppc_alloc_rma (void **rma) -{ -off_t size; -int fd; -struct kvm_allocate_rma ret; - -/* If cap_ppc_rma == 0, contiguous RMA allocation is not supported -* if cap_ppc_rma == 1, contiguous RMA allocation is supported, but -* not necessary on this hardware -* if cap_ppc_rma == 2, contiguous RMA allocation is needed on this hardware -* -* FIXME: We should allow the user to force contiguous RMA -* allocation in the cap_ppc_rma==1 case. -*/ -if (cap_ppc_rma <2 ) { -return 0 ; - } - - fd =kvm_vm_ioctl (kvm_state,KVM_ALLOCATE_RMA , &ret); -if (fd <0 ) { -fprintf (stderr,"KVM: Error on KVM_ALLOCATE_RMA: %s\n" , -strerror (errno)); -return -1 ; - } - - size =MIN (ret.rma_size,256ul <<20 ); - - *rma =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); -if (*rma ==MAP_FAILED ) { -fprintf (stderr,"KVM: Error mapping RMA: %s\n" ,strerror (errno)); -return -1 ; - }; - -return size; -} -uint64_t kvmppc_rma_size (uint64_t current_size,unsigned int hash_shift) {struct kvm_ppc_smmu_info info;
target/ppc/kvm_ppc.h +0 -6
@@ -37,7 +37,6 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool radix, bool gtse, uint64_t proc_tbl);#ifndef CONFIG_USER_ONLY -off_t kvmppc_alloc_rma (void **rma);bool kvmppc_spapr_use_multitce (void );int kvmppc_spapr_enable_inkernel_multitce (void ); void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,
@@ -188,11 +187,6 @@ static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, }#ifndef CONFIG_USER_ONLY -static inline off_t kvmppc_alloc_rma (void **rma) -{ -return 0 ; -} -static inline bool kvmppc_spapr_use_multitce (void ) {return false;
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
Quoted 6 lines · On Tue, 17 Apr 2018 17:17:14 +1000 David Gibson <[email protected]>…
Current POWER cpus allow for a VRMA, a special mapping which describes a guest's view of memory when in real mode (MMU off, from the guest's point of view). Older cpus didn't have that which meant that to support a guest a special host-contiguous region of memory was needed to give the guest its Real Mode Area (RMA).
Quoted 7 lines
This was useful in the early days of KVM on Power to allow it to be tested on PowerPC 970 chips as used in Macintosh G5 machines. Now, however, those machines are so old as to be irrelevant, and the host kernel has long since dropped support for this mode. It hasn't been tested in ages either.
So, to simplify the code, drop the support from qemu as well.
So this could possibly break TCG guests with 970, which happens to be bootable with the current code ?
$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.9 (Santiago) $ cat /proc/cpuinfo processor : 0 cpu : PPC970, altivec supported clock : 1000.000000MHz revision : 2.2 (pvr 0039 0202)
timebase : 512000000
platform : pSeries
model : IBM pSeries (emulated by qemu)
machine : CHRP IBM pSeries (emulated by qemu)
I guess nobody uses this setup, but my understanding is that some rules must be followed when it comes to removing something that works.
https://wiki.qemu.org/Features/LegacyRemoval#Rules_for_removing_an_interface
Maybe add a warning if 970 is used, and turn it into an error in two releases along with this patch ?
Quoted 185 lines
As well as the code for handling contiguous RMAs, we can remove some code to set the HIOR register, which existed on 970 but not on the current and supported CPUs.
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr.c | 61 +++++++++++++++---------------------------------- hw/ppc/spapr_cpu_core.c | 2 -- target/ppc/kvm.c | 36 ----------------------------- target/ppc/kvm_ppc.h | 6 ----- 4 files changed, 19 insertions(+), 86 deletions(-)hw/ppc/spapr.c +19
-42@@ -2376,9 +2376,6 @@ static void spapr_machine_init(MachineState *machine)int i;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 ); -MemoryRegion *rma_region; -void *rma =NULL ; -hwaddr rma_alloc_size;hwaddr node0_size =spapr_node0_size (machine);long load_limit, fw_size;char *filename;@@ -2417,40 +2414,28 @@ static void spapr_machine_init(MachineState *machine)exit (1 ); } -/* Allocate RMA if necessary */ - rma_alloc_size =kvmppc_alloc_rma (&rma); + spapr->rma_size = node0_size; -if (rma_alloc_size ==-1 ) { -error_report ("Unable to create RMA" ); -exit (1 ); +/* With KVM, we don't actually know whether KVM supports an +* unbounded RMA (PR KVM) or is limited by the hash table size (HV +* KVM using VRMA), so we always assume the latter +* +* In that case, we also limit the initial allocations for RTAS +* etc... to 256M since we have no way to know what the VRMA size +* is going to be as it depends on the size of the hash table +* isn't determined yet. +*/ +if (kvm_enabled ()) { + spapr->vrma_adjust =1 ; + spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); } -if (rma_alloc_size && (rma_alloc_size < node0_size)) { - spapr->rma_size = rma_alloc_size; - }else { - spapr->rma_size = node0_size; - -/* With KVM, we don't actually know whether KVM supports an -* unbounded RMA (PR KVM) or is limited by the hash table size -* (HV KVM using VRMA), so we always assume the latter -* -* In that case, we also limit the initial allocations for RTAS -* etc... to 256M since we have no way to know what the VRMA size -* is going to be as it depends on the size of the hash table -* isn't determined yet. -*/ -if (kvm_enabled ()) { - spapr->vrma_adjust =1 ; - spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); - } - -/* Actually we don't support unbounded RMA anymore since we -* added proper emulation of HV mode. The max we can get is -* 16G which also happens to be what we configure for PAPR -* mode so make sure we don't do anything bigger than that -*/ - spapr->rma_size =MIN (spapr->rma_size,0x400000000ull ); - } +/* Actually we don't support unbounded RMA anymore since we +* added proper emulation of HV mode. The max we can get is +* 16G which also happens to be what we configure for PAPR +* mode so make sure we don't do anything bigger than that +*/ + spapr->rma_size =MIN (spapr->rma_size,0x400000000ull );if (spapr->rma_size > node0_size) { error_report("Numa node 0 has to span the RMA (%#08"HWADDR_PRIx")",@@ -2508,14 +2493,6 @@ static void spapr_machine_init(MachineState *machine) machine->ram_size);memory_region_add_subregion (sysmem,0 , ram); -if (rma_alloc_size && rma) { - rma_region =g_new (MemoryRegion,1 ); -memory_region_init_ram_ptr (rma_region,NULL ,"ppc_spapr.rma" , - rma_alloc_size, rma); -vmstate_register_ram_global (rma_region); -memory_region_add_subregion (sysmem,0 , rma_region); - } -/* initialize hotplug memory address space */ if (machine->ram_size < machine->maxram_size) {ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size;hw/ppc/spapr_cpu_core.c +0
-2@@ -36,8 +36,6 @@ static void spapr_cpu_reset(void *opaque)* using an RTAS call */ cs->halted =1 ; - env->spr[SPR_HIOR ] =0 ; -/* Disable Power-saving mode Exit Cause exceptions for the CPU. * This can cause issues when rebooting the guest if a secondary * is awaken */ target/ppc/kvm.c +0
-36@@ -2159,42 +2159,6 @@ void kvmppc_hint_smt_possible(Error **errp)#ifdef TARGET_PPC64 -off_t kvmppc_alloc_rma (void **rma) -{ -off_t size; -int fd; -struct kvm_allocate_rma ret; - -/* If cap_ppc_rma == 0, contiguous RMA allocation is not supported -* if cap_ppc_rma == 1, contiguous RMA allocation is supported, but -* not necessary on this hardware -* if cap_ppc_rma == 2, contiguous RMA allocation is needed on this hardware -* -* FIXME: We should allow the user to force contiguous RMA -* allocation in the cap_ppc_rma==1 case. -*/ -if (cap_ppc_rma <2 ) { -return 0 ; - } - - fd =kvm_vm_ioctl (kvm_state,KVM_ALLOCATE_RMA , &ret); -if (fd <0 ) { -fprintf (stderr,"KVM: Error on KVM_ALLOCATE_RMA: %s\n" , -strerror (errno)); -return -1 ; - } - - size =MIN (ret.rma_size,256ul <<20 ); - - *rma =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); -if (*rma ==MAP_FAILED ) { -fprintf (stderr,"KVM: Error mapping RMA: %s\n" ,strerror (errno)); -return -1 ; - }; - -return size; -} -uint64_t kvmppc_rma_size (uint64_t current_size,unsigned int hash_shift) {struct kvm_ppc_smmu_info info;target/ppc/kvm_ppc.h +0
-6@@ -37,7 +37,6 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool radix, bool gtse, uint64_t proc_tbl);#ifndef CONFIG_USER_ONLY -off_t kvmppc_alloc_rma (void **rma);bool kvmppc_spapr_use_multitce (void );int kvmppc_spapr_enable_inkernel_multitce (void ); void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,@@ -188,11 +187,6 @@ static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, }#ifndef CONFIG_USER_ONLY -static inline off_t kvmppc_alloc_rma (void **rma) -{ -return 0 ; -} -static inline bool kvmppc_spapr_use_multitce (void ) {return false;
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
Quoted 33 lines · Greg Kurz
Quoted 6 lines · On Tue, 17 Apr 2018 17:17:14 +1000 David Gibson <[email protected]>…
Current POWER cpus allow for a VRMA, a special mapping which describes a guest's view of memory when in real mode (MMU off, from the guest's point of view). Older cpus didn't have that which meant that to support a guest a special host-contiguous region of memory was needed to give the guest its Real Mode Area (RMA).
Quoted 7 lines
This was useful in the early days of KVM on Power to allow it to be tested on PowerPC 970 chips as used in Macintosh G5 machines. Now, however, those machines are so old as to be irrelevant, and the host kernel has long since dropped support for this mode. It hasn't been tested in ages either.
So, to simplify the code, drop the support from qemu as well.
So this could possibly break TCG guests with 970, which happens to be bootable with the current code ?
$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.9 (Santiago) $ cat /proc/cpuinfo processor : 0 cpu : PPC970, altivec supported clock : 1000.000000MHz revision : 2.2 (pvr 0039 0202)timebase : 512000000
platform : pSeries
model : IBM pSeries (emulated by qemu)
machine : CHRP IBM pSeries (emulated by qemu)
Quoted 8 lines
I guess nobody uses this setup, but my understanding is that some rules must be followed when it comes to removing something that works.
https://wiki.qemu.org/Features/LegacyRemoval#Rules_for_removing_an_interface
Maybe add a warning if 970 is used, and turn it into an error in two releases along with this patch ?
Right, we've got a process for deprecating old features, so please follow that process.
Thomas
Re: [Qemu-devel] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
In reply to Greg KurzQuoted 14 lines · Greg Kurz
Quoted 11 lines · On Tue, 17 Apr 2018 17:17:14 +1000 David Gibson <[email protected]>…
Current POWER cpus allow for a VRMA, a special mapping which describes a guest's view of memory when in real mode (MMU off, from the guest's point of view). Older cpus didn't have that which meant that to support a guest a special host-contiguous region of memory was needed to give the guest its Real Mode Area (RMA).
This was useful in the early days of KVM on Power to allow it to be tested on PowerPC 970 chips as used in Macintosh G5 machines. Now, however, those machines are so old as to be irrelevant, and the host kernel has long since dropped support for this mode. It hasn't been tested in ages either.
Quoted 5 lines
Quoted 2 lines
So, to simplify the code, drop the support from qemu as well.
So this could possibly break TCG guests with 970, which happens to be bootable with the current code ?
Hm.. so that's actually a good question. In theory the HIOR change could break TCG.. except that AFAICT we don't do anything with the HIOR register except pass it to KVM.
The allocated RMA changes are only relevant with 970 *and* KVM HV. And allocate RMA mode was always kind of broken because there was no real way to ensure a consistent guest environment between HV and TCG.
The KVM side support for this has been gone for some time.
Quoted 13 lines
$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.9 (Santiago) $ cat /proc/cpuinfo processor : 0 cpu : PPC970, altivec supported clock : 1000.000000MHz revision : 2.2 (pvr 0039 0202)timebase : 512000000
platform : pSeries
model : IBM pSeries (emulated by qemu)
machine : CHRP IBM pSeries (emulated by qemu)
Quoted 5 lines
I guess nobody uses this setup, but my understanding is that some rules must be followed when it comes to removing something that works.
https://wiki.qemu.org/Features/LegacyRemoval#Rules_for_removing_an_interface
Well, that's for "interfaces" and I'm not really sure if this qualifies.
Quoted 2 lines
Maybe add a warning if 970 is used, and turn it into an error in two releases along with this patch ?
I really don't want to wait on that for the rma allocation stuff. It's a hideous wart that makes it really, really hard to make other changes to the init path (because testing if we broke it means finding a real 970 host).
Quoted 187 lines
Quoted 186 lines
As well as the code for handling contiguous RMAs, we can remove some code to set the HIOR register, which existed on 970 but not on the current and supported CPUs.
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr.c | 61 +++++++++++++++---------------------------------- hw/ppc/spapr_cpu_core.c | 2 -- target/ppc/kvm.c | 36 ----------------------------- target/ppc/kvm_ppc.h | 6 ----- 4 files changed, 19 insertions(+), 86 deletions(-)hw/ppc/spapr.c +19
-42@@ -2376,9 +2376,6 @@ static void spapr_machine_init(MachineState *machine)int i;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 ); -MemoryRegion *rma_region; -void *rma =NULL ; -hwaddr rma_alloc_size;hwaddr node0_size =spapr_node0_size (machine);long load_limit, fw_size;char *filename;@@ -2417,40 +2414,28 @@ static void spapr_machine_init(MachineState *machine)exit (1 ); } -/* Allocate RMA if necessary */ - rma_alloc_size =kvmppc_alloc_rma (&rma); + spapr->rma_size = node0_size; -if (rma_alloc_size ==-1 ) { -error_report ("Unable to create RMA" ); -exit (1 ); +/* With KVM, we don't actually know whether KVM supports an +* unbounded RMA (PR KVM) or is limited by the hash table size (HV +* KVM using VRMA), so we always assume the latter +* +* In that case, we also limit the initial allocations for RTAS +* etc... to 256M since we have no way to know what the VRMA size +* is going to be as it depends on the size of the hash table +* isn't determined yet. +*/ +if (kvm_enabled ()) { + spapr->vrma_adjust =1 ; + spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); } -if (rma_alloc_size && (rma_alloc_size < node0_size)) { - spapr->rma_size = rma_alloc_size; - }else { - spapr->rma_size = node0_size; - -/* With KVM, we don't actually know whether KVM supports an -* unbounded RMA (PR KVM) or is limited by the hash table size -* (HV KVM using VRMA), so we always assume the latter -* -* In that case, we also limit the initial allocations for RTAS -* etc... to 256M since we have no way to know what the VRMA size -* is going to be as it depends on the size of the hash table -* isn't determined yet. -*/ -if (kvm_enabled ()) { - spapr->vrma_adjust =1 ; - spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); - } - -/* Actually we don't support unbounded RMA anymore since we -* added proper emulation of HV mode. The max we can get is -* 16G which also happens to be what we configure for PAPR -* mode so make sure we don't do anything bigger than that -*/ - spapr->rma_size =MIN (spapr->rma_size,0x400000000ull ); - } +/* Actually we don't support unbounded RMA anymore since we +* added proper emulation of HV mode. The max we can get is +* 16G which also happens to be what we configure for PAPR +* mode so make sure we don't do anything bigger than that +*/ + spapr->rma_size =MIN (spapr->rma_size,0x400000000ull );if (spapr->rma_size > node0_size) { error_report("Numa node 0 has to span the RMA (%#08"HWADDR_PRIx")",@@ -2508,14 +2493,6 @@ static void spapr_machine_init(MachineState *machine) machine->ram_size);memory_region_add_subregion (sysmem,0 , ram); -if (rma_alloc_size && rma) { - rma_region =g_new (MemoryRegion,1 ); -memory_region_init_ram_ptr (rma_region,NULL ,"ppc_spapr.rma" , - rma_alloc_size, rma); -vmstate_register_ram_global (rma_region); -memory_region_add_subregion (sysmem,0 , rma_region); - } -/* initialize hotplug memory address space */ if (machine->ram_size < machine->maxram_size) {ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size;hw/ppc/spapr_cpu_core.c +0
-2@@ -36,8 +36,6 @@ static void spapr_cpu_reset(void *opaque)* using an RTAS call */ cs->halted =1 ; - env->spr[SPR_HIOR ] =0 ; -/* Disable Power-saving mode Exit Cause exceptions for the CPU. * This can cause issues when rebooting the guest if a secondary * is awaken */ target/ppc/kvm.c +0
-36@@ -2159,42 +2159,6 @@ void kvmppc_hint_smt_possible(Error **errp)#ifdef TARGET_PPC64 -off_t kvmppc_alloc_rma (void **rma) -{ -off_t size; -int fd; -struct kvm_allocate_rma ret; - -/* If cap_ppc_rma == 0, contiguous RMA allocation is not supported -* if cap_ppc_rma == 1, contiguous RMA allocation is supported, but -* not necessary on this hardware -* if cap_ppc_rma == 2, contiguous RMA allocation is needed on this hardware -* -* FIXME: We should allow the user to force contiguous RMA -* allocation in the cap_ppc_rma==1 case. -*/ -if (cap_ppc_rma <2 ) { -return 0 ; - } - - fd =kvm_vm_ioctl (kvm_state,KVM_ALLOCATE_RMA , &ret); -if (fd <0 ) { -fprintf (stderr,"KVM: Error on KVM_ALLOCATE_RMA: %s\n" , -strerror (errno)); -return -1 ; - } - - size =MIN (ret.rma_size,256ul <<20 ); - - *rma =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); -if (*rma ==MAP_FAILED ) { -fprintf (stderr,"KVM: Error mapping RMA: %s\n" ,strerror (errno)); -return -1 ; - }; - -return size; -} -uint64_t kvmppc_rma_size (uint64_t current_size,unsigned int hash_shift) {struct kvm_ppc_smmu_info info;target/ppc/kvm_ppc.h +0
-6@@ -37,7 +37,6 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool radix, bool gtse, uint64_t proc_tbl);#ifndef CONFIG_USER_ONLY -off_t kvmppc_alloc_rma (void **rma);bool kvmppc_spapr_use_multitce (void );int kvmppc_spapr_enable_inkernel_multitce (void ); void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,@@ -188,11 +187,6 @@ static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, }#ifndef CONFIG_USER_ONLY -static inline off_t kvmppc_alloc_rma (void **rma) -{ -return 0 ; -} -static inline bool kvmppc_spapr_use_multitce (void ) {return false;
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
(because testing if we broke it means finding
a real 970 host).
Hi, i have a real 970 host if you need an hand to test just ask
Luigi
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
Quoted 4 lines · luigi burdo
(because testing if we broke it means finding
a real 970 host).Hi, i have a real 970 host if you need an hand to test just ask
Thanks, and I'll keep it in mind, but borrowing a system from some random person isn't really a manageable approach for the long term.
Signature · 4 lines
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
Re: [Qemu-devel] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
In reply to David GibsonQuoted 11 lines · On Tue, 17 Apr 2018 17:17:14 +1000 David Gibson <[email protected]>…
Current POWER cpus allow for a VRMA, a special mapping which describes a guest's view of memory when in real mode (MMU off, from the guest's point of view). Older cpus didn't have that which meant that to support a guest a special host-contiguous region of memory was needed to give the guest its Real Mode Area (RMA).
This was useful in the early days of KVM on Power to allow it to be tested on PowerPC 970 chips as used in Macintosh G5 machines. Now, however, those machines are so old as to be irrelevant, and the host kernel has long since dropped support for this mode. It hasn't been tested in ages either.
Quoted 8 lines
So, to simplify the code, drop the support from qemu as well.
As well as the code for handling contiguous RMAs, we can remove some code to set the HIOR register, which existed on 970 but not on the current and supported CPUs.
Signed-off-by David Gibson <[email protected]>---
Regardless of the discussion on the deprecation process, just a cosmetic remark...
Quoted 29 lines
hw/ppc/spapr.c | 61 +++++++++++++++---------------------------------- hw/ppc/spapr_cpu_core.c | 2 -- target/ppc/kvm.c | 36 ----------------------------- target/ppc/kvm_ppc.h | 6 ----- 4 files changed, 19 insertions(+), 86 deletions(-)hw/ppc/spapr.c +1
-6@@ -2376,9 +2376,6 @@ static void spapr_machine_init(MachineState *machine)int i;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 ); -MemoryRegion *rma_region; -void *rma =NULL ; -hwaddr rma_alloc_size;hwaddr node0_size =spapr_node0_size (machine);long load_limit, fw_size;char *filename;@@ -2417,40 +2414,28 @@ static void spapr_machine_init(MachineState *machine)exit (1 ); } -/* Allocate RMA if necessary */ - rma_alloc_size =kvmppc_alloc_rma (&rma); + spapr->rma_size = node0_size; -if (rma_alloc_size ==-1 ) {
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2426
Quoted 10 lines
hw/ppc/spapr.c +8
-2-error_report ("Unable to create RMA" ); -exit (1 ); +/* With KVM, we don't actually know whether KVM supports an +* unbounded RMA (PR KVM) or is limited by the hash table size (HV +* KVM using VRMA), so we always assume the latter +* +* In that case, we also limit the initial allocations for RTAS +* etc... to 256M since we have no way to know what the VRMA size +* is going to be as it depends on the size of the hash table +* isn't determined yet.
... maybe s/isn't/which isn't/ while at it ?
Quoted 140 lines
hw/ppc/spapr.c +10
-34+*/ +if (kvm_enabled ()) { + spapr->vrma_adjust =1 ; + spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); } -if (rma_alloc_size && (rma_alloc_size < node0_size)) { - spapr->rma_size = rma_alloc_size; - }else { - spapr->rma_size = node0_size; - -/* With KVM, we don't actually know whether KVM supports an -* unbounded RMA (PR KVM) or is limited by the hash table size -* (HV KVM using VRMA), so we always assume the latter -* -* In that case, we also limit the initial allocations for RTAS -* etc... to 256M since we have no way to know what the VRMA size -* is going to be as it depends on the size of the hash table -* isn't determined yet. -*/ -if (kvm_enabled ()) { - spapr->vrma_adjust =1 ; - spapr->rma_size =MIN (spapr->rma_size,0x10000000 ); - } - -/* Actually we don't support unbounded RMA anymore since we -* added proper emulation of HV mode. The max we can get is -* 16G which also happens to be what we configure for PAPR -* mode so make sure we don't do anything bigger than that -*/ - spapr->rma_size =MIN (spapr->rma_size,0x400000000ull ); - } +/* Actually we don't support unbounded RMA anymore since we +* added proper emulation of HV mode. The max we can get is +* 16G which also happens to be what we configure for PAPR +* mode so make sure we don't do anything bigger than that +*/ + spapr->rma_size =MIN (spapr->rma_size,0x400000000ull );if (spapr->rma_size > node0_size) { error_report("Numa node 0 has to span the RMA (%#08"HWADDR_PRIx")",@@ -2508,14 +2493,6 @@ static void spapr_machine_init(MachineState *machine) machine->ram_size);memory_region_add_subregion (sysmem,0 , ram); -if (rma_alloc_size && rma) { - rma_region =g_new (MemoryRegion,1 ); -memory_region_init_ram_ptr (rma_region,NULL ,"ppc_spapr.rma" , - rma_alloc_size, rma); -vmstate_register_ram_global (rma_region); -memory_region_add_subregion (sysmem,0 , rma_region); - } -/* initialize hotplug memory address space */ if (machine->ram_size < machine->maxram_size) {ram_addr_t hotplug_mem_size = machine->maxram_size - machine->ram_size;hw/ppc/spapr_cpu_core.c +0
-2@@ -36,8 +36,6 @@ static void spapr_cpu_reset(void *opaque)* using an RTAS call */ cs->halted =1 ; - env->spr[SPR_HIOR ] =0 ; -/* Disable Power-saving mode Exit Cause exceptions for the CPU. * This can cause issues when rebooting the guest if a secondary * is awaken */ target/ppc/kvm.c +0
-36@@ -2159,42 +2159,6 @@ void kvmppc_hint_smt_possible(Error **errp)#ifdef TARGET_PPC64 -off_t kvmppc_alloc_rma (void **rma) -{ -off_t size; -int fd; -struct kvm_allocate_rma ret; - -/* If cap_ppc_rma == 0, contiguous RMA allocation is not supported -* if cap_ppc_rma == 1, contiguous RMA allocation is supported, but -* not necessary on this hardware -* if cap_ppc_rma == 2, contiguous RMA allocation is needed on this hardware -* -* FIXME: We should allow the user to force contiguous RMA -* allocation in the cap_ppc_rma==1 case. -*/ -if (cap_ppc_rma <2 ) { -return 0 ; - } - - fd =kvm_vm_ioctl (kvm_state,KVM_ALLOCATE_RMA , &ret); -if (fd <0 ) { -fprintf (stderr,"KVM: Error on KVM_ALLOCATE_RMA: %s\n" , -strerror (errno)); -return -1 ; - } - - size =MIN (ret.rma_size,256ul <<20 ); - - *rma =mmap (NULL , size,PROT_READ |PROT_WRITE ,MAP_SHARED , fd,0 ); -if (*rma ==MAP_FAILED ) { -fprintf (stderr,"KVM: Error mapping RMA: %s\n" ,strerror (errno)); -return -1 ; - }; - -return size; -} -uint64_t kvmppc_rma_size (uint64_t current_size,unsigned int hash_shift) {struct kvm_ppc_smmu_info info;target/ppc/kvm_ppc.h +0
-6@@ -37,7 +37,6 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool radix, bool gtse, uint64_t proc_tbl);#ifndef CONFIG_USER_ONLY -off_t kvmppc_alloc_rma (void **rma);bool kvmppc_spapr_use_multitce (void );int kvmppc_spapr_enable_inkernel_multitce (void ); void *kvmppc_create_spapr_tce(uint32_t liobn, uint32_t page_shift,@@ -188,11 +187,6 @@ static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, }#ifndef CONFIG_USER_ONLY -static inline off_t kvmppc_alloc_rma (void **rma) -{ -return 0 ; -} -static inline bool kvmppc_spapr_use_multitce (void ) {return false;
Re: [Qemu-devel] [PATCH for-2.13 02/10] spapr: Remove support for PowerPC 970 with pseries machine type
Quoted 54 lines · Greg Kurz
Quoted 11 lines · On Tue, 17 Apr 2018 17:17:14 +1000 David Gibson <[email protected]>…
Current POWER cpus allow for a VRMA, a special mapping which describes a guest's view of memory when in real mode (MMU off, from the guest's point of view). Older cpus didn't have that which meant that to support a guest a special host-contiguous region of memory was needed to give the guest its Real Mode Area (RMA).
This was useful in the early days of KVM on Power to allow it to be tested on PowerPC 970 chips as used in Macintosh G5 machines. Now, however, those machines are so old as to be irrelevant, and the host kernel has long since dropped support for this mode. It hasn't been tested in ages either.
Quoted 8 lines
So, to simplify the code, drop the support from qemu as well.
As well as the code for handling contiguous RMAs, we can remove some code to set the HIOR register, which existed on 970 but not on the current and supported CPUs.
Signed-off-by David Gibson <[email protected]>---
Regardless of the discussion on the deprecation process, just a cosmetic remark...
Quoted 28 lines
hw/ppc/spapr.c | 61 +++++++++++++++---------------------------------- hw/ppc/spapr_cpu_core.c | 2 -- target/ppc/kvm.c | 36 ----------------------------- target/ppc/kvm_ppc.h | 6 ----- 4 files changed, 19 insertions(+), 86 deletions(-)hw/ppc/spapr.c +1
-5@@ -2376,9 +2376,6 @@ static void spapr_machine_init(MachineState *machine)int i;MemoryRegion *sysmem =get_system_memory ();MemoryRegion *ram =g_new (MemoryRegion,1 ); -MemoryRegion *rma_region; -void *rma =NULL ; -hwaddr rma_alloc_size;hwaddr node0_size =spapr_node0_size (machine);long load_limit, fw_size;char *filename;@@ -2417,40 +2414,28 @@ static void spapr_machine_init(MachineState *machine)exit (1 ); } -/* Allocate RMA if necessary */ - rma_alloc_size =kvmppc_alloc_rma (&rma); + spapr->rma_size = node0_size;
Quoted 13 lines
hw/ppc/spapr.c static void spapr_machine_init(MachineState *machine) · line 2426
Quoted 11 lines
hw/ppc/spapr.c +8
-3-if (rma_alloc_size ==-1 ) { -error_report ("Unable to create RMA" ); -exit (1 ); +/* With KVM, we don't actually know whether KVM supports an +* unbounded RMA (PR KVM) or is limited by the hash table size (HV +* KVM using VRMA), so we always assume the latter +* +* In that case, we also limit the initial allocations for RTAS +* etc... to 256M since we have no way to know what the VRMA size +* is going to be as it depends on the size of the hash table +* isn't determined yet. ... maybe s/isn't/which isn't/ while at it ?
Thanks, I've made that change.
Signature · 4 lines
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
PATCH 3/10 target/ppc: Remove unnecessary initialization of LPCR_UPRT
In reply to David GibsonIn cpu_ppc_set_papr() the UPRT and GTSE bits of the LPCR are initialized based on on ppc64_radix_guest(). Which seems reasonable, except that ppc64_radix_guest() is based on spapr->patb_entry which is only set up in spapr_machine_reset, called much later than cpu_ppc_set_papr().
So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
--- target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)
target/ppc/translate_init.c +0 -16
@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ; -if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/ -if (ppc64_radix_guest (cpu)) { - lpcr->default_value |=LPCR_UPRT |LPCR_GTSE ; - }else { - lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); - } - } -/* Only enable Power-saving mode Exit Cause exceptions on the boot * CPU. The RTAS command start-cpu will enable them on secondaries. */
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
Quoted 11 lines · On Tue, 17 Apr 2018 17:17:15 +1000 David Gibson <[email protected]>…
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>---
Quoted 30 lines
target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)target/ppc/translate_init.c +0
-16@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ; -if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/ -if (ppc64_radix_guest (cpu)) { - lpcr->default_value |=LPCR_UPRT |LPCR_GTSE ; - }else { - lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); - } - } -/* Only enable Power-saving mode Exit Cause exceptions on the boot * CPU. The RTAS command start-cpu will enable them on secondaries. */
David Gibson
AppliedRe: [Qemu-devel] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
Quoted 8 lines · Greg Kurz
Quoted 5 lines · On Tue, 17 Apr 2018 17:17:15 +1000 David Gibson <[email protected]>…
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().
Quoted 8 lines
Quoted 6 lines
So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>---
Reviewed-by Greg Kurz <[email protected]>
Merged to ppc-for-2.13.
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
In reply to David GibsonQuoted 21 lines · David Gibson
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)target/ppc/translate_init.c +0
-0@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ;
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8908
Quoted 10 lines
target/ppc/translate_init.c +0
-9-if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/
This is breaking CPU hotplug under TCG. Should we reintroduce the same settings in spapr_cpu_reset() now ?
Thanks,
C.
Quoted 11 lines
target/ppc/translate_init.c +0
-7-if (ppc64_radix_guest (cpu)) { - lpcr->default_value |=LPCR_UPRT |LPCR_GTSE ; - }else { - lpcr->default_value &= ~(LPCR_UPRT |LPCR_GTSE ); - } - } -/* Only enable Power-saving mode Exit Cause exceptions on the boot * CPU. The RTAS command start-cpu will enable them on secondaries. */
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
Quoted 23 lines · Cédric Le Goater
Quoted 22 lines · David Gibson
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)target/ppc/translate_init.c +0
-0@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ;
Quoted 13 lines
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8908
Quoted 9 lines
target/ppc/translate_init.c +0
-9-if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/ This is breaking CPU hotplug under TCG. Should we reintroduce the same settings in
spapr_cpu_reset()now ?
Sod. Yeah, this code is important for the hotplug case.
But, no, I don't think it should go into reset, I think it should go into the rtas start-cpu path; it only makes sense for secondary CPUs.
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
Quoted 38 lines · David Gibson
Quoted 23 lines · Cédric Le Goater
Quoted 22 lines · David Gibson
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)target/ppc/translate_init.c +0
-0@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ;Quoted 13 lines
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8908
Quoted 9 lines
target/ppc/translate_init.c +0
-9-if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/ This is breaking CPU hotplug under TCG. Should we reintroduce the same settings in
spapr_cpu_reset()now ?
Quoted 4 lines
Sod. Yeah, this code is important for the hotplug case.
But, no, I don't think it should go into reset, I think it should go into the rtas start-cpu path; it only makes sense for secondary CPUs.
yes. I will send a fix.
Thanks,
C.
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
Quoted 39 lines · Cédric Le Goater
Quoted 38 lines · David Gibson
Quoted 36 lines · Cédric Le Goater
Quoted 21 lines · David Gibson
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)target/ppc/translate_init.c +0
-0@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ;target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8908
Quoted 10 lines
target/ppc/translate_init.c +0
-9-if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/ This is breaking CPU hotplug under TCG. Should we reintroduce the same settings in
spapr_cpu_reset()now ?
Quoted 6 lines
Quoted 4 lines
Sod. Yeah, this code is important for the hotplug case.
But, no, I don't think it should go into reset, I think it should go into the rtas start-cpu path; it only makes sense for secondary CPUs.
yes. I will send a fix.
Not sure if this is still on your radar, but if it is, don't bother. I've already made a fix (along with various others) and will be posting soonish.
Signature · 4 lines
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
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 03/10] target/ppc: Remove unnecessary initialization of LPCR_UPRT
Quoted 42 lines · David Gibson
Quoted 41 lines · Cédric Le Goater
Quoted 40 lines · David Gibson
Quoted 23 lines · Cédric Le Goater
Quoted 22 lines · David Gibson
In
cpu_ppc_set_papr()the UPRT and GTSE bits of the LPCR are initialized based on onppc64_radix_guest(). Which seems reasonable, except thatppc64_radix_guest()is based onspapr->patb_entrywhich is only set up inspapr_machine_reset, called much later thancpu_ppc_set_papr().So the initialization here is pointless. The base cpu initialization already sets a value that's good enough until the guest uses an hcall to configure it's preferred MMU mode.
Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 16 ---------------- 1 file changed, 16 deletions(-)target/ppc/translate_init.c +0
-0@@ -8897,22 +8897,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) lpcr->default_value &= ~LPCR_RMLS ; lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ;Quoted 13 lines
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8908
Quoted 9 lines
target/ppc/translate_init.c +0
-9-if (env->mmu_model ==POWERPC_MMU_3_00 ) { -/* By default we choose legacy mode and switch to new hash or radix -* when a register process table hcall is made. So disable process -* tables and guest translation shootdown by default -* -* Hot-plugged CPUs inherit from the guest radix setting under -* KVM but not under TCG. Update the default LPCR to keep new -* CPUs in sync when radix is enabled. -*/ This is breaking CPU hotplug under TCG. Should we reintroduce the same settings in
spapr_cpu_reset()now ?Sod. Yeah, this code is important for the hotplug case.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But, no, I don't think it should go into reset, I think it should go into the rtas start-cpu path; it only makes sense for secondary CPUs.
yes. I will send a fix.
Not sure if this is still on your radar, but if it is, don't bother. I've already made a fix (along with various others) and will be posting soonish.
As you reverted the changes in the ppc-2.13 branch, I postponed the changes. Go ahead.
Thanks,
C.
PATCH 4/10 spapr: Set compatibility mode before the rest of spapr_cpu_reset()
In reply to David GibsonAlthough the order doesn't really matter at the moment, it's possible other initializastions could depend on the compatiblity mode, so make sure we set it first in spapr_cpu_reset().
While we're at it drop the test against first_cpu. Setting the compat mode to the value it already has is redundant, but harmless, so we might as well make a small simplification to the code.
--- hw/ppc/spapr_cpu_core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
hw/ppc/spapr_cpu_core.c +5 -6
@@ -31,6 +31,11 @@ static void spapr_cpu_reset(void *opaque)cpu_reset (cs); +/* Set compatibility mode to match the boot CPU, which was either set +* by the machine reset code or by CAS. This should never fail. +*/ +ppc_set_compat (cpu,POWERPC_CPU (first_cpu)->compat_pvr, &error_abort); +/* All CPUs start halted. CPU0 is unhalted from the machine level * reset code and the rest are explicitly started up by the guest * using an RTAS call */
@@ -43,12 +48,6 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_LPCR ] &= ~pcc->lpcr_pm; } -/* Set compatibility mode to match the boot CPU, which was either set -* by the machine reset code or by CAS. This should never fail. -*/ -if (cs != first_cpu) { -ppc_set_compat (cpu,POWERPC_CPU (first_cpu)->compat_pvr, &error_abort); - } }static void spapr_cpu_destroy (PowerPCCPU *cpu)
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 04/10] spapr: Set compatibility mode before the rest of spapr_cpu_reset()
Quoted 10 lines · On Tue, 17 Apr 2018 17:17:16 +1000 David Gibson <[email protected]>…
Although the order doesn't really matter at the moment, it's possible other initializastions could depend on the compatiblity mode, so make sure we set it first in
spapr_cpu_reset().While we're at it drop the test against
first_cpu. Setting the compat mode to the value it already has is redundant, but harmless, so we might as well make a small simplification to the code.Signed-off-by David Gibson <[email protected]>---
Quoted 32 lines
hw/ppc/spapr_cpu_core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/ppc/spapr_cpu_core.c +5
-6@@ -31,6 +31,11 @@ static void spapr_cpu_reset(void *opaque)cpu_reset (cs); +/* Set compatibility mode to match the boot CPU, which was either set +* by the machine reset code or by CAS. This should never fail. +*/ +ppc_set_compat (cpu,POWERPC_CPU (first_cpu)->compat_pvr, &error_abort); +/* All CPUs start halted. CPU0 is unhalted from the machine level * reset code and the rest are explicitly started up by the guest * using an RTAS call */ @@ -43,12 +48,6 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_LPCR ] &= ~pcc->lpcr_pm; } -/* Set compatibility mode to match the boot CPU, which was either set -* by the machine reset code or by CAS. This should never fail. -*/ -if (cs != first_cpu) { -ppc_set_compat (cpu,POWERPC_CPU (first_cpu)->compat_pvr, &error_abort); - } }static void spapr_cpu_destroy (PowerPCCPU *cpu)
Re: [Qemu-devel] [PATCH for-2.13 04/10] spapr: Set compatibility mode before the rest of spapr_cpu_reset()
Quoted 7 lines · Greg Kurz
Quoted 4 lines · On Tue, 17 Apr 2018 17:17:16 +1000 David Gibson <[email protected]>…
Although the order doesn't really matter at the moment, it's possible other initializastions could depend on the compatiblity mode, so make sure we set it first in
spapr_cpu_reset().
Quoted 8 lines
Quoted 6 lines
While we're at it drop the test against
first_cpu. Setting the compat mode to the value it already has is redundant, but harmless, so we might as well make a small simplification to the code.Signed-off-by David Gibson <[email protected]>---
Reviewed-by Greg Kurz <[email protected]>
Ta. This one also doesn't really depend on the others, so I've merged it into ppc-for-2.13.
Quoted 34 lines
Quoted 33 lines
hw/ppc/spapr_cpu_core.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)hw/ppc/spapr_cpu_core.c +5
-6@@ -31,6 +31,11 @@ static void spapr_cpu_reset(void *opaque)cpu_reset (cs); +/* Set compatibility mode to match the boot CPU, which was either set +* by the machine reset code or by CAS. This should never fail. +*/ +ppc_set_compat (cpu,POWERPC_CPU (first_cpu)->compat_pvr, &error_abort); +/* All CPUs start halted. CPU0 is unhalted from the machine level * reset code and the rest are explicitly started up by the guest * using an RTAS call */ @@ -43,12 +48,6 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_LPCR ] &= ~pcc->lpcr_pm; } -/* Set compatibility mode to match the boot CPU, which was either set -* by the machine reset code or by CAS. This should never fail. -*/ -if (cs != first_cpu) { -ppc_set_compat (cpu,POWERPC_CPU (first_cpu)->compat_pvr, &error_abort); - } }static void spapr_cpu_destroy (PowerPCCPU *cpu)
Signature · 4 lines
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
PATCH 5/10 spapr: Move PAPR mode register initialization to spapr code
In reply to David Gibsoncpu_ppc_set_papr() has code to make sure the LPCR and AMOR (hypervisor privileged registers) have values which will make TCG behave correctly for paravirtualized guests, where we don't emulate the cpu when in hypervisor mode.
It does this by mangling the default values of the SPRs, so that they will be set correctly at reset time. Manipulating usually-static parameters of the cpu model like this is kind of ugly, especially since the values used really have more to do with the platform than the cpu.
The spapr code already has places for PAPR specific initializations of register state, so move the handling of LPCR and AMOR to there.
--- hw/ppc/spapr_cpu_core.c | 36 +++++++++++++++++++++++++++++++++++- target/ppc/translate_init.c | 39 --------------------------------------- 2 files changed, 35 insertions(+), 40 deletions(-)
hw/ppc/spapr_cpu_core.c +35 -1
@@ -28,6 +28,7 @@ static void spapr_cpu_reset(void *opaque)CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong lpcr;cpu_reset (cs);
@@ -41,13 +42,46 @@ static void spapr_cpu_reset(void *opaque)* using an RTAS call */ cs->halted =1 ; + lpcr = env->spr[SPR_LPCR ]; + +/* Set emulated LPCR to not send interrupts to hypervisor. Note that +* under KVM, the actual HW LPCR will be set differently by KVM itself, +* the settings below ensure proper operations with TCG in absence of +* a real hypervisor. +* +* Clearing VPM0 will also cause us to use RMOR in mmu-hash64.c for +* real mode accesses, which thankfully defaults to 0 and isn't +* accessible in guest mode. +*/ + lpcr &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV ); + lpcr |=LPCR_LPES0 |LPCR_LPES1 ; + +/* Set RMLS to the max (ie, 16G) */ + lpcr &= ~LPCR_RMLS ; + lpcr |=1ull <<LPCR_RMLS_SHIFT ; + +/* Only enable Power-saving mode Exit Cause exceptions on the boot +* CPU. The RTAS command start-cpu will enable them on secondaries. +*/ +if (cs == first_cpu) { + lpcr |= pcc->lpcr_pm; + } +/* Disable Power-saving mode Exit Cause exceptions for the CPU. * This can cause issues when rebooting the guest if a secondary * is awaken */ if (cs != first_cpu) { - env->spr[SPR_LPCR ] &= ~pcc->lpcr_pm; + lpcr &= ~pcc->lpcr_pm; } + env->spr[SPR_LPCR ] = lpcr; + +/* Set a full AMOR so guest can use the AMR as it sees fit */ + env->spr[SPR_AMOR ] =0xffffffffffffffffull ; + +/* Update some env bits based on new LPCR value */ +ppc_hash64_update_rmls (cpu); +ppc_hash64_update_vrma (cpu); }static void spapr_cpu_destroy (PowerPCCPU *cpu)
target/ppc/translate_init.c +0 -39
@@ -8866,11 +8866,7 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)#if !defined(CONFIG_USER_ONLY )void cpu_ppc_set_papr (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp) { -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env; -ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ]; -ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; -CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;
@@ -8881,41 +8877,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)*/ env->msr_mask &= ~((1ull <<MSR_EP ) |MSR_HVB ); -/* Set emulated LPCR to not send interrupts to hypervisor. Note that -* under KVM, the actual HW LPCR will be set differently by KVM itself, -* the settings below ensure proper operations with TCG in absence of -* a real hypervisor. -* -* Clearing VPM0 will also cause us to use RMOR in mmu-hash64.c for -* real mode accesses, which thankfully defaults to 0 and isn't -* accessible in guest mode. -*/ - lpcr->default_value &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV ); - lpcr->default_value |=LPCR_LPES0 |LPCR_LPES1 ; - -/* Set RMLS to the max (ie, 16G) */ - lpcr->default_value &= ~LPCR_RMLS ; - lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ; - -/* Only enable Power-saving mode Exit Cause exceptions on the boot -* CPU. The RTAS command start-cpu will enable them on secondaries. -*/ -if (cs == first_cpu) { - lpcr->default_value |= pcc->lpcr_pm; - } - -/* We should be followed by a CPU reset but update the active value -* just in case... -*/ - env->spr[SPR_LPCR ] = lpcr->default_value; - -/* Set a full AMOR so guest can use the AMR as it sees fit */ - env->spr[SPR_AMOR ] = amor->default_value =0xffffffffffffffffull ; - -/* Update some env bits based on new LPCR value */ -ppc_hash64_update_rmls (cpu); -ppc_hash64_update_vrma (cpu); -/* Tell KVM that we're in PAPR mode */ if (kvm_enabled ()) {kvmppc_set_papr (cpu);
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 05/10] spapr: Move PAPR mode register initialization to spapr code
Quoted 58 lines · On Tue, 17 Apr 2018 17:17:17 +1000 David Gibson <[email protected]>…
cpu_ppc_set_papr()has code to make sure the LPCR and AMOR (hypervisor privileged registers) have values which will make TCG behave correctly for paravirtualized guests, where we don't emulate the cpu when in hypervisor mode.It does this by mangling the default values of the SPRs, so that they will be set correctly at reset time. Manipulating usually-static parameters of the cpu model like this is kind of ugly, especially since the values used really have more to do with the platform than the cpu.
The spapr code already has places for PAPR specific initializations of register state, so move the handling of LPCR and AMOR to there.
Signed-off-by David Gibson <[email protected]>--- hw/ppc/spapr_cpu_core.c | 36 +++++++++++++++++++++++++++++++++++- target/ppc/translate_init.c | 39 --------------------------------------- 2 files changed, 35 insertions(+), 40 deletions(-)hw/ppc/spapr_cpu_core.c +24
-0@@ -28,6 +28,7 @@ static void spapr_cpu_reset(void *opaque)CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env;PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu); +target_ulong lpcr;cpu_reset (cs);@@ -41,13 +42,46 @@ static void spapr_cpu_reset(void *opaque)* using an RTAS call */ cs->halted =1 ; + lpcr = env->spr[SPR_LPCR ]; + +/* Set emulated LPCR to not send interrupts to hypervisor. Note that +* under KVM, the actual HW LPCR will be set differently by KVM itself, +* the settings below ensure proper operations with TCG in absence of +* a real hypervisor. +* +* Clearing VPM0 will also cause us to use RMOR in mmu-hash64.c for +* real mode accesses, which thankfully defaults to 0 and isn't +* accessible in guest mode. +*/ + lpcr &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV ); + lpcr |=LPCR_LPES0 |LPCR_LPES1 ; + +/* Set RMLS to the max (ie, 16G) */ + lpcr &= ~LPCR_RMLS ; + lpcr |=1ull <<LPCR_RMLS_SHIFT ; + +/* Only enable Power-saving mode Exit Cause exceptions on the boot +* CPU. The RTAS command start-cpu will enable them on secondaries. +*/ +if (cs == first_cpu) { + lpcr |= pcc->lpcr_pm;
hw/ppc/spapr_cpu_core.c static void spapr_cpu_reset(void *opaque) · line 76
Quoted 10 lines
hw/ppc/spapr_cpu_core.c +3
-1+ } +/* Disable Power-saving mode Exit Cause exceptions for the CPU. * This can cause issues when rebooting the guest if a secondary * is awaken */ if (cs != first_cpu) { - env->spr[SPR_LPCR ] &= ~pcc->lpcr_pm; + lpcr &= ~pcc->lpcr_pm; }
Maybe fold these into a single if-else with a consolidated comment ?
/* Only enable Power-saving mode Exit Cause exceptions on the boot
* CPU and disable it for secondaries because it is known to cause
* issues if a secondary is awaken too early when rebooting the guest.
* The RTAS command start-cpu will enable exceptions on secondaries.
*/
if (cs == first_cpu) {
lpcr |= pcc->lpcr_pm;
} else {
lpcr &= ~pcc->lpcr_pm;
}Anyway, the patch looks good and makes cpu_ppc_set_papr() a lot clearer.
Quoted 69 lines
hw/ppc/spapr_cpu_core.c +8
-0+ env->spr[SPR_LPCR ] = lpcr; + +/* Set a full AMOR so guest can use the AMR as it sees fit */ + env->spr[SPR_AMOR ] =0xffffffffffffffffull ; + +/* Update some env bits based on new LPCR value */ +ppc_hash64_update_rmls (cpu); +ppc_hash64_update_vrma (cpu); }static void spapr_cpu_destroy (PowerPCCPU *cpu)target/ppc/translate_init.c +0
-39@@ -8866,11 +8866,7 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data)#if !defined(CONFIG_USER_ONLY )void cpu_ppc_set_papr (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp) { -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env; -ppc_spr_t *lpcr = &env->spr_cb[SPR_LPCR ]; -ppc_spr_t *amor = &env->spr_cb[SPR_AMOR ]; -CPUState *cs =CPU (cpu); cpu->vhyp = vhyp;@@ -8881,41 +8877,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)*/ env->msr_mask &= ~((1ull <<MSR_EP ) |MSR_HVB ); -/* Set emulated LPCR to not send interrupts to hypervisor. Note that -* under KVM, the actual HW LPCR will be set differently by KVM itself, -* the settings below ensure proper operations with TCG in absence of -* a real hypervisor. -* -* Clearing VPM0 will also cause us to use RMOR in mmu-hash64.c for -* real mode accesses, which thankfully defaults to 0 and isn't -* accessible in guest mode. -*/ - lpcr->default_value &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV ); - lpcr->default_value |=LPCR_LPES0 |LPCR_LPES1 ; - -/* Set RMLS to the max (ie, 16G) */ - lpcr->default_value &= ~LPCR_RMLS ; - lpcr->default_value |=1ull <<LPCR_RMLS_SHIFT ; - -/* Only enable Power-saving mode Exit Cause exceptions on the boot -* CPU. The RTAS command start-cpu will enable them on secondaries. -*/ -if (cs == first_cpu) { - lpcr->default_value |= pcc->lpcr_pm; - } - -/* We should be followed by a CPU reset but update the active value -* just in case... -*/ - env->spr[SPR_LPCR ] = lpcr->default_value; - -/* Set a full AMOR so guest can use the AMR as it sees fit */ - env->spr[SPR_AMOR ] = amor->default_value =0xffffffffffffffffull ; - -/* Update some env bits based on new LPCR value */ -ppc_hash64_update_rmls (cpu); -ppc_hash64_update_vrma (cpu); -/* Tell KVM that we're in PAPR mode */ if (kvm_enabled ()) {kvmppc_set_papr (cpu);
PATCH 6/10 target/ppc: Add ppc_store_lpcr() helper
In reply to David GibsonThere are some fields in the cpu state which need to be updated when the LPCR register is changed, which is done by ppc_hash64_update_rmls() and ppc_hash64_update_vrma(). Code which alters env->spr[SPR_LPCR] needs to call them afterwards to make sure the state is up to date.
That's easy to get wrong. The normal way of dealing with sitautions like that is to use a helper which both updates the basic register value and the derived state.
So, do that.
--- hw/ppc/spapr_cpu_core.c | 6 +----- target/ppc/mmu-hash64.c | 15 +++++++++++---- target/ppc/mmu-hash64.h | 3 +-- 3 files changed, 13 insertions(+), 11 deletions(-)
hw/ppc/spapr_cpu_core.c +1 -5
@@ -74,14 +74,10 @@ static void spapr_cpu_reset(void *opaque) lpcr &= ~pcc->lpcr_pm; } - env->spr[SPR_LPCR ] = lpcr; +ppc_store_lpcr (cpu, lpcr);/* Set a full AMOR so guest can use the AMR as it sees fit */ env->spr[SPR_AMOR ] =0xffffffffffffffffull ; - -/* Update some env bits based on new LPCR value */ -ppc_hash64_update_rmls (cpu); -ppc_hash64_update_vrma (cpu); }static void spapr_cpu_destroy (PowerPCCPU *cpu)
target/ppc/mmu-hash64.c +11 -4
@@ -942,7 +942,7 @@ void ppc_hash64_tlb_flush_hpte(PowerPCCPU *cpu, target_ulong ptex, cpu->env.tlb_need_flush =TLB_NEED_GLOBAL_FLUSH |TLB_NEED_LOCAL_FLUSH ; } -void ppc_hash64_update_rmls (PowerPCCPU *cpu) +static void ppc_hash64_update_rmls (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;uint64_t lpcr = env->spr[SPR_LPCR ];
@@ -977,7 +977,7 @@ void ppc_hash64_update_rmls(PowerPCCPU *cpu) } } -void ppc_hash64_update_vrma (PowerPCCPU *cpu) +static void ppc_hash64_update_vrma (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;const PPCHash64SegmentPageSizes *sps =NULL ;
@@ -1028,9 +1028,9 @@ void ppc_hash64_update_vrma(PowerPCCPU *cpu) slb->sps = sps; } -void helper_store_lpcr (CPUPPCState *env,target_ulong val) +void ppc_store_lpcr (PowerPCCPU *cpu,target_ulong val) { -PowerPCCPU *cpu =ppc_env_get_cpu (env); +CPUPPCState *env = &cpu->env;uint64_t lpcr =0 ;/* Filter out bits */
@@ -1096,6 +1096,13 @@ void helper_store_lpcr(CPUPPCState *env, target_ulong val)ppc_hash64_update_vrma (cpu); } +void helper_store_lpcr (CPUPPCState *env,target_ulong val) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +ppc_store_lpcr (cpu, val); +} +void ppc_hash64_init (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;
target/ppc/mmu-hash64.h +1 -2
@@ -17,8 +17,7 @@ void ppc_hash64_tlb_flush_hpte(PowerPCCPU *cpu, target_ulong pte0, target_ulong pte1);unsigned ppc_hash64_hpte_page_shift_noslb (PowerPCCPU *cpu,uint64_t pte0,uint64_t pte1); -void ppc_hash64_update_vrma (PowerPCCPU *cpu); -void ppc_hash64_update_rmls (PowerPCCPU *cpu); +void ppc_store_lpcr (PowerPCCPU *cpu,target_ulong val);void ppc_hash64_init (PowerPCCPU *cpu);void ppc_hash64_finalize (PowerPCCPU *cpu);#endif
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 06/10] target/ppc: Add ppc_store_lpcr() helper
Quoted 6 lines · On Tue, 17 Apr 2018 17:17:18 +1000 David Gibson <[email protected]>…
There are some fields in the cpu state which need to be updated when the LPCR register is changed, which is done by
ppc_hash64_update_rmls()andppc_hash64_update_vrma(). Code which alters env->spr[SPR_LPCR] needs to call them afterwards to make sure the state is up to date.That's easy to get wrong. The normal way of dealing with sitautions like
s/sitautions/situations/
Quoted 7 lines
that is to use a helper which both updates the basic register value and the derived state.
So, do that.
Signed-off-by David Gibson <[email protected]>---
Quoted 87 lines
hw/ppc/spapr_cpu_core.c | 6 +----- target/ppc/mmu-hash64.c | 15 +++++++++++---- target/ppc/mmu-hash64.h | 3 +-- 3 files changed, 13 insertions(+), 11 deletions(-)hw/ppc/spapr_cpu_core.c +1
-5@@ -74,14 +74,10 @@ static void spapr_cpu_reset(void *opaque) lpcr &= ~pcc->lpcr_pm; } - env->spr[SPR_LPCR ] = lpcr; +ppc_store_lpcr (cpu, lpcr);/* Set a full AMOR so guest can use the AMR as it sees fit */ env->spr[SPR_AMOR ] =0xffffffffffffffffull ; - -/* Update some env bits based on new LPCR value */ -ppc_hash64_update_rmls (cpu); -ppc_hash64_update_vrma (cpu); }static void spapr_cpu_destroy (PowerPCCPU *cpu)target/ppc/mmu-hash64.c +11
-4@@ -942,7 +942,7 @@ void ppc_hash64_tlb_flush_hpte(PowerPCCPU *cpu, target_ulong ptex, cpu->env.tlb_need_flush =TLB_NEED_GLOBAL_FLUSH |TLB_NEED_LOCAL_FLUSH ; } -void ppc_hash64_update_rmls (PowerPCCPU *cpu) +static void ppc_hash64_update_rmls (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;uint64_t lpcr = env->spr[SPR_LPCR ];@@ -977,7 +977,7 @@ void ppc_hash64_update_rmls(PowerPCCPU *cpu) } } -void ppc_hash64_update_vrma (PowerPCCPU *cpu) +static void ppc_hash64_update_vrma (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;const PPCHash64SegmentPageSizes *sps =NULL ;@@ -1028,9 +1028,9 @@ void ppc_hash64_update_vrma(PowerPCCPU *cpu) slb->sps = sps; } -void helper_store_lpcr (CPUPPCState *env,target_ulong val) +void ppc_store_lpcr (PowerPCCPU *cpu,target_ulong val) { -PowerPCCPU *cpu =ppc_env_get_cpu (env); +CPUPPCState *env = &cpu->env;uint64_t lpcr =0 ;/* Filter out bits */ @@ -1096,6 +1096,13 @@ void helper_store_lpcr(CPUPPCState *env, target_ulong val)ppc_hash64_update_vrma (cpu); } +void helper_store_lpcr (CPUPPCState *env,target_ulong val) +{ +PowerPCCPU *cpu =ppc_env_get_cpu (env); + +ppc_store_lpcr (cpu, val); +} +void ppc_hash64_init (PowerPCCPU *cpu) {CPUPPCState *env = &cpu->env;target/ppc/mmu-hash64.h +1
-2@@ -17,8 +17,7 @@ void ppc_hash64_tlb_flush_hpte(PowerPCCPU *cpu, target_ulong pte0, target_ulong pte1);unsigned ppc_hash64_hpte_page_shift_noslb (PowerPCCPU *cpu,uint64_t pte0,uint64_t pte1); -void ppc_hash64_update_vrma (PowerPCCPU *cpu); -void ppc_hash64_update_rmls (PowerPCCPU *cpu); +void ppc_store_lpcr (PowerPCCPU *cpu,target_ulong val);void ppc_hash64_init (PowerPCCPU *cpu);void ppc_hash64_finalize (PowerPCCPU *cpu);#endif
PATCH 7/10 spapr: Make a helper to set up cpu entry point state
In reply to David GibsonUnder PAPR, only the boot CPU is active when the system starts. Other cpus must be explicitly activated using an RTAS call. The entry state for the boot and secondary cpus isn't identical, but it has some things in common. We're going to add a bit more common setup later, too, so to simplify make a helper which sets up the common entry state for both boot and secondary cpu threads.
--- hw/ppc/spapr.c | 4 +--- hw/ppc/spapr_cpu_core.c | 9 +++++++++ hw/ppc/spapr_rtas.c | 6 +++--- include/hw/ppc/spapr_cpu_core.h | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-)
hw/ppc/spapr.c +1 -3
@@ -1536,10 +1536,8 @@ static void spapr_machine_reset(void)g_free (fdt);/* Set up the entry state */ - first_ppc_cpu->env.gpr[3 ] = fdt_addr; +spapr_cpu_set_entry_state (first_ppc_cpu,SPAPR_ENTRY_POINT , fdt_addr); first_ppc_cpu->env.gpr[5 ] =0 ; - first_cpu->halted =0 ; - first_ppc_cpu->env.nip =SPAPR_ENTRY_POINT ; spapr->cas_reboot = false; }
hw/ppc/spapr_cpu_core.c +9 -0
@@ -80,6 +80,15 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_AMOR ] =0xffffffffffffffffull ; } +void spapr_cpu_set_entry_state (PowerPCCPU *cpu,target_ulong nip,target_ulong r3) +{ +CPUPPCState *env = &cpu->env; + + env->nip =SPAPR_ENTRY_POINT ; + env->gpr[3 ] = r3; +CPU (cpu)->halted =0 ; +} +static void spapr_cpu_destroy (PowerPCCPU *cpu) {qemu_unregister_reset (spapr_cpu_reset, cpu);
hw/ppc/spapr_rtas.c +3 -3
@@ -37,6 +37,7 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" #include "hw/ppc/spapr_rtas.h" +#include "hw/ppc/spapr_cpu_core.h" #include "hw/ppc/ppc.h" #include "hw/boards.h"
@@ -173,14 +174,13 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,* new cpu enters */ kvm_cpu_synchronize_state (cs); +spapr_cpu_set_entry_state (cpu, start, r3); + env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );/* Enable Power-saving mode Exit Cause exceptions for the new CPU */ env->spr[SPR_LPCR ] |= pcc->lpcr_pm; - env->nip = start; - env->gpr[3 ] = r3; - cs->halted =0 ;spapr_cpu_set_endianness (cpu);spapr_cpu_update_tb_offset (cpu);
include/hw/ppc/spapr_cpu_core.h +3 -0
@@ -12,6 +12,7 @@#include "hw/qdev.h" #include "hw/cpu/core.h" #include "target/ppc/cpu-qom.h" +#include "target/ppc/cpu.h" #define TYPE_SPAPR_CPU_CORE "spapr-cpu-core"#define SPAPR_CPU_CORE (obj) \
@@ -40,4 +41,6 @@ typedef struct sPAPRCPUCoreClass {const char *spapr_get_cpu_core_type (const char *cpu_type);void spapr_cpu_core_reset (sPAPRCPUCore *sc); +void spapr_cpu_set_entry_state (PowerPCCPU *cpu,target_ulong nip,target_ulong r3); +#endif
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 07/10] spapr: Make a helper to set up cpu entry point state
Quoted 9 lines · On Tue, 17 Apr 2018 17:17:19 +1000 David Gibson <[email protected]>…
Under PAPR, only the boot CPU is active when the system starts. Other cpus must be explicitly activated using an RTAS call. The entry state for the boot and secondary cpus isn't identical, but it has some things in common. We're going to add a bit more common setup later, too, so to simplify make a helper which sets up the common entry state for both boot and secondary cpu threads.
Signed-off-by David Gibson <[email protected]>---
Quoted 90 lines
hw/ppc/spapr.c | 4 +--- hw/ppc/spapr_cpu_core.c | 9 +++++++++ hw/ppc/spapr_rtas.c | 6 +++--- include/hw/ppc/spapr_cpu_core.h | 3 +++ 4 files changed, 16 insertions(+), 6 deletions(-)hw/ppc/spapr.c +1
-3@@ -1536,10 +1536,8 @@ static void spapr_machine_reset(void)g_free (fdt);/* Set up the entry state */ - first_ppc_cpu->env.gpr[3 ] = fdt_addr; +spapr_cpu_set_entry_state (first_ppc_cpu,SPAPR_ENTRY_POINT , fdt_addr); first_ppc_cpu->env.gpr[5 ] =0 ; - first_cpu->halted =0 ; - first_ppc_cpu->env.nip =SPAPR_ENTRY_POINT ; spapr->cas_reboot = false; }hw/ppc/spapr_cpu_core.c +9
-0@@ -80,6 +80,15 @@ static void spapr_cpu_reset(void *opaque) env->spr[SPR_AMOR ] =0xffffffffffffffffull ; } +void spapr_cpu_set_entry_state (PowerPCCPU *cpu,target_ulong nip,target_ulong r3) +{ +CPUPPCState *env = &cpu->env; + + env->nip =SPAPR_ENTRY_POINT ; + env->gpr[3 ] = r3; +CPU (cpu)->halted =0 ; +} +static void spapr_cpu_destroy (PowerPCCPU *cpu) {qemu_unregister_reset (spapr_cpu_reset, cpu);hw/ppc/spapr_rtas.c +3
-3@@ -37,6 +37,7 @@#include "hw/ppc/spapr.h" #include "hw/ppc/spapr_vio.h" #include "hw/ppc/spapr_rtas.h" +#include "hw/ppc/spapr_cpu_core.h" #include "hw/ppc/ppc.h" #include "hw/boards.h" @@ -173,14 +174,13 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,* new cpu enters */ kvm_cpu_synchronize_state (cs); +spapr_cpu_set_entry_state (cpu, start, r3); + env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME );/* Enable Power-saving mode Exit Cause exceptions for the new CPU */ env->spr[SPR_LPCR ] |= pcc->lpcr_pm; - env->nip = start; - env->gpr[3 ] = r3; - cs->halted =0 ;spapr_cpu_set_endianness (cpu);spapr_cpu_update_tb_offset (cpu);include/hw/ppc/spapr_cpu_core.h +3
-0@@ -12,6 +12,7 @@#include "hw/qdev.h" #include "hw/cpu/core.h" #include "target/ppc/cpu-qom.h" +#include "target/ppc/cpu.h" #define TYPE_SPAPR_CPU_CORE "spapr-cpu-core"#define SPAPR_CPU_CORE (obj) \@@ -40,4 +41,6 @@ typedef struct sPAPRCPUCoreClass {const char *spapr_get_cpu_core_type (const char *cpu_type);void spapr_cpu_core_reset (sPAPRCPUCore *sc); +void spapr_cpu_set_entry_state (PowerPCCPU *cpu,target_ulong nip,target_ulong r3); +#endif
PATCH 8/10 spapr: Clean up handling of LPCR power-saving exit bits
In reply to David GibsonTo prevent spurious wakeups on cpus that are supposed to be disabled, we need to clear the LPCR bits which control certain wakeup events. spapr_cpu_reset() has separate cases here for boot and non-boot (initially inactive) cpus. rtas_start_cpu() then turns the LPCR bits on when the non-boot cpus are activated.
But explicit checks against first_cpu are not how we usually do things:
instead spapr_cpu_reset() generally sets things up for non-boot (inactive) cpus, then spapr_machine_reset() and/or rtas_start_cpu() override as necessary.
So, do that instead. Because the LPCR activation is identical for boot cpus and non-boot cpus just activated with rtas_start_cpu() we can put the code common in spapr_cpu_set_entry_state().
--- hw/ppc/spapr_cpu_core.c | 22 +++++++--------------- hw/ppc/spapr_rtas.c | 4 ---- 2 files changed, 7 insertions(+), 19 deletions(-)
hw/ppc/spapr_cpu_core.c +7 -15
@@ -52,28 +52,17 @@ static void spapr_cpu_reset(void *opaque)* Clearing VPM0 will also cause us to use RMOR in mmu-hash64.c for * real mode accesses, which thankfully defaults to 0 and isn't * accessible in guest mode. +* +* Disable Power-saving mode Exit Cause exceptions for the CPU, so +* we don't get spurious wakups before an RTAS start-cpu call. */ - lpcr &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV ); + lpcr &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV | pcc->lpcr_pm); lpcr |=LPCR_LPES0 |LPCR_LPES1 ;/* Set RMLS to the max (ie, 16G) */ lpcr &= ~LPCR_RMLS ; lpcr |=1ull <<LPCR_RMLS_SHIFT ; -/* Only enable Power-saving mode Exit Cause exceptions on the boot -* CPU. The RTAS command start-cpu will enable them on secondaries. -*/ -if (cs == first_cpu) { - lpcr |= pcc->lpcr_pm; - } - -/* Disable Power-saving mode Exit Cause exceptions for the CPU. -* This can cause issues when rebooting the guest if a secondary -* is awaken */ -if (cs != first_cpu) { - lpcr &= ~pcc->lpcr_pm; - } -ppc_store_lpcr (cpu, lpcr);/* Set a full AMOR so guest can use the AMR as it sees fit */
@@ -82,11 +71,14 @@ static void spapr_cpu_reset(void *opaque)void spapr_cpu_set_entry_state (PowerPCCPU *cpu,target_ulong nip,target_ulong r3) { +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env; env->nip =SPAPR_ENTRY_POINT ; env->gpr[3 ] = r3;CPU (cpu)->halted =0 ; +/* Enable Power-saving mode Exit Cause exceptions */ +ppc_store_lpcr (cpu, env->spr[SPR_LPCR ] | pcc->lpcr_pm); }static void spapr_cpu_destroy (PowerPCCPU *cpu)
hw/ppc/spapr_rtas.c +0 -4
@@ -162,7 +162,6 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,if (cpu !=NULL ) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);if (!cs->halted) {rtas_st (rets,0 ,RTAS_OUT_HW_ERROR );
@@ -178,9 +177,6 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); -/* Enable Power-saving mode Exit Cause exceptions for the new CPU */ - env->spr[SPR_LPCR ] |= pcc->lpcr_pm; -spapr_cpu_set_endianness (cpu);spapr_cpu_update_tb_offset (cpu);
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 08/10] spapr: Clean up handling of LPCR power-saving exit bits
Quoted 11 lines · On Tue, 17 Apr 2018 17:17:20 +1000 David Gibson <[email protected]>…
To prevent spurious wakeups on cpus that are supposed to be disabled, we need to clear the LPCR bits which control certain wakeup events.
spapr_cpu_reset()has separate cases here for boot and non-boot (initially inactive) cpus.rtas_start_cpu()then turns the LPCR bits on when the non-boot cpus are activated.But explicit checks against
first_cpuare not how we usually do things:
insteadspapr_cpu_reset()generally sets things up for non-boot (inactive) cpus, thenspapr_machine_reset()and/orrtas_start_cpu()override as necessary.
Quoted 6 lines
So, do that instead. Because the LPCR activation is identical for boot cpus and non-boot cpus just activated with
rtas_start_cpu()we can put the code common inspapr_cpu_set_entry_state().Signed-off-by David Gibson <[email protected]>---
Ok, ok, I hadn't seen this patch yet when I commented on patch 5 :)
Quoted 78 lines
hw/ppc/spapr_cpu_core.c | 22 +++++++--------------- hw/ppc/spapr_rtas.c | 4 ---- 2 files changed, 7 insertions(+), 19 deletions(-)hw/ppc/spapr_cpu_core.c +7
-15@@ -52,28 +52,17 @@ static void spapr_cpu_reset(void *opaque)* Clearing VPM0 will also cause us to use RMOR in mmu-hash64.c for * real mode accesses, which thankfully defaults to 0 and isn't * accessible in guest mode. +* +* Disable Power-saving mode Exit Cause exceptions for the CPU, so +* we don't get spurious wakups before an RTAS start-cpu call. */ - lpcr &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV ); + lpcr &= ~(LPCR_VPM0 |LPCR_VPM1 |LPCR_ISL |LPCR_KBV | pcc->lpcr_pm); lpcr |=LPCR_LPES0 |LPCR_LPES1 ;/* Set RMLS to the max (ie, 16G) */ lpcr &= ~LPCR_RMLS ; lpcr |=1ull <<LPCR_RMLS_SHIFT ; -/* Only enable Power-saving mode Exit Cause exceptions on the boot -* CPU. The RTAS command start-cpu will enable them on secondaries. -*/ -if (cs == first_cpu) { - lpcr |= pcc->lpcr_pm; - } - -/* Disable Power-saving mode Exit Cause exceptions for the CPU. -* This can cause issues when rebooting the guest if a secondary -* is awaken */ -if (cs != first_cpu) { - lpcr &= ~pcc->lpcr_pm; - } -ppc_store_lpcr (cpu, lpcr);/* Set a full AMOR so guest can use the AMR as it sees fit */ @@ -82,11 +71,14 @@ static void spapr_cpu_reset(void *opaque)void spapr_cpu_set_entry_state (PowerPCCPU *cpu,target_ulong nip,target_ulong r3) { +PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);CPUPPCState *env = &cpu->env; env->nip =SPAPR_ENTRY_POINT ; env->gpr[3 ] = r3;CPU (cpu)->halted =0 ; +/* Enable Power-saving mode Exit Cause exceptions */ +ppc_store_lpcr (cpu, env->spr[SPR_LPCR ] | pcc->lpcr_pm); }static void spapr_cpu_destroy (PowerPCCPU *cpu)hw/ppc/spapr_rtas.c +0
-4@@ -162,7 +162,6 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr,if (cpu !=NULL ) {CPUState *cs =CPU (cpu);CPUPPCState *env = &cpu->env; -PowerPCCPUClass *pcc =POWERPC_CPU_GET_CLASS (cpu);if (!cs->halted) {rtas_st (rets,0 ,RTAS_OUT_HW_ERROR );@@ -178,9 +177,6 @@ static void rtas_start_cpu(PowerPCCPU *cpu_, sPAPRMachineState *spapr, env->msr = (1ULL <<MSR_SF ) | (1ULL <<MSR_ME ); -/* Enable Power-saving mode Exit Cause exceptions for the new CPU */ - env->spr[SPR_LPCR ] |= pcc->lpcr_pm; -spapr_cpu_set_endianness (cpu);spapr_cpu_update_tb_offset (cpu);
PATCH 9/10 target/ppc: Don't bother with MSR_EP in cpu_ppc_set_papr()
In reply to David Gibsoncpu_ppc_set_papr() removes the EP and HV bits from the MSR mask. While removing the HV bit makes sense (a cpu in PAPR mode should never be emulated in hypervisor mode), the EP bit is just bizarre. Although it's true that a papr mode guest shouldn't be able to change the exception prefix, the MSR[EP] bit doesn't even exist on the cpus supported for PAPR mode, so it's pointless to do anything with it here.
--- target/ppc/translate_init.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
target/ppc/translate_init.c +4 -5
@@ -8870,12 +8870,11 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) cpu->vhyp = vhyp; -/* PAPR always has exception vectors in RAM not ROM. To ensure this, -* MSR[IP] should never be set. -* -* We also disallow setting of MSR_HV +/* +* With a virtual hypervisor mode we never allow the CPU to go +* hypervisor mode itself */ - env->msr_mask &= ~((1ull <<MSR_EP ) |MSR_HVB ); + env->msr_mask &= ~MSR_HVB ;/* Tell KVM that we're in PAPR mode */ if (kvm_enabled ()) {
Signature · 1 line
2.14.3
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 09/10] target/ppc: Don't bother with MSR_EP in cpu_ppc_set_papr()
Quoted 23 lines · David Gibson
cpu_ppc_set_papr()removes the EP and HV bits from the MSR mask. While removing the HV bit makes sense (a cpu in PAPR mode should never be emulated in hypervisor mode), the EP bit is just bizarre. Although it's true that a papr mode guest shouldn't be able to change the exception prefix, the MSR[EP] bit doesn't even exist on the cpus supported for PAPR mode, so it's pointless to do anything with it here.Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)target/ppc/translate_init.c +0
-3@@ -8870,12 +8870,11 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) cpu->vhyp = vhyp; -/* PAPR always has exception vectors in RAM not ROM. To ensure this, -* MSR[IP] should never be set. -*
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8880
Quoted 10 lines
target/ppc/translate_init.c +4
-2-* We also disallow setting of MSR_HV +/* +* With a virtual hypervisor mode we never allow the CPU to go +* hypervisor mode itself */ - env->msr_mask &= ~((1ull <<MSR_EP ) |MSR_HVB ); + env->msr_mask &= ~MSR_HVB ;/* Tell KVM that we're in PAPR mode */ if (kvm_enabled ()) {
Looks right.
Re: [Qemu-devel] [Qemu-ppc] [PATCH for-2.13 09/10] target/ppc: Don't bother with MSR_EP in cpu_ppc_set_papr()
Quoted 32 lines · Thomas Huth
Quoted 31 lines · David Gibson
cpu_ppc_set_papr()removes the EP and HV bits from the MSR mask. While removing the HV bit makes sense (a cpu in PAPR mode should never be emulated in hypervisor mode), the EP bit is just bizarre. Although it's true that a papr mode guest shouldn't be able to change the exception prefix, the MSR[EP] bit doesn't even exist on the cpus supported for PAPR mode, so it's pointless to do anything with it here.Signed-off-by David Gibson <[email protected]>--- target/ppc/translate_init.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)target/ppc/translate_init.c +4
-5@@ -8870,12 +8870,11 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) cpu->vhyp = vhyp; -/* PAPR always has exception vectors in RAM not ROM. To ensure this, -* MSR[IP] should never be set. -* -* We also disallow setting of MSR_HV +/* +* With a virtual hypervisor mode we never allow the CPU to go +* hypervisor mode itself */ - env->msr_mask &= ~((1ull <<MSR_EP ) |MSR_HVB ); + env->msr_mask &= ~MSR_HVB ;
Quoted 6 lines
target/ppc/translate_init.c void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp) · line 8880
Quoted 2 lines
target/ppc/translate_init.c +0
-0/* Tell KVM that we're in PAPR mode */ if (kvm_enabled ()) {Looks right.
Reviewed-by Thomas Huth <[email protected]>
Turns out this one is pretty much independent of the rest of the series, so I've merged it to ppc-for-2.13 already.
Signature · 4 lines
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
PATCH 10/10 spapr: Move PAPR specific cpu logic to pseries machine type
In reply to David Gibsoncpu_ppc_set_papr() does three things: 1) it sets up the virtual hypervisor interface, 2) it prevents the cpu from ever entering hypervisor mode and
3) it tells KVM that we're emulating a cpu in PAPR mode.
(1) & (2) make sense for any virtual hypervisor (if one ever exists). (3) belongs more properly in the machine type specific to a PAPR guest.
While we're at it, remove an unnecessary test on kvm_enabled() by making kvmppc_set_papr() a safe no-op on non-KVM.
--- hw/ppc/spapr_cpu_core.c | 4 ++-- target/ppc/cpu.h | 2 +- target/ppc/kvm.c | 4 ++++ target/ppc/translate_init.c | 7 +------ 4 files changed, 8 insertions(+), 9 deletions(-)
hw/ppc/spapr_cpu_core.c +2 -2
@@ -94,8 +94,8 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,/* Set time-base frequency to 512 MHz */ cpu_ppc_tb_init (env,SPAPR_TIMEBASE_FREQ ); -/* Enable PAPR mode in TCG or KVM */ -cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr)); +cpu_ppc_set_vhyp (cpu,PPC_VIRTUAL_HYPERVISOR (spapr)); +kvmppc_set_papr (cpu);qemu_register_reset (spapr_cpu_reset, cpu); }
target/ppc/cpu.h +1 -1
@@ -1331,7 +1331,7 @@ void store_booke_tcr (CPUPPCState *env, target_ulong val);void store_booke_tsr (CPUPPCState *env,target_ulong val);void ppc_tlb_invalidate_all (CPUPPCState *env);void ppc_tlb_invalidate_one (CPUPPCState *env,target_ulong addr); -void cpu_ppc_set_papr (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp); +void cpu_ppc_set_vhyp (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp);#endif #endif
target/ppc/kvm.c +4 -0
@@ -2090,6 +2090,10 @@ void kvmppc_set_papr(PowerPCCPU *cpu)CPUState *cs =CPU (cpu);int ret; +if (!kvm_enabled ()) { +return ; + } + ret =kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_PAPR ,0 );if (ret) {error_report ("This vCPU type or KVM version does not support PAPR" );
target/ppc/translate_init.c +1 -6
@@ -8864,7 +8864,7 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data) }#if !defined(CONFIG_USER_ONLY ) -void cpu_ppc_set_papr (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp) +void cpu_ppc_set_vhyp (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp) {CPUPPCState *env = &cpu->env;
@@ -8875,11 +8875,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* hypervisor mode itself */ env->msr_mask &= ~MSR_HVB; - -/* Tell KVM that we're in PAPR mode */ -if (kvm_enabled ()) { -kvmppc_set_papr (cpu); - } }#endif /* !defined(CONFIG_USER_ONLY) */
Signature · 1 line
2.14.3
Re: [Qemu-devel] [PATCH for-2.13 10/10] spapr: Move PAPR specific cpu logic to pseries machine type
Quoted 4 lines · On Tue, 17 Apr 2018 17:17:22 +1000 David Gibson <[email protected]>…
cpu_ppc_set_papr()does three things: 1) it sets up the virtual hypervisor interface, 2) it prevents the cpu from ever entering hypervisor mode and
3) it tells KVM that we're emulating a cpu in PAPR mode.
Quoted 8 lines
(1) & (2) make sense for any virtual hypervisor (if one ever exists). (3) belongs more properly in the machine type specific to a PAPR guest.
While we're at it, remove an unnecessary test on
kvm_enabled()by makingkvmppc_set_papr()a safe no-op on non-KVM.Signed-off-by David Gibson <[email protected]>---
Quoted 74 lines
hw/ppc/spapr_cpu_core.c | 4 ++-- target/ppc/cpu.h | 2 +- target/ppc/kvm.c | 4 ++++ target/ppc/translate_init.c | 7 +------ 4 files changed, 8 insertions(+), 9 deletions(-)hw/ppc/spapr_cpu_core.c +2
-2@@ -94,8 +94,8 @@ static void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu,/* Set time-base frequency to 512 MHz */ cpu_ppc_tb_init (env,SPAPR_TIMEBASE_FREQ ); -/* Enable PAPR mode in TCG or KVM */ -cpu_ppc_set_papr (cpu,PPC_VIRTUAL_HYPERVISOR (spapr)); +cpu_ppc_set_vhyp (cpu,PPC_VIRTUAL_HYPERVISOR (spapr)); +kvmppc_set_papr (cpu);qemu_register_reset (spapr_cpu_reset, cpu); }target/ppc/cpu.h +1
-1@@ -1331,7 +1331,7 @@ void store_booke_tcr (CPUPPCState *env, target_ulong val);void store_booke_tsr (CPUPPCState *env,target_ulong val);void ppc_tlb_invalidate_all (CPUPPCState *env);void ppc_tlb_invalidate_one (CPUPPCState *env,target_ulong addr); -void cpu_ppc_set_papr (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp); +void cpu_ppc_set_vhyp (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp);#endif #endif target/ppc/kvm.c +4
-0@@ -2090,6 +2090,10 @@ void kvmppc_set_papr(PowerPCCPU *cpu)CPUState *cs =CPU (cpu);int ret; +if (!kvm_enabled ()) { +return ; + } + ret =kvm_vcpu_enable_cap (cs,KVM_CAP_PPC_PAPR ,0 );if (ret) {error_report ("This vCPU type or KVM version does not support PAPR" );target/ppc/translate_init.c +1
-6@@ -8864,7 +8864,7 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data) }#if !defined(CONFIG_USER_ONLY ) -void cpu_ppc_set_papr (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp) +void cpu_ppc_set_vhyp (PowerPCCPU *cpu,PPCVirtualHypervisor *vhyp) {CPUPPCState *env = &cpu->env;@@ -8875,11 +8875,6 @@ void cpu_ppc_set_papr(PowerPCCPU *cpu, PPCVirtualHypervisor *vhyp)* hypervisor mode itself */ env->msr_mask &= ~MSR_HVB; - -/* Tell KVM that we're in PAPR mode */ -if (kvm_enabled ()) { -kvmppc_set_papr (cpu); - } }#endif /* !defined(CONFIG_USER_ONLY) */