Skip to content

Commit 8cfa718

Browse files
yiliu1765awilliam
authored andcommitted
vfio-iommufd: Add detach_ioas support for emulated VFIO devices
This prepares for adding DETACH ioctl for emulated VFIO devices. Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Tested-by: Terrence Xu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Tested-by: Matthew Rosato <[email protected]> Tested-by: Yanting Jiang <[email protected]> Tested-by: Shameer Kolothum <[email protected]> Tested-by: Zhenzhong Duan <[email protected]> Signed-off-by: Yi Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alex Williamson <[email protected]>
1 parent e23a621 commit 8cfa718

File tree

8 files changed

+22
-0
lines changed

8 files changed

+22
-0
lines changed

drivers/gpu/drm/i915/gvt/kvmgt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ static const struct vfio_device_ops intel_vgpu_dev_ops = {
14741474
.bind_iommufd = vfio_iommufd_emulated_bind,
14751475
.unbind_iommufd = vfio_iommufd_emulated_unbind,
14761476
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
1477+
.detach_ioas = vfio_iommufd_emulated_detach_ioas,
14771478
};
14781479

14791480
static int intel_vgpu_probe(struct mdev_device *mdev)

drivers/s390/cio/vfio_ccw_ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,7 @@ static const struct vfio_device_ops vfio_ccw_dev_ops = {
632632
.bind_iommufd = vfio_iommufd_emulated_bind,
633633
.unbind_iommufd = vfio_iommufd_emulated_unbind,
634634
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
635+
.detach_ioas = vfio_iommufd_emulated_detach_ioas,
635636
};
636637

637638
struct mdev_driver vfio_ccw_mdev_driver = {

drivers/s390/crypto/vfio_ap_ops.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,7 @@ static const struct vfio_device_ops vfio_ap_matrix_dev_ops = {
19751975
.bind_iommufd = vfio_iommufd_emulated_bind,
19761976
.unbind_iommufd = vfio_iommufd_emulated_unbind,
19771977
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
1978+
.detach_ioas = vfio_iommufd_emulated_detach_ioas,
19781979
.request = vfio_ap_mdev_request
19791980
};
19801981

drivers/vfio/iommufd.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,16 @@ int vfio_iommufd_emulated_attach_ioas(struct vfio_device *vdev, u32 *pt_id)
231231
return 0;
232232
}
233233
EXPORT_SYMBOL_GPL(vfio_iommufd_emulated_attach_ioas);
234+
235+
void vfio_iommufd_emulated_detach_ioas(struct vfio_device *vdev)
236+
{
237+
lockdep_assert_held(&vdev->dev_set->lock);
238+
239+
if (WARN_ON(!vdev->iommufd_access) ||
240+
!vdev->iommufd_attached)
241+
return;
242+
243+
iommufd_access_detach(vdev->iommufd_access);
244+
vdev->iommufd_attached = false;
245+
}
246+
EXPORT_SYMBOL_GPL(vfio_iommufd_emulated_detach_ioas);

include/linux/vfio.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ int vfio_iommufd_emulated_bind(struct vfio_device *vdev,
128128
struct iommufd_ctx *ictx, u32 *out_device_id);
129129
void vfio_iommufd_emulated_unbind(struct vfio_device *vdev);
130130
int vfio_iommufd_emulated_attach_ioas(struct vfio_device *vdev, u32 *pt_id);
131+
void vfio_iommufd_emulated_detach_ioas(struct vfio_device *vdev);
131132
#else
132133
static inline struct iommufd_ctx *
133134
vfio_iommufd_device_ictx(struct vfio_device *vdev)
@@ -157,6 +158,8 @@ vfio_iommufd_get_dev_id(struct vfio_device *vdev, struct iommufd_ctx *ictx)
157158
((void (*)(struct vfio_device *vdev)) NULL)
158159
#define vfio_iommufd_emulated_attach_ioas \
159160
((int (*)(struct vfio_device *vdev, u32 *pt_id)) NULL)
161+
#define vfio_iommufd_emulated_detach_ioas \
162+
((void (*)(struct vfio_device *vdev)) NULL)
160163
#endif
161164

162165
static inline bool vfio_device_cdev_opened(struct vfio_device *device)

samples/vfio-mdev/mbochs.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ static const struct vfio_device_ops mbochs_dev_ops = {
13771377
.bind_iommufd = vfio_iommufd_emulated_bind,
13781378
.unbind_iommufd = vfio_iommufd_emulated_unbind,
13791379
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
1380+
.detach_ioas = vfio_iommufd_emulated_detach_ioas,
13801381
};
13811382

13821383
static struct mdev_driver mbochs_driver = {

samples/vfio-mdev/mdpy.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ static const struct vfio_device_ops mdpy_dev_ops = {
666666
.bind_iommufd = vfio_iommufd_emulated_bind,
667667
.unbind_iommufd = vfio_iommufd_emulated_unbind,
668668
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
669+
.detach_ioas = vfio_iommufd_emulated_detach_ioas,
669670
};
670671

671672
static struct mdev_driver mdpy_driver = {

samples/vfio-mdev/mtty.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ static const struct vfio_device_ops mtty_dev_ops = {
12721272
.bind_iommufd = vfio_iommufd_emulated_bind,
12731273
.unbind_iommufd = vfio_iommufd_emulated_unbind,
12741274
.attach_ioas = vfio_iommufd_emulated_attach_ioas,
1275+
.detach_ioas = vfio_iommufd_emulated_detach_ioas,
12751276
};
12761277

12771278
static struct mdev_driver mtty_driver = {

0 commit comments

Comments
 (0)