public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] test: Add emulator test for iret instruction
@ 2010-07-27 23:03 Mohammed Gamal
  0 siblings, 0 replies; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-27 23:03 UTC (permalink / raw)
  To: avi; +Cc: mtosatti, kvm, Mohammed Gamal

This adds a unit test for real mode emulation of the iret instruction

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
 kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
index bd79348..564116a 100644
--- a/kvm/test/x86/realmode.c
+++ b/kvm/test/x86/realmode.c
@@ -865,6 +865,28 @@ void test_pusha_popa()
 		print_serial("Pusha/Popa Test2: PASS\n");
 }
 
+void test_iret()
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(iret, "pushf\n\t"
+		      "pushl %cs\n\t"
+		      "call 1f\n\t" /* a near call will push eip onto the stack */
+		      "jmp 2f\n\t"
+		      "1:iret\n\t"
+		      "2:\n\t"
+		     );
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret,
+			      insn_iret_end - insn_iret);
+
+	if (!regs_equal(&inregs, &outregs, R_AX))
+		print_serial("iret Test 1: FAIL\n");
+	else
+		print_serial("iret Test 1: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -886,6 +908,7 @@ void realmode_start(void)
 	/* long jmp test uses call near so test it after testing call */
 	test_long_jmp();
 	test_xchg();
+	test_iret();
 
 	exit(0);
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH] test: Add emulator test for iret instruction
@ 2010-07-27 23:22 Mohammed Gamal
  2010-07-28  4:21 ` Avi Kivity
  0 siblings, 1 reply; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-27 23:22 UTC (permalink / raw)
  To: avi; +Cc: mtosatti, kvm, Mohammed Gamal

This adds a unit test for real mode emulation of the iret instruction

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
 kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
index bd79348..16716cc 100644
--- a/kvm/test/x86/realmode.c
+++ b/kvm/test/x86/realmode.c
@@ -865,6 +865,28 @@ void test_pusha_popa()
 		print_serial("Pusha/Popa Test2: PASS\n");
 }
 
+void test_iret()
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(iret, "pushf\n\t"
+		      "pushl %cs\n\t"
+		      "call 1f\n\t" /* a near call will push eip onto the stack */
+		      "jmp 2f\n\t"
+		      "1:iret\n\t"
+		      "2:\n\t"
+		     );
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret,
+			      insn_iret_end - insn_iret);
+
+	if (!regs_equal(&inregs, &outregs, 0))
+		print_serial("iret Test 1: FAIL\n");
+	else
+		print_serial("iret Test 1: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -886,6 +908,7 @@ void realmode_start(void)
 	/* long jmp test uses call near so test it after testing call */
 	test_long_jmp();
 	test_xchg();
+	test_iret();
 
 	exit(0);
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-27 23:22 Mohammed Gamal
@ 2010-07-28  4:21 ` Avi Kivity
  2010-07-28  4:28   ` Avi Kivity
  0 siblings, 1 reply; 13+ messages in thread
From: Avi Kivity @ 2010-07-28  4:21 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: mtosatti, kvm

  On 07/28/2010 02:22 AM, Mohammed Gamal wrote:
> This adds a unit test for real mode emulation of the iret instruction
>
> Signed-off-by: Mohammed Gamal<m.gamal005@gmail.com>
> ---
>   kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
>   1 files changed, 23 insertions(+), 0 deletions(-)
>
> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
> index bd79348..16716cc 100644
> --- a/kvm/test/x86/realmode.c
> +++ b/kvm/test/x86/realmode.c
> @@ -865,6 +865,28 @@ void test_pusha_popa()
>   		print_serial("Pusha/Popa Test2: PASS\n");
>   }
>
> +void test_iret()
> +{
> +	struct regs inregs = { 0 }, outregs;
> +
> +	MK_INSN(iret, "pushf\n\t"
> +		      "pushl %cs\n\t"
> +		      "call 1f\n\t" /* a near call will push eip onto the stack */
> +		      "jmp 2f\n\t"
> +		      "1:iret\n\t"
> +		      "2:\n\t"
> +		     );
> +
> +	exec_in_big_real_mode(&inregs,&outregs,
> +			      insn_iret,
> +			      insn_iret_end - insn_iret);
> +
> +	if (!regs_equal(&inregs,&outregs, 0))
> +		print_serial("iret Test 1: FAIL\n");
> +	else
> +		print_serial("iret Test 1: PASS\n");
> +}
> +

This tests 32-bit iret, please test 16-bit iret as well (pushfw, pushw 
cs, callw, iretw).

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28  4:21 ` Avi Kivity
@ 2010-07-28  4:28   ` Avi Kivity
  0 siblings, 0 replies; 13+ messages in thread
From: Avi Kivity @ 2010-07-28  4:28 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: mtosatti, kvm

  On 07/28/2010 07:21 AM, Avi Kivity wrote:
>  On 07/28/2010 02:22 AM, Mohammed Gamal wrote:
>> This adds a unit test for real mode emulation of the iret instruction
>>
>> Signed-off-by: Mohammed Gamal<m.gamal005@gmail.com>
>> ---
>>   kvm/test/x86/realmode.c |   23 +++++++++++++++++++++++
>>   1 files changed, 23 insertions(+), 0 deletions(-)
>>
>> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
>> index bd79348..16716cc 100644
>> --- a/kvm/test/x86/realmode.c
>> +++ b/kvm/test/x86/realmode.c
>> @@ -865,6 +865,28 @@ void test_pusha_popa()
>>           print_serial("Pusha/Popa Test2: PASS\n");
>>   }
>>
>> +void test_iret()
>> +{
>> +    struct regs inregs = { 0 }, outregs;
>> +
>> +    MK_INSN(iret, "pushf\n\t"
>> +              "pushl %cs\n\t"
>> +              "call 1f\n\t" /* a near call will push eip onto the 
>> stack */
>> +              "jmp 2f\n\t"
>> +              "1:iret\n\t"
>> +              "2:\n\t"
>> +             );
>> +
>> +    exec_in_big_real_mode(&inregs,&outregs,
>> +                  insn_iret,
>> +                  insn_iret_end - insn_iret);
>> +
>> +    if (!regs_equal(&inregs,&outregs, 0))
>> +        print_serial("iret Test 1: FAIL\n");
>> +    else
>> +        print_serial("iret Test 1: PASS\n");
>> +}
>> +
>
> This tests 32-bit iret, please test 16-bit iret as well (pushfw, pushw 
> cs, callw, iretw).
>

Also add tests that set bits that must be zero (and checks that IRET 
clears them in eflags) or clears bit 1 and sees that IRET sets it.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH] test: Add emulator test for iret instruction
@ 2010-07-28  9:39 Mohammed Gamal
  2010-07-28 19:55 ` Marcelo Tosatti
  2010-07-29 15:50 ` Marcelo Tosatti
  0 siblings, 2 replies; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-28  9:39 UTC (permalink / raw)
  To: avi; +Cc: mtosatti, kvm, Mohammed Gamal

This adds a unit test for real mode emulation of the iret instruction

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>

---
Changes from v1:
- Added test for 16-bit iret
- Added tests for returned eflags
---
 kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
index bd79348..74456c3 100644
--- a/kvm/test/x86/realmode.c
+++ b/kvm/test/x86/realmode.c
@@ -865,6 +865,84 @@ void test_pusha_popa()
 		print_serial("Pusha/Popa Test2: PASS\n");
 }
 
+void test_iret()
+{
+	struct regs inregs = { 0 }, outregs;
+
+	MK_INSN(iret32, "pushf\n\t"
+			"pushl %cs\n\t"
+			"call 1f\n\t" /* a near call will push eip onto the stack */
+			"jmp 2f\n\t"
+			"1: iret\n\t"
+			"2:\n\t"
+		     );
+
+	MK_INSN(iret16, "pushfw\n\t"
+			"pushw %cs\n\t"
+			"callw 1f\n\t"
+			"jmp 2f\n\t"
+			"1: iretw\n\t"
+			"2:\n\t");
+
+	MK_INSN(iret_flags32, "pushfl\n\t"
+			      "popl %eax\n\t"
+			      "andl $~0x2, %eax\n\t"
+			      "orl $0xffc08028, %eax\n\t"
+			      "pushl %eax\n\t"
+			      "pushl %cs\n\t"
+			      "call 1f\n\t"
+			      "jmp 2f\n\t"
+			      "1: iret\n\t"
+			      "2:\n\t");
+
+	MK_INSN(iret_flags16, "pushfw\n\t"
+			      "popw %ax\n\t"
+			      "and $~0x2, %ax\n\t"
+			      "or $0x8028, %ax\n\t" 
+			      "pushw %ax\n\t"
+			      "pushw %cs\n\t"
+			      "callw 1f\n\t"
+			      "jmp 2f\n\t"
+			      "1: iretw\n\t"
+			      "2:\n\t");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret32,
+			      insn_iret32_end - insn_iret32);
+
+	if (!regs_equal(&inregs, &outregs, 0))
+		print_serial("iret Test 1: FAIL\n");
+	else
+		print_serial("iret Test 1: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret16,
+			      insn_iret16_end - insn_iret16);
+
+	if (!regs_equal(&inregs, &outregs, 0))
+		print_serial("iret Test 2: FAIL\n");
+	else
+		print_serial("iret Test 2: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret_flags32,
+			      insn_iret_flags32_end - insn_iret_flags32);
+
+	if (!regs_equal(&inregs, &outregs, R_AX))
+		print_serial("iret Test 3: FAIL\n");
+	else
+		print_serial("iret Test 3: PASS\n");
+
+	exec_in_big_real_mode(&inregs, &outregs,
+			      insn_iret_flags16,
+			      insn_iret_flags16_end - insn_iret_flags16);
+
+	if (!regs_equal(&inregs, &outregs, R_AX))
+		print_serial("iret Test 4: FAIL\n");
+	else
+		print_serial("iret Test 4: PASS\n");
+}
+
 void realmode_start(void)
 {
 	test_null();
@@ -886,6 +964,7 @@ void realmode_start(void)
 	/* long jmp test uses call near so test it after testing call */
 	test_long_jmp();
 	test_xchg();
+	test_iret();
 
 	exit(0);
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28  9:39 [PATCH] test: Add emulator test for iret instruction Mohammed Gamal
@ 2010-07-28 19:55 ` Marcelo Tosatti
  2010-07-28 20:28   ` Mohammed Gamal
  2010-07-29 15:50 ` Marcelo Tosatti
  1 sibling, 1 reply; 13+ messages in thread
