From patchwork Thu Jun 8 07:03:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suraj Jitindar Singh X-Patchwork-Id: 9773991 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CFB8B60393 for ; Thu, 8 Jun 2017 07:05:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF34C283BD for ; Thu, 8 Jun 2017 07:05:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B3E0B284F4; Thu, 8 Jun 2017 07:05:55 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 32299283BD for ; Thu, 8 Jun 2017 07:05:55 +0000 (UTC) Received: from localhost ([::1]:47791 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIrVy-0000YK-8t for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Jun 2017 03:05:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57299) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIrUX-0000V0-Fv for qemu-devel@nongnu.org; Thu, 08 Jun 2017 03:04:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIrUW-0007eT-GU for qemu-devel@nongnu.org; Thu, 08 Jun 2017 03:04:25 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:34559) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIrUT-0007dX-Th; Thu, 08 Jun 2017 03:04:22 -0400 Received: by mail-pf0-x242.google.com with SMTP id u1so4105328pfg.1; Thu, 08 Jun 2017 00:04:21 -0700 (PDT) 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=+/qkyJDK9au2q5f+eV0qtQRbTaCfa26OXsBXR4bGmRU=; b=pf86kajZjnQOuxdXrEN6pduvFDZMjVKyBMa6U/GD+51RTK9vFvZiKNYCGU3J+rnUnX U/g9LKuRjvkqTCA7hdcv8fJiQxt+Y8EpQRow327SFi3MbUkudydxeUwIYWBo+BFxhsmp ZV7Bc2WFZTL7RYZgSL3TjWiI3ovvwOmNFi5z51vrv+S+9vFGwtcR803rMR4V+ZcoFn0w vLJs6oPxX06KgYctPGgS2IEsqAG3etJOyOLIa0Vl3gGosiTEowCos2uL4LBBhanZpNoo AFTyd5ut7ykwSVQygQPhv+dPGfqZF8jQcN3roB/CFBwwqb+5Xl6gumZpTnnNdECAQxhE hd7A== 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=+/qkyJDK9au2q5f+eV0qtQRbTaCfa26OXsBXR4bGmRU=; b=g3Fxjd+/Gwl3RPh4BQ29eDOd+ggo5sev6pWE5yQSYNRBop6psPGlwgpfkUMVWXO58U LMaRoOQT8OQwc/Mr6WRRE0X9+zISi5feL59R9AbsRPUWPO9+AhqSd6a1MmxUVOto2pfT qX1csOaJQInZ17aoDHiAv+hRsPmsxPKYAoAw/yje0NTw/PZnfTvOtDHVhSecMpXSNodb BgLmSrRYJKohAPh55XWpyFUbeWZDGZfi9iY4e8lo4b2YndQ7a2pjKQvJx9LBdLNH4XEu LLCCyV7vzRJmkInFrYv7CVjC0f2jHbJ3A5wcMnJSFnxML03JEEBmjCVujiReZUCclXxe x7vg== X-Gm-Message-State: AODbwcDFMLONIIY4X4CzfewfwaKV/ICSVghM/NzKIbnO/Y8LG33Armo9 Ia2r5XwH/mj/lzr/ X-Received: by 10.98.8.142 with SMTP id 14mr36014284pfi.35.1496905460886; Thu, 08 Jun 2017 00:04:20 -0700 (PDT) Received: from surajjs1.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id p76sm8568188pfl.24.2017.06.08.00.04.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 00:04:20 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Thu, 8 Jun 2017 17:03:50 +1000 Message-Id: <20170608070351.1434-5-sjitindarsingh@gmail.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170608070351.1434-1-sjitindarsingh@gmail.com> References: <20170608070351.1434-1-sjitindarsingh@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::242 Subject: [Qemu-devel] [PATCH 4/5] target/ppc: Enable the large decrementer for TCG and KVM guests 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: agraf@suse.de, qemu-devel@nongnu.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 Let the guest use the large decrementer. We have support for TCG and KVM guests to use the large decrementer and to migrate guests using the large decrementer, so add the final bits to indicate this capability to the guest. The guest will use the large decrementer if the cpu model is >= POWER9 and the ibm,dec-bits device-tree property of the cpu node is present. Add the ibm,dec-bits property to the device-tree when the hypervisor can support it. After CAS enable the large decrementer if the guest is going to use it, this means setting the LPCR_LD bit. Signed-off-by: Suraj Jitindar Singh --- hw/ppc/spapr.c | 18 ++++++++++++++++++ hw/ppc/spapr_hcall.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 6ba869a..6f38939 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -554,6 +554,19 @@ 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. This means we must be on a processor + * with a large decrementer and the hypervisor must support it. In TCG the + * large decrementer is always supported, in KVM we check the hypervisor + * capability. + */ + if (pcc->large_decr_bits && ((!kvm_enabled()) || + kvmppc_has_cap_large_decr())) { + _FDT((fdt_setprop_u32(fdt, offset, "ibm,dec-bits", + pcc->large_decr_bits))); + } } static void spapr_populate_cpus_dt_node(void *fdt, sPAPRMachineState *spapr) @@ -1328,6 +1341,11 @@ static void ppc_spapr_reset(void) spapr_setup_hpt_and_vrma(spapr); } + /* We have to do this after vcpus are created since it calls ioctls */ + if (kvm_enabled()) { + kvmppc_check_cap_large_decr(); + } + qemu_devices_reset(); /* diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index aae5a62..c06421b 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1091,6 +1091,37 @@ static uint32_t cas_check_pvr(PowerPCCPU *cpu, target_ulong *addr, return best_compat; } +static void cas_enable_large_decr(PowerPCCPU *cpu, sPAPRMachineState *spapr) +{ + PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu); + bool guest_large_decr = false; + + if (cpu->compat_pvr) { + guest_large_decr = cpu->compat_pvr >= CPU_POWERPC_LOGICAL_3_00; + } else { + guest_large_decr = (cpu->env.spr[SPR_PVR] & CPU_POWERPC_POWER_SERVER_MASK) + >= CPU_POWERPC_POWER9_BASE; + } + + if (guest_large_decr && ((!kvm_enabled()) || + kvmppc_has_cap_large_decr())) { + CPUState *cs; + + CPU_FOREACH(cs) { + if (kvm_enabled()) { + kvmppc_configure_large_decrementer(cs, true); + } else { + set_spr(cs, SPR_LPCR, LPCR_LD, LPCR_LD); + } + } + + spapr->large_decr_bits = pcc->large_decr_bits; + } else { + /* By default the large decrementer is already disabled */ + spapr->large_decr_bits = 0; + } +} + static target_ulong h_client_architecture_support(PowerPCCPU *cpu, sPAPRMachineState *spapr, target_ulong opcode, @@ -1166,6 +1197,9 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, } spapr->cas_legacy_guest_workaround = !spapr_ovec_test(ov1_guest, OV1_PPC_3_00); + + cas_enable_large_decr(cpu, spapr); + if (!spapr->cas_reboot) { spapr->cas_reboot = (spapr_h_cas_compose_response(spapr, args[1], args[2],