Re: [PATCH kvm-unit-tests 2/4] x86: replace set_exception_return with longjmp-based implementation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Dec 15, 2015 at 11:25:36AM +0100, Paolo Bonzini wrote:
> 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 one would 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).  This is unnecessarily brittle, and C already has a
> mechanism to do non-local returns---setjmp.  Now that libcflat includes
> an implementation of setjmp, replace set_exception_return with a wrapper
> that takes care of restoring the processor flags as well.
> 
> Reported-by: David Matlack <dmatlack@xxxxxxxxxx>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---
>  lib/x86/desc.c | 15 +++++++++++----
>  lib/x86/desc.h |  6 +++++-
>  x86/apic.c     |  8 ++++----
>  x86/vmx.c      | 18 +++++++++---------
>  4 files changed, 29 insertions(+), 18 deletions(-)
> 
> diff --git a/lib/x86/desc.c b/lib/x86/desc.c
> index 4760026..acf29e3 100644
> --- a/lib/x86/desc.c
> +++ b/lib/x86/desc.c
> @@ -1,6 +1,7 @@
>  #include "libcflat.h"
>  #include "desc.h"
>  #include "processor.h"
> +#include <setjmp.h>
>  
>  void set_idt_entry(int vec, void *addr, int dpl)
>  {
> @@ -315,12 +316,18 @@ void setup_alt_stack(void)
>  #endif
>  
>  static bool exception;
> -static void *exception_return;
> +static jmp_buf *exception_jmpbuf;

While changing this, how about making it per_cpu?
i.e. exception_jmpbuf[NR_CPUS]

drew
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux