Skip to contentSkip to conversation

KVM: vmx: hyper-v: don't pass EPT configuration info to vmx_hv_remote_flush_tlb()

PATCH In review Vitaly Kuznetsov 3 participants 7 messages Oct 11, 2018 – Oct 13, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: vmx: hyper-v: don't pass EPT configuration info to vmx_hv_remote_flush_tlb()

I'm observing random crashes in multi-vCPU L2 guests running on KVM on Hyper-V. I bisected the issue to the commit 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support"). Hyper-V TLFS states:

"AddressSpace specifies an address space ID (an EPT PML4 table pointer)"

So apparently, Hyper-V doesn't expect us to pass naked EPTP, only PML4 pointer should be used. Strip off EPT configuration information before calling into vmx_hv_remote_flush_tlb().

Fixes 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support")
---
 arch/x86/kvm/vmx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx.c +5 -1
index 612fd17be635..e665aa7167cf 100644
@@ -1572,8 +1572,12 @@ static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
 		goto out;
 	}
 
+	/*
+	 * FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE hypercall needs the address of the
+	 * base of EPT PML4 table, strip off EPT configuration information.
+	 */
 	ret = hyperv_flush_guest_mapping(
-			to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer);
+			to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer & PAGE_MASK);
 
 out:
 	spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 10 lines · Vitaly Kuznetsov

I'm observing random crashes in multi-vCPU L2 guests running on KVM on Hyper-V. I bisected the issue to the commit 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support"). Hyper-V TLFS states:

"AddressSpace specifies an address space ID (an EPT PML4 table pointer)"

So apparently, Hyper-V doesn't expect us to pass naked EPTP, only PML4 pointer should be used. Strip off EPT configuration information before calling into vmx_hv_remote_flush_tlb().

Hi Vitaly:
: Thanks to fix this. Sorry, I didn't meet the issue..
I think we may just store EPT PML4 table pointer without EPT configuration information
in the ept_pointer field for this case.

arch/x86/kvm/vmx.c +0 -0
index 619307b3e6bb..e316058b41a6 100644
@@ -5379,7 +5379,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu,

unsigned long cr3)

                if (kvm_x86_ops->tlb_remote_flush) {
                        spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
-                       to_vmx(vcpu)->ept_pointer = eptp;
+                       to_vmx(vcpu)->ept_pointer = cr3;
                        to_kvm_vmx(kvm)->ept_pointers_match
                                = EPT_POINTERS_CHECK;
                        spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
Quoted 28 lines
Fixes 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support")
---
 arch/x86/kvm/vmx.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx.c +5 -2
index 612fd17be635..e665aa7167cf 100644
@@ -1572,8 +1572,12 @@ static int vmx_hv_remote_flush_tlb(struct kvm *kvm)
                goto out;
        }
 
+       /*
+        * FLUSH_GUEST_PHYSICAL_ADDRESS_SPACE hypercall needs the address of the
+        * base of EPT PML4 table, strip off EPT configuration information.
+        */
        ret = hyperv_flush_guest_mapping(
-                       to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer);
+                       to_vmx(kvm_get_vcpu(kvm, 0))->ept_pointer & PAGE_MASK);
 
 out:
        spin_unlock(&to_kvm_vmx(kvm)->ept_pointer_lock);
--

2.17.1

Signature · 2 lines
Best regards
Tianyu Lan
#2 lore raw
Quoted 23 lines · Tianyu Lan
Quoted 10 lines · Vitaly Kuznetsov

I'm observing random crashes in multi-vCPU L2 guests running on KVM on Hyper-V. I bisected the issue to the commit 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support"). Hyper-V TLFS states:

"AddressSpace specifies an address space ID (an EPT PML4 table pointer)"

So apparently, Hyper-V doesn't expect us to pass naked EPTP, only PML4 pointer should be used. Strip off EPT configuration information before calling into vmx_hv_remote_flush_tlb().

Hi Vitaly:
: Thanks to fix this. Sorry, I didn't meet the issue..
I think we may just store EPT PML4 table pointer without EPT configuration information
in the ept_pointer field for this case.

arch/x86/kvm/vmx.c +0 -0
index 619307b3e6bb..e316058b41a6 100644

arch/x86/kvm/vmx.c static void vmx_set_cr3(struct kvm_vcpu *vcpu, · line 5383

Quoted 6 lines
arch/x86/kvm/vmx.c +1 -1
@@ -5379,7 +5379,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu,
 unsigned long cr3)
 
                if (kvm_x86_ops->tlb_remote_flush) {
                        spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
-                       to_vmx(vcpu)->ept_pointer = eptp;
+                       to_vmx(vcpu)->ept_pointer = cr3;

True, we can do that (and I even had a version of my patch doing so) but 'ept_pointer' will likely need to be renamed as it's not obvious why vcpu->ept_pointer != eptp.

Alternatively, we can filter lower 12 bits out in hyperv_flush_guest_mapping() but I would rename 'as' parameter to eptp then.

[snip]

Signature · 1 line
Vitaly
#3 lore raw
Quoted 28 lines · Vitaly Kuznetsov
Quoted 25 lines · Tianyu Lan
Quoted 10 lines · Vitaly Kuznetsov

I'm observing random crashes in multi-vCPU L2 guests running on KVM on Hyper-V. I bisected the issue to the commit 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support"). Hyper-V TLFS states:

"AddressSpace specifies an address space ID (an EPT PML4 table pointer)"

So apparently, Hyper-V doesn't expect us to pass naked EPTP, only PML4 pointer should be used. Strip off EPT configuration information before calling into vmx_hv_remote_flush_tlb().

Hi Vitaly:
: Thanks to fix this. Sorry, I didn't meet the issue..
I think we may just store EPT PML4 table pointer without EPT configuration information
in the ept_pointer field for this case.

arch/x86/kvm/vmx.c +0 -0
index 619307b3e6bb..e316058b41a6 100644
@@ -5379,7 +5379,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu,
 unsigned long cr3)
 
Quoted 9 lines

arch/x86/kvm/vmx.c static void vmx_set_cr3(struct kvm_vcpu *vcpu, · line 5383

Quoted 4 lines
arch/x86/kvm/vmx.c +1 -1
                if (kvm_x86_ops->tlb_remote_flush) {
                        spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
-                       to_vmx(vcpu)->ept_pointer = eptp;
+                       to_vmx(vcpu)->ept_pointer = cr3;

True, we can do that (and I even had a version of my patch doing so) but 'ept_pointer' will likely need to be renamed as it's not obvious why vcpu->ept_pointer != eptp.

Yes. that need to rename ept_pointer.

Quoted 3 lines

Alternatively, we can filter lower 12 bits out in hyperv_flush_guest_mapping() but I would rename 'as' parameter to eptp then.

OK. I got it. Thanks.

Signature · 2 lines
Best regards
Tianyu Lan
#4 lore raw
Quoted 39 lines · Tianyu Lan
Quoted 28 lines · Vitaly Kuznetsov
Quoted 25 lines · Tianyu Lan
Quoted 10 lines · Vitaly Kuznetsov

I'm observing random crashes in multi-vCPU L2 guests running on KVM on Hyper-V. I bisected the issue to the commit 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support"). Hyper-V TLFS states:

"AddressSpace specifies an address space ID (an EPT PML4 table pointer)"

So apparently, Hyper-V doesn't expect us to pass naked EPTP, only PML4 pointer should be used. Strip off EPT configuration information before calling into vmx_hv_remote_flush_tlb().

Hi Vitaly:
: Thanks to fix this. Sorry, I didn't meet the issue..
I think we may just store EPT PML4 table pointer without EPT configuration information
in the ept_pointer field for this case.

arch/x86/kvm/vmx.c +0 -0
index 619307b3e6bb..e316058b41a6 100644
@@ -5379,7 +5379,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu,
 unsigned long cr3)
 
Quoted 9 lines

arch/x86/kvm/vmx.c static void vmx_set_cr3(struct kvm_vcpu *vcpu, · line 5383

Quoted 4 lines
arch/x86/kvm/vmx.c +1 -1
                if (kvm_x86_ops->tlb_remote_flush) {
                        spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
-                       to_vmx(vcpu)->ept_pointer = eptp;
+                       to_vmx(vcpu)->ept_pointer = cr3;

True, we can do that (and I even had a version of my patch doing so) but 'ept_pointer' will likely need to be renamed as it's not obvious why vcpu->ept_pointer != eptp.

Quoted 2 lines

Yes. that need to rename ept_pointer.

Honestly, I would prefer to keep more information cached, e.g. if someone needs EPT configuration data later he can easily get it from ept_pointer and by putting raw cr3 there we'll just keep less.

But I don't have a strong opinion, I'll leave it up to the maintainers to tell us how to proceed)

Quoted 5 lines
Quoted 3 lines

Alternatively, we can filter lower 12 bits out in hyperv_flush_guest_mapping() but I would rename 'as' parameter to eptp then.

OK. I got it. Thanks.

Signature · 1 line
Vitaly
#5 lore raw
Quoted 42 lines · Vitaly Kuznetsov
Quoted 39 lines · Tianyu Lan
Quoted 37 lines · Vitaly Kuznetsov
Quoted 23 lines · Tianyu Lan
Quoted 10 lines · Vitaly Kuznetsov

I'm observing random crashes in multi-vCPU L2 guests running on KVM on Hyper-V. I bisected the issue to the commit 877ad952be3d ("KVM: vmx: Add tlb_remote_flush callback support"). Hyper-V TLFS states:

"AddressSpace specifies an address space ID (an EPT PML4 table pointer)"

So apparently, Hyper-V doesn't expect us to pass naked EPTP, only PML4 pointer should be used. Strip off EPT configuration information before calling into vmx_hv_remote_flush_tlb().

Hi Vitaly:
: Thanks to fix this. Sorry, I didn't meet the issue..
I think we may just store EPT PML4 table pointer without EPT configuration information
in the ept_pointer field for this case.

arch/x86/kvm/vmx.c +0 -0
index 619307b3e6bb..e316058b41a6 100644

arch/x86/kvm/vmx.c static void vmx_set_cr3(struct kvm_vcpu *vcpu, · line 5383

Quoted 6 lines
arch/x86/kvm/vmx.c +1 -1
@@ -5379,7 +5379,7 @@ static void vmx_set_cr3(struct kvm_vcpu *vcpu,
 unsigned long cr3)
 
                if (kvm_x86_ops->tlb_remote_flush) {
                        spin_lock(&to_kvm_vmx(kvm)->ept_pointer_lock);
-                       to_vmx(vcpu)->ept_pointer = eptp;
+                       to_vmx(vcpu)->ept_pointer = cr3;

True, we can do that (and I even had a version of my patch doing so) but 'ept_pointer' will likely need to be renamed as it's not obvious why vcpu->ept_pointer != eptp.

Quoted 7 lines
Quoted 2 lines

Yes. that need to rename ept_pointer.

Honestly, I would prefer to keep more information cached, e.g. if someone needs EPT configuration data later he can easily get it from ept_pointer and by putting raw cr3 there we'll just keep less.

Yes, that makes sense.

Signature · 2 lines
Best regards
Tianyu Lan
maintainer
#6 lore raw
In reply to Vitaly Kuznetsov
Quoted 9 lines · Vitaly Kuznetsov
Quoted 2 lines

Yes. that need to rename ept_pointer.

Honestly, I would prefer to keep more information cached, e.g. if someone needs EPT configuration data later he can easily get it from ept_pointer and by putting raw cr3 there we'll just keep less.

But I don't have a strong opinion, I'll leave it up to the maintainers to tell us how to proceed)

I have (re)applied your patch (I had queued it and tested it earlier, now I've added it back).

Paolo