From patchwork Wed Jan 4 12:39:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9496627 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 23B40606B5 for ; Wed, 4 Jan 2017 12:42:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 151A227F86 for ; Wed, 4 Jan 2017 12:42:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0A20E27F8D; Wed, 4 Jan 2017 12:42:28 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 290E427F8C for ; Wed, 4 Jan 2017 12:42:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOkrW-0003va-R1; Wed, 04 Jan 2017 12:40:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOkrV-0003uG-5y for xen-devel@lists.xen.org; Wed, 04 Jan 2017 12:40:13 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 16/E9-11476-C2DEC685; Wed, 04 Jan 2017 12:40:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrohUlfnbU6 EQe8NFoslHxezODB6HN39mymAMYo1My8pvyKBNWPvla9MBQtMKs4e2sHewPhTtYuRk0NCwF+i e+k7dhCbTUBfYveLT0wgtoiAusTpjousXYwcHMwCfhKHHviChIUFgiXu/NvEDGKzCKhITJ93n g3E5hXwkLhwYxs7xEg5ifPHf4LVcAp4SjzbuI4RxBYCqplycRk7hK0mca3/EjtEr6DEyZlPWE BsZgEJiYMvXjBPYOSdhSQ1C0lqASPTKkb14tSistQiXTO9pKLM9IyS3MTMHF1DAzO93NTi4sT 01JzEpGK95PzcTYzAwGEAgh2M8074H2KU5GBSEuXta8+JEOJLyk+pzEgszogvKs1JLT7EKMPB oSTBq/YGKCdYlJqeWpGWmQMMYZi0BAePkgivHUiat7ggMbc4Mx0idYpRUUqcVxskIQCSyCjNg 2uDxc0lRlkpYV5GoEOEeApSi3IzS1DlXzGKczAqCfMKgEzhycwrgZv+CmgxE9Di7QHZIItLEh FSUg2MW5bL+yz7233CbZPtFkftFM7EyP2RN12FV3Sozy4It9G98ugH+9OgJ8VGfhJHlxopreX p40zck67yeQZ37dwFAnsKtpf/WrjKsndTfOYxD839xoyLHybJSFheSpjkbWJUm8NxQiX8A+e0 iRNfRm16zfRWT+nGivtXPsexrM4JX3vNz9/+u0uDEktxRqKhFnNRcSIAgt6kZpYCAAA= X-Env-Sender: prvs=1701003ad=Andrew.Cooper3@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1483533609!79974537!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61617 invoked from network); 4 Jan 2017 12:40:11 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 4 Jan 2017 12:40:11 -0000 X-IronPort-AV: E=Sophos;i="5.33,459,1477958400"; d="scan'208";a="397866202" From: Andrew Cooper To: Xen-devel Date: Wed, 4 Jan 2017 12:39:25 +0000 Message-ID: <1483533584-8015-9-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1483533584-8015-1-git-send-email-andrew.cooper3@citrix.com> References: <1483533584-8015-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Jan Beulich Subject: [Xen-devel] [PATCH 08/27] x86/hvm: Dispatch cpuid_viridian_leaves() from guest_cpuid() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP ... rather than from the legacy path. Update the API to match guest_cpuid(), and remove its dependence on current. One check against EFER_SVME is replaced with the more appropriate cpu_has_svm, when determining whether MSR bitmaps are available. Make use of guest_cpuid() unconditionally zeroing res to avoid repeated re-zeroing. Signed-off-by: Andrew Cooper --- CC: Jan Beulich --- xen/arch/x86/cpuid.c | 13 ++++++++ xen/arch/x86/hvm/hvm.c | 3 -- xen/arch/x86/hvm/viridian.c | 65 ++++++++++++++++++-------------------- xen/include/asm-x86/hvm/viridian.h | 9 ++---- 4 files changed, 46 insertions(+), 44 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 36d11c0..c38e477 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -319,8 +319,21 @@ int init_domain_cpuid_policy(struct domain *d) void guest_cpuid(const struct vcpu *v, unsigned int leaf, unsigned int subleaf, struct cpuid_leaf *res) { + const struct domain *d = v->domain; + *res = EMPTY_LEAF; + /* + * First pass: + * - Dispatch the virtualised leaves to their respective handlers. + */ + switch ( leaf ) + { + case 0x40000000 ... 0x400000ff: + if ( is_viridian_domain(d) ) + return cpuid_viridian_leaves(v, leaf, subleaf, res); + } + /* {pv,hvm}_cpuid() have this expectation. */ ASSERT(v == current); diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 70afcc6..ce2785f 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3353,9 +3353,6 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, if ( !edx ) edx = &dummy; - if ( cpuid_viridian_leaves(input, eax, ebx, ecx, edx) ) - return; - if ( cpuid_hypervisor_leaves(input, count, eax, ebx, ecx, edx) ) return; diff --git a/xen/arch/x86/hvm/viridian.c b/xen/arch/x86/hvm/viridian.c index f6abdd2..f2ac0ab 100644 --- a/xen/arch/x86/hvm/viridian.c +++ b/xen/arch/x86/hvm/viridian.c @@ -66,77 +66,74 @@ #define CPUID6A_MSR_BITMAPS (1 << 1) #define CPUID6A_NESTED_PAGING (1 << 3) -int cpuid_viridian_leaves(unsigned int leaf, unsigned int *eax, - unsigned int *ebx, unsigned int *ecx, - unsigned int *edx) +void cpuid_viridian_leaves(const struct vcpu *v, unsigned int leaf, + unsigned int subleaf, struct cpuid_leaf *res) { - struct domain *d = current->domain; + const struct domain *d = v->domain; - if ( !is_viridian_domain(d) ) - return 0; + ASSERT(is_viridian_domain(d)); + ASSERT(leaf >= 0x40000000 && leaf < 0x40000100); leaf -= 0x40000000; - if ( leaf > 6 ) - return 0; - *eax = *ebx = *ecx = *edx = 0; switch ( leaf ) { case 0: - *eax = 0x40000006; /* Maximum leaf */ - *ebx = 0x7263694d; /* Magic numbers */ - *ecx = 0x666F736F; - *edx = 0x76482074; + res->a = 0x40000006; /* Maximum leaf */ + res->b = 0x7263694d; /* Magic numbers */ + res->c = 0x666F736F; + res->d = 0x76482074; break; + case 1: - *eax = 0x31237648; /* Version number */ + res->a = 0x31237648; /* Version number */ break; + case 2: /* Hypervisor information, but only if the guest has set its own version number. */ if ( d->arch.hvm_domain.viridian.guest_os_id.raw == 0 ) break; - *eax = 1; /* Build number */ - *ebx = (xen_major_version() << 16) | xen_minor_version(); - *ecx = 0; /* SP */ - *edx = 0; /* Service branch and number */ + res->a = 1; /* Build number */ + res->b = (xen_major_version() << 16) | xen_minor_version(); break; + case 3: /* Which hypervisor MSRs are available to the guest */ - *eax = (CPUID3A_MSR_APIC_ACCESS | - CPUID3A_MSR_HYPERCALL | - CPUID3A_MSR_VP_INDEX); + res->a = (CPUID3A_MSR_APIC_ACCESS | + CPUID3A_MSR_HYPERCALL | + CPUID3A_MSR_VP_INDEX); if ( !(viridian_feature_mask(d) & HVMPV_no_freq) ) - *eax |= CPUID3A_MSR_FREQ; + res->a |= CPUID3A_MSR_FREQ; if ( viridian_feature_mask(d) & HVMPV_time_ref_count ) - *eax |= CPUID3A_MSR_TIME_REF_COUNT; + res->a |= CPUID3A_MSR_TIME_REF_COUNT; if ( viridian_feature_mask(d) & HVMPV_reference_tsc ) - *eax |= CPUID3A_MSR_REFERENCE_TSC; + res->a |= CPUID3A_MSR_REFERENCE_TSC; break; + case 4: /* Recommended hypercall usage. */ if ( (d->arch.hvm_domain.viridian.guest_os_id.raw == 0) || (d->arch.hvm_domain.viridian.guest_os_id.fields.os < 4) ) break; - *eax = CPUID4A_RELAX_TIMER_INT; + res->a = CPUID4A_RELAX_TIMER_INT; if ( viridian_feature_mask(d) & HVMPV_hcall_remote_tlb_flush ) - *eax |= CPUID4A_HCALL_REMOTE_TLB_FLUSH; + res->a |= CPUID4A_HCALL_REMOTE_TLB_FLUSH; if ( !cpu_has_vmx_apic_reg_virt ) - *eax |= CPUID4A_MSR_BASED_APIC; - *ebx = 2047; /* long spin count */ + res->a |= CPUID4A_MSR_BASED_APIC; + res->b = 2047; /* long spin count */ break; + case 6: /* Detected and in use hardware features. */ if ( cpu_has_vmx_virtualize_apic_accesses ) - *eax |= CPUID6A_APIC_OVERLAY; - if ( cpu_has_vmx_msr_bitmap || (read_efer() & EFER_SVME) ) - *eax |= CPUID6A_MSR_BITMAPS; + res->a |= CPUID6A_APIC_OVERLAY; + if ( cpu_has_vmx_msr_bitmap || cpu_has_svm ) + res->a |= CPUID6A_MSR_BITMAPS; if ( hap_enabled(d) ) - *eax |= CPUID6A_NESTED_PAGING; + res->a |= CPUID6A_NESTED_PAGING; break; } - - return 1; } static void dump_guest_os_id(const struct domain *d) diff --git a/xen/include/asm-x86/hvm/viridian.h b/xen/include/asm-x86/hvm/viridian.h index bdbccd5..6e062df 100644 --- a/xen/include/asm-x86/hvm/viridian.h +++ b/xen/include/asm-x86/hvm/viridian.h @@ -97,13 +97,8 @@ struct viridian_domain union viridian_reference_tsc reference_tsc; }; -int -cpuid_viridian_leaves( - unsigned int leaf, - unsigned int *eax, - unsigned int *ebx, - unsigned int *ecx, - unsigned int *edx); +void cpuid_viridian_leaves(const struct vcpu *v, unsigned int leaf, + unsigned int subleaf, struct cpuid_leaf *res); int wrmsr_viridian_regs(