All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests] SVM: move guest past HLT
@ 2020-04-23 17:06 Paolo Bonzini
  2020-04-23 19:46 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2020-04-23 17:06 UTC (permalink / raw)
  To: kvm; +Cc: wei.huang2, cavery

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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/svm_tests.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/x86/svm_tests.c b/x86/svm_tests.c
index c2725af..1f2975c 100644
--- a/x86/svm_tests.c
+++ b/x86/svm_tests.c
@@ -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;
 
-- 
2.18.2


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

* Re: [PATCH kvm-unit-tests] SVM: move guest past HLT
  2020-04-23 17:06 [PATCH kvm-unit-tests] SVM: move guest past HLT Paolo Bonzini
@ 2020-04-23 19:46 ` Sean Christopherson
  2020-04-23 21:23   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2020-04-23 19:46 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, wei.huang2, cavery

On Thu, Apr 23, 2020 at 01:06:53PM -0400, Paolo Bonzini wrote:
> 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.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  x86/svm_tests.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/x86/svm_tests.c b/x86/svm_tests.c
> index c2725af..1f2975c 100644
> --- a/x86/svm_tests.c
> +++ b/x86/svm_tests.c
> @@ -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/20190509204838.GC12810@linux.intel.com

> +        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;
>  
> -- 
> 2.18.2
> 

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

* Re: [PATCH kvm-unit-tests] SVM: move guest past HLT
  2020-04-23 19:46 ` Sean Christopherson
@ 2020-04-23 21:23   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-04-23 21:23 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: kvm, wei.huang2, cavery

On 23/04/20 21:46, Sean Christopherson wrote:
>>  
>> +        /* 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/20190509204838.GC12810@linux.intel.com

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


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

end of thread, other threads:[~2020-04-23 21:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 17:06 [PATCH kvm-unit-tests] SVM: move guest past HLT Paolo Bonzini
2020-04-23 19:46 ` Sean Christopherson
2020-04-23 21:23   ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.