public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Nadav Amit <namit@cs.technion.ac.il>
Cc: gleb@kernel.org, tglx@linutronix.de, mingo@redhat.com,
	hpa@zytor.com, x86@kernel.org, linux-kernel@vger.kernel.org,
	nadav.amit@gmail.com
Subject: Re: [PATCH kvm-unit-tests] x86: Test rflags.rf is set upon faults
Date: Thu, 24 Jul 2014 14:09:55 +0200	[thread overview]
Message-ID: <53D0F793.5000207@redhat.com> (raw)
In-Reply-To: <1406202943-5427-1-git-send-email-namit@cs.technion.ac.il>

Il 24/07/2014 13:55, Nadav Amit ha scritto:
> This patch tests whether rflags.rf is set upon #UD and #GP faults as it should,
> according to Intel SDM 17.3.1.1.  The patch saves rflags.rf in an unused bit of
> the value which is saved during exception handling to save rflags.rf.
> 
> Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
> ---
>  lib/x86/desc.c | 16 ++++++++++++----
>  lib/x86/desc.h |  1 +
>  x86/idt_test.c | 13 +++++++++----
>  3 files changed, 22 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/x86/desc.c b/lib/x86/desc.c
> index 9a80f48..7fbe774 100644
> --- a/lib/x86/desc.c
> +++ b/lib/x86/desc.c
> @@ -36,8 +36,8 @@ static void check_exception_table(struct ex_regs *regs)
>      struct ex_record *ex;
>      unsigned ex_val;
>  
> -    ex_val = regs->vector | (regs->error_code << 16);
> -
> +    ex_val = regs->vector | (regs->error_code << 16) |
> +		(((regs->rflags >> 16) & 1) << 8);
>      asm("mov %0, %%gs:4" : : "r"(ex_val));
>  
>      for (ex = &exception_table_start; ex != &exception_table_end; ++ex) {
> @@ -173,9 +173,9 @@ void setup_idt(void)
>  
>  unsigned exception_vector(void)
>  {
> -    unsigned short vector;
> +    unsigned char vector;
>  
> -    asm("mov %%gs:4, %0" : "=rm"(vector));
> +    asm("movb %%gs:4, %0" : "=q"(vector));
>      return vector;
>  }
>  
> @@ -187,6 +187,14 @@ unsigned exception_error_code(void)
>      return error_code;
>  }
>  
> +bool exception_rflags_rf(void)
> +{
> +    unsigned char rf_flag;
> +
> +    asm("movb %%gs:5, %b0" : "=q"(rf_flag));
> +    return rf_flag & 1;
> +}
> +
>  static char intr_alt_stack[4096];
>  
>  #ifndef __x86_64__
> diff --git a/lib/x86/desc.h b/lib/x86/desc.h
> index 553bce9..bd4293e 100644
> --- a/lib/x86/desc.h
> +++ b/lib/x86/desc.h
> @@ -144,6 +144,7 @@ extern tss64_t tss;
>  
>  unsigned exception_vector(void);
>  unsigned exception_error_code(void);
> +bool exception_rflags_rf(void);
>  void set_idt_entry(int vec, void *addr, int dpl);
>  void set_idt_sel(int vec, u16 sel);
>  void set_gdt_entry(int sel, u32 base,  u32 limit, u8 access, u8 gran);
> diff --git a/x86/idt_test.c b/x86/idt_test.c
> index ecb76bb..349aade 100644
> --- a/x86/idt_test.c
> +++ b/x86/idt_test.c
> @@ -1,15 +1,16 @@
>  #include "libcflat.h"
>  #include "desc.h"
>  
> -int test_ud2(void)
> +int test_ud2(bool *rflags_rf)
>  {
>      asm volatile(ASM_TRY("1f")
>                   "ud2 \n\t"
>                   "1:" :);
> +    *rflags_rf = exception_rflags_rf();
>      return exception_vector();
>  }
>  
> -int test_gp(void)
> +int test_gp(bool *rflags_rf)
>  {
>      unsigned long tmp;
>  
> @@ -18,19 +19,23 @@ int test_gp(void)
>  		 "mov %0, %%cr4\n\t"
>                   "1:"
>                   : "=a"(tmp));
> +    *rflags_rf = exception_rflags_rf();
>      return exception_vector();
>  }
>  
>  int main(void)
>  {
>      int r;
> +    bool rflags_rf;
>  
>      printf("Starting IDT test\n");
>      setup_idt();
> -    r = test_gp();
> +    r = test_gp(&rflags_rf);
>      report("Testing #GP", r == GP_VECTOR);
> -    r = test_ud2();
> +    report("Testing #GP rflags.rf", rflags_rf);
> +    r = test_ud2(&rflags_rf);
>      report("Testing #UD", r == UD_VECTOR);
> +    report("Testing #UD rflags.rf", rflags_rf);
>  
>      return report_summary();
>  }
> 

