[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240812224820.34826-20-rick.p.edgecombe@intel.com>
Date: Mon, 12 Aug 2024 15:48:14 -0700
From: Rick Edgecombe <rick.p.edgecombe@...el.com>
To: seanjc@...gle.com,
pbonzini@...hat.com,
kvm@...r.kernel.org
Cc: kai.huang@...el.com,
isaku.yamahata@...il.com,
tony.lindgren@...ux.intel.com,
xiaoyao.li@...el.com,
linux-kernel@...r.kernel.org,
rick.p.edgecombe@...el.com
Subject: [PATCH 19/25] KVM: X86: Introduce kvm_get_supported_cpuid_internal()
From: Xiaoyao Li <xiaoyao.li@...el.com>
TDX module reports a set of configurable CPUIDs. Directly report these
bits to userspace and allow them to be set is not good nor right. If a
bit is unknown/unsupported to KVM, it should be reported as unsupported
thus inconfigurable to userspace.
Introduce and export kvm_get_supported_cpuid_internal() for TDX to get
the supported CPUID list of KVM. So that TDX can use it to cap the
configurable CPUID list reported by TDX module.
Signed-off-by: Xiaoyao Li <xiaoyao.li@...el.com>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@...el.com>
---
uAPI breakout v1:
- New patch
---
arch/x86/kvm/cpuid.c | 25 +++++++++++++++++++++++++
arch/x86/kvm/cpuid.h | 2 ++
2 files changed, 27 insertions(+)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 7310d8a8a503..499479c769d8 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1487,6 +1487,31 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
return r;
}
+int kvm_get_supported_cpuid_internal(struct kvm_cpuid2 *cpuid, const u32 *funcs,
+ int funcs_len)
+{
+ struct kvm_cpuid_array array = {
+ .nent = 0,
+ };
+ int i, r;
+
+ if (cpuid->nent < 1 || cpuid->nent > KVM_MAX_CPUID_ENTRIES)
+ return -E2BIG;
+
+ array.maxnent = cpuid->nent;
+ array.entries = cpuid->entries;
+
+ for (i = 0; i < funcs_len; i++) {
+ r = get_cpuid_func(&array, funcs[i], KVM_GET_SUPPORTED_CPUID);
+ if (r)
+ return r;
+ }
+
+ cpuid->nent = array.nent;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(kvm_get_supported_cpuid_internal);
+
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry2(
struct kvm_cpuid_entry2 *entries, int nent, u32 function, u64 index)
{
diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h
index 00570227e2ae..5cc13d1b7991 100644
--- a/arch/x86/kvm/cpuid.h
+++ b/arch/x86/kvm/cpuid.h
@@ -13,6 +13,8 @@ void kvm_set_cpu_caps(void);
void kvm_update_cpuid_runtime(struct kvm_vcpu *vcpu);
void kvm_update_pv_runtime(struct kvm_vcpu *vcpu);
+int kvm_get_supported_cpuid_internal(struct kvm_cpuid2 *cpuid, const u32 *funcs,
+ int func_len);
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry2(struct kvm_cpuid_entry2 *entries,
int nent, u32 function, u64 index);
struct kvm_cpuid_entry2 *kvm_find_cpuid_entry_index(struct kvm_vcpu *vcpu,
--
2.34.1
Powered by blists - more mailing lists