From patchwork Wed Jan 4 12:39:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 9496679 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 E2E7B606DD for ; Wed, 4 Jan 2017 12:48:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4D2027F85 for ; Wed, 4 Jan 2017 12:48:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9B1227F8C; Wed, 4 Jan 2017 12:48:29 +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 5A22D27F88 for ; Wed, 4 Jan 2017 12:48:29 +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 1cOkxV-0005VM-0G; Wed, 04 Jan 2017 12:46:25 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cOkxT-0005Ut-9K for xen-devel@lists.xen.org; Wed, 04 Jan 2017 12:46:23 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 3B/F2-14551-E9EEC685; Wed, 04 Jan 2017 12:46:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpmkeJIrShJLcpLzFFi42JxWrohUnfuu5w IgzubrC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyWjpXMBYv0K2a/fMHYwHhIoYuRk0NCwF/i 3rxrjCA2m4C+xO4Xn5hAbBEBdYnTHRdZuxg5OJgF/CQOPfAFCQsL+EpMbOxmBbFZBFQkGk/3g 5XzCnhKtE/eyQgxUk7i/PGfzCA2J1D82cZ1YHEhAQ+JKReXsUPYahLX+i+xQ/QKSpyc+YQFxG YWkJA4+OIF8wRG3llIUrOQpBYwMq1iVC9OLSpLLdI10UsqykzPKMlNzMzRNTQw1stNLS5OTE/ NSUwq1kvOz93ECAwcBiDYwdj4xekQoyQHk5Iob197ToQQX1J+SmVGYnFGfFFpTmrxIUYZDg4l CV6ht0A5waLU9NSKtMwcYAjDpCU4eJREeNNB0rzFBYm5xZnpEKlTjIpS4rzGIAkBkERGaR5cG yxuLjHKSgnzMgIdIsRTkFqUm1mCKv+KUZyDUUmY1wZkCk9mXgnc9FdAi5mAFm8PyAZZXJKIkJ JqYMyXKbmXk5D03ovtmU7Hqg1Z0z9fuSSXIbuwwEHpzExD0X+LlJIuPJtfrv3Qdv2yYiVTxkp /m7vNAsbqRlPrX/dzfZApsrjeGnXrxtO1Dx4xfJBpl7Fpyb6cfCHbW2RGgpP2vJkr7j30tDk5 h3e7pXrlKlnvvVx3LE8qFgRsdN74Jvzx1YBzfkosxRmJhlrMRcWJAGBx5/WWAgAA X-Env-Sender: prvs=1701003ad=Andrew.Cooper3@citrix.com X-Msg-Ref: server-6.tower-31.messagelabs.com!1483533980!52605894!1 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 45852 invoked from network); 4 Jan 2017 12:46:21 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 4 Jan 2017 12:46:21 -0000 X-IronPort-AV: E=Sophos;i="5.33,459,1477958400"; d="scan'208";a="397866967" From: Andrew Cooper To: Xen-devel Date: Wed, 4 Jan 2017 12:39:40 +0000 Message-ID: <1483533584-8015-24-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 23/27] x86/cpuid: Move all leaf 7 handling into 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 All per-domain policy data concerning leaf 7 is accurate. Handle it all in guest_cpuid() by reading out of the raw array block, and introduing a dynamic adjustment for OSPKE. Signed-off-by: Andrew Cooper --- CC: Jan Beulich --- xen/arch/x86/cpuid.c | 41 +++++++++++++++++++++++++++++++++++++---- xen/arch/x86/hvm/hvm.c | 17 ++++------------- xen/arch/x86/traps.c | 28 ++++------------------------ xen/include/asm-x86/cpuid.h | 2 ++ 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index d140482..9181fc7 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -339,6 +339,7 @@ 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 vcpu *curr = current; const struct domain *d = v->domain; const struct cpuid_policy *p = d->arch.cpuid; @@ -348,6 +349,7 @@ void guest_cpuid(const struct vcpu *v, unsigned int leaf, * First pass: * - Dispatch the virtualised leaves to their respective handlers. * - Perform max_leaf/subleaf calculations, maybe returning early. + * - Fill in *res for leaves no longer handled on the legacy path. */ switch ( leaf ) { @@ -358,17 +360,20 @@ void guest_cpuid(const struct vcpu *v, unsigned int leaf, #endif if ( leaf > p->basic.max_leaf ) return; - break; + goto legacy; case 0x7: if ( subleaf > p->feat.max_subleaf ) return; + + BUG_ON(subleaf >= ARRAY_SIZE(p->feat.raw)); + *res = p->feat.raw[subleaf]; break; case 0xd: if ( subleaf > ARRAY_SIZE(p->xstate.raw) ) return; - break; + goto legacy; case 0x40000000 ... 0x400000ff: if ( is_viridian_domain(d) ) @@ -380,14 +385,42 @@ void guest_cpuid(const struct vcpu *v, unsigned int leaf, case 0x80000000 ... 0x80000000 + CPUID_GUEST_NR_EXTD - 1: if ( leaf > p->extd.max_leaf ) return; - break; + goto legacy; default: return; } + /* Skip dynamic adjustments if we are in the wrong context. */ + if ( v != curr ) + return; + + /* + * Second pass: + * - Dynamic adjustments + */ + switch ( leaf ) + { + case 0x7: + switch ( subleaf ) + { + case 0: + /* OSPKE clear in policy. Fast-forward CR4 back in. */ + if ( (is_pv_vcpu(v) + ? v->arch.pv_vcpu.ctrlreg[4] + : v->arch.hvm_vcpu.guest_cr[4]) & X86_CR4_PKE ) + res->c |= cpufeat_mask(X86_FEATURE_OSPKE); + break; + } + break; + } + + /* Done. */ + return; + + legacy: /* {pv,hvm}_cpuid() have this expectation. */ - ASSERT(v == current); + ASSERT(v == curr); if ( is_pv_vcpu(v) || is_pvh_vcpu(v) ) { diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 1dd92e3..4ded533 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3354,19 +3354,6 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, break; - case 0x7: - if ( count == 0 ) - { - *ebx = d->arch.cpuid->feat._7b0; - *ecx = d->arch.cpuid->feat._7c0; - *edx = d->arch.cpuid->feat._7d0; - - /* OSPKE clear in policy. Fast-forward CR4 back in. */ - if ( v->arch.hvm_vcpu.guest_cr[4] & X86_CR4_PKE ) - *ecx |= cpufeat_mask(X86_FEATURE_OSPKE); - } - break; - case 0xb: /* Fix the x2APIC identifier. */ *edx = v->vcpu_id * 2; @@ -3543,6 +3530,10 @@ void hvm_cpuid(unsigned int input, unsigned int *eax, unsigned int *ebx, else *eax = 0; break; + + case 0x7: + ASSERT_UNREACHABLE(); + /* Now handled in guest_cpuid(). */ } } diff --git a/xen/arch/x86/traps.c b/xen/arch/x86/traps.c index aed96c3..e2669b1 100644 --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -1180,30 +1180,6 @@ void pv_cpuid(struct cpu_user_regs *regs) } break; - case 0x00000007: - if ( subleaf == 0 ) - { - b = currd->arch.cpuid->feat._7b0; - c = currd->arch.cpuid->feat._7c0; - d = currd->arch.cpuid->feat._7d0; - - if ( !is_pvh_domain(currd) ) - { - /* - * Delete the PVH condition when HVMLite formally replaces PVH, - * and HVM guests no longer enter a PV codepath. - */ - - /* OSPKE clear in policy. Fast-forward CR4 back in. */ - if ( curr->arch.pv_vcpu.ctrlreg[4] & X86_CR4_PKE ) - c |= cpufeat_mask(X86_FEATURE_OSPKE); - } - } - else - b = c = d = 0; - a = 0; - break; - case 0x0000000a: /* Architectural Performance Monitor Features (Intel) */ if ( boot_cpu_data.x86_vendor != X86_VENDOR_INTEL || !vpmu_enabled(curr) ) @@ -1305,6 +1281,10 @@ void pv_cpuid(struct cpu_user_regs *regs) unsupported: a = b = c = d = 0; break; + + case 0x7: + ASSERT_UNREACHABLE(); + /* Now handled in guest_cpuid(). */ } regs->rax = a; diff --git a/xen/include/asm-x86/cpuid.h b/xen/include/asm-x86/cpuid.h index 7363263..c7e9df5 100644 --- a/xen/include/asm-x86/cpuid.h +++ b/xen/include/asm-x86/cpuid.h @@ -81,12 +81,14 @@ struct cpuid_policy * - {xcr0,xss}_{high,low} * * - Guest appropriate: + * - All of the feat union * - max_{,sub}leaf * - All FEATURESET_* words * * Per-domain objects: * * - Guest accurate: + * - All of the feat union * - max_{,sub}leaf * - All FEATURESET_* words *