cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-spapr-Enable-DD2.3-accelerated-count-cache-flush-in-.patch

ddf19c
From eb121ffa97c1c25d7853d51b4c8209c0bb521deb Mon Sep 17 00:00:00 2001
ddf19c
From: David Gibson <dgibson@redhat.com>
ddf19c
Date: Fri, 7 Feb 2020 00:57:04 +0000
ddf19c
Subject: [PATCH 1/7] spapr: Enable DD2.3 accelerated count cache flush in
ddf19c
 pseries-5.0 machine
ddf19c
ddf19c
RH-Author: David Gibson <dgibson@redhat.com>
ddf19c
Message-id: <20200207005704.194428-1-dgibson@redhat.com>
ddf19c
Patchwork-id: 93737
ddf19c
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCHv2] spapr: Enable DD2.3 accelerated count cache flush in pseries-5.0 machine
ddf19c
Bugzilla: 1796240
ddf19c
RH-Acked-by: Danilo de Paula <ddepaula@redhat.com>
ddf19c
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ddf19c
RH-Acked-by: Thomas Huth <thuth@redhat.com>
ddf19c
ddf19c
From: David Gibson <david@gibson.dropbear.id.au>
ddf19c
ddf19c
For POWER9 DD2.2 cpus, the best current Spectre v2 indirect branch
ddf19c
mitigation is "count cache disabled", which is configured with:
ddf19c
    -machine cap-ibs=fixed-ccd
ddf19c
However, this option isn't available on DD2.3 CPUs with KVM, because they
ddf19c
don't have the count cache disabled.
ddf19c
ddf19c
For POWER9 DD2.3 cpus, it is "count cache flush with assist", configured
ddf19c
with:
ddf19c
    -machine cap-ibs=workaround,cap-ccf-assist=on
ddf19c
However this option isn't available on DD2.2 CPUs with KVM, because they
ddf19c
don't have the special CCF assist instruction this relies on.
ddf19c
ddf19c
On current machine types, we default to "count cache flush w/o assist",
ddf19c
that is:
ddf19c
    -machine cap-ibs=workaround,cap-ccf-assist=off
ddf19c
This runs, with mitigation on both DD2.2 and DD2.3 host cpus, but has a
ddf19c
fairly significant performance impact.
ddf19c
ddf19c
It turns out we can do better.  The special instruction that CCF assist
ddf19c
uses to trigger a count cache flush is a no-op on earlier CPUs, rather than
ddf19c
trapping or causing other badness.  It doesn't, of itself, implement the
ddf19c
mitigation, but *if* we have count-cache-disabled, then the count cache
ddf19c
flush is unnecessary, and so using the count cache flush mitigation is
ddf19c
harmless.
ddf19c
ddf19c
Therefore for the new pseries-5.0 machine type, enable cap-ccf-assist by
ddf19c
default.  Along with that, suppress throwing an error if cap-ccf-assist
ddf19c
is selected but KVM doesn't support it, as long as KVM *is* giving us
ddf19c
count-cache-disabled.  To allow TCG to work out of the box, even though it
ddf19c
doesn't implement the ccf flush assist, downgrade the error in that case to
ddf19c
a warning.  This matches several Spectre mitigations where we allow TCG
ddf19c
to operate for debugging, since we don't really make guarantees about TCG
ddf19c
security properties anyway.
ddf19c
ddf19c
While we're there, make the TCG warning for this case match that for other
ddf19c
mitigations.
ddf19c
ddf19c
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ddf19c
Tested-by: Michael Ellerman <mpe@ellerman.id.au>
ddf19c
(cherry picked from commit 37965dfe4dffa3ac49438337417608e7f346b58a)
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
ddf19c
Conflicts:
ddf19c
	hw/ppc/spapr.c
