From 7d050527e3f5cadbf9db3bce09409fb4e9259997 Mon Sep 17 00:00:00 2001 From: Suraj Jitindar Singh Date: Fri, 1 Mar 2019 13:43:16 +1100 Subject: target/ppc: Implement large decrementer support for KVM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement support to allow KVM guests to take advantage of the large decrementer introduced on POWER9 cpus. To determine if the host can support the requested large decrementer size, we check it matches that specified in the ibm,dec-bits device-tree property. We also need to enable it in KVM by setting the LPCR_LD bit in the LPCR. Note that to do this we need to try and set the bit, then read it back to check the host allowed us to set it, if so we can use it but if we were unable to set it the host cannot support it and we must not use the large decrementer. Signed-off-by: Suraj Jitindar Singh Signed-off-by: Cédric Le Goater Message-Id: <20190301024317.22137-3-sjitindarsingh@gmail.com> [dwg: Small style fixes] Signed-off-by: David Gibson --- hw/ppc/spapr_caps.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'hw/ppc/spapr_caps.c') diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 6d6dca30db..942ac8ebbe 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -394,6 +394,7 @@ static void cap_large_decr_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp) { PowerPCCPU *cpu = POWERPC_CPU(first_cpu); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); if (!val) { return; /* Disabled by default */ @@ -406,9 +407,17 @@ static void cap_large_decr_apply(sPAPRMachineState *spapr, "Large decrementer only supported on POWER9, try -cpu POWER9"); return; } - } else { - error_setg(errp, - "No large decrementer support, try cap-large-decr=off"); + } else if (kvm_enabled()) { + int kvm_nr_bits = kvmppc_get_cap_large_decr(); + + if (!kvm_nr_bits) { + error_setg(errp, + "No large decrementer support, try cap-large-decr=off"); + } else if (pcc->lrg_decr_bits != kvm_nr_bits) { + error_setg(errp, +"KVM large decrementer size (%d) differs to model (%d), try -cap-large-decr=off", + kvm_nr_bits, pcc->lrg_decr_bits); + } } } @@ -419,6 +428,13 @@ static void cap_large_decr_cpu_apply(sPAPRMachineState *spapr, CPUPPCState *env = &cpu->env; target_ulong lpcr = env->spr[SPR_LPCR]; + if (kvm_enabled()) { + if (kvmppc_enable_cap_large_decr(cpu, val)) { + error_setg(errp, + "No large decrementer support, try cap-large-decr=off"); + } + } + if (val) { lpcr |= LPCR_LD; } else { -- cgit v1.2.3