Skip to contentSkip to conversation

svm: run tests with host IF=1

PATCH In review Paolo Bonzini 2 participants 4 messages Nov 13, 2019 KVM

lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 svm: run tests with host IF=1

Tests should in general call VMRUN with EFLAGS.IF=1 (if there are exceptions in the future we can add a cmp/jz in test_run). This is because currently interrupts are masked during all of VMRUN, while we usually want interrupts during a test to cause a vmexit. This is similar to how PIN_EXTINT and PIN_NMI are included by default in the VMCS used by vmx.flat.

---
 x86/svm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
x86/svm.c +4 -1
index 4ddfaa4..097a296 100644
@@ -254,6 +254,7 @@ static void test_run(struct test *test, struct vmcb *vmcb)
     u64 vmcb_phys = virt_to_phys(vmcb);
     u64 guest_stack[10000];
 
+    irq_disable();
     test->vmcb = vmcb;
     test->prepare(test);
     vmcb->save.rip = (ulong)test_thunk;
@@ -269,7 +270,9 @@ static void test_run(struct test *test, struct vmcb *vmcb)
             "mov regs, %%r15\n\t"       // rax
             "mov %%r15, 0x1f8(%0)\n\t"
             LOAD_GPR_C
+            "sti \n\t"		// only used if V_INTR_MASKING=1
             "vmrun \n\t"
+            "cli \n\t"
             SAVE_GPR_C
             "mov 0x170(%0), %%r15\n\t"  // rflags
             "mov %%r15, regs+0x80\n\t"
@@ -284,6 +287,7 @@ static void test_run(struct test *test, struct vmcb *vmcb)
 	tsc_end = rdtsc();
         ++test->exits;
     } while (!test->finished(test));
+    irq_enable();
 
     report("%s", test->succeeded(test), test->name);
 }
@@ -301,7 +305,6 @@ static bool default_supported(void)
 static void default_prepare(struct test *test)
 {
     vmcb_ident(test->vmcb);
-    cli();
 }
 
 static bool default_finished(struct test *test)
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 43 lines · Paolo Bonzini

Tests should in general call VMRUN with EFLAGS.IF=1 (if there are exceptions in the future we can add a cmp/jz in test_run). This is because currently interrupts are masked during all of VMRUN, while we usually want interrupts during a test to cause a vmexit. This is similar to how PIN_EXTINT and PIN_NMI are included by default in the VMCS used by vmx.flat.

---
  x86/svm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
x86/svm.c +4 -0
index 4ddfaa4..097a296 100644
@@ -254,6 +254,7 @@ static void test_run(struct test *test, struct vmcb *vmcb)
      u64 vmcb_phys = virt_to_phys(vmcb);
      u64 guest_stack[10000];
 
+    irq_disable();
      test->vmcb = vmcb;
      test->prepare(test);
      vmcb->save.rip = (ulong)test_thunk;
@@ -269,7 +270,9 @@ static void test_run(struct test *test, struct vmcb *vmcb)
              "mov regs, %%r15\n\t"       // rax
              "mov %%r15, 0x1f8(%0)\n\t"
              LOAD_GPR_C
+            "sti \n\t"		// only used if V_INTR_MASKING=1
              "vmrun \n\t"
+            "cli \n\t"
              SAVE_GPR_C
              "mov 0x170(%0), %%r15\n\t"  // rflags
              "mov %%r15, regs+0x80\n\t"
@@ -284,6 +287,7 @@ static void test_run(struct test *test, struct vmcb *vmcb)
  	tsc_end = rdtsc();
          ++test->exits;
      } while (!test->finished(test));
+    irq_enable();
 
      report("%s", test->succeeded(test), test->name);
  }

x86/svm.c static bool default_supported(void) · line 310

Quoted 7 lines
x86/svm.c +0 -1
@@ -301,7 +305,6 @@ static bool default_supported(void)
  static void default_prepare(struct test *test)
  {
      vmcb_ident(test->vmcb);
-    cli();
  }
 
  static bool default_finished(struct test *test)
#2 lore raw
In reply to Paolo Bonzini
Quoted 25 lines · Paolo Bonzini

