Skip to content

Commit 5a081f7

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Move the nid to pdom_setup_pgtable()
The only thing that uses the nid is the io_pgtable code, and it should be set before calling alloc_io_pgtable_ops() to ensure that the top levels are allocated on the correct nid. Since dev is never NULL now we can just do this trivially and remove the other uses of nid. SVA and identity code paths never use it since they don't use io_pgtable. Reviewed-by: Vasant Hegde <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 13b4ec7 commit 5a081f7

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern unsigned long amd_iommu_pgsize_bitmap;
4646

4747
/* Protection domain ops */
4848
void amd_iommu_init_identity_domain(void);
49-
struct protection_domain *protection_domain_alloc(int nid);
49+
struct protection_domain *protection_domain_alloc(void);
5050
void protection_domain_free(struct protection_domain *domain);
5151
struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
5252
struct mm_struct *mm);

drivers/iommu/amd/iommu.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,6 @@ static int pdom_attach_iommu(struct amd_iommu *iommu,
21772177
struct protection_domain *pdom)
21782178
{
21792179
struct pdom_iommu_info *pdom_iommu_info, *curr;
2180-
struct io_pgtable_cfg *cfg = &pdom->iop.pgtbl.cfg;
21812180
unsigned long flags;
21822181
int ret = 0;
21832182

@@ -2206,10 +2205,6 @@ static int pdom_attach_iommu(struct amd_iommu *iommu,
22062205
goto out_unlock;
22072206
}
22082207

2209-
/* Update NUMA Node ID */
2210-
if (cfg->amd.nid == NUMA_NO_NODE)
2211-
cfg->amd.nid = dev_to_node(&iommu->dev->dev);
2212-
22132208
out_unlock:
22142209
spin_unlock_irqrestore(&pdom->lock, flags);
22152210
return ret;
@@ -2446,16 +2441,15 @@ void protection_domain_free(struct protection_domain *domain)
24462441
kfree(domain);
24472442
}
24482443

2449-
static void protection_domain_init(struct protection_domain *domain, int nid)
2444+
static void protection_domain_init(struct protection_domain *domain)
24502445
{
24512446
spin_lock_init(&domain->lock);
24522447
INIT_LIST_HEAD(&domain->dev_list);
24532448
INIT_LIST_HEAD(&domain->dev_data_list);
24542449
xa_init(&domain->iommu_array);
2455-
domain->iop.pgtbl.cfg.amd.nid = nid;
24562450
}
24572451

2458-
struct protection_domain *protection_domain_alloc(int nid)
2452+
struct protection_domain *protection_domain_alloc(void)
24592453
{
24602454
struct protection_domain *domain;
24612455
int domid;
@@ -2471,12 +2465,13 @@ struct protection_domain *protection_domain_alloc(int nid)
24712465
}
24722466
domain->id = domid;
24732467

2474-
protection_domain_init(domain, nid);
2468+
protection_domain_init(domain);
24752469

24762470
return domain;
24772471
}
24782472

2479-
static int pdom_setup_pgtable(struct protection_domain *domain)
2473+
static int pdom_setup_pgtable(struct protection_domain *domain,
2474+
struct device *dev)
24802475
{
24812476
struct io_pgtable_ops *pgtbl_ops;
24822477
enum io_pgtable_fmt fmt;
@@ -2490,6 +2485,7 @@ static int pdom_setup_pgtable(struct protection_domain *domain)
24902485
break;
24912486
}
24922487

2488+
domain->iop.pgtbl.cfg.amd.nid = dev_to_node(dev);
24932489
pgtbl_ops = alloc_io_pgtable_ops(fmt, &domain->iop.pgtbl.cfg, domain);
24942490
if (!pgtbl_ops)
24952491
return -ENOMEM;
@@ -2520,12 +2516,12 @@ do_iommu_domain_alloc(struct device *dev, u32 flags,
25202516
struct protection_domain *domain;
25212517
int ret;
25222518

2523-
domain = protection_domain_alloc(dev_to_node(dev));
2519+
domain = protection_domain_alloc();
25242520
if (!domain)
25252521
return ERR_PTR(-ENOMEM);
25262522

25272523
domain->pd_mode = pgtable;
2528-
ret = pdom_setup_pgtable(domain);
2524+
ret = pdom_setup_pgtable(domain, dev);
25292525
if (ret) {
25302526
pdom_id_free(domain->id);
25312527
kfree(domain);
@@ -2624,7 +2620,7 @@ void amd_iommu_init_identity_domain(void)
26242620

26252621
identity_domain.id = pdom_id_alloc();
26262622

2627-
protection_domain_init(&identity_domain, NUMA_NO_NODE);
2623+
protection_domain_init(&identity_domain);
26282624
}
26292625

26302626
/* Same as blocked domain except it supports only ops->attach_dev() */

drivers/iommu/amd/pasid.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
185185
struct protection_domain *pdom;
186186
int ret;
187187

188-
pdom = protection_domain_alloc(dev_to_node(dev));
188+
pdom = protection_domain_alloc();
189189
if (!pdom)
190190
return ERR_PTR(-ENOMEM);
191191

0 commit comments

Comments
 (0)