Skip to content

Commit

Permalink
vfio: Test kvm pointer in _vfio_device_get_kvm_safe()
Browse files Browse the repository at this point in the history
This saves some lines when adding the kvm get logic for the vfio_device
cdev path.

This also renames _vfio_device_get_kvm_safe() to be vfio_device_get_kvm_safe().

Suggested-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Tested-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Tested-by: Yanting Jiang <yanting.jiang@intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Link: https://lore.kernel.org/r/20230718135551.6592-20-yi.l.liu@intel.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
  • Loading branch information
Yi Liu authored and Alex Williamson committed Jul 25, 2023
1 parent 8b6f173 commit 5c6de3e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
7 changes: 1 addition & 6 deletions drivers/vfio/group.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,7 @@ static int vfio_group_ioctl_set_container(struct vfio_group *group,
static void vfio_device_group_get_kvm_safe(struct vfio_device *device)
{
spin_lock(&device->group->kvm_ref_lock);
if (!device->group->kvm)
goto unlock;

_vfio_device_get_kvm_safe(device, device->group->kvm);

unlock:
vfio_device_get_kvm_safe(device, device->group->kvm);
spin_unlock(&device->group->kvm_ref_lock);
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/vfio/vfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,11 @@ enum { vfio_noiommu = false };
#endif

#ifdef CONFIG_HAVE_KVM
void _vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm);
void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm);
void vfio_device_put_kvm(struct vfio_device *device);
#else
static inline void _vfio_device_get_kvm_safe(struct vfio_device *device,
struct kvm *kvm)
static inline void vfio_device_get_kvm_safe(struct vfio_device *device,
struct kvm *kvm)
{
}

Expand Down
5 changes: 4 additions & 1 deletion drivers/vfio/vfio_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,14 +373,17 @@ void vfio_unregister_group_dev(struct vfio_device *device)
EXPORT_SYMBOL_GPL(vfio_unregister_group_dev);

#ifdef CONFIG_HAVE_KVM
void _vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm)
void vfio_device_get_kvm_safe(struct vfio_device *device, struct kvm *kvm)
{
void (*pfn)(struct kvm *kvm);
bool (*fn)(struct kvm *kvm);
bool ret;

lockdep_assert_held(&device->dev_set->lock);

if (!kvm)
return;

pfn = symbol_get(kvm_put_kvm);
if (WARN_ON(!pfn))
return;
Expand Down

0 comments on commit 5c6de3e

Please sign in to comment.