From patchwork Tue Feb 26 03:05:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10829355 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 45C3D13B5 for ; Tue, 26 Feb 2019 03:07:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B9582A924 for ; Tue, 26 Feb 2019 03:07:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D6F42A9F8; Tue, 26 Feb 2019 03:07:18 +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 DD6FC2A924 for ; Tue, 26 Feb 2019 03:07:16 +0000 (UTC) Received: from localhost ([127.0.0.1]:47466 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT5P-0004e2-NV for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Feb 2019 22:07:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT4B-0003mP-F2 for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyT49-0007e7-GW for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:05:58 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:34060) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyT43-0007ZZ-UR; Mon, 25 Feb 2019 22:05:53 -0500 Received: by mail-pg1-x543.google.com with SMTP id i130so5490215pgd.1; Mon, 25 Feb 2019 19:05:51 -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; bh=WQDXkCmh5rBijD/gAa3omNNQKSohMAjO2v9mmnrwUjI=; b=pk7PCkttXFKPByoCW5Y7gy6+l8m3Sw4FeriUvWdOka6uyL7xU7X7CCTsIizpnmZwME q5Ipl/V1k99l0fLRjQNSn7TE2+13tA5YLSYO+iUNqf8yLWPjQKaHSKIkh6+jn7TgXXdS QEuheXopR07i7iFarHIWkjxyNFts4Dpu4e/aDxUZdq791+0lLvNG2KhiGVVgO7nbaLK7 +hSRJkvNbiqZdtKqUlxHwdabHrlDopn8K3fK8wrnztw+hjwPwbbnkVMe+Ukmk8yCuYyt lLS30/hwkdne026bqaF3JGQPKnddFvJcRRKhoD2QlDK0lw/wFQYGeK5BT/+axTksgopQ vBoA== 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; bh=WQDXkCmh5rBijD/gAa3omNNQKSohMAjO2v9mmnrwUjI=; b=lyBvRFj+G9jTvUEcPe02WRZ7LkyO/8WJWR8oe2rwYrQVBcH/C1KyLm6UGLmIWbwE26 vJWaouWKaju9ejhe6WdB3r3tKEQtfh8/HTSai0ujTnK8Iq6C8aj2jVHu9E5TWAeJb0SJ FNSaxRoOjQtfwClD+bFlGPUbfAReikqlzHk+7NuvelJ1LoMW3WnVtANBJ+24xTsbvLbi CYo0mkgja/EBYtrOP7JPdWM+Jce4atHaw4156UPTybWTweENrN7Y6lzjSqj8hSxRMAmA uJJ6fexZX8yXjPZQJE4eKQaz9GFEoQw4kjW2MbSTyxVw+B3F18wFbCHobXv+4mElWLDG 6L4g== X-Gm-Message-State: AHQUAuatiNTFgyBFOeOxfJxl2NmGwW0C71aCWWG16pvvjVNleGbOIpld f9OFbDP2pp6foZJJel0yIArM2eMH X-Google-Smtp-Source: AHgI3Ia0tSzCQecoTAe2SfNa7pID5trLJMY4it+angliR+G90tZIa83kJKWKLbe4cLp/bxkLL/8jMQ== X-Received: by 2002:a62:4684:: with SMTP id o4mr2637607pfi.254.1551150350192; Mon, 25 Feb 2019 19:05:50 -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.47 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Feb 2019 19:05:49 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Tue, 26 Feb 2019 14:05:28 +1100 Message-Id: <20190226030531.9932-1-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.13.6 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 1/4] target/ppc/spapr: Add SPAPR_CAP_LARGE_DECREMENTER 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 Add spapr_cap SPAPR_CAP_LARGE_DECREMENTER to be used to control the availability and size of the large decrementer made available to the guest. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_caps.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 5 ++++- 3 files changed, 51 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index b6a571b6f1..acf62a2b9f 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2077,6 +2077,7 @@ static const VMStateDescription vmstate_spapr = { &vmstate_spapr_irq_map, &vmstate_spapr_cap_nested_kvm_hv, &vmstate_spapr_dtb, + &vmstate_spapr_cap_large_decr, NULL } }; @@ -4288,6 +4289,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) smc->default_caps.caps[SPAPR_CAP_IBS] = SPAPR_CAP_BROKEN; smc->default_caps.caps[SPAPR_CAP_HPT_MAXPAGESIZE] = 16; /* 64kiB */ smc->default_caps.caps[SPAPR_CAP_NESTED_KVM_HV] = SPAPR_CAP_OFF; + smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = 0; spapr_caps_add_properties(smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true; diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 64f98ae68d..1545a02729 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -182,6 +182,34 @@ static void spapr_cap_set_pagesize(Object *obj, Visitor *v, const char *name, spapr->eff.caps[cap->index] = val; } +static void spapr_cap_get_uint8(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + sPAPRCapabilityInfo *cap = opaque; + sPAPRMachineState *spapr = SPAPR_MACHINE(obj); + uint8_t val = spapr_get_cap(spapr, cap->index); + + visit_type_uint8(v, name, &val, errp); +} + +static void spapr_cap_set_uint8(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + sPAPRCapabilityInfo *cap = opaque; + sPAPRMachineState *spapr = SPAPR_MACHINE(obj); + Error *local_err = NULL; + uint8_t val; + + visit_type_uint8(v, name, &val, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + spapr->cmd_line_caps[cap->index] = true; + spapr->eff.caps[cap->index] = val; +} + static void cap_htm_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp) { if (!val) { @@ -390,6 +418,13 @@ static void cap_nested_kvm_hv_apply(sPAPRMachineState *spapr, } } +static void cap_large_decr_apply(sPAPRMachineState *spapr, + uint8_t val, Error **errp) +{ + if (val) + error_setg(errp, "No large decrementer support, try cap-large-decr=0"); +} + sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { [SPAPR_CAP_HTM] = { .name = "htm", @@ -468,6 +503,15 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_nested_kvm_hv_apply, }, + [SPAPR_CAP_LARGE_DECREMENTER] = { + .name = "large-decr", + .description = "Size of Large Decrementer for the Guest (bits) 0=disabled", + .index = SPAPR_CAP_LARGE_DECREMENTER, + .get = spapr_cap_get_uint8, + .set = spapr_cap_set_uint8, + .type = "int", + .apply = cap_large_decr_apply, + }, }; static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr, @@ -596,6 +640,7 @@ SPAPR_CAP_MIG_STATE(cfpc, SPAPR_CAP_CFPC); SPAPR_CAP_MIG_STATE(sbbc, SPAPR_CAP_SBBC); SPAPR_CAP_MIG_STATE(ibs, SPAPR_CAP_IBS); SPAPR_CAP_MIG_STATE(nested_kvm_hv, SPAPR_CAP_NESTED_KVM_HV); +SPAPR_CAP_MIG_STATE(large_decr, SPAPR_CAP_LARGE_DECREMENTER); void spapr_caps_init(sPAPRMachineState *spapr) { diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 59073a7579..8efc5e0779 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -74,8 +74,10 @@ typedef enum { #define SPAPR_CAP_HPT_MAXPAGESIZE 0x06 /* Nested KVM-HV */ #define SPAPR_CAP_NESTED_KVM_HV 0x07 +/* Large Decrementer */ +#define SPAPR_CAP_LARGE_DECREMENTER 0x08 /* Num Caps */ -#define SPAPR_CAP_NUM (SPAPR_CAP_NESTED_KVM_HV + 1) +#define SPAPR_CAP_NUM (SPAPR_CAP_LARGE_DECREMENTER + 1) /* * Capability Values @@ -828,6 +830,7 @@ extern const VMStateDescription vmstate_spapr_cap_cfpc; extern const VMStateDescription vmstate_spapr_cap_sbbc; extern const VMStateDescription vmstate_spapr_cap_ibs; extern const VMStateDescription vmstate_spapr_cap_nested_kvm_hv; +extern const VMStateDescription vmstate_spapr_cap_large_decr; static inline uint8_t spapr_get_cap(sPAPRMachineState *spapr, int cap) { From patchwork Tue Feb 26 03:05:29 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: 10829361 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 A2B5E15AC for ; Tue, 26 Feb 2019 03:10:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 883DF2B338 for ; Tue, 26 Feb 2019 03:10:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7620C2AA4E; Tue, 26 Feb 2019 03:10:10 +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 81FD82AA4E for ; Tue, 26 Feb 2019 03:10:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:47503 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT8C-0006CU-Su for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Feb 2019 22:10:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT4H-0003tE-T2 for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyT4F-0007iA-EM for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:05 -0500 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]:44483) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyT49-0007bX-IJ; Mon, 25 Feb 2019 22:05:59 -0500 Received: by mail-pf1-x441.google.com with SMTP id a3so5465363pff.11; Mon, 25 Feb 2019 19:05:54 -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=Jj6lZWiiSlrOt4vVog8SmooRLMbEyS7xw1jh6oSDAjQ=; b=ucKrV6Dm7LcsRyu4hnARFiTV6jxJryOKd6e4YYRhIKqs/PfNN6awDNHozMQveZTdu1 imHG2Uz72antJfNf5yFTSHEsgkzR9Gd6ZbCCzcHbKIMbBrqQqRANyUxhUILmQyw1awCN tPgQlLZ+0o+fwszNS8mYyjXVsM1l5n3A75ucap7So9xbRAgjqvpq0N/0gqzEj6ZdIeNP zcEwriDgPRY5jb2J6tNmqSq3Tz+7u5t7If7Q4jCdEWz998TkNSXCquYMcjdmsqFaKb41 pPi3K3QYc446oin1v6zxcSFWPYF30kO3rwYmANShLQcIK67nkFRuU3xMYXeJC9tZp4W7 c7gg== 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=Jj6lZWiiSlrOt4vVog8SmooRLMbEyS7xw1jh6oSDAjQ=; b=Ite3v/RE1Vmipp8xIuZikE42+z/TkBjuw3CqocI7si2p4C3abX33eNuIjRtVVbZmL6 Ohqn6lyf6soZT2k9EbcD6NCxAQ85qS0pHyoKYwxmr+7EntEfOL75Cbfq2Goi8ja654IE IIffXqsmhN0BcGCxHuC22poD4vcB+9wux0eSfwHm3OM48BWlzbRteBZzq/x/WswcrkLX mlGGuD7C6jRWazwN4UErvzck16EtPUiqtuXXBW+LvsMOynBkRnfNkvlv+3hculObSmKa v1VyIcMNJefyAcYy0ew9BtS0i9FUCqDFORRl/94cY9/2Fhgo/ik5Au4VhRHbK8VjiNpR BkXA== X-Gm-Message-State: AHQUAuYjypjI+92/dGWg6gWRxWdRSoQHRkSNrA+fxAO2U3RJlWrNGZe5 QCXLA8GXPkIvFty+w5ssCNVDP9+S X-Google-Smtp-Source: AHgI3IYL/ZziYvUVmwUjB4Yd5zex+aaKUxTnPHd4cpB7O8G+JnWR5/U+WjkXtyrRuVfGz4w3DmAJOw== X-Received: by 2002:a62:449b:: with SMTP id m27mr23963491pfi.79.1551150353248; Mon, 25 Feb 2019 19:05:53 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Feb 2019 19:05:52 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Tue, 26 Feb 2019 14:05:29 +1100 Message-Id: <20190226030531.9932-2-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::441 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 2/4] target/ppc: Implement large decrementer support for TCG 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 Prior to POWER9 the decrementer was a 32-bit register which decremented with each tick of the timebase. From POWER9 onwards the decrementer can be set to operate in a mode called large decrementer where it acts as a n-bit decrementing register which is visible as a 64-bit register, that is the value of the decrementer is sign extended to 64 bits (where n is implementation dependant). The mode in which the decrementer operates is controlled by the LPCR_LD bit in the logical paritition control register (LPCR). From POWER9 onwards the HDEC (hypervisor decrementer) was enlarged to h-bits, also sign extended to 64 bits (where h is implementation dependant). Note this isn't configurable and is always enabled. For TCG we allow the user to configure a custom large decrementer size, so long as it's at least 32 and less than the size of the HDEC (the restrictions imposed by the ISA). Signed-off-by: Suraj Jitindar Singh Signed-off-by: Cédric Le Goater --- hw/ppc/ppc.c | 78 ++++++++++++++++++++++++++++------------- hw/ppc/spapr.c | 8 +++++ hw/ppc/spapr_caps.c | 38 +++++++++++++++++++- target/ppc/cpu-qom.h | 1 + target/ppc/cpu.h | 11 +++--- target/ppc/mmu-hash64.c | 2 +- target/ppc/translate.c | 2 +- target/ppc/translate_init.inc.c | 1 + 8 files changed, 109 insertions(+), 32 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index d1e3d4cd20..853afeed6a 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -744,10 +744,10 @@ bool ppc_decr_clear_on_delivery(CPUPPCState *env) return ((tb_env->flags & flags) == PPC_DECR_UNDERFLOW_TRIGGERED); } -static inline uint32_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) +static inline uint64_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) { ppc_tb_t *tb_env = env->tb_env; - uint32_t decr; + uint64_t decr; int64_t diff; diff = next - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); @@ -758,27 +758,42 @@ static inline uint32_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) } else { decr = -muldiv64(-diff, tb_env->decr_freq, NANOSECONDS_PER_SECOND); } - LOG_TB("%s: %08" PRIx32 "\n", __func__, decr); + LOG_TB("%s: %016" PRIx64 "\n", __func__, decr); return decr; } -uint32_t cpu_ppc_load_decr (CPUPPCState *env) +target_ulong cpu_ppc_load_decr (CPUPPCState *env) { ppc_tb_t *tb_env = env->tb_env; + uint64_t decr; if (kvm_enabled()) { return env->spr[SPR_DECR]; } - return _cpu_ppc_load_decr(env, tb_env->decr_next); + decr = _cpu_ppc_load_decr(env, tb_env->decr_next); + + /* + * If large decrementer is enabled then the decrementer is signed extened + * to 64 bits, otherwise it is a 32 bit value. + */ + if (env->spr[SPR_LPCR] & LPCR_LD) + return decr; + return (uint32_t) decr; } -uint32_t cpu_ppc_load_hdecr (CPUPPCState *env) +target_ulong cpu_ppc_load_hdecr (CPUPPCState *env) { ppc_tb_t *tb_env = env->tb_env; + uint64_t decr; - return _cpu_ppc_load_decr(env, tb_env->hdecr_next); + decr = _cpu_ppc_load_decr(env, tb_env->hdecr_next); + + /* If POWER9 or later then hdecr is sign extended to 64 bits otherwise 32 */ + if (env->mmu_model & POWERPC_MMU_3_00) + return decr; + return (uint32_t) decr; } uint64_t cpu_ppc_load_purr (CPUPPCState *env) @@ -832,13 +847,21 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, QEMUTimer *timer, void (*raise_excp)(void *), void (*lower_excp)(PowerPCCPU *), - uint32_t decr, uint32_t value) + target_ulong decr, target_ulong value, + int nr_bits) { CPUPPCState *env = &cpu->env; ppc_tb_t *tb_env = env->tb_env; uint64_t now, next; + bool negative; + + /* Truncate value to decr_width and sign extend for simplicity */ + value &= ((1ULL << nr_bits) - 1); + negative = !!(value & (1ULL << (nr_bits - 1))); + if (negative) + value |= (0xFFFFFFFFULL << nr_bits); - LOG_TB("%s: %08" PRIx32 " => %08" PRIx32 "\n", __func__, + LOG_TB("%s: " TARGET_FMT_lx " => " TARGET_FMT_lx "\n", __func__, decr, value); if (kvm_enabled()) { @@ -860,15 +883,15 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, * an edge interrupt, so raise it here too. */ if ((value < 3) || - ((tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL) && (value & 0x80000000)) || - ((tb_env->flags & PPC_DECR_UNDERFLOW_TRIGGERED) && (value & 0x80000000) - && !(decr & 0x80000000))) { + ((tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL) && negative) || + ((tb_env->flags & PPC_DECR_UNDERFLOW_TRIGGERED) && negative + && !(decr & (1ULL << (nr_bits - 1))))) { (*raise_excp)(cpu); return; } /* On MSB level based systems a 0 for the MSB stops interrupt delivery */ - if (!(value & 0x80000000) && (tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL)) { + if (!negative && (tb_env->flags & PPC_DECR_UNDERFLOW_LEVEL)) { (*lower_excp)(cpu); } @@ -881,21 +904,24 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, timer_mod(timer, next); } -static inline void _cpu_ppc_store_decr(PowerPCCPU *cpu, uint32_t decr, - uint32_t value) +static inline void _cpu_ppc_store_decr(PowerPCCPU *cpu, target_ulong decr, + target_ulong value, int nr_bits) { ppc_tb_t *tb_env = cpu->env.tb_env; __cpu_ppc_store_decr(cpu, &tb_env->decr_next, tb_env->decr_timer, tb_env->decr_timer->cb, &cpu_ppc_decr_lower, decr, - value); + value, nr_bits); } -void cpu_ppc_store_decr (CPUPPCState *env, uint32_t value) +void cpu_ppc_store_decr (CPUPPCState *env, target_ulong value) { PowerPCCPU *cpu = ppc_env_get_cpu(env); + int nr_bits = 32; + if ((env->spr[SPR_LPCR] & LPCR_LD) && (env->large_decr_bits > 32)) + nr_bits = env->large_decr_bits; - _cpu_ppc_store_decr(cpu, cpu_ppc_load_decr(env), value); + _cpu_ppc_store_decr(cpu, cpu_ppc_load_decr(env), value, nr_bits); } static void cpu_ppc_decr_cb(void *opaque) @@ -905,23 +931,25 @@ static void cpu_ppc_decr_cb(void *opaque) cpu_ppc_decr_excp(cpu); } -static inline void _cpu_ppc_store_hdecr(PowerPCCPU *cpu, uint32_t hdecr, - uint32_t value) +static inline void _cpu_ppc_store_hdecr(PowerPCCPU *cpu, target_ulong hdecr, + target_ulong value, int nr_bits) { ppc_tb_t *tb_env = cpu->env.tb_env; if (tb_env->hdecr_timer != NULL) { __cpu_ppc_store_decr(cpu, &tb_env->hdecr_next, tb_env->hdecr_timer, tb_env->hdecr_timer->cb, &cpu_ppc_hdecr_lower, - hdecr, value); + hdecr, value, nr_bits); } } -void cpu_ppc_store_hdecr (CPUPPCState *env, uint32_t value) +void cpu_ppc_store_hdecr (CPUPPCState *env, target_ulong value) { PowerPCCPU *cpu = ppc_env_get_cpu(env); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + int nr_bits = (pcc->hdecr_bits > 32) ? pcc->hdecr_bits : 32; - _cpu_ppc_store_hdecr(cpu, cpu_ppc_load_hdecr(env), value); + _cpu_ppc_store_hdecr(cpu, cpu_ppc_load_hdecr(env), value, nr_bits); } static void cpu_ppc_hdecr_cb(void *opaque) @@ -951,8 +979,8 @@ static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq) * if a decrementer exception is pending when it enables msr_ee at startup, * it's not ready to handle it... */ - _cpu_ppc_store_decr(cpu, 0xFFFFFFFF, 0xFFFFFFFF); - _cpu_ppc_store_hdecr(cpu, 0xFFFFFFFF, 0xFFFFFFFF); + _cpu_ppc_store_decr(cpu, 0xFFFFFFFF, 0xFFFFFFFF, 32); + _cpu_ppc_store_hdecr(cpu, 0xFFFFFFFF, 0xFFFFFFFF, 32); cpu_ppc_store_purr(cpu, 0x0000000000000000ULL); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index acf62a2b9f..966bc74e68 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -557,6 +557,14 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset, pcc->radix_page_info->count * sizeof(radix_AP_encodings[0])))); } + + /* + * We set this property to let the guest know that it can use the large + * decrementer and its width in bits. + */ + if (env->large_decr_bits) + _FDT((fdt_setprop_u32(fdt, offset, "ibm,dec-bits", + env->large_decr_bits))); } static void spapr_populate_cpus_dt_node(void *fdt, sPAPRMachineState *spapr) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 1545a02729..44542fdbb2 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -421,8 +421,43 @@ static void cap_nested_kvm_hv_apply(sPAPRMachineState *spapr, static void cap_large_decr_apply(sPAPRMachineState *spapr, uint8_t val, Error **errp) { - if (val) + PowerPCCPU *cpu = POWERPC_CPU(first_cpu); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + + if (!val) + return; /* Disabled by default */ + + if (tcg_enabled()) { + if (!ppc_check_compat(cpu, CPU_POWERPC_LOGICAL_3_00, 0, + spapr->max_compat_pvr)) { + error_setg(errp, + "Large decrementer only supported on POWER9, try -cpu POWER9"); + return; + } + if ((val < 32) || (val > pcc->hdecr_bits)) { + error_setg(errp, + "Large decrementer size unsupported, try -cap-large-decr=%d", + pcc->hdecr_bits); + return; + } + } else { error_setg(errp, "No large decrementer support, try cap-large-decr=0"); + } +} + +static void cap_large_decr_cpu_apply(sPAPRMachineState *spapr, + PowerPCCPU *cpu, + uint8_t val, Error **errp) +{ + CPUPPCState *env = &cpu->env; + target_ulong lpcr = env->spr[SPR_LPCR]; + + if (val) + lpcr |= LPCR_LD; + else + lpcr &= ~LPCR_LD; + ppc_store_lpcr(cpu, lpcr); + env->large_decr_bits = val; } sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { @@ -511,6 +546,7 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .set = spapr_cap_set_uint8, .type = "int", .apply = cap_large_decr_apply, + .cpu_apply = cap_large_decr_cpu_apply, }, }; diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h index ae51fe754e..cced705e30 100644 --- a/target/ppc/cpu-qom.h +++ b/target/ppc/cpu-qom.h @@ -190,6 +190,7 @@ typedef struct PowerPCCPUClass { #endif const PPCHash64Options *hash64_opts; struct ppc_radix_page_info *radix_page_info; + uint32_t hdecr_bits; void (*init_proc)(CPUPPCState *env); int (*check_pow)(CPUPPCState *env); int (*handle_mmu_fault)(PowerPCCPU *cpu, vaddr eaddr, int rwx, int mmu_idx); diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 26604ddf98..8da333e9da 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1171,6 +1171,9 @@ struct CPUPPCState { uint32_t tm_vscr; uint64_t tm_dscr; uint64_t tm_tar; + + /* Large Decrementer */ + int large_decr_bits; }; #define SET_FIT_PERIOD(a_, b_, c_, d_) \ @@ -1321,10 +1324,10 @@ uint32_t cpu_ppc_load_atbu (CPUPPCState *env); void cpu_ppc_store_atbl (CPUPPCState *env, uint32_t value); void cpu_ppc_store_atbu (CPUPPCState *env, uint32_t value); bool ppc_decr_clear_on_delivery(CPUPPCState *env); -uint32_t cpu_ppc_load_decr (CPUPPCState *env); -void cpu_ppc_store_decr (CPUPPCState *env, uint32_t value); -uint32_t cpu_ppc_load_hdecr (CPUPPCState *env); -void cpu_ppc_store_hdecr (CPUPPCState *env, uint32_t value); +target_ulong cpu_ppc_load_decr (CPUPPCState *env); +void cpu_ppc_store_decr (CPUPPCState *env, target_ulong value); +target_ulong cpu_ppc_load_hdecr (CPUPPCState *env); +void cpu_ppc_store_hdecr (CPUPPCState *env, target_ulong value); uint64_t cpu_ppc_load_purr (CPUPPCState *env); uint32_t cpu_ppc601_load_rtcl (CPUPPCState *env); uint32_t cpu_ppc601_load_rtcu (CPUPPCState *env); diff --git a/target/ppc/mmu-hash64.c b/target/ppc/mmu-hash64.c index c431303eff..a2b1ec5040 100644 --- a/target/ppc/mmu-hash64.c +++ b/target/ppc/mmu-hash64.c @@ -1109,7 +1109,7 @@ void ppc_store_lpcr(PowerPCCPU *cpu, target_ulong val) case POWERPC_MMU_3_00: /* P9 */ lpcr = val & (LPCR_VPM1 | LPCR_ISL | LPCR_KBV | LPCR_DPFD | (LPCR_PECE_U_MASK & LPCR_HVEE) | LPCR_ILE | LPCR_AIL | - LPCR_UPRT | LPCR_EVIRT | LPCR_ONL | LPCR_HR | + LPCR_UPRT | LPCR_EVIRT | LPCR_ONL | LPCR_HR | LPCR_LD | (LPCR_PECE_L_MASK & (LPCR_PDEE | LPCR_HDEE | LPCR_EEE | LPCR_DEE | LPCR_OEE)) | LPCR_MER | LPCR_GTSE | LPCR_TC | LPCR_HEIC | LPCR_LPES0 | LPCR_HVICE | LPCR_HDICE); diff --git a/target/ppc/translate.c b/target/ppc/translate.c index 819221f246..b156be4d98 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -7417,7 +7417,7 @@ void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, #if !defined(NO_TIMER_DUMP) cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 #if !defined(CONFIG_USER_ONLY) - " DECR %08" PRIu32 + " DECR " TARGET_FMT_lu #endif "\n", cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index 58542c0fe0..4e0bf1f47a 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -8926,6 +8926,7 @@ POWERPC_FAMILY(POWER9)(ObjectClass *oc, void *data) /* segment page size remain the same */ pcc->hash64_opts = &ppc_hash64_opts_POWER7; pcc->radix_page_info = &POWER9_radix_page_info; + pcc->hdecr_bits = 56; #endif pcc->excp_model = POWERPC_EXCP_POWER9; pcc->bus_model = PPC_FLAGS_INPUT_POWER9; 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; From patchwork Tue Feb 26 03:05:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 10829357 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 16B8215AC for ; Tue, 26 Feb 2019 03:07:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 043F52A924 for ; Tue, 26 Feb 2019 03:07:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC1D52A9F8; Tue, 26 Feb 2019 03:07: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 A29C62A924 for ; Tue, 26 Feb 2019 03:07:19 +0000 (UTC) Received: from localhost ([127.0.0.1]:47468 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT5S-0004gG-Ud for patchwork-qemu-devel@patchwork.kernel.org; Mon, 25 Feb 2019 22:07:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyT4F-0003qe-Rq for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyT4F-0007hs-3g for qemu-devel@nongnu.org; Mon, 25 Feb 2019 22:06:03 -0500 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]:41206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyT4D-0007gK-F0; Mon, 25 Feb 2019 22:06:01 -0500 Received: by mail-pl1-x643.google.com with SMTP id y5so5480596plk.8; Mon, 25 Feb 2019 19:06:00 -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; bh=RP4PmwQRzdsB1yZhZry1b6YePNqWvjkg4wt30WSqpRg=; b=SjM5h0O5sLjmN8QTM1Tac88B/Zo1hjMSxVWWSi7sZmwxhDTcliQyHYTV8xMj1fO2Ih nF3YPHGi+vK69WO4sPrMlOT8h4sxmRpsJSJwBRyOXxt9vv+lr3v01p9VvgS9goktu8Zc tg1NtSW0W60WcPvhe2FIghn5UsPTlBIaFnilbqxKoi2enw1VjZuBQ9FzTSieFGXmYCme wlKuNrALiebGUxqmibLMUHrJTGV6dMBe7H4evRYUUXmJuWHKnWiB/AV/IZi0Sepfc+xt ZRaEqPWI/YuV7H4F0ncSCxCBffeuSVT82UrezndH9st4pgXz/PaS9gZeRLaZyIOpkwQh 1P/A== 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; bh=RP4PmwQRzdsB1yZhZry1b6YePNqWvjkg4wt30WSqpRg=; b=Az+ia35u3hgpKQdWyOS8bIvupTHh8oywAyhqt7LNp9nDI/j2OmwXLTuUESlwjnbIU9 8bizrRO6Yaf0oe7FR4zff+6Lmv+HZ87gN1aziNdMEindxI47LVoq9xA7QLP0wH4lBnQw uwLlMndYqNMZlQrmoS6Q5wvf467AIkVfsU+aoI7hNHRlY9EK1yY90pI0CtmOWN5j3AQV Gyv7NLegmMNgXBSeF8LhDC1jPDg1vtUPZse7p9A3BMiEJp4dkNvleUm5eYY/2LuMLbHo lvA6lxvb/MZ22fpg4OA0TEw8Hht1HADVmGXgWS07VP1o0i9VTh2Y55Nwj1PmEW+IYLxi h6HQ== X-Gm-Message-State: AHQUAua4QDzZARzwrTuoduYYb2ySb0u80/9z7joyyMTHxPUC8CgkOkoT 2+OwGMGMo5G19u4M4ZrPQKUwpZjd X-Google-Smtp-Source: AHgI3IaSXWprnR6DAP3vozVGzdJLT+ytskBvEsj+iNpqQMNA3Yh70WPhEaEiI/aV5vOJdMwHhMKn+A== X-Received: by 2002:a17:902:8692:: with SMTP id g18mr23294403plo.149.1551150358823; Mon, 25 Feb 2019 19:05:58 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Feb 2019 19:05:58 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Tue, 26 Feb 2019 14:05:31 +1100 Message-Id: <20190226030531.9932-4-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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::643 Subject: [Qemu-devel] [QEMU-PPC] [PATCH 4/4] target/ppc/spapr: Enable the large decrementer by default on POWER9 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 Enable the large decrementer by default on POWER9 cpu models. The default value applied is that provided in the cpu class. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr_caps.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index e07568fb94..f48aa367e3 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -566,11 +566,18 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr, const char *cputype) { + PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(object_class_by_name(cputype)); sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(spapr); sPAPRCapabilities caps; caps = smc->default_caps; + caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = pcc->hdecr_bits; + if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_3_00, + 0, spapr->max_compat_pvr)) { + caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = 0; + } + if (!ppc_type_check_compat(cputype, CPU_POWERPC_LOGICAL_2_07, 0, spapr->max_compat_pvr)) { caps.caps[SPAPR_CAP_HTM] = SPAPR_CAP_OFF;