qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 0/8] Generalize start-powered-off property from ARM
@ 2020-08-19 16:42 Thiago Jung Bauermann
  2020-08-19 16:42 ` [PATCH v6 1/8] target/arm: Move start-powered-off property to generic CPUState Thiago Jung Bauermann
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:42 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

This version has one small fix in patch 7, and adds Philippe's Reviewed-bys.

Applies cleanly on dgibson/ppc-for-5.2.

Original cover letter below, followed by changelog:


The ARM code has a start-powered-off property in ARMCPU, which is a
subclass of CPUState. This property causes arm_cpu_reset() to set
CPUState::halted to 1, signalling that the CPU should start in a halted
state. Other architectures also have code which aim to achieve the same
effect, but without using a property.

The ppc/spapr version has a bug where QEMU does a KVM_RUN on the vcpu
before cs->halted is set to 1, causing the vcpu to run while it's still in
an unitialized state (more details in patch 3).

Peter Maydell mentioned the ARM start-powered-off property and
Eduardo Habkost suggested making it generic, so this patch series does
that, for all cases which I was able to find via grep in the code.

The only problem is that I was only able to test these changes on a ppc64le
pseries KVM guest, so except for patches 2 and 3, all others are only
build-tested. Also, my grasp of QOM lifecycle is basically non-existant so
please be aware of that when reviewing this series.

The last patch may be wrong, as pointed out by Eduardo, so I marked it as
RFC. It may make sense to drop it.

Changes since v5:

Patch "ppc/e500: Use start-powered-off CPUState property"
Patch "mips/cps: Use start-powered-off CPUState property"
Patch "sparc/sun4m: Remove main_cpu_reset()"
Patch "target/s390x: Use start-powered-off CPUState property"
- Added Philippe's Reviewed-by.

Patch "sparc/sun4m: Use start-powered-off CPUState property"
- Move call to qdev_realize_and_unref() right after object_property_set_bool(),
  as suggested by Philippe.

Changes since v4:

Patch "ppc/e500: Use start-powered-off CPUState property"
Patch "sparc/sun4m: Use start-powered-off CPUState property"
- Use qdev_realize_and_unref() instead of qdev_realize(), as suggested
  by Igor.
- Pass &error_fatal to qdev_realize_and_unref() instead of manually
  reporting the error and exiting QEMU, as suggested by Philippe.
- Changed object_property_set_bool() to use &error_fatal instead of
  &error_abort.

Patch "mips/cps: Use start-powered-off CPUState property"
- Use qdev_realize_and_unref() instead of qdev_realize(), as suggested
  by Igor.
- Use existing errp argument to propagate error back to the caller, as
  suggested by Philippe.
- Changed object_property_set_bool() to use existing errp argument to
  propagate error back to the caller instead of using &error_abort.

Changes since v3:

General:
- Added David's, Greg's and Cornelia's Reviewed-by and Acked-by to some
  of the patches.
- Rebased on top of dgibson/ppc-for-5.2.

Patch "ppc/e500: Use start-powered-off CPUState property"
Patch "mips/cps: Use start-powered-off CPUState property"
Patch "sparc/sun4m: Use start-powered-off CPUState property"
- Initialize CPU object with object_new() and qdev_realize() instead
  of cpu_create().
- Removed Reviewed-by's and Acked-by's from these patches because of
  these changes.

Changes since v2:

General:
- Added Philippe's Reviewed-by to some of the patches.

Patch "ppc/spapr: Use start-powered-off CPUState property"
- Set the CPUState::start_powered_off variable directly rather than using
  object_property_set_bool(). Suggested by Philippe.

Patch "sparc/sun4m: Remove main_cpu_reset()"
- New patch. Suggested by Philippe.

Patch "sparc/sun4m: Use start-powered-off CPUState property"
- Remove secondary_cpu_reset(). Suggested by Philippe.
- Remove setting of `cs->halted = 1` from cpu_devinit(). Suggested by Philippe.

Patch "Don't set CPUState::halted in cpu_devinit()"
- Squashed into previous patch. Suggested by Philippe.

Patch "sparc/sun4m: Use one cpu_reset() function for main and secondary CPUs"
- Dropped.

Patch "target/s390x: Use start-powered-off CPUState property"
- Set the CPUState::start_powered_off variable directly rather than using
  object_property_set_bool(). Suggested by Philippe.
- Mention in the commit message Eduardo's observation that before this
  patch, the code didn't set cs->halted on reset.

Thiago Jung Bauermann (8):
  target/arm: Move start-powered-off property to generic CPUState
  target/arm: Move setting of CPU halted state to generic code
  ppc/spapr: Use start-powered-off CPUState property
  ppc/e500: Use start-powered-off CPUState property
  mips/cps: Use start-powered-off CPUState property
  sparc/sun4m: Remove main_cpu_reset()
  sparc/sun4m: Use start-powered-off CPUState property
  target/s390x: Use start-powered-off CPUState property

 exec.c                  |  1 +
 hw/core/cpu.c           |  2 +-
 hw/mips/cps.c           | 14 ++++++++++----
 hw/ppc/e500.c           | 14 ++++++++++----
 hw/ppc/spapr_cpu_core.c | 10 +++++-----
 hw/sparc/sun4m.c        | 31 ++++---------------------------
 include/hw/core/cpu.h   |  4 ++++
 target/arm/cpu.c        |  4 +---
 target/arm/cpu.h        |  3 ---
 target/arm/kvm32.c      |  2 +-
 target/arm/kvm64.c      |  2 +-
 target/s390x/cpu.c      |  2 +-
 12 files changed, 39 insertions(+), 50 deletions(-)



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v6 1/8] target/arm: Move start-powered-off property to generic CPUState
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
@ 2020-08-19 16:42 ` Thiago Jung Bauermann
  2020-08-19 16:43 ` [PATCH v6 2/8] target/arm: Move setting of CPU halted state to generic code Thiago Jung Bauermann
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:42 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

There are other platforms which also have CPUs that start powered off, so
generalize the start-powered-off property so that it can be used by them.

Note that ARMv7MState also has a property of the same name but this patch
doesn't change it because that class isn't a subclass of CPUState so it
wouldn't be a trivial change.

This change should not cause any change in behavior.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 exec.c                | 1 +
 include/hw/core/cpu.h | 4 ++++
 target/arm/cpu.c      | 5 ++---
 target/arm/cpu.h      | 3 ---
 target/arm/kvm32.c    | 2 +-
 target/arm/kvm64.c    | 2 +-
 6 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/exec.c b/exec.c
index 6f381f98e2..82e82fab09 100644
--- a/exec.c
+++ b/exec.c
@@ -899,6 +899,7 @@ Property cpu_common_props[] = {
     DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
                      MemoryRegion *),
 #endif
+    DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 8f145733ce..9fc2696db5 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -374,6 +374,10 @@ struct CPUState {
     bool created;
     bool stop;
     bool stopped;
+
+    /* Should CPU start in powered-off state? */
+    bool start_powered_off;
+
     bool unplug;
     bool crash_occurred;
     bool exit_request;
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 111579554f..ec65c7653f 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -174,8 +174,8 @@ static void arm_cpu_reset(DeviceState *dev)
     env->vfp.xregs[ARM_VFP_MVFR1] = cpu->isar.mvfr1;
     env->vfp.xregs[ARM_VFP_MVFR2] = cpu->isar.mvfr2;
 
-    cpu->power_state = cpu->start_powered_off ? PSCI_OFF : PSCI_ON;
-    s->halted = cpu->start_powered_off;
+    cpu->power_state = s->start_powered_off ? PSCI_OFF : PSCI_ON;
+    s->halted = s->start_powered_off;
 
     if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
         env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
@@ -2182,7 +2182,6 @@ static const ARMCPUInfo arm_cpus[] = {
 };
 
 static Property arm_cpu_properties[] = {
-    DEFINE_PROP_BOOL("start-powered-off", ARMCPU, start_powered_off, false),
     DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0),
     DEFINE_PROP_UINT64("midr", ARMCPU, midr, 0),
     DEFINE_PROP_UINT64("mp-affinity", ARMCPU,
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 9e8ed423ea..a925d26996 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -810,9 +810,6 @@ struct ARMCPU {
      */
     uint32_t psci_version;
 
-    /* Should CPU start in PSCI powered-off state? */
-    bool start_powered_off;
-
     /* Current power state, access guarded by BQL */
     ARMPSCIState power_state;
 
diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c
index 0af46b41c8..1f2b8f8b7a 100644
--- a/target/arm/kvm32.c
+++ b/target/arm/kvm32.c
@@ -218,7 +218,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
 
     /* Determine init features for this CPU */
     memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features));
-    if (cpu->start_powered_off) {
+    if (cs->start_powered_off) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
     if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {
diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
index 1169237905..f8a6d905fb 100644
--- a/target/arm/kvm64.c
+++ b/target/arm/kvm64.c
@@ -775,7 +775,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
 
     /* Determine init features for this CPU */
     memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features));
-    if (cpu->start_powered_off) {
+    if (cs->start_powered_off) {
         cpu->kvm_init_features[0] |= 1 << KVM_ARM_VCPU_POWER_OFF;
     }
     if (kvm_check_extension(cs->kvm_state, KVM_CAP_ARM_PSCI_0_2)) {


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 2/8] target/arm: Move setting of CPU halted state to generic code
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
  2020-08-19 16:42 ` [PATCH v6 1/8] target/arm: Move start-powered-off property to generic CPUState Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-19 16:43 ` [PATCH v6 3/8] ppc/spapr: Use start-powered-off CPUState property Thiago Jung Bauermann
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

This change is in a separate patch because it's not so obvious that it
won't cause a regression.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 hw/core/cpu.c    | 2 +-
 target/arm/cpu.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 594441a150..71bb7859f1 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -258,7 +258,7 @@ static void cpu_common_reset(DeviceState *dev)
     }
 
     cpu->interrupt_request = 0;
-    cpu->halted = 0;
+    cpu->halted = cpu->start_powered_off;
     cpu->mem_io_pc = 0;
     cpu->icount_extra = 0;
     atomic_set(&cpu->icount_decr_ptr->u32, 0);
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index ec65c7653f..b6c65e4df6 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -175,7 +175,6 @@ static void arm_cpu_reset(DeviceState *dev)
     env->vfp.xregs[ARM_VFP_MVFR2] = cpu->isar.mvfr2;
 
     cpu->power_state = s->start_powered_off ? PSCI_OFF : PSCI_ON;
-    s->halted = s->start_powered_off;
 
     if (arm_feature(env, ARM_FEATURE_IWMMXT)) {
         env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 3/8] ppc/spapr: Use start-powered-off CPUState property
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
  2020-08-19 16:42 ` [PATCH v6 1/8] target/arm: Move start-powered-off property to generic CPUState Thiago Jung Bauermann
  2020-08-19 16:43 ` [PATCH v6 2/8] target/arm: Move setting of CPU halted state to generic code Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-19 16:43 ` [PATCH v6 4/8] ppc/e500: " Thiago Jung Bauermann
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

