diff mbox series

[20/25] KVM: X86: Introduce tdx_get_kvm_supported_cpuid()

Message ID 20240812224820.34826-21-rick.p.edgecombe@intel.com (mailing list archive)
State New, archived
Headers show
Series TDX vCPU/VM creation | expand

Commit Message

Edgecombe, Rick P Aug. 12, 2024, 10:48 p.m. UTC
Two future TDX ioctl's will want to filter output by supported CPUID

Add a helper in TDX code instead of using
kvm_get_supported_cpuid_internal() directly for two reasons:
1. Logic around which CPUID leaf ranges to query would need to be
   duplicated.
2. Future patches will add TDX specific fixups to the CPUID data provided
   by kvm_get_supported_cpuid_internal().

Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
uAPI breakout v1:
 - New patch
---
 arch/x86/kvm/vmx/tdx.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index ba7b436fae86..b2ed031ac0d6 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -1014,6 +1014,30 @@  static int tdx_td_vcpu_init(struct kvm_vcpu *vcpu, u64 vcpu_rcx)
 	return ret;
 }
 
+static int __maybe_unused tdx_get_kvm_supported_cpuid(struct kvm_cpuid2 **cpuid)
+{
+	int r;
+	static const u32 funcs[] = {
+		0, 0x80000000, KVM_CPUID_SIGNATURE,
+	};
+
+	*cpuid = kzalloc(sizeof(struct kvm_cpuid2) +
+			sizeof(struct kvm_cpuid_entry2) * KVM_MAX_CPUID_ENTRIES,
+			GFP_KERNEL);
+	if (!*cpuid)
+		return -ENOMEM;
+	(*cpuid)->nent = KVM_MAX_CPUID_ENTRIES;
+	r = kvm_get_supported_cpuid_internal(*cpuid, funcs, ARRAY_SIZE(funcs));
+	if (r)
+		goto err;
+
+	return 0;
+err:
+	kfree(*cpuid);
+	*cpuid = NULL;
+	return r;
+}
+
 static int tdx_vcpu_init(struct kvm_vcpu *vcpu, struct kvm_tdx_cmd *cmd)
 {
 	struct msr_data apic_base_msr;