From patchwork Wed Feb 27 04:30:07 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: 10831049 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 D7131922 for ; Wed, 27 Feb 2019 04:34:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C21B22C789 for ; Wed, 27 Feb 2019 04:34:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3B752C830; Wed, 27 Feb 2019 04:34:19 +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 26D7E2C789 for ; Wed, 27 Feb 2019 04:34:19 +0000 (UTC) Received: from localhost ([127.0.0.1]:37745 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqvC-0002uS-Fm for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Feb 2019 23:34:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48121) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqrl-0000fk-2z for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyqrj-0008UX-1K for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:44 -0500 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:44486) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyqre-0008Cw-82; Tue, 26 Feb 2019 23:30:38 -0500 Received: by mail-pl1-x642.google.com with SMTP id c4so7321690pls.11; Tue, 26 Feb 2019 20:30:26 -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=BjeHFbhN+7Am2uICjQaFMBirxT9NzgzFU+oFo1cIHWM=; b=VLiXI0IfPZY1GILvzibzqSBfnfl9Fu7Fo2CpYbPeXBAshU+Gngac7AV9fGTKwiJuDF ZujH4i1tIiZbOVSEPvse42vymcQzknYZ9Cmfl3PkXk8NjgAlpilg6vvxCvmW537WeD1w r7spA2FKG1H6cAy0pnTftHlY7oyJy7MJAY/cyaVtxdWBxyvxRtVwE2fsikZCmpiy1D6p 0KSdXgwKvTCxAKyTAt8Y79MP2j9lLindQDSW9iJLwh3BpZcTo2MwsplyLr0i7gOLrcoB X7T6weYztMVBXMsZRnR6lS0z4ixFWt5nuvk04fFEafcO2I5YK2yAHCK2XBPhSZ2GtKA0 0JQg== 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=BjeHFbhN+7Am2uICjQaFMBirxT9NzgzFU+oFo1cIHWM=; b=qpla0IsJQVvqXSMfPuN+HHQeIEXcmrWC4q01ZRTkosuXt1Td4sV/t/QHpkF2xA5DOt pe4kdFc67ETw2wMNUuW+d/CUtLDqy2YENKrV3sXtO4lie9+G4yuMjXJee8oPgMioVWiV BVZtg7khff8LvvTZ2rxL8LW4Ol4OocIL8Sfn/9+mPHuSuuPTuVmYaQZ8kJAJA7zgdJVY xeWjPJt2PNiGBNA4iO1X/hiRpoe7Ck5SeTG5XMmPbvM+i3OeFMsc9JXaRaW1PhlDlRYa UxDDnvnMHqQV9DPTUSQvUTJd6zbJmfeU8U0iGozL6c8VXavAygIgDi1vrglHsCI36eZV uEMg== X-Gm-Message-State: AHQUAuZkPRvAEBW/VIJZQPWwwkHaGcF5Rzp/ZvOVcBJPGxIs3iAwCGY3 aVkV9qpNwTW+J3ahVXDoFNK1HVfy X-Google-Smtp-Source: AHgI3IaKNsWuE49w5KGEl4BwQZFk2AdbxXag1No/y0O5cxOF0S1Lbau0E29w/in1KMbBLCMx3elL7A== X-Received: by 2002:a17:902:e3:: with SMTP id a90mr99502pla.45.1551241824955; Tue, 26 Feb 2019 20:30:24 -0800 (PST) Received: from localhost.au.ibm.com ([43.245.162.131]) by smtp.gmail.com with ESMTPSA id k18sm9203642pfj.92.2019.02.26.20.30.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 20:30:24 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Wed, 27 Feb 2019 15:30:07 +1100 Message-Id: <20190227043008.12059-3-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20190227043008.12059-1-sjitindarsingh@gmail.com> References: <20190227043008.12059-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 v2 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 --- 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 32f68cbd9e..1e76685199 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -406,8 +406,16 @@ 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); + } } } @@ -418,6 +426,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=off"); + } + 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;