[PATCH] spapr: Don't allow multiple active vCPUs at CAS

Greg Kurz posted 1 patch 4 years, 3 months ago
Test FreeBSD passed
Test docker-mingw@fedora passed
Test checkpatch passed
Test docker-quick@centos7 passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/157969867170.571404.12117797348882189656.stgit@bahia.lan
Maintainers: David Gibson <david@gibson.dropbear.id.au>
hw/ppc/spapr_hcall.c |   12 ++++++++++++
1 file changed, 12 insertions(+)
[PATCH] spapr: Don't allow multiple active vCPUs at CAS
Posted by Greg Kurz 4 years, 3 months ago
According to the description of "ibm,client-architecture-support" that
can found in LoPAPR "B.6.2.3 Root Node Methods":

If multiple partition processors or threads are active at the time of
the ibm,client-architecture-support method call, or an error is detected
in the format of the ibm,architecture.vec structure, the err? boolean
shall be TRUE; else FALSE.

We certainly don't want to temper with the platform or with the PCR of
the other vCPUs if they happen to be active. Ensure we have only one
active vCPU and fail CAS otherwise. This is just for conformance and
robustness, it doesn't fix any known bugs.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr_hcall.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
index ffb14641f9d3..b8bb66b5c0d4 100644
--- a/hw/ppc/spapr_hcall.c
+++ b/hw/ppc/spapr_hcall.c
@@ -1676,6 +1676,18 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
     Error *local_err = NULL;
     bool raw_mode_supported = false;
     bool guest_xive;
+    CPUState *cs;
+
+    /* CAS is supposed to be called early when only the boot vCPU is active. */
+    CPU_FOREACH(cs) {
+        if (cs == CPU(cpu)) {
+            continue;
+        }
+        if (!cs->halted) {
+            warn_report("guest has multiple active vCPUs at CAS, which is not allowed");
+            return H_MULTI_THREADS_ACTIVE;
+        }
+    }
 
     cas_pvr = cas_check_pvr(spapr, cpu, &addr, &raw_mode_supported, &local_err);
     if (local_err) {


Re: [PATCH] spapr: Don't allow multiple active vCPUs at CAS
Posted by David Gibson 4 years, 3 months ago
On Wed, Jan 22, 2020 at 02:11:12PM +0100, Greg Kurz wrote:
> According to the description of "ibm,client-architecture-support" that
> can found in LoPAPR "B.6.2.3 Root Node Methods":
> 
> If multiple partition processors or threads are active at the time of
> the ibm,client-architecture-support method call, or an error is detected
> in the format of the ibm,architecture.vec structure, the err? boolean
> shall be TRUE; else FALSE.
> 
> We certainly don't want to temper with the platform or with the PCR of
> the other vCPUs if they happen to be active. Ensure we have only one
> active vCPU and fail CAS otherwise. This is just for conformance and
> robustness, it doesn't fix any known bugs.
> 
> Signed-off-by: Greg Kurz <groug@kaod.org>

Applied to ppc-for-5.0, thanks.

> ---
>  hw/ppc/spapr_hcall.c |   12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c
> index ffb14641f9d3..b8bb66b5c0d4 100644
> --- a/hw/ppc/spapr_hcall.c
> +++ b/hw/ppc/spapr_hcall.c
> @@ -1676,6 +1676,18 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu,
>      Error *local_err = NULL;
>      bool raw_mode_supported = false;
>      bool guest_xive;
> +    CPUState *cs;
> +
> +    /* CAS is supposed to be called early when only the boot vCPU is active. */
> +    CPU_FOREACH(cs) {
> +        if (cs == CPU(cpu)) {
> +            continue;
> +        }
> +        if (!cs->halted) {
> +            warn_report("guest has multiple active vCPUs at CAS, which is not allowed");
> +            return H_MULTI_THREADS_ACTIVE;
> +        }
> +    }
>  
>      cas_pvr = cas_check_pvr(spapr, cpu, &addr, &raw_mode_supported, &local_err);
>      if (local_err) {
> 

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