Thanks, applying to kvm-unit-tests.

Paolo

  reply	other threads:[~2014-07-24 12:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-21 11:37 [PATCH 0/7] KVM: x86: Additional rflags.rf fixes Nadav Amit
2014-07-21 11:37 ` [PATCH 1/7] KVM: x86: Defining missing x86 vectors Nadav Amit
2014-07-21 11:37 ` [PATCH 2/7] KVM: x86: Function for determining exception type Nadav Amit
2014-07-21 12:18   ` Paolo Bonzini
2014-07-21 21:30     ` Nadav Amit
2014-07-22  8:08       ` Paolo Bonzini
2014-07-21 11:37 ` [PATCH 3/7] KVM: x86: Clearing rflags.rf upon skipped emulated instruction Nadav Amit
2014-07-21 11:37 ` [PATCH 4/7] KVM: vmx: set rflags.rf during fault injection Nadav Amit
2014-07-21 12:05   ` Paolo Bonzini
2014-07-21 11:37 ` [PATCH 5/7] KVM: x86: popf emulation should not change RF Nadav Amit
2014-07-21 11:37 ` [PATCH 6/7] KVM: x86: Clear rflags.rf on emulated instructions Nadav Amit
2014-07-21 11:37 ` [PATCH 7/7] KVM: x86: Cleanup of rflags.rf cleaning Nadav Amit
2014-07-21 11:39 ` [PATCH kvm-unit-tests 0/3] x86: Test rflags.rf clearing/setting Nadav Amit
2014-07-21 11:39   ` [PATCH kvm-unit-tests 1/3] x86: Check rflags.rf is cleared after emulation Nadav Amit
2014-07-21 11:39   ` [PATCH kvm-unit-tests 2/3] x86: Test rflags.rf is set upon faults Nadav Amit
2014-07-21 12:24     ` Paolo Bonzini
2014-07-21 11:39   ` [PATCH kvm-unit-tests 3/3] x86: Check RFLAGS.RF on interrupt during REP-str Nadav Amit
2014-07-21 12:25   ` [PATCH kvm-unit-tests 0/3] x86: Test rflags.rf clearing/setting Paolo Bonzini
2014-07-24 11:55     ` [PATCH kvm-unit-tests] x86: Test rflags.rf is set upon faults Nadav Amit
2014-07-24 12:09       ` Paolo Bonzini [this message]
2014-07-21 12:19 ` [PATCH 0/7] KVM: x86: Additional rflags.rf fixes Paolo Bonzini
2014-07-21 12:28   ` Nadav Amit
2014-07-21 12:31     ` Paolo Bonzini
2014-07-24 11:51       ` [PATCH 0/2] KVM: x86: Missing " Nadav Amit
2014-07-24 11:51         ` [PATCH 1/2] KVM: x86: Setting rflags.rf during rep-string emulation Nadav Amit
2014-07-24 11:51         ` [PATCH 2/2] KVM: x86: set rflags.rf during fault injection Nadav Amit

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=53D0F793.5000207@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=gleb@kernel.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=nadav.amit@gmail.com \
    --cc=namit@cs.technion.ac.il \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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