Skip to content

Commit 6254eeb

Browse files
committed
Merge tag 'kvm-x86-fixes-6.7-rcN' of https://github.com/kvm-x86/linux into kvm-master
KVM fixes for 6.7-rcN: - When checking if a _running_ vCPU is "in-kernel", i.e. running at CPL0, get the CPL directly instead of relying on preempted_in_kernel, which is valid if and only if the vCPU was preempted, i.e. NOT running. - Set .owner for various KVM file_operations so that files refcount the KVM module until KVM is done executing _all_ code, including the last few instructions of kvm_put_kvm(). And then revert the misguided attempt to rely on "struct kvm" refcounts to pin KVM-the-module. - Fix a benign "return void" that was recently introduced.
2 parents aa0ae3d + ef8d890 commit 6254eeb

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

arch/x86/kvm/debugfs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)
182182
}
183183

184184
static const struct file_operations mmu_rmaps_stat_fops = {
185+
.owner = THIS_MODULE,
185186
.open = kvm_mmu_rmaps_stat_open,
186187
.read = seq_read,
187188
.llseek = seq_lseek,

arch/x86/kvm/x86.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5518,8 +5518,8 @@ static void kvm_vcpu_ioctl_x86_get_xsave2(struct kvm_vcpu *vcpu,
55185518
static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu,
55195519
struct kvm_xsave *guest_xsave)
55205520
{
5521-
return kvm_vcpu_ioctl_x86_get_xsave2(vcpu, (void *)guest_xsave->region,
5522-
sizeof(guest_xsave->region));
5521+
kvm_vcpu_ioctl_x86_get_xsave2(vcpu, (void *)guest_xsave->region,
5522+
sizeof(guest_xsave->region));
55235523
}
55245524

55255525
static int kvm_vcpu_ioctl_x86_set_xsave(struct kvm_vcpu *vcpu,
@@ -13031,7 +13031,10 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
1303113031
if (vcpu->arch.guest_state_protected)
1303213032
return true;
1303313033

13034-
return vcpu->arch.preempted_in_kernel;
13034+
if (vcpu != kvm_get_running_vcpu())
13035+
return vcpu->arch.preempted_in_kernel;
13036+
13037+
return static_call(kvm_x86_get_cpl)(vcpu) == 0;
1303513038
}
1303613039

1303713040
unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)

virt/kvm/kvm_main.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ EXPORT_SYMBOL_GPL(kvm_debugfs_dir);
115115

116116
static const struct file_operations stat_fops_per_vm;
117117

118-
static struct file_operations kvm_chardev_ops;
119-
120118
static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
121119
unsigned long arg);
122120
#ifdef CONFIG_KVM_COMPAT
@@ -1157,9 +1155,6 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
11571155
if (!kvm)
11581156
return ERR_PTR(-ENOMEM);
11591157

1160-
/* KVM is pinned via open("/dev/kvm"), the fd passed to this ioctl(). */
1161-
__module_get(kvm_chardev_ops.owner);
1162-
11631158
KVM_MMU_LOCK_INIT(kvm);
11641159
mmgrab(current->mm);
11651160
kvm->mm = current->mm;
@@ -1279,7 +1274,6 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
12791274
out_err_no_srcu:
12801275
kvm_arch_free_vm(kvm);
12811276
mmdrop(current->mm);
1282-
module_put(kvm_chardev_ops.owner);
12831277
return ERR_PTR(r);
12841278
}
12851279

@@ -1348,7 +1342,6 @@ static void kvm_destroy_vm(struct kvm *kvm)
13481342
preempt_notifier_dec();
13491343
hardware_disable_all();
13501344
mmdrop(mm);
1351-
module_put(kvm_chardev_ops.owner);
13521345
}
13531346

13541347
void kvm_get_kvm(struct kvm *kvm)
@@ -3887,7 +3880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
38873880
return 0;
38883881
}
38893882

3890-
static const struct file_operations kvm_vcpu_fops = {
3883+
static struct file_operations kvm_vcpu_fops = {
38913884
.release = kvm_vcpu_release,
38923885
.unlocked_ioctl = kvm_vcpu_ioctl,
38933886
.mmap = kvm_vcpu_mmap,
@@ -4081,6 +4074,7 @@ static int kvm_vcpu_stats_release(struct inode *inode, struct file *file)
40814074
}
40824075

40834076
static const struct file_operations kvm_vcpu_stats_fops = {
4077+
.owner = THIS_MODULE,
40844078
.read = kvm_vcpu_stats_read,
40854079
.release = kvm_vcpu_stats_release,
40864080
.llseek = noop_llseek,
@@ -4431,7 +4425,7 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
44314425
return 0;
44324426
}
44334427

4434-
static const struct file_operations kvm_device_fops = {
4428+
static struct file_operations kvm_device_fops = {
44354429
.unlocked_ioctl = kvm_device_ioctl,
44364430
.release = kvm_device_release,
44374431
KVM_COMPAT(kvm_device_ioctl),
@@ -4759,6 +4753,7 @@ static int kvm_vm_stats_release(struct inode *inode, struct file *file)
47594753
}
47604754

47614755
static const struct file_operations kvm_vm_stats_fops = {
4756+
.owner = THIS_MODULE,
47624757
.read = kvm_vm_stats_read,
47634758
.release = kvm_vm_stats_release,
47644759
.llseek = noop_llseek,
@@ -5060,7 +5055,7 @@ static long kvm_vm_compat_ioctl(struct file *filp,
50605055
}
50615056
#endif
50625057

5063-
static const struct file_operations kvm_vm_fops = {
5058+
static struct file_operations kvm_vm_fops = {
50645059
.release = kvm_vm_release,
50655060
.unlocked_ioctl = kvm_vm_ioctl,
50665061
.llseek = noop_llseek,
@@ -6095,6 +6090,9 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
60956090
goto err_async_pf;
60966091

60976092
kvm_chardev_ops.owner = module;
6093+
kvm_vm_fops.owner = module;
6094+
kvm_vcpu_fops.owner = module;
6095+
kvm_device_fops.owner = module;
60986096

60996097
kvm_preempt_ops.sched_in = kvm_sched_in;
61006098
kvm_preempt_ops.sched_out = kvm_sched_out;

0 commit comments

Comments
 (0)