From: Marcelo Tosatti @ 2010-07-28 19:55 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: avi, kvm

On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
> This adds a unit test for real mode emulation of the iret instruction
> 
> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
> 
> ---
> Changes from v1:
> - Added test for 16-bit iret
> - Added tests for returned eflags
> ---
>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 79 insertions(+), 0 deletions(-)
> 
> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
> index bd79348..74456c3 100644
> --- a/kvm/test/x86/realmode.c
> +++ b/kvm/test/x86/realmode.c
> @@ -865,6 +865,84 @@ void test_pusha_popa()
>  		print_serial("Pusha/Popa Test2: PASS\n");
>  }
>  
> +void test_iret()
> +{
> +	struct regs inregs = { 0 }, outregs;
> +
> +	MK_INSN(iret32, "pushf\n\t"
> +			"pushl %cs\n\t"
> +			"call 1f\n\t" /* a near call will push eip onto the stack */
> +			"jmp 2f\n\t"
> +			"1: iret\n\t"
> +			"2:\n\t"
> +		     );
> +
> +	MK_INSN(iret16, "pushfw\n\t"
> +			"pushw %cs\n\t"
> +			"callw 1f\n\t"
> +			"jmp 2f\n\t"
> +			"1: iretw\n\t"
> +			"2:\n\t");

Unless iret causes a task switch, it will not cause an exit.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28 19:55 ` Marcelo Tosatti
@ 2010-07-28 20:28   ` Mohammed Gamal
  2010-07-28 20:32     ` Marcelo Tosatti
  0 siblings, 1 reply; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-28 20:28 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: avi, kvm

On Wed, Jul 28, 2010 at 10:55 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
> On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
>> This adds a unit test for real mode emulation of the iret instruction
>>
>> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
>>
>> ---
>> Changes from v1:
>> - Added test for 16-bit iret
>> - Added tests for returned eflags
>> ---
>>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
>>  1 files changed, 79 insertions(+), 0 deletions(-)
>>
>> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
>> index bd79348..74456c3 100644
>> --- a/kvm/test/x86/realmode.c
>> +++ b/kvm/test/x86/realmode.c
>> @@ -865,6 +865,84 @@ void test_pusha_popa()
>>               print_serial("Pusha/Popa Test2: PASS\n");
>>  }
>>
>> +void test_iret()
>> +{
>> +     struct regs inregs = { 0 }, outregs;
>> +
>> +     MK_INSN(iret32, "pushf\n\t"
>> +                     "pushl %cs\n\t"
>> +                     "call 1f\n\t" /* a near call will push eip onto the stack */
>> +                     "jmp 2f\n\t"
>> +                     "1: iret\n\t"
>> +                     "2:\n\t"
>> +                  );
>> +
>> +     MK_INSN(iret16, "pushfw\n\t"
>> +                     "pushw %cs\n\t"
>> +                     "callw 1f\n\t"
>> +                     "jmp 2f\n\t"
>> +                     "1: iretw\n\t"
>> +                     "2:\n\t");
>
> Unless iret causes a task switch, it will not cause an exit.
>
>
The test covers only the real mode case, we won't have a task switch there, no?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28 20:28   ` Mohammed Gamal
@ 2010-07-28 20:32     ` Marcelo Tosatti
  2010-07-28 20:36       ` Mohammed Gamal
  0 siblings, 1 reply; 13+ messages in thread
From: Marcelo Tosatti @ 2010-07-28 20:32 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: avi, kvm

On Wed, Jul 28, 2010 at 11:28:05PM +0300, Mohammed Gamal wrote:
> On Wed, Jul 28, 2010 at 10:55 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
> > On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
> >> This adds a unit test for real mode emulation of the iret instruction
> >>
> >> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
> >>
> >> ---
> >> Changes from v1:
> >> - Added test for 16-bit iret
> >> - Added tests for returned eflags
> >> ---
> >>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
> >>  1 files changed, 79 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
> >> index bd79348..74456c3 100644
> >> --- a/kvm/test/x86/realmode.c
> >> +++ b/kvm/test/x86/realmode.c
> >> @@ -865,6 +865,84 @@ void test_pusha_popa()
> >>               print_serial("Pusha/Popa Test2: PASS\n");
> >>  }
> >>
> >> +void test_iret()
> >> +{
> >> +     struct regs inregs = { 0 }, outregs;
> >> +
> >> +     MK_INSN(iret32, "pushf\n\t"
> >> +                     "pushl %cs\n\t"
> >> +                     "call 1f\n\t" /* a near call will push eip onto the stack */
> >> +                     "jmp 2f\n\t"
> >> +                     "1: iret\n\t"
> >> +                     "2:\n\t"
> >> +                  );
> >> +
> >> +     MK_INSN(iret16, "pushfw\n\t"
> >> +                     "pushw %cs\n\t"
> >> +                     "callw 1f\n\t"
> >> +                     "jmp 2f\n\t"
> >> +                     "1: iretw\n\t"
> >> +                     "2:\n\t");
> >
> > Unless iret causes a task switch, it will not cause an exit.
> >
> >
> The test covers only the real mode case, we won't have a task switch there, no?

No. And there is no vmexit for iret, so it does not go through the
emulator.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28 20:32     ` Marcelo Tosatti
@ 2010-07-28 20:36       ` Mohammed Gamal
       [not found]         ` <20100728205627.GA31469@amt.cnet>
  0 siblings, 1 reply; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-28 20:36 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: avi, kvm

On Wed, Jul 28, 2010 at 11:32 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
> On Wed, Jul 28, 2010 at 11:28:05PM +0300, Mohammed Gamal wrote:
>> On Wed, Jul 28, 2010 at 10:55 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>> > On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
>> >> This adds a unit test for real mode emulation of the iret instruction
>> >>
>> >> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
>> >>
>> >> ---
>> >> Changes from v1:
>> >> - Added test for 16-bit iret
>> >> - Added tests for returned eflags
>> >> ---
>> >>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
>> >>  1 files changed, 79 insertions(+), 0 deletions(-)
>> >>
>> >> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
>> >> index bd79348..74456c3 100644
>> >> --- a/kvm/test/x86/realmode.c
>> >> +++ b/kvm/test/x86/realmode.c
>> >> @@ -865,6 +865,84 @@ void test_pusha_popa()
>> >>               print_serial("Pusha/Popa Test2: PASS\n");
>> >>  }
>> >>
>> >> +void test_iret()
>> >> +{
>> >> +     struct regs inregs = { 0 }, outregs;
>> >> +
>> >> +     MK_INSN(iret32, "pushf\n\t"
>> >> +                     "pushl %cs\n\t"
>> >> +                     "call 1f\n\t" /* a near call will push eip onto the stack */
>> >> +                     "jmp 2f\n\t"
>> >> +                     "1: iret\n\t"
>> >> +                     "2:\n\t"
>> >> +                  );
>> >> +
>> >> +     MK_INSN(iret16, "pushfw\n\t"
>> >> +                     "pushw %cs\n\t"
>> >> +                     "callw 1f\n\t"
>> >> +                     "jmp 2f\n\t"
>> >> +                     "1: iretw\n\t"
>> >> +                     "2:\n\t");
>> >
>> > Unless iret causes a task switch, it will not cause an exit.
>> >
>> >
>> The test covers only the real mode case, we won't have a task switch there, no?
>
> No. And there is no vmexit for iret, so it does not go through the
> emulator.
>
I'm pretty sure the iret instruction went through the emulator. I saw
the instruction opcode (0xcf) being in ftrace.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
       [not found]           ` <AANLkTi=tguT3Y2qStz-Z31HQF684VDiG=gomJfB34AJj@mail.gmail.com>
@ 2010-07-28 23:16             ` Mohammed Gamal
  2010-07-28 23:18               ` Mohammed Gamal
  0 siblings, 1 reply; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-28 23:16 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm-devel, Avi Kivity

On Thu, Jul 29, 2010 at 2:13 AM, Mohammed Gamal <m.gamal005@gmail.com> wrote:
> On Wed, Jul 28, 2010 at 11:56 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>> On Wed, Jul 28, 2010 at 11:36:16PM +0300, Mohammed Gamal wrote:
>>> On Wed, Jul 28, 2010 at 11:32 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>>> > On Wed, Jul 28, 2010 at 11:28:05PM +0300, Mohammed Gamal wrote:
>>> >> On Wed, Jul 28, 2010 at 10:55 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>>> >> > On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
>>> >> >> This adds a unit test for real mode emulation of the iret instruction
>>> >> >>
>>> >> >> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
>>> >> >>
>>> >> >> ---
>>> >> >> Changes from v1:
>>> >> >> - Added test for 16-bit iret
>>> >> >> - Added tests for returned eflags
>>> >> >> ---
>>> >> >>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
>>> >> >>  1 files changed, 79 insertions(+), 0 deletions(-)
>>> >> >>
>>> >> >> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
>>> >> >> index bd79348..74456c3 100644
>>> >> >> --- a/kvm/test/x86/realmode.c
>>> >> >> +++ b/kvm/test/x86/realmode.c
>>> >> >> @@ -865,6 +865,84 @@ void test_pusha_popa()
>>> >> >>               print_serial("Pusha/Popa Test2: PASS\n");
>>> >> >>  }
>>> >> >>
>>> >> >> +void test_iret()
>>> >> >> +{
>>> >> >> +     struct regs inregs = { 0 }, outregs;
>>> >> >> +
>>> >> >> +     MK_INSN(iret32, "pushf\n\t"
>>> >> >> +                     "pushl %cs\n\t"
>>> >> >> +                     "call 1f\n\t" /* a near call will push eip onto the stack */
>>> >> >> +                     "jmp 2f\n\t"
>>> >> >> +                     "1: iret\n\t"
>>> >> >> +                     "2:\n\t"
>>> >> >> +                  );
>>> >> >> +
>>> >> >> +     MK_INSN(iret16, "pushfw\n\t"
>>> >> >> +                     "pushw %cs\n\t"
>>> >> >> +                     "callw 1f\n\t"
>>> >> >> +                     "jmp 2f\n\t"
>>> >> >> +                     "1: iretw\n\t"
>>> >> >> +                     "2:\n\t");
>>> >> >
>>> >> > Unless iret causes a task switch, it will not cause an exit.
>>> >> >
>>> >> >
>>> >> The test covers only the real mode case, we won't have a task switch there, no?
>>> >
>>> > No. And there is no vmexit for iret, so it does not go through the
>>> > emulator.
>>> >
>>> I'm pretty sure the iret instruction went through the emulator. I saw
>>> the instruction opcode (0xcf) being in ftrace.
>>
>> Can you confirm that please? I don't see it here.
>>
>
Sure, here is the ftrace output corresponding to the test instructions

From the first test
qemu-system-x86-12850 [001]  5167.509842: kvm_emulate_insn: 0:4200: 66 9c (real)
 qemu-system-x86-12850 [001]  5167.509844: kvm_emulate_insn: 0:4202:
66 0e (real)
 qemu-system-x86-12850 [001]  5167.509847: kvm_emulate_insn: 0:4204:
66 e8 02 00 00 00 (real)
 qemu-system-x86-12850 [001]  5167.509849: kvm_emulate_insn: 0:420c:
66 cf (real)
 qemu-system-x86-12850 [001]  5167.509852: kvm_emulate_insn: 0:420a:
eb 02 (real)

Second test:
qemu-system-x86-12850 [001]  5167.509998: kvm_emulate_insn: 0:4200: 9c (real)
 qemu-system-x86-12850 [001]  5167.510000: kvm_emulate_insn: 0:4201: 0e (real)
 qemu-system-x86-12850 [001]  5167.510002: kvm_emulate_insn: 0:4202:
e8 02 00 (real)
  qemu-system-x86-12850 [001]  5167.510004: kvm_emulate_insn: 0:4207: cf (real)
  qemu-system-x86-12850 [001]  5167.510006: kvm_emulate_insn: 0:4205:
eb 01 (real)

Third test:
          <...>-12850 [001]  5167.510162: kvm_emulate_insn: 0:4200: 66 9c (real)
           <...>-12850 [001]  5167.510164: kvm_emulate_insn: 0:4202:
 66 58 (real)
           <...>-12850 [001]  5167.510166: kvm_emulate_insn: 0:4204:
 66 83 e0 fd (real)
           <...>-12850 [001]  5167.510168: kvm_emulate_insn: 0:4208:
 66 0d 28 80 c0 ff (real)
           <...>-12850 [001]  5167.510170: kvm_emulate_insn: 0:420e:
 66 50 (real)
           <...>-12850 [001]  5167.510172: kvm_emulate_insn: 0:4210:
 66 0e (real)
           <...>-12850 [001]  5167.510174: kvm_emulate_insn: 0:4212:
 66 e8 02 00 00 00 (real)
           <...>-12850 [001]  5167.510176: kvm_emulate_insn: 0:421a:
 66 cf (real)
           <...>-12850 [001]  5167.510179: kvm_emulate_insn: 0:4218:
 eb 02 (real)


 Fourth test:
  qemu-system-x86-12850 [001]  5167.510302: kvm_emulate_insn: 0:4200: 9c (real)
  qemu-system-x86-12850 [001]  5167.510304: kvm_emulate_insn: 0:4201: 58 (real)
  qemu-system-x86-12850 [001]  5167.510306: kvm_emulate_insn: 0:4202:
 83 e0 fd (real)
  qemu-system-x86-12850 [001]  5167.510308: kvm_emulate_insn: 0:4205:
 0d 28 80 (real)
  qemu-system-x86-12850 [001]  5167.510310: kvm_emulate_insn: 0:4208: 50 (real)
  qemu-system-x86-12850 [001]  5167.510312: kvm_emulate_insn: 0:4209: 0e (real)
  qemu-system-x86-12850 [001]  5167.510313: kvm_emulate_insn: 0:420a:
 e8 02 00 (real)
  qemu-system-x86-12850 [001]  5167.510315: kvm_emulate_insn: 0:420f: cf (real)
  qemu-system-x86-12850 [001]  5167.510318: kvm_emulate_insn: 0:420d:
 eb 01 (real)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28 23:16             ` Mohammed Gamal
@ 2010-07-28 23:18               ` Mohammed Gamal
  2010-07-29  1:21                 ` Marcelo Tosatti
  0 siblings, 1 reply; 13+ messages in thread
From: Mohammed Gamal @ 2010-07-28 23:18 UTC (permalink / raw)
  To: Marcelo Tosatti; +Cc: kvm-devel, Avi Kivity

On Thu, Jul 29, 2010 at 2:16 AM, Mohammed Gamal <m.gamal005@gmail.com> wrote:
> On Thu, Jul 29, 2010 at 2:13 AM, Mohammed Gamal <m.gamal005@gmail.com> wrote:
>> On Wed, Jul 28, 2010 at 11:56 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>>> On Wed, Jul 28, 2010 at 11:36:16PM +0300, Mohammed Gamal wrote:
>>>> On Wed, Jul 28, 2010 at 11:32 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>>>> > On Wed, Jul 28, 2010 at 11:28:05PM +0300, Mohammed Gamal wrote:
>>>> >> On Wed, Jul 28, 2010 at 10:55 PM, Marcelo Tosatti <mtosatti@redhat.com> wrote:
>>>> >> > On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
>>>> >> >> This adds a unit test for real mode emulation of the iret instruction
>>>> >> >>
>>>> >> >> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
>>>> >> >>
>>>> >> >> ---
>>>> >> >> Changes from v1:
>>>> >> >> - Added test for 16-bit iret
>>>> >> >> - Added tests for returned eflags
>>>> >> >> ---
>>>> >> >>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
>>>> >> >>  1 files changed, 79 insertions(+), 0 deletions(-)
>>>> >> >>
>>>> >> >> diff --git a/kvm/test/x86/realmode.c b/kvm/test/x86/realmode.c
>>>> >> >> index bd79348..74456c3 100644
>>>> >> >> --- a/kvm/test/x86/realmode.c
>>>> >> >> +++ b/kvm/test/x86/realmode.c
>>>> >> >> @@ -865,6 +865,84 @@ void test_pusha_popa()
>>>> >> >>               print_serial("Pusha/Popa Test2: PASS\n");
>>>> >> >>  }
>>>> >> >>
>>>> >> >> +void test_iret()
>>>> >> >> +{
>>>> >> >> +     struct regs inregs = { 0 }, outregs;
>>>> >> >> +
>>>> >> >> +     MK_INSN(iret32, "pushf\n\t"
>>>> >> >> +                     "pushl %cs\n\t"
>>>> >> >> +                     "call 1f\n\t" /* a near call will push eip onto the stack */
>>>> >> >> +                     "jmp 2f\n\t"
>>>> >> >> +                     "1: iret\n\t"
>>>> >> >> +                     "2:\n\t"
>>>> >> >> +                  );
>>>> >> >> +
>>>> >> >> +     MK_INSN(iret16, "pushfw\n\t"
>>>> >> >> +                     "pushw %cs\n\t"
>>>> >> >> +                     "callw 1f\n\t"
>>>> >> >> +                     "jmp 2f\n\t"
>>>> >> >> +                     "1: iretw\n\t"
>>>> >> >> +                     "2:\n\t");
>>>> >> >
>>>> >> > Unless iret causes a task switch, it will not cause an exit.
>>>> >> >
>>>> >> >
>>>> >> The test covers only the real mode case, we won't have a task switch there, no?
>>>> >
>>>> > No. And there is no vmexit for iret, so it does not go through the
>>>> > emulator.
>>>> >
>>>> I'm pretty sure the iret instruction went through the emulator. I saw
>>>> the instruction opcode (0xcf) being in ftrace.
>>>
>>> Can you confirm that please? I don't see it here.
>>>
>>
> Sure, here is the ftrace output corresponding to the test instructions
>
> From the first test
> qemu-system-x86-12850 [001]  5167.509842: kvm_emulate_insn: 0:4200: 66 9c (real)
>  qemu-system-x86-12850 [001]  5167.509844: kvm_emulate_insn: 0:4202:
> 66 0e (real)
>  qemu-system-x86-12850 [001]  5167.509847: kvm_emulate_insn: 0:4204:
> 66 e8 02 00 00 00 (real)
>  qemu-system-x86-12850 [001]  5167.509849: kvm_emulate_insn: 0:420c:
> 66 cf (real)
>  qemu-system-x86-12850 [001]  5167.509852: kvm_emulate_insn: 0:420a:
> eb 02 (real)
>
> Second test:
> qemu-system-x86-12850 [001]  5167.509998: kvm_emulate_insn: 0:4200: 9c (real)
>  qemu-system-x86-12850 [001]  5167.510000: kvm_emulate_insn: 0:4201: 0e (real)
>  qemu-system-x86-12850 [001]  5167.510002: kvm_emulate_insn: 0:4202:
> e8 02 00 (real)
>   qemu-system-x86-12850 [001]  5167.510004: kvm_emulate_insn: 0:4207: cf (real)
>   qemu-system-x86-12850 [001]  5167.510006: kvm_emulate_insn: 0:4205:
> eb 01 (real)
>
> Third test:
>           <...>-12850 [001]  5167.510162: kvm_emulate_insn: 0:4200: 66 9c (real)
>            <...>-12850 [001]  5167.510164: kvm_emulate_insn: 0:4202:
>  66 58 (real)
>            <...>-12850 [001]  5167.510166: kvm_emulate_insn: 0:4204:
>  66 83 e0 fd (real)
>            <...>-12850 [001]  5167.510168: kvm_emulate_insn: 0:4208:
>  66 0d 28 80 c0 ff (real)
>            <...>-12850 [001]  5167.510170: kvm_emulate_insn: 0:420e:
>  66 50 (real)
>            <...>-12850 [001]  5167.510172: kvm_emulate_insn: 0:4210:
>  66 0e (real)
>            <...>-12850 [001]  5167.510174: kvm_emulate_insn: 0:4212:
>  66 e8 02 00 00 00 (real)
>            <...>-12850 [001]  5167.510176: kvm_emulate_insn: 0:421a:
>  66 cf (real)
>            <...>-12850 [001]  5167.510179: kvm_emulate_insn: 0:4218:
>  eb 02 (real)
>
>
>  Fourth test:
>   qemu-system-x86-12850 [001]  5167.510302: kvm_emulate_insn: 0:4200: 9c (real)
>   qemu-system-x86-12850 [001]  5167.510304: kvm_emulate_insn: 0:4201: 58 (real)
>   qemu-system-x86-12850 [001]  5167.510306: kvm_emulate_insn: 0:4202:
>  83 e0 fd (real)
>   qemu-system-x86-12850 [001]  5167.510308: kvm_emulate_insn: 0:4205:
>  0d 28 80 (real)
>   qemu-system-x86-12850 [001]  5167.510310: kvm_emulate_insn: 0:4208: 50 (real)
>   qemu-system-x86-12850 [001]  5167.510312: kvm_emulate_insn: 0:4209: 0e (real)
>   qemu-system-x86-12850 [001]  5167.510313: kvm_emulate_insn: 0:420a:
>  e8 02 00 (real)
>   qemu-system-x86-12850 [001]  5167.510315: kvm_emulate_insn: 0:420f: cf (real)
>   qemu-system-x86-12850 [001]  5167.510318: kvm_emulate_insn: 0:420d:
>  eb 01 (real)
>

As an extra note, you need to run realmode.flat with the
emulate_invalid_guest_state=1 module option for kvm_intel. If you
don't use that option, the emulator is not going to be invoked.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28 23:18               ` Mohammed Gamal
@ 2010-07-29  1:21                 ` Marcelo Tosatti
  0 siblings, 0 replies; 13+ messages in thread
From: Marcelo Tosatti @ 2010-07-29  1:21 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: kvm-devel, Avi Kivity

On Thu, Jul 29, 2010 at 02:18:20AM +0300, Mohammed Gamal wrote:
> >  Fourth test:
> >   qemu-system-x86-12850 [001]  5167.510302: kvm_emulate_insn: 0:4200: 9c (real)
> >   qemu-system-x86-12850 [001]  5167.510304: kvm_emulate_insn: 0:4201: 58 (real)
> >   qemu-system-x86-12850 [001]  5167.510306: kvm_emulate_insn: 0:4202:
> >  83 e0 fd (real)
> >   qemu-system-x86-12850 [001]  5167.510308: kvm_emulate_insn: 0:4205:
> >  0d 28 80 (real)
> >   qemu-system-x86-12850 [001]  5167.510310: kvm_emulate_insn: 0:4208: 50 (real)
> >   qemu-system-x86-12850 [001]  5167.510312: kvm_emulate_insn: 0:4209: 0e (real)
> >   qemu-system-x86-12850 [001]  5167.510313: kvm_emulate_insn: 0:420a:
> >  e8 02 00 (real)
> >   qemu-system-x86-12850 [001]  5167.510315: kvm_emulate_insn: 0:420f: cf (real)
> >   qemu-system-x86-12850 [001]  5167.510318: kvm_emulate_insn: 0:420d:
> >  eb 01 (real)
> >
> 
> As an extra note, you need to run realmode.flat with the
> emulate_invalid_guest_state=1 module option for kvm_intel. If you
> don't use that option, the emulator is not going to be invoked.

Doh, right.


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH] test: Add emulator test for iret instruction
  2010-07-28  9:39 [PATCH] test: Add emulator test for iret instruction Mohammed Gamal
  2010-07-28 19:55 ` Marcelo Tosatti
@ 2010-07-29 15:50 ` Marcelo Tosatti
  1 sibling, 0 replies; 13+ messages in thread
From: Marcelo Tosatti @ 2010-07-29 15:50 UTC (permalink / raw)
  To: Mohammed Gamal; +Cc: avi, kvm

On Wed, Jul 28, 2010 at 12:39:01PM +0300, Mohammed Gamal wrote:
> This adds a unit test for real mode emulation of the iret instruction
> 
> Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
> 
> ---
> Changes from v1:
> - Added test for 16-bit iret
> - Added tests for returned eflags
> ---
>  kvm/test/x86/realmode.c |   79 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 79 insertions(+), 0 deletions(-)

Applied, thanks.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-07-29 16:20 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-28  9:39 [PATCH] test: Add emulator test for iret instruction Mohammed Gamal
2010-07-28 19:55 ` Marcelo Tosatti
2010-07-28 20:28   ` Mohammed Gamal
2010-07-28 20:32     ` Marcelo Tosatti
2010-07-28 20:36       ` Mohammed Gamal
     [not found]         ` <20100728205627.GA31469@amt.cnet>
     [not found]           ` <AANLkTi=tguT3Y2qStz-Z31HQF684VDiG=gomJfB34AJj@mail.gmail.com>
2010-07-28 23:16             ` Mohammed Gamal
2010-07-28 23:18               ` Mohammed Gamal
2010-07-29  1:21                 ` Marcelo Tosatti
2010-07-29 15:50 ` Marcelo Tosatti
  -- strict thread matches above, loose matches on Subject: below --
2010-07-27 23:22 Mohammed Gamal
2010-07-28  4:21 ` Avi Kivity
2010-07-28  4:28   ` Avi Kivity
2010-07-27 23:03 Mohammed Gamal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox