From nobody Thu Apr 25 06:54:12 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1555329906; cv=none; d=zoho.com; s=zohoarc; b=j3L79PGbuz/i5kJfyAicnM6ZTTihvHFtZORdusxYw6MOAB74yCsW+axVk6dUfKvIXBSZzH4Liq6hnay1jWobko/gzNlBaXuO+EMH08f+GL12FcgRmhbyYbtxznvCpBk7ZyRQdQPGYL5b4YRrL5V4oMjBH4CXVblk74qnWdTpJgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555329906; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=EIR8PqoanyNeifJpDJR/7eQB0hqYDtSEyV9e0xfj9K4=; b=atJGnRsO4nQqfO2Vf/RWV8z0Y2P23ZO7slhCfDdHWUyWKCSLABC2Uk/r/RAFx4yWWAMG0V5YgX0LHnumCCBYT2foW64tERPlwmdFJDk84FO9bMsk7pz33SFILfXgflQeqElsPSA0HG/VkcOKVi1U4wWWagu7aDp9Ksar/6A1Gxo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 155532990635762.69021934257489; Mon, 15 Apr 2019 05:05:06 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hG0Kn-0001ny-4n; Mon, 15 Apr 2019 12:03:37 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hG0Kl-0001np-5z for xen-devel@lists.xenproject.org; Mon, 15 Apr 2019 12:03:35 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 7d83077c-5f76-11e9-92d7-bc764e045a96; Mon, 15 Apr 2019 12:03:33 +0000 (UTC) X-Inumbo-ID: 7d83077c-5f76-11e9-92d7-bc764e045a96 X-IronPort-AV: E=Sophos;i="5.60,353,1549929600"; d="scan'208";a="83569649" From: Andrew Cooper To: Xen-devel Date: Mon, 15 Apr 2019 13:03:29 +0100 Message-ID: <1555329809-3248-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2] x86/msr: Fix fallout from mostly c/s 832c180 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Kevin Tian , Wei Liu , Jan Beulich , Andrew Cooper , Jun Nakajima , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" * Fix the shim build by providing a !CONFIG_HVM declaration for hvm_get_guest_bndcfgs(), and removing the introduced ASSERT(is_hvm_domain(d))'s. They are needed for DCE to keep the build working. Furthermore, in this way, the risk of runtime type confusion is removed. * Revert the de-const'ing of the vcpu pointer in vmx_get_guest_bndcfgs(). vmx_vmcs_enter() really does mutate the vcpu, and may cause it to underg= o a full de/reschedule, which is in violation of the ABI described by hvm_get_guest_bndcfgs(). guest_rdmsr() was always going to need to lose its const parameter, and this was the correct time for it to happen. * The MSRs in vcpu_msrs are in numeric order. Re-position XSS to match. Signed-off-by: Andrew Cooper Reviewed-by: Paul Durrant Acked-by: Jan Beulich Reviewed-by: Kevin Tian --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Jun Nakajima CC: Kevin Tian v2: * Rephrase the commit message --- xen/arch/x86/hvm/vmx/vmx.c | 5 +---- xen/arch/x86/msr.c | 18 +++++------------- xen/arch/x86/pv/emul-priv-op.c | 2 +- xen/include/asm-x86/hvm/hvm.h | 5 +++-- xen/include/asm-x86/msr.h | 12 ++++++------ 5 files changed, 16 insertions(+), 26 deletions(-) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index c46e05b..283eb7b 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -1150,11 +1150,8 @@ static bool vmx_set_guest_bndcfgs(struct vcpu *v, u6= 4 val) return true; } =20 -static bool vmx_get_guest_bndcfgs(const struct vcpu *cv, u64 *val) +static bool vmx_get_guest_bndcfgs(struct vcpu *v, u64 *val) { - /* Get a non-const pointer for vmx_vmcs_enter() */ - struct vcpu *v =3D cv->domain->vcpu[cv->vcpu_id]; - ASSERT(cpu_has_mpx && cpu_has_vmx_mpx); =20 vmx_vmcs_enter(v); diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index 815d599..0049a73 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -115,7 +115,7 @@ int init_vcpu_msr_policy(struct vcpu *v) return 0; } =20 -int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val) +int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val) { const struct vcpu *curr =3D current; const struct domain *d =3D v->domain; @@ -182,13 +182,9 @@ int guest_rdmsr(const struct vcpu *v, uint32_t msr, ui= nt64_t *val) break; =20 case MSR_IA32_BNDCFGS: - if ( !cp->feat.mpx ) + if ( !cp->feat.mpx || !is_hvm_domain(d) || + !hvm_get_guest_bndcfgs(v, val) ) goto gp_fault; - - ASSERT(is_hvm_domain(d)); - if (!hvm_get_guest_bndcfgs(v, val) ) - goto gp_fault; - break; =20 case MSR_IA32_XSS: @@ -375,13 +371,9 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t= val) break; =20 case MSR_IA32_BNDCFGS: - if ( !cp->feat.mpx ) + if ( !cp->feat.mpx || !is_hvm_domain(d) || + !hvm_set_guest_bndcfgs(v, val) ) goto gp_fault; - - ASSERT(is_hvm_domain(d)); - if ( !hvm_set_guest_bndcfgs(v, val) ) - goto gp_fault; - break; =20 case MSR_IA32_XSS: diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c index a55a400..af74f50 100644 --- a/xen/arch/x86/pv/emul-priv-op.c +++ b/xen/arch/x86/pv/emul-priv-op.c @@ -819,7 +819,7 @@ static inline bool is_cpufreq_controller(const struct d= omain *d) static int read_msr(unsigned int reg, uint64_t *val, struct x86_emulate_ctxt *ctxt) { - const struct vcpu *curr =3D current; + struct vcpu *curr =3D current; const struct domain *currd =3D curr->domain; bool vpmu_msr =3D false; int ret; diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index c811fa9..157f0de 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -145,7 +145,7 @@ struct hvm_function_table { int (*get_guest_pat)(struct vcpu *v, u64 *); int (*set_guest_pat)(struct vcpu *v, u64); =20 - bool (*get_guest_bndcfgs)(const struct vcpu *v, u64 *); + bool (*get_guest_bndcfgs)(struct vcpu *v, u64 *); bool (*set_guest_bndcfgs)(struct vcpu *v, u64); =20 void (*set_tsc_offset)(struct vcpu *v, u64 offset, u64 at_tsc); @@ -444,7 +444,7 @@ static inline unsigned long hvm_get_shadow_gs_base(stru= ct vcpu *v) return hvm_funcs.get_shadow_gs_base(v); } =20 -static inline bool hvm_get_guest_bndcfgs(const struct vcpu *v, u64 *val) +static inline bool hvm_get_guest_bndcfgs(struct vcpu *v, u64 *val) { return hvm_funcs.get_guest_bndcfgs && hvm_funcs.get_guest_bndcfgs(v, val); @@ -692,6 +692,7 @@ unsigned long hvm_get_shadow_gs_base(struct vcpu *v); void hvm_set_info_guest(struct vcpu *v); void hvm_cpuid_policy_changed(struct vcpu *v); void hvm_set_tsc_offset(struct vcpu *v, uint64_t offset, uint64_t at_tsc); +bool hvm_get_guest_bndcfgs(struct vcpu *v, uint64_t *val); =20 /* End of prototype list */ =20 diff --git a/xen/include/asm-x86/msr.h b/xen/include/asm-x86/msr.h index 0d52c08..3cbbc65 100644 --- a/xen/include/asm-x86/msr.h +++ b/xen/include/asm-x86/msr.h @@ -296,6 +296,11 @@ struct vcpu_msrs }; } misc_features_enables; =20 + /* 0x00000da0 - MSR_IA32_XSS */ + struct { + uint64_t raw; + } xss; + /* * 0xc0000103 - MSR_TSC_AUX * @@ -313,11 +318,6 @@ struct vcpu_msrs * values here may be stale in current context. */ uint32_t dr_mask[4]; - - /* 0x00000da0 - MSR_IA32_XSS */ - struct { - uint64_t raw; - } xss; }; =20 void init_guest_msr_policy(void); @@ -333,7 +333,7 @@ int init_vcpu_msr_policy(struct vcpu *v); * These functions are also used by the migration logic, so need to cope w= ith * being used outside of v's context. */ -int guest_rdmsr(const struct vcpu *v, uint32_t msr, uint64_t *val); +int guest_rdmsr(struct vcpu *v, uint32_t msr, uint64_t *val); int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_t val); =20 #endif /* !__ASSEMBLY__ */ --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel