Commit 6254eeba authored by Paolo Bonzini's avatar Paolo Bonzini

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.
parents aa0ae3df ef8d8903
...@@ -182,6 +182,7 @@ static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file) ...@@ -182,6 +182,7 @@ static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)
} }
static const struct file_operations mmu_rmaps_stat_fops = { static const struct file_operations mmu_rmaps_stat_fops = {
.owner = THIS_MODULE,
.open = kvm_mmu_rmaps_stat_open, .open = kvm_mmu_rmaps_stat_open,
.read = seq_read, .read = seq_read,
.llseek = seq_lseek, .llseek = seq_lseek,
......
...@@ -5518,7 +5518,7 @@ static void kvm_vcpu_ioctl_x86_get_xsave2(struct kvm_vcpu *vcpu, ...@@ -5518,7 +5518,7 @@ static void kvm_vcpu_ioctl_x86_get_xsave2(struct kvm_vcpu *vcpu,
static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu, static void kvm_vcpu_ioctl_x86_get_xsave(struct kvm_vcpu *vcpu,
struct kvm_xsave *guest_xsave) struct kvm_xsave *guest_xsave)
{ {
return kvm_vcpu_ioctl_x86_get_xsave2(vcpu, (void *)guest_xsave->region, kvm_vcpu_ioctl_x86_get_xsave2(vcpu, (void *)guest_xsave->region,
sizeof(guest_xsave->region)); sizeof(guest_xsave->region));
} }
...@@ -13031,7 +13031,10 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu) ...@@ -13031,7 +13031,10 @@ bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
if (vcpu->arch.guest_state_protected) if (vcpu->arch.guest_state_protected)
return true; return true;
if (vcpu != kvm_get_running_vcpu())
return vcpu->arch.preempted_in_kernel; return vcpu->arch.preempted_in_kernel;
return static_call(kvm_x86_get_cpl)(vcpu) == 0;
} }
unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu) unsigned long kvm_arch_vcpu_get_ip(struct kvm_vcpu *vcpu)
......
...@@ -115,8 +115,6 @@ EXPORT_SYMBOL_GPL(kvm_debugfs_dir); ...@@ -115,8 +115,6 @@ EXPORT_SYMBOL_GPL(kvm_debugfs_dir);
static const struct file_operations stat_fops_per_vm; static const struct file_operations stat_fops_per_vm;
static struct file_operations kvm_chardev_ops;
static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl, static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl,
unsigned long arg); unsigned long arg);
#ifdef CONFIG_KVM_COMPAT #ifdef CONFIG_KVM_COMPAT
...@@ -1157,9 +1155,6 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) ...@@ -1157,9 +1155,6 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
if (!kvm) if (!kvm)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
/* KVM is pinned via open("/dev/kvm"), the fd passed to this ioctl(). */
__module_get(kvm_chardev_ops.owner);
KVM_MMU_LOCK_INIT(kvm); KVM_MMU_LOCK_INIT(kvm);
mmgrab(current->mm); mmgrab(current->mm);
kvm->mm = current->mm; kvm->mm = current->mm;
...@@ -1279,7 +1274,6 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname) ...@@ -1279,7 +1274,6 @@ static struct kvm *kvm_create_vm(unsigned long type, const char *fdname)
out_err_no_srcu: out_err_no_srcu:
kvm_arch_free_vm(kvm); kvm_arch_free_vm(kvm);
mmdrop(current->mm); mmdrop(current->mm);
module_put(kvm_chardev_ops.owner);
return ERR_PTR(r); return ERR_PTR(r);
} }
...@@ -1348,7 +1342,6 @@ static void kvm_destroy_vm(struct kvm *kvm) ...@@ -1348,7 +1342,6 @@ static void kvm_destroy_vm(struct kvm *kvm)
preempt_notifier_dec(); preempt_notifier_dec();
hardware_disable_all(); hardware_disable_all();
mmdrop(mm); mmdrop(mm);
module_put(kvm_chardev_ops.owner);
} }
void kvm_get_kvm(struct kvm *kvm) void kvm_get_kvm(struct kvm *kvm)
...@@ -3887,7 +3880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp) ...@@ -3887,7 +3880,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
return 0; return 0;
} }
static const struct file_operations kvm_vcpu_fops = { static struct file_operations kvm_vcpu_fops = {
.release = kvm_vcpu_release, .release = kvm_vcpu_release,
.unlocked_ioctl = kvm_vcpu_ioctl, .unlocked_ioctl = kvm_vcpu_ioctl,
.mmap = kvm_vcpu_mmap, .mmap = kvm_vcpu_mmap,
...@@ -4081,6 +4074,7 @@ static int kvm_vcpu_stats_release(struct inode *inode, struct file *file) ...@@ -4081,6 +4074,7 @@ static int kvm_vcpu_stats_release(struct inode *inode, struct file *file)
} }
static const struct file_operations kvm_vcpu_stats_fops = { static const struct file_operations kvm_vcpu_stats_fops = {
.owner = THIS_MODULE,
.read = kvm_vcpu_stats_read, .read = kvm_vcpu_stats_read,
.release = kvm_vcpu_stats_release, .release = kvm_vcpu_stats_release,
.llseek = noop_llseek, .llseek = noop_llseek,
...@@ -4431,7 +4425,7 @@ static int kvm_device_release(struct inode *inode, struct file *filp) ...@@ -4431,7 +4425,7 @@ static int kvm_device_release(struct inode *inode, struct file *filp)
return 0; return 0;
} }
static const struct file_operations kvm_device_fops = { static struct file_operations kvm_device_fops = {
.unlocked_ioctl = kvm_device_ioctl, .unlocked_ioctl = kvm_device_ioctl,
.release = kvm_device_release, .release = kvm_device_release,
KVM_COMPAT(kvm_device_ioctl), KVM_COMPAT(kvm_device_ioctl),
...@@ -4759,6 +4753,7 @@ static int kvm_vm_stats_release(struct inode *inode, struct file *file) ...@@ -4759,6 +4753,7 @@ static int kvm_vm_stats_release(struct inode *inode, struct file *file)
} }
static const struct file_operations kvm_vm_stats_fops = { static const struct file_operations kvm_vm_stats_fops = {
.owner = THIS_MODULE,
.read = kvm_vm_stats_read, .read = kvm_vm_stats_read,
.release = kvm_vm_stats_release, .release = kvm_vm_stats_release,
.llseek = noop_llseek, .llseek = noop_llseek,
...@@ -5060,7 +5055,7 @@ static long kvm_vm_compat_ioctl(struct file *filp, ...@@ -5060,7 +5055,7 @@ static long kvm_vm_compat_ioctl(struct file *filp,
} }
#endif #endif
static const struct file_operations kvm_vm_fops = { static struct file_operations kvm_vm_fops = {
.release = kvm_vm_release, .release = kvm_vm_release,
.unlocked_ioctl = kvm_vm_ioctl, .unlocked_ioctl = kvm_vm_ioctl,
.llseek = noop_llseek, .llseek = noop_llseek,
...@@ -6095,6 +6090,9 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module) ...@@ -6095,6 +6090,9 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align, struct module *module)
goto err_async_pf; goto err_async_pf;
kvm_chardev_ops.owner = module; kvm_chardev_ops.owner = module;
kvm_vm_fops.owner = module;
kvm_vcpu_fops.owner = module;
kvm_device_fops.owner = module;
kvm_preempt_ops.sched_in = kvm_sched_in; kvm_preempt_ops.sched_in = kvm_sched_in;
kvm_preempt_ops.sched_out = kvm_sched_out; kvm_preempt_ops.sched_out = kvm_sched_out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment