diff mbox

[kvm-unit-tests,v2] x86: Test task-switch with cs.rpl != cs.dpl

Message ID 1408453449-4243-1-git-send-email-namit@cs.technion.ac.il (mailing list archive)
State New, archived
Headers show

Commit Message

Nadav Amit Aug. 19, 2014, 1:04 p.m. UTC
Commit 5045b46803 added a check that cs.dpl equals cs.rpl during task-switch.
This is a wrong check, and this patch introduces a test in which cs.dpl !=
cs.rpl. To do so, it configures tss.cs to be conforming with rpl=3 and dpl=0.
Since the cpl after calling is 3, it does not make any prints in the callee.

Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
---
 x86/taskswitch2.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Comments

Paolo Bonzini Aug. 19, 2014, 1:28 p.m. UTC | #1
Il 19/08/2014 15:04, Nadav Amit ha scritto:
> Commit 5045b46803 added a check that cs.dpl equals cs.rpl during task-switch.
> This is a wrong check, and this patch introduces a test in which cs.dpl !=
> cs.rpl. To do so, it configures tss.cs to be conforming with rpl=3 and dpl=0.
> Since the cpl after calling is 3, it does not make any prints in the callee.
> 
> Signed-off-by: Nadav Amit <namit@cs.technion.ac.il>
> ---
>  x86/taskswitch2.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/x86/taskswitch2.c b/x86/taskswitch2.c
> index 92fc941..1fe833e 100644
> --- a/x86/taskswitch2.c
> +++ b/x86/taskswitch2.c
> @@ -7,6 +7,7 @@
>  
>  #define MAIN_TSS_SEL (FIRST_SPARE_SEL + 0)
>  #define VM86_TSS_SEL (FIRST_SPARE_SEL + 8)
> +#define CONFORM_CS_SEL  (FIRST_SPARE_SEL + 16)
>  
>  static volatile int test_count;
>  static volatile unsigned int test_divider;
> @@ -102,6 +103,14 @@ start:
>  	goto start;
>  }
>  
> +static void user_tss(void)
> +{
> +start:
> +	test_count++;
> +	asm volatile ("iret");
> +	goto start;
> +}
> +
>  void test_kernel_mode_int()
>  {
>  	unsigned int res;
> @@ -248,6 +257,19 @@ void test_vm86_switch(void)
>      report("VM86", 1);
>  }
>  
> +void test_conforming_switch(void)
> +{
> +	/* test lcall with conforming segment, cs.dpl != cs.rpl */
> +	test_count = 0;
> +	set_intr_task_gate(0, user_tss);

No need to use set_intr_task_gate, since the IDT is not involved here.

        tss_intr.eip = (u32)user_tss;

is enough.

I fixed this up and applied the patch.  Thanks!

Paolo

> +
> +	tss_intr.cs = CONFORM_CS_SEL | 3;
> +	tss_intr.ds = tss_intr.gs = tss_intr.fs = tss_intr.ss = USER_DS;
> +	set_gdt_entry(CONFORM_CS_SEL, 0, 0xffffffff, 0x9f, 0xc0);
> +	asm volatile("lcall $" xstr(TSS_INTR) ", $0xf4f4f4f4");
> +	report("lcall with cs.rpl != cs.dpl", test_count == 1);
> +}
> +
>  int main()
>  {
>  	setup_vm();
> @@ -256,6 +278,7 @@ int main()
>  
>  	test_kernel_mode_int();
>  	test_vm86_switch();
> +	test_conforming_switch();
>  
>  	return report_summary();
>  }
> 

--
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
Nadav Amit Aug. 19, 2014, 1:34 p.m. UTC | #2
On Aug 19, 2014, at 4:28 PM, Paolo Bonzini <pbonzini@redhat.com> wrote:

> Il 19/08/2014 15:04, Nadav Amit ha scritto:
>> 
>> +void test_conforming_switch(void)
>> +{
>> +	/* test lcall with conforming segment, cs.dpl != cs.rpl */
>> +	test_count = 0;
>> +	set_intr_task_gate(0, user_tss);
> 
> No need to use set_intr_task_gate, since the IDT is not involved here.
> 
>        tss_intr.eip = (u32)user_tss;
> 
> is enough.
> 
> I fixed this up and applied the patch.  Thanks!

I know, but all the other ‘call' tests did. If there is an error, at least it should be consistent. ;-)

Thanks,
Nadav
diff mbox

Patch

diff --git a/x86/taskswitch2.c b/x86/taskswitch2.c
index 92fc941..1fe833e 100644
--- a/x86/taskswitch2.c
+++ b/x86/taskswitch2.c
@@ -7,6 +7,7 @@ 
 
 #define MAIN_TSS_SEL (FIRST_SPARE_SEL + 0)
 #define VM86_TSS_SEL (FIRST_SPARE_SEL + 8)
+#define CONFORM_CS_SEL  (FIRST_SPARE_SEL + 16)
 
 static volatile int test_count;
 static volatile unsigned int test_divider;
@@ -102,6 +103,14 @@  start:
 	goto start;
 }
 
+static void user_tss(void)
+{
+start:
+	test_count++;
+	asm volatile ("iret");
+	goto start;
+}
+
 void test_kernel_mode_int()
 {
 	unsigned int res;
@@ -248,6 +257,19 @@  void test_vm86_switch(void)
     report("VM86", 1);
 }
 
+void test_conforming_switch(void)
+{
+	/* test lcall with conforming segment, cs.dpl != cs.rpl */
+	test_count = 0;
+	set_intr_task_gate(0, user_tss);
+
+	tss_intr.cs = CONFORM_CS_SEL | 3;
+	tss_intr.ds = tss_intr.gs = tss_intr.fs = tss_intr.ss = USER_DS;
+	set_gdt_entry(CONFORM_CS_SEL, 0, 0xffffffff, 0x9f, 0xc0);
+	asm volatile("lcall $" xstr(TSS_INTR) ", $0xf4f4f4f4");
+	report("lcall with cs.rpl != cs.dpl", test_count == 1);
+}
+
 int main()
 {
 	setup_vm();
@@ -256,6 +278,7 @@  int main()
 
 	test_kernel_mode_int();
 	test_vm86_switch();
+	test_conforming_switch();
 
 	return report_summary();
 }