Skip to contentSkip to conversation

SVM: move guest past HLT

PATCH In review Paolo Bonzini 2 participants 3 messages Apr 23, 2020 KVM

lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 SVM: move guest past HLT

On AMD, the guest is not woken up from HLT by the interrupt or NMI vmexits. Therefore we have to fix up the RIP manually.

---
 x86/svm_tests.c | 8 ++++++++
 1 file changed, 8 insertions(+)
x86/svm_tests.c +8 -0
index c2725af..1f2975c 100644
@@ -1316,6 +1316,11 @@ static bool interrupt_finished(struct svm_test *test)
             return true;
         }
 
+        /* The guest is not woken up from HLT, unlike Intel.  Fix that up.  */
+        if (get_test_stage(test) == 3) {
+            vmcb->save.rip++;
+        }
+
         irq_enable();
         asm volatile ("nop");
         irq_disable();
@@ -1501,6 +1506,9 @@ static bool nmi_hlt_finished(struct svm_test *test)
             return true;
         }
 
+        /* The guest is not woken up from HLT, unlike Intel.  Fix that up.  */
+        vmcb->save.rip++;
+
         report(true, "NMI intercept while running guest");
         break;
 
Signature · 1 line
2.18.2
#1 lore raw
Quoted 13 lines · Paolo Bonzini

On AMD, the guest is not woken up from HLT by the interrupt or NMI vmexits. Therefore we have to fix up the RIP manually.

---
 x86/svm_tests.c | 8 ++++++++
 1 file changed, 8 insertions(+)
x86/svm_tests.c +0 -0
index c2725af..1f2975c 100644

x86/svm_tests.c static bool interrupt_finished(struct svm_test *test) · line 1319

Quoted 4 lines
x86/svm_tests.c +1 -0
@@ -1316,6 +1316,11 @@ static bool interrupt_finished(struct svm_test *test)
             return true;
         }
 
+        /* The guest is not woken up from HLT, unlike Intel.  Fix that up.  */

The comment about "unlike Intel" isn't correct, or at least it's not always correct. Intercept NMIs/interrupts don't affect vmcs.GUEST_ACTIVITY, i.e. if the guest was in HLT before the exit then that's what will be recorded in the VMCS.

https://lkml.kernel.org/r/[email protected]

Quoted 20 lines
x86/svm_tests.c +7 -0
+        if (get_test_stage(test) == 3) {
+            vmcb->save.rip++;
+        }
+
         irq_enable();
         asm volatile ("nop");
         irq_disable();
@@ -1501,6 +1506,9 @@ static bool nmi_hlt_finished(struct svm_test *test)
             return true;
         }
 
+        /* The guest is not woken up from HLT, unlike Intel.  Fix that up.  */
+        vmcb->save.rip++;
+
         report(true, "NMI intercept while running guest");
         break;
 
Signature · 1 line
2.18.2
author maintainer
#2 lore raw
Quoted 8 lines · Sean Christopherson
Quoted 2 lines

+ /* The guest is not woken up from HLT, unlike Intel. Fix that up. */

The comment about "unlike Intel" isn't correct, or at least it's not always correct. Intercept NMIs/interrupts don't affect vmcs.GUEST_ACTIVITY, i.e. if the guest was in HLT before the exit then that's what will be recorded in the VMCS.

https://lkml.kernel.org/r/[email protected]

Ok, I'll change it to "The guest is not woken up from HLT and RIP still points to it".

On Intel indeed it is not woken up either but vmx_tests.c has

                if (vmx_get_test_stage() >= 2)
                        vmcs_write(GUEST_ACTV_STATE, ACTV_ACTIVE);

Then it's not surprising that, when I fixed a bunch of nested AMD things to behave the same as in vmx/vmx.c, SVM broke and needed this patch.

Paolo