@@ -390,6 +390,7 @@ void kvm_x86_state_cleanup(struct kvm_x86_state *state);
struct kvm_msr_list *kvm_get_msr_index_list(void);
uint64_t kvm_get_feature_msr(uint64_t msr_index);
+struct kvm_cpuid2 *_kvm_get_supported_cpuid(void);
struct kvm_cpuid2 *kvm_get_supported_cpuid(void);
struct kvm_cpuid2 *vcpu_get_cpuid(struct kvm_vm *vm, uint32_t vcpuid);
@@ -772,17 +772,14 @@ static struct kvm_cpuid2 *allocate_kvm_cpuid2(void)
*
* Return: The supported KVM CPUID
*
- * Get the guest CPUID supported by KVM.
+ * Gets the supported guest CPUID with the KVM_GET_SUPPORTED_CPUID ioctl.
*/
-struct kvm_cpuid2 *kvm_get_supported_cpuid(void)
+struct kvm_cpuid2 *_kvm_get_supported_cpuid(void)
{
- static struct kvm_cpuid2 *cpuid;
+ struct kvm_cpuid2 *cpuid;
int ret;
int kvm_fd;
- if (cpuid)
- return cpuid;
-
cpuid = allocate_kvm_cpuid2();
kvm_fd = open_kvm_dev_path_or_exit();
@@ -794,6 +791,30 @@ struct kvm_cpuid2 *kvm_get_supported_cpuid(void)
return cpuid;
}
+/*
+ * KVM Supported CPUID Get
+ *
+ * Input Args: None
+ *
+ * Output Args: None
+ *
+ * Return: The supported KVM CPUID
+ *
+ * Gets the supported guest CPUID with the KVM_GET_SUPPORTED_CPUID ioctl.
+ * The first call creates a static allocation of CPUID for the process.
+ * Subsequent calls will return a pointer to the previously allocated CPUID.
+ */
+struct kvm_cpuid2 *kvm_get_supported_cpuid(void)
+{
+ static struct kvm_cpuid2 *cpuid;
+
+ if (cpuid)
+ return cpuid;
+
+ cpuid = _kvm_get_supported_cpuid();
+ return cpuid;
+}
+
/*
* KVM Get MSR
*
The library code allows for a single allocation of CPUID to store the value returned by KVM_GET_SUPPORTED_CPUID. Subsequent calls to the helper simply return a pointer to the aforementioned allocation. A subsequent change introduces a selftest that contains test cases which adjust the CPUID value before calling KVM_SET_CPUID2. Using a single definition of CPUID is problematic, as the changes are not isolated to a single test case. Create a helper that allocates memory for CPUID on a per-call basis. Signed-off-by: Oliver Upton <oupton@google.com> --- .../selftests/kvm/include/x86_64/processor.h | 1 + .../selftests/kvm/lib/x86_64/processor.c | 33 +++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-)