diff mbox series

[22/26] KVM: x86: asi: Stabilize CR3 when potentially accessing with ASI

Message ID 20240712-asi-rfc-24-v1-22-144b319a40d8@google.com (mailing list archive)
State New, archived
Headers show
Series Address Space Isolation (ASI) 2024 | expand

Commit Message

Brendan Jackman July 12, 2024, 5 p.m. UTC
nested_vmx_check_vmentry_hw() does a VM Enter as a "dry run" to check
the VMCS. It's important that we VM Exit back into the correct CR3 in
order to avoid going out of sync with ASI state. Under ASI, CR3 is
unstable even when interrupts are disabled, except
a) during the ASI critical section and
b) when the address space is unrestricted. We can take advantage of case
b) here to make sure the VM Enter is safe.

Signed-off-by: Brendan Jackman <jackmanb@google.com>
---
 arch/x86/kvm/vmx/nested.c | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index d05ddf751491..ffca468f8197 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -3147,6 +3147,14 @@  static int nested_vmx_check_vmentry_hw(struct kvm_vcpu *vcpu)
 	 */
 	vmcs_writel(GUEST_RFLAGS, 0);
 
+	/*
+	 * Stabilize CR3 to ensure the VM Exit returns to the correct address
+	 * space. This is costly; at the expense of complexity it could be
+	 * optimized away by instead doing an asi_enter() to create an ASI
+	 * critical section, in the case that we are currently restricted.
+	 */
+	asi_exit();
+
 	cr3 = __get_current_cr3_fast();
 	if (unlikely(cr3 != vmx->loaded_vmcs->host_state.cr3)) {
 		vmcs_writel(HOST_CR3, cr3);