Skip to contentSkip to conversation

Task stack pointer should point to the end of the page.

PATCH Applied Gleb Natapov 3 participants 8 messages Jan 11, 2011 – Jan 19, 2011 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Task stack pointer should point to the end of the page.

---
 lib/x86/desc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/x86/desc.c +1 -1
index 1bd4421..11bd2a2 100644
@@ -362,7 +362,7 @@ void setup_tss32(void)
 		tss[i].cr3 = read_cr3();
 		tss[i].ss0 = tss[i].ss1 = tss[i].ss2 = 0x10;
 		tss[i].esp = tss[i].esp0 = tss[i].esp1 = tss[i].esp2 =
-			(u32)tss_stack[i];
+			(u32)tss_stack[i] + 4096;
 		tss[i].cs = 0x08;
 		tss[i].ds = tss[i].es = tss[i].fs = tss[i].gs = tss[i].ss = 0x10;
 		tss[i].iomap_base = (u16)desc_size;
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 2/3 Test that error code is pushed on exception's task stack.

If exception with error code is handled by task gate, error code should be pushed to new task stack.

---
 x86/taskswitch2.c |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
x86/taskswitch2.c +39 -0
index f51cb91..683834e 100644
@@ -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);
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 3/3 Test that vcpu does not continue to run after issuing S3.

In reply to Gleb Natapov
---
 config-x86-common.mak |    5 +-
 x86/s3.c              |  167 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 171 insertions(+), 1 deletions(-)
 create mode 100644 x86/s3.c
config-x86-common.mak +4 -1
index cca8f87..033bae0 100644
@@ -33,7 +33,8 @@ tests-common = $(TEST_DIR)/vmexit.flat $(TEST_DIR)/tsc.flat \
                $(TEST_DIR)/smptest.flat  $(TEST_DIR)/port80.flat \
                $(TEST_DIR)/realmode.flat $(TEST_DIR)/msr.flat \
                $(TEST_DIR)/hypercall.flat $(TEST_DIR)/sieve.flat \
-               $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat
+               $(TEST_DIR)/kvmclock_test.flat  $(TEST_DIR)/eventinj.flat \
+               $(TEST_DIR)/s3.flat
 
 tests-common += api/api-sample
 tests-common += api/dirty-log
@@ -82,6 +83,8 @@ $(TEST_DIR)/kvmclock_test.elf: $(cstart.o) $(TEST_DIR)/kvmclock.o \
 
 $(TEST_DIR)/eventinj.elf: $(cstart.o) $(TEST_DIR)/eventinj.o
 
