Commit ba70a89f authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Alex Williamson

vfio: Change vfio_group_set_kvm() to vfio_file_set_kvm()

Just change the argument from struct vfio_group to struct file *.
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/6-v3-f7729924a7ea+25e33-vfio_kvm_no_group_jgg@nvidia.comSigned-off-by: default avatarAlex Williamson <alex.williamson@redhat.com>
parent a905ad04
...@@ -1731,6 +1731,27 @@ bool vfio_file_enforced_coherent(struct file *file) ...@@ -1731,6 +1731,27 @@ bool vfio_file_enforced_coherent(struct file *file)
} }
EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent); EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent);
/**
* vfio_file_set_kvm - Link a kvm with VFIO drivers
* @file: VFIO group file
* @kvm: KVM to link
*
* The kvm pointer will be forwarded to all the vfio_device's attached to the
* VFIO file via the VFIO_GROUP_NOTIFY_SET_KVM notifier.
*/
void vfio_file_set_kvm(struct file *file, struct kvm *kvm)
{
struct vfio_group *group = file->private_data;
if (file->f_op != &vfio_group_fops)
return;
group->kvm = kvm;
blocking_notifier_call_chain(&group->notifier,
VFIO_GROUP_NOTIFY_SET_KVM, kvm);
}
EXPORT_SYMBOL_GPL(vfio_file_set_kvm);
/* /*
* Sub-module support * Sub-module support
*/ */
...@@ -1999,14 +2020,6 @@ static int vfio_unregister_iommu_notifier(struct vfio_group *group, ...@@ -1999,14 +2020,6 @@ static int vfio_unregister_iommu_notifier(struct vfio_group *group,
return ret; return ret;
} }
void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
{
group->kvm = kvm;
blocking_notifier_call_chain(&group->notifier,
VFIO_GROUP_NOTIFY_SET_KVM, kvm);
}
EXPORT_SYMBOL_GPL(vfio_group_set_kvm);
static int vfio_register_group_notifier(struct vfio_group *group, static int vfio_register_group_notifier(struct vfio_group *group,
unsigned long *events, unsigned long *events,
struct notifier_block *nb) struct notifier_block *nb)
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <linux/poll.h> #include <linux/poll.h>
#include <uapi/linux/vfio.h> #include <uapi/linux/vfio.h>
struct kvm;
/* /*
* VFIO devices can be placed in a set, this allows all devices to share this * VFIO devices can be placed in a set, this allows all devices to share this
* structure and the VFIO core will provide a lock that is held around * structure and the VFIO core will provide a lock that is held around
...@@ -140,6 +142,7 @@ extern struct vfio_group *vfio_group_get_external_user(struct file *filep); ...@@ -140,6 +142,7 @@ extern struct vfio_group *vfio_group_get_external_user(struct file *filep);
extern void vfio_group_put_external_user(struct vfio_group *group); extern void vfio_group_put_external_user(struct vfio_group *group);
extern struct iommu_group *vfio_file_iommu_group(struct file *file); extern struct iommu_group *vfio_file_iommu_group(struct file *file);
extern bool vfio_file_enforced_coherent(struct file *file); extern bool vfio_file_enforced_coherent(struct file *file);
extern void vfio_file_set_kvm(struct file *file, struct kvm *kvm);
#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long)) #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
...@@ -170,8 +173,6 @@ extern int vfio_unregister_notifier(struct vfio_device *device, ...@@ -170,8 +173,6 @@ extern int vfio_unregister_notifier(struct vfio_device *device,
enum vfio_notify_type type, enum vfio_notify_type type,
struct notifier_block *nb); struct notifier_block *nb);
struct kvm;
extern void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm);
/* /*
* Sub-module helpers * Sub-module helpers
......
...@@ -62,17 +62,17 @@ static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group) ...@@ -62,17 +62,17 @@ static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group)
symbol_put(vfio_group_put_external_user); symbol_put(vfio_group_put_external_user);
} }
static void kvm_vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm) static void kvm_vfio_file_set_kvm(struct file *file, struct kvm *kvm)
{ {
void (*fn)(struct vfio_group *, struct kvm *); void (*fn)(struct file *file, struct kvm *kvm);
fn = symbol_get(vfio_group_set_kvm); fn = symbol_get(vfio_file_set_kvm);
if (!fn) if (!fn)
return; return;
fn(group, kvm); fn(file, kvm);
symbol_put(vfio_group_set_kvm); symbol_put(vfio_file_set_kvm);
} }
static bool kvm_vfio_file_enforced_coherent(struct file *file) static bool kvm_vfio_file_enforced_coherent(struct file *file)
...@@ -195,7 +195,7 @@ static int kvm_vfio_group_add(struct kvm_device *dev, unsigned int fd) ...@@ -195,7 +195,7 @@ static int kvm_vfio_group_add(struct kvm_device *dev, unsigned int fd)
mutex_unlock(&kv->lock); mutex_unlock(&kv->lock);
kvm_vfio_group_set_kvm(vfio_group, dev->kvm); kvm_vfio_file_set_kvm(kvg->file, dev->kvm);
kvm_vfio_update_coherency(dev); kvm_vfio_update_coherency(dev);
return 0; return 0;
...@@ -231,7 +231,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd) ...@@ -231,7 +231,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd)
#ifdef CONFIG_SPAPR_TCE_IOMMU #ifdef CONFIG_SPAPR_TCE_IOMMU
kvm_spapr_tce_release_vfio_group(dev->kvm, kvg); kvm_spapr_tce_release_vfio_group(dev->kvm, kvg);
#endif #endif
kvm_vfio_group_set_kvm(kvg->vfio_group, NULL); kvm_vfio_file_set_kvm(kvg->file, NULL);
kvm_vfio_group_put_external_user(kvg->vfio_group); kvm_vfio_group_put_external_user(kvg->vfio_group);
fput(kvg->file); fput(kvg->file);
kfree(kvg); kfree(kvg);
...@@ -360,7 +360,7 @@ static void kvm_vfio_destroy(struct kvm_device *dev) ...@@ -360,7 +360,7 @@ static void kvm_vfio_destroy(struct kvm_device *dev)
#ifdef CONFIG_SPAPR_TCE_IOMMU #ifdef CONFIG_SPAPR_TCE_IOMMU
kvm_spapr_tce_release_vfio_group(dev->kvm, kvg); kvm_spapr_tce_release_vfio_group(dev->kvm, kvg);
#endif #endif
kvm_vfio_group_set_kvm(kvg->vfio_group, NULL); kvm_vfio_file_set_kvm(kvg->file, NULL);
kvm_vfio_group_put_external_user(kvg->vfio_group); kvm_vfio_group_put_external_user(kvg->vfio_group);
fput(kvg->file); fput(kvg->file);
list_del(&kvg->node); list_del(&kvg->node);
......
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