|
|
9bac43 |
From cdb93019369dff9f8a3ab19df18f24a5ba508698 Mon Sep 17 00:00:00 2001
|
|
|
9bac43 |
From: Sam Bobroff <sbobroff@redhat.com>
|
|
|
9bac43 |
Date: Fri, 6 Oct 2017 06:04:59 +0200
|
|
|
9bac43 |
Subject: [PATCH 13/34] PPC: KVM: Support machine option to set VSMT mode
|
|
|
9bac43 |
|
|
|
9bac43 |
RH-Author: Sam Bobroff <sbobroff@redhat.com>
|
|
|
9bac43 |
Message-id: <1507269899-22908-1-git-send-email-sbobroff@redhat.com>
|
|
|
9bac43 |
Patchwork-id: 76834
|
|
|
9bac43 |
O-Subject: [RHEL7.5 qemu-kvm-rhev PATCH] PPC: KVM: Support machine option to set VSMT mode
|
|
|
9bac43 |
Bugzilla: 1479178
|
|
|
9bac43 |
RH-Acked-by: David Gibson <dgibson@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
|
|
|
9bac43 |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
From: Sam Bobroff <sam.bobroff@au1.ibm.com>
|
|
|
9bac43 |
|
|
|
9bac43 |
KVM now allows writing to KVM_CAP_PPC_SMT which has previously been
|
|
|
9bac43 |
read only. Doing so causes KVM to act, for that VM, as if the host's
|
|
|
9bac43 |
SMT mode was the given value. This is particularly important on Power
|
|
|
9bac43 |
9 systems because their default value is 1, but they are able to
|
|
|
9bac43 |
support values up to 8.
|
|
|
9bac43 |
|
|
|
9bac43 |
This patch introduces a way to control this capability via a new
|
|
|
9bac43 |
machine property called VSMT ("Virtual SMT"). If the value is not set
|
|
|
9bac43 |
on the command line a default is chosen that is, when possible,
|
|
|
9bac43 |
compatible with legacy systems.
|
|
|
9bac43 |
|
|
|
9bac43 |
Note that the intialization of KVM_CAP_PPC_SMT has changed slightly
|
|
|
9bac43 |
because it has changed (in KVM) from a global capability to a
|
|
|
9bac43 |
VM-specific one. This won't cause a problem on older KVMs because VM
|
|
|
9bac43 |
capabilities fall back to global ones.
|
|
|
9bac43 |
|
|
|
9bac43 |
Signed-off-by: Sam Bobroff <sam.bobroff@au1.ibm.com>
|
|
|
9bac43 |
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
|
|
|
9bac43 |
(cherry picked from commit fa98fbfcdfcb980b4a690b8bc93ab597935087b1)
|
|
|
9bac43 |
|
|
|
9bac43 |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1479178
|
|
|
9bac43 |
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=14187630
|
|
|
9bac43 |
Testing: Start QEMU using "--machine pseries,vsmt=4".
|
|
|
9bac43 |
Signed-off-by: Sam Bobroff <sbobroff@redhat.com>
|
|
|
9bac43 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9bac43 |
---
|
|
|
9bac43 |
hw/ppc/spapr.c | 75 +++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9bac43 |
include/hw/ppc/spapr.h | 1 +
|
|
|
9bac43 |
target/ppc/kvm.c | 39 ++++++++++++++++++++++-
|
|
|
9bac43 |
target/ppc/kvm_ppc.h | 12 ++++++++
|
|
|
9bac43 |
target/ppc/translate_init.c | 14 ---------
|
|
|
9bac43 |
5 files changed, 126 insertions(+), 15 deletions(-)
|
|
|
9bac43 |
|
|
|
9bac43 |
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
|
|
|
9bac43 |
index d3db051..30b2c5b 100644
|
|
|
9bac43 |
--- a/hw/ppc/spapr.c
|
|
|
9bac43 |
+++ b/hw/ppc/spapr.c
|
|
|
9bac43 |
@@ -26,6 +26,7 @@
|
|
|
9bac43 |
*/
|
|
|
9bac43 |
#include "qemu/osdep.h"
|
|
|
9bac43 |
#include "qapi/error.h"
|
|
|
9bac43 |
+#include "qapi/visitor.h"
|
|
|
9bac43 |
#include "sysemu/sysemu.h"
|
|
|
9bac43 |
#include "sysemu/numa.h"
|
|
|
9bac43 |
#include "hw/hw.h"
|
|
|
9bac43 |
@@ -2166,6 +2167,61 @@ static void spapr_init_cpus(sPAPRMachineState *spapr)
|
|
|
9bac43 |
g_free(type);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
+static void spapr_set_vsmt_mode(sPAPRMachineState *spapr, Error **errp)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ Error *local_err = NULL;
|
|
|
9bac43 |
+ bool vsmt_user = !!spapr->vsmt;
|
|
|
9bac43 |
+ int kvm_smt = kvmppc_smt_threads();
|
|
|
9bac43 |
+ int ret;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ if (!kvm_enabled() && (smp_threads > 1)) {
|
|
|
9bac43 |
+ error_setg(&local_err, "TCG cannot support more than 1 thread/core "
|
|
|
9bac43 |
+ "on a pseries machine");
|
|
|
9bac43 |
+ goto out;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ if (!is_power_of_2(smp_threads)) {
|
|
|
9bac43 |
+ error_setg(&local_err, "Cannot support %d threads/core on a pseries "
|
|
|
9bac43 |
+ "machine because it must be a power of 2", smp_threads);
|
|
|
9bac43 |
+ goto out;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ /* Detemine the VSMT mode to use: */
|
|
|
9bac43 |
+ if (vsmt_user) {
|
|
|
9bac43 |
+ if (spapr->vsmt < smp_threads) {
|
|
|
9bac43 |
+ error_setg(&local_err, "Cannot support VSMT mode %d"
|
|
|
9bac43 |
+ " because it must be >= threads/core (%d)",
|
|
|
9bac43 |
+ spapr->vsmt, smp_threads);
|
|
|
9bac43 |
+ goto out;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ /* In this case, spapr->vsmt has been set by the command line */
|
|
|
9bac43 |
+ } else {
|
|
|
9bac43 |
+ /* Choose a VSMT mode that may be higher than necessary but is
|
|
|
9bac43 |
+ * likely to be compatible with hosts that don't have VSMT. */
|
|
|
9bac43 |
+ spapr->vsmt = MAX(kvm_smt, smp_threads);
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ /* KVM: If necessary, set the SMT mode: */
|
|
|
9bac43 |
+ if (kvm_enabled() && (spapr->vsmt != kvm_smt)) {
|
|
|
9bac43 |
+ ret = kvmppc_set_smt_threads(spapr->vsmt);
|
|
|
9bac43 |
+ if (ret) {
|
|
|
9bac43 |
+ error_setg(&local_err,
|
|
|
9bac43 |
+ "Failed to set KVM's VSMT mode to %d (errno %d)",
|
|
|
9bac43 |
+ spapr->vsmt, ret);
|
|
|
9bac43 |
+ if (!vsmt_user) {
|
|
|
9bac43 |
+ error_append_hint(&local_err, "On PPC, a VM with %d threads/"
|
|
|
9bac43 |
+ "core on a host with %d threads/core requires "
|
|
|
9bac43 |
+ " the use of VSMT mode %d.\n",
|
|
|
9bac43 |
+ smp_threads, kvm_smt, spapr->vsmt);
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ kvmppc_hint_smt_possible(&local_err);
|
|
|
9bac43 |
+ goto out;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ /* else TCG: nothing to do currently */
|
|
|
9bac43 |
+out:
|
|
|
9bac43 |
+ error_propagate(errp, local_err);
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
/* pSeries LPAR / sPAPR hardware init */
|
|
|
9bac43 |
static void ppc_spapr_init(MachineState *machine)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
@@ -2298,6 +2354,8 @@ static void ppc_spapr_init(MachineState *machine)
|
|
|
9bac43 |
|
|
|
9bac43 |
spapr_cpu_parse_features(spapr);
|
|
|
9bac43 |
|
|
|
9bac43 |
+ spapr_set_vsmt_mode(spapr, &error_fatal);
|
|
|
9bac43 |
+
|
|
|
9bac43 |
spapr_init_cpus(spapr);
|
|
|
9bac43 |
|
|
|
9bac43 |
if (kvm_enabled()) {
|
|
|
9bac43 |
@@ -2682,6 +2740,18 @@ static void spapr_set_resize_hpt(Object *obj, const char *value, Error **errp)
|
|
|
9bac43 |
}
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
+static void spapr_get_vsmt(Object *obj, Visitor *v, const char *name,
|
|
|
9bac43 |
+ void *opaque, Error **errp)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ visit_type_uint32(v, name, (uint32_t *)opaque, errp);
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static void spapr_set_vsmt(Object *obj, Visitor *v, const char *name,
|
|
|
9bac43 |
+ void *opaque, Error **errp)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ visit_type_uint32(v, name, (uint32_t *)opaque, errp);
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
static void spapr_machine_initfn(Object *obj)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
sPAPRMachineState *spapr = SPAPR_MACHINE(obj);
|
|
|
9bac43 |
@@ -2712,6 +2782,11 @@ static void spapr_machine_initfn(Object *obj)
|
|
|
9bac43 |
object_property_set_description(obj, "resize-hpt",
|
|
|
9bac43 |
"Resizing of the Hash Page Table (enabled, disabled, required)",
|
|
|
9bac43 |
NULL);
|
|
|
9bac43 |
+ object_property_add(obj, "vsmt", "uint32", spapr_get_vsmt,
|
|
|
9bac43 |
+ spapr_set_vsmt, NULL, &spapr->vsmt, &error_abort);
|
|
|
9bac43 |
+ object_property_set_description(obj, "vsmt",
|
|
|
9bac43 |
+ "Virtual SMT: KVM behaves as if this were"
|
|
|
9bac43 |
+ " the host's SMT mode", &error_abort);
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
static void spapr_machine_finalizefn(Object *obj)
|
|
|
9bac43 |
diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h
|
|
|
9bac43 |
index 5d161ec..3d0d206 100644
|
|
|
9bac43 |
--- a/include/hw/ppc/spapr.h
|
|
|
9bac43 |
+++ b/include/hw/ppc/spapr.h
|
|
|
9bac43 |
@@ -99,6 +99,7 @@ struct sPAPRMachineState {
|
|
|
9bac43 |
uint64_t rtc_offset; /* Now used only during incoming migration */
|
|
|
9bac43 |
struct PPCTimebase tb;
|
|
|
9bac43 |
bool has_graphics;
|
|
|
9bac43 |
+ uint32_t vsmt; /* Virtual SMT mode (KVM's "core stride") */
|
|
|
9bac43 |
|
|
|
9bac43 |
Notifier epow_notifier;
|
|
|
9bac43 |
QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
|
|
|
9bac43 |
diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c
|
|
|
9bac43 |
index f31c67e..ce7e2ec 100644
|
|
|
9bac43 |
--- a/target/ppc/kvm.c
|
|
|
9bac43 |
+++ b/target/ppc/kvm.c
|
|
|
9bac43 |
@@ -74,6 +74,7 @@ static int cap_interrupt_level = false;
|
|
|
9bac43 |
static int cap_segstate;
|
|
|
9bac43 |
static int cap_booke_sregs;
|
|
|
9bac43 |
static int cap_ppc_smt;
|
|
|
9bac43 |
+static int cap_ppc_smt_possible;
|
|
|
9bac43 |
static int cap_ppc_rma;
|
|
|
9bac43 |
static int cap_spapr_tce;
|
|
|
9bac43 |
static int cap_spapr_tce_64;
|
|
|
9bac43 |
@@ -130,7 +131,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
|
|
|
9bac43 |
cap_interrupt_level = kvm_check_extension(s, KVM_CAP_PPC_IRQ_LEVEL);
|
|
|
9bac43 |
cap_segstate = kvm_check_extension(s, KVM_CAP_PPC_SEGSTATE);
|
|
|
9bac43 |
cap_booke_sregs = kvm_check_extension(s, KVM_CAP_PPC_BOOKE_SREGS);
|
|
|
9bac43 |
- cap_ppc_smt = kvm_check_extension(s, KVM_CAP_PPC_SMT);
|
|
|
9bac43 |
+ cap_ppc_smt_possible = kvm_check_extension(s, KVM_CAP_PPC_SMT_POSSIBLE);
|
|
|
9bac43 |
cap_ppc_rma = kvm_check_extension(s, KVM_CAP_PPC_RMA);
|
|
|
9bac43 |
cap_spapr_tce = kvm_check_extension(s, KVM_CAP_SPAPR_TCE);
|
|
|
9bac43 |
cap_spapr_tce_64 = kvm_check_extension(s, KVM_CAP_SPAPR_TCE_64);
|
|
|
9bac43 |
@@ -144,6 +145,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)
|
|
|
9bac43 |
* only activated after this by kvmppc_set_papr() */
|
|
|
9bac43 |
cap_htab_fd = kvm_check_extension(s, KVM_CAP_PPC_HTAB_FD);
|
|
|
9bac43 |
cap_fixup_hcalls = kvm_check_extension(s, KVM_CAP_PPC_FIXUP_HCALL);
|
|
|
9bac43 |
+ cap_ppc_smt = kvm_vm_check_extension(s, KVM_CAP_PPC_SMT);
|
|
|
9bac43 |
cap_htm = kvm_vm_check_extension(s, KVM_CAP_PPC_HTM);
|
|
|
9bac43 |
cap_mmu_radix = kvm_vm_check_extension(s, KVM_CAP_PPC_MMU_RADIX);
|
|
|
9bac43 |
cap_mmu_hash_v3 = kvm_vm_check_extension(s, KVM_CAP_PPC_MMU_HASH_V3);
|
|
|
9bac43 |
@@ -2134,6 +2136,41 @@ int kvmppc_smt_threads(void)
|
|
|
9bac43 |
return cap_ppc_smt ? cap_ppc_smt : 1;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
+int kvmppc_set_smt_threads(int smt)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ int ret;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ ret = kvm_vm_enable_cap(kvm_state, KVM_CAP_PPC_SMT, 0, smt, 0);
|
|
|
9bac43 |
+ if (!ret) {
|
|
|
9bac43 |
+ cap_ppc_smt = smt;
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ return ret;
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+void kvmppc_hint_smt_possible(Error **errp)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ int i;
|
|
|
9bac43 |
+ GString *g;
|
|
|
9bac43 |
+ char *s;
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+ assert(kvm_enabled());
|
|
|
9bac43 |
+ if (cap_ppc_smt_possible) {
|
|
|
9bac43 |
+ g = g_string_new("Available VSMT modes:");
|
|
|
9bac43 |
+ for (i = 63; i >= 0; i--) {
|
|
|
9bac43 |
+ if ((1UL << i) & cap_ppc_smt_possible) {
|
|
|
9bac43 |
+ g_string_append_printf(g, " %lu", (1UL << i));
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+ s = g_string_free(g, false);
|
|
|
9bac43 |
+ error_append_hint(errp, "%s.\n", s);
|
|
|
9bac43 |
+ g_free(s);
|
|
|
9bac43 |
+ } else {
|
|
|
9bac43 |
+ error_append_hint(errp,
|
|
|
9bac43 |
+ "This KVM seems to be too old to support VSMT.\n");
|
|
|
9bac43 |
+ }
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+
|
|
|
9bac43 |
#ifdef TARGET_PPC64
|
|
|
9bac43 |
off_t kvmppc_alloc_rma(void **rma)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h
|
|
|
9bac43 |
index 381afe6..e6711fc 100644
|
|
|
9bac43 |
--- a/target/ppc/kvm_ppc.h
|
|
|
9bac43 |
+++ b/target/ppc/kvm_ppc.h
|
|
|
9bac43 |
@@ -29,6 +29,8 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
|
|
|
9bac43 |
int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
|
|
|
9bac43 |
void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
|
|
|
9bac43 |
int kvmppc_smt_threads(void);
|
|
|
9bac43 |
+void kvmppc_hint_smt_possible(Error **errp);
|
|
|
9bac43 |
+int kvmppc_set_smt_threads(int smt);
|
|
|
9bac43 |
int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
|
|
|
9bac43 |
int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
|
|
|
9bac43 |
int kvmppc_set_tcr(PowerPCCPU *cpu);
|
|
|
9bac43 |
@@ -148,6 +150,16 @@ static inline int kvmppc_smt_threads(void)
|
|
|
9bac43 |
return 1;
|
|
|
9bac43 |
}
|
|
|
9bac43 |
|
|
|
9bac43 |
+static inline void kvmppc_hint_smt_possible(Error **errp)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ return;
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
+static inline int kvmppc_set_smt_threads(int smt)
|
|
|
9bac43 |
+{
|
|
|
9bac43 |
+ return 0;
|
|
|
9bac43 |
+}
|
|
|
9bac43 |
+
|
|
|
9bac43 |
static inline int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits)
|
|
|
9bac43 |
{
|
|
|
9bac43 |
return 0;
|
|
|
9bac43 |
diff --git a/target/ppc/translate_init.c b/target/ppc/translate_init.c
|
|
|
9bac43 |
index 8fb407e..371bbae 100644
|
|
|
9bac43 |
--- a/target/ppc/translate_init.c
|
|
|
9bac43 |
+++ b/target/ppc/translate_init.c
|
|
|
9bac43 |
@@ -9817,20 +9817,6 @@ static void ppc_cpu_realizefn(DeviceState *dev, Error **errp)
|
|
|
9bac43 |
int max_smt = kvmppc_smt_threads();
|
|
|
9bac43 |
#endif
|
|
|
9bac43 |
|
|
|
9bac43 |
-#if !defined(CONFIG_USER_ONLY)
|
|
|
9bac43 |
- if (smp_threads > max_smt) {
|
|
|
9bac43 |
- error_setg(errp, "Cannot support more than %d threads on PPC with %s",
|
|
|
9bac43 |
- max_smt, kvm_enabled() ? "KVM" : "TCG");
|
|
|
9bac43 |
- return;
|
|
|
9bac43 |
- }
|
|
|
9bac43 |
- if (!is_power_of_2(smp_threads)) {
|
|
|
9bac43 |
- error_setg(errp, "Cannot support %d threads on PPC with %s, "
|
|
|
9bac43 |
- "threads count must be a power of 2.",
|
|
|
9bac43 |
- smp_threads, kvm_enabled() ? "KVM" : "TCG");
|
|
|
9bac43 |
- return;
|
|
|
9bac43 |
- }
|
|
|
9bac43 |
-#endif
|
|
|
9bac43 |
-
|
|
|
9bac43 |
cpu_exec_realizefn(cs, &local_err);
|
|
|
9bac43 |
if (local_err != NULL) {
|
|
|
9bac43 |
error_propagate(errp, local_err);
|
|
|
9bac43 |
--
|
|
|
9bac43 |
1.8.3.1
|
|
|
9bac43 |
|