diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2014-09-22 07:17:48 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-09-24 08:07:57 -0400 |
commit | c1118b3602c2329671ad5ec8bdf8e374323d6343 (patch) | |
tree | 57dce6397f2dbf19701fa1a7671abcde453e170b /arch/x86/include | |
parent | 81760dccf8d1fe5b128b58736fe3f56a566133cb (diff) |
x86: kvm: use alternatives for VMCALL vs. VMMCALL if kernel text is read-only
On x86_64, kernel text mappings are mapped read-only with CONFIG_DEBUG_RODATA.
In that case, KVM will fail to patch VMCALL instructions to VMMCALL
as required on AMD processors.
The failure mode is currently a divide-by-zero exception, which obviously
is a KVM bug that has to be fixed. However, picking the right instruction
between VMCALL and VMMCALL will be faster and will help if you cannot upgrade
the hypervisor.
Reported-by: Chris Webb <chris@arachsys.com>
Tested-by: Chris Webb <chris@arachsys.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org
Acked-by: Borislav Petkov <bp@suse.de>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/include')
-rw-r--r-- | arch/x86/include/asm/cpufeature.h | 1 | ||||
-rw-r--r-- | arch/x86/include/asm/kvm_para.h | 10 |
2 files changed, 9 insertions, 2 deletions
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index bb9b258d60e7..2075e6c34c78 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h | |||
@@ -202,6 +202,7 @@ | |||
202 | #define X86_FEATURE_DECODEASSISTS ( 8*32+12) /* AMD Decode Assists support */ | 202 | #define X86_FEATURE_DECODEASSISTS ( 8*32+12) /* AMD Decode Assists support */ |
203 | #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */ | 203 | #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */ |
204 | #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */ | 204 | #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */ |
205 | #define X86_FEATURE_VMMCALL ( 8*32+15) /* Prefer vmmcall to vmcall */ | ||
205 | 206 | ||
206 | 207 | ||
207 | /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */ | 208 | /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */ |
diff --git a/arch/x86/include/asm/kvm_para.h b/arch/x86/include/asm/kvm_para.h index c7678e43465b..e62cf897f781 100644 --- a/arch/x86/include/asm/kvm_para.h +++ b/arch/x86/include/asm/kvm_para.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define _ASM_X86_KVM_PARA_H | 2 | #define _ASM_X86_KVM_PARA_H |
3 | 3 | ||
4 | #include <asm/processor.h> | 4 | #include <asm/processor.h> |
5 | #include <asm/alternative.h> | ||
5 | #include <uapi/asm/kvm_para.h> | 6 | #include <uapi/asm/kvm_para.h> |
6 | 7 | ||
7 | extern void kvmclock_init(void); | 8 | extern void kvmclock_init(void); |
@@ -16,10 +17,15 @@ static inline bool kvm_check_and_clear_guest_paused(void) | |||
16 | } | 17 | } |
17 | #endif /* CONFIG_KVM_GUEST */ | 18 | #endif /* CONFIG_KVM_GUEST */ |
18 | 19 | ||
19 | /* This instruction is vmcall. On non-VT architectures, it will generate a | 20 | #ifdef CONFIG_DEBUG_RODATA |
20 | * trap that we will then rewrite to the appropriate instruction. | 21 | #define KVM_HYPERCALL \ |
22 | ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL) | ||
23 | #else | ||
24 | /* On AMD processors, vmcall will generate a trap that we will | ||
25 | * then rewrite to the appropriate instruction. | ||
21 | */ | 26 | */ |
22 | #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1" | 27 | #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1" |
28 | #endif | ||
23 | 29 | ||
24 | /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall | 30 | /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall |
25 | * instruction. The hypervisor may replace it with something else but only the | 31 | * instruction. The hypervisor may replace it with something else but only the |