From patchwork Thu Jun 8 07:03:48 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: 9773989 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 466E560393 for ; Thu, 8 Jun 2017 07:05:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35052283BD for ; Thu, 8 Jun 2017 07:05:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 27582284F4; Thu, 8 Jun 2017 07:05:53 +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 83E13283BD for ; Thu, 8 Jun 2017 07:05:52 +0000 (UTC) Received: from localhost ([::1]:47790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIrVv-0000WP-Gr for patchwork-qemu-devel@patchwork.kernel.org; Thu, 08 Jun 2017 03:05:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57263) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIrUV-0000SP-4e for qemu-devel@nongnu.org; Thu, 08 Jun 2017 03:04:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIrUR-0007cp-0Z for qemu-devel@nongnu.org; Thu, 08 Jun 2017 03:04:23 -0400 Received: from mail-pf0-x243.google.com ([2607:f8b0:400e:c00::243]:36456) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dIrUO-0007c9-88; Thu, 08 Jun 2017 03:04:16 -0400 Received: by mail-pf0-x243.google.com with SMTP id y7so4100956pfd.3; Thu, 08 Jun 2017 00:04:16 -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=Kl/dN2yGr4gVA12VPtofYbXkY7x2xy5nWJzM44+JO3w=; b=S+K61g2vW2bFquaYESuu1nHRICSjv+5Mv7QA3qUBIn2ifIEcr7izQFN/VzxLxJuHqw cw2/B84vTF2Pkw5z4aC44pOYDV8X6X+7i2KD0ImR4Ksbc6cN58AT6I0n+v4AY5Lx9Vp3 uH4erEIotuZt4KxlALUdzHzt3/ML23dz/vy7BVd/jjpH6nOIOMqAdtmMXJ0RnCsmbfL4 pbu+SSi1ekpv+bQkuWY+a0ZEUxmka/HF3yy5lZ+qh+M0M+YnU48gwu6IMZBcu4NVimb2 kszSkQGsXthyQrvgaifKfUDfpNhHlEipOhP5kDtBA76BuQDMG6DuRxPrt1+THNQ1I+rK 0WCw== 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=Kl/dN2yGr4gVA12VPtofYbXkY7x2xy5nWJzM44+JO3w=; b=VsxhZ78Ju9Qc90kpChi8bMCORhlsbic6/+kmxRkJ6YEC26I/Th8vtNZuz4/7/eHUzR YQRh5rzaU4dTz/EeupW46jbe+JMvUYBmnSLvTVg34t03T+cp6vtKuK/hfA9xJ0UhsWSY IDGcGE0IMl4DxWU7VPJD9UF/+zCuz93aJAJW8PWIJay3ykI57l3SdQTXDQDWWJk2T7rG inyGhV9J2Cccg+yHluqTgMn3BKIopYCqf32d7UhTGhmw1UFhYSPs2BRKhbx7zNHoRNYa bOzPrp+U+Sr8ZSPeQOGd+6Q8d7hhGUPGB3QNuCORsvBsQFhSTHxgUNUf7QtrK8KRe/uR xABQ== X-Gm-Message-State: AODbwcAQFq240IIc6fTqB7IVo1Le6B4nrJ+Eh5Of38me2TnWrl9VSBQE it5sdc6p1JBHtqeX X-Received: by 10.101.88.131 with SMTP id d3mr8240899pgu.21.1496905455037; Thu, 08 Jun 2017 00:04:15 -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.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Jun 2017 00:04:14 -0700 (PDT) From: Suraj Jitindar Singh To: qemu-ppc@nongnu.org Date: Thu, 8 Jun 2017 17:03:48 +1000 Message-Id: <20170608070351.1434-3-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::243 Subject: [Qemu-devel] [PATCH 2/5] 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: 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 The large decrementer is an operating mode of the decrementer. The decrementer is normally a 32-bit register. When operating in large decrementer mode the decrementer is a d-bit register which is sign extended to 64-bits (where d is implementation dependant). Implement support for a KVM guest to use the decrementer in large decrementer mode. This means adding functions to query the large decrementer support of the hypervisor and to enable the large decrementer with the hypervisor. Signed-off-by: Suraj Jitindar Singh --- target/ppc/kvm.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ target/ppc/kvm_ppc.h | 25 ++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 51249ce..b2c94a0 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -88,6 +88,7 @@ static int cap_fixup_hcalls; static int cap_htm; /* Hardware transactional memory support */ static int cap_mmu_radix; static int cap_mmu_hash_v3; +static int cap_large_decr; static uint32_t debug_inst_opcode; @@ -393,6 +394,19 @@ target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, } } +void kvmppc_configure_large_decrementer(CPUState *cs, bool enable_ld) +{ + uint64_t lpcr; + + kvm_get_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); + if (enable_ld) { + lpcr |= LPCR_LD; + } else { + lpcr &= LPCR_LD; + } + kvm_set_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); +} + static bool kvm_valid_page_size(uint32_t flags, long rampgsize, uint32_t shift) { if (!(flags & KVM_PPC_PAGE_SIZES_REAL)) { @@ -2004,6 +2018,11 @@ uint32_t kvmppc_get_dfp(void) return kvmppc_read_int_cpu_dt("ibm,dfp"); } +uint32_t kvmppc_get_dec_bits(void) +{ + return kvmppc_read_int_cpu_dt("ibm,dec-bits"); +} + static int kvmppc_get_pvinfo(CPUPPCState *env, struct kvm_ppc_pvinfo *pvinfo) { PowerPCCPU *cpu = ppc_env_get_cpu(env); @@ -2380,6 +2399,7 @@ static void kvmppc_host_cpu_class_init(ObjectClass *oc, void *data) #if defined(TARGET_PPC64) pcc->radix_page_info = kvm_get_radix_page_info(); + pcc->large_decr_bits = kvmppc_get_dec_bits(); if ((pcc->pvr & 0xffffff00) == CPU_POWERPC_POWER9_DD1) { /* @@ -2424,6 +2444,45 @@ bool kvmppc_has_cap_mmu_hash_v3(void) return cap_mmu_hash_v3; } +void kvmppc_check_cap_large_decr(void) +{ + PowerPCCPU *cpu = POWERPC_CPU(first_cpu); + CPUState *cs = CPU(cpu); + bool large_dec_support; + uint32_t dec_bits; + uint64_t lpcr; + + /* + * Try and set the LPCR_LD (large decrementer) bit to enable the large + * decrementer. A hypervisor with large decrementer capabilities will allow + * this so the value read back after this will have the LPCR_LD bit set. + * Otherwise the bit will be cleared meaning we can't use the large + * decrementer. + */ + kvm_get_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); + 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); + large_dec_support = !!(lpcr & LPCR_LD); + /* Probably a good idea to clear it again */ + lpcr &= ~LPCR_LD; + kvm_set_one_reg(cs, KVM_REG_PPC_LPCR_64, &lpcr); + + /* + * Check for the ibm,dec-bits property on the host, if it isn't there then + * something has gone wrong and we're better off not letting the guest use + * the large decrementer. + */ + dec_bits = kvmppc_get_dec_bits(); + + cap_large_decr = large_dec_support && dec_bits; +} + +bool kvmppc_has_cap_large_decr(void) +{ + return cap_large_decr; +} + 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 f48243d..c49c7f0 100644 --- a/target/ppc/kvm_ppc.h +++ b/target/ppc/kvm_ppc.h @@ -17,6 +17,7 @@ uint32_t kvmppc_get_tbfreq(void); uint64_t kvmppc_get_clockfreq(void); uint32_t kvmppc_get_vmx(void); uint32_t kvmppc_get_dfp(void); +uint32_t kvmppc_get_dec_bits(void); bool kvmppc_get_host_model(char **buf); bool kvmppc_get_host_serial(char **buf); int kvmppc_get_hasidle(CPUPPCState *env); @@ -36,6 +37,8 @@ int kvmppc_booke_watchdog_enable(PowerPCCPU *cpu); target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, bool radix, bool gtse, uint64_t proc_tbl); +void kvmppc_check_cap_large_decr(void); +void kvmppc_configure_large_decrementer(CPUState *cs, bool enable_ld); #ifndef CONFIG_USER_ONLY off_t kvmppc_alloc_rma(void **rma); bool kvmppc_spapr_use_multitce(void); @@ -60,6 +63,7 @@ bool kvmppc_has_cap_fixup_hcalls(void); bool kvmppc_has_cap_htm(void); bool kvmppc_has_cap_mmu_radix(void); bool kvmppc_has_cap_mmu_hash_v3(void); +bool kvmppc_has_cap_large_decr(void); int kvmppc_enable_hwrng(void); int kvmppc_put_books_sregs(PowerPCCPU *cpu); PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void); @@ -98,6 +102,11 @@ static inline uint32_t kvmppc_get_dfp(void) return 0; } +static inline uint32_t kvmppc_get_dec_bits(void) +{ + return 0; +} + static inline int kvmppc_get_hasidle(CPUPPCState *env) { return 0; @@ -170,6 +179,17 @@ static inline target_ulong kvmppc_configure_v3_mmu(PowerPCCPU *cpu, return 0; } +static inline void kvmppc_check_cap_large_decr(void) +{ + return; +} + +static inline void kvmppc_configure_large_decrementer(CPUState *cs, + bool enable_ld) +{ + return; +} + #ifndef CONFIG_USER_ONLY static inline off_t kvmppc_alloc_rma(void **rma) { @@ -282,6 +302,11 @@ static inline bool kvmppc_has_cap_mmu_hash_v3(void) return false; } +static inline bool kvmppc_has_cap_large_decr(void) +{ + return false; +} + static inline int kvmppc_enable_hwrng(void) { return -1;