Skip to content

Commit 74bc8ac

Browse files
committed
Merge tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm
Pull more KVM fixes from Paolo Bonzini: - fixes for CONFIG_KVM_COMPAT=n - two updates to the IFU erratum - selftests build fix - brown paper bag fix * tag 'for-linus' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: Add a comment describing the /dev/kvm no_compat handling KVM: x86/mmu: Take slots_lock when using kvm_mmu_zap_all_fast() KVM: Forbid /dev/kvm being opened by a compat task when CONFIG_KVM_COMPAT=n KVM: X86: Reset the three MSR list number variables to 0 in kvm_init_msr_list() selftests: kvm: fix build with glibc >= 2.30 kvm: x86: disable shattered huge page recovery for PREEMPT_RT.
2 parents 5b675f7 + 9cb09e7 commit 74bc8ac

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

arch/x86/kvm/mmu.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@
5151
extern bool itlb_multihit_kvm_mitigation;
5252

5353
static int __read_mostly nx_huge_pages = -1;
54+
#ifdef CONFIG_PREEMPT_RT
55+
/* Recovery can cause latency spikes, disable it for PREEMPT_RT. */
56+
static uint __read_mostly nx_huge_pages_recovery_ratio = 0;
57+
#else
5458
static uint __read_mostly nx_huge_pages_recovery_ratio = 60;
59+
#endif
5560

5661
static int set_nx_huge_pages(const char *val, const struct kernel_param *kp);
5762
static int set_nx_huge_pages_recovery_ratio(const char *val, const struct kernel_param *kp);
@@ -6280,14 +6285,13 @@ static int set_nx_huge_pages(const char *val, const struct kernel_param *kp)
62806285

62816286
if (new_val != old_val) {
62826287
struct kvm *kvm;
6283-
int idx;
62846288

62856289
mutex_lock(&kvm_lock);
62866290

62876291
list_for_each_entry(kvm, &vm_list, vm_list) {
6288-
idx = srcu_read_lock(&kvm->srcu);
6292+
mutex_lock(&kvm->slots_lock);
62896293
kvm_mmu_zap_all_fast(kvm);
6290-
srcu_read_unlock(&kvm->srcu, idx);
6294+
mutex_unlock(&kvm->slots_lock);
62916295

62926296
wake_up_process(kvm->arch.nx_lpage_recovery_thread);
62936297
}

arch/x86/kvm/x86.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5130,6 +5130,10 @@ static void kvm_init_msr_list(void)
51305130

51315131
perf_get_x86_pmu_capability(&x86_pmu);
51325132

5133+
num_msrs_to_save = 0;
5134+
num_emulated_msrs = 0;
5135+
num_msr_based_features = 0;
5136+
51335137
for (i = 0; i < ARRAY_SIZE(msrs_to_save_all); i++) {
51345138
if (rdmsr_safe(msrs_to_save_all[i], &dummy[0], &dummy[1]) < 0)
51355139
continue;

tools/testing/selftests/kvm/lib/assert.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static void test_dump_stack(void)
5555
#pragma GCC diagnostic pop
5656
}
5757

58-
static pid_t gettid(void)
58+
static pid_t _gettid(void)
5959
{
6060
return syscall(SYS_gettid);
6161
}
@@ -72,7 +72,7 @@ test_assert(bool exp, const char *exp_str,
7272
fprintf(stderr, "==== Test Assertion Failure ====\n"
7373
" %s:%u: %s\n"
7474
" pid=%d tid=%d - %s\n",
75-
file, line, exp_str, getpid(), gettid(),
75+
file, line, exp_str, getpid(), _gettid(),
7676
strerror(errno));
7777
test_dump_stack();
7878
if (fmt) {

virt/kvm/kvm_main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,22 @@ static long kvm_vcpu_compat_ioctl(struct file *file, unsigned int ioctl,
122122
unsigned long arg);
123123
#define KVM_COMPAT(c) .compat_ioctl = (c)
124124
#else
125+
/*
126+
* For architectures that don't implement a compat infrastructure,
127+
* adopt a double line of defense:
128+
* - Prevent a compat task from opening /dev/kvm
129+
* - If the open has been done by a 64bit task, and the KVM fd
130+
* passed to a compat task, let the ioctls fail.
131+
*/
125132
static long kvm_no_compat_ioctl(struct file *file, unsigned int ioctl,
126133
unsigned long arg) { return -EINVAL; }
127-
#define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl
134+
135+
static int kvm_no_compat_open(struct inode *inode, struct file *file)
136+
{
137+
return is_compat_task() ? -ENODEV : 0;
138+
}
139+
#define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl, \
140+
.open = kvm_no_compat_open
128141
#endif
129142
static int hardware_enable_all(void);
130143
static void hardware_disable_all(void);

0 commit comments

Comments
 (0)