From: "Jan Beulich" Subject: [PATCH v4 4/4] x86: make hvm_cpuid() tolerate NULL pointers Date: Mon, 23 Sep 2013 11:12:53 +0100 Message-ID: <5240304502000078000F570D@nat28.tlf.novell.com> References: <52402E3202000078000F5665@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part5B684435.2__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VO38W-0008Ok-La for xen-devel@lists.xenproject.org; Mon, 23 Sep 2013 10:13:01 +0000 In-Reply-To: <52402E3202000078000F5665@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser , suravee.suthikulpanit@amd.com, Jacob Shin , Eddie Dong , Jun Nakajima , Yang Z Zhang , Boris Ostrovsky List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part5B684435.2__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Now that we other HVM code start making more extensive use of hvm_cpuid(), let's not force every caller to declare dummy variables for output not cared about. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -2757,7 +2757,17 @@ void hvm_cpuid(unsigned int input, unsig { struct vcpu *v =3D current; struct domain *d =3D v->domain; - unsigned int count =3D *ecx; + unsigned int count, dummy =3D 0; + + if ( !eax ) + eax =3D &dummy; + if ( !ebx ) + ebx =3D &dummy; + if ( !ecx ) + ecx =3D &dummy; + count =3D *ecx; + if ( !edx ) + edx =3D &dummy; =20 if ( cpuid_viridian_leaves(input, eax, ebx, ecx, edx) ) return; @@ -2765,7 +2775,7 @@ void hvm_cpuid(unsigned int input, unsig if ( cpuid_hypervisor_leaves(input, count, eax, ebx, ecx, edx) ) return; =20 - domain_cpuid(d, input, *ecx, eax, ebx, ecx, edx); + domain_cpuid(d, input, count, eax, ebx, ecx, edx); =20 switch ( input ) { @@ -2853,15 +2863,15 @@ int hvm_msr_read_intercept(unsigned int=20 { struct vcpu *v =3D current; uint64_t *var_range_base, *fixed_range_base; - int index, mtrr; - uint32_t cpuid[4]; + bool_t mtrr; + unsigned int edx, index; int ret =3D X86EMUL_OKAY; =20 var_range_base =3D (uint64_t *)v->arch.hvm_vcpu.mtrr.var_ranges; fixed_range_base =3D (uint64_t *)v->arch.hvm_vcpu.mtrr.fixed_ranges; =20 - hvm_cpuid(1, &cpuid[0], &cpuid[1], &cpuid[2], &cpuid[3]); - mtrr =3D !!(cpuid[3] & cpufeat_mask(X86_FEATURE_MTRR)); + hvm_cpuid(1, NULL, NULL, NULL, &edx); + mtrr =3D !!(edx & cpufeat_mask(X86_FEATURE_MTRR)); =20 switch ( msr ) { @@ -2969,15 +2979,15 @@ int hvm_msr_read_intercept(unsigned int=20 int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content) { struct vcpu *v =3D current; - int index, mtrr; - uint32_t cpuid[4]; + bool_t mtrr; + unsigned int edx, index; int ret =3D X86EMUL_OKAY; =20 HVMTRACE_3D(MSR_WRITE, msr, (uint32_t)msr_content, (uint32_t)(msr_content >> 32)); =20 - hvm_cpuid(1, &cpuid[0], &cpuid[1], &cpuid[2], &cpuid[3]); - mtrr =3D !!(cpuid[3] & cpufeat_mask(X86_FEATURE_MTRR)); + hvm_cpuid(1, NULL, NULL, NULL, &edx); + mtrr =3D !!(edx & cpufeat_mask(X86_FEATURE_MTRR)); =20 hvm_memory_event_msr(msr, msr_content); =20 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -806,13 +806,13 @@ static inline void svm_lwp_load(struct v /* Update LWP_CFG MSR (0xc0000105). Return -1 if error; otherwise returns = 0. */ static int svm_update_lwp_cfg(struct vcpu *v, uint64_t msr_content) { - unsigned int eax, ebx, ecx, edx; + unsigned int edx; uint32_t msr_low; static uint8_t lwp_intr_vector; =20 if ( xsave_enabled(v) && cpu_has_lwp ) { - hvm_cpuid(0x8000001c, &eax, &ebx, &ecx, &edx); + hvm_cpuid(0x8000001c, NULL, NULL, NULL, &edx); msr_low =3D (uint32_t)msr_content; =20 /* generate #GP if guest tries to turn on unsupported features. = */ @@ -1163,10 +1163,10 @@ static void svm_init_erratum_383(struct=20 =20 static int svm_handle_osvw(struct vcpu *v, uint32_t msr, uint64_t *val, = bool_t read) { - uint eax, ebx, ecx, edx; + unsigned int ecx; =20 /* Guest OSVW support */ - hvm_cpuid(0x80000001, &eax, &ebx, &ecx, &edx); + hvm_cpuid(0x80000001, NULL, NULL, &ecx, NULL); if ( !test_bit((X86_FEATURE_OSVW & 31), &ecx) ) return -1; =20 --- a/xen/arch/x86/hvm/vmx/vvmx.c +++ b/xen/arch/x86/hvm/vmx/vvmx.c @@ -1813,7 +1813,7 @@ int nvmx_handle_invvpid(struct cpu_user_ int nvmx_msr_read_intercept(unsigned int msr, u64 *msr_content) { struct vcpu *v =3D current; - unsigned int eax, ebx, ecx, edx, dummy; + unsigned int eax, ebx, ecx, edx; u64 data =3D 0, host_data =3D 0; int r =3D 1; =20 @@ -1821,7 +1821,7 @@ int nvmx_msr_read_intercept(unsigned int return 0; =20 /* VMX capablity MSRs are available only when guest supports VMX. */ - hvm_cpuid(0x1, &dummy, &dummy, &ecx, &edx); + hvm_cpuid(0x1, NULL, NULL, &ecx, &edx); if ( !(ecx & cpufeat_mask(X86_FEATURE_VMXE)) ) return 0; =20 @@ -1972,18 +1972,18 @@ int nvmx_msr_read_intercept(unsigned int if ( ecx & cpufeat_mask(X86_FEATURE_XSAVE) ) data |=3D X86_CR4_OSXSAVE; =20 - hvm_cpuid(0x0, &eax, &dummy, &dummy, &dummy); + hvm_cpuid(0x0, &eax, NULL, NULL, NULL); switch ( eax ) { default: - hvm_cpuid(0xa, &eax, &dummy, &dummy, &dummy); + hvm_cpuid(0xa, &eax, NULL, NULL, NULL); /* Check whether guest has the perf monitor feature. */ if ( (eax & 0xff) && (eax & 0xff00) ) data |=3D X86_CR4_PCE; /* fall through */ case 0x7 ... 0x9: ecx =3D 0; - hvm_cpuid(0x7, &dummy, &ebx, &ecx, &dummy); + hvm_cpuid(0x7, NULL, &ebx, &ecx, NULL); if ( ebx & cpufeat_mask(X86_FEATURE_FSGSBASE) ) data |=3D X86_CR4_FSGSBASE; if ( ebx & cpufeat_mask(X86_FEATURE_SMEP) ) --=__Part5B684435.2__= Content-Type: text/plain; name="x86-hvm_cpuid-tolerate-NULL.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-hvm_cpuid-tolerate-NULL.patch" x86: make hvm_cpuid() tolerate NULL pointers=0A=0ANow that we other HVM = code start making more extensive use of=0Ahvm_cpuid(), let's not force = every caller to declare dummy variables=0Afor output not cared about.=0A=0A= Signed-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/= hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c=0A@@ -2757,7 +2757,17 @@ void = hvm_cpuid(unsigned int input, unsig=0A {=0A struct vcpu *v =3D = current;=0A struct domain *d =3D v->domain;=0A- unsigned int count = =3D *ecx;=0A+ unsigned int count, dummy =3D 0;=0A+=0A+ if ( !eax = )=0A+ eax =3D &dummy;=0A+ if ( !ebx )=0A+ ebx =3D = &dummy;=0A+ if ( !ecx )=0A+ ecx =3D &dummy;=0A+ count =3D = *ecx;=0A+ if ( !edx )=0A+ edx =3D &dummy;=0A =0A if ( = cpuid_viridian_leaves(input, eax, ebx, ecx, edx) )=0A return;=0A@@ = -2765,7 +2775,7 @@ void hvm_cpuid(unsigned int input, unsig=0A if ( = cpuid_hypervisor_leaves(input, count, eax, ebx, ecx, edx) )=0A = return;=0A =0A- domain_cpuid(d, input, *ecx, eax, ebx, ecx, edx);=0A+ = domain_cpuid(d, input, count, eax, ebx, ecx, edx);=0A =0A switch ( = input )=0A {=0A@@ -2853,15 +2863,15 @@ int hvm_msr_read_intercept(unsig= ned int =0A {=0A struct vcpu *v =3D current;=0A uint64_t *var_range= _base, *fixed_range_base;=0A- int index, mtrr;=0A- uint32_t = cpuid[4];=0A+ bool_t mtrr;=0A+ unsigned int edx, index;=0A int = ret =3D X86EMUL_OKAY;=0A =0A var_range_base =3D (uint64_t *)v->arch.hvm= _vcpu.mtrr.var_ranges;=0A fixed_range_base =3D (uint64_t *)v->arch.hvm_= vcpu.mtrr.fixed_ranges;=0A =0A- hvm_cpuid(1, &cpuid[0], &cpuid[1], = &cpuid[2], &cpuid[3]);=0A- mtrr =3D !!(cpuid[3] & cpufeat_mask(X86_FEATU= RE_MTRR));=0A+ hvm_cpuid(1, NULL, NULL, NULL, &edx);=0A+ mtrr =3D = !!(edx & cpufeat_mask(X86_FEATURE_MTRR));=0A =0A switch ( msr )=0A = {=0A@@ -2969,15 +2979,15 @@ int hvm_msr_read_intercept(unsigned int =0A = int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content)=0A = {=0A struct vcpu *v =3D current;=0A- int index, mtrr;=0A- = uint32_t cpuid[4];=0A+ bool_t mtrr;=0A+ unsigned int edx, index;=0A = int ret =3D X86EMUL_OKAY;=0A =0A HVMTRACE_3D(MSR_WRITE, msr,=0A = (uint32_t)msr_content, (uint32_t)(msr_content >> 32));=0A =0A- = hvm_cpuid(1, &cpuid[0], &cpuid[1], &cpuid[2], &cpuid[3]);=0A- mtrr = =3D !!(cpuid[3] & cpufeat_mask(X86_FEATURE_MTRR));=0A+ hvm_cpuid(1, = NULL, NULL, NULL, &edx);=0A+ mtrr =3D !!(edx & cpufeat_mask(X86_FEATURE_= MTRR));=0A =0A hvm_memory_event_msr(msr, msr_content);=0A =0A--- = a/xen/arch/x86/hvm/svm/svm.c=0A+++ b/xen/arch/x86/hvm/svm/svm.c=0A@@ = -806,13 +806,13 @@ static inline void svm_lwp_load(struct v=0A /* Update = LWP_CFG MSR (0xc0000105). Return -1 if error; otherwise returns 0. */=0A = static int svm_update_lwp_cfg(struct vcpu *v, uint64_t msr_content)=0A = {=0A- unsigned int eax, ebx, ecx, edx;=0A+ unsigned int edx;=0A = uint32_t msr_low;=0A static uint8_t lwp_intr_vector;=0A =0A if ( = xsave_enabled(v) && cpu_has_lwp )=0A {=0A- hvm_cpuid(0x8000001c,= &eax, &ebx, &ecx, &edx);=0A+ hvm_cpuid(0x8000001c, NULL, NULL, = NULL, &edx);=0A msr_low =3D (uint32_t)msr_content;=0A =0A = /* generate #GP if guest tries to turn on unsupported features. = */=0A@@ -1163,10 +1163,10 @@ static void svm_init_erratum_383(struct =0A = =0A static int svm_handle_osvw(struct vcpu *v, uint32_t msr, uint64_t = *val, bool_t read)=0A {=0A- uint eax, ebx, ecx, edx;=0A+ unsigned = int ecx;=0A =0A /* Guest OSVW support */=0A- hvm_cpuid(0x80000001, = &eax, &ebx, &ecx, &edx);=0A+ hvm_cpuid(0x80000001, NULL, NULL, &ecx, = NULL);=0A if ( !test_bit((X86_FEATURE_OSVW & 31), &ecx) )=0A = return -1;=0A =0A--- a/xen/arch/x86/hvm/vmx/vvmx.c=0A+++ b/xen/arch/x86/hvm= /vmx/vvmx.c=0A@@ -1813,7 +1813,7 @@ int nvmx_handle_invvpid(struct = cpu_user_=0A int nvmx_msr_read_intercept(unsigned int msr, u64 *msr_content= )=0A {=0A struct vcpu *v =3D current;=0A- unsigned int eax, ebx, = ecx, edx, dummy;=0A+ unsigned int eax, ebx, ecx, edx;=0A u64 data = =3D 0, host_data =3D 0;=0A int r =3D 1;=0A =0A@@ -1821,7 +1821,7 @@ = int nvmx_msr_read_intercept(unsigned int=0A return 0;=0A =0A = /* VMX capablity MSRs are available only when guest supports VMX. */=0A- = hvm_cpuid(0x1, &dummy, &dummy, &ecx, &edx);=0A+ hvm_cpuid(0x1, NULL, = NULL, &ecx, &edx);=0A if ( !(ecx & cpufeat_mask(X86_FEATURE_VMXE)) = )=0A return 0;=0A =0A@@ -1972,18 +1972,18 @@ int nvmx_msr_read_inte= rcept(unsigned int=0A if ( ecx & cpufeat_mask(X86_FEATURE_XSAVE) = )=0A data |=3D X86_CR4_OSXSAVE;=0A =0A- hvm_cpuid(0x0, = &eax, &dummy, &dummy, &dummy);=0A+ hvm_cpuid(0x0, &eax, NULL, NULL, = NULL);=0A switch ( eax )=0A {=0A default:=0A- = hvm_cpuid(0xa, &eax, &dummy, &dummy, &dummy);=0A+ = hvm_cpuid(0xa, &eax, NULL, NULL, NULL);=0A /* Check whether = guest has the perf monitor feature. */=0A if ( (eax & 0xff) && = (eax & 0xff00) )=0A data |=3D X86_CR4_PCE;=0A = /* fall through */=0A case 0x7 ... 0x9:=0A ecx =3D = 0;=0A- hvm_cpuid(0x7, &dummy, &ebx, &ecx, &dummy);=0A+ = hvm_cpuid(0x7, NULL, &ebx, &ecx, NULL);=0A if ( ebx & = cpufeat_mask(X86_FEATURE_FSGSBASE) )=0A data |=3D = X86_CR4_FSGSBASE;=0A if ( ebx & cpufeat_mask(X86_FEATURE_SMEP) = )=0A --=__Part5B684435.2__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part5B684435.2__=--