PowerPC sPAPR CPUs start in the halted state, and spapr_reset_vcpu()
attempts to implement this by setting CPUState::halted to 1. But that's too
late for the case of hotplugged CPUs in a machine configure with 2 or more
threads per core.

By then, other parts of QEMU have already caused the vCPU to run in an
unitialized state a couple of times. For example, ppc_cpu_reset() calls
ppc_tlb_invalidate_all(), which ends up calling async_run_on_cpu(). This
kicks the new vCPU while it has CPUState::halted = 0, causing QEMU to issue
a KVM_RUN ioctl on the new vCPU before the guest is able to make the
start-cpu RTAS call to initialize its register state.

This problem doesn't seem to cause visible issues for regular guests, but
on a secure guest running under the Ultravisor it does. The Ultravisor
relies on being able to snoop on the start-cpu RTAS call to map vCPUs to
guests, and this issue causes it to see a stray vCPU that doesn't belong to
any guest.

Fix by setting the start-powered-off CPUState property in
spapr_create_vcpu(), which makes cpu_common_reset() initialize
CPUState::halted to 1 at an earlier moment.

Suggested-by: Eduardo Habkost <ehabkost@redhat.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Greg Kurz <groug@kaod.org>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 hw/ppc/spapr_cpu_core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index c4f47dcc04..2125fdac34 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -36,11 +36,6 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu)
 
     cpu_reset(cs);
 
-    /* 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 */
-    cs->halted = 1;
-
     env->spr[SPR_HIOR] = 0;
 
     lpcr = env->spr[SPR_LPCR];
@@ -274,6 +269,11 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp)
 
     cs = CPU(obj);
     cpu = POWERPC_CPU(obj);
+    /*
+     * 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.
+     */
+    cs->start_powered_off = true;
     cs->cpu_index = cc->core_id + i;
     spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err);
     if (local_err) {


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
                   ` (2 preceding siblings ...)
  2020-08-19 16:43 ` [PATCH v6 3/8] ppc/spapr: Use start-powered-off CPUState property Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-22  8:59   ` Cédric Le Goater
  2020-08-19 16:43 ` [PATCH v6 5/8] mips/cps: " Thiago Jung Bauermann
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
the start-powered-off property which makes cpu_common_reset() initialize it
to 1 in common code.

Also change creation of CPU object from cpu_create() to object_new() and
qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
possible to set a property after the object is realized.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 hw/ppc/e500.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
index ab9884e315..d7b803ef26 100644
--- a/hw/ppc/e500.c
+++ b/hw/ppc/e500.c
@@ -704,9 +704,6 @@ static void ppce500_cpu_reset_sec(void *opaque)
 
     cpu_reset(cs);
 
-    /* Secondary CPU starts in halted state for now. Needs to change when
-       implementing non-kernel boot. */
-    cs->halted = 1;
     cs->exception_index = EXCP_HLT;
 }
 
@@ -865,7 +862,7 @@ void ppce500_init(MachineState *machine)
         CPUState *cs;
         qemu_irq *input;
 
-        cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
+        cpu = POWERPC_CPU(object_new(machine->cpu_type));
         env = &cpu->env;
         cs = CPU(cpu);
 
@@ -897,7 +894,16 @@ void ppce500_init(MachineState *machine)
         } else {
             /* Secondary CPUs */
             qemu_register_reset(ppce500_cpu_reset_sec, cpu);
+
+            /*
+             * Secondary CPU starts in halted state for now. Needs to change
+             * when implementing non-kernel boot.
+             */
+            object_property_set_bool(OBJECT(cs), "start-powered-off", true,
+                                     &error_fatal);
         }
+
+        qdev_realize_and_unref(DEVICE(cs), NULL, &error_fatal);
     }
 
     env = firstenv;


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 5/8] mips/cps: Use start-powered-off CPUState property
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
                   ` (3 preceding siblings ...)
  2020-08-19 16:43 ` [PATCH v6 4/8] ppc/e500: " Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-19 16:43 ` [PATCH v6 6/8] sparc/sun4m: Remove main_cpu_reset() Thiago Jung Bauermann
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

