Commit 5a081f7f authored by Jason Gunthorpe's avatar Jason Gunthorpe Committed by Joerg Roedel
Browse files

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: default avatarVasant Hegde <vasant.hegde@amd.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/6-v2-9776c53c2966+1c7-amd_paging_flags_jgg@nvidia.com


Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 13b4ec74
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ extern unsigned long amd_iommu_pgsize_bitmap;

/* Protection domain ops */
void amd_iommu_init_identity_domain(void);
struct protection_domain *protection_domain_alloc(int nid);
struct protection_domain *protection_domain_alloc(void);
void protection_domain_free(struct protection_domain *domain);
struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
						struct mm_struct *mm);
+9 −13
Original line number Diff line number Diff line
@@ -2177,7 +2177,6 @@ static int pdom_attach_iommu(struct amd_iommu *iommu,
			     struct protection_domain *pdom)
{
	struct pdom_iommu_info *pdom_iommu_info, *curr;
	struct io_pgtable_cfg *cfg = &pdom->iop.pgtbl.cfg;
	unsigned long flags;
	int ret = 0;

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

	/* Update NUMA Node ID */
	if (cfg->amd.nid == NUMA_NO_NODE)
		cfg->amd.nid = dev_to_node(&iommu->dev->dev);

out_unlock:
	spin_unlock_irqrestore(&pdom->lock, flags);
	return ret;
@@ -2446,16 +2441,15 @@ void protection_domain_free(struct protection_domain *domain)
	kfree(domain);
}

static void protection_domain_init(struct protection_domain *domain, int nid)
static void protection_domain_init(struct protection_domain *domain)
{
	spin_lock_init(&domain->lock);
	INIT_LIST_HEAD(&domain->dev_list);
	INIT_LIST_HEAD(&domain->dev_data_list);
	xa_init(&domain->iommu_array);
	domain->iop.pgtbl.cfg.amd.nid = nid;
}

struct protection_domain *protection_domain_alloc(int nid)
struct protection_domain *protection_domain_alloc(void)
{
	struct protection_domain *domain;
	int domid;
@@ -2471,12 +2465,13 @@ struct protection_domain *protection_domain_alloc(int nid)
	}
	domain->id = domid;

	protection_domain_init(domain, nid);
	protection_domain_init(domain);

	return domain;
}

static int pdom_setup_pgtable(struct protection_domain *domain)
static int pdom_setup_pgtable(struct protection_domain *domain,
			      struct device *dev)
{
	struct io_pgtable_ops *pgtbl_ops;
	enum io_pgtable_fmt fmt;
@@ -2490,6 +2485,7 @@ static int pdom_setup_pgtable(struct protection_domain *domain)
		break;
	}

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

	domain = protection_domain_alloc(dev_to_node(dev));
	domain = protection_domain_alloc();
	if (!domain)
		return ERR_PTR(-ENOMEM);

	domain->pd_mode = pgtable;
	ret = pdom_setup_pgtable(domain);
	ret = pdom_setup_pgtable(domain, dev);
	if (ret) {
		pdom_id_free(domain->id);
		kfree(domain);
@@ -2624,7 +2620,7 @@ void amd_iommu_init_identity_domain(void)

	identity_domain.id = pdom_id_alloc();

	protection_domain_init(&identity_domain, NUMA_NO_NODE);
	protection_domain_init(&identity_domain);
}

/* Same as blocked domain except it supports only ops->attach_dev() */
+1 −1
Original line number Diff line number Diff line
@@ -185,7 +185,7 @@ struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
	struct protection_domain *pdom;
	int ret;

	pdom = protection_domain_alloc(dev_to_node(dev));
	pdom = protection_domain_alloc();
	if (!pdom)
		return ERR_PTR(-ENOMEM);