From patchwork Wed Jun 1 15:05:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 9147553 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 9D23C60761 for ; Wed, 1 Jun 2016 15:08:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B9E720410 for ; Wed, 1 Jun 2016 15:08:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DEF326B39; Wed, 1 Jun 2016 15:08:16 +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 7181F20410 for ; Wed, 1 Jun 2016 15:08:15 +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 1b87id-0005uH-9K; Wed, 01 Jun 2016 15:06:03 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b87ib-0005tq-Ej for xen-devel@lists.xenproject.org; Wed, 01 Jun 2016 15:06:01 +0000 Received: from [193.109.254.147] by server-4.bemta-14.messagelabs.com id 31/A5-09542-8D9FE475; Wed, 01 Jun 2016 15:06:00 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsXS6fjDS/f6T79 wg5nzNSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxP7QkF/doVJw7+ZmxgnCDfxcjJISSQJ7G0 ZRk7iM0rYCdxpOslK4gtIWAosW/+KrYuRg4OFgFViVc7pUDCbALqEm3PtrOChEUEDCTOHU0CC TMLBErcuj+DESQsLOAi0bPFAsQUAhr4pC0HpIJTwF7iypUd7CBhXgFBib87hCEa7SSm3m1lnM DIMwshMwtJBsLWknj46xYLhK0tsWzha2aQcmYBaYnl/zggws4Sl69PwaLET6LzdeUCRo5VjOr FqUVlqUW6pnpJRZnpGSW5iZk5uoaGJnq5qcXFiempOYlJxXrJ+bmbGIEBygAEOxjXLXY+xCjJ waQkyhv8zS9ciC8pP6UyI7E4I76oNCe1+BCjDAeHkgRv2w+gnGBRanpqRVpmDjBWYNISHDxKI ryHQdK8xQWJucWZ6RCpU4yKUuK8nSAJAZBERmkeXBssPi8xykoJ8zICHSLEU5BalJtZgir/il Gcg1FJmPc4yBSezLwSuOmvgBYzAS2Oz/ABWVySiJCSamBkU7NMzFjnY//hdugOk2PRtzeE2Ks wfVYWrcxUk3325Gh1iZ0ol1zs92u/Nc3iIv4us5u0a2O3pseiHe/zRNM5eq9Oybet0b4wz+dX /Kzlt9e1vzz3S+vztssSKqzBKq4WvSWGOjvmGc3cPjH37CffyZ9/25gK88Qz2X/abiu+oUR4u teHMwZKLMUZiYZazEXFiQAWqU95ygIAAA== X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1464793557!45206094!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 5791 invoked from network); 1 Jun 2016 15:05:59 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 1 Jun 2016 15:05:59 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Wed, 01 Jun 2016 09:05:56 -0600 Message-Id: <574F15F402000078000F07F9@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Wed, 01 Jun 2016 09:05:56 -0600 From: "Jan Beulich" To: "xen-devel" References: <574F13FB02000078000F07D9@prv-mh.provo.novell.com> In-Reply-To: <574F13FB02000078000F07D9@prv-mh.provo.novell.com> Mime-Version: 1.0 Cc: Andrew Cooper , Wei Liu Subject: [Xen-devel] [PATCH 1/2] x86: flush high xstate CPUID sub-leaves to zero 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 In line with other recent changes, these should be fully white listed, requiring us to zero them until the obtain a meaning we support. Without XSAVE support, all xstate sub-leaves should be zero. Also move away from checking host XSAVE support - we really ought to consider the guest flag for that purpose. Signed-off-by: Jan Beulich x86: flush high xstate CPUID sub-leaves to zero In line with other recent changes, these should be fully white listed, requiring us to zero them until the obtain a meaning we support. Without XSAVE support, all xstate sub-leaves should be zero. Also move away from checking host XSAVE support - we really ought to consider the guest flag for that purpose. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3433,7 +3433,13 @@ void hvm_cpuid(unsigned int input, unsig *edx = v->vcpu_id * 2; break; - case 0xd: + case XSTATE_CPUID: + hvm_cpuid(1, NULL, NULL, &_ecx, NULL); + if ( !(_ecx & cpufeat_mask(X86_FEATURE_XSAVE)) || count >= 63 ) + { + *eax = *ebx = *ecx = *edx = 0; + break; + } /* EBX value of main leaf 0 depends on enabled xsave features */ if ( count == 0 && v->arch.xcr0 ) { --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -928,6 +928,8 @@ void pv_cpuid(struct cpu_user_regs *regs switch ( leaf ) { + uint32_t tmp; + case 0x00000001: c &= pv_featureset[FEATURESET_1c]; d &= pv_featureset[FEATURESET_1d]; @@ -1085,14 +1087,19 @@ void pv_cpuid(struct cpu_user_regs *regs break; case XSTATE_CPUID: - if ( !cpu_has_xsave ) + if ( !((!is_control_domain(currd) && !is_hardware_domain(currd) + ? ({ + uint32_t ecx; + + domain_cpuid(currd, 1, 0, &tmp, &tmp, &ecx, &tmp); + ecx & pv_featureset[FEATURESET_1c]; + }) + : cpuid_ecx(1)) & cpufeat_mask(X86_FEATURE_XSAVE)) || + subleaf >= 63 ) goto unsupported; switch ( subleaf ) { case 0: - { - uint32_t tmp; - /* * Always read CPUID.0xD[ECX=0].EBX from hardware, rather than * domain policy. It varies with enabled xstate, and the correct @@ -1101,7 +1108,6 @@ void pv_cpuid(struct cpu_user_regs *regs if ( !is_control_domain(currd) && !is_hardware_domain(currd) ) cpuid_count(leaf, subleaf, &tmp, &b, &tmp, &tmp); break; - } case 1: a &= pv_featureset[FEATURESET_Da1]; Reviewed-by: Andrew Cooper , with one suggestion --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -3433,7 +3433,13 @@ void hvm_cpuid(unsigned int input, unsig *edx = v->vcpu_id * 2; break; - case 0xd: + case XSTATE_CPUID: + hvm_cpuid(1, NULL, NULL, &_ecx, NULL); + if ( !(_ecx & cpufeat_mask(X86_FEATURE_XSAVE)) || count >= 63 ) + { + *eax = *ebx = *ecx = *edx = 0; + break; + } /* EBX value of main leaf 0 depends on enabled xsave features */ if ( count == 0 && v->arch.xcr0 ) { --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -928,6 +928,8 @@ void pv_cpuid(struct cpu_user_regs *regs switch ( leaf ) { + uint32_t tmp; + case 0x00000001: c &= pv_featureset[FEATURESET_1c]; d &= pv_featureset[FEATURESET_1d]; @@ -1085,14 +1087,19 @@ void pv_cpuid(struct cpu_user_regs *regs break; case XSTATE_CPUID: - if ( !cpu_has_xsave ) + if ( !((!is_control_domain(currd) && !is_hardware_domain(currd) + ? ({ + uint32_t ecx; + + domain_cpuid(currd, 1, 0, &tmp, &tmp, &ecx, &tmp); + ecx & pv_featureset[FEATURESET_1c]; + }) + : cpuid_ecx(1)) & cpufeat_mask(X86_FEATURE_XSAVE)) || + subleaf >= 63 ) goto unsupported; switch ( subleaf ) { case 0: - { - uint32_t tmp; - /* * Always read CPUID.0xD[ECX=0].EBX from hardware, rather than * domain policy. It varies with enabled xstate, and the correct @@ -1101,7 +1108,6 @@ void pv_cpuid(struct cpu_user_regs *regs if ( !is_control_domain(currd) && !is_hardware_domain(currd) ) cpuid_count(leaf, subleaf, &tmp, &b, &tmp, &tmp); break; - } case 1: a &= pv_featureset[FEATURESET_Da1];