Skip to content

Commit 6eedb59

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Remove amd_iommu_domain_get_pgtable
Since the IO page table root and mode parameters have been moved into the struct amd_io_pg, the function is no longer needed. Therefore, remove it along with the struct domain_pgtable. Signed-off-by: Suravee Suthikulpanit <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent e42ba06 commit 6eedb59

File tree

4 files changed

+19
-61
lines changed

4 files changed

+19
-61
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ static inline
110110
void amd_iommu_domain_set_pt_root(struct protection_domain *domain, u64 root)
111111
{
112112
atomic64_set(&domain->iop.pt_root, root);
113+
domain->iop.root = (u64 *)(root & PAGE_MASK);
114+
domain->iop.mode = root & 7; /* lowest 3 bits encode pgtable mode */
113115
}
114116

115117
static inline
@@ -144,8 +146,6 @@ extern unsigned long iommu_unmap_page(struct protection_domain *dom,
144146
extern u64 *fetch_pte(struct protection_domain *domain,
145147
unsigned long address,
146148
unsigned long *page_size);
147-
extern void amd_iommu_domain_get_pgtable(struct protection_domain *domain,
148-
struct domain_pgtable *pgtable);
149149
extern void amd_iommu_domain_set_pgtable(struct protection_domain *domain,
150150
u64 *root, int mode);
151151
#endif

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,6 @@ struct protection_domain {
519519
unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */
520520
};
521521

522-
/* For decocded pt_root */
523-
struct domain_pgtable {
524-
int mode;
525-
u64 *root;
526-
};
527-
528522
/*
529523
* Structure where we save information about one hardware AMD IOMMU in the
530524
* system.

drivers/iommu/amd/io_pgtable.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -178,38 +178,35 @@ static bool increase_address_space(struct protection_domain *domain,
178178
unsigned long address,
179179
gfp_t gfp)
180180
{
181-
struct domain_pgtable pgtable;
182181
unsigned long flags;
183182
bool ret = true;
184183
u64 *pte;
185184

186185
spin_lock_irqsave(&domain->lock, flags);
187186

188-
amd_iommu_domain_get_pgtable(domain, &pgtable);
189-
190-
if (address <= PM_LEVEL_SIZE(pgtable.mode))
187+
if (address <= PM_LEVEL_SIZE(domain->iop.mode))
191188
goto out;
192189

193190
ret = false;
194-
if (WARN_ON_ONCE(pgtable.mode == PAGE_MODE_6_LEVEL))
191+
if (WARN_ON_ONCE(domain->iop.mode == PAGE_MODE_6_LEVEL))
195192
goto out;
196193

197194
pte = (void *)get_zeroed_page(gfp);
198195
if (!pte)
199196
goto out;
200197

201-
*pte = PM_LEVEL_PDE(pgtable.mode, iommu_virt_to_phys(pgtable.root));
198+
*pte = PM_LEVEL_PDE(domain->iop.mode, iommu_virt_to_phys(domain->iop.root));
202199

203-
pgtable.root = pte;
204-
pgtable.mode += 1;
200+
domain->iop.root = pte;
201+
domain->iop.mode += 1;
205202
amd_iommu_update_and_flush_device_table(domain);
206203
amd_iommu_domain_flush_complete(domain);
207204

208205
/*
209206
* Device Table needs to be updated and flushed before the new root can
210207
* be published.
211208
*/
212-
amd_iommu_domain_set_pgtable(domain, pte, pgtable.mode);
209+
amd_iommu_domain_set_pgtable(domain, pte, domain->iop.mode);
213210

214211
ret = true;
215212

@@ -226,29 +223,23 @@ static u64 *alloc_pte(struct protection_domain *domain,
226223
gfp_t gfp,
227224
bool *updated)
228225
{
229-
struct domain_pgtable pgtable;
230226
int level, end_lvl;
231227
u64 *pte, *page;
232228

233229
BUG_ON(!is_power_of_2(page_size));
234230

235-
amd_iommu_domain_get_pgtable(domain, &pgtable);
236-
237-
while (address > PM_LEVEL_SIZE(pgtable.mode)) {
231+
while (address > PM_LEVEL_SIZE(domain->iop.mode)) {
238232
/*
239233
* Return an error if there is no memory to update the
240234
* page-table.
241235
*/
242236
if (!increase_address_space(domain, address, gfp))
243237
return NULL;
244-
245-
/* Read new values to check if update was successful */
246-
amd_iommu_domain_get_pgtable(domain, &pgtable);
247238
}
248239

249240

250-
level = pgtable.mode - 1;
251-
pte = &pgtable.root[PM_LEVEL_INDEX(level, address)];
241+
level = domain->iop.mode - 1;
242+
pte = &domain->iop.root[PM_LEVEL_INDEX(level, address)];
252243
address = PAGE_SIZE_ALIGN(address, page_size);
253244
end_lvl = PAGE_SIZE_LEVEL(page_size);
254245

@@ -324,19 +315,16 @@ u64 *fetch_pte(struct protection_domain *domain,
324315
unsigned long address,
325316
unsigned long *page_size)
326317
{
327-
struct domain_pgtable pgtable;
328318
int level;
329319
u64 *pte;
330320

331321
*page_size = 0;
332322

333-
amd_iommu_domain_get_pgtable(domain, &pgtable);
334-
335-
if (address > PM_LEVEL_SIZE(pgtable.mode))
323+
if (address > PM_LEVEL_SIZE(domain->iop.mode))
336324
return NULL;
337325

338-
level = pgtable.mode - 1;
339-
pte = &pgtable.root[PM_LEVEL_INDEX(level, address)];
326+
level = domain->iop.mode - 1;
327+
pte = &domain->iop.root[PM_LEVEL_INDEX(level, address)];
340328
*page_size = PTE_LEVEL_PAGE_SIZE(level);
341329

342330
while (level > 0) {

drivers/iommu/amd/iommu.c

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,6 @@ static struct protection_domain *to_pdomain(struct iommu_domain *dom)
138138
return container_of(dom, struct protection_domain, domain);
139139
}
140140

141-
void amd_iommu_domain_get_pgtable(struct protection_domain *domain,
142-
struct domain_pgtable *pgtable)
143-
{
144-
u64 pt_root = atomic64_read(&domain->iop.pt_root);
145-
146-
pgtable->root = (u64 *)(pt_root & PAGE_MASK);
147-
pgtable->mode = pt_root & 7; /* lowest 3 bits encode pgtable mode */
148-
}
149-
150141
static struct iommu_dev_data *alloc_dev_data(u16 devid)
151142
{
152143
struct iommu_dev_data *dev_data;
@@ -1483,7 +1474,6 @@ static void clear_dte_entry(u16 devid)
14831474
static void do_attach(struct iommu_dev_data *dev_data,
14841475
struct protection_domain *domain)
14851476
{
1486-
struct domain_pgtable pgtable;
14871477
struct amd_iommu *iommu;
14881478
bool ats;
14891479

@@ -1499,7 +1489,6 @@ static void do_attach(struct iommu_dev_data *dev_data,
14991489
domain->dev_cnt += 1;
15001490

15011491
/* Update device table */
1502-
amd_iommu_domain_get_pgtable(domain, &pgtable);
15031492
set_dte_entry(dev_data->devid, domain,
15041493
ats, dev_data->iommu_v2);
15051494
clone_aliases(dev_data->pdev);
@@ -1826,10 +1815,7 @@ void amd_iommu_update_and_flush_device_table(struct protection_domain *domain)
18261815

18271816
void amd_iommu_domain_update(struct protection_domain *domain)
18281817
{
1829-
struct domain_pgtable pgtable;
1830-
18311818
/* Update device table */
1832-
amd_iommu_domain_get_pgtable(domain, &pgtable);
18331819
amd_iommu_update_and_flush_device_table(domain);
18341820

18351821
/* Flush domain TLB(s) and wait for completion */
@@ -2079,12 +2065,10 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
20792065
gfp_t gfp)
20802066
{
20812067
struct protection_domain *domain = to_pdomain(dom);
2082-
struct domain_pgtable pgtable;
20832068
int prot = 0;
20842069
int ret;
20852070

2086-
amd_iommu_domain_get_pgtable(domain, &pgtable);
2087-
if (pgtable.mode == PAGE_MODE_NONE)
2071+
if (domain->iop.mode == PAGE_MODE_NONE)
20882072
return -EINVAL;
20892073

20902074
if (iommu_prot & IOMMU_READ)
@@ -2104,10 +2088,8 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
21042088
struct iommu_iotlb_gather *gather)
21052089
{
21062090
struct protection_domain *domain = to_pdomain(dom);
2107-
struct domain_pgtable pgtable;
21082091

2109-
amd_iommu_domain_get_pgtable(domain, &pgtable);
2110-
if (pgtable.mode == PAGE_MODE_NONE)
2092+
if (domain->iop.mode == PAGE_MODE_NONE)
21112093
return 0;
21122094

21132095
return iommu_unmap_page(domain, iova, page_size);
@@ -2118,11 +2100,9 @@ static phys_addr_t amd_iommu_iova_to_phys(struct iommu_domain *dom,
21182100
{
21192101
struct protection_domain *domain = to_pdomain(dom);
21202102
unsigned long offset_mask, pte_pgsize;
2121-
struct domain_pgtable pgtable;
21222103
u64 *pte, __pte;
21232104

2124-
amd_iommu_domain_get_pgtable(domain, &pgtable);
2125-
if (pgtable.mode == PAGE_MODE_NONE)
2105+
if (domain->iop.mode == PAGE_MODE_NONE)
21262106
return iova;
21272107

21282108
pte = fetch_pte(domain, iova, &pte_pgsize);
@@ -2492,11 +2472,9 @@ static u64 *__get_gcr3_pte(u64 *root, int level, u32 pasid, bool alloc)
24922472
static int __set_gcr3(struct protection_domain *domain, u32 pasid,
24932473
unsigned long cr3)
24942474
{
2495-
struct domain_pgtable pgtable;
24962475
u64 *pte;
24972476

2498-
amd_iommu_domain_get_pgtable(domain, &pgtable);
2499-
if (pgtable.mode != PAGE_MODE_NONE)
2477+
if (domain->iop.mode != PAGE_MODE_NONE)
25002478
return -EINVAL;
25012479

25022480
pte = __get_gcr3_pte(domain->gcr3_tbl, domain->glx, pasid, true);
@@ -2510,11 +2488,9 @@ static int __set_gcr3(struct protection_domain *domain, u32 pasid,
25102488

25112489
static int __clear_gcr3(struct protection_domain *domain, u32 pasid)
25122490
{
2513-
struct domain_pgtable pgtable;
25142491
u64 *pte;
25152492

2516-
amd_iommu_domain_get_pgtable(domain, &pgtable);
2517-
if (pgtable.mode != PAGE_MODE_NONE)
2493+
if (domain->iop.mode != PAGE_MODE_NONE)
25182494
return -EINVAL;
25192495

25202496
pte = __get_gcr3_pte(domain->gcr3_tbl, domain->glx, pasid, false);

0 commit comments

Comments
 (0)