From patchwork Tue Feb 26 03:05:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10829359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3AD3013B5 for ; Tue, 26 Feb 2019 03:08:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3263E2A814 for ; Tue, 26 Feb 2019 03:08:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2197D2A9F8; Tue, 26 Feb 2019 03:08:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 88AEA2A924 for ; Tue, 26 Feb 2019 03:08:55 +0000 (UTC) Received: from localhost ([127.0.0.1]:47478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT70-0005Ys-UE for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Feb 2019 22:08:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT4F-0003qf-SH for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyT4E-0007hi-OT for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:03 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:33501) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyT49-0007d8-Hh; Mon, 25 Feb 2019 22:05:58 -0500 Received: by mail-pl1-x642.google.com with SMTP id y10so5507973plp.0; Mon, 25 Feb 2019 19:05:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xBn5iGguHFsihYWBRyXwDdl88hnkfQwuU/+bSB3tU6k=; b=I2OY9hU6bk4kIMhz6LPbQ3sxBLUntME+lOFsQuiiIXz/qTcIUfh9XJ1mIf8oIGkMT9 OgxPZCSKv22ct3rn+nLsVAhz6iv8fswj0TdhumEXJ7hJcrC+Ap4Z3JUoIRkIHZ2ESVzo D1aOp+7fM9hGgLe88+jrkjnxIvOb8lXWKLeSw8ewb4Ux+8QDaomyYvr4WYhcuZuEkt1S hhRjmZdThT6pSO4/CvKl0j1aejJ1rcWyrffXG203oiNmZKNhoEL3JeOzm5X1Xsvjq4fk i7De4dM7EjkKituiiG82Bhn7jMEPwwAuu7QWK/clib/3/XR4uAzUtelX+us1wWirvNhO HxWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xBn5iGguHFsihYWBRyXwDdl88hnkfQwuU/+bSB3tU6k=; b=IvqTerxRC3zY1FYcflWW5JG069+hFaGRYMuE46IkOkuDWYOtrggw99CN2fqBbDHxUN FnRrrLumcoNLxYYyL5qlBAAFwj212Glehb+/O8wWWR2tmvcHfQzJ+zH3CfINAK1l1T6v H1uEqAk/KFCntOiTn9/g0RPPrMe7Lg4MwnqEiD/lgcAjQUhWTN00o+JjNUCfmiWyOUNG AQUNV9SV9Kf4x/oSW672J4RWEzyck//8E6dNCJh2gEL7Wm+z6pumo7Rm6gRKxmPs0Afn QXc5hHlnnXHwIs+IHMzXm2LvbecFO5gd4NwdV79cY2vaAKOMn6SzoxJiUQisLFL4F2pO ThZA== X-Gm-Message-State: AHQUAuYYhSAFSEoBgFguGMMwgwBycaCE3Sohz9TwEsrbn96llXr7TJg9 Q6/t07yq2jYS7L4QyQ8/vWl7WF/5 X-Google-Smtp-Source: AHgI3IafxhBytPSpWsvsjlUCR1RgqJa1GQCskHfmqpfXkQ7cnRsW7SHYv8e6LjB8gCXnNbhwX2f8Pg== X-Received: by 2002:a17:902:509:: with SMTP id 9mr23223268plf.94.1551150356112; Mon, 25 Feb 2019 19:05:56 -0800 (PST) Received: from surajjs2.ozlabs.ibm.com.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id j1sm4427825pgp.84.2019.02.25.19.05.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Feb 2019 19:05:55 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Tue, 26 Feb 2019 14:05:30 +1100 Message-Id: <20190226030531.9932-3-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190226030531.9932-1-sjitindarsingh@gmail.com> References: <20190226030531.9932-1-sjitindarsingh@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 3/4] target/ppc: Implement large decrementer support for KVM X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, clg@kaod.org, Suraj Jitindar Singh , david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: David Gibson --- hw/ppc/spapr_caps.c | 17 +++++++++++++++-- target/ppc/kvm.c | 39 +++++++++++++++++++++++++++++++++++++++ target/ppc/kvm_ppc.h | 12 ++++++++++++ 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 44542fdbb2..e07568fb94 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -440,8 +440,16 @@ static void cap_large_decr_apply(sPAPRMachineState *spapr, pcc->hdecr_bits); return; } - } else { - error_setg(errp, "No large decrementer support, try cap-large-decr=0"); + } 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=0"); + } else if (val != kvm_nr_bits) { + error_setg(errp, + "Large decrementer size unsupported, try -cap-large-decr=%d", + kvm_nr_bits); + } } } @@ -452,6 +460,11 @@ 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=0"); + } + if (val) lpcr |= LPCR_LD; else diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index d01852fe31..3f650c8fc4 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -91,6 +91,7 @@ static int cap_ppc_safe_cache; static int cap_ppc_safe_bounds_check; static int cap_ppc_safe_indirect_branch; static int cap_ppc_nested_kvm_hv; +static int cap_large_decr; static uint32_t debug_inst_opcode; @@ -124,6 +125,7 @@ static bool kvmppc_is_pr(KVMState *ks) static int kvm_ppc_register_host_cpu_type(MachineState *ms); static void kvmppc_get_cpu_characteristics(KVMState *s); +static int kvmppc_get_dec_bits(void); int kvm_arch_init(MachineState *ms, KVMState *s) { @@ -151,6 +153,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) cap_resize_hpt = kvm_vm_check_extension(s, KVM_CAP_SPAPR_RESIZE_HPT); kvmppc_get_cpu_characteristics(s); cap_ppc_nested_kvm_hv = kvm_vm_check_extension(s, KVM_CAP_PPC_NESTED_HV); + cap_large_decr = kvmppc_get_dec_bits(); /* * Note: setting it to false because there is not such capability * in KVM at this moment. @@ -1927,6 +1930,15 @@ uint64_t kvmppc_get_clockfreq(void) return kvmppc_read_int_cpu_dt("clock-frequency"); } +static int kvmppc_get_dec_bits(void) +{ + int nr_bits = kvmppc_read_int_cpu_dt("ibm,dec-bits"); + + if (nr_bits > 0) + return nr_bits; + return 0; +} + static int kvmppc_get_pvinfo(CPUPPCState *env, struct kvm_ppc_pvinfo *pvinfo) { PowerPCCPU *cpu = ppc_env_get_cpu(env); @@ -2442,6 +2454,33 @@ bool kvmppc_has_cap_spapr_vfio(void) return cap_spapr_vfio; } +int kvmppc_get_cap_large_decr(void) +{ + return cap_large_decr; +} + +int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable) +{ + CPUState *cs = CPU(cpu); + uint64_t lpcr; + + kvm_get_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); + /* Do we need to modify the LPCR? */ + if (!!(lpcr & LPCR_LD) != !!enable) { + if (enable) + lpcr |= LPCR_LD; + else + lpcr &= ~LPCR_LD; + kvm_set_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); + kvm_get_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); + + if (!!(lpcr & LPCR_LD) != !!enable) + return -1; + } + + return 0; +} + PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) { uint32_t host_pvr = mfpvr(); diff --git a/target/ppc/kvm_ppc.h b/target/ppc/kvm_ppc.h index bdfaa4e70a..a79835bd14 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -64,6 +64,8 @@ int kvmppc_get_cap_safe_bounds_check(void); int kvmppc_get_cap_safe_indirect_branch(void); bool kvmppc_has_cap_nested_kvm_hv(void); int kvmppc_set_cap_nested_kvm_hv(int enable); +int kvmppc_get_cap_large_decr(void); +int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable); int kvmppc_enable_hwrng(void); int kvmppc_put_books_sregs(PowerPCCPU *cpu); PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void); @@ -332,6 +334,16 @@ static inline int kvmppc_set_cap_nested_kvm_hv(int enable) return -1; } +static inline int kvmppc_get_cap_large_decr(void) +{ + return 0; +} + +static inline int kvmppc_enable_cap_large_decr(PowerPCCPU *cpu, int enable) +{ + return -1; +} + static inline int kvmppc_enable_hwrng(void) { return -1;