@@ -162,15 +162,26 @@ static void amd_iommu_domain_get_pgtable(struct protection_domain *domain,
162
162
pgtable -> mode = pt_root & 7 ; /* lowest 3 bits encode pgtable mode */
163
163
}
164
164
165
- static u64 amd_iommu_domain_encode_pgtable (u64 * root , int mode )
165
+ static void amd_iommu_domain_set_pt_root (struct protection_domain * domain , u64 root )
166
+ {
167
+ atomic64_set (& domain -> pt_root , root );
168
+ }
169
+
170
+ static void amd_iommu_domain_clr_pt_root (struct protection_domain * domain )
171
+ {
172
+ amd_iommu_domain_set_pt_root (domain , 0 );
173
+ }
174
+
175
+ static void amd_iommu_domain_set_pgtable (struct protection_domain * domain ,
176
+ u64 * root , int mode )
166
177
{
167
178
u64 pt_root ;
168
179
169
180
/* lowest 3 bits encode pgtable mode */
170
181
pt_root = mode & 7 ;
171
182
pt_root |= (u64 )root ;
172
183
173
- return pt_root ;
184
+ amd_iommu_domain_set_pt_root ( domain , pt_root ) ;
174
185
}
175
186
176
187
static struct iommu_dev_data * alloc_dev_data (u16 devid )
@@ -1410,7 +1421,7 @@ static bool increase_address_space(struct protection_domain *domain,
1410
1421
struct domain_pgtable pgtable ;
1411
1422
unsigned long flags ;
1412
1423
bool ret = true;
1413
- u64 * pte , root ;
1424
+ u64 * pte ;
1414
1425
1415
1426
spin_lock_irqsave (& domain -> lock , flags );
1416
1427
@@ -1438,8 +1449,7 @@ static bool increase_address_space(struct protection_domain *domain,
1438
1449
* Device Table needs to be updated and flushed before the new root can
1439
1450
* be published.
1440
1451
*/
1441
- root = amd_iommu_domain_encode_pgtable (pte , pgtable .mode );
1442
- atomic64_set (& domain -> pt_root , root );
1452
+ amd_iommu_domain_set_pgtable (domain , pte , pgtable .mode );
1443
1453
1444
1454
ret = true;
1445
1455
@@ -2319,15 +2329,15 @@ static void protection_domain_free(struct protection_domain *domain)
2319
2329
domain_id_free (domain -> id );
2320
2330
2321
2331
amd_iommu_domain_get_pgtable (domain , & pgtable );
2322
- atomic64_set ( & domain -> pt_root , 0 );
2332
+ amd_iommu_domain_clr_pt_root ( domain );
2323
2333
free_pagetable (& pgtable );
2324
2334
2325
2335
kfree (domain );
2326
2336
}
2327
2337
2328
2338
static int protection_domain_init (struct protection_domain * domain , int mode )
2329
2339
{
2330
- u64 * pt_root = NULL , root ;
2340
+ u64 * pt_root = NULL ;
2331
2341
2332
2342
BUG_ON (mode < PAGE_MODE_NONE || mode > PAGE_MODE_6_LEVEL );
2333
2343
@@ -2343,8 +2353,7 @@ static int protection_domain_init(struct protection_domain *domain, int mode)
2343
2353
return - ENOMEM ;
2344
2354
}
2345
2355
2346
- root = amd_iommu_domain_encode_pgtable (pt_root , mode );
2347
- atomic64_set (& domain -> pt_root , root );
2356
+ amd_iommu_domain_set_pgtable (domain , pt_root , mode );
2348
2357
2349
2358
return 0 ;
2350
2359
}
@@ -2713,8 +2722,8 @@ void amd_iommu_domain_direct_map(struct iommu_domain *dom)
2713
2722
/* First save pgtable configuration*/
2714
2723
amd_iommu_domain_get_pgtable (domain , & pgtable );
2715
2724
2716
- /* Update data structure */
2717
- atomic64_set ( & domain -> pt_root , 0 );
2725
+ /* Remove page-table from domain */
2726
+ amd_iommu_domain_clr_pt_root ( domain );
2718
2727
2719
2728
/* Make changes visible to IOMMUs */
2720
2729
update_domain (domain );
0 commit comments