[PATCH] x86/kernel/cpu/amd.c: don't apply the lahf_lm workaround in a hypervisor

From: Mikulas Patocka
Date: Wed Jul 12 2017 - 03:20:07 EST


When I start a virtual machine, kvm complains about accesses to an unknown
MSR ("vcpu0 unhandled rdmsr: 0xc001100d"). This is caused by the code in
init_amd_k8 that tries to work around a BIOS bug that incorrectly sets
lahf_lm.

This patch disables this workaround when running in a hypervisor.

Note that the processors for which this erratum applies do not support
virtualization at all, so if we are running in a hypervisor, we can be
sure that the workaronud doesn't apply.

Signed-off-by: Mikulas Patocka <mpatocka@xxxxxxxxxx>

---
arch/x86/kernel/cpu/amd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

Index: linux-2.6/arch/x86/kernel/cpu/amd.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/cpu/amd.c
+++ linux-2.6/arch/x86/kernel/cpu/amd.c
@@ -627,8 +627,12 @@ static void init_amd_k8(struct cpuinfo_x
* Some BIOSes incorrectly force this feature, but only K8 revision D
* (model = 0x14) and later actually support it.
* (AMD Erratum #110, docId: 25759).
+ *
+ * Don't apply this workaround in a virtual machine because kvm
+ * complains about reads from an unknown MSR.
*/
- if (c->x86_model < 0x14 && cpu_has(c, X86_FEATURE_LAHF_LM)) {
+ if (c->x86_model < 0x14 && cpu_has(c, X86_FEATURE_LAHF_LM) &&
+ !boot_cpu_has(X86_FEATURE_HYPERVISOR)) {
clear_cpu_cap(c, X86_FEATURE_LAHF_LM);
if (!rdmsrl_amd_safe(0xc001100d, &value)) {
value &= ~BIT_64(32);