File tree Expand file tree Collapse file tree 3 files changed +39
-22
lines changed Expand file tree Collapse file tree 3 files changed +39
-22
lines changed Original file line number Diff line number Diff line change @@ -207,9 +207,13 @@ static int vfio_df_group_open(struct vfio_device_file *df)
207
207
}
208
208
209
209
ret = vfio_df_open (df );
210
- if (ret ) {
211
- df -> iommufd = NULL ;
210
+ if (ret )
212
211
goto out_put_kvm ;
212
+
213
+ if (df -> iommufd && device -> open_count == 1 ) {
214
+ ret = vfio_iommufd_compat_attach_ioas (device , df -> iommufd );
215
+ if (ret )
216
+ goto out_close_device ;
213
217
}
214
218
215
219
/*
@@ -218,12 +222,17 @@ static int vfio_df_group_open(struct vfio_device_file *df)
218
222
*/
219
223
smp_store_release (& df -> access_granted , true);
220
224
225
+ mutex_unlock (& device -> dev_set -> lock );
226
+ mutex_unlock (& device -> group -> group_lock );
227
+ return 0 ;
228
+
229
+ out_close_device :
230
+ vfio_df_close (df );
221
231
out_put_kvm :
232
+ df -> iommufd = NULL ;
222
233
if (device -> open_count == 0 )
223
234
vfio_device_put_kvm (device );
224
-
225
235
mutex_unlock (& device -> dev_set -> lock );
226
-
227
236
out_unlock :
228
237
mutex_unlock (& device -> group -> group_lock );
229
238
return ret ;
Original file line number Diff line number Diff line change @@ -20,33 +20,32 @@ bool vfio_iommufd_device_has_compat_ioas(struct vfio_device *vdev,
20
20
21
21
int vfio_iommufd_bind (struct vfio_device * vdev , struct iommufd_ctx * ictx )
22
22
{
23
- u32 ioas_id ;
24
23
u32 device_id ;
24
+
25
+ lockdep_assert_held (& vdev -> dev_set -> lock );
26
+
27
+ /* The legacy path has no way to return the device id */
28
+ return vdev -> ops -> bind_iommufd (vdev , ictx , & device_id );
29
+ }
30
+
31
+ int vfio_iommufd_compat_attach_ioas (struct vfio_device * vdev ,
32
+ struct iommufd_ctx * ictx )
33
+ {
34
+ u32 ioas_id ;
25
35
int ret ;
26
36
27
37
lockdep_assert_held (& vdev -> dev_set -> lock );
28
38
29
- ret = vdev -> ops -> bind_iommufd ( vdev , ictx , & device_id );
30
- if (ret )
31
- return ret ;
39
+ /* compat noiommu does not need to do ioas attach */
40
+ if (vfio_device_is_noiommu ( vdev ) )
41
+ return 0 ;
32
42
33
43
ret = iommufd_vfio_compat_ioas_get_id (ictx , & ioas_id );
34
44
if (ret )
35
- goto err_unbind ;
36
- ret = vdev -> ops -> attach_ioas (vdev , & ioas_id );
37
- if (ret )
38
- goto err_unbind ;
39
-
40
- /*
41
- * The legacy path has no way to return the device id or the selected
42
- * pt_id
43
- */
44
- return 0 ;
45
+ return ret ;
45
46
46
- err_unbind :
47
- if (vdev -> ops -> unbind_iommufd )
48
- vdev -> ops -> unbind_iommufd (vdev );
49
- return ret ;
47
+ /* The legacy path has no way to return the selected pt_id */
48
+ return vdev -> ops -> attach_ioas (vdev , & ioas_id );
50
49
}
51
50
52
51
void vfio_iommufd_unbind (struct vfio_device * vdev )
Original file line number Diff line number Diff line change @@ -238,6 +238,8 @@ bool vfio_iommufd_device_has_compat_ioas(struct vfio_device *vdev,
238
238
struct iommufd_ctx * ictx );
239
239
int vfio_iommufd_bind (struct vfio_device * device , struct iommufd_ctx * ictx );
240
240
void vfio_iommufd_unbind (struct vfio_device * device );
241
+ int vfio_iommufd_compat_attach_ioas (struct vfio_device * device ,
242
+ struct iommufd_ctx * ictx );
241
243
#else
242
244
static inline bool
243
245
vfio_iommufd_device_has_compat_ioas (struct vfio_device * vdev ,
@@ -255,6 +257,13 @@ static inline int vfio_iommufd_bind(struct vfio_device *device,
255
257
static inline void vfio_iommufd_unbind (struct vfio_device * device )
256
258
{
257
259
}
260
+
261
+ static inline int
262
+ vfio_iommufd_compat_attach_ioas (struct vfio_device * device ,
263
+ struct iommufd_ctx * ictx )
264
+ {
265
+ return - EOPNOTSUPP ;
266
+ }
258
267
#endif
259
268
260
269
#if IS_ENABLED (CONFIG_VFIO_VIRQFD )
You can’t perform that action at this time.
0 commit comments