Instead of setting CPUState::halted to 1 in main_cpu_reset(), use the
start-powered-off property which makes cpu_common_reset() initialize it
to 1 in common code.

Also change creation of CPU object from cpu_create() to object_new() and
qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
possible to set a property after the object is realized.

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 hw/mips/cps.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/hw/mips/cps.c b/hw/mips/cps.c
index 615e1a1ad2..4a98cf2287 100644
--- a/hw/mips/cps.c
+++ b/hw/mips/cps.c
@@ -52,9 +52,6 @@ static void main_cpu_reset(void *opaque)
     CPUState *cs = CPU(cpu);
 
     cpu_reset(cs);
-
-    /* All VPs are halted on reset. Leave powering up to CPC. */
-    cs->halted = 1;
 }
 
 static bool cpu_mips_itu_supported(CPUMIPSState *env)
@@ -76,7 +73,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
     bool saar_present = false;
 
     for (i = 0; i < s->num_vp; i++) {
-        cpu = MIPS_CPU(cpu_create(s->cpu_type));
+        cpu = MIPS_CPU(object_new(s->cpu_type));
 
         /* Init internal devices */
         cpu_mips_irq_init_cpu(cpu);
@@ -89,7 +86,16 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
             env->itc_tag = mips_itu_get_tag_region(&s->itu);
             env->itu = &s->itu;
         }
+        /* All VPs are halted on reset. Leave powering up to CPC. */
+        if (!object_property_set_bool(OBJECT(cpu), "start-powered-off", true,
+                                      errp)) {
+            return;
+        }
         qemu_register_reset(main_cpu_reset, cpu);
+
+        if (!qdev_realize_and_unref(DEVICE(cpu), NULL, errp)) {
+            return;
+        }
     }
 
     cpu = MIPS_CPU(first_cpu);


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 6/8] sparc/sun4m: Remove main_cpu_reset()
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
                   ` (4 preceding siblings ...)
  2020-08-19 16:43 ` [PATCH v6 5/8] mips/cps: " Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-26  3:09   ` Thiago Jung Bauermann
  2020-08-19 16:43 ` [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property Thiago Jung Bauermann
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

We rely on cpu_common_reset() to set cs->halted to 0, so main_cpu_reset()
is pointless.

Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 hw/sparc/sun4m.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index cf7dfa4af5..22c51dac8a 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level)
 {
 }
 
-static void main_cpu_reset(void *opaque)
-{
-    SPARCCPU *cpu = opaque;
-    CPUState *cs = CPU(cpu);
-
-    cpu_reset(cs);
-    cs->halted = 0;
-}
-
 static void secondary_cpu_reset(void *opaque)
 {
     SPARCCPU *cpu = opaque;
@@ -827,9 +818,7 @@ static void cpu_devinit(const char *cpu_type, unsigned int id,
     env = &cpu->env;
 
     cpu_sparc_set_id(env, id);
-    if (id == 0) {
-        qemu_register_reset(main_cpu_reset, cpu);
-    } else {
+    if (id != 0) {
         qemu_register_reset(secondary_cpu_reset, cpu);
         cs = CPU(cpu);
         cs->halted = 1;


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
                   ` (5 preceding siblings ...)
  2020-08-19 16:43 ` [PATCH v6 6/8] sparc/sun4m: Remove main_cpu_reset() Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-19 17:03   ` Philippe Mathieu-Daudé
  2020-08-19 16:43 ` [PATCH v6 8/8] target/s390x: " Thiago Jung Bauermann
  2020-08-20  1:42 ` [PATCH v6 0/8] Generalize start-powered-off property from ARM David Gibson
  8 siblings, 1 reply; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

Instead of setting CPUState::halted to 1 in secondary_cpu_reset(), use the
start-powered-off property which makes cpu_common_reset() initialize it
to 1 in common code.

This makes secondary_cpu_reset() unnecessary, so remove it.

Also remove setting of cs->halted from cpu_devinit(), which seems out of
place when compared to similar code in other architectures (e.g.,
ppce500_init() in hw/ppc/e500.c).

Finally, change creation of CPU object from cpu_create() to object_new()
and qdev_realize_and_unref() because cpu_create() realizes the CPU and it's
not possible to set a property after the object is realized.

Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 hw/sparc/sun4m.c | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index 22c51dac8a..23991ccd47 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level)
 {
 }
 
