x86: always inline functions called after set_exception_return
Subsystems (2)
PATCH 1/1 x86: always inline functions called after set_exception_return
set_exception_return forces exceptions handlers to return to a specific address instead of returning to the instruction address pushed by the CPU at the time of the exception. The unit tests apic.c and vmx.c use this functionality to recover from expected exceptions.
When using set_exception_return we have to be careful not to modify the stack (such as by doing a function call) as triggering the exception will likely jump us past the instructions which undo the stack manipulation (such as a ret). To accomplish this, declare all functions called after set_exception_return as __always_inline, so that the compiler always inlines them.
--- lib/libcflat.h | 4 ++++ lib/x86/processor.h | 2 +- x86/vmx.c | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-)
lib/libcflat.h +4 -0
@@ -27,6 +27,10 @@#define __unused __attribute__((__unused__)) +#ifndef __always_inline +# define __always_inline inline __attribute__((always_inline)) +#endif +#define xstr (s) xxstr(s)#define xxstr (s) #s
lib/x86/processor.h +1 -1
@@ -149,7 +149,7 @@ static inline u64 rdmsr(u32 index)return a | ((u64 )d <<32 ); } -static inline void wrmsr (u32 index,u64 val) +static __always_inline void wrmsr(u32 index, u64 val) {u32 a = val, d = val >>32 ; asmvolatile ("wrmsr" : :"a" (a),"d" (d),"c" (index) :"memory" );
x86/vmx.c +2 -2
@@ -117,7 +117,7 @@ static void __attribute__((__used__)) syscall_handler(u64 syscall_no) current->syscall_handler (syscall_no); } -static inline int vmx_on () +static __always_inline int vmx_on() {bool ret;u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ;
@@ -126,7 +126,7 @@ static inline int vmx_on()return ret; } -static inline int vmx_off () +static __always_inline int vmx_off() {bool ret;u64 rflags =read_rflags () |X86_EFLAGS_CF |X86_EFLAGS_ZF ;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
Paolo Bonzini
maintainerQuoted 11 lines · David Matlack
set_exception_returnforces exceptions handlers to return to a specific address instead of returning to the instruction address pushed by the CPU at the time of the exception. The unit testsapic.candvmx.cuse this functionality to recover from expected exceptions.When using
set_exception_returnwe have to be careful not to modify the stack (such as by doing a function call) as triggering the exception will likely jump us past the instructions which undo the stack manipulation (such as a ret). To accomplish this, declare all functions called afterset_exception_returnas__always_inline, so that the compiler always inlines them.
set_exception_return is generally not a great idea IMHO---thanks for looking at it.
A couple years ago we discussed adding setjmp/longjmp to libcflat
(http://www.spinics.net/lists/kvm/msg94159.html which is however missing a 32-bit version). Making the exceptions do a longjmp would be a much safer option.
Paolo
Quoted 13 lines · Paolo Bonzini
Quoted 11 lines · David Matlack
set_exception_returnforces exceptions handlers to return to a specific address instead of returning to the instruction address pushed by the CPU at the time of the exception. The unit testsapic.candvmx.cuse this functionality to recover from expected exceptions.When using
set_exception_returnwe have to be careful not to modify the stack (such as by doing a function call) as triggering the exception will likely jump us past the instructions which undo the stack manipulation (such as a ret). To accomplish this, declare all functions called afterset_exception_returnas__always_inline, so that the compiler always inlines them.
Quoted 2 lines
set_exception_returnis generally not a great idea IMHO---thanks for looking at it.
Yup. This is a band-aid just to fix the current implementation.
Quoted 5 lines
A couple years ago we discussed adding setjmp/longjmp to libcflat
(http://www.spinics.net/lists/kvm/msg94159.html which is however missing a 32-bit version). Making the exceptions do a longjmp would be a much safer option.
Good idea! I might give this a try, but don't hold your breath :)
Quoted 2 lines
Paolo