+$(TEST_DIR)/s3.elf: $(cstart.o) $(TEST_DIR)/s3.o
+
 arch_clean:
 	$(RM) $(TEST_DIR)/*.o $(TEST_DIR)/*.flat $(TEST_DIR)/*.elf \
 	$(TEST_DIR)/.*.d $(TEST_DIR)/lib/.*.d $(TEST_DIR)/lib/*.o
x86/s3.c new file +167 -0

167 lines not on this page · raw message

Signature · 1 line
1.7.2.3
#3 lore raw

Re: [PATCH unit-tests 3/3] Test that vcpu does not continue to run after issuing S3.

Quoted 8 lines · Gleb Natapov
x86/s3.c new file +8 -0
+
+asm (
+        ".global resume_start\n"
+	".global resume_end\n"
+	".code16\n"
+	"resume_start:\n"
+	"mov 0x0, %eax\n"
+	"mov $0xf4, %dx\n"

x86/s3.c line 167

Quoted 10 lines
x86/s3.c new file +10 -0
+	"out %eax, %dx\n"
+	"1: hlt\n"
+	"jmp 1b\n"
+	"resume_end:\n"
+#ifdef __i386__
+	".code32\n"
+#else
+	".code64\n"
+#endif
+    );

Is this a kvm unit test or a qemu unit test?

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw

Re: [PATCH unit-tests 3/3] Test that vcpu does not continue to run after issuing S3.

Quoted 13 lines · Avi Kivity
Quoted 12 lines · Gleb Natapov
x86/s3.c new file +12 -0
+
+asm (
+        ".global resume_start\n"
+	".global resume_end\n"
+	".code16\n"
+	"resume_start:\n"
+	"mov 0x0, %eax\n"
+	"mov $0xf4, %dx\n"
+	"out %eax, %dx\n"
+	"1: hlt\n"
+	"jmp 1b\n"
+	"resume_end:\n"
Quoted 9 lines

x86/s3.c line 167

Quoted 6 lines
x86/s3.c new file +6 -0
+#ifdef __i386__
+	".code32\n"
+#else
+	".code64\n"
+#endif
+    );

Is this a kvm unit test or a qemu unit test?

Both? Is this a bad thing?

--
Gleb.

#5 lore raw

Re: [PATCH unit-tests 3/3] Test that vcpu does not continue to run after issuing S3.

Quoted 21 lines · Gleb Natapov
Quoted 20 lines · Avi Kivity
Quoted 18 lines · Gleb Natapov
x86/s3.c new file +18 -0
+
+asm (
+        ".global resume_start\n"
+	".global resume_end\n"
+	".code16\n"
+	"resume_start:\n"
+	"mov 0x0, %eax\n"
+	"mov $0xf4, %dx\n"
+	"out %eax, %dx\n"
+	"1: hlt\n"
+	"jmp 1b\n"
+	"resume_end:\n"
+#ifdef __i386__
+	".code32\n"
+#else
+	".code64\n"
+#endif
+    );
Quoted 3 lines
Quoted 2 lines

Is this a kvm unit test or a qemu unit test?

Both? Is this a bad thing?

We may want to move non-kvm tests to qemu.git. Though all of the non-api tests work equally for qemu and kvm.

Signature · 1 line
error compiling committee.c: too many arguments to function
#6 lore raw

Re: [PATCH unit-tests 3/3] Test that vcpu does not continue to run after issuing S3.

Quoted 22 lines · Avi Kivity
Quoted 21 lines · Gleb Natapov
Quoted 20 lines · Avi Kivity
Quoted 18 lines · Gleb Natapov
x86/s3.c new file +18 -0
+
+asm (
+        ".global resume_start\n"
+	".global resume_end\n"
+	".code16\n"
+	"resume_start:\n"
+	"mov 0x0, %eax\n"
+	"mov $0xf4, %dx\n"
+	"out %eax, %dx\n"
+	"1: hlt\n"
+	"jmp 1b\n"
+	"resume_end:\n"
+#ifdef __i386__
+	".code32\n"
+#else
+	".code64\n"
+#endif
+    );
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Is this a kvm unit test or a qemu unit test?

Both? Is this a bad thing?

We may want to move non-kvm tests to qemu.git. Though all of the non-api tests work equally for qemu and kvm.

We will have to maintain two separate unit test infrastructures then. We can make x86/qemu or x86/device-model subdir in kvm-unit-test.

--
Gleb.

#7 lore raw
In reply to Gleb Natapov
Quoted 21 lines · Gleb Natapov
---
 lib/x86/desc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/x86/desc.c +1 -1
index 1bd4421..11bd2a2 100644
@@ -362,7 +362,7 @@ void setup_tss32(void)
 		tss[i].cr3 = read_cr3();
 		tss[i].ss0 = tss[i].ss1 = tss[i].ss2 = 0x10;
 		tss[i].esp = tss[i].esp0 = tss[i].esp1 = tss[i].esp2 =
-			(u32)tss_stack[i];
+			(u32)tss_stack[i] + 4096;
 		tss[i].cs = 0x08;
 		tss[i].ds = tss[i].es = tss[i].fs = tss[i].gs = tss[i].ss = 0x10;
 		tss[i].iomap_base = (u16)desc_size;
Signature · 1 line
1.7.2.3

Applied, thanks.