-static void secondary_cpu_reset(void *opaque)
-{
-    SPARCCPU *cpu = opaque;
-    CPUState *cs = CPU(cpu);
-
-    cpu_reset(cs);
-    cs->halted = 1;
-}
-
 static void cpu_halt_signal(void *opaque, int irq, int level)
 {
     if (level && current_cpu) {
@@ -810,19 +801,16 @@ static const TypeInfo ram_info = {
 static void cpu_devinit(const char *cpu_type, unsigned int id,
                         uint64_t prom_addr, qemu_irq **cpu_irqs)
 {
-    CPUState *cs;
     SPARCCPU *cpu;
     CPUSPARCState *env;
 
-    cpu = SPARC_CPU(cpu_create(cpu_type));
+    cpu = SPARC_CPU(object_new(cpu_type));
     env = &cpu->env;
 
     cpu_sparc_set_id(env, id);
-    if (id != 0) {
-        qemu_register_reset(secondary_cpu_reset, cpu);
-        cs = CPU(cpu);
-        cs->halted = 1;
-    }
+    object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0,
+                             &error_fatal);
+    qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
     *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
     env->prom_addr = prom_addr;
 }


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v6 8/8] target/s390x: Use start-powered-off CPUState property
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
                   ` (6 preceding siblings ...)
  2020-08-19 16:43 ` [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property Thiago Jung Bauermann
@ 2020-08-19 16:43 ` Thiago Jung Bauermann
  2020-08-20  1:42 ` [PATCH v6 0/8] Generalize start-powered-off property from ARM David Gibson
  8 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 16:43 UTC (permalink / raw)
  To: qemu-ppc
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, Thiago Jung Bauermann,
	Igor Mammedov, Aurelien Jarno

Instead of setting CPUState::halted to 1 in s390_cpu_initfn(), use the
start-powered-off property which makes cpu_common_reset() initialize it
to 1 in common code.

Note that this changes behavior by setting cs->halted to 1 on reset, which
didn't happen before.

Acked-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
---
 target/s390x/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 08eb674d22..73d7d6007e 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -291,7 +291,7 @@ static void s390_cpu_initfn(Object *obj)
     S390CPU *cpu = S390_CPU(obj);
 
     cpu_set_cpustate_pointers(cpu);
-    cs->halted = 1;
+    cs->start_powered_off = true;
     cs->exception_index = EXCP_HLT;
 #if !defined(CONFIG_USER_ONLY)
     object_property_add(obj, "crash-information", "GuestPanicInformation",


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property
  2020-08-19 16:43 ` [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property Thiago Jung Bauermann
@ 2020-08-19 17:03   ` Philippe Mathieu-Daudé
  2020-08-19 23:54     ` Thiago Jung Bauermann
  0 siblings, 1 reply; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-08-19 17:03 UTC (permalink / raw)
  To: Thiago Jung Bauermann, qemu-ppc
  Cc: Peter Maydell, Aleksandar Rikalo, Eduardo Habkost,
	Aleksandar Markovic, Cornelia Huck, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Greg Kurz, qemu-s390x, qemu-arm, Artyom Tarasenko,
	Igor Mammedov, Thomas Huth, Paolo Bonzini, David Hildenbrand,
	Richard Henderson, Alex Bennée, Aurelien Jarno,
	David Gibson

On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
> Instead of setting CPUState::halted to 1 in secondary_cpu_reset(), use the
> start-powered-off property which makes cpu_common_reset() initialize it
> to 1 in common code.
> 
> This makes secondary_cpu_reset() unnecessary, so remove it.
> 
> Also remove setting of cs->halted from cpu_devinit(), which seems out of
> place when compared to similar code in other architectures (e.g.,
> ppce500_init() in hw/ppc/e500.c).
> 
> Finally, change creation of CPU object from cpu_create() to object_new()
> and qdev_realize_and_unref() because cpu_create() realizes the CPU and it's
> not possible to set a property after the object is realized.
> 
> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>  hw/sparc/sun4m.c | 20 ++++----------------
>  1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index 22c51dac8a..23991ccd47 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level)
>  {
>  }
>  
> -static void secondary_cpu_reset(void *opaque)
> -{
> -    SPARCCPU *cpu = opaque;
> -    CPUState *cs = CPU(cpu);
> -
> -    cpu_reset(cs);
> -    cs->halted = 1;
> -}
> -
>  static void cpu_halt_signal(void *opaque, int irq, int level)
>  {
>      if (level && current_cpu) {
> @@ -810,19 +801,16 @@ static const TypeInfo ram_info = {
>  static void cpu_devinit(const char *cpu_type, unsigned int id,
>                          uint64_t prom_addr, qemu_irq **cpu_irqs)
>  {
> -    CPUState *cs;
>      SPARCCPU *cpu;
>      CPUSPARCState *env;
>  
> -    cpu = SPARC_CPU(cpu_create(cpu_type));
> +    cpu = SPARC_CPU(object_new(cpu_type));
>      env = &cpu->env;
>  
>      cpu_sparc_set_id(env, id);
> -    if (id != 0) {
> -        qemu_register_reset(secondary_cpu_reset, cpu);
> -        cs = CPU(cpu);
> -        cs->halted = 1;
> -    }
> +    object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0,
> +                             &error_fatal);
> +    qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
>      *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
>      env->prom_addr = prom_addr;
>  }
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property
  2020-08-19 17:03   ` Philippe Mathieu-Daudé
@ 2020-08-19 23:54     ` Thiago Jung Bauermann
  0 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-19 23:54 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth, David Gibson,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, qemu-ppc, Igor Mammedov,
	Aurelien Jarno


Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
>> Instead of setting CPUState::halted to 1 in secondary_cpu_reset(), use the
>> start-powered-off property which makes cpu_common_reset() initialize it
>> to 1 in common code.
>> 
>> This makes secondary_cpu_reset() unnecessary, so remove it.
>> 
>> Also remove setting of cs->halted from cpu_devinit(), which seems out of
>> place when compared to similar code in other architectures (e.g.,
>> ppce500_init() in hw/ppc/e500.c).
>> 
>> Finally, change creation of CPU object from cpu_create() to object_new()
>> and qdev_realize_and_unref() because cpu_create() realizes the CPU and it's
>> not possible to set a property after the object is realized.
>> 
>> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Thanks!

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 0/8] Generalize start-powered-off property from ARM
  2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
                   ` (7 preceding siblings ...)
  2020-08-19 16:43 ` [PATCH v6 8/8] target/s390x: " Thiago Jung Bauermann
@ 2020-08-20  1:42 ` David Gibson
  2020-08-20  2:04   ` Thiago Jung Bauermann
  8 siblings, 1 reply; 20+ messages in thread
From: David Gibson @ 2020-08-20  1:42 UTC (permalink / raw)
  To: Thiago Jung Bauermann
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, qemu-ppc, Igor Mammedov,
	Aurelien Jarno

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

On Wed, Aug 19, 2020 at 01:42:58PM -0300, Thiago Jung Bauermann wrote:
> This version has one small fix in patch 7, and adds Philippe's Reviewed-bys.
> 
> Applies cleanly on dgibson/ppc-for-5.2.
> 
> Original cover letter below, followed by changelog:
> 
> 
> The ARM code has a start-powered-off property in ARMCPU, which is a
> subclass of CPUState. This property causes arm_cpu_reset() to set
> CPUState::halted to 1, signalling that the CPU should start in a halted
> state. Other architectures also have code which aim to achieve the same
> effect, but without using a property.
> 
> The ppc/spapr version has a bug where QEMU does a KVM_RUN on the vcpu
> before cs->halted is set to 1, causing the vcpu to run while it's still in
> an unitialized state (more details in patch 3).
> 
> Peter Maydell mentioned the ARM start-powered-off property and
> Eduardo Habkost suggested making it generic, so this patch series does
> that, for all cases which I was able to find via grep in the code.
> 
> The only problem is that I was only able to test these changes on a ppc64le
> pseries KVM guest, so except for patches 2 and 3, all others are only
> build-tested. Also, my grasp of QOM lifecycle is basically non-existant so
> please be aware of that when reviewing this series.
> 
> The last patch may be wrong, as pointed out by Eduardo, so I marked it as
> RFC. It may make sense to drop it.

Applied to ppc-for-5.2.

> 
> Changes since v5:
> 
> Patch "ppc/e500: Use start-powered-off CPUState property"
> Patch "mips/cps: Use start-powered-off CPUState property"
> Patch "sparc/sun4m: Remove main_cpu_reset()"
> Patch "target/s390x: Use start-powered-off CPUState property"
> - Added Philippe's Reviewed-by.
> 
> Patch "sparc/sun4m: Use start-powered-off CPUState property"
> - Move call to qdev_realize_and_unref() right after object_property_set_bool(),
>   as suggested by Philippe.
> 
> Changes since v4:
> 
> Patch "ppc/e500: Use start-powered-off CPUState property"
> Patch "sparc/sun4m: Use start-powered-off CPUState property"
> - Use qdev_realize_and_unref() instead of qdev_realize(), as suggested
>   by Igor.
> - Pass &error_fatal to qdev_realize_and_unref() instead of manually
>   reporting the error and exiting QEMU, as suggested by Philippe.
> - Changed object_property_set_bool() to use &error_fatal instead of
>   &error_abort.
> 
> Patch "mips/cps: Use start-powered-off CPUState property"
> - Use qdev_realize_and_unref() instead of qdev_realize(), as suggested
>   by Igor.
> - Use existing errp argument to propagate error back to the caller, as
>   suggested by Philippe.
> - Changed object_property_set_bool() to use existing errp argument to
>   propagate error back to the caller instead of using &error_abort.
> 
> Changes since v3:
> 
> General:
> - Added David's, Greg's and Cornelia's Reviewed-by and Acked-by to some
>   of the patches.
> - Rebased on top of dgibson/ppc-for-5.2.
> 
> Patch "ppc/e500: Use start-powered-off CPUState property"
> Patch "mips/cps: Use start-powered-off CPUState property"
> Patch "sparc/sun4m: Use start-powered-off CPUState property"
> - Initialize CPU object with object_new() and qdev_realize() instead
>   of cpu_create().
> - Removed Reviewed-by's and Acked-by's from these patches because of
>   these changes.
> 
> Changes since v2:
> 
> General:
> - Added Philippe's Reviewed-by to some of the patches.
> 
> Patch "ppc/spapr: Use start-powered-off CPUState property"
> - Set the CPUState::start_powered_off variable directly rather than using
>   object_property_set_bool(). Suggested by Philippe.
> 
> Patch "sparc/sun4m: Remove main_cpu_reset()"
> - New patch. Suggested by Philippe.
> 
> Patch "sparc/sun4m: Use start-powered-off CPUState property"
> - Remove secondary_cpu_reset(). Suggested by Philippe.
> - Remove setting of `cs->halted = 1` from cpu_devinit(). Suggested by Philippe.
> 
> Patch "Don't set CPUState::halted in cpu_devinit()"
> - Squashed into previous patch. Suggested by Philippe.
> 
> Patch "sparc/sun4m: Use one cpu_reset() function for main and secondary CPUs"
> - Dropped.
> 
> Patch "target/s390x: Use start-powered-off CPUState property"
> - Set the CPUState::start_powered_off variable directly rather than using
>   object_property_set_bool(). Suggested by Philippe.
> - Mention in the commit message Eduardo's observation that before this
>   patch, the code didn't set cs->halted on reset.
> 
> Thiago Jung Bauermann (8):
>   target/arm: Move start-powered-off property to generic CPUState
>   target/arm: Move setting of CPU halted state to generic code
>   ppc/spapr: Use start-powered-off CPUState property
>   ppc/e500: Use start-powered-off CPUState property
>   mips/cps: Use start-powered-off CPUState property
>   sparc/sun4m: Remove main_cpu_reset()
>   sparc/sun4m: Use start-powered-off CPUState property
>   target/s390x: Use start-powered-off CPUState property
> 
>  exec.c                  |  1 +
>  hw/core/cpu.c           |  2 +-
>  hw/mips/cps.c           | 14 ++++++++++----
>  hw/ppc/e500.c           | 14 ++++++++++----
>  hw/ppc/spapr_cpu_core.c | 10 +++++-----
>  hw/sparc/sun4m.c        | 31 ++++---------------------------
>  include/hw/core/cpu.h   |  4 ++++
>  target/arm/cpu.c        |  4 +---
>  target/arm/cpu.h        |  3 ---
>  target/arm/kvm32.c      |  2 +-
>  target/arm/kvm64.c      |  2 +-
>  target/s390x/cpu.c      |  2 +-
>  12 files changed, 39 insertions(+), 50 deletions(-)
> 

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 0/8] Generalize start-powered-off property from ARM
  2020-08-20  1:42 ` [PATCH v6 0/8] Generalize start-powered-off property from ARM David Gibson
@ 2020-08-20  2:04   ` Thiago Jung Bauermann
  0 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-20  2:04 UTC (permalink / raw)
  To: David Gibson
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, Thomas Huth,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Aleksandar Rikalo, Eduardo Habkost, Greg Kurz,
	qemu-s390x, qemu-arm, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, qemu-ppc, Igor Mammedov,
	Aurelien Jarno


David Gibson <david@gibson.dropbear.id.au> writes:

> On Wed, Aug 19, 2020 at 01:42:58PM -0300, Thiago Jung Bauermann wrote:
>> This version has one small fix in patch 7, and adds Philippe's Reviewed-bys.
>> 
>> Applies cleanly on dgibson/ppc-for-5.2.
>> 
>> Original cover letter below, followed by changelog:
>> 
>> 
>> The ARM code has a start-powered-off property in ARMCPU, which is a
>> subclass of CPUState. This property causes arm_cpu_reset() to set
>> CPUState::halted to 1, signalling that the CPU should start in a halted
>> state. Other architectures also have code which aim to achieve the same
>> effect, but without using a property.
>> 
>> The ppc/spapr version has a bug where QEMU does a KVM_RUN on the vcpu
>> before cs->halted is set to 1, causing the vcpu to run while it's still in
>> an unitialized state (more details in patch 3).
>> 
>> Peter Maydell mentioned the ARM start-powered-off property and
>> Eduardo Habkost suggested making it generic, so this patch series does
>> that, for all cases which I was able to find via grep in the code.
>> 
>> The only problem is that I was only able to test these changes on a ppc64le
>> pseries KVM guest, so except for patches 2 and 3, all others are only
>> build-tested. Also, my grasp of QOM lifecycle is basically non-existant so
>> please be aware of that when reviewing this series.
>> 
>> The last patch may be wrong, as pointed out by Eduardo, so I marked it as
>> RFC. It may make sense to drop it.
>
> Applied to ppc-for-5.2.

Great news. Thanks!

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-19 16:43 ` [PATCH v6 4/8] ppc/e500: " Thiago Jung Bauermann
@ 2020-08-22  8:59   ` Cédric Le Goater
  2020-08-22 14:35     ` Philippe Mathieu-Daudé
  2020-08-23  7:14     ` David Gibson
  0 siblings, 2 replies; 20+ messages in thread
From: Cédric Le Goater @ 2020-08-22  8:59 UTC (permalink / raw)
  To: Thiago Jung Bauermann, qemu-ppc
  Cc: Peter Maydell, Thomas Huth, Eduardo Habkost, David Hildenbrand,
	qemu-s390x, Alex Bennée, Aleksandar Rikalo, Cornelia Huck,
	Mark Cave-Ayland, qemu-devel, Jiaxun Yang, Greg Kurz,
	Aleksandar Markovic, qemu-arm, Aurelien Jarno, Igor Mammedov,
	Paolo Bonzini, Richard Henderson, Philippe Mathieu-Daudé,
	Artyom Tarasenko, David Gibson

Hello,

On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
> Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
> the start-powered-off property which makes cpu_common_reset() initialize it
> to 1 in common code.
> 
> Also change creation of CPU object from cpu_create() to object_new() and
> qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
> possible to set a property after the object is realized.
> 
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>


This is breaking make check : 

    tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
    ERROR boot-serial-test - too few tests run (expected 7, got 0)
    make: *** [/home/legoater/work/qemu/qemu-powernv-5.2.git/tests/Makefile.include:650: check-qtest-ppc64] Error 1
    make: *** Waiting for unfinished jobs....
    
    
    gdb --args build/ppc64-softmmu/qemu-system-ppc64  -display none   -M ppce500
    ...
    Thread 1 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
    0x000055555596ebf2 in ppce500_init (machine=0x5555567aa6e0)
        at /home/legoater/work/qemu/qemu-powernv-5.2.git/hw/ppc/e500.c:880
    880	        irqs[i].irq[OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
 
    
    AFAIUI, 'input is not initialized since the CPU is not yet realized.

    C.

> ---
>  hw/ppc/e500.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
> index ab9884e315..d7b803ef26 100644
> --- a/hw/ppc/e500.c
> +++ b/hw/ppc/e500.c
> @@ -704,9 +704,6 @@ static void ppce500_cpu_reset_sec(void *opaque)
> 
>      cpu_reset(cs);
> 
> -    /* Secondary CPU starts in halted state for now. Needs to change when
> -       implementing non-kernel boot. */
> -    cs->halted = 1;
>      cs->exception_index = EXCP_HLT;
>  }
> 
> @@ -865,7 +862,7 @@ void ppce500_init(MachineState *machine)
>          CPUState *cs;
>          qemu_irq *input;
> 
> -        cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
> +        cpu = POWERPC_CPU(object_new(machine->cpu_type));
>          env = &cpu->env;
>          cs = CPU(cpu);
> 
> @@ -897,7 +894,16 @@ void ppce500_init(MachineState *machine)
>          } else {
>              /* Secondary CPUs */
>              qemu_register_reset(ppce500_cpu_reset_sec, cpu);
> +
> +            /*
> +             * Secondary CPU starts in halted state for now. Needs to change
> +             * when implementing non-kernel boot.
> +             */
> +            object_property_set_bool(OBJECT(cs), "start-powered-off", true,
> +                                     &error_fatal);
>          }
> +
> +        qdev_realize_and_unref(DEVICE(cs), NULL, &error_fatal);
>      }
> 
>      env = firstenv;
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-22  8:59   ` Cédric Le Goater
@ 2020-08-22 14:35     ` Philippe Mathieu-Daudé
  2020-08-24 23:34       ` Thiago Jung Bauermann
  2020-08-26  5:48       ` Thiago Jung Bauermann
  2020-08-23  7:14     ` David Gibson
  1 sibling, 2 replies; 20+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-08-22 14:35 UTC (permalink / raw)
  To: Cédric Le Goater, Thiago Jung Bauermann, qemu-ppc
  Cc: Peter Maydell, Thomas Huth, Eduardo Habkost, David Hildenbrand,
	qemu-s390x, Alex Bennée, Cornelia Huck, Mark Cave-Ayland,
	qemu-devel, Jiaxun Yang, Greg Kurz, Aleksandar Markovic,
	qemu-arm, Aurelien Jarno, Igor Mammedov, Paolo Bonzini,
	Richard Henderson, Aleksandar Rikalo, Artyom Tarasenko,
	David Gibson

On 8/22/20 10:59 AM, Cédric Le Goater wrote:
> Hello,
> 
> On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
>> Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
>> the start-powered-off property which makes cpu_common_reset() initialize it
>> to 1 in common code.
>>
>> Also change creation of CPU object from cpu_create() to object_new() and
>> qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
>> possible to set a property after the object is realized.
>>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
> 
> 
> This is breaking make check : 
> 
>     tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
>     ERROR boot-serial-test - too few tests run (expected 7, got 0)
>     make: *** [/home/legoater/work/qemu/qemu-powernv-5.2.git/tests/Makefile.include:650: check-qtest-ppc64] Error 1
>     make: *** Waiting for unfinished jobs....
>     
>     
>     gdb --args build/ppc64-softmmu/qemu-system-ppc64  -display none   -M ppce500
>     ...
>     Thread 1 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
>     0x000055555596ebf2 in ppce500_init (machine=0x5555567aa6e0)
>         at /home/legoater/work/qemu/qemu-powernv-5.2.git/hw/ppc/e500.c:880
>     880	        irqs[i].irq[OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
>  
>     
>     AFAIUI, 'input is not initialized since the CPU is not yet realized.

Thiago, see ad938fc1d53 ("hw/arm/palm.c: Encapsulate misc GPIO handling
in a device") and eventually f8a865d36dc ("hw/arm/allwinner-a10:
Simplify by passing IRQs with qdev_pass_gpios") to get an idea how you
can fix that.

> 
>     C.
> 
>> ---
>>  hw/ppc/e500.c | 14 ++++++++++----
>>  1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/ppc/e500.c b/hw/ppc/e500.c
>> index ab9884e315..d7b803ef26 100644
>> --- a/hw/ppc/e500.c
>> +++ b/hw/ppc/e500.c
>> @@ -704,9 +704,6 @@ static void ppce500_cpu_reset_sec(void *opaque)
>>
>>      cpu_reset(cs);
>>
>> -    /* Secondary CPU starts in halted state for now. Needs to change when
>> -       implementing non-kernel boot. */
>> -    cs->halted = 1;
>>      cs->exception_index = EXCP_HLT;
>>  }
>>
>> @@ -865,7 +862,7 @@ void ppce500_init(MachineState *machine)
>>          CPUState *cs;
>>          qemu_irq *input;
>>
>> -        cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
>> +        cpu = POWERPC_CPU(object_new(machine->cpu_type));
>>          env = &cpu->env;
>>          cs = CPU(cpu);
>>
>> @@ -897,7 +894,16 @@ void ppce500_init(MachineState *machine)
>>          } else {
>>              /* Secondary CPUs */
>>              qemu_register_reset(ppce500_cpu_reset_sec, cpu);
>> +
>> +            /*
>> +             * Secondary CPU starts in halted state for now. Needs to change
>> +             * when implementing non-kernel boot.
>> +             */
>> +            object_property_set_bool(OBJECT(cs), "start-powered-off", true,
>> +                                     &error_fatal);
>>          }
>> +
>> +        qdev_realize_and_unref(DEVICE(cs), NULL, &error_fatal);
>>      }
>>
>>      env = firstenv;
>>
> 



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-22  8:59   ` Cédric Le Goater
  2020-08-22 14:35     ` Philippe Mathieu-Daudé
@ 2020-08-23  7:14     ` David Gibson
  2020-08-24 23:33       ` Thiago Jung Bauermann
  1 sibling, 1 reply; 20+ messages in thread
From: David Gibson @ 2020-08-23  7:14 UTC (permalink / raw)
  To: Cédric Le Goater
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland,
	Aleksandar Rikalo, Jiaxun Yang, Aleksandar Markovic,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Thomas Huth, Eduardo Habkost, Greg Kurz,
	qemu-devel, qemu-s390x, qemu-arm, Paolo Bonzini,
	Alex Bennée, Richard Henderson, Cornelia Huck, qemu-ppc,
	Thiago Jung Bauermann, Igor Mammedov, Aurelien Jarno

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

On Sat, Aug 22, 2020 at 10:59:56AM +0200, Cédric Le Goater wrote:
> Hello,
> 
> On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
> > Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
> > the start-powered-off property which makes cpu_common_reset() initialize it
> > to 1 in common code.
> > 
> > Also change creation of CPU object from cpu_create() to object_new() and
> > qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
> > possible to set a property after the object is realized.
> > 
> > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> > Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
> 
> 
> This is breaking make check : 
> 
>     tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
>     ERROR boot-serial-test - too few tests run (expected 7, got 0)
>     make: *** [/home/legoater/work/qemu/qemu-powernv-5.2.git/tests/Makefile.include:650: check-qtest-ppc64] Error 1
>     make: *** Waiting for unfinished jobs....
>     
>     
>     gdb --args build/ppc64-softmmu/qemu-system-ppc64  -display none   -M ppce500
>     ...
>     Thread 1 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
>     0x000055555596ebf2 in ppce500_init (machine=0x5555567aa6e0)
>         at /home/legoater/work/qemu/qemu-powernv-5.2.git/hw/ppc/e500.c:880
>     880	        irqs[i].irq[OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
>  
>     
>     AFAIUI, 'input is not initialized since the CPU is not yet
>     realized.

Sigh.  For future reference, Thiago, running an all-targets make check
is pretty much a minimum bar to test before posting.

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-23  7:14     ` David Gibson
@ 2020-08-24 23:33       ` Thiago Jung Bauermann
  0 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-24 23:33 UTC (permalink / raw)
  To: David Gibson
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland,
	Aleksandar Rikalo, Jiaxun Yang, Aleksandar Markovic,
	Philippe Mathieu-Daudé,
	Artyom Tarasenko, Thomas Huth, Eduardo Habkost, Greg Kurz,
	qemu-devel, qemu-s390x, qemu-arm, Cédric Le Goater,
	Paolo Bonzini, Alex Bennée, Richard Henderson,
	Cornelia Huck, qemu-ppc, Igor Mammedov, Aurelien Jarno


David Gibson <david@gibson.dropbear.id.au> writes:

> On Sat, Aug 22, 2020 at 10:59:56AM +0200, Cédric Le Goater wrote:
>> Hello,
>> 
>> On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
>> > Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
>> > the start-powered-off property which makes cpu_common_reset() initialize it
>> > to 1 in common code.
>> > 
>> > Also change creation of CPU object from cpu_create() to object_new() and
>> > qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
>> > possible to set a property after the object is realized.
>> > 
>> > Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> > Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
>> 
>> 
>> This is breaking make check : 
>> 
>>     tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
>>     ERROR boot-serial-test - too few tests run (expected 7, got 0)
>>     make: *** [/home/legoater/work/qemu/qemu-powernv-5.2.git/tests/Makefile.include:650: check-qtest-ppc64] Error 1
>>     make: *** Waiting for unfinished jobs....
>>     
>>     
>>     gdb --args build/ppc64-softmmu/qemu-system-ppc64  -display none   -M ppce500
>>     ...
>>     Thread 1 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
>>     0x000055555596ebf2 in ppce500_init (machine=0x5555567aa6e0)
>>         at /home/legoater/work/qemu/qemu-powernv-5.2.git/hw/ppc/e500.c:880
>>     880	        irqs[i].irq[OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
>>  
>>     
>>     AFAIUI, 'input is not initialized since the CPU is not yet
>>     realized.
>
> Sigh.  For future reference, Thiago, running an all-targets make check
> is pretty much a minimum bar to test before posting.

Sorry for the breakage. I'm working on it.

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-22 14:35     ` Philippe Mathieu-Daudé
@ 2020-08-24 23:34       ` Thiago Jung Bauermann
  2020-08-26  5:48       ` Thiago Jung Bauermann
  1 sibling, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-24 23:34 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, David Hildenbrand, Mark Cave-Ayland, qemu-devel,
	Jiaxun Yang, Aleksandar Markovic, David Gibson, Artyom Tarasenko,
	Thomas Huth, Eduardo Habkost, Greg Kurz, qemu-s390x, qemu-arm,
	Cédric Le Goater, Paolo Bonzini, Alex Bennée,
	Richard Henderson, Cornelia Huck, qemu-ppc, Igor Mammedov,
	Aleksandar Rikalo, Aurelien Jarno


Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 8/22/20 10:59 AM, Cédric Le Goater wrote:
>> Hello,
>> 
>> On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
>>> Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
>>> the start-powered-off property which makes cpu_common_reset() initialize it
>>> to 1 in common code.
>>>
>>> Also change creation of CPU object from cpu_create() to object_new() and
>>> qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
>>> possible to set a property after the object is realized.
>>>
>>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
>> 
>> 
>> This is breaking make check : 
>> 
>>     tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
>>     ERROR boot-serial-test - too few tests run (expected 7, got 0)
>>     make: *** [/home/legoater/work/qemu/qemu-powernv-5.2.git/tests/Makefile.include:650: check-qtest-ppc64] Error 1
>>     make: *** Waiting for unfinished jobs....
>>     
>>     
>>     gdb --args build/ppc64-softmmu/qemu-system-ppc64  -display none   -M ppce500
>>     ...
>>     Thread 1 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
>>     0x000055555596ebf2 in ppce500_init (machine=0x5555567aa6e0)
>>         at /home/legoater/work/qemu/qemu-powernv-5.2.git/hw/ppc/e500.c:880
>>     880	        irqs[i].irq[OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
>>  
>>     
>>     AFAIUI, 'input is not initialized since the CPU is not yet realized.
>
> Thiago, see ad938fc1d53 ("hw/arm/palm.c: Encapsulate misc GPIO handling
> in a device") and eventually f8a865d36dc ("hw/arm/allwinner-a10:
> Simplify by passing IRQs with qdev_pass_gpios") to get an idea how you
> can fix that.

Thanks for the references, those are very useful.

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 6/8] sparc/sun4m: Remove main_cpu_reset()
  2020-08-19 16:43 ` [PATCH v6 6/8] sparc/sun4m: Remove main_cpu_reset() Thiago Jung Bauermann
@ 2020-08-26  3:09   ` Thiago Jung Bauermann
  0 siblings, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-26  3:09 UTC (permalink / raw)
  Cc: Peter Maydell, David Hildenbrand, Aleksandar Rikalo,
	Aleksandar Markovic, David Gibson, Philippe Mathieu-Daudé,
	Artyom Tarasenko, Thomas Huth, Eduardo Habkost, Greg Kurz,
	qemu-devel, qemu-s390x, qemu-arm, Paolo Bonzini,
	Alex Bennée, Richard Henderson, Cornelia Huck, qemu-ppc,
	Igor Mammedov, Aurelien Jarno


Thiago Jung Bauermann <bauerman@linux.ibm.com> writes:

> We rely on cpu_common_reset() to set cs->halted to 0, so main_cpu_reset()
> is pointless.
>
> Suggested-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
> ---
>  hw/sparc/sun4m.c | 13 +------------
>  1 file changed, 1 insertion(+), 12 deletions(-)
>
> diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
> index cf7dfa4af5..22c51dac8a 100644
> --- a/hw/sparc/sun4m.c
> +++ b/hw/sparc/sun4m.c
> @@ -218,15 +218,6 @@ static void dummy_cpu_set_irq(void *opaque, int irq, int level)
>  {
>  }
>  
> -static void main_cpu_reset(void *opaque)
> -{
> -    SPARCCPU *cpu = opaque;
> -    CPUState *cs = CPU(cpu);
> -
> -    cpu_reset(cs);
> -    cs->halted = 0;
> -}
> -
>  static void secondary_cpu_reset(void *opaque)
>  {
>      SPARCCPU *cpu = opaque;
> @@ -827,9 +818,7 @@ static void cpu_devinit(const char *cpu_type, unsigned int id,
>      env = &cpu->env;
>  
>      cpu_sparc_set_id(env, id);
> -    if (id == 0) {
> -        qemu_register_reset(main_cpu_reset, cpu);
> -    } else {
> +    if (id != 0) {
>          qemu_register_reset(secondary_cpu_reset, cpu);
>          cs = CPU(cpu);
>          cs->halted = 1;

Surprisingly, this patch also causes a make check failure:

$ make && make check-qtest
  GEN     docs/index.html
  CC      qga/main.o
  CC      qemu-nbd.o
  CC      qemu-storage-daemon.o
  CC      monitor/qmp-cmds-control.o
  CC      qemu-img.o
  CC      qemu-io.o
  CC      sparc-softmmu/hw/sparc/sun4m.o
  CC      sparc-softmmu/softmmu/vl.o
  LINK    qemu-ga
  LINK    qemu-nbd
  LINK    qemu-storage-daemon
  LINK    qemu-img
  LINK    sparc-softmmu/qemu-system-sparc
  LINK    qemu-io
  TEST    check-qtest-sparc: tests/qtest/prom-env-test
Broken pipe
/home/bauermann/trabalho/src/qemu/tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
ERROR prom-env-test - too few tests run (expected 3, got 0)
make: *** [/home/bauermann/trabalho/src/qemu/tests/Makefile.include:650: check-qtest-sparc] Fehler 1

Here's what I got from the core file:

$ gdb sparc-softmmu/qemu-system-sparc core.645493
Reading symbols from sparc-softmmu/qemu-system-sparc...
[New LWP 645497]
[New LWP 645496]
[New LWP 645493]
[New LWP 645495]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
Core was generated by `sparc-softmmu/qemu-system-sparc -qtest unix:/tmp/qtest-645490.sock -qtest-log /'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0000000000000000 in ?? ()
[Current thread is 1 (Thread 0x7f713ce60700 (LWP 645497))]
(gdb) bt
#0  0x0000000000000000 in  ()
#1  0x0000557b3d6155c5 in helper_compute_psr (env=env@entry=0x557b3f444030) at /home/bauermann/trabalho/src/qemu/target/sparc/cc_helper.c:459
#2  0x0000557b3d6156e9 in cpu_get_psr (env=env@entry=0x557b3f444030) at /home/bauermann/trabalho/src/qemu/target/sparc/win_helper.c:56
#3  0x0000557b3d61779c in sparc_cpu_do_interrupt (cs=0x557b3f43b7f0) at /home/bauermann/trabalho/src/qemu/target/sparc/int32_helper.c:76
#4  0x0000557b3d5e29a6 in cpu_handle_exception (ret=<synthetic pointer>, cpu=0x557b3f43b7f0) at /home/bauermann/trabalho/src/qemu/accel/tcg/cpu-exec.c:504
#5  cpu_exec (cpu=cpu@entry=0x557b3f43b7f0) at /home/bauermann/trabalho/src/qemu/accel/tcg/cpu-exec.c:729
#6  0x0000557b3d5f6c85 in tcg_cpu_exec (cpu=<optimized out>) at /home/bauermann/trabalho/src/qemu/softmmu/cpus.c:1356
#7  qemu_tcg_rr_cpu_thread_fn (arg=arg@entry=0x557b3f43b7f0) at /home/bauermann/trabalho/src/qemu/softmmu/cpus.c:1458
#8  0x0000557b3d81e919 in qemu_thread_start (args=0x7f713ce5e930) at /home/bauermann/trabalho/src/qemu/util/qemu-thread-posix.c:521
#9  0x00007f717dc6b432 in start_thread () at /lib64/libpthread.so.0
#10 0x00007f717db99913 in clone () at /lib64/libc.so.6
(gdb) up
#1  0x0000557b3d6155c5 in helper_compute_psr (env=env@entry=0x557b3f444030) at /home/bauermann/trabalho/src/qemu/target/sparc/cc_helper.c:459
459         new_psr = icc_table[CC_OP].compute_all(env);
(gdb) list
454
455     void helper_compute_psr(CPUSPARCState *env)
456     {
457         uint32_t new_psr;
458
459         new_psr = icc_table[CC_OP].compute_all(env);
460         env->psr = new_psr;
461     #ifdef TARGET_SPARC64
462         new_psr = xcc_table[CC_OP].compute_all(env);
463         env->xcc = new_psr;

CC_OP is:

#define CC_OP  (env->cc_op)

So:

(gdb) p env->cc_op
$1 = 0

0 is CC_OP_DYNAMIC, but the icc_table definition says:

static const CCTable icc_table[CC_OP_NB] = {
    /* CC_OP_DYNAMIC should never happen */

I don't know what is going on. So I will change this patch to keep
main_cpu_reset() but drop the line which sets cs->halted to 0 (which
does pass make check).

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v6 4/8] ppc/e500: Use start-powered-off CPUState property
  2020-08-22 14:35     ` Philippe Mathieu-Daudé
  2020-08-24 23:34       ` Thiago Jung Bauermann
@ 2020-08-26  5:48       ` Thiago Jung Bauermann
  1 sibling, 0 replies; 20+ messages in thread
From: Thiago Jung Bauermann @ 2020-08-26  5:48 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Peter Maydell, Thomas Huth, Eduardo Habkost, David Hildenbrand,
	Aleksandar Rikalo, Cornelia Huck, qemu-devel, Greg Kurz,
	Aleksandar Markovic, qemu-s390x, qemu-arm, qemu-ppc,
	Cédric Le Goater, Artyom Tarasenko, Paolo Bonzini,
	Igor Mammedov, David Gibson, Alex Bennée, Aurelien Jarno,
	Richard Henderson


Philippe Mathieu-Daudé <philmd@redhat.com> writes:

> On 8/22/20 10:59 AM, Cédric Le Goater wrote:
>> Hello,
>> 
>> On 8/19/20 6:43 PM, Thiago Jung Bauermann wrote:
>>> Instead of setting CPUState::halted to 1 in ppce500_cpu_reset_sec(), use
>>> the start-powered-off property which makes cpu_common_reset() initialize it
>>> to 1 in common code.
>>>
>>> Also change creation of CPU object from cpu_create() to object_new() and
>>> qdev_realize_and_unref() because cpu_create() realizes the CPU and it's not
>>> possible to set a property after the object is realized.
>>>
>>> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>>> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
>> 
>> 
>> This is breaking make check : 
>> 
>>     tests/qtest/libqtest.c:175: kill_qemu() detected QEMU death from signal 11 (Segmentation fault) (core dumped)
>>     ERROR boot-serial-test - too few tests run (expected 7, got 0)
>>     make: *** [/home/legoater/work/qemu/qemu-powernv-5.2.git/tests/Makefile.include:650: check-qtest-ppc64] Error 1
>>     make: *** Waiting for unfinished jobs....
>>     
>>     
>>     gdb --args build/ppc64-softmmu/qemu-system-ppc64  -display none   -M ppce500
>>     ...
>>     Thread 1 "qemu-system-ppc" received signal SIGSEGV, Segmentation fault.
>>     0x000055555596ebf2 in ppce500_init (machine=0x5555567aa6e0)
>>         at /home/legoater/work/qemu/qemu-powernv-5.2.git/hw/ppc/e500.c:880
>>     880	        irqs[i].irq[OPENPIC_OUTPUT_INT] = input[PPCE500_INPUT_INT];
>>  
>>     
>>     AFAIUI, 'input is not initialized since the CPU is not yet realized.
>
> Thiago, see ad938fc1d53 ("hw/arm/palm.c: Encapsulate misc GPIO handling
> in a device") and eventually f8a865d36dc ("hw/arm/allwinner-a10:
> Simplify by passing IRQs with qdev_pass_gpios") to get an idea how you
> can fix that.

I ended up not following this route. There were other patches in this
series which also caused problems in make check, but in those cases it
wasn't related to IRQ setup.

I started feeling like I had fallen into a rabbit hole so I opted
instead to solve these problems by minimizing the consequences of the
changes made by this patch series.

-- 
Thiago Jung Bauermann
IBM Linux Technology Center


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2020-08-26  5:49 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 16:42 [PATCH v6 0/8] Generalize start-powered-off property from ARM Thiago Jung Bauermann
2020-08-19 16:42 ` [PATCH v6 1/8] target/arm: Move start-powered-off property to generic CPUState Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 2/8] target/arm: Move setting of CPU halted state to generic code Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 3/8] ppc/spapr: Use start-powered-off CPUState property Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 4/8] ppc/e500: " Thiago Jung Bauermann
2020-08-22  8:59   ` Cédric Le Goater
2020-08-22 14:35     ` Philippe Mathieu-Daudé
2020-08-24 23:34       ` Thiago Jung Bauermann
2020-08-26  5:48       ` Thiago Jung Bauermann
2020-08-23  7:14     ` David Gibson
2020-08-24 23:33       ` Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 5/8] mips/cps: " Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 6/8] sparc/sun4m: Remove main_cpu_reset() Thiago Jung Bauermann
2020-08-26  3:09   ` Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 7/8] sparc/sun4m: Use start-powered-off CPUState property Thiago Jung Bauermann
2020-08-19 17:03   ` Philippe Mathieu-Daudé
2020-08-19 23:54     ` Thiago Jung Bauermann
2020-08-19 16:43 ` [PATCH v6 8/8] target/s390x: " Thiago Jung Bauermann
2020-08-20  1:42 ` [PATCH v6 0/8] Generalize start-powered-off property from ARM David Gibson
2020-08-20  2:04   ` Thiago Jung Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).