@@ -123,8 +123,8 @@ struct iommu_group *vfio_iommu_group_get(struct device *dev)
123
123
/*
124
124
* With noiommu enabled, an IOMMU group will be created for a device
125
125
* that doesn't already have one and doesn't have an iommu_ops on their
126
- * bus. We use iommu_present() again in the main code to detect these
127
- * fake groups .
126
+ * bus. We set iommudata simply to be able to identify these groups
127
+ * as special use and for reclamation later .
128
128
*/
129
129
if (group || !noiommu || iommu_present (dev -> bus ))
130
130
return group ;
@@ -134,6 +134,7 @@ struct iommu_group *vfio_iommu_group_get(struct device *dev)
134
134
return NULL ;
135
135
136
136
iommu_group_set_name (group , "vfio-noiommu" );
137
+ iommu_group_set_iommudata (group , & noiommu , NULL );
137
138
ret = iommu_group_add_device (group , dev );
138
139
iommu_group_put (group );
139
140
if (ret )
@@ -158,7 +159,7 @@ EXPORT_SYMBOL_GPL(vfio_iommu_group_get);
158
159
void vfio_iommu_group_put (struct iommu_group * group , struct device * dev )
159
160
{
160
161
#ifdef CONFIG_VFIO_NOIOMMU
161
- if (! iommu_present ( dev -> bus ) )
162
+ if (iommu_group_get_iommudata ( group ) == & noiommu )
162
163
iommu_group_remove_device (dev );
163
164
#endif
164
165
@@ -190,16 +191,10 @@ static long vfio_noiommu_ioctl(void *iommu_data,
190
191
return - ENOTTY ;
191
192
}
192
193
193
- static int vfio_iommu_present (struct device * dev , void * unused )
194
- {
195
- return iommu_present (dev -> bus ) ? 1 : 0 ;
196
- }
197
-
198
194
static int vfio_noiommu_attach_group (void * iommu_data ,
199
195
struct iommu_group * iommu_group )
200
196
{
201
- return iommu_group_for_each_dev (iommu_group , NULL ,
202
- vfio_iommu_present ) ? - EINVAL : 0 ;
197
+ return iommu_group_get_iommudata (iommu_group ) == & noiommu ? 0 : - EINVAL ;
203
198
}
204
199
205
200
static void vfio_noiommu_detach_group (void * iommu_data ,
@@ -323,8 +318,7 @@ static void vfio_group_unlock_and_free(struct vfio_group *group)
323
318
/**
324
319
* Group objects - create, release, get, put, search
325
320
*/
326
- static struct vfio_group * vfio_create_group (struct iommu_group * iommu_group ,
327
- bool iommu_present )
321
+ static struct vfio_group * vfio_create_group (struct iommu_group * iommu_group )
328
322
{
329
323
struct vfio_group * group , * tmp ;
330
324
struct device * dev ;
@@ -342,7 +336,9 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group,
342
336
atomic_set (& group -> container_users , 0 );
343
337
atomic_set (& group -> opened , 0 );
344
338
group -> iommu_group = iommu_group ;
345
- group -> noiommu = !iommu_present ;
339
+ #ifdef CONFIG_VFIO_NOIOMMU
340
+ group -> noiommu = (iommu_group_get_iommudata (iommu_group ) == & noiommu );
341
+ #endif
346
342
347
343
group -> nb .notifier_call = vfio_iommu_group_notifier ;
348
344
@@ -767,7 +763,7 @@ int vfio_add_group_dev(struct device *dev,
767
763
768
764
group = vfio_group_get_from_iommu (iommu_group );
769
765
if (!group ) {
770
- group = vfio_create_group (iommu_group , iommu_present ( dev -> bus ) );
766
+ group = vfio_create_group (iommu_group );
771
767
if (IS_ERR (group )) {
772
768
iommu_group_put (iommu_group );
773
769
return PTR_ERR (group );
0 commit comments