KVM/x86: Move definition of __ex to x86.h
PATCH v3 1/1 KVM/x86: Move definition of __ex to x86.h
Merge __kvm_handle_fault_on_reboot with its sole user and move the definition of __ex to a common include to be shared between VMX and SVM.
v2: Rebase to the latest kvm/queue.
v3: Incorporate changes from review comments.
--- arch/x86/include/asm/kvm_host.h | 25 ------------------------- arch/x86/kvm/svm/sev.c | 2 -- arch/x86/kvm/svm/svm.c | 2 -- arch/x86/kvm/vmx/vmx.c | 4 +--- arch/x86/kvm/vmx/vmx_ops.h | 4 +--- arch/x86/kvm/x86.h | 24 ++++++++++++++++++++++++ 6 files changed, 26 insertions(+), 35 deletions(-)
arch/x86/include/asm/kvm_host.h +0 -25
@@ -1634,31 +1634,6 @@ enum {#define kvm_arch_vcpu_memslots_id (vcpu) ((vcpu)->arch.hflags & HF_SMM_MASK ? 1 : 0)#define kvm_memslots_for_spte_role (kvm, role) __kvm_memslots(kvm, (role).smm) -asmlinkage void kvm_spurious_fault(void); - -/* -* Hardware virtualization extension instructions may fault if a -* reboot turns off virtualization while processes are running. -* Usually after catching the fault we just panic; during reboot -* instead the instruction is ignored. -*/ -#define __kvm_handle_fault_on_reboot (insn) \ - "666: \n\t" \ - insn "\n\t" \ - "jmp 668f \n\t" \ - "667: \n\t" \ - "1: \n\t" \ - ".pushsection .discard.instr_begin \n\t" \ - ".long 1b - . \n\t" \ - ".popsection \n\t" \ - "call kvm_spurious_fault \n\t" \ - "1: \n\t" \ - ".pushsection .discard.instr_end \n\t" \ - ".long 1b - . \n\t" \ - ".popsection \n\t" \ - "668: \n\t" \ - _ASM_EXTABLE(666b, 667b) -#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end,unsigned flags);
arch/x86/kvm/svm/sev.c +0 -2
@@ -25,8 +25,6 @@#include "cpuid.h" #include "trace.h" -#define __ex (x) __kvm_handle_fault_on_reboot(x) -static u8 sev_enc_bit;static int sev_flush_asids (void );static DECLARE_RWSEM (sev_deactivate_lock);
arch/x86/kvm/svm/svm.c +0 -2
@@ -42,8 +42,6 @@#include "svm.h" -#define __ex (x) __kvm_handle_fault_on_reboot(x) -MODULE_AUTHOR ("Qumranet" );MODULE_LICENSE ("GPL" );
arch/x86/kvm/vmx/vmx.c +1 -3
@@ -2320,9 +2320,7 @@ static void vmclear_local_loaded_vmcss(void) } -/* Just like cpu_vmxoff(), but with the __kvm_handle_fault_on_reboot() -* tricks. -*/ +/* Just like cpu_vmxoff(), but with the fault handling. */ static void kvm_cpu_vmxoff (void ) { asm volatile (__ex("vmxoff"));
arch/x86/kvm/vmx/vmx_ops.h +1 -3
@@ -4,13 +4,11 @@#include <linux/nospec.h> -#include <asm/kvm_host.h> #include <asm/vmx.h> #include "evmcs.h" #include "vmcs.h" - -#define __ex (x) __kvm_handle_fault_on_reboot(x) +#include "x86.h" asmlinkage void vmread_error(unsigned long field, bool fault); __attribute__((regparm(0))) void vmread_error_trampoline(unsigned long field,
arch/x86/kvm/x86.h +24 -0
@@ -8,6 +8,30 @@#include "kvm_cache_regs.h" #include "kvm_emulate.h" +asmlinkage void kvm_spurious_fault(void); + +/* +* Handle a fault on a hardware virtualization (VMX or SVM) instruction. +* +* Hardware virtualization extension instructions may fault if a reboot turns +* off virtualization while processes are running. Usually after catching the +* fault we just panic; during reboot instead the instruction is ignored. +*/ +#define __ex (insn) \ + "666: " insn "\n" \ + " jmp 669f\n" \ + "667:\n" \ + " .pushsection .discard.instr_begin\n" \ + " .long 667b - .\n" \ + " .popsection\n" \ + " call kvm_spurious_fault\n" \ + "668:\n" \ + " .pushsection .discard.instr_end\n" \ + " .long 668b - .\n" \ + " .popsection\n" \ + "669:\n" \ + _ASM_EXTABLE(666b, 667b) +#define KVM_DEFAULT_PLE_GAP 128#define KVM_VMX_DEFAULT_PLE_WINDOW 4096#define KVM_DEFAULT_PLE_WINDOW_GROW 2
Signature · 1 line
2.29.2
Quoted 125 lines · Uros Bizjak
Merge
__kvm_handle_fault_on_rebootwith its sole user and move the definition of__exto a common include to be shared between VMX and SVM.v2: Rebase to the latest kvm/queue.
v3: Incorporate changes from review comments.
Cc Paolo Bonzini <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Uros Bizjak <[email protected]>Reviewed-by Krish Sadhukhan <[email protected]>--- arch/x86/include/asm/kvm_host.h | 25 ------------------------- arch/x86/kvm/svm/sev.c | 2 -- arch/x86/kvm/svm/svm.c | 2 -- arch/x86/kvm/vmx/vmx.c | 4 +--- arch/x86/kvm/vmx/vmx_ops.h | 4 +--- arch/x86/kvm/x86.h | 24 ++++++++++++++++++++++++ 6 files changed, 26 insertions(+), 35 deletions(-)arch/x86/include/asm/kvm_host.h +0
-25@@ -1634,31 +1634,6 @@ enum {#define kvm_arch_vcpu_memslots_id (vcpu) ((vcpu)->arch.hflags & HF_SMM_MASK ? 1 : 0)#define kvm_memslots_for_spte_role (kvm, role) __kvm_memslots(kvm, (role).smm) -asmlinkage void kvm_spurious_fault(void); - -/* -* Hardware virtualization extension instructions may fault if a -* reboot turns off virtualization while processes are running. -* Usually after catching the fault we just panic; during reboot -* instead the instruction is ignored. -*/ -#define __kvm_handle_fault_on_reboot (insn) \ - "666: \n\t" \ - insn "\n\t" \ - "jmp 668f \n\t" \ - "667: \n\t" \ - "1: \n\t" \ - ".pushsection .discard.instr_begin \n\t" \ - ".long 1b - . \n\t" \ - ".popsection \n\t" \ - "call kvm_spurious_fault \n\t" \ - "1: \n\t" \ - ".pushsection .discard.instr_end \n\t" \ - ".long 1b - . \n\t" \ - ".popsection \n\t" \ - "668: \n\t" \ - _ASM_EXTABLE(666b, 667b) -#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end,unsigned flags);arch/x86/kvm/svm/sev.c +0
-2@@ -25,8 +25,6 @@#include "cpuid.h" #include "trace.h" -#define __ex (x) __kvm_handle_fault_on_reboot(x) -static u8 sev_enc_bit;static int sev_flush_asids (void );static DECLARE_RWSEM (sev_deactivate_lock);arch/x86/kvm/svm/svm.c +0
-2@@ -42,8 +42,6 @@#include "svm.h" -#define __ex (x) __kvm_handle_fault_on_reboot(x) -MODULE_AUTHOR ("Qumranet" );MODULE_LICENSE ("GPL" );arch/x86/kvm/vmx/vmx.c +1
-3@@ -2320,9 +2320,7 @@ static void vmclear_local_loaded_vmcss(void) } -/* Just like cpu_vmxoff(), but with the __kvm_handle_fault_on_reboot() -* tricks. -*/ +/* Just like cpu_vmxoff(), but with the fault handling. */ static void kvm_cpu_vmxoff (void ) { asm volatile (__ex("vmxoff"));arch/x86/kvm/vmx/vmx_ops.h +1
-3@@ -4,13 +4,11 @@#include <linux/nospec.h> -#include <asm/kvm_host.h> #include <asm/vmx.h> #include "evmcs.h" #include "vmcs.h" - -#define __ex (x) __kvm_handle_fault_on_reboot(x) +#include "x86.h" asmlinkage void vmread_error(unsigned long field, bool fault); __attribute__((regparm(0))) void vmread_error_trampoline(unsigned long field,arch/x86/kvm/x86.h +0
-0@@ -8,6 +8,30 @@#include "kvm_cache_regs.h" #include "kvm_emulate.h"
arch/x86/kvm/x86.h line 20
Quoted 10 lines
arch/x86/kvm/x86.h +10
-0+asmlinkage void kvm_spurious_fault(void); + +/* +* Handle a fault on a hardware virtualization (VMX or SVM) instruction. +* +* Hardware virtualization extension instructions may fault if a reboot turns +* off virtualization while processes are running. Usually after catching the +* fault we just panic; during reboot instead the instruction is ignored. +*/ +#define __ex (insn) \
While the previous name was too elaborate, this new name is very cryptic. Unless we are saving for space, it's better to give a somewhat descriptive name.
Quoted 17 lines
arch/x86/kvm/x86.h +14
-0+"666: " insn"\n" \ +" jmp 669f\n" \ +"667:\n" \ +" .pushsection .discard.instr_begin\n" \ +" .long 667b - .\n" \ +" .popsection\n" \ +" call kvm_spurious_fault\n" \ +"668:\n" \ +" .pushsection .discard.instr_end\n" \ +" .long 668b - .\n" \ +" .popsection\n" \ +"669:\n" \ + _ASM_EXTABLE(666b, 667b) +#define KVM_DEFAULT_PLE_GAP 128#define KVM_VMX_DEFAULT_PLE_WINDOW 4096#define KVM_DEFAULT_PLE_WINDOW_GROW 2
Quoted 128 lines · Krish Sadhukhan
Quoted 125 lines · Uros Bizjak
Merge
__kvm_handle_fault_on_rebootwith its sole user and move the definition of__exto a common include to be shared between VMX and SVM.v2: Rebase to the latest kvm/queue.
v3: Incorporate changes from review comments.
Cc Paolo Bonzini <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Uros Bizjak <[email protected]>Reviewed-by Krish Sadhukhan <[email protected]>--- arch/x86/include/asm/kvm_host.h | 25 ------------------------- arch/x86/kvm/svm/sev.c | 2 -- arch/x86/kvm/svm/svm.c | 2 -- arch/x86/kvm/vmx/vmx.c | 4 +--- arch/x86/kvm/vmx/vmx_ops.h | 4 +--- arch/x86/kvm/x86.h | 24 ++++++++++++++++++++++++ 6 files changed, 26 insertions(+), 35 deletions(-)arch/x86/include/asm/kvm_host.h +0
-25@@ -1634,31 +1634,6 @@ enum {#define kvm_arch_vcpu_memslots_id (vcpu) ((vcpu)->arch.hflags & HF_SMM_MASK ? 1 : 0)#define kvm_memslots_for_spte_role (kvm, role) __kvm_memslots(kvm, (role).smm) -asmlinkage void kvm_spurious_fault(void); - -/* -* Hardware virtualization extension instructions may fault if a -* reboot turns off virtualization while processes are running. -* Usually after catching the fault we just panic; during reboot -* instead the instruction is ignored. -*/ -#define __kvm_handle_fault_on_reboot (insn) \ - "666: \n\t" \ - insn "\n\t" \ - "jmp 668f \n\t" \ - "667: \n\t" \ - "1: \n\t" \ - ".pushsection .discard.instr_begin \n\t" \ - ".long 1b - . \n\t" \ - ".popsection \n\t" \ - "call kvm_spurious_fault \n\t" \ - "1: \n\t" \ - ".pushsection .discard.instr_end \n\t" \ - ".long 1b - . \n\t" \ - ".popsection \n\t" \ - "668: \n\t" \ - _ASM_EXTABLE(666b, 667b) -#define KVM_ARCH_WANT_MMU_NOTIFIER int kvm_unmap_hva_range (struct kvm *kvm,unsigned long start,unsigned long end,unsigned flags);arch/x86/kvm/svm/sev.c +0
-2@@ -25,8 +25,6 @@#include "cpuid.h" #include "trace.h" -#define __ex (x) __kvm_handle_fault_on_reboot(x) -static u8 sev_enc_bit;static int sev_flush_asids (void );static DECLARE_RWSEM (sev_deactivate_lock);arch/x86/kvm/svm/svm.c +0
-2@@ -42,8 +42,6 @@#include "svm.h" -#define __ex (x) __kvm_handle_fault_on_reboot(x) -MODULE_AUTHOR ("Qumranet" );MODULE_LICENSE ("GPL" );arch/x86/kvm/vmx/vmx.c +1
-3@@ -2320,9 +2320,7 @@ static void vmclear_local_loaded_vmcss(void) } -/* Just like cpu_vmxoff(), but with the __kvm_handle_fault_on_reboot() -* tricks. -*/ +/* Just like cpu_vmxoff(), but with the fault handling. */ static void kvm_cpu_vmxoff (void ) { asm volatile (__ex("vmxoff"));arch/x86/kvm/vmx/vmx_ops.h +1
-3@@ -4,13 +4,11 @@#include <linux/nospec.h> -#include <asm/kvm_host.h> #include <asm/vmx.h> #include "evmcs.h" #include "vmcs.h" - -#define __ex (x) __kvm_handle_fault_on_reboot(x) +#include "x86.h" asmlinkage void vmread_error(unsigned long field, bool fault); __attribute__((regparm(0))) void vmread_error_trampoline(unsigned long field,arch/x86/kvm/x86.h +0
-0@@ -8,6 +8,30 @@#include "kvm_cache_regs.h" #include "kvm_emulate.h"
Quoted 15 lines
arch/x86/kvm/x86.h line 20
Quoted 10 lines
arch/x86/kvm/x86.h +10
-0+asmlinkage void kvm_spurious_fault(void); + +/* +* Handle a fault on a hardware virtualization (VMX or SVM) instruction. +* +* Hardware virtualization extension instructions may fault if a reboot turns +* off virtualization while processes are running. Usually after catching the +* fault we just panic; during reboot instead the instruction is ignored. +*/ +#define __ex (insn) \While the previous name was too elaborate, this new name is very cryptic. Unless we are saving for space, it's better to give a somewhat descriptive name.
Then we will need to update all usage sites to a new name, something I tried to avoid.
Uros.
Quoted 17 lines
Quoted 17 lines
arch/x86/kvm/x86.h +14
-0+"666: " insn"\n" \ +" jmp 669f\n" \ +"667:\n" \ +" .pushsection .discard.instr_begin\n" \ +" .long 667b - .\n" \ +" .popsection\n" \ +" call kvm_spurious_fault\n" \ +"668:\n" \ +" .pushsection .discard.instr_end\n" \ +" .long 668b - .\n" \ +" .popsection\n" \ +"669:\n" \ + _ASM_EXTABLE(666b, 667b) +#define KVM_DEFAULT_PLE_GAP 128#define KVM_VMX_DEFAULT_PLE_WINDOW 4096#define KVM_DEFAULT_PLE_WINDOW_GROW 2
Sean Christopherson
maintainerQuoted 16 lines · Krish Sadhukhan
Quoted 14 lines · Uros Bizjak
arch/x86/kvm/x86.h +7
-0@@ -8,6 +8,30 @@#include "kvm_cache_regs.h" #include "kvm_emulate.h" +asmlinkage void kvm_spurious_fault(void); + +/* +* Handle a fault on a hardware virtualization (VMX or SVM) instruction. +* +* Hardware virtualization extension instructions may fault if a reboot turns +* off virtualization while processes are running. Usually after catching the
Quoted 8 lines
arch/x86/kvm/x86.h line 20
Quoted 3 lines
arch/x86/kvm/x86.h +3
-0+* fault we just panic; during reboot instead the instruction is ignored. +*/ +#define __ex (insn) \While the previous name was too elaborate, this new name is very cryptic. Unless we are saving for space,it's better to give a somewhat descriptive name.
We are saving for space in a way. Not so much to actually save lines of code, but to avoid stealing the focus from the code that matters. __ex() is cryptic for the completely unfamiliar, but I'm worried that anything more verbose will harm the readability of the code where it is used, which is usually what's more important in the long run.
__ex() does have some meaning, as it's connected to the various ex_handler_*() helpers. ex_handle() is the best semi-verbose alternative that I can think of, but even that is too long for my liking when reading the inline asm flows. And it's not like ex_handle() tells the whole story; the reader still has to go to the definition to understand what it does, or worse, will make incorrect assumptions about how exceptions are handled.
E.g. with the short version, my eyes gravitate toward vmxoff/vmsave without getting stuck on the verbose wrapper.
asm volatile (__ex("vmxoff"));
asm volatile(__ex("vmsave") : : "a" (__sme_page_pa(sd->save_area)) : "memory");vs.
asm volatile (ex_handle("vmxoff"));
asm volatile(ex_handle("vmsave") : : "a" (__sme_page_pa(sd->save_area)) : "memory");Quoted 7 lines · Uros Bizjak
Merge
__kvm_handle_fault_on_rebootwith its sole user and move the definition of__exto a common include to be shared between VMX and SVM.v2: Rebase to the latest kvm/queue.
v3: Incorporate changes from review comments.
The v2, v3, ... vN patch history should go below the '---' so that it doesn't need to be manually stripped when applying.
Quoted 5 lines
Cc Paolo Bonzini <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Uros Bizjak <[email protected]>Reviewed-by Krish Sadhukhan <[email protected]>---
vN stuff down here
Quoted 7 lines
arch/x86/include/asm/kvm_host.h | 25 ------------------------- arch/x86/kvm/svm/sev.c | 2 -- arch/x86/kvm/svm/svm.c | 2 -- arch/x86/kvm/vmx/vmx.c | 4 +--- arch/x86/kvm/vmx/vmx_ops.h | 4 +--- arch/x86/kvm/x86.h | 24 ++++++++++++++++++++++++ 6 files changed, 26 insertions(+), 35 deletions(-)
Sean Christopherson
maintainerQuoted 28 lines · Sean Christopherson
Quoted 7 lines · Uros Bizjak
Merge
__kvm_handle_fault_on_rebootwith its sole user and move the definition of__exto a common include to be shared between VMX and SVM.v2: Rebase to the latest kvm/queue.
v3: Incorporate changes from review comments.
The v2, v3, ... vN patch history should go below the '---' so that it doesn't need to be manually stripped when applying.
Quoted 5 lines
Cc Paolo Bonzini <[email protected]>Cc Sean Christopherson <[email protected]>Signed-off-by Uros Bizjak <[email protected]>Reviewed-by Krish Sadhukhan <[email protected]>---
vN stuff down here
Quoted 7 lines
arch/x86/include/asm/kvm_host.h | 25 ------------------------- arch/x86/kvm/svm/sev.c | 2 -- arch/x86/kvm/svm/svm.c | 2 -- arch/x86/kvm/vmx/vmx.c | 4 +--- arch/x86/kvm/vmx/vmx_ops.h | 4 +--- arch/x86/kvm/x86.h | 24 ++++++++++++++++++++++++ 6 files changed, 26 insertions(+), 35 deletions(-)
Quoted 1 line
Reviewed-by Sean Christopherson <[email protected]>
Paolo, can you hold off on queuing this patch? Long story short, this jogged my memory for something tangentially related and I ended up with series that kills off __ex() / ____kvm_handle_fault_on_reboot() completely. It's coded up, I just need to test. I'm OOO for a few days, will hopefully get it posted next week.
Thanks!