From: "Jan Beulich" Subject: [PATCH] svm: support EFER.LMSLE for guests Date: Tue, 04 May 2010 17:03:34 +0100 Message-ID: <4BE061760200007800001362@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartC0EA6646.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com Cc: andre.przywara@amd.com 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. --=__PartC0EA6646.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Now that the feature is officially documented (see http://support.amd.com/us/Processor_TechDocs/24593.pdf), I think it makes sense to also allow HVM guests to make use of it. Signed-off-by: Jan Beulich Cc: Andre Przywara --- 2010-05-04.orig/xen/arch/x86/hvm/hvm.c 2010-04-22 14:43:25.0000000= 00 +0200 +++ 2010-05-04/xen/arch/x86/hvm/hvm.c 2010-05-04 13:26:07.000000000 = +0200 @@ -590,6 +590,7 @@ static bool_t hvm_efer_valid(uint64_t va ((sizeof(long) !=3D 8) && (value & EFER_LME)) || (!cpu_has_nx && (value & EFER_NX)) || (!cpu_has_syscall && (value & EFER_SCE)) || + (!cpu_has_lmsl && (value & EFER_LMSLE)) || (!cpu_has_ffxsr && (value & EFER_FFXSE)) || ((value & (EFER_LME|EFER_LMA)) =3D=3D EFER_LMA)); } @@ -641,7 +642,8 @@ static int hvm_load_cpu_ctxt(struct doma } =20 if ( !hvm_efer_valid( - ctxt.msr_efer, EFER_FFXSE | EFER_LME | EFER_LMA | EFER_NX | = EFER_SCE) ) + ctxt.msr_efer, + EFER_FFXSE | EFER_LMSLE | EFER_LME | EFER_LMA | EFER_NX | = EFER_SCE) ) { gdprintk(XENLOG_ERR, "HVM restore: bad EFER 0x%"PRIx64"\n", ctxt.msr_efer); @@ -995,7 +997,8 @@ int hvm_set_efer(uint64_t value) =20 value &=3D ~EFER_LMA; =20 - if ( !hvm_efer_valid(value, EFER_FFXSE | EFER_LME | EFER_NX | = EFER_SCE) ) + if ( !hvm_efer_valid(value, + EFER_FFXSE | EFER_LMSLE | EFER_LME | EFER_NX | EFER_SCE) ) { gdprintk(XENLOG_WARNING, "Trying to set reserved bit in " "EFER: %"PRIx64"\n", value); --- 2010-05-04.orig/xen/arch/x86/hvm/svm/svm.c 2010-04-12 11:28:20.0000000= 00 +0200 +++ 2010-05-04/xen/arch/x86/hvm/svm/svm.c 2010-05-04 13:23:02.0000000= 00 +0200 @@ -57,6 +57,11 @@ =20 u32 svm_feature_flags; =20 +#ifdef __x86_64__ +/* indicate whether guest may use EFER.LMSLE */ +unsigned char cpu_has_lmsl =3D 0; +#endif + #define set_segment_register(name, value) \ asm volatile ( "movw %%ax ,%%" STR(name) "" : : "a" (value) ) =20 @@ -848,6 +853,29 @@ static int svm_cpu_up(struct cpuinfo_x86 /* Initialize core's ASID handling. */ svm_asid_init(c); =20 +#ifdef __x86_64__ + /* + * Check whether EFER.LMSLE can be written. + * Unfortunately there's no feature bit defined for this. + */ + eax =3D read_efer(); + edx =3D read_efer() >> 32; + if ( wrmsr_safe(MSR_EFER, eax | EFER_LMSLE, edx) =3D=3D 0 ) + rdmsr(MSR_EFER, eax, edx); + if ( eax & EFER_LMSLE ) + { + if ( c =3D=3D &boot_cpu_data ) + cpu_has_lmsl =3D 1; + wrmsr(MSR_EFER, eax ^ EFER_LMSLE, edx); + } + else + { + if ( cpu_has_lmsl ) + printk(XENLOG_WARNING "Inconsistent LMLSE support across = CPUs!\n"); + cpu_has_lmsl =3D 0; + } +#endif + return 1; } =20 --- 2010-05-04.orig/xen/include/asm-x86/hvm/hvm.h 2010-04-12 = 11:28:20.000000000 +0200 +++ 2010-05-04/xen/include/asm-x86/hvm/hvm.h 2010-05-04 13:23:02.0000000= 00 +0200 @@ -136,6 +136,12 @@ struct hvm_function_table { extern struct hvm_function_table hvm_funcs; extern int hvm_enabled; =20 +#ifdef __i386__ +# define cpu_has_lmsl 0 +#else +extern unsigned char cpu_has_lmsl; +#endif + int hvm_domain_initialise(struct domain *d); void hvm_domain_relinquish_resources(struct domain *d); void hvm_domain_destroy(struct domain *d); --=__PartC0EA6646.1__= Content-Type: text/plain; name="svm-lmsl.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="svm-lmsl.patch" Now that the feature is officially documented (see=0Ahttp://support.amd.com= /us/Processor_TechDocs/24593.pdf), I think it=0Amakes sense to also allow = HVM guests to make use of it.=0A=0ASigned-off-by: Jan Beulich =0ACc: Andre Przywara =0A=0A--- 2010-05-04.= orig/xen/arch/x86/hvm/hvm.c 2010-04-22 14:43:25.000000000 +0200=0A+++ = 2010-05-04/xen/arch/x86/hvm/hvm.c 2010-05-04 13:26:07.000000000 = +0200=0A@@ -590,6 +590,7 @@ static bool_t hvm_efer_valid(uint64_t va=0A = ((sizeof(long) !=3D 8) && (value & EFER_LME)) ||=0A = (!cpu_has_nx && (value & EFER_NX)) ||=0A (!cpu_has_syscall && = (value & EFER_SCE)) ||=0A+ (!cpu_has_lmsl && (value & = EFER_LMSLE)) ||=0A (!cpu_has_ffxsr && (value & EFER_FFXSE)) = ||=0A ((value & (EFER_LME|EFER_LMA)) =3D=3D EFER_LMA));=0A = }=0A@@ -641,7 +642,8 @@ static int hvm_load_cpu_ctxt(struct doma=0A = }=0A =0A if ( !hvm_efer_valid(=0A- ctxt.msr_efer, EFER_FFXSE | = EFER_LME | EFER_LMA | EFER_NX | EFER_SCE) )=0A+ ctxt.msr_efer,=0A+ = EFER_FFXSE | EFER_LMSLE | EFER_LME | EFER_LMA | EFER_NX | EFER_SCE) = )=0A {=0A gdprintk(XENLOG_ERR, "HVM restore: bad EFER = 0x%"PRIx64"\n",=0A ctxt.msr_efer);=0A@@ -995,7 +997,8 @@ = int hvm_set_efer(uint64_t value)=0A =0A value &=3D ~EFER_LMA;=0A =0A- = if ( !hvm_efer_valid(value, EFER_FFXSE | EFER_LME | EFER_NX | EFER_SCE) = )=0A+ if ( !hvm_efer_valid(value,=0A+ EFER_FFXSE | EFER_LMSLE= | EFER_LME | EFER_NX | EFER_SCE) )=0A {=0A gdprintk(XENLOG_WAR= NING, "Trying to set reserved bit in "=0A "EFER: = %"PRIx64"\n", value);=0A--- 2010-05-04.orig/xen/arch/x86/hvm/svm/svm.c = 2010-04-12 11:28:20.000000000 +0200=0A+++ 2010-05-04/xen/arch/x86/hvm/svm/s= vm.c 2010-05-04 13:23:02.000000000 +0200=0A@@ -57,6 +57,11 @@=0A =0A = u32 svm_feature_flags;=0A =0A+#ifdef __x86_64__=0A+/* indicate whether = guest may use EFER.LMSLE */=0A+unsigned char cpu_has_lmsl =3D 0;=0A+#endif= =0A+=0A #define set_segment_register(name, value) \=0A asm volatile ( = "movw %%ax ,%%" STR(name) "" : : "a" (value) )=0A =0A@@ -848,6 +853,29 @@ = static int svm_cpu_up(struct cpuinfo_x86=0A /* Initialize core's ASID = handling. */=0A svm_asid_init(c);=0A =0A+#ifdef __x86_64__=0A+ = /*=0A+ * Check whether EFER.LMSLE can be written.=0A+ * Unfortunate= ly there's no feature bit defined for this.=0A+ */=0A+ eax =3D = read_efer();=0A+ edx =3D read_efer() >> 32;=0A+ if ( wrmsr_safe(MSR_E= FER, eax | EFER_LMSLE, edx) =3D=3D 0 )=0A+ rdmsr(MSR_EFER, eax, = edx);=0A+ if ( eax & EFER_LMSLE )=0A+ {=0A+ if ( c =3D=3D = &boot_cpu_data )=0A+ cpu_has_lmsl =3D 1;=0A+ wrmsr(MSR_EF= ER, eax ^ EFER_LMSLE, edx);=0A+ }=0A+ else=0A+ {=0A+ if ( = cpu_has_lmsl )=0A+ printk(XENLOG_WARNING "Inconsistent LMLSE = support across CPUs!\n");=0A+ cpu_has_lmsl =3D 0;=0A+ }=0A+#endif= =0A+=0A return 1;=0A }=0A =0A--- 2010-05-04.orig/xen/include/asm-x86/hv= m/hvm.h 2010-04-12 11:28:20.000000000 +0200=0A+++ 2010-05-04/xen/include/as= m-x86/hvm/hvm.h 2010-05-04 13:23:02.000000000 +0200=0A@@ -136,6 +136,12 @@ = struct hvm_function_table {=0A extern struct hvm_function_table hvm_funcs;= =0A extern int hvm_enabled;=0A =0A+#ifdef __i386__=0A+# define cpu_has_lmsl= 0=0A+#else=0A+extern unsigned char cpu_has_lmsl;=0A+#endif=0A+=0A int = hvm_domain_initialise(struct domain *d);=0A void hvm_domain_relinquish_reso= urces(struct domain *d);=0A void hvm_domain_destroy(struct domain *d);=0A --=__PartC0EA6646.1__= 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.xensource.com http://lists.xensource.com/xen-devel --=__PartC0EA6646.1__=--