From: Gleb Natapov <gleb@redhat.com>
To: avi@redhat.com, mtosatti@redhat.com
Cc: kvm@vger.kernel.org
Subject: [PATCH unit-tests 2/3] Test that error code is pushed on exception's task stack.
Date: Tue, 11 Jan 2011 15:30:06 +0200 [thread overview]
Message-ID: <1294752607-7920-2-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1294752607-7920-1-git-send-email-gleb@redhat.com>
If exception with error code is handled by task gate, error code should
be pushed to new task stack.
Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
x86/taskswitch2.c | 39 +++++++++++++++++++++++++++++++++++++++
1 files changed, 39 insertions(+), 0 deletions(-)
diff --git a/x86/taskswitch2.c b/x86/taskswitch2.c
index f51cb91..683834e 100644
--- a/x86/taskswitch2.c
+++ b/x86/taskswitch2.c
@@ -3,6 +3,7 @@
#include "apic-defs.h"
#include "apic.h"
#include "processor.h"
+#include "vm.h"
#define xstr(s) str(s)
#define str(s) #s
@@ -10,6 +11,9 @@
static volatile int test_count;
static volatile unsigned int test_divider;
+static char *fault_addr;
+static ulong fault_phys;
+
static int g_fail;
static int g_tests;
@@ -66,6 +70,27 @@ start:
goto start;
}
+void do_pf_tss(ulong *error_code)
+{
+ printf("PF task is running %x %x\n", error_code, *(ulong*)error_code);
+ print_current_tss_info();
+ if (*(ulong*)error_code == 0x2) /* write access, not present */
+ test_count++;
+ install_pte(phys_to_virt(read_cr3()), 1, fault_addr,
+ fault_phys | PTE_PRESENT | PTE_WRITE, 0);
+}
+
+extern void pf_tss(void);
+
+asm (
+ "pf_tss: \n\t"
+ "push %esp \n\t"
+ "call do_pf_tss \n\t"
+ "add $4, %esp \n\t"
+ "iret\n\t"
+ "jmp pf_tss\n\t"
+ );
+
static void jmp_tss(void)
{
start:
@@ -92,6 +117,7 @@ int main()
{
unsigned int res;
+ setup_vm();
setup_idt();
setup_gdt();
setup_tss32();
@@ -156,6 +182,19 @@ int main()
printf("Return from int 3\n");
report("BP exeption", test_count == 1);
+ /*
+ * test that PF triggers task gate and error code is placed on
+ * exception task's stack
+ */
+ fault_addr = alloc_vpage();
+ fault_phys = (ulong)virt_to_phys(alloc_page());
+ test_count = 0;
+ set_intr_task_gate(14, pf_tss);
+ printf("Access unmapped page\n");
+ *fault_addr = 0;
+ printf("Return from pf tss\n");
+ report("PF exeption", test_count == 1);
+
/* test that calling a task by lcall works */
test_count = 0;
set_intr_task_gate(0, irq_tss);
--
1.7.2.3
next prev parent reply other threads:[~2011-01-11 13:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-11 13:30 [PATCH unit-tests 1/3] Task stack pointer should point to the end of the page Gleb Natapov
2011-01-11 13:30 ` Gleb Natapov [this message]
2011-01-11 13:30 ` [PATCH unit-tests 3/3] Test that vcpu does not continue to run after issuing S3 Gleb Natapov
2011-01-11 13:53 ` Avi Kivity
2011-01-11 13:54 ` Gleb Natapov
2011-01-11 14:08 ` Avi Kivity
2011-01-11 14:17 ` Gleb Natapov
2011-01-19 16:37 ` [PATCH unit-tests 1/3] Task stack pointer should point to the end of the page Marcelo Tosatti
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=1294752607-7920-2-git-send-email-gleb@redhat.com \
--to=gleb@redhat.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@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