From: Ryan Afranji <afranji@google.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org
Cc: sagis@google.com, bp@alien8.de, chao.p.peng@linux.intel.com,
dave.hansen@linux.intel.com, dmatlack@google.com,
erdemaktas@google.com, isaku.yamahata@intel.com,
kai.huang@intel.com, mingo@redhat.com, pbonzini@redhat.com,
seanjc@google.com, tglx@linutronix.de, zhi.wang.linux@gmail.com,
ackerleytng@google.com, andrew.jones@linux.dev,
david@redhat.com, hpa@zytor.com,
kirill.shutemov@linux.intel.com,
linux-kselftest@vger.kernel.org, tabba@google.com,
vannapurve@google.com, yan.y.zhao@intel.com,
rick.p.edgecombe@intel.com, Ryan Afranji <afranji@google.com>
Subject: [RFC PATCH v2 03/10] KVM: TDX: Add base implementation for tdx_vm_move_enc_context_from
Date: Wed, 11 Jun 2025 21:16:30 +0000 [thread overview]
Message-ID: <c55644ec81c22e7239d52f97e744eb4bafeccac3.1749672978.git.afranji@google.com> (raw)
In-Reply-To: <cover.1749672978.git.afranji@google.com>
From: Sagi Shahar <sagis@google.com>
This should mostly match the logic in sev_vm_move_enc_context_from.
Signed-off-by: Sagi Shahar <sagis@google.com>
Signed-off-by: Ryan Afranji <afranji@google.com>
---
arch/x86/kvm/vmx/main.c | 12 +++++++++++-
arch/x86/kvm/vmx/tdx.c | 24 ++++++++++++++++++++++++
arch/x86/kvm/vmx/x86_ops.h | 1 +
3 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
index d1e02e567b57..125af25fd09a 100644
--- a/arch/x86/kvm/vmx/main.c
+++ b/arch/x86/kvm/vmx/main.c
@@ -879,6 +879,14 @@ static int vt_gmem_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn)
return 0;
}
+static int vt_move_enc_context_from(struct kvm *kvm, struct kvm *source_kvm)
+{
+ if (!is_td(kvm))
+ return -ENOTTY;
+
+ return tdx_vm_move_enc_context_from(kvm, source_kvm);
+}
+
#define vt_op(name) vt_##name
#define vt_op_tdx_only(name) vt_##name
#else /* CONFIG_KVM_INTEL_TDX */
@@ -1044,7 +1052,9 @@ struct kvm_x86_ops vt_x86_ops __initdata = {
.mem_enc_ioctl = vt_op_tdx_only(mem_enc_ioctl),
.vcpu_mem_enc_ioctl = vt_op_tdx_only(vcpu_mem_enc_ioctl),
- .private_max_mapping_level = vt_op_tdx_only(gmem_private_max_mapping_level)
+ .private_max_mapping_level = vt_op_tdx_only(gmem_private_max_mapping_level),
+
+ .vm_move_enc_context_from = vt_move_enc_context_from
};
struct kvm_x86_init_ops vt_init_ops __initdata = {
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index b952bc673271..07583a11d6e3 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -626,6 +626,7 @@ int tdx_vm_init(struct kvm *kvm)
kvm->arch.has_protected_state = true;
kvm->arch.has_private_mem = true;
kvm->arch.disabled_quirks |= KVM_X86_QUIRK_IGNORE_GUEST_PAT;
+ kvm->arch.use_vm_enc_ctxt_op = true;
/*
* Because guest TD is protected, VMM can't parse the instruction in TD.
@@ -3524,3 +3525,26 @@ int __init tdx_bringup(void)
enable_tdx = 0;
return 0;
}
+
+static __always_inline bool tdx_finalized(struct kvm *kvm)
+{
+ struct kvm_tdx *tdx_kvm = to_kvm_tdx(kvm);
+
+ return tdx_kvm->state == TD_STATE_RUNNABLE;
+}
+
+static int tdx_migrate_from(struct kvm *dst, struct kvm *src)
+{
+ return -EINVAL;
+}
+
+int tdx_vm_move_enc_context_from(struct kvm *kvm, struct kvm *src_kvm)
+{
+ if (!is_td(kvm) || !is_td(src_kvm))
+ return -EINVAL;
+
+ if (tdx_finalized(kvm) || !tdx_finalized(src_kvm))
+ return -EINVAL;
+
+ return tdx_migrate_from(kvm, src_kvm);
+}
diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h
index b4596f651232..001f1540a560 100644
--- a/arch/x86/kvm/vmx/x86_ops.h
+++ b/arch/x86/kvm/vmx/x86_ops.h
@@ -164,6 +164,7 @@ void tdx_flush_tlb_current(struct kvm_vcpu *vcpu);
void tdx_flush_tlb_all(struct kvm_vcpu *vcpu);
void tdx_load_mmu_pgd(struct kvm_vcpu *vcpu, hpa_t root_hpa, int root_level);
int tdx_gmem_private_max_mapping_level(struct kvm *kvm, kvm_pfn_t pfn);
+int tdx_vm_move_enc_context_from(struct kvm *kvm, struct kvm *source_kvm);
#endif
#endif /* __KVM_X86_VMX_X86_OPS_H */
--
2.50.0.rc1.591.g9c95f17f64-goog
next prev parent reply other threads:[~2025-06-11 21:17 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-11 21:16 [RFC PATCH v2 00/10] Add TDX intra-host migration support Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 01/10] KVM: Split tdp_mmu_pages to mirror and direct counters Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 02/10] KVM: x86: Adjust locking order in move_enc_context_from Ryan Afranji
2025-06-11 21:16 ` Ryan Afranji [this message]
2025-06-11 21:16 ` [RFC PATCH v2 04/10] KVM: TDX: Implement moving mirror pages between 2 TDs Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 05/10] KVM: TDX: Allow vCPUs to be created for migration Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 06/10] KVM: TDX: Add core logic for TDX intra-host migration Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 07/10] KVM: selftests: Refactor userspace_mem_region creation out of vm_mem_add Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 08/10] KVM: selftests: TDX: Add tests for TDX in-place migration Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 09/10] KVM: selftests: Add TDX support for ucalls Ryan Afranji
2025-06-11 21:16 ` [RFC PATCH v2 10/10] KVM: selftests: Add irqfd/interrupts test for TDX with migration Ryan Afranji
2026-03-09 14:17 ` [RFC PATCH v2 00/10] Add TDX intra-host migration support Sean Christopherson
2026-03-09 15:04 ` Vishal Annapurve
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=c55644ec81c22e7239d52f97e744eb4bafeccac3.1749672978.git.afranji@google.com \
--to=afranji@google.com \
--cc=ackerleytng@google.com \
--cc=andrew.jones@linux.dev \
--cc=bp@alien8.de \
--cc=chao.p.peng@linux.intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=dmatlack@google.com \
--cc=erdemaktas@google.com \
--cc=hpa@zytor.com \
--cc=isaku.yamahata@intel.com \
--cc=kai.huang@intel.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pbonzini@redhat.com \
--cc=rick.p.edgecombe@intel.com \
--cc=sagis@google.com \
--cc=seanjc@google.com \
--cc=tabba@google.com \
--cc=tglx@linutronix.de \
--cc=vannapurve@google.com \
--cc=x86@kernel.org \
--cc=yan.y.zhao@intel.com \
--cc=zhi.wang.linux@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®