From patchwork Wed Feb 27 04:30:05 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: 10831043 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 725A31575 for ; Wed, 27 Feb 2019 04:32:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 507B32D1FF for ; Wed, 27 Feb 2019 04:32:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 419BC2D209; Wed, 27 Feb 2019 04:32:04 +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 EDBA92D1FF for ; Wed, 27 Feb 2019 04:32:02 +0000 (UTC) Received: from localhost ([127.0.0.1]:37729 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqsz-0001Z5-IH for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Feb 2019 23:32:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqrf-0000bI-GF for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyqre-0008Qo-5v for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:39 -0500 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:36396) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyqrS-00086d-Na; Tue, 26 Feb 2019 23:30:28 -0500 Received: by mail-pl1-x644.google.com with SMTP id k2so7345770plt.3; Tue, 26 Feb 2019 20:30:19 -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=z009jlxilyphKgBm7mwL2ucTFQCVyXjWYX7AOpZ5zfI=; b=gMWSa1L+TuFd/Lhre7vmJsCE/mN7lMfT5b7zRaX/A3YBXQ7pgczK3fpYqRsb1gmsfq KWe0mxfJ034qBFCAlXDwYNKpP8V0s1VZqLqnRQhgEIKphQZBP3jbwUU2Am2nUvcsuxiI 6sn6uqzXAp3lcXExK0LEBO3PH9IZY0MyaklaiMmBNhZWNq/PUpdRM76E8W+OONf7mhpP VF0655oe9Inreh49LD3Xosud1H4DP2aMIOJIUVVf3AGdCM6075lVSCoOFmyXvv6Lb38B va6RypBWtRrWOgWDvbj4bn8RWRByKKZs1os8aq5uISYfd7WO2HgG5eGbFrvBl5iNfXVA llUg== 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=z009jlxilyphKgBm7mwL2ucTFQCVyXjWYX7AOpZ5zfI=; b=IdRyW8G4FPLJpSMSMTgDEUTTke1LDdoTEl5VoLlybhttuMuYK5nK8N6KG/lXL9oSmh 3ISW+fxXJ7/olAknTjdW9Np07EHmgFM3aAZLiWZukLmDgp9HP4/6rFm50vXZ+upG7ek5 W/21+LwkQ4vJzq/9AFl1Nqz17ScqGPflGo0X2Ag/B5TW4nHXqRVjWkgXEB8naPqGJ0cF yvm5Q2UTBQ6GvyVe46wqlnVxWiuejg04HxqugALaIrjMhp7oxnE/NhtSa9V7MnpX+BXg bM/NEHUJfElEZDxNoom6FPWrYWC7+DXyA8ivl1Q/PHpYWJ4n3cbTdfRbs5aUweJxDPpS bQIA== X-Gm-Message-State: AHQUAub5m656HEWD7CVbZyv5/ynY5+hrX9kR1a4XsWZ6MCQmn05TjswI k0G9ZKuYgav9Z2l5Jxmgh6aP6jxC X-Google-Smtp-Source: AHgI3IZAMp0vhFeXaMGp4LtvgJyr3/kcCGczEj9eErd0CTT8wxL0bFOqPa16yMLK+kKlcVybKBOXjw== X-Received: by 2002:a17:902:f83:: with SMTP id 3mr94699plz.125.1551241817988; Tue, 26 Feb 2019 20:30:17 -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.14 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 20:30:17 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Wed, 27 Feb 2019 15:30:05 +1100 Message-Id: <20190227043008.12059-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::644 Subject: [Qemu-devel] [QEMU-PPC] [PATCH v2 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 of the large decrementer for a guest. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr.c | 2 ++ hw/ppc/spapr_caps.c | 17 +++++++++++++++++ include/hw/ppc/spapr.h | 5 ++++- 3 files changed, 23 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..3f90f5823e 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -390,6 +390,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=off"); +} + sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { [SPAPR_CAP_HTM] = { .name = "htm", @@ -468,6 +475,15 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .type = "bool", .apply = cap_nested_kvm_hv_apply, }, + [SPAPR_CAP_LARGE_DECREMENTER] = { + .name = "large-decr", + .description = "Allow Large Decrementer", + .index = SPAPR_CAP_LARGE_DECREMENTER, + .get = spapr_cap_get_bool, + .set = spapr_cap_set_bool, + .type = "bool", + .apply = cap_large_decr_apply, + }, }; static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr, @@ -596,6 +612,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 Wed Feb 27 04:30:06 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: 10831047 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 C5E201575 for ; Wed, 27 Feb 2019 04:34:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A2A7A2C7CB for ; Wed, 27 Feb 2019 04:34:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 967B42C855; Wed, 27 Feb 2019 04:34: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 8A6822C7CB for ; Wed, 27 Feb 2019 04:34:09 +0000 (UTC) Received: from localhost ([127.0.0.1]:37743 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqv2-0002m5-TF for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Feb 2019 23:34:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqrl-0000fj-2v for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyqrj-0008Uc-1k for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:44 -0500 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]:43122) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyqra-0008A7-Bb; Tue, 26 Feb 2019 23:30:37 -0500 Received: by mail-pg1-x541.google.com with SMTP id l11so7281594pgq.10; Tue, 26 Feb 2019 20:30:22 -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=/icmbNKENPo/ILUZCXX/MVLYMZVvYejcQSv+0/OPxTg=; b=AMqR2JN4Bph80O6g8qvDt0dnKl3YQIK4kGjrYk3H1dnR96RHjselTmCXcOfnNRAyV0 XUYPiQkk+GBKkq4TScO8FspjzLkquNDlD4g/JL8pB2MxKyodwM+saeudBZM9BtS1eqKw z86BOXq9TDTqQ0Hn+8wkrtoN9kPVJWhPZoNTx2HlCTVbxBTht+lOjWqVSkFUK0CqTJjJ dA0LeOWNUFqKEwCDDumbNR6wCU7oy0WdR3TQfZJxBRoAf9oVzoHpfEYBiMUAYAAd9pbz /sDuNRpx9rzsdJ9dn6YqvVBhlE3qiMliCbg5oCEEcQmDY2ORI7YomPiT2iHWbntnGVfg GPFQ== 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=/icmbNKENPo/ILUZCXX/MVLYMZVvYejcQSv+0/OPxTg=; b=PT8TgmZBzAfXuTiAuyLZtmy45zbPLtPruM7QejKWKpt8vxO+re0bNZIwg7SUF6OHNS kgeCdQ04V2cRFOv1KxZKVEnROjGnSGhVaowTh7Wmm4RRJrKzD3tMwAqOXjD9qVgbJcXi DpWajgPgMyFX4Pa2DxFPwE1E6XF8mWDrzCihHhaCd/Zp/Srz6ZHa688YeAE4/7m17A7E tlliwpttibUrKy4VhWhXeqS8I3CbMxN8f9lSj2pN8x5sI0yVgTcevfKQvjYKQKLHabKA fk7AZJAmSO1KEpPArW2CQBOD4qHnOXJYC9NCjHnqvvv9pCB/G5WtifwEvoSqOHByWL58 t90A== X-Gm-Message-State: AHQUAuYDP9yNAQP+73ZsP3pGTD9e250iqET0hSgjGRD3XkOhfH67/wUD QvCTqfW8v3LCInY3bGyPuiAH7XjG X-Google-Smtp-Source: AHgI3Ibvr/6VRhoyze5SgonzZcrSr4jryBz8vK6W/BVbyuA7y0vkyCEP2UOe0jNq+ucTGhNFHxzHGw== X-Received: by 2002:a63:d49:: with SMTP id 9mr1058741pgn.27.1551241821529; Tue, 26 Feb 2019 20:30:21 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 20:30:20 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Wed, 27 Feb 2019 15:30:06 +1100 Message-Id: <20190227043008.12059-2-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::541 Subject: [Qemu-devel] [QEMU-PPC] [PATCH v2 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. On POWER9 the large decrementer and hdec are both 56 bits, as represented by the lrg_decr_bits cpu class property. Since they are the same size we only add one property for now, which could be extended in the case they ever differ in the future. We also add the lrg_decr_bits property for POWER5+/7/8 since it is used to determine the size of the hdec, which is only generated on the POWER5+ processor and later. On these processors it is 32 bits. Signed-off-by: Suraj Jitindar Singh Signed-off-by: Cédric Le Goater --- hw/ppc/ppc.c | 85 ++++++++++++++++++++++++++++------------- hw/ppc/spapr.c | 8 ++++ hw/ppc/spapr_caps.c | 31 ++++++++++++++- target/ppc/cpu-qom.h | 1 + target/ppc/cpu.h | 8 ++-- target/ppc/mmu-hash64.c | 2 +- target/ppc/translate.c | 2 +- target/ppc/translate_init.inc.c | 4 ++ 8 files changed, 108 insertions(+), 33 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index d1e3d4cd20..9145aeddcb 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -744,11 +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 int64_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) { ppc_tb_t *tb_env = env->tb_env; - uint32_t decr; - int64_t diff; + int64_t decr, diff; diff = next - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); if (diff >= 0) { @@ -758,27 +757,47 @@ 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) { + PowerPCCPU *cpu = ppc_env_get_cpu(env); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); ppc_tb_t *tb_env = env->tb_env; + uint64_t hdecr; - return _cpu_ppc_load_decr(env, tb_env->hdecr_next); + hdecr = _cpu_ppc_load_decr(env, tb_env->hdecr_next); + + /* + * If we have a large decrementer (POWER9 or later) then hdecr is sign + * extended to 64 bits, otherwise it is 32 bits. + */ + if (pcc->lrg_decr_bits > 32) + return hdecr; + return (uint32_t) hdecr; } uint64_t cpu_ppc_load_purr (CPUPPCState *env) @@ -832,13 +851,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 +887,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 +908,25 @@ 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); + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + int nr_bits = 32; + if (env->spr[SPR_LPCR] & LPCR_LD) + nr_bits = pcc->lrg_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 +936,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); - _cpu_ppc_store_hdecr(cpu, cpu_ppc_load_hdecr(env), value); + _cpu_ppc_store_hdecr(cpu, cpu_ppc_load_hdecr(env), value, + pcc->lrg_decr_bits); } static void cpu_ppc_hdecr_cb(void *opaque) @@ -951,8 +984,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..ff5ba59cc0 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 (spapr_get_cap(spapr, SPAPR_CAP_LARGE_DECREMENTER)) + _FDT((fdt_setprop_u32(fdt, offset, "ibm,dec-bits", + pcc->lrg_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 3f90f5823e..32f68cbd9e 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -393,8 +393,36 @@ 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; + } + } else { error_setg(errp, "No large decrementer support, try cap-large-decr=off"); + } +} + +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); } sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { @@ -483,6 +511,7 @@ sPAPRCapabilityInfo capability_table[SPAPR_CAP_NUM] = { .set = spapr_cap_set_bool, .type = "bool", .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..be9b4c30c3 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 lrg_decr_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..81763d72f9 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1321,10 +1321,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..af70a3b78c 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -8376,6 +8376,7 @@ POWERPC_FAMILY(POWER5P)(ObjectClass *oc, void *data) #if defined(CONFIG_SOFTMMU) pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault; pcc->hash64_opts = &ppc_hash64_opts_basic; + pcc->lrg_decr_bits = 32; #endif pcc->excp_model = POWERPC_EXCP_970; pcc->bus_model = PPC_FLAGS_INPUT_970; @@ -8550,6 +8551,7 @@ POWERPC_FAMILY(POWER7)(ObjectClass *oc, void *data) #if defined(CONFIG_SOFTMMU) pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault; pcc->hash64_opts = &ppc_hash64_opts_POWER7; + pcc->lrg_decr_bits = 32; #endif pcc->excp_model = POWERPC_EXCP_POWER7; pcc->bus_model = PPC_FLAGS_INPUT_POWER7; @@ -8718,6 +8720,7 @@ POWERPC_FAMILY(POWER8)(ObjectClass *oc, void *data) #if defined(CONFIG_SOFTMMU) pcc->handle_mmu_fault = ppc_hash64_handle_mmu_fault; pcc->hash64_opts = &ppc_hash64_opts_POWER7; + pcc->lrg_decr_bits = 32; #endif pcc->excp_model = POWERPC_EXCP_POWER8; pcc->bus_model = PPC_FLAGS_INPUT_POWER7; @@ -8926,6 +8929,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->lrg_decr_bits = 56; #endif pcc->excp_model = POWERPC_EXCP_POWER9; pcc->bus_model = PPC_FLAGS_INPUT_POWER9; 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; From patchwork Wed Feb 27 04:30:08 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: 10831045 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 23D6D13B5 for ; Wed, 27 Feb 2019 04:32:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EA4A2D1FF for ; Wed, 27 Feb 2019 04:32:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 016812D209; Wed, 27 Feb 2019 04:32:21 +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 9CDD92D1FF for ; Wed, 27 Feb 2019 04:32:21 +0000 (UTC) Received: from localhost ([127.0.0.1]:37731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqtI-0001im-RU for patchwork-qemu-devel@patchwork.kernel.org; Tue, 26 Feb 2019 23:32:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48106) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyqrj-0000fg-1k for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyqrh-0008Tn-50 for qemu-devel@nongnu.org; Tue, 26 Feb 2019 23:30:42 -0500 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:42650) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyqre-0008EB-Gv; Tue, 26 Feb 2019 23:30:38 -0500 Received: by mail-pl1-x636.google.com with SMTP id v11so1916091plg.9; Tue, 26 Feb 2019 20:30:29 -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=hDS45rUlD2G2PkXn682BysQkY5AvQdxmLuVDOsB6cqM=; b=rR3pZtohu00yXoyi1Yf70kPGSY30elg8T6raAmQos/lL00DcKfMo3VBTblYtqM9kbD MU207nhQrEaGwm5QXo8M/cCnXtTeywVKXvEPNYa1+Bq+QhIIsnabFqicjgzHPq5SHJdm 7DK9bgY5i8DQ7Tsd6Any5Pts+Zz0sHChaOEfwf87VsJQ39kmdNsviPF+dtT/fN+XHL5c kXowlEdeol4b/YU3H6IfuwVfADy8Q51berSN01XX3qdE2XOBbJJxs3oLegMIse5TqmD8 7B7e9VAxQabR7Pjv+SP7XPEFFH4CXiDutYqyja3QgKoPrRazTAXZvQP8X9dSgOiAhiDn vcWA== 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=hDS45rUlD2G2PkXn682BysQkY5AvQdxmLuVDOsB6cqM=; b=SMb/nUdnYfvuvHYb+1dkqUVviUVm9ZrsPeWqYCWMRLqW8p4dGnVy71AYEHLNJWnXCC WaRUJZW8wOKMuw2k2JvCg0c+LdtBpb4vdqE5MBBGj0vtqojmvzhQDsM9dlSRJ8O2z7/r LMDk4K8jUoxV2rzp4DHA59PX8Sojs8LTDmtstzllcoBPKSZ6422nbPdGAPDTBJMXGib6 dFmRgAeBR/UJG8PMsOA6CWCVDaZaZvjO2tuzvBLmheRlskymtJXcKVXm3p8O8/Qgqd8i Wdpqam2P8g4iGCoJ1N7bIbK1BNkHKhmakY9nDI0PzFzsA5QnhTEOP/83pdk/LQUopJKG 8dFw== X-Gm-Message-State: AHQUAuYFP8wt5CjklVfdm97BXnWICKX6zsB1tqSkhFZbQN7+SsSuXlHr iuuZZNwnzNYSdlvkNQKxcCsTdDgG X-Google-Smtp-Source: AHgI3IaH9twT6OUfiUXUIgtOxYEiNdqXqI3O2EhyRp+pA9cEcPSaKFbbkm2/4U4ohI7pumuTn4BfcA== X-Received: by 2002:a17:902:7688:: with SMTP id m8mr112355pll.248.1551241828223; Tue, 26 Feb 2019 20:30:28 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Feb 2019 20:30:27 -0800 (PST) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Wed, 27 Feb 2019 15:30:08 +1100 Message-Id: <20190227043008.12059-4-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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::636 Subject: [Qemu-devel] [QEMU-PPC] [PATCH v2 4/4] target/ppc/spapr: Enable the large decrementer for pseries-4.0 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 for the pseries-4.0 machine type. It is disabled again by default_caps_with_cpu() for pre-POWER9 cpus since they don't support the large decrementer. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr.c | 3 ++- hw/ppc/spapr_caps.c | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index ff5ba59cc0..bbfaca3b05 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4297,7 +4297,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; + smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = 1; spapr_caps_add_properties(smc, &error_abort); smc->irq = &spapr_irq_xics; smc->dr_phb_enabled = true; @@ -4373,6 +4373,7 @@ static void spapr_machine_3_1_class_options(MachineClass *mc) mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("power8_v2.0"); smc->update_dt_enabled = false; smc->dr_phb_enabled = false; + smc->default_caps.caps[SPAPR_CAP_LARGE_DECREMENTER] = 0; } DEFINE_SPAPR_MACHINE(3_1, "3.1", false); diff --git a/hw/ppc/spapr_caps.c b/hw/ppc/spapr_caps.c index 1e76685199..fbd5d35cd0 100644 --- a/hw/ppc/spapr_caps.c +++ b/hw/ppc/spapr_caps.c @@ -536,6 +536,11 @@ static sPAPRCapabilities default_caps_with_cpu(sPAPRMachineState *spapr, caps = smc->default_caps; + 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;