Skip to content

Commit ba70a89

Browse files
jgunthorpeawilliam
authored andcommitted
vfio: Change vfio_group_set_kvm() to vfio_file_set_kvm()
Just change the argument from struct vfio_group to struct file *. Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent a905ad0 commit ba70a89

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

drivers/vfio/vfio.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,27 @@ bool vfio_file_enforced_coherent(struct file *file)
17311731
}
17321732
EXPORT_SYMBOL_GPL(vfio_file_enforced_coherent);
17331733

1734+
/**
1735+
* vfio_file_set_kvm - Link a kvm with VFIO drivers
1736+
* @file: VFIO group file
1737+
* @kvm: KVM to link
1738+
*
1739+
* The kvm pointer will be forwarded to all the vfio_device's attached to the
1740+
* VFIO file via the VFIO_GROUP_NOTIFY_SET_KVM notifier.
1741+
*/
1742+
void vfio_file_set_kvm(struct file *file, struct kvm *kvm)
1743+
{
1744+
struct vfio_group *group = file->private_data;
1745+
1746+
if (file->f_op != &vfio_group_fops)
1747+
return;
1748+
1749+
group->kvm = kvm;
1750+
blocking_notifier_call_chain(&group->notifier,
1751+
VFIO_GROUP_NOTIFY_SET_KVM, kvm);
1752+
}
1753+
EXPORT_SYMBOL_GPL(vfio_file_set_kvm);
1754+
17341755
/*
17351756
* Sub-module support
17361757
*/
@@ -1999,14 +2020,6 @@ static int vfio_unregister_iommu_notifier(struct vfio_group *group,
19992020
return ret;
20002021
}
20012022

2002-
void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
2003-
{
2004-
group->kvm = kvm;
2005-
blocking_notifier_call_chain(&group->notifier,
2006-
VFIO_GROUP_NOTIFY_SET_KVM, kvm);
2007-
}
2008-
EXPORT_SYMBOL_GPL(vfio_group_set_kvm);
2009-
20102023
static int vfio_register_group_notifier(struct vfio_group *group,
20112024
unsigned long *events,
20122025
struct notifier_block *nb)

include/linux/vfio.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <linux/poll.h>
1616
#include <uapi/linux/vfio.h>
1717

18+
struct kvm;
19+
1820
/*
1921
* VFIO devices can be placed in a set, this allows all devices to share this
2022
* 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);
140142
extern void vfio_group_put_external_user(struct vfio_group *group);
141143
extern struct iommu_group *vfio_file_iommu_group(struct file *file);
142144
extern bool vfio_file_enforced_coherent(struct file *file);
145+
extern void vfio_file_set_kvm(struct file *file, struct kvm *kvm);
143146

144147
#define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))
145148

@@ -170,8 +173,6 @@ extern int vfio_unregister_notifier(struct vfio_device *device,
170173
enum vfio_notify_type type,
171174
struct notifier_block *nb);
172175

173-
struct kvm;
174-
extern void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm);
175176

176177
/*
177178
* Sub-module helpers

virt/kvm/vfio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ static void kvm_vfio_group_put_external_user(struct vfio_group *vfio_group)
6262
symbol_put(vfio_group_put_external_user);
6363
}
6464

65-
static void kvm_vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
65+
static void kvm_vfio_file_set_kvm(struct file *file, struct kvm *kvm)
6666
{
67-
void (*fn)(struct vfio_group *, struct kvm *);
67+
void (*fn)(struct file *file, struct kvm *kvm);
6868

69-
fn = symbol_get(vfio_group_set_kvm);
69+
fn = symbol_get(vfio_file_set_kvm);
7070
if (!fn)
7171
return;
7272

73-
fn(group, kvm);
73+
fn(file, kvm);
7474

75-
symbol_put(vfio_group_set_kvm);
75+
symbol_put(vfio_file_set_kvm);
7676
}
7777

7878
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)
195195

196196
mutex_unlock(&kv->lock);
197197

198-
kvm_vfio_group_set_kvm(vfio_group, dev->kvm);
198+
kvm_vfio_file_set_kvm(kvg->file, dev->kvm);
199199
kvm_vfio_update_coherency(dev);
200200

201201
return 0;
@@ -231,7 +231,7 @@ static int kvm_vfio_group_del(struct kvm_device *dev, unsigned int fd)
231231
#ifdef CONFIG_SPAPR_TCE_IOMMU
232232
kvm_spapr_tce_release_vfio_group(dev->kvm, kvg);
233233
#endif
234-
kvm_vfio_group_set_kvm(kvg->vfio_group, NULL);
234+
kvm_vfio_file_set_kvm(kvg->file, NULL);
235235
kvm_vfio_group_put_external_user(kvg->vfio_group);
236236
fput(kvg->file);
237237
kfree(kvg);
@@ -360,7 +360,7 @@ static void kvm_vfio_destroy(struct kvm_device *dev)
360360
#ifdef CONFIG_SPAPR_TCE_IOMMU
361361
kvm_spapr_tce_release_vfio_group(dev->kvm, kvg);
362362
#endif
363-
kvm_vfio_group_set_kvm(kvg->vfio_group, NULL);
363+
kvm_vfio_file_set_kvm(kvg->file, NULL);
364364
kvm_vfio_group_put_external_user(kvg->vfio_group);
365365
fput(kvg->file);
366366
list_del(&kvg->node);

0 commit comments

Comments
 (0)