Tests should in general call VMRUN with EFLAGS.IF=1 (if there are exceptions in the future we can add a cmp/jz in test_run). This is because currently interrupts are masked during all of VMRUN, while we usually want interrupts during a test to cause a vmexit. This is similar to how PIN_EXTINT and PIN_NMI are included by default in the VMCS used by vmx.flat.

---
  x86/svm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
x86/svm.c +1 -0
index 4ddfaa4..097a296 100644
@@ -254,6 +254,7 @@ static void test_run(struct test *test, struct vmcb *vmcb)
      u64 vmcb_phys = virt_to_phys(vmcb);
      u64 guest_stack[10000];
 
+    irq_disable();
      test->vmcb = vmcb;
      test->prepare(test);
      vmcb->save.rip = (ulong)test_thunk;

x86/svm.c static void test_run(struct test *test, struct vmcb *vmcb) · line 273

Quoted 4 lines
x86/svm.c +1 -0
@@ -269,7 +270,9 @@ static void test_run(struct test *test, struct vmcb *vmcb)
              "mov regs, %%r15\n\t"       // rax
              "mov %%r15, 0x1f8(%0)\n\t"
              LOAD_GPR_C
+            "sti \n\t"		// only used if V_INTR_MASKING=1

I thought sti was going to be conditional

// entered with IF=0
    clgi
    cmp    $0, test_host_if
    jz    1f
    sti

Quoted 21 lines
x86/svm.c +2 -1
              "vmrun \n\t"
+            "cli \n\t"
              SAVE_GPR_C
              "mov 0x170(%0), %%r15\n\t"  // rflags
              "mov %%r15, regs+0x80\n\t"
@@ -284,6 +287,7 @@ static void test_run(struct test *test, struct vmcb *vmcb)
  	tsc_end = rdtsc();
          ++test->exits;
      } while (!test->finished(test));
+    irq_enable();
 
      report("%s", test->succeeded(test), test->name);
  }
@@ -301,7 +305,6 @@ static bool default_supported(void)
  static void default_prepare(struct test *test)
  {
      vmcb_ident(test->vmcb);
-    cli();
  }
 
  static bool default_finished(struct test *test)
#3 lore raw
Quoted 34 lines · Cathy Avery
Quoted 26 lines · Paolo Bonzini

Tests should in general call VMRUN with EFLAGS.IF=1 (if there are exceptions in the future we can add a cmp/jz in test_run).  This is because currently interrupts are masked during all of VMRUN, while we usually want interrupts during a test to cause a vmexit. This is similar to how PIN_EXTINT and PIN_NMI are included by default in the VMCS used by vmx.flat.

---
  x86/svm.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
x86/svm.c +0 -0
index 4ddfaa4..097a296 100644
@@ -254,6 +254,7 @@ static void test_run(struct test *test, struct 
 vmcb *vmcb)
       u64 vmcb_phys = virt_to_phys(vmcb);
       u64 guest_stack[10000];
   +    irq_disable();
       test->vmcb = vmcb;
       test->prepare(test);

      vmcb->save.rip = (ulong)test_thunk;

x86/svm.c +0 -0
@@ -269,7 +270,9 @@ static void test_run(struct test *test, struct 
 vmcb *vmcb)
Quoted 4 lines

              "mov regs, %%r15\n\t"       // rax
              "mov %%r15, 0x1f8(%0)\n\t"
              LOAD_GPR_C
+            "sti \n\t"        // only used if V_INTR_MASKING=1

I thought sti was going to be conditional

Quoted 5 lines

// entered with IF=0
    clgi
    cmp    $0, test_host_if
    jz    1f
    sti

OK missed the comment above.

Quoted 23 lines
Quoted 21 lines

              "vmrun \n\t"
+            "cli \n\t"
              SAVE_GPR_C
              "mov 0x170(%0), %%r15\n\t"  // rflags "mov %%r15, regs+0x80\n\t"

x86/svm.c +1 -1
@@ -284,6 +287,7 @@ static void test_run(struct test *test, struct 
 vmcb *vmcb)
       tsc_end = rdtsc();
           ++test->exits;
       } while (!test->finished(test));
+    irq_enable();
         report("%s", test->succeeded(test), test->name);
   }
@@ -301,7 +305,6 @@ static bool default_supported(void)
   static void default_prepare(struct test *test)
   {
       vmcb_ident(test->vmcb);
-    cli();
   }
     static bool default_finished(struct test *test)