From: "Jan Beulich" Subject: [PATCH] x86-64: workaround for BIOSes wrongly enabling LAHF_LM feature indicator Date: Thu, 07 Oct 2010 11:36:22 +0100 Message-ID: <4CADBEC6020000780001B377@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part9DB071B6.0__=" 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" 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. --=__Part9DB071B6.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This workaround is taken from Linux, and the main motivation (besides such workarounds indeed belonging in the hypervisor rather than each kernel) is to suppress the warnings in the Xen log each Linux guest would cause due to the disallowed wrmsr. Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -43,6 +43,47 @@ static inline void wrmsr_amd(unsigned in ); } =20 +static inline int rdmsr_amd_safe(unsigned int msr, unsigned int *lo, + unsigned int *hi) +{ + int err; + + asm volatile("1: rdmsr\n2:\n" + ".section .fixup,\"ax\"\n" + "3: movl %6,%2\n" + " jmp 2b\n" + ".previous\n" + ".section __ex_table,\"a\"\n" + __FIXUP_ALIGN "\n" + __FIXUP_WORD " 1b,3b\n" + ".previous\n" + : "=3Da" (*lo), "=3Dd" (*hi), "=3Dr" (err) + : "c" (msr), "D" (0x9c5a203a), "2" (0), "i" (-EFAULT))= ; + + return err; +} + +static inline int wrmsr_amd_safe(unsigned int msr, unsigned int lo, + unsigned int hi) +{ + int err; + + asm volatile("1: wrmsr\n2:\n" + ".section .fixup,\"ax\"\n" + "3: movl %6,%0\n" + " jmp 2b\n" + ".previous\n" + ".section __ex_table,\"a\"\n" + __FIXUP_ALIGN "\n" + __FIXUP_WORD " 1b,3b\n" + ".previous\n" + : "=3Dr" (err) + : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a), + "0" (0), "i" (-EFAULT)); + + return err; +} + /* * Mask the features and extended features returned by CPUID. Parameters = are * set from the boot line via two methods: @@ -329,6 +370,24 @@ static void __devinit init_amd(struct cp 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */ clear_bit(0*32+31, c->x86_capability); =09 +#ifdef CONFIG_X86_64 + if (c->x86 =3D=3D 0xf && c->x86_model < 0x14 + && cpu_has(c, X86_FEATURE_LAHF_LM)) { + /* + * Some BIOSes incorrectly force this feature, but only K8 + * revision D (model =3D 0x14) and later actually support = it. + * (AMD Erratum #110, docId: 25759). + */ + unsigned int lo, hi; + + clear_bit(X86_FEATURE_LAHF_LM, c->x86_capability); + if (!rdmsr_amd_safe(0xc001100d, &lo, &hi)) { + hi &=3D ~1; + wrmsr_amd_safe(0xc001100d, lo, hi); + } + } +#endif + r =3D get_model_name(c); =20 switch(c->x86) --=__Part9DB071B6.0__= Content-Type: text/plain; name="x86_64-amd-lahf-lm.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86_64-amd-lahf-lm.patch" This workaround is taken from Linux, and the main motivation (besides=0Asuc= h workarounds indeed belonging in the hypervisor rather than each=0Akernel)= is to suppress the warnings in the Xen log each Linux guest=0Awould cause = due to the disallowed wrmsr.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/cpu/amd.c=0A+++ b/xen/arch/x86/cpu/amd.c=0A= @@ -43,6 +43,47 @@ static inline void wrmsr_amd(unsigned in=0A );=0A }=0A = =0A+static inline int rdmsr_amd_safe(unsigned int msr, unsigned int = *lo,=0A+ unsigned int *hi)=0A+{=0A+ = int err;=0A+=0A+ asm volatile("1: rdmsr\n2:\n"=0A+ = ".section .fixup,\"ax\"\n"=0A+ "3: movl %6,%2\n"=0A+ = " jmp 2b\n"=0A+ ".previous\n"=0A+ = ".section __ex_table,\"a\"\n"=0A+ __FIXUP_ALIGN = "\n"=0A+ __FIXUP_WORD " 1b,3b\n"=0A+ = ".previous\n"=0A+ : "=3Da" (*lo), "=3Dd" (*hi), "=3Dr" = (err)=0A+ : "c" (msr), "D" (0x9c5a203a), "2" (0), "i" = (-EFAULT));=0A+=0A+ return err;=0A+}=0A+=0A+static inline int = wrmsr_amd_safe(unsigned int msr, unsigned int lo,=0A+ = unsigned int hi)=0A+{=0A+ int err;=0A+=0A+ asm volatile("1: = wrmsr\n2:\n"=0A+ ".section .fixup,\"ax\"\n"=0A+ = "3: movl %6,%0\n"=0A+ " jmp 2b\n"=0A+ = ".previous\n"=0A+ ".section __ex_table,\"a\"\n"=0A+ = __FIXUP_ALIGN "\n"=0A+ __FIXUP_WORD " 1b,3b\n"=0A+ = ".previous\n"=0A+ : "=3Dr" (err)=0A+ = : "c" (msr), "a" (lo), "d" (hi), "D" (0x9c5a203a),=0A+ = "0" (0), "i" (-EFAULT));=0A+=0A+ return err;=0A+}=0A+=0A /*=0A * = Mask the features and extended features returned by CPUID. Parameters = are=0A * set from the boot line via two methods:=0A@@ -329,6 +370,24 @@ = static void __devinit init_amd(struct cp=0A 3DNow is IDd by bit 31 = in extended CPUID (1*32+31) anyway */=0A clear_bit(0*32+31, = c->x86_capability);=0A =0A+#ifdef CONFIG_X86_64=0A+ if (c->x86 =3D=3D = 0xf && c->x86_model < 0x14=0A+ && cpu_has(c, X86_FEATURE_LAHF_LM)) = {=0A+ /*=0A+ * Some BIOSes incorrectly force this = feature, but only K8=0A+ * revision D (model =3D 0x14) and = later actually support it.=0A+ * (AMD Erratum #110, docId: = 25759).=0A+ */=0A+ unsigned int lo, hi;=0A+=0A+ = clear_bit(X86_FEATURE_LAHF_LM, c->x86_capability);=0A+ if = (!rdmsr_amd_safe(0xc001100d, &lo, &hi)) {=0A+ hi &=3D = ~1;=0A+ wrmsr_amd_safe(0xc001100d, lo, hi);=0A+ = }=0A+ }=0A+#endif=0A+=0A r =3D get_model_name(c);=0A =0A = switch(c->x86)=0A --=__Part9DB071B6.0__= 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 --=__Part9DB071B6.0__=--