diff options
Diffstat (limited to 'arch/x86/kvm/x86.c')
| -rw-r--r-- | arch/x86/kvm/x86.c | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 58f517b5964..934b4c6b0bf 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
| @@ -2395,9 +2395,9 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function, | |||
| 2395 | int i; | 2395 | int i; |
| 2396 | 2396 | ||
| 2397 | entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; | 2397 | entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX; |
| 2398 | for (i = 1; *nent < maxnent; ++i) { | 2398 | for (i = 1; *nent < maxnent && i < 64; ++i) { |
| 2399 | if (entry[i - 1].eax == 0 && i != 2) | 2399 | if (entry[i].eax == 0) |
| 2400 | break; | 2400 | continue; |
| 2401 | do_cpuid_1_ent(&entry[i], function, i); | 2401 | do_cpuid_1_ent(&entry[i], function, i); |
| 2402 | entry[i].flags |= | 2402 | entry[i].flags |= |
| 2403 | KVM_CPUID_FLAG_SIGNIFCANT_INDEX; | 2403 | KVM_CPUID_FLAG_SIGNIFCANT_INDEX; |
| @@ -4958,12 +4958,6 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu, | |||
| 4958 | best = e; | 4958 | best = e; |
| 4959 | break; | 4959 | break; |
| 4960 | } | 4960 | } |
| 4961 | /* | ||
| 4962 | * Both basic or both extended? | ||
| 4963 | */ | ||
| 4964 | if (((e->function ^ function) & 0x80000000) == 0) | ||
| 4965 | if (!best || e->function > best->function) | ||
| 4966 | best = e; | ||
| 4967 | } | 4961 | } |
| 4968 | return best; | 4962 | return best; |
| 4969 | } | 4963 | } |
| @@ -4983,6 +4977,27 @@ not_found: | |||
| 4983 | return 36; | 4977 | return 36; |
| 4984 | } | 4978 | } |
| 4985 | 4979 | ||
| 4980 | /* | ||
| 4981 | * If no match is found, check whether we exceed the vCPU's limit | ||
| 4982 | * and return the content of the highest valid _standard_ leaf instead. | ||
| 4983 | * This is to satisfy the CPUID specification. | ||
| 4984 | */ | ||
| 4985 | static struct kvm_cpuid_entry2* check_cpuid_limit(struct kvm_vcpu *vcpu, | ||
| 4986 | u32 function, u32 index) | ||
| 4987 | { | ||
| 4988 | struct kvm_cpuid_entry2 *maxlevel; | ||
| 4989 | |||
| 4990 | maxlevel = kvm_find_cpuid_entry(vcpu, function & 0x80000000, 0); | ||
| 4991 | if (!maxlevel || maxlevel->eax >= function) | ||
| 4992 | return NULL; | ||
| 4993 | if (function & 0x80000000) { | ||
| 4994 | maxlevel = kvm_find_cpuid_entry(vcpu, 0, 0); | ||
| 4995 | if (!maxlevel) | ||
| 4996 | return NULL; | ||
| 4997 | } | ||
| 4998 | return kvm_find_cpuid_entry(vcpu, maxlevel->eax, index); | ||
| 4999 | } | ||
| 5000 | |||
| 4986 | void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) | 5001 | void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) |
| 4987 | { | 5002 | { |
| 4988 | u32 function, index; | 5003 | u32 function, index; |
| @@ -4995,6 +5010,10 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu) | |||
| 4995 | kvm_register_write(vcpu, VCPU_REGS_RCX, 0); | 5010 | kvm_register_write(vcpu, VCPU_REGS_RCX, 0); |
| 4996 | kvm_register_write(vcpu, VCPU_REGS_RDX, 0); | 5011 | kvm_register_write(vcpu, VCPU_REGS_RDX, 0); |
| 4997 | best = kvm_find_cpuid_entry(vcpu, function, index); | 5012 | best = kvm_find_cpuid_entry(vcpu, function, index); |
| 5013 | |||
| 5014 | if (!best) | ||
| 5015 | best = check_cpuid_limit(vcpu, function, index); | ||
| 5016 | |||
| 4998 | if (best) { | 5017 | if (best) { |
| 4999 | kvm_register_write(vcpu, VCPU_REGS_RAX, best->eax); | 5018 | kvm_register_write(vcpu, VCPU_REGS_RAX, best->eax); |
| 5000 | kvm_register_write(vcpu, VCPU_REGS_RBX, best->ebx); | 5019 | kvm_register_write(vcpu, VCPU_REGS_RBX, best->ebx); |
