Skip to contentSkip to conversation

some nested vmx fixing to hyper-v

PATCH In review Yang Zhang 5 participants 26 messages Dec 12, 2013 – Jan 21, 2014

lore
Share & tools
lore

Yang Zhang

author
#0 lore raw

cover some nested vmx fixing to hyper-v

From: Yang Zhang <[email protected]>

This series patches fix some issues which i encountered when boot L1 hyper-v.

This patch fixed RHEL6 guest installation problem with L1 hyper-v:
Nested VMX: update nested paging mode when vmswitch is in progress

The two fixing SMP hyper-v boot issue:
VMX,apicv: Set "NMI-window exiting" for NMI Nested VMX: Setup the virtual NMI exiting info:

Yang Zhang (3):
Nested VMX: update nested paging mode when vmswitch is in progress VMX,apicv: Set "NMI-window exiting" for NMI
Nested VMX: Setup the virtual NMI exiting info

 xen/arch/x86/hvm/hvm.c      |    4 ++--
 xen/arch/x86/hvm/vmx/intr.c |    7 ++++---
 xen/arch/x86/hvm/vmx/vvmx.c |    6 ++++++
 3 files changed, 12 insertions(+), 5 deletions(-)
author
#1 lore raw

PATCH 1/3 Nested VMX: update nested paging mode when vmswitch is in progress

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c +2 -2
index 69f7e74..1f62e00 100644
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
@@ -2014,7 +2014,7 @@ int hvm_set_cr4(unsigned long value)
           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE | X86_CR4_SMEP)) ||
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 6 lines · Yang Zhang

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

I weakly remember the "!nestedhvm_vmswitch_in_progress" is needed to avoid a nested pagefault loop on AMD. I do not remember the actual reproduction case. Unfortunately, I do not have a setup to verify.

Christoph

Quoted 29 lines
---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c +2 -2
index 69f7e74..1f62e00 100644
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
@@ -2014,7 +2014,7 @@ int hvm_set_cr4(unsigned long value)
           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE | X86_CR4_SMEP)) ||
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
#3 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Egger, Christoph wrote on 2013-12-12:

Quoted 6 lines · Yang Zhang
Quoted 5 lines

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

Quoted 6 lines
Quoted 1 line

I weakly remember the "!nestedhvm_vmswitch_in_progress" is needed to avoid a nested pagefault loop on AMD. I do not remember the actual reproduction case. Unfortunately, I do not have a setup to verify.

So you mean if CR0.PG bit is changed during vmentry, there is no need to update nested paging mode on AMD?
Consider that, if the nested VCPU is scheduled from ETP to shadow and you don't update the nested paging mode, then it will cause problem, and vice versa.

Best regards,
Yang

#4 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

In reply to Egger, Christoph

Zhang, Yang Z wrote on 2013-12-13:

Quoted 13 lines

Egger, Christoph wrote on 2013-12-12:

Quoted 11 lines · Yang Zhang
Quoted 6 lines

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

I weakly remember the "!nestedhvm_vmswitch_in_progress" is needed to avoid a nested pagefault loop on AMD. I do not remember the actual reproduction case. Unfortunately, I do not have a setup to verify.

Quoted 5 lines

So you mean if CR0.PG bit is changed during vmentry, there is no need to update nested paging mode on AMD?
Consider that, if the nested VCPU is scheduled from ETP to shadow and you don't update the nested paging mode, then it will cause problem, and vice versa.

Hi, Christoph,

Any concern with this patch?

Best regards,
Yang

#5 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

In reply to Yang Zhang

Acked by Eddie Dong <[email protected]>

-----Original Message-----
From: Zhang, Yang Z
Sent: Thursday, December 12, 2013 10:07 AM
To: [email protected]
Cc: [email protected]; Dong, Eddie; Zhang, Yang Z
Subject: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c +2 -2
index 69f7e74..1f62e00 100644
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
@@ -2014,7 +2014,7 @@ int hvm_set_cr4(unsigned long value)
           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE | X86_CR4_SMEP)) ||
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
Signature · 1 line
1.7.1
#6 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to go in).

Jan

Quoted 46 lines

-----Original Message-----
From: Zhang, Yang Z
Sent: Thursday, December 12, 2013 10:07 AM
To: [email protected]
Cc: [email protected]; Dong, Eddie; Zhang, Yang Z
Subject: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c +1 -1
index 69f7e74..1f62e00 100644
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) && 
 nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
xen/arch/x86/hvm/hvm.c +1 -1
@@ -2014,7 +2014,7 @@ int hvm_set_cr4(unsigned long value)
           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE | X86_CR4_SMEP)) ||
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) && 
 nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
Signature · 1 line
1.7.1
#7 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Jan Beulich wrote on 2013-12-18:

Quoted 9 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

Actually, I asked him help to review the first patch. Since Christoph thought the first patch may break AMD. So I hope he can help to review the first patch to see whether I am wrong.

Quoted 4 lines

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to go in).

Yes, the three patches are independent.

Quoted 31 lines

Jan

Zhang, Yang Z wrote on 2013-12-12:

Quoted 18 lines

vmswitch is in progress

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c index renamed from xen/arch/x86/hvm/hvm.c +0 -0

69f7e74..1f62e00 100644

xen/arch/x86/hvm/hvm.c int hvm_set_cr0(unsigned long value) · line 1931

Quoted 8 lines
xen/arch/x86/hvm/hvm.c +1 -1
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) &&
 nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v); else
             paging_update_paging_modes(v); @@ -2014,7 +2014,7

@@ int

Quoted 14 lines
Quoted 2 lines

hvm_set_cr4(unsigned long value)

           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE |

X86_CR4_SMEP)) ||

Quoted 9 lines
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) &&
nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v); else
             paging_update_paging_modes(v);

--
1.7.1

Best regards,
Yang

#8 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 11 lines · Yang Z

Jan Beulich wrote on 2013-12-18:

Quoted 9 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

Quoted 8 lines

Actually, I asked him help to review the first patch. Since Christoph thought the first patch may break AMD. So I hope he can help to review the first patch to see whether I am wrong.

Quoted 4 lines

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to go in).

Yes, the three patches are independent.

I have looked through code.

vcpu is in guestmode till the vmentry/vmexit emulation is done. In SVM the vcpu guestmode changes right before setting nv_vmswitch_in_progress to 0 when the vmentry/vmexit emulation was successfull (there is a bunch of error-checking).

This patch breaks both vmentry and vmexit emulation for SVM. The vmentry breakage comes with l1-hypervisor using shadow-paging.

During vmexit emulation hvm_set_cr0 and hvm_set_cr4 are called to restore cr0 and cr4 for the l1 guest.
With this patch the paging mode for the l2 guest is updated rather for the l1 guest.

I think this patch also breaks the case where l2 guest wants to set cr0 or cr4 and l1-hypervisor does not intercept cr0/cr4 and l1-hypervisor uses shadow-paging. This may also count for VMX.

This is just from reading the code. As I said, I do not have a setup to verify this, unfortunately.

Christoph

Quoted 51 lines
Quoted 31 lines

Jan

Zhang, Yang Z wrote on 2013-12-12:

Quoted 18 lines

vmswitch is in progress

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c index renamed from xen/arch/x86/hvm/hvm.c +0 -0

69f7e74..1f62e00 100644

xen/arch/x86/hvm/hvm.c int hvm_set_cr0(unsigned long value) · line 1931

Quoted 8 lines
xen/arch/x86/hvm/hvm.c +1 -1
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) &&
 nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v); else
             paging_update_paging_modes(v); @@ -2014,7 +2014,7

@@ int

Quoted 14 lines
Quoted 2 lines

hvm_set_cr4(unsigned long value)

           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE |

X86_CR4_SMEP)) ||

Quoted 9 lines
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) &&
nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v); else
             paging_update_paging_modes(v);

--
1.7.1

Best regards,
Yang

#9 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Egger, Christoph wrote on 2013-12-18:

Quoted 24 lines · Yang Z
Quoted 7 lines

Jan Beulich wrote on 2013-12-18:

Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Quoted 6 lines
Quoted 3 lines

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

Actually, I asked him help to review the first patch. Since Christoph thought

the first patch may break AMD. So I hope he can help to review the first patch to see whether I am wrong.

Quoted 6 lines
Quoted 6 lines

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to

go in).

Quoted 1 line
Quoted 9 lines
Quoted 1 line

Yes, the three patches are independent.

I have looked through code.

vcpu is in guestmode till the vmentry/vmexit emulation is done. In SVM the vcpu guestmode changes right before setting nv_vmswitch_in_progress to 0 when the vmentry/vmexit emulation was successfull (there is a bunch of error-checking).

After checking the SVM logic, I find the basic usage of vcpu_in/exitk_guestmode of VMX side is different from that of SVM side:
VMX side:
virtual vmentry: set vcpu in guestmode after vmcs switched to vmcs02. This happed at the beginning of vmentry which means the whole vmentry emulation code is executed when vcpu is in guest mode.
virtual vmexit: set vcpu exit guestmode after vmcs switched to vmcs01. Also, this action occurred just after sync vmcs02 to vmcs12 and before the vmcs01's state restored (like set_cr), which means the vmcs01's state restored when vcpu is not in guest mode.
SVM side:
virtual vmentry: set vcpu in guest mode after vmentry emulation is done, which means the emulation code is executed when vcpu is not in guest mode.
virtual vmexit: set vcpu exit guest mode after vmexit emulation is done, which means the emulation code is executed when vcpu is in guest mode.

Ok, now let us take a look at current implementation, take hvm_set_cr0 for example:
Update nested mode when (vcpu_in_guestmode && !vmswitch_in_progress). Otherwise, update L1's paging mode:

        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
            paging_update_nestedmode(v);
        else 
            paging_update_paging_modes(v);

virtual vmentry:
Expected result: nested mode is being updated.
Current result in SVM:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging mode is updated. Wrong.
Current result in VMX:
vcpu_in_guestmode and vmswitch_in_progress : L1's paging mode is updated. Wrong.

Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode and vmswitch_in_progress: L1's paging mode is updated. Correct.
Current result in VMX:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging mod is updated. Correct

Quoted 1 line

From the above result, we can see the vmswitch_in_progress is actually take effect not vcpu_guest_mode. The original code doesn't consider the paging mode changed during vmentry/vmexit emulation. This seems wrong to me, because paging mode changing happens in real world.

Here is the result with my patch:
Update nested mode when vcpu_in_guestmode. Otherwise, update L1's paging mode:

        if (nestedhvm_vcpu_in_guestmode(v) )
            paging_update_nestedmode(v);
        else 
            paging_update_paging_modes(v);

virtual vmentry:
Expected result: nested mode is being updated.
Current result in SVM:
!vcpu_in_guestmode: L1's paging mode is updated. Wrong.
Current result in VMX:
vcpu_in_guestmode : Nested paging mode is updated. Correct.

Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode: Nested paging mode is updated. Wrong.
Current result in VMX:
!vcpu_in_guestmode: L1's paging mod is updated. Correct

Quoted 1 line

From the above, we can see the problem is that the way to distinguish the vmentry and vmexit in SVM and VMX side is different. Since I am not familiar the SVM, so i am not sure whether the usage of vcpu_in_guestmode in SVM is right or wrong. But in VMX side, once the vmcs is changed, then the vcpu_in_guestmode is changed too which we think is following hardware's behavior.

Also, I think I found another issue that the paging mode cannot be tracked correctly with current way or with my patch. Need more time to investigate.

Quoted 10 lines

This patch breaks both vmentry and vmexit emulation for SVM. The vmentry breakage comes with l1-hypervisor using shadow-paging.

During vmexit emulation hvm_set_cr0 and hvm_set_cr4 are called to restore cr0 and cr4 for the l1 guest. With this patch the paging mode for the l2 guest is updated rather for the l1 guest.

I think this patch also breaks the case where l2 guest wants to set cr0 or cr4 and l1-hypervisor does not intercept cr0/cr4 and l1-hypervisor uses shadow-paging. This may also count for VMX.

For this case, am I missing something? If yes, please correct me.

Quoted 4 lines

This is just from reading the code. As I said, I do not have a setup to verify this, unfortunately.

Best regards,
Yang

#10 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

In reply to Egger, Christoph

Zhang, Yang Z wrote on 2013-12-23:

Quoted 106 lines

Egger, Christoph wrote on 2013-12-18:

Quoted 24 lines · Yang Z
Quoted 7 lines

Jan Beulich wrote on 2013-12-18:

Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Quoted 6 lines
Quoted 3 lines

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

Actually, I asked him help to review the first patch. Since Christoph thought

the first patch may break AMD. So I hope he can help to review the first patch to see whether I am wrong.

Quoted 6 lines
Quoted 6 lines

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to

go in).

Quoted 1 line
Quoted 9 lines
Quoted 1 line

Yes, the three patches are independent.

I have looked through code.

vcpu is in guestmode till the vmentry/vmexit emulation is done. In SVM the vcpu guestmode changes right before setting nv_vmswitch_in_progress to 0 when the vmentry/vmexit emulation was successfull (there is a bunch of error-checking).

After checking the SVM logic, I find the basic usage of vcpu_in/exitk_guestmode of VMX side is different from that of SVM side:
VMX side:
virtual vmentry: set vcpu in guestmode after vmcs switched to vmcs02.
This happed at the beginning of vmentry which means the whole vmentry emulation code is executed when vcpu is in guest mode.
virtual vmexit: set vcpu exit guestmode after vmcs switched to vmcs01.
Also, this action occurred just after sync vmcs02 to vmcs12 and before the vmcs01's state restored (like set_cr), which means the vmcs01's state restored when vcpu is not in guest mode.
SVM side:
virtual vmentry: set vcpu in guest mode after vmentry emulation is done, which means the emulation code is executed when vcpu is not in guest mode. virtual vmexit: set vcpu exit guest mode after vmexit emulation is
done, which means the emulation code is executed when vcpu is in guest mode.

Ok, now let us take a look at current implementation, take hvm_set_cr0 for example: Update nested mode when (vcpu_in_guestmode && !vmswitch_in_progress). Otherwise, update L1's paging mode:

        if ( !nestedhvm_vmswitch_in_progress(v) &&
nestedhvm_vcpu_in_guestmode(v) )
            paging_update_nestedmode(v); else
            paging_update_paging_modes(v);

virtual vmentry:
Expected result: nested mode is being updated. Current result in SVM:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mode is updated. Wrong.
Current result in VMX:
vcpu_in_guestmode and vmswitch_in_progress : L1's paging
mode is updated. Wrong.

Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mode is updated. Correct.
Current result in VMX:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mod is updated. Correct

From the above result, we can see the vmswitch_in_progress is actually take effect not vcpu_guest_mode. The original code doesn't consider the paging mode changed during vmentry/vmexit emulation. This seems wrong to me, because paging mode changing happens in real world.

Here is the result with my patch: Update nested mode when vcpu_in_guestmode. Otherwise, update L1's paging mode:
if (nestedhvm_vcpu_in_guestmode(v) )
paging_update_nestedmode(v); else paging_update_paging_modes(v);
virtual vmentry:
Expected result: nested mode is being updated.
Current result in SVM:
!vcpu_in_guestmode: L1's paging mode is updated. Wrong.
Current result in VMX: vcpu_in_guestmode : Nested paging mode is updated. Correct.
Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode: Nested paging mode is updated. Wrong.
Current result in VMX: !vcpu_in_guestmode: L1's paging mod is
updated. Correct
From the above, we can see the problem is that the way to distinguish the vmentry and vmexit in SVM and VMX side is different. Since I am not familiar the SVM, so i am not sure whether the usage of vcpu_in_guestmode in SVM is right or wrong. But in VMX side, once the vmcs is changed, then the vcpu_in_guestmode is changed too which we think is following hardware's behavior.

Quoted 2 lines

Also, I think I found another issue that the paging mode cannot be tracked correctly with current way or with my patch. Need more time to investigate.

Ok. The issue is that if the paging state is changed via vmwrite (L1 writes L2's vmcs to change paging mode directly) which is unaware to L0. And hypervisor cannot set the right nested paging mode during virtual vmentry. So we need to update nest mode unconditionally for each virtual vmentry.

Quoted 16 lines
Quoted 5 lines

This patch breaks both vmentry and vmexit emulation for SVM. The vmentry breakage comes with l1-hypervisor using shadow-paging.

Quoted 7 lines

During vmexit emulation hvm_set_cr0 and hvm_set_cr4 are called to restore cr0 and cr4 for the l1 guest. With this patch the paging mode for the l2 guest is updated rather for the l1 guest.

I think this patch also breaks the case where l2 guest wants to set cr0 or cr4 and l1-hypervisor does not intercept cr0/cr4 and l1-hypervisor uses shadow-paging. This may also count for VMX.

For this case, am I missing something? If yes, please correct me.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

This is just from reading the code. As I said, I do not have a setup to verify this, unfortunately.

Best regards,
Yang

Best regards,
Yang

#11 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

In reply to Egger, Christoph

Zhang, Yang Z wrote on 2013-12-24:

Quoted 139 lines

Zhang, Yang Z wrote on 2013-12-23:

Quoted 82 lines

Egger, Christoph wrote on 2013-12-18:

Quoted 24 lines · Yang Z
Quoted 7 lines

Jan Beulich wrote on 2013-12-18:

Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Quoted 6 lines
Quoted 3 lines

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

Actually, I asked him help to review the first patch. Since Christoph thought

the first patch may break AMD. So I hope he can help to review the first patch to see whether I am wrong.

Quoted 6 lines
Quoted 6 lines

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to

go in).

Quoted 1 line
Quoted 9 lines
Quoted 1 line

Yes, the three patches are independent.

I have looked through code.

vcpu is in guestmode till the vmentry/vmexit emulation is done. In SVM the vcpu guestmode changes right before setting nv_vmswitch_in_progress to 0 when the vmentry/vmexit emulation was successfull (there is a bunch of error-checking).

After checking the SVM logic, I find the basic usage of vcpu_in/exitk_guestmode of VMX side is different from that of SVM side:
VMX side:
virtual vmentry: set vcpu in guestmode after vmcs switched to vmcs02.
This happed at the beginning of vmentry which means the whole vmentry emulation code is executed when vcpu is in guest mode.
virtual vmexit: set vcpu exit guestmode after vmcs switched to vmcs01.
Also, this action occurred just after sync vmcs02 to vmcs12 and before the vmcs01's state restored (like set_cr), which means the vmcs01's state restored when vcpu is not in guest mode.
SVM side:
virtual vmentry: set vcpu in guest mode after vmentry emulation is done, which means the emulation code is executed when vcpu is not in guest mode. virtual vmexit: set vcpu exit guest mode after vmexit emulation is
done, which means the emulation code is executed when vcpu is in guest mode.

Ok, now let us take a look at current implementation, take hvm_set_cr0 for example: Update nested mode when (vcpu_in_guestmode && !vmswitch_in_progress). Otherwise, update L1's paging mode:

        if ( !nestedhvm_vmswitch_in_progress(v) &&

nestedhvm_vcpu_in_guestmode(v) )
paging_update_nestedmode(v); else paging_update_paging_modes(v); virtual vmentry:
Expected result: nested mode is being updated. Current result in SVM:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mode is updated. Wrong.
Current result in VMX:
vcpu_in_guestmode and vmswitch_in_progress : L1's paging
mode is updated. Wrong.

Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mode is updated. Correct.
Current result in VMX:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mod is updated. Correct

From the above result, we can see the vmswitch_in_progress is actually take effect not vcpu_guest_mode. The original code doesn't consider the paging mode changed during vmentry/vmexit emulation. This seems wrong to me, because paging mode changing happens in real world.

Quoted 16 lines

Here is the result with my patch: Update nested mode when vcpu_in_guestmode. Otherwise, update L1's paging mode:
if (nestedhvm_vcpu_in_guestmode(v) )
paging_update_nestedmode(v); else paging_update_paging_modes(v); virtual vmentry:
Expected result: nested mode is being updated. Current result in SVM:
!vcpu_in_guestmode: L1's paging mode is updated. Wrong. Current result in VMX: vcpu_in_guestmode : Nested paging mode is updated. Correct.
Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode: Nested paging mode is updated. Wrong. Current result in VMX: !vcpu_in_guestmode: L1's paging
mod

is

Quoted 11 lines

updated. Correct
From the above, we can see the problem is that the way to distinguish the vmentry and vmexit in SVM and VMX side is different. Since I am not familiar the SVM, so i am not sure whether the usage of vcpu_in_guestmode in SVM is right or wrong. But in VMX side, once the vmcs is changed, then the vcpu_in_guestmode is changed too which we think is following hardware's behavior.

Also, I think I found another issue that the paging mode cannot be tracked correctly with current way or with my patch. Need more time to

investigate.

Ok. The issue is that if the paging state is changed via vmwrite (L1
writes L2's vmcs to change paging mode directly) which is unaware to
L0. And hypervisor cannot set the right nested paging mode during
virtual vmentry. So we need to update nest mode unconditionally for each virtual vmentry.

Quoted 21 lines
Quoted 5 lines

This patch breaks both vmentry and vmexit emulation for SVM. The vmentry breakage comes with l1-hypervisor using shadow-paging.

Quoted 7 lines

During vmexit emulation hvm_set_cr0 and hvm_set_cr4 are called to restore cr0 and cr4 for the l1 guest. With this patch the paging mode for the l2 guest is updated rather for the l1 guest.

I think this patch also breaks the case where l2 guest wants to set cr0 or cr4 and l1-hypervisor does not intercept cr0/cr4 and l1-hypervisor uses shadow-paging. This may also count for VMX.

For this case, am I missing something? If yes, please correct me.

Quoted 4 lines

This is just from reading the code. As I said, I do not have a setup to verify this, unfortunately.

Quoted 8 lines
Quoted 3 lines

Best regards,
Yang

Best regards,
Yang

Any comments ?

Best regards,
Yang

#12 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 134 lines
Quoted 1 line
Quoted 1 line · Yang Z

Zhang, Yang Z wrote on 2013-12-24:

Quoted 111 lines

Zhang, Yang Z wrote on 2013-12-23:

Quoted 82 lines

Egger, Christoph wrote on 2013-12-18:

Quoted 24 lines · Yang Z
Quoted 7 lines

Jan Beulich wrote on 2013-12-18:

Quoted 6 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Quoted 6 lines
Quoted 3 lines

Furthermore, while you ack-ed this patch (which isn't really VMX specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

Actually, I asked him help to review the first patch. Since Christoph thought

the first patch may break AMD. So I hope he can help to review the first patch to see whether I am wrong.

Quoted 6 lines
Quoted 6 lines

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to

go in).

Quoted 1 line
Quoted 9 lines
Quoted 1 line

Yes, the three patches are independent.

I have looked through code.

vcpu is in guestmode till the vmentry/vmexit emulation is done. In SVM the vcpu guestmode changes right before setting nv_vmswitch_in_progress to 0 when the vmentry/vmexit emulation was successfull (there is a bunch of error-checking).

After checking the SVM logic, I find the basic usage of vcpu_in/exitk_guestmode of VMX side is different from that of SVM side:
VMX side:
virtual vmentry: set vcpu in guestmode after vmcs switched to vmcs02.
This happed at the beginning of vmentry which means the whole vmentry emulation code is executed when vcpu is in guest mode.
virtual vmexit: set vcpu exit guestmode after vmcs switched to vmcs01.
Also, this action occurred just after sync vmcs02 to vmcs12 and before the vmcs01's state restored (like set_cr), which means the vmcs01's state restored when vcpu is not in guest mode.
SVM side:
virtual vmentry: set vcpu in guest mode after vmentry emulation is done, which means the emulation code is executed when vcpu is not in guest mode. virtual vmexit: set vcpu exit guest mode after vmexit emulation is
done, which means the emulation code is executed when vcpu is in guest mode.

Ok, now let us take a look at current implementation, take hvm_set_cr0 for example: Update nested mode when (vcpu_in_guestmode && !vmswitch_in_progress). Otherwise, update L1's paging mode:

        if ( !nestedhvm_vmswitch_in_progress(v) &&

nestedhvm_vcpu_in_guestmode(v) )
paging_update_nestedmode(v); else paging_update_paging_modes(v); virtual vmentry:
Expected result: nested mode is being updated. Current result in SVM:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mode is updated. Wrong.
Current result in VMX:
vcpu_in_guestmode and vmswitch_in_progress : L1's paging
mode is updated. Wrong.

Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mode is updated. Correct.
Current result in VMX:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging
mod is updated. Correct

From the above result, we can see the vmswitch_in_progress is actually take effect not vcpu_guest_mode. The original code doesn't consider the paging mode changed during vmentry/vmexit emulation. This seems wrong to me, because paging mode changing happens in real world.

Quoted 16 lines

Here is the result with my patch: Update nested mode when vcpu_in_guestmode. Otherwise, update L1's paging mode:
if (nestedhvm_vcpu_in_guestmode(v) )
paging_update_nestedmode(v); else paging_update_paging_modes(v); virtual vmentry:
Expected result: nested mode is being updated. Current result in SVM:
!vcpu_in_guestmode: L1's paging mode is updated. Wrong. Current result in VMX: vcpu_in_guestmode : Nested paging mode is updated. Correct.
Virtual vmexit:
Expected result: L1's paging mode is updated. Current result in SVM:
vcpu_in_guestmode: Nested paging mode is updated. Wrong. Current result in VMX: !vcpu_in_guestmode: L1's paging
mod

is

Quoted 11 lines

updated. Correct
From the above, we can see the problem is that the way to distinguish the vmentry and vmexit in SVM and VMX side is different. Since I am not familiar the SVM, so i am not sure whether the usage of vcpu_in_guestmode in SVM is right or wrong. But in VMX side, once the vmcs is changed, then the vcpu_in_guestmode is changed too which we think is following hardware's behavior.

Also, I think I found another issue that the paging mode cannot be tracked correctly with current way or with my patch. Need more time to

Quoted 6 lines

investigate.

Ok. The issue is that if the paging state is changed via vmwrite (L1 writes L2's vmcs to change paging mode directly) which is unaware to L0. And hypervisor cannot set the right nested paging mode during virtual vmentry. So we need to update nest mode unconditionally for each

virtual vmentry.

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

This patch breaks both vmentry and vmexit emulation for SVM. The vmentry breakage comes with l1-hypervisor using shadow-paging.

During vmexit emulation hvm_set_cr0 and hvm_set_cr4 are called to restore cr0 and cr4 for the l1 guest. With this patch the paging mode for the l2 guest is updated rather for the l1 guest.

I think this patch also breaks the case where l2 guest wants to set cr0 or cr4 and l1-hypervisor does not intercept cr0/cr4 and l1-hypervisor uses shadow-paging. This may also count for VMX.

Quoted 7 lines
Quoted 5 lines
Quoted 5 lines

For this case, am I missing something? If yes, please correct me.

Quoted 3 lines

This is just from reading the code. As I said, I do not have a setup to verify this, unfortunately.

Any comments ?

Considering Christoph's comments and reservations, if you can't alone deal with this I think you should work with the AMD people to eliminate or address his concerns.

Jan

#13 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Jan Beulich wrote on 2014-01-14:

Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Yang Z

Zhang, Yang Z wrote on 2013-12-24:

Any comments ?

Considering Christoph's comments and reservations, if you can't alone deal with this I think you should work with the AMD people to eliminate or address his concerns.

Yes. But the problem puzzled me is that Christoph said nested SVM works well w/o my patch which I cannot understand. Because according my analysis in previous thread, it also buggy in AMD side. But if they really solved the issue in their side, I wonder how they fix it. Perhaps I can use the same solution in VMX side without touch the common code.

Christoph, can you help to check it? thanks.

Quoted 1 line

Jan

Best regards,
Yang

#14 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 11 lines · Yang Z

Jan Beulich wrote on 2014-01-14:

Quoted 9 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line · Yang Z

Zhang, Yang Z wrote on 2013-12-24:

Any comments ?

Considering Christoph's comments and reservations, if you can't alone deal with this I think you should work with the AMD people to eliminate or address his concerns.

Quoted 7 lines

Yes. But the problem puzzled me is that Christoph said nested SVM works well w/o my patch which I cannot understand. Because according my analysis in previous thread, it also buggy in AMD side. But if they really solved the issue in their side, I wonder how they fix it. Perhaps I can use the same solution in VMX side without touch the common code.

Christoph, can you help to check it? thanks.

The fix I mentioned solves the vmswitch problem on AMD side. The page mode problem you discovered is a seperate issue for both SVM and VMX that needs to be addressed.

Christoph

#15 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Egger, Christoph wrote on 2014-01-20:

Quoted 20 lines · Yang Z
Quoted 2 lines

Jan Beulich wrote on 2014-01-14:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 14.01.14 at 03:33, "Zhang, Yang Z" <[email protected]>

Quoted 16 lines · wrote:
Quoted 8 lines
Quoted 3 lines

Zhang, Yang Z wrote on 2013-12-24:

Any comments ?

Considering Christoph's comments and reservations, if you can't alone deal with this I think you should work with the AMD people to eliminate or address his concerns.

Yes. But the problem puzzled me is that Christoph said nested SVM works well w/o my patch which I cannot understand. Because according my analysis in previous thread, it also buggy in AMD side. But if they really solved the issue in their side, I wonder how they fix it. Perhaps I can use the same solution in VMX side without touch the common code.

Quoted 3 lines
Quoted 1 line

Christoph, can you help to check it? thanks.

The fix I mentioned solves the vmswitch problem on AMD side.

But the current code is buggy with your fixing even in AMD side, see below scenario:
virtual vmentry:
Expected result: nested mode is being updated.
Current result in SVM:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging mode is updated. Wrong.

I cannot understand why you said it is working.

Quoted 4 lines

The page mode problem you discovered is a seperate issue for both SVM and VMX that needs to be addressed.

Christoph

Best regards,
Yang

#16 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 25 lines · Yang Z

Egger, Christoph wrote on 2014-01-20:

Quoted 20 lines · Yang Z
Quoted 2 lines

Jan Beulich wrote on 2014-01-14:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 14.01.14 at 03:33, "Zhang, Yang Z" <[email protected]>

Quoted 16 lines · wrote:
Quoted 8 lines
Quoted 3 lines

Zhang, Yang Z wrote on 2013-12-24:

Any comments ?

Considering Christoph's comments and reservations, if you can't alone deal with this I think you should work with the AMD people to eliminate or address his concerns.

Yes. But the problem puzzled me is that Christoph said nested SVM works well w/o my patch which I cannot understand. Because according my analysis in previous thread, it also buggy in AMD side. But if they really solved the issue in their side, I wonder how they fix it. Perhaps I can use the same solution in VMX side without touch the common code.

Quoted 3 lines
Quoted 1 line

Christoph, can you help to check it? thanks.

The fix I mentioned solves the vmswitch problem on AMD side.

Quoted 7 lines

But the current code is buggy with your fixing even in AMD side, see below scenario:
virtual vmentry:
Expected result: nested mode is being updated.
Current result in SVM:
!vcpu_in_guestmode and vmswitch_in_progress: L1's paging mode is updated. Wrong.

I cannot understand why you said it is working.

This page mode problem you discovered that needs to be addressed for both SVM and VMX.

The fix I am saying is working solves the problem of emulating an MMIO instruction which is finished in the softirq while an interrupt can cause a vmswitch during instruction emulation.

We are talking about two different issues. One is fixed on AMD side and one not.

Christoph

#17 lore raw

Re: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

In reply to Jan Beulich

Hi Jan:
Usually I ack one for a series of patch. This one is probably different: It appears as a series of patch, but it seems they look like quit independent. But you are correct, the 1st one is not VMX only stuff. The 3rd one appears to be harmless to me, that you may take seperately.
Thx Eddie

-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Wednesday, December 18, 2013 6:08 PM
To: Dong, Eddie; Zhang, Yang Z
Cc: Christoph Egger; xen-devel
Subject: RE: [PATCH 1/3] Nested VMX: update nested paging mode when vmswitch is in progress

Quoted 2 lines
Quoted 1 line
Quoted 1 line · Eddie

Acked by Eddie Dong <[email protected]>

As long as Christoph's reservations wrt SVM aren't being addressed/ eliminated, I don't think we can apply this patch.

Furthermore, while you ack-ed this patch (which isn't really VMX
specific) and patch 3, you didn't ack patch 2, but you also didn't indicate anything that's possibly wrong with it.

And finally, with patch 1 needing to be left out for the moment, I'd like to have confirmation that all three patches can be applied independently (i.e. with the current state of things only patch 3 is ready to go in).

Jan

author
#18 lore raw

PATCH 2/3 VMX, apicv: Set "NMI-window exiting" for NMI

In reply to Yang Zhang

From: Yang Zhang <[email protected]>

Enable NMI-window exiting if interrupt is blocked by NMI under apicv enabled platform.

---
 xen/arch/x86/hvm/vmx/intr.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/intr.c +4 -3
index 7757910..8507432 100644
@@ -252,10 +252,11 @@ void vmx_intr_assist(void)
         intblk = hvm_interrupt_blocked(v, intack);
         if ( cpu_has_vmx_virtual_intr_delivery )
         {
-            /* Set "Interrupt-window exiting" for ExtINT */
+            /* Set "Interrupt-window exiting" for ExtINT and NMI. */
             if ( (intblk != hvm_intblk_none) &&
-                 ( (intack.source == hvm_intsrc_pic) ||
-                 ( intack.source == hvm_intsrc_vector) ) )
+                 (intack.source == hvm_intsrc_pic ||
+                  intack.source == hvm_intsrc_vector ||
+                  intack.source == hvm_intsrc_nmi) )
             {
                 enable_intr_window(v, intack);
                 goto out;
Signature · 1 line
1.7.1
#19 lore raw

Re: [PATCH 2/3] VMX, apicv: Set "NMI-window exiting" for NMI

Zhang, Yang Z wrote on 2013-12-12:

Quoted 5 lines

From: Yang Zhang <[email protected]>

Enable NMI-window exiting if interrupt is blocked by NMI under apicv enabled platform.

Hi Jun,

Can you help to review this patch? Thanks.

Quoted 12 lines
---
 xen/arch/x86/hvm/vmx/intr.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/intr.c +0 -0
index 7757910..8507432 100644 --- a/xen/arch/x86/hvm/vmx/intr.c +++

b/xen/arch/x86/hvm/vmx/intr.c @@ -252,10 +252,11 @@ void vmx_intr_assist(void)

         intblk = hvm_interrupt_blocked(v, intack);
         if ( cpu_has_vmx_virtual_intr_delivery )
         {
xen/arch/x86/hvm/vmx/intr.c +0 -1
-            /* Set "Interrupt-window exiting" for ExtINT */

xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 262

Quoted 10 lines
xen/arch/x86/hvm/vmx/intr.c +4 -2
+            /* Set "Interrupt-window exiting" for ExtINT and NMI. */
             if ( (intblk != hvm_intblk_none) &&
-                 ( (intack.source == hvm_intsrc_pic) ||
-                 ( intack.source == hvm_intsrc_vector) ) )
+                 (intack.source == hvm_intsrc_pic ||
+                  intack.source == hvm_intsrc_vector ||
+                  intack.source == hvm_intsrc_nmi) )
             {
                 enable_intr_window(v, intack);
                 goto out;

Best regards,
Yang

#21 lore raw

Re: [PATCH 2/3] VMX, apicv: Set "NMI-window exiting" for NMI

Andrew Cooper wrote on 2014-01-08:

Quoted 9 lines · Yang Z
Quoted 8 lines

Zhang, Yang Z wrote on 2013-12-12:

Quoted 5 lines

From: Yang Zhang <[email protected]>

Enable NMI-window exiting if interrupt is blocked by NMI under apicv enabled platform.

Hi Jun,

Quoted 7 lines
Quoted 1 line

Can you help to review this patch? Thanks.

Also committed earlier today
(http://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=185e83591ce42
0e0 b004646b55c5e4783e388531)

~Andrew

I see it. Thanks for your remainder.

Best regards,
Yang

#22 lore raw

Re: [PATCH 2/3] VMX, apicv: Set "NMI-window exiting" for NMI

In reply to Yang Zhang

Zhang, Yang Z wrote on 2014-01-08:

Quoted 10 lines

Zhang, Yang Z wrote on 2013-12-12:

Quoted 5 lines

From: Yang Zhang <[email protected]>

Enable NMI-window exiting if interrupt is blocked by NMI under apicv enabled platform.

Hi Jun,

Can you help to review this patch? Thanks.

Sorry. It already been committed earlier today.

Quoted 26 lines
Quoted 14 lines
---
 xen/arch/x86/hvm/vmx/intr.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-) diff --git

a/xen/arch/x86/hvm/vmx/intr.c b/xen/arch/x86/hvm/vmx/intr.c index 7757910..8507432 100644 --- a/xen/arch/x86/hvm/vmx/intr.c +++ b/xen/arch/x86/hvm/vmx/intr.c @@ -252,10 +252,11 @@ void vmx_intr_assist(void)

         intblk = hvm_interrupt_blocked(v, intack);
         if ( cpu_has_vmx_virtual_intr_delivery )
         {
xen/arch/x86/hvm/vmx/intr.c +1 -1
-            /* Set "Interrupt-window exiting" for ExtINT */
+            /* Set "Interrupt-window exiting" for ExtINT and NMI.

xen/arch/x86/hvm/vmx/intr.c void vmx_intr_assist(void) · line 262

Quoted 10 lines
xen/arch/x86/hvm/vmx/intr.c +4 -2
+ */
             if ( (intblk != hvm_intblk_none) &&
-                 ( (intack.source == hvm_intsrc_pic) ||
-                 ( intack.source == hvm_intsrc_vector) ) )
+                 (intack.source == hvm_intsrc_pic ||
+                  intack.source == hvm_intsrc_vector ||
+                  intack.source == hvm_intsrc_nmi) )
             {
                 enable_intr_window(v, intack);
                 goto out;
Quoted 3 lines

Best regards,
Yang

Best regards,
Yang

author
#23 lore raw

PATCH 3/3 Nested VMX: Setup the virtual NMI exiting info

In reply to Yang Zhang

From: Yang Zhang <[email protected]>

When inject a virtual nmi exit to L1, hypervisor need to set the virtual vmcs with right vaule which is missing in current Xen.

---
 xen/arch/x86/hvm/vmx/vvmx.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
index 0daad79..41db52b 100644
@@ -1293,6 +1293,12 @@ static void sync_exception_state(struct vcpu *v)
                     nvmx->intr.error_code);
         break;
     case X86_EVENTTYPE_NMI:
+        __set_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_REASON,
+                    EXIT_REASON_EXCEPTION_NMI);
+        __set_vvmcs(nvcpu->nv_vvmcx, EXIT_QUALIFICATION, 0);
+        __set_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_INTR_INFO,
+                    nvmx->intr.intr_info);
+        break;
     default:
         gdprintk(XENLOG_ERR, "Exception state %lx not handled\n",
                nvmx->intr.intr_info); 
Signature · 1 line
1.7.1
#24 lore raw

Re: [PATCH 3/3] Nested VMX: Setup the virtual NMI exiting info

Acked by Eddie Dong <[email protected]>

-----Original Message-----
From: Zhang, Yang Z
Sent: Thursday, December 12, 2013 10:07 AM
To: [email protected]
Cc: [email protected]; Dong, Eddie; Zhang, Yang Z
Subject: [PATCH 3/3] Nested VMX: Setup the virtual NMI exiting info

From: Yang Zhang <[email protected]>

When inject a virtual nmi exit to L1, hypervisor need to set the virtual vmcs with right vaule which is missing in current Xen.

---
 xen/arch/x86/hvm/vmx/vvmx.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
index 0daad79..41db52b 100644
@@ -1293,6 +1293,12 @@ static void sync_exception_state(struct vcpu *v)
                     nvmx->intr.error_code);
         break;
     case X86_EVENTTYPE_NMI:
+        __set_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_REASON,
+                    EXIT_REASON_EXCEPTION_NMI);
+        __set_vvmcs(nvcpu->nv_vvmcx, EXIT_QUALIFICATION, 0);
+        __set_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_INTR_INFO,
+                    nvmx->intr.intr_info);
+        break;
     default:
         gdprintk(XENLOG_ERR, "Exception state %lx not handled\n",
                nvmx->intr.intr_info); 
Signature · 1 line
1.7.1
#25 lore raw
In reply to Yang Zhang

Hi, eddie,

Can you help to review the patches?

Best regards,
Yang

Quoted 23 lines

-----Original Message-----
From: Zhang, Yang Z
Sent: Thursday, December 12, 2013 10:07 AM
To: [email protected]
Cc: [email protected]; Dong, Eddie; Zhang, Yang Z
Subject: [PATCH 0/3] some nested vmx fixing to hyper-v

From: Yang Zhang <[email protected]>

This series patches fix some issues which i encountered when boot L1 hyper-v.

This patch fixed RHEL6 guest installation problem with L1 hyper-v:
Nested VMX: update nested paging mode when vmswitch is in progress

The two fixing SMP hyper-v boot issue:
VMX,apicv: Set "NMI-window exiting" for NMI Nested VMX: Setup the virtual NMI exiting info:

Yang Zhang (3):
Nested VMX: update nested paging mode when vmswitch is in progress VMX,apicv: Set "NMI-window exiting" for NMI
Nested VMX: Setup the virtual NMI exiting info

Quoted 4 lines
 xen/arch/x86/hvm/hvm.c      |    4 ++--
 xen/arch/x86/hvm/vmx/intr.c |    7 ++++---
 xen/arch/x86/hvm/vmx/vvmx.c |    6 ++++++
 3 files changed, 12 insertions(+), 5 deletions(-)

From: Yang Zhang <[email protected]>

virtual vmentry will change paging related stucture, so corrensponding nested mode need to be updated which is missing currently.

---
 xen/arch/x86/hvm/hvm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

This patch fixed RHEL6 guest installation problem with L1 hyper-v.

xen/arch/x86/hvm/hvm.c +2 -2
index 69f7e74..1f62e00 100644
@@ -1925,7 +1925,7 @@ int hvm_set_cr0(unsigned long value)
     hvm_update_cr(v, 0, value);
 
     if ( (value ^ old_value) & X86_CR0_PG ) {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);
@@ -2014,7 +2014,7 @@ int hvm_set_cr4(unsigned long value)
           (X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE | X86_CR4_SMEP)) ||
          (!(value & X86_CR4_PCIDE) && (old_cr & X86_CR4_PCIDE)) )
     {
-        if ( !nestedhvm_vmswitch_in_progress(v) && nestedhvm_vcpu_in_guestmode(v) )
+        if ( nestedhvm_vcpu_in_guestmode(v) )
             paging_update_nestedmode(v);
         else
             paging_update_paging_modes(v);

--
1.7.1

From: Yang Zhang <[email protected]>

Enable NMI-window exiting if interrupt is blocked by NMI under apicv enabled platform.

---
 xen/arch/x86/hvm/vmx/intr.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/vmx/intr.c +4 -3
index 7757910..8507432 100644
@@ -252,10 +252,11 @@ void vmx_intr_assist(void)
         intblk = hvm_interrupt_blocked(v, intack);
         if ( cpu_has_vmx_virtual_intr_delivery )
         {
-            /* Set "Interrupt-window exiting" for ExtINT */
+            /* Set "Interrupt-window exiting" for ExtINT and NMI. */
             if ( (intblk != hvm_intblk_none) &&
-                 ( (intack.source == hvm_intsrc_pic) ||
-                 ( intack.source == hvm_intsrc_vector) ) )
+                 (intack.source == hvm_intsrc_pic ||
+                  intack.source == hvm_intsrc_vector ||
+                  intack.source == hvm_intsrc_nmi) )
             {
                 enable_intr_window(v, intack);
                 goto out;

--
1.7.1

From: Yang Zhang <[email protected]>

When inject a virtual nmi exit to L1, hypervisor need to set the virtual vmcs with right vaule which is missing in current Xen.

---
 xen/arch/x86/hvm/vmx/vvmx.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
xen/arch/x86/hvm/vmx/vvmx.c +6 -0
index 0daad79..41db52b 100644
@@ -1293,6 +1293,12 @@ static void sync_exception_state(struct vcpu *v)
                     nvmx->intr.error_code);
         break;
     case X86_EVENTTYPE_NMI:
+        __set_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_REASON,
+                    EXIT_REASON_EXCEPTION_NMI);
+        __set_vvmcs(nvcpu->nv_vvmcx, EXIT_QUALIFICATION, 0);
+        __set_vvmcs(nvcpu->nv_vvmcx, VM_EXIT_INTR_INFO,
+                    nvmx->intr.intr_info);
+        break;
     default:
         gdprintk(XENLOG_ERR, "Exception state %lx not handled\n",
                nvmx->intr.intr_info);

--
1.7.1

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel