mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 09:36:22 +02:00
KVM VFIO changes for 7.2
Use guard() to cleanup up various KVM+VFIO flows. -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEKTobbabEP7vbhhN9OlYIJqCjN/0FAmorRDwACgkQOlYIJqCj N/2bDRAAo2Kvt1GCfVWSrhgvRIcjoil3JYUhrtKnCTqj7DoMFv3q97PnNQt3eCHC K7RcjhoTYuMZjWLnzpYFgV2L2WIUOXrJJvHtiK5FvcmoENRy+4drDaowVQXXx6TX T0mWJ0MK8v5z+cr6JI9/dfv8a73j6PtOaAkL2QlYOScGvNz55jOmob4M+zemMypP 7urPQa7EiSbYzZOn7dWx6gt3waOQOBPN/jaDWbI+uLZQooIVe9xtbsqFyWE0maJt p6caai2bVAu8R8V87VhOgJr8bcgjYRC6gL9QeFIZiEjglEkDbmdJcJdJ3n76T7Us NexazthWdYDLAIQjwaEzJo+Z2jZzmiLkRNhXkcQl0MTzi7BhmqoJtuivlG/toKMr k4D4mxjZvoPu53qGFZOG3mmCy+tKOBE+pk/GRWZEJL1FE4+yuc/rkMgrT2cg8K8F K8ZgWMyddhSNbDRLoy7w7SB7byjVo3BRMdJ1Kbww3p9ffEHNogdouvOuVgIg92hd I8sUC0vKopuwFbQnDIok82AWwjVrjp4QDBCs9F1ksf0tutJLCLzqNfjjYLL2U/UY FxVe8VVeRTzEdlxN1KG/kUC00/3HlFuh9PfQxy6yMGZ8uZ9PUkYX+8zxHwuXaHhW bLZ/6JuzxBL6kepAd74sz1x/6U4KsiDm4PFKXZpIaaBwwONIp20= =bz6q -----END PGP SIGNATURE----- Merge tag 'kvm-x86-vfio-7.2' of https://github.com/kvm-x86/linux into HEAD KVM VFIO changes for 7.2 Use guard() to cleanup up various KVM+VFIO flows.
This commit is contained in:
commit
3ef8a08e22
|
|
@ -144,33 +144,26 @@ static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd)
|
|||
{
|
||||
struct kvm_vfio *kv = dev->private;
|
||||
struct kvm_vfio_file *kvf;
|
||||
struct file *filp;
|
||||
int ret = 0;
|
||||
struct file *filp __free(fput) = NULL;
|
||||
|
||||
filp = fget(fd);
|
||||
if (!filp)
|
||||
return -EBADF;
|
||||
|
||||
/* Ensure the FD is a vfio FD. */
|
||||
if (!kvm_vfio_file_is_valid(filp)) {
|
||||
ret = -EINVAL;
|
||||
goto out_fput;
|
||||
}
|
||||
if (!kvm_vfio_file_is_valid(filp))
|
||||
return -EINVAL;
|
||||
|
||||
mutex_lock(&kv->lock);
|
||||
guard(mutex)(&kv->lock);
|
||||
|
||||
list_for_each_entry(kvf, &kv->file_list, node) {
|
||||
if (kvf->file == filp) {
|
||||
ret = -EEXIST;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (kvf->file == filp)
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
kvf = kzalloc_obj(*kvf, GFP_KERNEL_ACCOUNT);
|
||||
if (!kvf) {
|
||||
ret = -ENOMEM;
|
||||
goto out_unlock;
|
||||
}
|
||||
if (!kvf)
|
||||
return -ENOMEM;
|
||||
|
||||
kvf->file = get_file(filp);
|
||||
list_add_tail(&kvf->node, &kv->file_list);
|
||||
|
|
@ -178,11 +171,18 @@ static int kvm_vfio_file_add(struct kvm_device *dev, unsigned int fd)
|
|||
kvm_vfio_file_set_kvm(kvf->file, dev->kvm);
|
||||
kvm_vfio_update_coherency(dev);
|
||||
|
||||
out_unlock:
|
||||
mutex_unlock(&kv->lock);
|
||||
out_fput:
|
||||
fput(filp);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void kvm_vfio_file_free(struct kvm_device *dev, struct kvm_vfio_file *kvf)
|
||||
{
|
||||
#ifdef CONFIG_SPAPR_TCE_IOMMU
|
||||
kvm_spapr_tce_release_vfio_group(dev->kvm, kvf);
|
||||
#endif
|
||||
kvm_vfio_file_set_kvm(kvf->file, NULL);
|
||||
fput(kvf->file);
|
||||
list_del(&kvf->node);
|
||||
kfree(kvf);
|
||||
}
|
||||
|
||||
static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
|
||||
|
|
@ -190,34 +190,21 @@ static int kvm_vfio_file_del(struct kvm_device *dev, unsigned int fd)
|
|||
struct kvm_vfio *kv = dev->private;
|
||||
struct kvm_vfio_file *kvf;
|
||||
CLASS(fd, f)(fd);
|
||||
int ret;
|
||||
|
||||
if (fd_empty(f))
|
||||
return -EBADF;
|
||||
|
||||
ret = -ENOENT;
|
||||
|
||||
mutex_lock(&kv->lock);
|
||||
guard(mutex)(&kv->lock);
|
||||
|
||||
list_for_each_entry(kvf, &kv->file_list, node) {
|
||||
if (kvf->file != fd_file(f))
|
||||
continue;
|
||||
|
||||
list_del(&kvf->node);
|
||||
#ifdef CONFIG_SPAPR_TCE_IOMMU
|
||||
kvm_spapr_tce_release_vfio_group(dev->kvm, kvf);
|
||||
#endif
|
||||
kvm_vfio_file_set_kvm(kvf->file, NULL);
|
||||
fput(kvf->file);
|
||||
kfree(kvf);
|
||||
ret = 0;
|
||||
break;
|
||||
if (kvf->file == fd_file(f)) {
|
||||
kvm_vfio_file_free(dev, kvf);
|
||||
kvm_vfio_update_coherency(dev);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
kvm_vfio_update_coherency(dev);
|
||||
|
||||
mutex_unlock(&kv->lock);
|
||||
return ret;
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SPAPR_TCE_IOMMU
|
||||
|
|
@ -227,7 +214,6 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
|
|||
struct kvm_vfio_spapr_tce param;
|
||||
struct kvm_vfio *kv = dev->private;
|
||||
struct kvm_vfio_file *kvf;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(¶m, arg, sizeof(struct kvm_vfio_spapr_tce)))
|
||||
return -EFAULT;
|
||||
|
|
@ -236,9 +222,7 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
|
|||
if (fd_empty(f))
|
||||
return -EBADF;
|
||||
|
||||
ret = -ENOENT;
|
||||
|
||||
mutex_lock(&kv->lock);
|
||||
guard(mutex)(&kv->lock);
|
||||
|
||||
list_for_each_entry(kvf, &kv->file_list, node) {
|
||||
if (kvf->file != fd_file(f))
|
||||
|
|
@ -246,20 +230,15 @@ static int kvm_vfio_file_set_spapr_tce(struct kvm_device *dev,
|
|||
|
||||
if (!kvf->iommu_group) {
|
||||
kvf->iommu_group = kvm_vfio_file_iommu_group(kvf->file);
|
||||
if (WARN_ON_ONCE(!kvf->iommu_group)) {
|
||||
ret = -EIO;
|
||||
goto err_fdput;
|
||||
}
|
||||
if (WARN_ON_ONCE(!kvf->iommu_group))
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = kvm_spapr_tce_attach_iommu_group(dev->kvm, param.tablefd,
|
||||
kvf->iommu_group);
|
||||
break;
|
||||
return kvm_spapr_tce_attach_iommu_group(dev->kvm, param.tablefd,
|
||||
kvf->iommu_group);
|
||||
}
|
||||
|
||||
err_fdput:
|
||||
mutex_unlock(&kv->lock);
|
||||
return ret;
|
||||
return -ENOENT;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -326,15 +305,8 @@ static void kvm_vfio_release(struct kvm_device *dev)
|
|||
struct kvm_vfio *kv = dev->private;
|
||||
struct kvm_vfio_file *kvf, *tmp;
|
||||
|
||||
list_for_each_entry_safe(kvf, tmp, &kv->file_list, node) {
|
||||
#ifdef CONFIG_SPAPR_TCE_IOMMU
|
||||
kvm_spapr_tce_release_vfio_group(dev->kvm, kvf);
|
||||
#endif
|
||||
kvm_vfio_file_set_kvm(kvf->file, NULL);
|
||||
fput(kvf->file);
|
||||
list_del(&kvf->node);
|
||||
kfree(kvf);
|
||||
}
|
||||
list_for_each_entry_safe(kvf, tmp, &kv->file_list, node)
|
||||
kvm_vfio_file_free(dev, kvf);
|
||||
|
||||
kvm_vfio_update_coherency(dev);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user