File tree Expand file tree Collapse file tree 3 files changed +30
-14
lines changed Expand file tree Collapse file tree 3 files changed +30
-14
lines changed Original file line number Diff line number Diff line change @@ -192,6 +192,19 @@ static int vfio_df_group_open(struct vfio_device_file *df)
192
192
vfio_device_group_get_kvm_safe (device );
193
193
194
194
df -> iommufd = device -> group -> iommufd ;
195
+ if (df -> iommufd && vfio_device_is_noiommu (device ) && device -> open_count == 0 ) {
196
+ /*
197
+ * Require no compat ioas to be assigned to proceed. The basic
198
+ * statement is that the user cannot have done something that
199
+ * implies they expected translation to exist
200
+ */
201
+ if (!capable (CAP_SYS_RAWIO ) ||
202
+ vfio_iommufd_device_has_compat_ioas (device , df -> iommufd ))
203
+ ret = - EPERM ;
204
+ else
205
+ ret = 0 ;
206
+ goto out_put_kvm ;
207
+ }
195
208
196
209
ret = vfio_df_open (df );
197
210
if (ret ) {
Original file line number Diff line number Diff line change 10
10
MODULE_IMPORT_NS (IOMMUFD );
11
11
MODULE_IMPORT_NS (IOMMUFD_VFIO );
12
12
13
+ bool vfio_iommufd_device_has_compat_ioas (struct vfio_device * vdev ,
14
+ struct iommufd_ctx * ictx )
15
+ {
16
+ u32 ioas_id ;
17
+
18
+ return !iommufd_vfio_compat_ioas_get_id (ictx , & ioas_id );
19
+ }
20
+
13
21
int vfio_iommufd_bind (struct vfio_device * vdev , struct iommufd_ctx * ictx )
14
22
{
15
23
u32 ioas_id ;
@@ -18,20 +26,6 @@ int vfio_iommufd_bind(struct vfio_device *vdev, struct iommufd_ctx *ictx)
18
26
19
27
lockdep_assert_held (& vdev -> dev_set -> lock );
20
28
21
- if (vfio_device_is_noiommu (vdev )) {
22
- if (!capable (CAP_SYS_RAWIO ))
23
- return - EPERM ;
24
-
25
- /*
26
- * Require no compat ioas to be assigned to proceed. The basic
27
- * statement is that the user cannot have done something that
28
- * implies they expected translation to exist
29
- */
30
- if (!iommufd_vfio_compat_ioas_get_id (ictx , & ioas_id ))
31
- return - EPERM ;
32
- return 0 ;
33
- }
34
-
35
29
ret = vdev -> ops -> bind_iommufd (vdev , ictx , & device_id );
36
30
if (ret )
37
31
return ret ;
Original file line number Diff line number Diff line change @@ -234,9 +234,18 @@ static inline void vfio_container_cleanup(void)
234
234
#endif
235
235
236
236
#if IS_ENABLED (CONFIG_IOMMUFD )
237
+ bool vfio_iommufd_device_has_compat_ioas (struct vfio_device * vdev ,
238
+ struct iommufd_ctx * ictx );
237
239
int vfio_iommufd_bind (struct vfio_device * device , struct iommufd_ctx * ictx );
238
240
void vfio_iommufd_unbind (struct vfio_device * device );
239
241
#else
242
+ static inline bool
243
+ vfio_iommufd_device_has_compat_ioas (struct vfio_device * vdev ,
244
+ struct iommufd_ctx * ictx )
245
+ {
246
+ return false;
247
+ }
248
+
240
249
static inline int vfio_iommufd_bind (struct vfio_device * device ,
241
250
struct iommufd_ctx * ictx )
242
251
{
You can’t perform that action at this time.
0 commit comments