diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index a5a62d9d963f..2167452c2499 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -479,6 +479,19 @@ void vfio_device_put_kvm(struct vfio_device *device) clear: device->kvm = NULL; } + +static struct vfio_device *vfio_device_from_file(struct file *file); +/** + * vfio_file_get_device - Return struct device from vfio device fd + * @file: VFIO device file + */ +struct device *vfio_file_get_device(struct file *file) +{ + struct vfio_device *device = vfio_device_from_file(file); + + return device ? device->dev : NULL; +} +EXPORT_SYMBOL_GPL(vfio_file_get_device); #endif /* true if the vfio_device has open_device() called but not close_device() */ diff --git a/include/linux/vfio.h b/include/linux/vfio.h index 000a6cab2d31..861bbeaa3d86 100644 --- a/include/linux/vfio.h +++ b/include/linux/vfio.h @@ -316,6 +316,7 @@ static inline bool vfio_file_has_dev(struct file *file, struct vfio_device *devi bool vfio_file_is_valid(struct file *file); bool vfio_file_enforced_coherent(struct file *file); void vfio_file_set_kvm(struct file *file, struct kvm *kvm); +struct device *vfio_file_get_device(struct file *file); #define VFIO_PIN_PAGES_MAX_ENTRIES (PAGE_SIZE/sizeof(unsigned long))