From 2c53e1a9f344ee09946170510440bb239a8a2cf8 Mon Sep 17 00:00:00 2001 From: ddugger@redhat.com Date: Wed, 21 Sep 2011 04:59:50 +0200 Subject: [PATCH 01/76] bz716261: kvm: Extend kvm_arch_get_supported_cpuid() to support index RH-Author: ddugger@redhat.com Message-id: <1316581195-18779-2-git-send-email-ddugger@redhat.com> Patchwork-id: 33031 O-Subject: [RHEL 6.2 PATCH 1/6 V3] bz716261: kvm: Extend kvm_arch_get_supported_cpuid() to support index Bugzilla: 716261 RH-Acked-by: Marcelo Tosatti RH-Acked-by: Eduardo Habkost RH-Acked-by: Avi Kivity From: n0ano@n0ano.com Upstream Commit: commit 139610b36bc54bf98a193831256437f0cc9a522b Author: Sheng Yang Date: Thu Jun 10 11:31:01 2010 +0800 qemu: kvm: Extend kvm_arch_get_supported_cpuid() to support index Would use it later for XSAVE related CPUID. Signed-off-by: Sheng Yang Signed-off-by: Marcelo Tosatti Signed-off-by: Frank Arnold Signed-off-by: Don Dugger --- kvm.h | 2 +- kvm/libkvm/libkvm-x86.c | 11 +++++++---- kvm/libkvm/libkvm.h | 3 ++- qemu-kvm-x86.c | 22 ++++++++++++---------- qemu-kvm.h | 5 +++-- target-i386/helper.c | 10 +++++----- target-i386/kvm.c | 19 +++++++++++-------- 7 files changed, 41 insertions(+), 31 deletions(-) Signed-off-by: Michal Novotny --- kvm.h | 2 +- kvm/libkvm/libkvm-x86.c | 11 +++++++---- kvm/libkvm/libkvm.h | 3 ++- qemu-kvm-x86.c | 22 ++++++++++++---------- qemu-kvm.h | 5 +++-- target-i386/helper.c | 10 +++++----- target-i386/kvm.c | 19 +++++++++++-------- 7 files changed, 41 insertions(+), 31 deletions(-) diff --git a/kvm.h b/kvm.h index d93b20b..78d6595 100644 --- a/kvm.h +++ b/kvm.h @@ -142,7 +142,7 @@ void kvm_arch_update_guest_debug(CPUState *env, struct kvm_guest_debug *dbg); int kvm_check_extension(KVMState *s, unsigned int extension); uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, - int reg); + uint32_t index, int reg); void kvm_cpu_synchronize_state(CPUState *env); /* generic hooks - to be moved/refactored once there are more users */ diff --git a/kvm/libkvm/libkvm-x86.c b/kvm/libkvm/libkvm-x86.c index f1aef76..d231a66 100644 --- a/kvm/libkvm/libkvm-x86.c +++ b/kvm/libkvm/libkvm-x86.c @@ -609,7 +609,8 @@ static struct kvm_cpuid2 *try_get_cpuid(kvm_context_t kvm, int max) #define R_ESI 6 #define R_EDI 7 -uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) +uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, + uint32_t index, int reg) { struct kvm_cpuid2 *cpuid; int i, max; @@ -626,7 +627,8 @@ uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) } for (i = 0; i < cpuid->nent; ++i) { - if (cpuid->entries[i].function == function) { + if (cpuid->entries[i].function == function && + cpuid->entries[i].index == index) { switch (reg) { case R_EAX: ret = cpuid->entries[i].eax; @@ -653,7 +655,7 @@ uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) * according to the AMD spec: */ if (function == 0x80000001) { - cpuid_1_edx = kvm_get_supported_cpuid(kvm, 1, R_EDX); + cpuid_1_edx = kvm_get_supported_cpuid(kvm, 1, 0, R_EDX); ret |= cpuid_1_edx & 0xdfeff7ff; } break; @@ -668,7 +670,8 @@ uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) #else -uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) +uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, + uint32_t index, int reg) { return -1U; } diff --git a/kvm/libkvm/libkvm.h b/kvm/libkvm/libkvm.h index 4821a1e..1c9eb96 100644 --- a/kvm/libkvm/libkvm.h +++ b/kvm/libkvm/libkvm.h @@ -863,6 +863,7 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm, struct kvm_assigned_msix_entry *entry); #endif -uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg); +uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, + uint32_t index, int reg); #endif diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c index 81cb90a..3a644bf 100644 --- a/qemu-kvm-x86.c +++ b/qemu-kvm-x86.c @@ -695,7 +695,8 @@ static int get_para_features(kvm_context_t kvm_context) } -uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) +uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, + uint32_t index, int reg) { uint32_t ret = -1; int has_kvm_features = 0; @@ -716,7 +717,8 @@ uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) } for (i = 0; i < cpuid->nent; ++i) { - if (cpuid->entries[i].function == function) { + if (cpuid->entries[i].function == function && + cpuid->entries[i].index == index) { if (cpuid->entries[i].function == KVM_CPUID_FEATURES) { has_kvm_features = 1; } @@ -747,7 +749,7 @@ uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg) * according to the AMD spec: */ if (function == 0x80000001) { - cpuid_1_edx = kvm_get_supported_cpuid(kvm, 1, R_EDX); + cpuid_1_edx = kvm_get_supported_cpuid(kvm, 1, 0, R_EDX); ret |= cpuid_1_edx & 0x183f7ff; } break; @@ -1330,22 +1332,22 @@ int kvm_arch_init_vcpu(CPUState *cenv) memset(pv_ent, 0, sizeof(*pv_ent)); pv_ent->function = KVM_CPUID_FEATURES; pv_ent->eax = cenv->cpuid_kvm_features & kvm_arch_get_supported_cpuid(cenv, - KVM_CPUID_FEATURES, R_EAX); + KVM_CPUID_FEATURES, 0, R_EAX); #endif kvm_trim_features(&cenv->cpuid_features, - kvm_arch_get_supported_cpuid(cenv, 1, R_EDX)); + kvm_arch_get_supported_cpuid(cenv, 1, 0, R_EDX)); /* prevent the hypervisor bit from being cleared by the kernel */ i = cenv->cpuid_ext_features & CPUID_EXT_HYPERVISOR; kvm_trim_features(&cenv->cpuid_ext_features, - kvm_arch_get_supported_cpuid(cenv, 1, R_ECX)); + kvm_arch_get_supported_cpuid(cenv, 1, 0, R_ECX)); cenv->cpuid_ext_features |= i; kvm_trim_features(&cenv->cpuid_ext2_features, - kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_EDX)); + kvm_arch_get_supported_cpuid(cenv, 0x80000001, 0, R_EDX)); kvm_trim_features(&cenv->cpuid_ext3_features, - kvm_arch_get_supported_cpuid(cenv, 0x80000001, R_ECX)); + kvm_arch_get_supported_cpuid(cenv, 0x80000001, 0, R_ECX)); copy = *cenv; @@ -1738,9 +1740,9 @@ int kvm_arch_init_irq_routing(void) } uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, - int reg) + uint32_t index, int reg) { - return kvm_get_supported_cpuid(kvm_context, function, reg); + return kvm_get_supported_cpuid(kvm_context, function, index, reg); } void kvm_arch_process_irqchip_events(CPUState *env) diff --git a/qemu-kvm.h b/qemu-kvm.h index 0747a6a..3e55ab4 100644 --- a/qemu-kvm.h +++ b/qemu-kvm.h @@ -865,7 +865,8 @@ int kvm_assign_set_msix_entry(kvm_context_t kvm, struct kvm_assigned_msix_entry *entry); #endif -uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, int reg); +uint32_t kvm_get_supported_cpuid(kvm_context_t kvm, uint32_t function, + uint32_t index, int reg); #else /* !CONFIG_KVM */ @@ -1115,7 +1116,7 @@ static inline void cpu_synchronize_state(CPUState *env) } uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, - int reg); + uint32_t index, int reg); #endif diff --git a/target-i386/helper.c b/target-i386/helper.c index 332884d..6e355b1 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -500,7 +500,7 @@ static void summary_cpuid_features(CPUX86State *env, x86_def_t *hd) for (p = fmap; p->pfeat; ++p) { if (p->mask) { *p->pfeat |= p->mask & - kvm_arch_get_supported_cpuid(env, p->cmd, p->reg); + kvm_arch_get_supported_cpuid(env, p->cmd, 0, p->reg); } } } @@ -2143,10 +2143,10 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, break; case 7: if (kvm_enabled()) { - *eax = kvm_arch_get_supported_cpuid(env, 0x7, R_EAX); - *ebx = kvm_arch_get_supported_cpuid(env, 0x7, R_EBX); - *ecx = kvm_arch_get_supported_cpuid(env, 0x7, R_ECX); - *edx = kvm_arch_get_supported_cpuid(env, 0x7, R_EDX); + *eax = kvm_arch_get_supported_cpuid(env, 0x7, 0, R_EAX); + *ebx = kvm_arch_get_supported_cpuid(env, 0x7, 0, R_EBX); + *ecx = kvm_arch_get_supported_cpuid(env, 0x7, 0, R_ECX); + *edx = kvm_arch_get_supported_cpuid(env, 0x7, 0, R_EDX); } else { *eax = 0; *ebx = 0; diff --git a/target-i386/kvm.c b/target-i386/kvm.c index 56fc1ac..c7cd1c0 100644 --- a/target-i386/kvm.c +++ b/target-i386/kvm.c @@ -66,7 +66,8 @@ static struct kvm_cpuid2 *try_get_cpuid(KVMState *s, int max) return cpuid; } -uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) +uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, + uint32_t index, int reg) { struct kvm_cpuid2 *cpuid; int i, max; @@ -83,7 +84,8 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) } for (i = 0; i < cpuid->nent; ++i) { - if (cpuid->entries[i].function == function) { + if (cpuid->entries[i].function == function && + cpuid->entries[i].index == index) { switch (reg) { case R_EAX: ret = cpuid->entries[i].eax; @@ -100,7 +102,7 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) /* On Intel, kvm returns cpuid according to the Intel spec, * so add missing bits according to the AMD spec: */ - cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, R_EDX); + cpuid_1_edx = kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX); ret |= cpuid_1_edx & 0xdfeff7ff; } break; @@ -115,7 +117,8 @@ uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) #else -uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, int reg) +uint32_t kvm_arch_get_supported_cpuid(CPUState *env, uint32_t function, + uint32_t index, int reg) { return -1U; } @@ -147,17 +150,17 @@ int kvm_arch_init_vcpu(CPUState *env) env->mp_state = KVM_MP_STATE_RUNNABLE; kvm_trim_features(&env->cpuid_features, - kvm_arch_get_supported_cpuid(env, 1, R_EDX)); + kvm_arch_get_supported_cpuid(env, 1, 0, R_EDX)); i = env->cpuid_ext_features & CPUID_EXT_HYPERVISOR; kvm_trim_features(&env->cpuid_ext_features, - kvm_arch_get_supported_cpuid(env, 1, R_ECX)); + kvm_arch_get_supported_cpuid(env, 1, 0, R_ECX)); env->cpuid_ext_features |= i; kvm_trim_features(&env->cpuid_ext2_features, - kvm_arch_get_supported_cpuid(env, 0x80000001, R_EDX)); + kvm_arch_get_supported_cpuid(env, 0x80000001, 0, R_EDX)); kvm_trim_features(&env->cpuid_ext3_features, - kvm_arch_get_supported_cpuid(env, 0x80000001, R_ECX)); + kvm_arch_get_supported_cpuid(env, 0x80000001, 0, R_ECX)); cpuid_i = 0; -- 1.7.4.4