[RFC PATCH 46/47] kvm: asi: Do asi_exit() in vcpu_run loop before returning to userspace

Junaid Shahid
2022-02-23T05:29:03Z

From: Ofir Weisse <oweisse@google.com>

For the time being, we switch to the full kernel address space before
returning back to userspace. Once KPTI is also implemented using ASI,
we could potentially also switch to the KPTI address space directly.

Signed-off-by: Ofir Weisse <oweisse@google.com>

---
arch/x86/kvm/x86.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 680725089a18..294f73e9e71e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10148,13 +10148,17 @@ static int vcpu_run(struct kvm_vcpu *vcpu)
srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);
r = xfer_to_guest_mode_handle_work(vcpu);
if (r)
- return r;
+ goto exit;
vcpu->srcu_idx = srcu_read_lock(&kvm->srcu);
}
}

srcu_read_unlock(&kvm->srcu, vcpu->srcu_idx);

+exit:
+ /* TODO(oweisse): trace this exit if we're still within an ASI. */
+ asi_exit();
+
return r;
}

--
2.35.1.473.g83b2b277ed-goog