From: Eduardo Habkost <ehabkost@redhat.com>
To: Thiago Jung Bauermann <bauerman@linux.ibm.com>
Cc: qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH] cpu: Add starts_halted() method
Date: Tue, 7 Jul 2020 17:49:17 -0400 [thread overview]
Message-ID: <20200707214917.GX7276@habkost.net> (raw)
In-Reply-To: <20200707204333.261506-1-bauerman@linux.ibm.com>
On Tue, Jul 07, 2020 at 05:43:33PM -0300, Thiago Jung Bauermann wrote:
> PowerPC sPAPRs CPUs start in the halted state, but generic QEMU code
> assumes that CPUs start in the non-halted state. spapr_reset_vcpu()
> attempts to rectify this by setting CPUState::halted to 1. But that's too
> late for hotplugged CPUs in a machine configured with 2 or mor 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 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 adding a starts_halted() method to the CPUState class, and making it
> return 1 if the machine is an sPAPR guest.
>
> Signed-off-by: Thiago Jung Bauermann <bauerman@linux.ibm.com>
[...]
> +static uint32_t ppc_cpu_starts_halted(void)
> +{
> + SpaprMachineState *spapr =
> + (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(),
> + TYPE_SPAPR_MACHINE);
Wouldn't it be simpler to just implement this as a MachineClass
boolean field? e.g.:
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 426ce5f625..ffadc7a17d 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -215,6 +215,7 @@ struct MachineClass {
bool nvdimm_supported;
bool numa_mem_supported;
bool auto_enable_numa;
+ bool cpu_starts_halted;
const char *default_ram_id;
HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
diff --git a/hw/core/cpu.c b/hw/core/cpu.c
index 0f23409f1d..08dd504034 100644
--- a/hw/core/cpu.c
+++ b/hw/core/cpu.c
@@ -252,6 +252,7 @@ static void cpu_common_reset(DeviceState *dev)
{
CPUState *cpu = CPU(dev);
CPUClass *cc = CPU_GET_CLASS(cpu);
+ MachineState *machine = object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE);
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
@@ -259,7 +260,7 @@ static void cpu_common_reset(DeviceState *dev)
}
cpu->interrupt_request = 0;
- cpu->halted = 0;
+ cpu->halted = machine ? MACHINE_GET_CLASS(machine)->cpu_starts_halted : 0;
cpu->mem_io_pc = 0;
cpu->icount_extra = 0;
atomic_set(&cpu->icount_decr_ptr->u32, 0);
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index f6f034d039..d16ec33033 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -4487,6 +4487,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power9_v2.0");
mc->has_hotpluggable_cpus = true;
mc->nvdimm_supported = true;
+ mc->cpu_starts_halted = true;
smc->resize_hpt_default = SPAPR_RESIZE_HPT_ENABLED;
fwc->get_dev_path = spapr_get_fw_dev_path;
nc->nmi_monitor_handler = spapr_nmi;
> +
> + /*
> + * In sPAPR, 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.
> + */
> + return spapr != NULL;
> +}
> +
--
Eduardo
next prev parent reply other threads:[~2020-07-08 22:24 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-07 20:43 [PATCH] cpu: Add starts_halted() method Thiago Jung Bauermann
2020-07-07 21:49 ` Eduardo Habkost [this message]
2020-07-07 23:28 ` Thiago Jung Bauermann
2020-07-08 8:38 ` Philippe Mathieu-Daudé
2020-07-08 10:00 ` David Gibson
2020-07-08 13:14 ` Peter Maydell
2020-07-08 15:25 ` Eduardo Habkost
2020-07-08 15:32 ` Peter Maydell
2020-07-08 16:03 ` Eduardo Habkost
2020-07-08 17:09 ` Peter Maydell
2020-07-08 17:36 ` Eduardo Habkost
2020-07-08 20:11 ` Peter Maydell
2020-07-08 21:32 ` Eduardo Habkost
2020-07-09 3:05 ` Thiago Jung Bauermann
2020-07-09 3:26 ` Thiago Jung Bauermann
2020-07-09 10:24 ` Philippe Mathieu-Daudé
2020-07-10 20:02 ` Thiago Jung Bauermann
2020-07-10 20:17 ` Eduardo Habkost
[not found] ` <87k0zdm63s.fsf@linaro.org>
2020-07-10 20:16 ` Thiago Jung Bauermann
2020-07-11 17:55 ` Alex Bennée
2020-07-08 16:45 ` Philippe Mathieu-Daudé
2020-07-08 21:39 ` Eduardo Habkost
2020-07-09 5:11 ` Philippe Mathieu-Daudé
2020-07-09 9:54 ` Greg Kurz
2020-07-09 10:18 ` Philippe Mathieu-Daudé
2020-07-09 10:55 ` Greg Kurz
2020-07-09 12:21 ` Philippe Mathieu-Daudé
2020-07-09 13:13 ` Greg Kurz
2020-07-09 13:19 ` Philippe Mathieu-Daudé
2020-07-09 13:40 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200707214917.GX7276@habkost.net \
--to=ehabkost@redhat.com \
--cc=bauerman@linux.ibm.com \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.