From: Sriram Nambakam <snambakam@linux.microsoft.com>
To: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [RFC PATCH v2 4/4] KVM: x86: handle VBS VTL call/return via in-kernel plane switch
Date: Mon, 10 Aug 2026 17:31:14 -0700 [thread overview]
Message-ID: <20260811003114.30107-5-snambakam@linux.microsoft.com> (raw)
In-Reply-To: <20260811003114.30107-1-snambakam@linux.microsoft.com>
Service the VBS inter-plane hypercalls in-kernel, with no userspace round
trip, by switching planes:
KVM_HC_VBS_VTL_CALL - the normal plane (0) calls into the secure plane
(1). a0 is the guest-physical address of the
shared calling area; deliver it to the secure
plane's pending VTL return (or mark it pending if
the secure plane is still booting) and switch.
KVM_HC_VBS_VTL_RETURN - the secure plane (>0) hands control back to plane
0, announcing readiness and delivering any call
that arrived while it was booting.
The switch reuses the per-plane scheduling (kvm_vcpu_set_plane_runnable/
stopped + KVM_REQ_PLANE_RESCHED).
---
arch/x86/kvm/x86.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 3b21c72fc9e0..35fbe0776a3e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10562,6 +10562,65 @@ int ____kvm_emulate_hypercall(struct kvm_vcpu *vcpu, int cpl,
vcpu->arch.complete_userspace_io = complete_hypercall;
return 0;
}
+ case KVM_HC_VBS_VTL_CALL: {
+ /*
+ * Runtime VBS call from the normal plane (0) into the secure
+ * plane (1), serviced in-kernel by switching planes. a0 is the
+ * guest-physical address of the shared calling area. If the
+ * secure plane is parked in its VTL return, deliver the GPA as
+ * that return's value now; otherwise mark it pending so the
+ * secure plane picks it up on its first return.
+ */
+ struct kvm_vcpu_common *common = vcpu->common;
+ struct kvm_vcpu *secure;
+
+ if (vcpu->plane_level != 0)
+ break;
+
+ secure = common->vcpus[1];
+ if (!secure)
+ break;
+
+ common->vtl_call_ca = a0;
+ if (common->vtl_plane_ready) {
+ kvm_rax_write_raw(secure, a0);
+ common->vtl_call_pending = false;
+ } else {
+ common->vtl_call_pending = true;
+ }
+
+ kvm_vcpu_set_plane_runnable(secure);
+ kvm_vcpu_set_plane_stopped(vcpu);
+ ret = 0;
+ break;
+ }
+ case KVM_HC_VBS_VTL_RETURN: {
+ /*
+ * The secure plane (>0) hands control back to plane 0. On its
+ * first return it announces readiness; if a call arrived while
+ * it was still booting, deliver that calling-area GPA now and
+ * stay in the secure plane. Otherwise switch back to plane 0.
+ */
+ struct kvm_vcpu_common *common = vcpu->common;
+
+ if (vcpu->plane_level == 0) {
+ ret = -KVM_EPERM;
+ break;
+ }
+
+ common->vtl_plane_ready = true;
+
+ if (common->vtl_call_pending) {
+ common->vtl_call_pending = false;
+ ret = common->vtl_call_ca;
+ break;
+ }
+
+ kvm_vcpu_set_plane_runnable(common->vcpus[0]);
+ kvm_vcpu_set_plane_stopped(vcpu);
+ ret = 0;
+ break;
+ }
case KVM_HC_VM_PLANES_CONFIG:
case KVM_HC_VM_PLANES_ACTIVATE:
/*
--
2.55.0
prev parent reply other threads:[~2026-08-11 0:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 0:31 [RFC PATCH v2 0/4] KVM: VM Planes host support for VBS Sriram Nambakam
2026-08-11 0:31 ` [RFC PATCH v2 1/4] kvm: uapi: reserve VM-plane and VBS hypercall numbers Sriram Nambakam
2026-08-11 0:31 ` [RFC PATCH v2 2/4] KVM: x86: exit VM-plane config/activate hypercalls to userspace Sriram Nambakam
2026-08-11 0:31 ` [RFC PATCH v2 3/4] KVM: x86: add VTL-call state to struct kvm_vcpu_common Sriram Nambakam
2026-08-11 0:31 ` Sriram Nambakam [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260811003114.30107-5-snambakam@linux.microsoft.com \
--to=snambakam@linux.microsoft.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.