From patchwork Fri Dec 18 16:51:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 7887091 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 585C5BEEE5 for ; Fri, 18 Dec 2015 16:55:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7A9212021F for ; Fri, 18 Dec 2015 16:55:07 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 790DD2045A for ; Fri, 18 Dec 2015 16:55:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a9yGG-0007mr-4H; Fri, 18 Dec 2015 16:52:08 +0000 Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1a9yGE-0007mk-Ge for xen-devel@lists.xenproject.org; Fri, 18 Dec 2015 16:52:06 +0000 Received: from [85.158.143.35] by server-2.bemta-4.messagelabs.com id 57/13-18316-5B934765; Fri, 18 Dec 2015 16:52:05 +0000 X-Env-Sender: JBeulich@suse.com X-Msg-Ref: server-8.tower-21.messagelabs.com!1450457521!6131093!1 X-Originating-IP: [137.65.248.74] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9103 invoked from network); 18 Dec 2015 16:52:02 -0000 Received: from prv-mh.provo.novell.com (HELO prv-mh.provo.novell.com) (137.65.248.74) by server-8.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 18 Dec 2015 16:52:02 -0000 Received: from INET-PRV-MTA by prv-mh.provo.novell.com with Novell_GroupWise; Fri, 18 Dec 2015 09:52:00 -0700 Message-Id: <567447BF02000078000C167E@prv-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 14.2.0 Date: Fri, 18 Dec 2015 09:51:59 -0700 From: "Jan Beulich" To: "xen-devel" Mime-Version: 1.0 Cc: Andrew Cooper , Kevin Tian , Keir Fraser , Boris Ostrovsky , Jun Nakajima Subject: [Xen-devel] [PATCH v2] x86/vPMU: constrain MSR_IA32_DS_AREA loads X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For one, loading the MSR with a possibly non-canonical address was possible since the verification is conditional, while the MSR load wasn't. And then for PV guests we need to further limit the range of valid addresses to exclude the hypervisor range. Signed-off-by: Jan Beulich Reviewed-by: Boris Ostrovsky Acked-by: Kevin Tian --- v2: Also alter the MSR write check, in anticipation of it becoming accessible by PV guests eventually. x86/vPMU: constrain MSR_IA32_DS_AREA loads For one, loading the MSR with a possibly non-canonical address was possible since the verification is conditional, while the MSR load wasn't. And then for PV guests we need to further limit the range of valid addresses to exclude the hypervisor range. Signed-off-by: Jan Beulich --- v2: Also alter the MSR write check, in anticipation of it becoming accessible by PV guests eventually. --- a/xen/arch/x86/cpu/vpmu_intel.c +++ b/xen/arch/x86/cpu/vpmu_intel.c @@ -366,7 +366,8 @@ static inline void __core2_vpmu_load(str } wrmsrl(MSR_CORE_PERF_FIXED_CTR_CTRL, core2_vpmu_cxt->fixed_ctrl); - wrmsrl(MSR_IA32_DS_AREA, core2_vpmu_cxt->ds_area); + if ( vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) ) + wrmsrl(MSR_IA32_DS_AREA, core2_vpmu_cxt->ds_area); wrmsrl(MSR_IA32_PEBS_ENABLE, core2_vpmu_cxt->pebs_enable); if ( !has_hvm_container_vcpu(v) ) @@ -415,8 +416,10 @@ static int core2_vpmu_verify(struct vcpu enabled_cntrs |= (1ULL << i); } - if ( vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) && - !is_canonical_address(core2_vpmu_cxt->ds_area) ) + if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) && + !(has_hvm_container_vcpu(v) + ? is_canonical_address(core2_vpmu_cxt->ds_area) + : __addr_ok(core2_vpmu_cxt->ds_area)) ) return -EINVAL; if ( (core2_vpmu_cxt->global_ctrl & enabled_cntrs) || @@ -609,7 +612,9 @@ static int core2_vpmu_do_wrmsr(unsigned case MSR_IA32_DS_AREA: if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) ) { - if ( !is_canonical_address(msr_content) ) + if ( !(has_hvm_container_vcpu(v) + ? is_canonical_address(msr_content) + : __addr_ok(msr_content)) ) { gdprintk(XENLOG_WARNING, "Illegal address for IA32_DS_AREA: %#" PRIx64 "x\n", --- a/xen/arch/x86/cpu/vpmu_intel.c +++ b/xen/arch/x86/cpu/vpmu_intel.c @@ -366,7 +366,8 @@ static inline void __core2_vpmu_load(str } wrmsrl(MSR_CORE_PERF_FIXED_CTR_CTRL, core2_vpmu_cxt->fixed_ctrl); - wrmsrl(MSR_IA32_DS_AREA, core2_vpmu_cxt->ds_area); + if ( vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) ) + wrmsrl(MSR_IA32_DS_AREA, core2_vpmu_cxt->ds_area); wrmsrl(MSR_IA32_PEBS_ENABLE, core2_vpmu_cxt->pebs_enable); if ( !has_hvm_container_vcpu(v) ) @@ -415,8 +416,10 @@ static int core2_vpmu_verify(struct vcpu enabled_cntrs |= (1ULL << i); } - if ( vpmu_is_set(vcpu_vpmu(v), VPMU_CPU_HAS_DS) && - !is_canonical_address(core2_vpmu_cxt->ds_area) ) + if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) && + !(has_hvm_container_vcpu(v) + ? is_canonical_address(core2_vpmu_cxt->ds_area) + : __addr_ok(core2_vpmu_cxt->ds_area)) ) return -EINVAL; if ( (core2_vpmu_cxt->global_ctrl & enabled_cntrs) || @@ -609,7 +612,9 @@ static int core2_vpmu_do_wrmsr(unsigned case MSR_IA32_DS_AREA: if ( vpmu_is_set(vpmu, VPMU_CPU_HAS_DS) ) { - if ( !is_canonical_address(msr_content) ) + if ( !(has_hvm_container_vcpu(v) + ? is_canonical_address(msr_content) + : __addr_ok(msr_content)) ) { gdprintk(XENLOG_WARNING, "Illegal address for IA32_DS_AREA: %#" PRIx64 "x\n",