From patchwork Wed Jul 6 05:35:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Bobroff X-Patchwork-Id: 9215391 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 D47A360752 for ; Wed, 6 Jul 2016 05:36:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5E74286B5 for ; Wed, 6 Jul 2016 05:36:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9B04286B7; Wed, 6 Jul 2016 05:36: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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 3010C286B5 for ; Wed, 6 Jul 2016 05:36:17 +0000 (UTC) Received: from localhost ([::1]:59348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKfVQ-0002E9-KZ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Jul 2016 01:36:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKfUn-00025y-7F for qemu-devel@nongnu.org; Wed, 06 Jul 2016 01:35:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKfUi-0004IN-U4 for qemu-devel@nongnu.org; Wed, 06 Jul 2016 01:35:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47799) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKfUi-0004HM-Ln for qemu-devel@nongnu.org; Wed, 06 Jul 2016 01:35:32 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u665XYnx026755 for ; Wed, 6 Jul 2016 01:35:31 -0400 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 240nf1sn00-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 06 Jul 2016 01:35:31 -0400 Received: from localhost by e23smtp04.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Jul 2016 15:35:29 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Jul 2016 15:35:25 +1000 X-IBM-Helo: d23dlp03.au.ibm.com X-IBM-MailFrom: sam.bobroff@au1.ibm.com X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d23relay07.au.ibm.com (d23relay07.au.ibm.com [9.190.26.37]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 4E2E93578057; Wed, 6 Jul 2016 15:35:25 +1000 (EST) Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u665ZPSl1049012; Wed, 6 Jul 2016 15:35:25 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u665ZOtt007232; Wed, 6 Jul 2016 15:35:24 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u665ZO3i007223; Wed, 6 Jul 2016 15:35:24 +1000 Received: from tungsten.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id B820BA039A; Wed, 6 Jul 2016 15:35:23 +1000 (AEST) From: Sam Bobroff To: david@gibson.dropbear.id.au Date: Wed, 6 Jul 2016 15:35:23 +1000 X-Mailer: git-send-email 2.1.4 In-Reply-To: References: In-Reply-To: References: X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16070605-0012-0000-0000-000001A783D7 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16070605-0013-0000-0000-00000587627A Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-07-06_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1607060051 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 3/3] spapr: Set ibm, pa-features HTM from KVM_CAP_PPC_HTM 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: mikey@neuling.org, aik@ozlabs.ru, mpe@ellerman.id.au, anton@au1.ibm.com, agraf@suse.de, qemu-devel@nongnu.org, paulus@samba.org, qemu-ppc@nongnu.org, linuxppc-dev@lists.ozlabs.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Advertise HTM support in ibm, pa-features if KVM indicates support when queried via a new capability (KVM_CAP_PPC_HTM). If KVM returns false for the capability (which may indicate that the host kernel doesn't support the capability itself) attempt to determine availability using a fallback method based on KVM being KVM-HV and HTM being available to the QEMU process. Signed-off-by: Sam Bobroff Reviewed-by: David Gibson --- v2: * Improve readability of HTM bit set code. * Move the test for KVM into kvmppc_get_htm_support(). hw/ppc/spapr.c | 3 +++ target-ppc/kvm.c | 29 +++++++++++++++++++++++++++++ target-ppc/kvm_ppc.h | 6 ++++++ 3 files changed, 38 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 704aae7..843fbe7 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -712,6 +712,9 @@ static void spapr_populate_cpu_dt(CPUState *cs, void *fdt, int offset, } else /* env->mmu_model == POWERPC_MMU_2_07 */ { pa_features = pa_features_207; pa_size = sizeof(pa_features_207); + if (kvmppc_get_htm_support(env)) { + pa_features[24] |= 0x80; + } } if (env->ci_large_pages) { pa_features[3] |= 0x20; diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c index 884d564..9d13446 100644 --- a/target-ppc/kvm.c +++ b/target-ppc/kvm.c @@ -20,6 +20,7 @@ #include #include +#include "elf.h" #include "qemu-common.h" #include "qemu/error-report.h" @@ -1976,6 +1977,34 @@ uint32_t kvmppc_get_dfp(void) return kvmppc_read_int_cpu_dt("ibm,dfp"); } +bool kvmppc_get_htm_support(CPUPPCState *env) +{ + PowerPCCPU *cpu = ppc_env_get_cpu(env); + CPUState *cs = CPU(cpu); + + if (!kvm_enabled()) { + return false; + } + if (kvm_vm_check_extension(cs->kvm_state, KVM_CAP_PPC_HTM)) { + return true; + } + /* + * Fallback test for host kernels that don't yet support KVM_CAP_PPC_HTM. + * This will be unnecessary when KVM_API_VERSION is incremented (to 13 or + * above) because that will remove the ambiguity between the host kernel + * lacking support for KVM_CAP_PPC_HTM and it having support but reporting + * HTM as unavailable (both of which return 0, above). + */ + if (kvm_vm_check_extension(cs->kvm_state, KVM_CAP_PPC_GET_PVINFO)) { + /* Assume this means PR KVM, so no TM. */ + return false; + } else { + /* Assume this means HV KVM, propagate whatever host userspace sees. */ + unsigned long hwcap2 = qemu_getauxval(AT_HWCAP2); + return !!(hwcap2 & PPC_FEATURE2_HAS_HTM); + } +} + static int kvmppc_get_pvinfo(CPUPPCState *env, struct kvm_ppc_pvinfo *pvinfo) { PowerPCCPU *cpu = ppc_env_get_cpu(env); diff --git a/target-ppc/kvm_ppc.h b/target-ppc/kvm_ppc.h index 20bfb59..b01c717 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); +bool kvmppc_get_htm_support(CPUPPCState *env); bool kvmppc_get_host_model(char **buf); bool kvmppc_get_host_serial(char **buf); int kvmppc_get_hasidle(CPUPPCState *env); @@ -90,6 +91,11 @@ static inline uint32_t kvmppc_get_dfp(void) return 0; } +static inline bool kvmppc_get_htm_support(KVMState *kvm_state) +{ + return false; +} + static inline int kvmppc_get_hasidle(CPUPPCState *env) { return 0;