ddf19c
ddf19c
Adjusted machine version compatibility code to the RHEL machine types
ddf19c
rather than the upstream machine types.
ddf19c
ddf19c
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1796240
ddf19c
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=26285002
ddf19c
Branch: rhel-av-8.2.0
ddf19c
Upstream: Merged for qemu-5.0
ddf19c
ddf19c
Signed-off-by: David Gibson <dgibson@redhat.com>
ddf19c
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ddf19c
---
ddf19c
 hw/ppc/spapr.c      |  4 +++-
ddf19c
 hw/ppc/spapr_caps.c | 21 +++++++++++++++++----
ddf19c
 2 files changed, 20 insertions(+), 5 deletions(-)
ddf19c
ddf19c
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
ddf19c
index c12862d..a330f03 100644
ddf19c
--- a/hw/ppc/spapr.c
ddf19c
+++ b/hw/ppc/spapr.c
ddf19c
@@ -4440,7 +4440,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data)
ddf19c
     smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 16; /* 64kiB */
ddf19c
     smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV] = SPAPR_CAP_OFF;
ddf19c
     smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = SPAPR_CAP_ON;
ddf19c
-    smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF;
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_ON;
ddf19c
     spapr_caps_add_properties(smc, &error_abort);
ddf19c
     smc->irq = &spapr_irq_dual;
ddf19c
     smc->dr_phb_enabled = true;
ddf19c
@@ -4904,6 +4904,8 @@ static void spapr_machine_rhel810_class_options(MachineClass *mc)
ddf19c
                      hw_compat_rhel_8_1_len);
ddf19c
     compat_props_add(mc->compat_props, compat, G_N_ELEMENTS(compat));
ddf19c
 
ddf19c
+    /* from pseries-4.2 */
ddf19c
+    smc->default_caps.caps[SPAPR_CAP_CCF_ASSIST] = SPAPR_CAP_OFF;
ddf19c
 }
ddf19c
 
ddf19c
 DEFINE_SPAPR_MACHINE(rhel810, "rhel8.1.0", false);
ddf19c
diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c
ddf19c
index 805f385..6e6fb28 100644
ddf19c
--- a/hw/ppc/spapr_caps.c
ddf19c
+++ b/hw/ppc/spapr_caps.c
ddf19c
@@ -492,11 +492,24 @@ static void cap_ccf_assist_apply(SpaprMachineState *spapr, uint8_t val,
ddf19c
     uint8_t kvm_val = kvmppc_get_cap_count_cache_flush_assist();
ddf19c
 
ddf19c
     if (tcg_enabled() && val) {
ddf19c
-        /* TODO - for now only allow broken for TCG */
ddf19c
-        error_setg(errp,
ddf19c
-"Requested count cache flush assist capability level not supported by tcg,"
ddf19c
-                   " try appending -machine cap-ccf-assist=off");
ddf19c
+        /* TCG doesn't implement anything here, but allow with a warning */
ddf19c
+        warn_report("TCG doesn't support requested feature, cap-ccf-assist=on");
ddf19c
     } else if (kvm_enabled() && (val > kvm_val)) {
ddf19c
+        uint8_t kvm_ibs = kvmppc_get_cap_safe_indirect_branch();
ddf19c
+
ddf19c
+        if (kvm_ibs == SPAPR_CAP_FIXED_CCD) {
ddf19c
+            /*
ddf19c
+             * If we don't have CCF assist on the host, the assist
ddf19c
+             * instruction is a harmless no-op.  It won't correctly
ddf19c
+             * implement the cache count flush *but* if we have
ddf19c
+             * count-cache-disabled in the host, that flush is
ddf19c
+             * unnnecessary.  So, specifically allow this case.  This
ddf19c
+             * allows us to have better performance on POWER9 DD2.3,
ddf19c
+             * while still working on POWER9 DD2.2 and POWER8 host
ddf19c
+             * cpus.
ddf19c
+             */
ddf19c
+            return;
ddf19c
+        }
ddf19c
         error_setg(errp,
ddf19c
 "Requested count cache flush assist capability level not supported by kvm,"
ddf19c
                    " try appending -machine cap-ccf-assist=off");
ddf19c
-- 
ddf19c
1.8.3.1
ddf19c