Add linux-next specific files for 20110831
[linux-2.6/next.git] / tools / kvm / cpuid.c
blobc3b3d58aacfe31bed2c3fd279b0f64df45676c83
1 #include "kvm/kvm-cpu.h"
3 #include "kvm/kvm.h"
4 #include "kvm/util.h"
6 #include <sys/ioctl.h>
7 #include <stdlib.h>
8 #include <assert.h>
10 #define CPUID_FUNC_PERFMON 0x0A
12 #define MAX_KVM_CPUID_ENTRIES 100
14 static void filter_cpuid(struct kvm_cpuid2 *kvm_cpuid)
16 unsigned int i;
19 * Filter CPUID functions that are not supported by the hypervisor.
21 for (i = 0; i < kvm_cpuid->nent; i++) {
22 struct kvm_cpuid_entry2 *entry = &kvm_cpuid->entries[i];
24 switch (entry->function) {
25 case CPUID_FUNC_PERFMON:
26 entry->eax = 0x00; /* disable it */
27 break;
28 default:
29 /* Keep the CPUID function as -is */
30 break;
35 void kvm_cpu__setup_cpuid(struct kvm_cpu *vcpu)
37 struct kvm_cpuid2 *kvm_cpuid;
39 kvm_cpuid = calloc(1, sizeof(*kvm_cpuid) + MAX_KVM_CPUID_ENTRIES * sizeof(*kvm_cpuid->entries));
41 kvm_cpuid->nent = MAX_KVM_CPUID_ENTRIES;
42 if (ioctl(vcpu->kvm->sys_fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) < 0)
43 die_perror("KVM_GET_SUPPORTED_CPUID failed");
45 filter_cpuid(kvm_cpuid);
47 if (ioctl(vcpu->vcpu_fd, KVM_SET_CPUID2, kvm_cpuid) < 0)
48 die_perror("KVM_SET_CPUID2 failed");
50 free(kvm_cpuid);