* [PATCH kvm-unit-tests] Test fault during IRET from NMI.
@ 2013-09-15 8:17 Gleb Natapov
2013-09-15 9:54 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Gleb Natapov @ 2013-09-15 8:17 UTC (permalink / raw)
To: kvm; +Cc: pbonzini
This test checks that NMI window opens only after IRET from NMI is
executed without a fault.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index e46d8d0..de1dc47 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -62,6 +62,13 @@ static inline u16 read_gs(void)
return val;
}
+static inline unsigned long read_rflags(void)
+{
+ unsigned long f;
+ asm ("pushf; pop %0\n\t" : "=rm"(f));
+ return f;
+}
+
static inline void write_ds(unsigned val)
{
asm ("mov %0, %%ds" : : "rm"(val) : "memory");
diff --git a/x86/eventinj.c b/x86/eventinj.c
index 7bed7c5..c171e30 100644
--- a/x86/eventinj.c
+++ b/x86/eventinj.c
@@ -125,6 +125,42 @@ static void nmi_isr(struct ex_regs *r)
printf("After nested NMI to itself\n");
}
+unsigned long after_iret_addr;
+
+static void nested_nmi_iret_isr(struct ex_regs *r)
+{
+ printf("Nested NMI isr running rip=%x\n", r->rip);
+
+ if (r->rip == after_iret_addr)
+ test_count++;
+}
+static void nmi_iret_isr(struct ex_regs *r)
+{
+ unsigned long *s = alloc_page();
+ test_count++;
+ printf("NMI isr running %p stack %p\n", &&after_iret, s);
+ handle_exception(2, nested_nmi_iret_isr);
+ printf("Try send nested NMI to itself\n");
+ apic_self_nmi();
+ printf("After nested NMI to itself\n");
+ s[4] = read_ss();
+ s[3] = 0; /* rsp */
+ s[2] = read_rflags();
+ s[1] = read_cs();
+ s[0] = after_iret_addr = (unsigned long)&&after_iret;
+ asm ("mov %%rsp, %0\n\t"
+ "mov %1, %%rsp\n\t"
+ "outl %2, $0xe4\n\t" /* flush stack page */
+#ifdef __x86_64__
+ "iretq\n\t"
+#else
+ "iretl\n\t"
+#endif
+ : "=m"(s[3]) : "rm"(&s[0]), "a"((unsigned int)virt_to_phys(s)) : "memory");
+after_iret:
+ printf("After iret\n");
+}
+
static void tirq0(isr_regs_t *r)
{
printf("irq0 running\n");
@@ -300,6 +336,20 @@ int main()
irq_disable();
report("NMI", test_count == 2);
+ /* generate NMI that will fault on IRET */
+ printf("Before NMI IRET test\n");
+ test_count = 0;
+ handle_exception(2, nmi_iret_isr);
+ printf("Try send NMI to itself\n");
+ apic_self_nmi();
+ /* this is needed on VMX without NMI window notificatoin.
+ Interrupt windows is used instead, so let pending NMI
+ to be injected */
+ irq_enable();
+ asm volatile ("nop");
+ irq_disable();
+ printf("After NMI to itself\n");
+ report("NMI", test_count == 2);
#ifndef __x86_64__
stack_phys = (ulong)virt_to_phys(alloc_page());
stack_va = alloc_vpage();
--
Gleb.
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH kvm-unit-tests] Test fault during IRET from NMI.
2013-09-15 8:17 [PATCH kvm-unit-tests] Test fault during IRET from NMI Gleb Natapov
@ 2013-09-15 9:54 ` Paolo Bonzini
2013-09-15 9:56 ` Gleb Natapov
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2013-09-15 9:54 UTC (permalink / raw)
To: Gleb Natapov; +Cc: kvm
Il 15/09/2013 10:17, Gleb Natapov ha scritto:
> This test checks that NMI window opens only after IRET from NMI is
> executed without a fault.
>
> Signed-off-by: Gleb Natapov <gleb@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
... with a couple English nits (see inline).
> diff --git a/lib/x86/processor.h b/lib/x86/processor.h
> index e46d8d0..de1dc47 100644
> --- a/lib/x86/processor.h
> +++ b/lib/x86/processor.h
> @@ -62,6 +62,13 @@ static inline u16 read_gs(void)
> return val;
> }
>
> +static inline unsigned long read_rflags(void)
> +{
> + unsigned long f;
> + asm ("pushf; pop %0\n\t" : "=rm"(f));
> + return f;
> +}
> +
> static inline void write_ds(unsigned val)
> {
> asm ("mov %0, %%ds" : : "rm"(val) : "memory");
> diff --git a/x86/eventinj.c b/x86/eventinj.c
> index 7bed7c5..c171e30 100644
> --- a/x86/eventinj.c
> +++ b/x86/eventinj.c
> @@ -125,6 +125,42 @@ static void nmi_isr(struct ex_regs *r)
> printf("After nested NMI to itself\n");
> }
>
> +unsigned long after_iret_addr;
> +
> +static void nested_nmi_iret_isr(struct ex_regs *r)
> +{
> + printf("Nested NMI isr running rip=%x\n", r->rip);
> +
> + if (r->rip == after_iret_addr)
> + test_count++;
> +}
> +static void nmi_iret_isr(struct ex_regs *r)
> +{
> + unsigned long *s = alloc_page();
> + test_count++;
> + printf("NMI isr running %p stack %p\n", &&after_iret, s);
> + handle_exception(2, nested_nmi_iret_isr);
> + printf("Try send nested NMI to itself\n");
s/Try send/Sending/
> + apic_self_nmi();
> + printf("After nested NMI to itself\n");
> + s[4] = read_ss();
> + s[3] = 0; /* rsp */
> + s[2] = read_rflags();
> + s[1] = read_cs();
> + s[0] = after_iret_addr = (unsigned long)&&after_iret;
> + asm ("mov %%rsp, %0\n\t"
> + "mov %1, %%rsp\n\t"
> + "outl %2, $0xe4\n\t" /* flush stack page */
> +#ifdef __x86_64__
> + "iretq\n\t"
> +#else
> + "iretl\n\t"
> +#endif
> + : "=m"(s[3]) : "rm"(&s[0]), "a"((unsigned int)virt_to_phys(s)) : "memory");
> +after_iret:
> + printf("After iret\n");
> +}
> +
> static void tirq0(isr_regs_t *r)
> {
> printf("irq0 running\n");
> @@ -300,6 +336,20 @@ int main()
> irq_disable();
> report("NMI", test_count == 2);
>
> + /* generate NMI that will fault on IRET */
> + printf("Before NMI IRET test\n");
> + test_count = 0;
> + handle_exception(2, nmi_iret_isr);
> + printf("Try send NMI to itself\n");
s/Try send/Sending/
> + apic_self_nmi();
> + /* this is needed on VMX without NMI window notificatoin.
s/notifiatoin/notification/
> + Interrupt windows is used instead, so let pending NMI
> + to be injected */
> + irq_enable();
> + asm volatile ("nop");
> + irq_disable();
> + printf("After NMI to itself\n");
> + report("NMI", test_count == 2);
> #ifndef __x86_64__
> stack_phys = (ulong)virt_to_phys(alloc_page());
> stack_va = alloc_vpage();
> --
> Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH kvm-unit-tests] Test fault during IRET from NMI.
2013-09-15 9:54 ` Paolo Bonzini
@ 2013-09-15 9:56 ` Gleb Natapov
2013-09-16 9:30 ` Paolo Bonzini
0 siblings, 1 reply; 5+ messages in thread
From: Gleb Natapov @ 2013-09-15 9:56 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
On Sun, Sep 15, 2013 at 11:54:15AM +0200, Paolo Bonzini wrote:
> Il 15/09/2013 10:17, Gleb Natapov ha scritto:
> > This test checks that NMI window opens only after IRET from NMI is
> > executed without a fault.
> >
> > Signed-off-by: Gleb Natapov <gleb@redhat.com>
>
> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>
> ... with a couple English nits (see inline).
>
Yeah, those are copy/paste from other places. The file is full of it :)
> > diff --git a/lib/x86/processor.h b/lib/x86/processor.h
> > index e46d8d0..de1dc47 100644
> > --- a/lib/x86/processor.h
> > +++ b/lib/x86/processor.h
> > @@ -62,6 +62,13 @@ static inline u16 read_gs(void)
> > return val;
> > }
> >
> > +static inline unsigned long read_rflags(void)
> > +{
> > + unsigned long f;
> > + asm ("pushf; pop %0\n\t" : "=rm"(f));
> > + return f;
> > +}
> > +
> > static inline void write_ds(unsigned val)
> > {
> > asm ("mov %0, %%ds" : : "rm"(val) : "memory");
> > diff --git a/x86/eventinj.c b/x86/eventinj.c
> > index 7bed7c5..c171e30 100644
> > --- a/x86/eventinj.c
> > +++ b/x86/eventinj.c
> > @@ -125,6 +125,42 @@ static void nmi_isr(struct ex_regs *r)
> > printf("After nested NMI to itself\n");
> > }
> >
> > +unsigned long after_iret_addr;
> > +
> > +static void nested_nmi_iret_isr(struct ex_regs *r)
> > +{
> > + printf("Nested NMI isr running rip=%x\n", r->rip);
> > +
> > + if (r->rip == after_iret_addr)
> > + test_count++;
> > +}
> > +static void nmi_iret_isr(struct ex_regs *r)
> > +{
> > + unsigned long *s = alloc_page();
> > + test_count++;
> > + printf("NMI isr running %p stack %p\n", &&after_iret, s);
> > + handle_exception(2, nested_nmi_iret_isr);
> > + printf("Try send nested NMI to itself\n");
>
> s/Try send/Sending/
>
> > + apic_self_nmi();
> > + printf("After nested NMI to itself\n");
> > + s[4] = read_ss();
> > + s[3] = 0; /* rsp */
> > + s[2] = read_rflags();
> > + s[1] = read_cs();
> > + s[0] = after_iret_addr = (unsigned long)&&after_iret;
> > + asm ("mov %%rsp, %0\n\t"
> > + "mov %1, %%rsp\n\t"
> > + "outl %2, $0xe4\n\t" /* flush stack page */
> > +#ifdef __x86_64__
> > + "iretq\n\t"
> > +#else
> > + "iretl\n\t"
> > +#endif
> > + : "=m"(s[3]) : "rm"(&s[0]), "a"((unsigned int)virt_to_phys(s)) : "memory");
> > +after_iret:
> > + printf("After iret\n");
> > +}
> > +
> > static void tirq0(isr_regs_t *r)
> > {
> > printf("irq0 running\n");
> > @@ -300,6 +336,20 @@ int main()
> > irq_disable();
> > report("NMI", test_count == 2);
> >
> > + /* generate NMI that will fault on IRET */
> > + printf("Before NMI IRET test\n");
> > + test_count = 0;
> > + handle_exception(2, nmi_iret_isr);
> > + printf("Try send NMI to itself\n");
>
> s/Try send/Sending/
>
> > + apic_self_nmi();
> > + /* this is needed on VMX without NMI window notificatoin.
>
> s/notifiatoin/notification/
>
> > + Interrupt windows is used instead, so let pending NMI
> > + to be injected */
> > + irq_enable();
> > + asm volatile ("nop");
> > + irq_disable();
> > + printf("After NMI to itself\n");
> > + report("NMI", test_count == 2);
> > #ifndef __x86_64__
> > stack_phys = (ulong)virt_to_phys(alloc_page());
> > stack_va = alloc_vpage();
> > --
> > Gleb.
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> >
--
Gleb.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH kvm-unit-tests] Test fault during IRET from NMI.
2013-09-15 9:56 ` Gleb Natapov
@ 2013-09-16 9:30 ` Paolo Bonzini
2013-09-16 10:40 ` Gleb Natapov
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2013-09-16 9:30 UTC (permalink / raw)
To: Gleb Natapov; +Cc: kvm
Il 15/09/2013 11:56, Gleb Natapov ha scritto:
> On Sun, Sep 15, 2013 at 11:54:15AM +0200, Paolo Bonzini wrote:
>> Il 15/09/2013 10:17, Gleb Natapov ha scritto:
>>> This test checks that NMI window opens only after IRET from NMI is
>>> executed without a fault.
>>>
>>> Signed-off-by: Gleb Natapov <gleb@redhat.com>
>>
>> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
>>
>> ... with a couple English nits (see inline).
>>
> Yeah, those are copy/paste from other places. The file is full of it :)
Can you fix all of them? :)
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH kvm-unit-tests] Test fault during IRET from NMI.
2013-09-16 9:30 ` Paolo Bonzini
@ 2013-09-16 10:40 ` Gleb Natapov
0 siblings, 0 replies; 5+ messages in thread
From: Gleb Natapov @ 2013-09-16 10:40 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: kvm
On Mon, Sep 16, 2013 at 11:30:58AM +0200, Paolo Bonzini wrote:
> Il 15/09/2013 11:56, Gleb Natapov ha scritto:
> > On Sun, Sep 15, 2013 at 11:54:15AM +0200, Paolo Bonzini wrote:
> >> Il 15/09/2013 10:17, Gleb Natapov ha scritto:
> >>> This test checks that NMI window opens only after IRET from NMI is
> >>> executed without a fault.
> >>>
> >>> Signed-off-by: Gleb Natapov <gleb@redhat.com>
> >>
> >> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> >>
> >> ... with a couple English nits (see inline).
> >>
> > Yeah, those are copy/paste from other places. The file is full of it :)
>
> Can you fix all of them? :)
>
Sure, I will commit this one as is then and fix all places with a patch
on top.
--
Gleb.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-16 10:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-15 8:17 [PATCH kvm-unit-tests] Test fault during IRET from NMI Gleb Natapov
2013-09-15 9:54 ` Paolo Bonzini
2013-09-15 9:56 ` Gleb Natapov
2013-09-16 9:30 ` Paolo Bonzini
2013-09-16 10:40 ` Gleb Natapov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox