From: Andrew Jones <drjones@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, dmatlack@google.com
Subject: Re: [PATCH kvm-unit-tests 2/4] x86: replace set_exception_return with longjmp-based implementation
Date: Tue, 15 Dec 2015 12:09:48 -0600 [thread overview]
Message-ID: <20151215180948.GJ5373@hawk.localdomain> (raw)
In-Reply-To: <1450175138-1140-3-git-send-email-pbonzini@redhat.com>
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@google.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> 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
next prev parent reply other threads:[~2015-12-15 18:09 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-15 10:25 [PATCH kvm-unit-tests 0/3] use setjmp/longjmp to catch exceptions Paolo Bonzini
2015-12-15 10:25 ` [PATCH kvm-unit-tests 1/4] lib: add setjmp header and x86 implementation Paolo Bonzini
2015-12-15 16:43 ` Andrew Jones
2015-12-15 16:53 ` Paolo Bonzini
2015-12-15 10:25 ` [PATCH kvm-unit-tests 2/4] x86: replace set_exception_return with longjmp-based implementation Paolo Bonzini
2015-12-15 18:09 ` Andrew Jones [this message]
2015-12-15 10:25 ` [PATCH kvm-unit-tests 3/4] x86: remove test_for_exception Paolo Bonzini
2015-12-15 16:57 ` Andrew Jones
2015-12-15 18:32 ` David Matlack
2016-01-12 12:42 ` Paolo Bonzini
2016-01-12 17:17 ` David Matlack
2015-12-15 10:25 ` [PATCH kvm-unit-tests 4/4] x86: apic: cleanup Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151215180948.GJ5373@hawk.localdomain \
--to=drjones@redhat.com \
--cc=dmatlack@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox