nVMX: Fixes to run Xen as L1
cover nVMX: Fixes to run Xen as L1
Minor changes to enable Xen as a L1 hypervisor.
Tested with a Haswell host, Xen-4.3 L1 and debian6 L2
Bandan Das (3):
KVM: nVMX: Advertise support for interrupt acknowledgement
KVM: nVMX: Ack and write vector info to intr_info if L1 asks us to
KVM: nVMX: check for null vmcs12 when L1 does invept
arch/x86/kvm/irq.c | 1 + arch/x86/kvm/vmx.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/3 KVM: nVMX: Advertise support for interrupt acknowledgement
Some Type 1 hypervisors such as XEN won't enable VMX without it present
--- arch/x86/kvm/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/x86/kvm/vmx.c +2 -1
@@ -2273,7 +2273,8 @@ static __init void nested_vmx_setup_ctls_msrs(void) nested_vmx_pinbased_ctls_high &= ~PIN_BASED_VMX_PREEMPTION_TIMER ; } nested_vmx_exit_ctls_high |= (VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR | -VM_EXIT_LOAD_IA32_EFER |VM_EXIT_SAVE_IA32_EFER ); +VM_EXIT_LOAD_IA32_EFER |VM_EXIT_SAVE_IA32_EFER | +VM_EXIT_ACK_INTR_ON_EXIT );/* entry controls */ rdmsr(MSR_IA32_VMX_ENTRY_CTLS,
Signature · 1 line
1.8.3.1
Re: [PATCH 1/3] KVM: nVMX: Advertise support for interrupt acknowledgement
Quoted 13 lines · Bandan Das
Some Type 1 hypervisors such as XEN won't enable VMX without it present
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/kvm/vmx.c +0
-0
arch/x86/kvm/vmx.c static __init void nested_vmx_setup_ctls_msrs(void) · line 2280
Quoted 9 lines
arch/x86/kvm/vmx.c +2
-1@@ -2273,7 +2273,8 @@ static __init void nested_vmx_setup_ctls_msrs(void) nested_vmx_pinbased_ctls_high &= ~PIN_BASED_VMX_PREEMPTION_TIMER ; } nested_vmx_exit_ctls_high |= (VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR | -VM_EXIT_LOAD_IA32_EFER |VM_EXIT_SAVE_IA32_EFER ); +VM_EXIT_LOAD_IA32_EFER |VM_EXIT_SAVE_IA32_EFER | +VM_EXIT_ACK_INTR_ON_EXIT );/* entry controls */ rdmsr(MSR_IA32_VMX_ENTRY_CTLS,
Shouldn't this come after patch 2?
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 1/3] KVM: nVMX: Advertise support for interrupt acknowledgement
Quoted 20 lines · Jan Kiszka
Quoted 19 lines · Bandan Das
Some Type 1 hypervisors such as XEN won't enable VMX without it present
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/x86/kvm/vmx.c +2
-1@@ -2273,7 +2273,8 @@ static __init void nested_vmx_setup_ctls_msrs(void) nested_vmx_pinbased_ctls_high &= ~PIN_BASED_VMX_PREEMPTION_TIMER ; } nested_vmx_exit_ctls_high |= (VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR | -VM_EXIT_LOAD_IA32_EFER |VM_EXIT_SAVE_IA32_EFER ); +VM_EXIT_LOAD_IA32_EFER |VM_EXIT_SAVE_IA32_EFER | +VM_EXIT_ACK_INTR_ON_EXIT );
Quoted 5 lines
arch/x86/kvm/vmx.c static __init void nested_vmx_setup_ctls_msrs(void) · line 2280
Quoted 3 lines
arch/x86/kvm/vmx.c +0
-0/* entry controls */ rdmsr(MSR_IA32_VMX_ENTRY_CTLS,Shouldn't this come after patch 2?
Right, that makes sense. Will fix in v2.
Quoted 1 line
Jan
PATCH 2/3 KVM: nVMX: Ack and write vector info to intr_info if L1 asks us to
In reply to Bandan Das--- arch/x86/kvm/irq.c | 1 + arch/x86/kvm/vmx.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)
arch/x86/kvm/irq.c +1 -0
@@ -113,6 +113,7 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)return kvm_get_apic_interrupt (v);/* APIC */ } +EXPORT_SYMBOL_GPL (kvm_cpu_get_interrupt);void kvm_inject_pending_timer_irqs (struct kvm_vcpu *vcpu) {
arch/x86/kvm/vmx.c +17 -0
@@ -4491,6 +4491,16 @@ static bool nested_exit_on_intr(struct kvm_vcpu *vcpu)PIN_BASED_EXT_INTR_MASK ; } +/* +* In nested virtualization, check if L1 has set +* VM_EXIT_ACK_INTR_ON_EXIT +*/ +static bool nested_exit_intr_ack_set (struct kvm_vcpu *vcpu) +{ +return get_vmcs12 (vcpu)->vm_exit_controls & +VM_EXIT_ACK_INTR_ON_EXIT ; +} +static bool nested_exit_on_nmi (struct kvm_vcpu *vcpu) { return get_vmcs12(vcpu)->pin_based_vm_exec_control &
@@ -8448,6 +8458,13 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,prepare_vmcs12 (vcpu, vmcs12, exit_reason, exit_intr_info, exit_qualification); +if ((exit_reason ==EXIT_REASON_EXTERNAL_INTERRUPT ) + &&nested_exit_intr_ack_set (vcpu)) { +int irq =kvm_cpu_get_interrupt (vcpu); + vmcs12->vm_exit_intr_info = irq | +INTR_INFO_VALID_MASK |INTR_TYPE_EXT_INTR ; + } + trace_kvm_nested_vmexit_inject(vmcs12->vm_exit_reason, vmcs12->exit_qualification, vmcs12->idt_vectoring_info_field,
Signature · 1 line
1.8.3.1
Re: [PATCH 2/3] KVM: nVMX: Ack and write vector info to intr_info if L1 asks us to
Commit description is missing.
Quoted 23 lines · Bandan Das
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/irq.c | 1 + arch/x86/kvm/vmx.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)arch/x86/kvm/irq.c +1
-0@@ -113,6 +113,7 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)return kvm_get_apic_interrupt (v);/* APIC */ } +EXPORT_SYMBOL_GPL (kvm_cpu_get_interrupt);void kvm_inject_pending_timer_irqs (struct kvm_vcpu *vcpu) {arch/x86/kvm/vmx.c +0
-0
arch/x86/kvm/vmx.c static bool nested_exit_on_intr(struct kvm_vcpu *vcpu) · line 4496
Quoted 6 lines
arch/x86/kvm/vmx.c +3
-0@@ -4491,6 +4491,16 @@ static bool nested_exit_on_intr(struct kvm_vcpu *vcpu)PIN_BASED_EXT_INTR_MASK ; } +/* +* In nested virtualization, check if L1 has set +* VM_EXIT_ACK_INTR_ON_EXIT
This comment does not really contribute much information compared to the code below.
Quoted 15 lines
arch/x86/kvm/vmx.c +7
-0+*/ +static bool nested_exit_intr_ack_set (struct kvm_vcpu *vcpu) +{ +return get_vmcs12 (vcpu)->vm_exit_controls & +VM_EXIT_ACK_INTR_ON_EXIT ; +} +static bool nested_exit_on_nmi (struct kvm_vcpu *vcpu) { return get_vmcs12(vcpu)->pin_based_vm_exec_control &@@ -8448,6 +8458,13 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,prepare_vmcs12 (vcpu, vmcs12, exit_reason, exit_intr_info, exit_qualification);
arch/x86/kvm/vmx.c static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, · line 8470
Quoted 10 lines
arch/x86/kvm/vmx.c +7
-0+if ((exit_reason ==EXIT_REASON_EXTERNAL_INTERRUPT ) + &&nested_exit_intr_ack_set (vcpu)) { +int irq =kvm_cpu_get_interrupt (vcpu); + vmcs12->vm_exit_intr_info = irq | +INTR_INFO_VALID_MASK |INTR_TYPE_EXT_INTR ; + } + trace_kvm_nested_vmexit_inject(vmcs12->vm_exit_reason, vmcs12->exit_qualification, vmcs12->idt_vectoring_info_field,
Looks correct. What about adding a corresponding unit test kvm-unit-tests/x86/vmx_tests.c)? I would highly recommend this.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 2/3] KVM: nVMX: Ack and write vector info to intr_info if L1 asks us to
Quoted 50 lines · Jan Kiszka
Commit description is missing.
Quoted 23 lines · Bandan Das
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/irq.c | 1 + arch/x86/kvm/vmx.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+)arch/x86/kvm/irq.c +1
-0@@ -113,6 +113,7 @@ int kvm_cpu_get_interrupt(struct kvm_vcpu *v)return kvm_get_apic_interrupt (v);/* APIC */ } +EXPORT_SYMBOL_GPL (kvm_cpu_get_interrupt);void kvm_inject_pending_timer_irqs (struct kvm_vcpu *vcpu) {arch/x86/kvm/vmx.c +0
-0arch/x86/kvm/vmx.c static bool nested_exit_on_intr(struct kvm_vcpu *vcpu) · line 4496
Quoted 6 lines
arch/x86/kvm/vmx.c +3
-0@@ -4491,6 +4491,16 @@ static bool nested_exit_on_intr(struct kvm_vcpu *vcpu)PIN_BASED_EXT_INTR_MASK ; } +/* +* In nested virtualization, check if L1 has set +* VM_EXIT_ACK_INTR_ON_EXIT This comment does not really contribute much information compared to the code below.
Quoted 14 lines
arch/x86/kvm/vmx.c +7
-0+*/ +static bool nested_exit_intr_ack_set (struct kvm_vcpu *vcpu) +{ +return get_vmcs12 (vcpu)->vm_exit_controls & +VM_EXIT_ACK_INTR_ON_EXIT ; +} +static bool nested_exit_on_nmi (struct kvm_vcpu *vcpu) { return get_vmcs12(vcpu)->pin_based_vm_exec_control &@@ -8448,6 +8458,13 @@ static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason,prepare_vmcs12 (vcpu, vmcs12, exit_reason, exit_intr_info, exit_qualification);
Quoted 14 lines
arch/x86/kvm/vmx.c static void nested_vmx_vmexit(struct kvm_vcpu *vcpu, u32 exit_reason, · line 8470
Quoted 11 lines
arch/x86/kvm/vmx.c +7
-0+if ((exit_reason ==EXIT_REASON_EXTERNAL_INTERRUPT ) + &&nested_exit_intr_ack_set (vcpu)) { +int irq =kvm_cpu_get_interrupt (vcpu); + vmcs12->vm_exit_intr_info = irq | +INTR_INFO_VALID_MASK |INTR_TYPE_EXT_INTR ; + } + trace_kvm_nested_vmexit_inject(vmcs12->vm_exit_reason, vmcs12->exit_qualification, vmcs12->idt_vectoring_info_field,Looks correct. What about adding a corresponding unit test
kvm-unit-tests/x86/vmx_tests.c)? I would highly recommend this.
Thanks for pointing this out, I will take a look.
Quoted 1 line
Jan
PATCH 3/3 KVM: nVMX: check for null vmcs12 when L1 does invept
In reply to Bandan DasSome L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
arch/x86/kvm/vmx.c +3 -2
@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);
Signature · 1 line
1.8.3.1
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
Jan
Quoted 23 lines
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/vmx.c +3
-2@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);
Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE Corporate Competence Center Embedded Linux
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Note that I based this on what we currently do for context invalidation - static inline void ept_sync_context(u64 eptp)
{
if (enable_ept) {
if (cpu_has_vmx_invept_context())
__invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0);
else
ept_sync_global();
}
}Seemed easier and cleaner than having a cached eptp after vmcs12 is long gone :)
If you prefer, I can modify the commit message to reflect this.
Quoted 25 lines
Jan
Quoted 23 lines
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/vmx.c +3
-2@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 8 lines · Bandan Das
Quoted 6 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Quoted 7 lines
Quoted 2 lines
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Yes, "may". So we are implementing undefined behavior in order to please a broken hypervisor that relies on it? Then please state this in the patch and probably also inform Xen about their issue.
Quoted 11 lines
Note that I based this on what we currently do for context invalidation - static inline void
ept_sync_context(u64 eptp){ if (enable_ept) { if (cpu_has_vmx_invept_context()) __invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0); else ept_sync_global(); } }
Don't get your point. This test is about testing for the CPU support context invalidating, then falling back to global invalidation if there is no support.
Jan
Quoted 31 lines
Seemed easier and cleaner than having a cached eptp after vmcs12 is long gone :)
If you prefer, I can modify the commit message to reflect this.
Quoted 25 lines
Jan
Quoted 23 lines
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/vmx.c +3
-2@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Bandan Das
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
Quoted 8 lines
Quoted 4 lines
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Yes, "may". So we are implementing undefined behavior in order to please a broken hypervisor that relies on it? Then please state this in the patch and probably also inform Xen about their issue.
Why undefined behavior ? We don't do anything specific for the single context invalidation case ianyway .e If the eptp matches what vmcs12 has, single context invalidation does fall though to the global invalidation case already. All this change does is add the "L1 calls invept after vmclear and before vmptrld" to the list of cases to fall though to global invalidation since nvmx doesn't have any knowledge of the current eptp for this case.
Or do you think we should rethink this approach ?
Quoted 12 lines
Quoted 11 lines
Note that I based this on what we currently do for context invalidation - static inline void
ept_sync_context(u64 eptp){ if (enable_ept) { if (cpu_has_vmx_invept_context()) __invept(VMX_EPT_EXTENT_CONTEXT, eptp, 0); else ept_sync_global(); } }
Quoted 3 lines
Don't get your point. This test is about testing for the CPU support context invalidating, then falling back to global invalidation if there is no support.
Sorry, if this was confusing. All I was trying to say is switching to global invalidation if we can't do single context invalidation for some reason is not unusual.
Thanks,
Bandan
Quoted 33 lines
Jan
Quoted 31 lines
Seemed easier and cleaner than having a cached eptp after vmcs12 is long gone :)
If you prefer, I can modify the commit message to reflect this.
Quoted 25 lines
Jan
Quoted 23 lines
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/vmx.c +3
-2@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 23 lines · Bandan Das
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Bandan Das
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
Quoted 8 lines
Quoted 4 lines
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Yes, "may". So we are implementing undefined behavior in order to please a broken hypervisor that relies on it? Then please state this in the patch and probably also inform Xen about their issue.
Quoted 7 lines
Why undefined behavior ? We don't do anything specific for the single context invalidation case ianyway .e If the eptp matches what vmcs12 has, single context invalidation does fall though to the global invalidation case already. All this change does is add the "L1 calls invept after vmclear and before vmptrld" to the list of cases to fall though to global invalidation since nvmx doesn't have any knowledge of the current eptp for this case.
OK, I think I misunderstood what the guest expects and how we currently achieve this: we do not track the mapping between guest and host eptp, thus cannot properly emulate its behaviour. We therefore need to flush everything.
Quoted 2 lines
Or do you think we should rethink this approach ?
Well, I wonder if we should expose single-context invept support at all.
I'm also wondering if we are returning proper flags on
if ((operand.eptp & eptp_mask) !=
(nested_ept_get_cr3(vcpu) & eptp_mask))
break;Neither nested_vmx_succeed nor nested_vmx_fail* is called if this condition evaluates to true.
Jan
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 40 lines · Jan Kiszka
Quoted 23 lines · Bandan Das
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Bandan Das
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
Quoted 8 lines
Quoted 4 lines
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Yes, "may". So we are implementing undefined behavior in order to please a broken hypervisor that relies on it? Then please state this in the patch and probably also inform Xen about their issue.
Quoted 7 lines
Why undefined behavior ? We don't do anything specific for the single context invalidation case ianyway .e If the eptp matches what vmcs12 has, single context invalidation does fall though to the global invalidation case already. All this change does is add the "L1 calls invept after vmclear and before vmptrld" to the list of cases to fall though to global invalidation since nvmx doesn't have any knowledge of the current eptp for this case.
OK, I think I misunderstood what the guest expects and how we currently achieve this: we do not track the mapping between guest and host eptp, thus cannot properly emulate its behaviour. We therefore need to flush everything.
Quoted 2 lines
Or do you think we should rethink this approach ?
Quoted 7 lines
Well, I wonder if we should expose single-context invept support at all.
I'm also wondering if we are returning proper flags on
if ((operand.eptp & eptp_mask) != (nested_ept_get_cr3(vcpu) & eptp_mask)) break;
That does sound plausible but then we would have to get rid of this little optimization in the code you have quoted above. We would have to flush and sync roots for all invept calls. So, my preference is to keep it.
Quoted 2 lines
Neither
nested_vmx_succeednor nested_vmx_fail* is called if this condition evaluates to true.
It appears we should always call nested_vmx_succeed(). If you are ok, I will send a v2.
Thanks,
Bandan
Quoted 1 line
Jan
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 46 lines · Bandan Das
Quoted 44 lines · Jan Kiszka
Quoted 23 lines · Bandan Das
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Bandan Das
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
Quoted 8 lines
Quoted 4 lines
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Yes, "may". So we are implementing undefined behavior in order to please a broken hypervisor that relies on it? Then please state this in the patch and probably also inform Xen about their issue.
Quoted 7 lines
Why undefined behavior ? We don't do anything specific for the single context invalidation case ianyway .e If the eptp matches what vmcs12 has, single context invalidation does fall though to the global invalidation case already. All this change does is add the "L1 calls invept after vmclear and before vmptrld" to the list of cases to fall though to global invalidation since nvmx doesn't have any knowledge of the current eptp for this case.
OK, I think I misunderstood what the guest expects and how we currently achieve this: we do not track the mapping between guest and host eptp, thus cannot properly emulate its behaviour. We therefore need to flush everything.
Quoted 2 lines
Or do you think we should rethink this approach ?
Well, I wonder if we should expose single-context invept support at all.
I'm also wondering if we are returning proper flags on
Quoted 8 lines
Quoted 3 lines
if ((operand.eptp & eptp_mask) != (nested_ept_get_cr3(vcpu) & eptp_mask)) break;That does sound plausible but then we would have to get rid of this little optimization in the code you have quoted above. We would have to flush and sync roots for all invept calls. So, my preference is to keep it.
Do you have any numbers on how many per-context invept calls we are able to ignore? At least for KVM this is should be 0 as we only flush on changes to the current EPT structures.
Jan
Quoted 11 lines
Quoted 3 lines
Neither
nested_vmx_succeednor nested_vmx_fail* is called if this condition evaluates to true.It appears we should always call
nested_vmx_succeed(). If you are ok, I will send a v2.Thanks,
BandanQuoted 1 line
Jan
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 51 lines · Jan Kiszka
Quoted 50 lines · Bandan Das
Quoted 47 lines · Jan Kiszka
Quoted 23 lines · Bandan Das
Quoted 12 lines · Jan Kiszka
Quoted 11 lines · Bandan Das
Quoted 8 lines · Jan Kiszka
Quoted 4 lines · Bandan Das
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Can we also base this behaviour on a statement in the SDM? But on first glance, I do not find anything like this over there.
Quoted 8 lines
Quoted 4 lines
The SDM has nothing of this sort explicitly mentioned but 28.3.3.1 "Operations that invalidate Cached Mappings" does mention that the instruction may invalidate mappings associated with other EP4TAs (even in single context).
Yes, "may". So we are implementing undefined behavior in order to please a broken hypervisor that relies on it? Then please state this in the patch and probably also inform Xen about their issue.
Quoted 7 lines
Why undefined behavior ? We don't do anything specific for the single context invalidation case ianyway .e If the eptp matches what vmcs12 has, single context invalidation does fall though to the global invalidation case already. All this change does is add the "L1 calls invept after vmclear and before vmptrld" to the list of cases to fall though to global invalidation since nvmx doesn't have any knowledge of the current eptp for this case.
OK, I think I misunderstood what the guest expects and how we currently achieve this: we do not track the mapping between guest and host eptp, thus cannot properly emulate its behaviour. We therefore need to flush everything.
Quoted 2 lines
Or do you think we should rethink this approach ?
Well, I wonder if we should expose single-context invept support at all.
I'm also wondering if we are returning proper flags on
if ((operand.eptp & eptp_mask) != (nested_ept_get_cr3(vcpu) & eptp_mask)) break;
Quoted 8 lines
Quoted 4 lines
That does sound plausible but then we would have to get rid of this little optimization in the code you have quoted above. We would have to flush and sync roots for all invept calls. So, my preference is to keep it.
Do you have any numbers on how many per-context invept calls we are able to ignore? At least for KVM this is should be 0 as we only flush on changes to the current EPT structures.
Just instrumented a Debian L2 bootup under L1 Xen and there were 0 per-context invept calls (with a valid vmcs12). I will spin out a version for testing where we don't advertise single context invept and if everything works, put a comment as to why we are removing support.
Thanks,
Bandan
Quoted 13 lines
Jan
Quoted 11 lines
Quoted 3 lines
Neither
nested_vmx_succeednor nested_vmx_fail* is called if this condition evaluates to true.It appears we should always call
nested_vmx_succeed(). If you are ok, I will send a v2.Thanks,
BandanQuoted 1 line
Jan
Paolo Bonzini
maintainerRe: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
In reply to Bandan DasIl 20/03/2014 04:28, Bandan Das ha scritto:
Quoted 17 lines
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/vmx.c +0
-0@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)
arch/x86/kvm/vmx.c static int handle_invept(struct kvm_vcpu *vcpu) · line 6443
Quoted 10 lines
arch/x86/kvm/vmx.c +3
-2switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);
Please add a /* fall through */ comment as well.
Paolo
Re: [PATCH 3/3] KVM: nVMX: check for null vmcs12 when L1 does invept
Quoted 17 lines · Paolo Bonzini
Il 20/03/2014 04:28, Bandan Das ha scritto:
Quoted 16 lines
Some L1 hypervisors such as Xen seem to be calling invept after vmclear or before vmptrld on L2. In this case, proceed with falling through and syncing roots as a case where context wide invalidation can't be supported
Signed-off-by Bandan Das <[email protected]>--- arch/x86/kvm/vmx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)arch/x86/kvm/vmx.c +0
-0@@ -6435,8 +6435,9 @@ static int handle_invept(struct kvm_vcpu *vcpu)
Quoted 13 lines
arch/x86/kvm/vmx.c static int handle_invept(struct kvm_vcpu *vcpu) · line 6443
Quoted 11 lines
arch/x86/kvm/vmx.c +3
-2switch (type) {case VMX_EPT_EXTENT_CONTEXT : -if ((operand.eptp & eptp_mask) != - (nested_ept_get_cr3 (vcpu) & eptp_mask)) +if (get_vmcs12 (vcpu) && + ((operand.eptp & eptp_mask) != (nested_ept_get_cr3 (vcpu) & + eptp_mask)))break ;case VMX_EPT_EXTENT_GLOBAL :kvm_mmu_sync_roots (vcpu);Please add a /* fall through */ comment as well.
Thanks for reviewing Paolo, will fix in v2.
Quoted 1 line
Paolo