-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'kvm-x86-fixes-6.4' of https://github.com/kvm-x86/linux int…
…o HEAD KVM x86 fixes for 6.4 - Fix a memslot lookup bug in the NX recovery thread that could theoretically let userspace bypass the NX hugepage mitigation - Fix a s/BLOCKING/PENDING bug in SVM's vNMI support - Account exit stats for fastpath VM-Exits that never leave the super tight run-loop - Fix an out-of-bounds bug in the optimized APIC map code, and add a regression test for the race.
- Loading branch information
Showing
6 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Test edge cases and race conditions in kvm_recalculate_apic_map(). | ||
*/ | ||
|
||
#include <sys/ioctl.h> | ||
#include <pthread.h> | ||
#include <time.h> | ||
|
||
#include "processor.h" | ||
#include "test_util.h" | ||
#include "kvm_util.h" | ||
#include "apic.h" | ||
|
||
#define TIMEOUT 5 /* seconds */ | ||
|
||
#define LAPIC_DISABLED 0 | ||
#define LAPIC_X2APIC (MSR_IA32_APICBASE_ENABLE | X2APIC_ENABLE) | ||
#define MAX_XAPIC_ID 0xff | ||
|
||
static void *race(void *arg) | ||
{ | ||
struct kvm_lapic_state lapic = {}; | ||
struct kvm_vcpu *vcpu = arg; | ||
|
||
while (1) { | ||
/* Trigger kvm_recalculate_apic_map(). */ | ||
vcpu_ioctl(vcpu, KVM_SET_LAPIC, &lapic); | ||
pthread_testcancel(); | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
int main(void) | ||
{ | ||
struct kvm_vcpu *vcpus[KVM_MAX_VCPUS]; | ||
struct kvm_vcpu *vcpuN; | ||
struct kvm_vm *vm; | ||
pthread_t thread; | ||
time_t t; | ||
int i; | ||
|
||
kvm_static_assert(KVM_MAX_VCPUS > MAX_XAPIC_ID); | ||
|
||
/* | ||
* Create the max number of vCPUs supported by selftests so that KVM | ||
* has decent amount of work to do when recalculating the map, i.e. to | ||
* make the problematic window large enough to hit. | ||
*/ | ||
vm = vm_create_with_vcpus(KVM_MAX_VCPUS, NULL, vcpus); | ||
|
||
/* | ||
* Enable x2APIC on all vCPUs so that KVM doesn't bail from the recalc | ||
* due to vCPUs having aliased xAPIC IDs (truncated to 8 bits). | ||
*/ | ||
for (i = 0; i < KVM_MAX_VCPUS; i++) | ||
vcpu_set_msr(vcpus[i], MSR_IA32_APICBASE, LAPIC_X2APIC); | ||
|
||
ASSERT_EQ(pthread_create(&thread, NULL, race, vcpus[0]), 0); | ||
|
||
vcpuN = vcpus[KVM_MAX_VCPUS - 1]; | ||
for (t = time(NULL) + TIMEOUT; time(NULL) < t;) { | ||
vcpu_set_msr(vcpuN, MSR_IA32_APICBASE, LAPIC_X2APIC); | ||
vcpu_set_msr(vcpuN, MSR_IA32_APICBASE, LAPIC_DISABLED); | ||
} | ||
|
||
ASSERT_EQ(pthread_cancel(thread), 0); | ||
ASSERT_EQ(pthread_join(thread, NULL), 0); | ||
|
||
kvm_vm_free(vm); | ||
|
||
return 0; | ||
} |