Skip to content

Commit 7bc30c2

Browse files
committed
Merge branch 'kvm-updates/2.6.39' of git://git.kernel.org/pub/scm/virt/kvm/kvm
* 'kvm-updates/2.6.39' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: move and fix substitue search for missing CPUID entries KVM: fix XSAVE bit scanning KVM: Enable async page fault processing KVM: fix crash on irqfd deassign
2 parents ccfeef0 + bd22f5c commit 7bc30c2

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

arch/x86/kvm/x86.c

+28-9
Original file line numberDiff line numberDiff line change
@@ -2395,9 +2395,9 @@ static void do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
23952395
int i;
23962396

23972397
entry->flags |= KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
2398-
for (i = 1; *nent < maxnent; ++i) {
2399-
if (entry[i - 1].eax == 0 && i != 2)
2400-
break;
2398+
for (i = 1; *nent < maxnent && i < 64; ++i) {
2399+
if (entry[i].eax == 0)
2400+
continue;
24012401
do_cpuid_1_ent(&entry[i], function, i);
24022402
entry[i].flags |=
24032403
KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
@@ -4958,12 +4958,6 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
49584958
best = e;
49594959
break;
49604960
}
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;
49674961
}
49684962
return best;
49694963
}
@@ -4983,6 +4977,27 @@ int cpuid_maxphyaddr(struct kvm_vcpu *vcpu)
49834977
return 36;
49844978
}
49854979

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+
49865001
void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
49875002
{
49885003
u32 function, index;
@@ -4995,6 +5010,10 @@ void kvm_emulate_cpuid(struct kvm_vcpu *vcpu)
49955010
kvm_register_write(vcpu, VCPU_REGS_RCX, 0);
49965011
kvm_register_write(vcpu, VCPU_REGS_RDX, 0);
49975012
best = kvm_find_cpuid_entry(vcpu, function, index);
5013+
5014+
if (!best)
5015+
best = check_cpuid_limit(vcpu, function, index);
5016+
49985017
if (best) {
49995018
kvm_register_write(vcpu, VCPU_REGS_RAX, best->eax);
50005019
kvm_register_write(vcpu, VCPU_REGS_RBX, best->ebx);

virt/kvm/eventfd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ irqfd_shutdown(struct work_struct *work)
9090
* We know no new events will be scheduled at this point, so block
9191
* until all previously outstanding events have completed
9292
*/
93-
flush_work(&irqfd->inject);
93+
flush_work_sync(&irqfd->inject);
9494

9595
/*
9696
* It is now safe to release the object's resources

virt/kvm/kvm_main.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,17 @@ static pfn_t get_fault_pfn(void)
10371037
return fault_pfn;
10381038
}
10391039

1040+
int get_user_page_nowait(struct task_struct *tsk, struct mm_struct *mm,
1041+
unsigned long start, int write, struct page **page)
1042+
{
1043+
int flags = FOLL_TOUCH | FOLL_NOWAIT | FOLL_HWPOISON | FOLL_GET;
1044+
1045+
if (write)
1046+
flags |= FOLL_WRITE;
1047+
1048+
return __get_user_pages(tsk, mm, start, 1, flags, page, NULL, NULL);
1049+
}
1050+
10401051
static inline int check_user_page_hwpoison(unsigned long addr)
10411052
{
10421053
int rc, flags = FOLL_TOUCH | FOLL_HWPOISON | FOLL_WRITE;
@@ -1070,7 +1081,14 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
10701081
if (writable)
10711082
*writable = write_fault;
10721083

1073-
npages = get_user_pages_fast(addr, 1, write_fault, page);
1084+
if (async) {
1085+
down_read(&current->mm->mmap_sem);
1086+
npages = get_user_page_nowait(current, current->mm,
1087+
addr, write_fault, page);
1088+
up_read(&current->mm->mmap_sem);
1089+
} else
1090+
npages = get_user_pages_fast(addr, 1, write_fault,
1091+
page);
10741092

10751093
/* map read fault as writable if possible */
10761094
if (unlikely(!write_fault) && npages == 1) {
@@ -1093,7 +1111,8 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
10931111
return get_fault_pfn();
10941112

10951113
down_read(&current->mm->mmap_sem);
1096-
if (check_user_page_hwpoison(addr)) {
1114+
if (npages == -EHWPOISON ||
1115+
(!async && check_user_page_hwpoison(addr))) {
10971116
up_read(&current->mm->mmap_sem);
10981117
get_page(hwpoison_page);
10991118
return page_to_pfn(hwpoison_page);

0 commit comments

Comments
 (0)