KVM: VMX: Enable Notify VM exit
PATCH v3 1/1 KVM: VMX: Enable Notify VM exit
From: Tao Xu <[email protected]>
There are cases that malicious virtual machines can cause CPU stuck (due to event windows don't open up), e.g., infinite loop in microcode when nested #AC (CVE-2015-5307). No event window means no event (NMI, SMI and IRQ) can be delivered. It leads the CPU to be unavailable to host or other VMs.
VMM can enable notify VM exit that a VM exit generated if no event window occurs in VM non-root mode for a specified amount of time (notify window).
Feature enabling:
- The new vmcs field SECONDARY_EXEC_NOTIFY_VM_EXITING is introduced to enable this feature. VMM can set NOTIFY_WINDOW vmcs field to adjust the expected notify window.
- Expose a module param to configure notify window by admin, which is in unit of crystal clock.
- if notify_window < 0, feature disabled;
- if notify_window >= 0, feature enabled;
- There's a possibility, however small, that a notify VM exit happens with VM_CONTEXT_INVALID set in exit qualification. In this case, the vcpu can no longer run. To avoid killing a well-behaved guest, set notify window as -1 to disable this feature by default.
- It's safe to even set notify window to zero since an internal hardware threshold is added to vmcs.notifiy_window.
VM exit handling:
- Introduce a vcpu state notify_window_exits to records the count of notify VM exits and expose it through the debugfs.
- warn the notify vm exit in kernel log since host can a) get an indication that a guest is potentially malicious and b) rule out (or confirm) notify VM exits as the source of degraded guest performance.
- Notify VM exit can happen incident to delivery of a vector event. Allow it in KVM.
Nested handling
- Nested notify VM exits are not supported yet. Keep the same notify window control in vmcs02 as vmcs01, so that L1 can't escape the restriction of notify VM exits through launching L2 VM.
- When L2 VM is context invalid, synthesize a nested EXIT_REASON_TRIPLE_FAULT to L1 so that L1 won't be killed due to L2's VM_CONTEXT_INVALID happens.
Notify VM exit is defined in latest Intel Architecture Instruction Set Extensions Programming Reference, chapter 9.2.
TODO: Allow to change the window size (to enable the feature) at runtime, which can make it more flexible to do management.
---
Change logs:
v2 -> v3
- add a vcpu state notify_window_exits to record the number of occurence as well as a pr_warn output. (Sean)
- Add the handling in nested VM to prevent L1 bypassing the restriction through launching a L2. (Sean)
- Only kill L2 when L2 VM is context invalid, synthesize a EXIT_REASON_TRIPLE_FAULT to L1 (Sean)
- To ease the current implementation, make module parameter notify_window read-only. (Sean)
- Disable notify window exit by default.
- v2: https://lore.kernel.org/lkml/[email protected]/
v1 -> v2
- Default set notify window to 0, less than 0 to disable.
- Add more description in commit message.
---
--- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/include/asm/vmx.h | 7 ++++ arch/x86/include/asm/vmxfeatures.h | 1 + arch/x86/include/uapi/asm/vmx.h | 4 +- arch/x86/kvm/vmx/capabilities.h | 7 ++++ arch/x86/kvm/vmx/nested.c | 16 +++++++- arch/x86/kvm/vmx/vmx.c | 59 +++++++++++++++++++++++++++++- arch/x86/kvm/x86.c | 3 +- include/uapi/linux/kvm.h | 2 + 9 files changed, 95 insertions(+), 5 deletions(-)
arch/x86/include/asm/kvm_host.h +1 -0
@@ -1281,6 +1281,7 @@ struct kvm_vcpu_stat {u64 directed_yield_attempted;u64 directed_yield_successful;u64 guest_mode; +u64 notify_window_exits; };struct x86_instruction_info ;
arch/x86/include/asm/vmx.h +7 -0
@@ -74,6 +74,7 @@#define SECONDARY_EXEC_TSC_SCALING VMCS_CONTROL_BIT(TSC_SCALING)#define SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE VMCS_CONTROL_BIT(USR_WAIT_PAUSE)#define SECONDARY_EXEC_BUS_LOCK_DETECTION VMCS_CONTROL_BIT(BUS_LOCK_DETECTION) +#define SECONDARY_EXEC_NOTIFY_VM_EXITING VMCS_CONTROL_BIT(NOTIFY_VM_EXITING)#define PIN_BASED_EXT_INTR_MASK VMCS_CONTROL_BIT(INTR_EXITING)#define PIN_BASED_NMI_EXITING VMCS_CONTROL_BIT(NMI_EXITING)
@@ -269,6 +270,7 @@ enum vmcs_field {SECONDARY_VM_EXEC_CONTROL =0x0000401e ,PLE_GAP =0x00004020 ,PLE_WINDOW =0x00004022 , +NOTIFY_WINDOW =0x00004024 ,VM_INSTRUCTION_ERROR =0x00004400 ,VM_EXIT_REASON =0x00004402 , VM_EXIT_INTR_INFO = 0x00004404,
@@ -555,6 +557,11 @@ enum vm_entry_failure_code {#define EPT_VIOLATION_EXECUTABLE (1 << EPT_VIOLATION_EXECUTABLE_BIT)#define EPT_VIOLATION_GVA_TRANSLATED (1 << EPT_VIOLATION_GVA_TRANSLATED_BIT) +/* +* Exit Qualifications for NOTIFY VM EXIT +*/ +#define NOTIFY_VM_CONTEXT_INVALID BIT(0) +/* * VM-instruction error numbers */
arch/x86/include/asm/vmxfeatures.h +1 -0
@@ -84,5 +84,6 @@#define VMX_FEATURE_USR_WAIT_PAUSE ( 2*32+ 26)/* Enable TPAUSE, UMONITOR, UMWAIT in guest */ #define VMX_FEATURE_ENCLV_EXITING ( 2*32+ 28)/* "" VM-Exit on ENCLV (leaf dependent) */ #define VMX_FEATURE_BUS_LOCK_DETECTION ( 2*32+ 30)/* "" VM-Exit when bus lock caused */ +#define VMX_FEATURE_NOTIFY_VM_EXITING ( 2*32+ 31)/* VM-Exit when no event windows after notify window */ #endif /* _ASM_X86_VMXFEATURES_H */
arch/x86/include/uapi/asm/vmx.h +3 -1
@@ -91,6 +91,7 @@#define EXIT_REASON_UMWAIT 67#define EXIT_REASON_TPAUSE 68#define EXIT_REASON_BUS_LOCK 74 +#define EXIT_REASON_NOTIFY 75#define VMX_EXIT_REASONS \ { EXIT_REASON_EXCEPTION_NMI, "EXCEPTION_NMI" }, \
@@ -153,7 +154,8 @@ { EXIT_REASON_XRSTORS, "XRSTORS" }, \ { EXIT_REASON_UMWAIT, "UMWAIT" }, \ { EXIT_REASON_TPAUSE, "TPAUSE" }, \ - { EXIT_REASON_BUS_LOCK, "BUS_LOCK" } + { EXIT_REASON_BUS_LOCK, "BUS_LOCK" }, \ + { EXIT_REASON_NOTIFY, "NOTIFY"} #define VMX_EXIT_REASON_FLAGS \ { VMX_EXIT_REASONS_FAILED_VMENTRY, "FAILED_VMENTRY" }
arch/x86/kvm/vmx/capabilities.h +7 -0
@@ -14,6 +14,7 @@ extern bool __read_mostly enable_unrestricted_guest;extern bool __read_mostly enable_ept_ad_bits;extern bool __read_mostly enable_pml;extern int __read_mostly pt_mode; +extern int __read_mostly notify_window;#define PT_MODE_SYSTEM 0#define PT_MODE_HOST_GUEST 1
@@ -417,4 +418,10 @@ static inline u64 vmx_supported_debugctl(void) return debugctl; } +static inline bool cpu_has_notify_vm_exiting (void ) +{ +return vmcs_config.cpu_based_2nd_exec_ctrl & +SECONDARY_EXEC_NOTIFY_VM_EXITING ; +} +#endif /* __KVM_X86_VMX_CAPS_H */
arch/x86/kvm/vmx/nested.c +15 -1
@@ -2177,6 +2177,9 @@ static void prepare_vmcs02_constant_state(struct vcpu_vmx *vmx)if (cpu_has_vmx_encls_vmexit ())vmcs_write64 (ENCLS_EXITING_BITMAP ,INVALID_GPA ); +if (notify_window >=0 ) +vmcs_write32 (NOTIFY_WINDOW , notify_window); +/* * Set the MSR load/store lists to match L0's settings. Only the * addresses are constant (for vmcs02), the counts can change based
@@ -4213,8 +4216,16 @@ static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,/* * Transfer the event that L0 or L1 may wanted to inject into * L2 to IDT_VECTORING_INFO_FIELD. +* L0 will synthensize a nested TRIPLE_FAULT to kill L2 when +* notify VM exit occurred in L2 and NOTIFY_VM_CONTEXT_INVALID is +* set in exit qualification. In this case, if notify VM exit +* occurred incident to delivery of a vectored event, the IDT +* vectoring info are recorded in VMCS. Drop the pending event +* in vmcs12, otherwise L1 VMM will exit to userspace with +* internal error due to delivery event. */ -vmcs12_save_pending_event (vcpu, vmcs12); +if (to_vmx (vcpu)->exit_reason.basic !=EXIT_REASON_NOTIFY ) +vmcs12_save_pending_event (vcpu, vmcs12);/* * According to spec, there's no need to store the guest's
@@ -6080,6 +6091,9 @@ static bool nested_vmx_l1_wants_exit(struct kvm_vcpu *vcpu, SECONDARY_EXEC_ENABLE_USR_WAIT_PAUSE);case EXIT_REASON_ENCLS :return nested_vmx_exit_handled_encls (vcpu, vmcs12); +case EXIT_REASON_NOTIFY : +return nested_cpu_has2 (vmcs12, +SECONDARY_EXEC_NOTIFY_VM_EXITING );default :return true; }
arch/x86/kvm/vmx/vmx.c +57 -2
107 lines not on this page · raw message
arch/x86/kvm/x86.c +2 -1
@@ -289,7 +289,8 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = {STATS_DESC_COUNTER (VCPU , nested_run),STATS_DESC_COUNTER (VCPU , directed_yield_attempted),STATS_DESC_COUNTER (VCPU , directed_yield_successful), -STATS_DESC_ICOUNTER (VCPU , guest_mode) +STATS_DESC_ICOUNTER (VCPU , guest_mode), + STATS_DESC_COUNTER(VCPU, notify_window_exits), }; const struct kvm_stats_header kvm_vcpu_stats_header = {
include/uapi/linux/kvm.h +2 -0
@@ -280,6 +280,8 @@ struct kvm_xen_exit {#define KVM_INTERNAL_ERROR_DELIVERY_EV 3/* Encounter unexpected vm-exit reason */ #define KVM_INTERNAL_ERROR_UNEXPECTED_EXIT_REASON 4 +/* Encounter notify vm-exit */ +#define KVM_INTERNAL_ERROR_NO_EVENT_WINDOW 5/* Flags that describe what fields in emulation_failure hold valid data. */ #define KVM_INTERNAL_ERROR_EMULATION_FLAG_INSTRUCTION_BYTES (1ULL << 0)
Signature · 1 line
2.17.1
Paolo Bonzini
maintainerQuoted 8 lines · Chenyi Qiang
Nested handling
- Nested notify VM exits are not supported yet. Keep the same notify window control in vmcs02 as vmcs01, so that L1 can't escape the restriction of notify VM exits through launching L2 VM.
- When L2 VM is context invalid, synthesize a nestedEXIT_REASON_TRIPLE_FAULTto L1 so that L1 won't be killed due to L2'sVM_CONTEXT_INVALIDhappens.
Quoted 5 lines
Notify VM exit is defined in latest Intel Architecture Instruction Set Extensions Programming Reference, chapter 9.2.
TODO: Allow to change the window size (to enable the feature) at runtime, which can make it more flexible to do management.
I only have a couple questions, any changes in response to the question I can do myself.
arch/x86/kvm/vmx/nested.c static void prepare_vmcs02_constant_state(struct vcpu_vmx *vmx) · line 2181
Quoted 10 lines
arch/x86/kvm/vmx/nested.c +2
-0@@ -2177,6 +2177,9 @@ static void prepare_vmcs02_constant_state(struct vcpu_vmx *vmx)if (cpu_has_vmx_encls_vmexit ())vmcs_write64 (ENCLS_EXITING_BITMAP ,INVALID_GPA ); +if (notify_window >=0 ) +vmcs_write32 (NOTIFY_WINDOW , notify_window);
Is a value of 0 valid? Should it be changed to the recommended value of 128000 in hardware_setup()?
arch/x86/kvm/vmx/nested.c static bool nested_vmx_l1_wants_exit(struct kvm_vcpu *vcpu, · line 6096
Quoted 3 lines
arch/x86/kvm/vmx/nested.c +3
-0+case EXIT_REASON_NOTIFY : +return nested_cpu_has2 (vmcs12, +SECONDARY_EXEC_NOTIFY_VM_EXITING );
This should be "return false" since you don't expose the secondary control to L1 (meaning, it will never be set).
arch/x86/kvm/vmx/nested.c static void prepare_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12, · line 4228
Quoted 11 lines
arch/x86/kvm/vmx/nested.c +9
-1+* L0 will synthensize a nested TRIPLE_FAULT to kill L2 when +* notify VM exit occurred in L2 and NOTIFY_VM_CONTEXT_INVALID is +* set in exit qualification. In this case, if notify VM exit +* occurred incident to delivery of a vectored event, the IDT +* vectoring info are recorded in VMCS. Drop the pending event +* in vmcs12, otherwise L1 VMM will exit to userspace with +* internal error due to delivery event. */ -vmcs12_save_pending_event (vcpu, vmcs12); +if (to_vmx (vcpu)->exit_reason.basic !=EXIT_REASON_NOTIFY ) +vmcs12_save_pending_event (vcpu, vmcs12);
I would prefer to call out the triple fault here:
/*
* Transfer the event that L0 or L1 may have wanted to inject into
* L2 to IDT_VECTORING_INFO_FIELD.
*
* Skip this if the exit is due to a NOTIFY_VM_CONTEXT_INVALID
* exit; in that case, L0 will synthesize a nested TRIPLE_FAULT
* vmexit to kill L2. No IDT vectoring info is recorded for
* triple faults, and __vmx_handle_exit does not expect it. */
if (!(to_vmx(vcpu)->exit_reason.basic == EXIT_REASON_NOTIFY)
&& kvm_test_request(KVM_REQ_TRIPLE_FAULT, vcpu))
vmcs12_save_pending_event(vcpu, vmcs12);
What do you think?
Paolo
Quoted 18 lines · Paolo Bonzini
Quoted 8 lines · Chenyi Qiang
Nested handling
- Nested notify VM exits are not supported yet. Keep the same notify window control in vmcs02 as vmcs01, so that L1 can't escape the restriction of notify VM exits through launching L2 VM.
- When L2 VM is context invalid, synthesize a nestedEXIT_REASON_TRIPLE_FAULTto L1 so that L1 won't be killed due to L2'sVM_CONTEXT_INVALIDhappens.Quoted 5 lines
Notify VM exit is defined in latest Intel Architecture Instruction Set Extensions Programming Reference, chapter 9.2.
TODO: Allow to change the window size (to enable the feature) at runtime, which can make it more flexible to do management.
I only have a couple questions, any changes in response to the question I can do myself.
Quoted 12 lines
arch/x86/kvm/vmx/nested.c static void prepare_vmcs02_constant_state(struct · line 2181
Quoted 10 lines
arch/x86/kvm/vmx/nested.c +2
-0@@ -2177,6 +2177,9 @@ static void prepare_vmcs02_constant_state(struct vcpu_vmx *vmx) if (cpu_has_vmx_encls_vmexit()) vmcs_write64(ENCLS_EXITING_BITMAP, INVALID_GPA); + if (notify_window >= 0) + vmcs_write32(NOTIFY_WINDOW, notify_window);Is a value of 0 valid?
Yes, 0 is valid. That's why there is an internal value to ensure even 0 won't cause false positive
Quoted 9 lines
Should it be changed to the recommended value of
128000 inhardware_setup()?arch/x86/kvm/vmx/nested.c static bool nested_vmx_l1_wants_exit(struct kvm_vcpu *vcpu, · line 6096
Quoted 3 lines
arch/x86/kvm/vmx/nested.c +3
-0+ case EXIT_REASON_NOTIFY: + return nested_cpu_has2(vmcs12, + SECONDARY_EXEC_NOTIFY_VM_EXITING);This should be "return false" since you don't expose the secondary control to L1 (meaning, it will never be set).
Fine with either.
Quoted 25 lines
Quoted 4 lines
arch/x86/kvm/vmx/nested.c +2
-0+ * L0 will synthensize a nested TRIPLE_FAULT to kill L2 when + * notify VM exit occurred in L2 and
NOTIFY_VM_CONTEXT_INVALIDis
+ * set in exit qualification. In this case, if notify VM exitQuoted 8 lines
+ * occurred incident to delivery of a vectored event, the IDT + * vectoring info are recorded in VMCS. Drop the pending event + * in vmcs12, otherwise L1 VMM will exit to userspace with + * internal error due to delivery event.
*/
-vmcs12_save_pending_event(vcpu, vmcs12);
+ if (to_vmx(vcpu)->exit_reason.basic !=EXIT_REASON_NOTIFY) +vmcs12_save_pending_event(vcpu, vmcs12);I would prefer to call out the triple fault here:
/*
* Transfer the event that L0 or L1 may have wanted to
inject into
* L2 toIDT_VECTORING_INFO_FIELD.
*
* Skip this if the exit is due to aNOTIFY_VM_CONTEXT_INVALID
* exit; in that case, L0 will synthesize a nestedTRIPLE_FAULT
* vmexit to kill L2. No IDT vectoring info is
Quoted 8 lines
recorded for
* triple faults, and__vmx_handle_exitdoes not expect
it.
*/
if (!(to_vmx(vcpu)->exit_reason.basic ==EXIT_REASON_NOTIFY)
&&kvm_test_request(KVM_REQ_TRIPLE_FAULT, vcpu))vmcs12_save_pending_event(vcpu, vmcs12);
looks good to me.
Quoted 4 lines
What do you think?
Paolo
Quoted 13 lines · Chenyi Qiang
From: Tao Xu <[email protected]>
There are cases that malicious virtual machines can cause CPU stuck (due to event windows don't open up), e.g., infinite loop in microcode when nested #AC (CVE-2015-5307). No event window means no event (NMI, SMI and IRQ) can be delivered. It leads the CPU to be unavailable to host or other VMs.
VMM can enable notify VM exit that a VM exit generated if no event window occurs in VM non-root mode for a specified amount of time (notify window).
Quoted 14 lines
Feature enabling:
- The new vmcs fieldSECONDARY_EXEC_NOTIFY_VM_EXITINGis introduced to enable this feature. VMM can setNOTIFY_WINDOWvmcs field to adjust the expected notify window.
- Expose a module param to configure notify window by admin, which is in unit of crystal clock.
- ifnotify_window< 0, feature disabled;
- ifnotify_window>= 0, feature enabled;
- There's a possibility, however small, that a notify VM exit happens withVM_CONTEXT_INVALIDset in exit qualification. In this case, the vcpu can no longer run. To avoid killing a well-behaved guest, set notify window as -1 to disable this feature by default.
- It's safe to even set notify window to zero since an internal hardware threshold is added to vmcs.notifiy_window.
What causes a VM_CONTEXT_INVALID VM-exit? How small is this possibility?
Quoted 7 lines
Nested handling
- Nested notify VM exits are not supported yet. Keep the same notify window control in vmcs02 as vmcs01, so that L1 can't escape the restriction of notify VM exits through launching L2 VM.
- When L2 VM is context invalid, synthesize a nestedEXIT_REASON_TRIPLE_FAULTto L1 so that L1 won't be killed due to L2'sVM_CONTEXT_INVALIDhappens.
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Quoted 29 lines · Jim Mattson
Quoted 13 lines · Chenyi Qiang
From: Tao Xu <[email protected]>
There are cases that malicious virtual machines can cause CPU stuck (due to event windows don't open up), e.g., infinite loop in microcode when nested #AC (CVE-2015-5307). No event window means no event (NMI, SMI and IRQ) can be delivered. It leads the CPU to be unavailable to host or other VMs.
VMM can enable notify VM exit that a VM exit generated if no event window occurs in VM non-root mode for a specified amount of time (notify window).
Quoted 14 lines
Feature enabling:
- The new vmcs fieldSECONDARY_EXEC_NOTIFY_VM_EXITINGis introduced to enable this feature. VMM can setNOTIFY_WINDOWvmcs field to adjust the expected notify window.
- Expose a module param to configure notify window by admin, which is in unit of crystal clock.
- ifnotify_window< 0, feature disabled;
- ifnotify_window>= 0, feature enabled;
- There's a possibility, however small, that a notify VM exit happens withVM_CONTEXT_INVALIDset in exit qualification. In this case, the vcpu can no longer run. To avoid killing a well-behaved guest, set notify window as -1 to disable this feature by default.
- It's safe to even set notify window to zero since an internal hardware threshold is added to vmcs.notifiy_window.
Quoted 1 line
What causes a
VM_CONTEXT_INVALIDVM-exit? How small is this possibility?
For now, no case will set VM_CONTEXT_INVALID bit.
In the future, it must be some fatal case that vmcs is corrupted.
Quoted 8 lines
Quoted 7 lines
Nested handling
- Nested notify VM exits are not supported yet. Keep the same notify window control in vmcs02 as vmcs01, so that L1 can't escape the restriction of notify VM exits through launching L2 VM.
- When L2 VM is context invalid, synthesize a nestedEXIT_REASON_TRIPLE_FAULTto L1 so that L1 won't be killed due to L2'sVM_CONTEXT_INVALIDhappens.
Quoted 5 lines
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 10 lines · Xiaoyao Li
Quoted 9 lines · Jim Mattson
Quoted 7 lines · Chenyi Qiang
Nested handling
- Nested notify VM exits are not supported yet. Keep the same notify window control in vmcs02 as vmcs01, so that L1 can't escape the restriction of notify VM exits through launching L2 VM.
- When L2 VM is context invalid, synthesize a nestedEXIT_REASON_TRIPLE_FAULTto L1 so that L1 won't be killed due to L2'sVM_CONTEXT_INVALIDhappens.
Quoted 8 lines
Quoted 5 lines
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
Paolo Bonzini
maintainerQuoted 8 lines · Xiaoyao Li
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Quoted 4 lines
Quoted 2 lines
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
Paolo
Quoted 10 lines · Paolo Bonzini
Quoted 8 lines · Xiaoyao Li
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
Could we synthesize a machine check? I haven't looked in detail at the MCE MSRs, but surely there must be room in there for Intel to reserve some encodings for synthesized machine checks.
Sean Christopherson
maintainerQuoted 15 lines · Jim Mattson
Quoted 14 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
Could we synthesize a machine check? I haven't looked in detail at the MCE MSRs, but surely there must be room in there for Intel to reserve some encodings for synthesized machine checks.
I don't think we have any choice but to synthesize SHUTDOWN until we get more details on the exact semantics of VM_CONTEXT_INVALID. E.g. if GUEST_EFER or any other critical guest field is corrupted, attempting to re-enter the guest, even to (attempt to) inject a machine check, is risking undefined behavior in the guest.
Quoted 22 lines · Sean Christopherson
Quoted 20 lines · Jim Mattson
Quoted 18 lines · Paolo Bonzini
Quoted 8 lines · Xiaoyao Li
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Quoted 6 lines
Quoted 3 lines
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
Quoted 8 lines
Quoted 3 lines
Could we synthesize a machine check? I haven't looked in detail at the MCE MSRs, but surely there must be room in there for Intel to reserve some encodings for synthesized machine checks.
I don't think we have any choice but to synthesize SHUTDOWN until we get more details on the exact semantics of
VM_CONTEXT_INVALID. E.g. ifGUEST_EFERor any other critical guest field is corrupted, attempting to re-enter the guest, even to (attempt to) inject a machine check, is risking undefined behavior in the guest.
Synthesizing shutdown is fine, as long as userspace is notified.
Quoted 9 lines · Paolo Bonzini
Quoted 8 lines · Xiaoyao Li
Quoted 8 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes notify_vm_exit with invalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:
a) if (notify_vm_exit available & notify_vm_exit enabled) {
handle in b)
} else {
report unexpected vm exit reason to userspace;
}b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;
c) no Notify VM Exit related code (e.g. old KVM), it's treated as unsupported exit reason
As long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Quoted 2 lines
Paolo
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;
Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers
&& kvm_vmx_exit_handlers[exit_reason])
return kvm_vmx_exit_handlers[exit_reason](vcpu);
else {
WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason);
kvm_queue_exception(vcpu, UD_VECTOR);
return 1;
}At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with invalid_context, which is malicious to L0 and L1.
If we use triple_fault (i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }
Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.
There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.
Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with exit_qualification passed, then userspace can take the same action like what this patch does in KVM that
- re-enter guest when context_invalid is false;
- stop running the guest if context_invalid is true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)
Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a triple_fault from L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.
3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Do you have any better solution other than above? If no, we need to pick one from above though it cannot make everyone happy.
thanks,
-Xiaoyao
Quoted 123 lines · Xiaoyao Li
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with
exit_qualificationpassed, then userspace can take the same action like what this patch does in KVM that- re-enter guest when
context_invalidis false;
- stop running the guest ifcontext_invalidis true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.
Quoted 7 lines
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a
triple_faultfrom L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.
You are correct on that last point, and I feel that I cannot stress it enough. In a typical environment, the L0 kernel log is only available to the administrator of the L0 host.
Quoted 8 lines
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.
Quoted 5 lines
3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Do you have any better solution other than above? If no, we need to pick one from above though it cannot make everyone happy.
Yes, I believe I have a better solution. We obviously need an API for userspace to synthesize a SHUTDOWN event for a vCPU. In addition, to avoid breaking legacy userspace, the NOTIFY VM-exit should be opt-in.
Quoted 144 lines · Jim Mattson
Quoted 123 lines · Xiaoyao Li
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with
exit_qualificationpassed, then userspace can take the same action like what this patch does in KVM that- re-enter guest when
context_invalidis false;
- stop running the guest ifcontext_invalidis true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.Quoted 7 lines
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a
triple_faultfrom L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.You are correct on that last point, and I feel that I cannot stress it enough. In a typical environment, the L0 kernel log is only available to the administrator of the L0 host.
Quoted 8 lines
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.
Quoted 8 lines
Quoted 5 lines
3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Do you have any better solution other than above? If no, we need to pick one from above though it cannot make everyone happy.
Yes, I believe I have a better solution. We obviously need an API for userspace to synthesize a SHUTDOWN event for a vCPU.
Can you elaborate on it? Do you mean userspace to inject a synthesized SHUTDOWN to guest? If so, I have no idea how it will work.
Quoted 2 lines
In addition, to
avoid breaking legacy userspace, the NOTIFY VM-exit should be opt-in.
Yes, it's designed as opt-in already that the feature is off by default.
Quoted 149 lines · Xiaoyao Li
Quoted 147 lines · Jim Mattson
Quoted 123 lines · Xiaoyao Li
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
Quoted 1 line
I don't like the idea of making things up without notifying userspace that this is fictional. How is my customer running nested VMs supposed to know that L2 didn't actually shutdown, but L0 killed it because the notify window was exceeded? If this information isn't reported to userspace, I have no way of getting the information to the customer.
Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with
exit_qualificationpassed, then userspace can take the same action like what this patch does in KVM that- re-enter guest when
context_invalidis false;
- stop running the guest ifcontext_invalidis true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.Quoted 7 lines
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a
triple_faultfrom L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.You are correct on that last point, and I feel that I cannot stress it enough. In a typical environment, the L0 kernel log is only available to the administrator of the L0 host.
Quoted 11 lines
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Do you have any better solution other than above? If no, we need to pick> >> one from above though it cannot make everyone happy.
Yes, I believe I have a better solution. We obviously need an API for userspace to synthesize a SHUTDOWN event for a vCPU.
Can you elaborate on it? Do you mean userspace to inject a synthesized SHUTDOWN to guest? If so, I have no idea how it will work.
It can probably be implemented as an extension of KVM_SET_VCPU_EVENTS that invokes kvm_make_request(KVM_REQ_TRIPLE_FAULT).
Quoted 152 lines · Jim Mattson
Quoted 151 lines · Xiaoyao Li
Quoted 149 lines · Jim Mattson
Quoted 123 lines · Xiaoyao Li
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
Quoted 7 lines
I don't like the idea of making things up without notifying userspace
that this is fictional. How is my customer running nested VMs supposed
to know that L2 didn't actually shutdown, but L0 killed it because the
notify window was exceeded? If this information isn't reported to
userspace, I have no way of getting the information to the customer.Then, maybe a dedicated software define VM exit for it instead of reusing triple fault?
Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with
exit_qualificationpassed, then userspace can take the same action like what this patch does in KVM that- re-enter guest when
context_invalidis false;
- stop running the guest ifcontext_invalidis true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.Quoted 7 lines
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a
triple_faultfrom L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.You are correct on that last point, and I feel that I cannot stress it enough. In a typical environment, the L0 kernel log is only available to the administrator of the L0 host.
Quoted 12 lines
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Do you have any better solution other than above? If no, we need to pick> >> one from above though it cannot make everyone happy.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Yes, I believe I have a better solution. We obviously need an API for userspace to synthesize a SHUTDOWN event for a vCPU.
Can you elaborate on it? Do you mean userspace to inject a synthesized SHUTDOWN to guest? If so, I have no idea how it will work.
It can probably be implemented as an extension of
KVM_SET_VCPU_EVENTSthat invokeskvm_make_request(KVM_REQ_TRIPLE_FAULT).
Then, you mean
1. notify vm exit from guest;
2. exit to userspace on notify vm exit;
3. a. if context_invalid, inject SHUTDOWN to vcpu from userspace to request KVM_REQ_TRIPLE_FAULT; goto step 4; b. if !context_invalid, re-run vcpu; no step 4 and 5;
4. exit to userspace again with KVM_EXIT_SHUTDOWN due to triple fault;
5. userspace stop running the vcpu/VM
Then why not handle it as KVM_EXIT_SHUTDOWN directly in 3.a ? I don't get the point of userspace to inject TRIPLE_FAULT to KVM.
Quoted 168 lines · Xiaoyao Li
Quoted 152 lines · Jim Mattson
Quoted 151 lines · Xiaoyao Li
Quoted 149 lines · Jim Mattson
Quoted 123 lines · Xiaoyao Li
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
Quoted 11 lines
I don't like the idea of making things up without notifying userspace
that this is fictional. How is my customer running nested VMs supposed
to know that L2 didn't actually shutdown, but L0 killed it because the
notify window was exceeded? If this information isn't reported to
userspace, I have no way of getting the information to the customer.Then, maybe a dedicated software define VM exit for it instead of
reusing triple fault?Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell L2 causes Notify VM exit, even thought Notify VM exit is not exposed to L1.
That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with
exit_qualificationpassed, then userspace can take the same action like what this patch does in KVM that- re-enter guest when
context_invalidis false;
- stop running the guest ifcontext_invalidis true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.Quoted 7 lines
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a
triple_faultfrom L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.You are correct on that last point, and I feel that I cannot stress it enough. In a typical environment, the L0 kernel log is only available to the administrator of the L0 host.
Quoted 12 lines
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Do you have any better solution other than above? If no, we need to pick> >> one from above though it cannot make everyone happy.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Yes, I believe I have a better solution. We obviously need an API for userspace to synthesize a SHUTDOWN event for a vCPU.
Can you elaborate on it? Do you mean userspace to inject a synthesized SHUTDOWN to guest? If so, I have no idea how it will work.
It can probably be implemented as an extension of
KVM_SET_VCPU_EVENTSthat invokeskvm_make_request(KVM_REQ_TRIPLE_FAULT).Then, you mean
1. notify vm exit from guest;
2. exit to userspace on notify vm exit;
3. a. ifcontext_invalid, inject SHUTDOWN to vcpu from userspace to
Quoted 7 lines
request KVM_REQ_TRIPLE_FAULT; goto step 4; b. if !context_invalid, re-run vcpu; no step 4 and 5;4. exit to userspace again with
KVM_EXIT_SHUTDOWNdue to triple fault;
5. userspace stop running the vcpu/VMThen why not handle it as
KVM_EXIT_SHUTDOWNdirectly in 3.a ? I don't get the point of userspace to injectTRIPLE_FAULTto KVM.
Sure, that should work, as long as L0 userspace is notified of the emulation error.
Going back to something you said previously:
Quoted 3 lines
Quoted 1 line
In addition, to avoid breaking legacy userspace, the NOTIFY VM-exit should be opt-in.
Yes, it's designed as opt-in already that the feature is off by default.
I meant that userspace should opt-in, per VM. I believe your design is opt-in by system administrator, host-wide.
Quoted 174 lines · Jim Mattson
Quoted 173 lines · Xiaoyao Li
Quoted 152 lines · Jim Mattson
Quoted 151 lines · Xiaoyao Li
Quoted 149 lines · Jim Mattson
Quoted 123 lines · Xiaoyao Li
Quoted 93 lines · Jim Mattson
Quoted 67 lines · Xiaoyao Li
Quoted 65 lines · Jim Mattson
Quoted 43 lines · Jim Mattson
Quoted 41 lines · Xiaoyao Li
Quoted 13 lines · Paolo Bonzini
Quoted 12 lines · Xiaoyao Li
I don't like the idea of making things up without notifying userspace
that this is fictional. How is my customer running nested VMs supposed
to know that L2 didn't actually shutdown, but L0 killed it because the
notify window was exceeded? If this information isn't reported to
userspace, I have no way of getting the information to the customer.Then, maybe a dedicated software define VM exit for it instead of
reusing triple fault?Quoted 5 lines
Quoted 3 lines
Second thought, we can even just return Notify VM exit to L1 to tell
L2 causes Notify VM exit, even thought Notify VM exit is not exposed
to L1.That might cause NULL pointer dereferences or other nasty occurrences.
IMO, a well written VMM (in L1) should handle it correctly.
L0 KVM reports no Notify VM Exit support to L1, so L1 runs without setting Notify VM exit. If a L2 causes
notify_vm_exitwithinvalid_vm_context, L0 just reflects it to L1. In L1's view, there is no support of Notify VM Exit from VMX MSR capability. Following L1 handler is possible:a) if (notify_vm_exit available & notify_vm_exit enabled) { handle in b) } else { report unexpected vm exit reason to userspace; }b) similar handler like we implement in KVM:
if (!vm_context_invalid) re-enter guest; else report to userspace;Quoted 8 lines
Quoted 6 lines
c) no Notify VM Exit related code (e.g. old KVM), it's treated as
unsupported exit reasonAs long as it belongs to any case above, I think L1 can handle it correctly. Any nasty occurrence should be caused by incorrect handler in L1 VMM, in my opinion.
Please test some common hypervisors (e.g. ESXi and Hyper-V).
I took a look at KVM in Linux v4.9 (one of our more popular guests), and it will not handle this case well:
if (exit_reason < kvm_vmx_max_exit_handlers && kvm_vmx_exit_handlers[exit_reason]) return kvm_vmx_exit_handlers[exit_reason](vcpu); else { WARN_ONCE(1, "vmx: unexpected exit reason 0x%x\n", exit_reason); kvm_queue_exception(vcpu, UD_VECTOR); return 1; }Quoted 7 lines
Quoted 3 lines
At least there's an L1 kernel log message for the first unexpected NOTIFY VM-exit, but after that, there is silence. Just a completely inexplicable #UD in L2, assuming that L2 is resumable at this point.
At least there is a message to tell L1 a notify VM exit is triggered in L2. Yes, the inexplicable #UD won't be hit unless L2 triggers Notify VM exit with
invalid_context, which is malicious to L0 and L1.There is only an L1 kernel log message *the first time*. That's not good enough. And this is just one of the myriad of possible L1 hypervisors.
Quoted 5 lines
If we use
triple_fault(i.e., shutdown), then no info to tell L1 that it's caused by Notify VM exit with invalid context. Triple fault needs to be extended and L1 kernel needs to be enlightened. It doesn't help old guest kernel.Quoted 7 lines
If we use Machine Check, it's somewhat same inexplicable to L2 unless it's enlightened. But it doesn't help old guest kernel.
Anyway, for Notify VM exit with invalid context from L2, I don't see a good solution to tell L1 VMM it's a "Notify VM exit with invalid context from L2" and keep all kinds of L1 VMM happy, especially for those with old kernel versions.
Quoted 4 lines
I agree that there is no way to make every conceivable L1 happy. That's why the information needs to be surfaced to the L0 userspace. I contend that any time L0 kvm violates the architectural specification in its emulation of L1 or L2, the L0 userspace *must* be informed.
We can make the design to exit to userspace on notify vm exit unconditionally with
exit_qualificationpassed, then userspace can take the same action like what this patch does in KVM that- re-enter guest when
context_invalidis false;
- stop running the guest ifcontext_invalidis true; (userspace can
definitely re-enter the guest in this case, but it needs to take the fall on this)Then, for nested case, L0 needs to enable it transparently for L2 if this feature is enabled for L1 guest (the reason as we all agreed that cannot allow L1 to escape just by creating a L2). Then what should KVM do when notify vm exit from L2?
- Exit to L0 userspace on L2's notify vm exit. L0 userspace takes the
same action:
- re-enter if context-invalid is false;
- kill L1 if context-invalid is true; (I don't know if there is any
interface for L0 userspace to kill L2). Then it opens the potential door for malicious user to kill L1 by creating a L2 to trigger fatal notify vm exit. If you guys accept it, we can implement in this way.Quoted 7 lines
in conclusion, we have below solution:
1. Take this patch as is. The drawback is L1 VMM receives a
triple_faultfrom L2 when L2 triggers notify vm exit with invalid context. Neither of L1 VMM, L1 userspace, nor L2 kernel know it's caused due to notify vm exit. There is only kernel log in L0, which seems not accessible for L1 user or L2 guest.You are correct on that last point, and I feel that I cannot stress it enough. In a typical environment, the L0 kernel log is only available to the administrator of the L0 host.
Quoted 12 lines
2. a) Inject notify vm exit back to L1 if L2 triggers notify vm exit with invalid context. The drawback is, old L1 hypervisor is not enlightened of it and maybe misbehave on it.
b) Inject a synthesized SHUTDOWN exit to L1, with additional info to
tell it's caused by fatal notify vm exit from L2. It has the same drawback that old hypervisor has no idea of it and maybe misbehave on it.3. Exit to L0 usersapce unconditionally no matter it's caused from L1 or L2. Then it may open the door for L1 user to kill L1.
Do you have any better solution other than above? If no, we need to pick> >> one from above though it cannot make everyone happy.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Yes, I believe I have a better solution. We obviously need an API for userspace to synthesize a SHUTDOWN event for a vCPU.
Can you elaborate on it? Do you mean userspace to inject a synthesized SHUTDOWN to guest? If so, I have no idea how it will work.
It can probably be implemented as an extension of
KVM_SET_VCPU_EVENTSthat invokeskvm_make_request(KVM_REQ_TRIPLE_FAULT).Then, you mean
1. notify vm exit from guest;
2. exit to userspace on notify vm exit;
3. a. ifcontext_invalid, inject SHUTDOWN to vcpu from userspace torequest KVM_REQ_TRIPLE_FAULT; goto step 4; b. if !context_invalid, re-run vcpu; no step 4 and 5;4. exit to userspace again with
KVM_EXIT_SHUTDOWNdue to triple fault;
5. userspace stop running the vcpu/VM
Quoted 7 lines
Quoted 2 lines
Then why not handle it as
KVM_EXIT_SHUTDOWNdirectly in 3.a ? I don't get the point of userspace to injectTRIPLE_FAULTto KVM.Sure, that should work, as long as L0 userspace is notified of the emulation error.
Going back to something you said previously:
So, after adding the nested handling case, can we summarize the whole working flow as:
1. notify VM exit from guest;
2. a. if !context_invalid, resume vcpu, no further process;
b. if context_invalid, exit to userspace;
3. userspace injects SHUTDOWN event by KVM_SET_VCPU_EVENTS to request KVM_REQ_TRIPLE_FAULT;
4. a. if !is_guest_mode(vcpu), exit to userspace again with KVM_EXIT_SHUTDOWN due to triple fault. L1 shutdown; b. if is_guest_mode(vcpu), synthesize a nested triple fault to L1.
L2 shutdown;
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
In addition, to avoid breaking legacy userspace, the NOTIFY VM-exit should be opt-in.
Yes, it's designed as opt-in already that the feature is off by default.
I meant that userspace should opt-in, per VM. I believe your design is opt-in by system administrator, host-wide.
OK, we will change to the per-VM control.