]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
iommu/amd: Move the nid to pdom_setup_pgtable()
authorJason Gunthorpe <jgg@nvidia.com>
Fri, 10 Jan 2025 16:35:04 +0000 (12:35 -0400)
committerJoerg Roedel <jroedel@suse.de>
Fri, 17 Jan 2025 07:59:31 +0000 (08:59 +0100)
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 <vasant.hegde@amd.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/6-v2-9776c53c2966+1c7-amd_paging_flags_jgg@nvidia.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd/amd_iommu.h
drivers/iommu/amd/iommu.c
drivers/iommu/amd/pasid.c

index 0fb0c8392b530754603eb70693def32a06be38da..68debf5ee2d7516846b7263b9c8231b7ccc90919 100644 (file)
@@ -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);
index 3a12ef96e7ea674fd609aa1c87a11d12d2db69c4..0600f0682b91573a6a6288843286aaef963eee15 100644 (file)
@@ -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() */
index 9101d07b11d3f76125194bae14fb8a30eeb42e6d..11150cfd67182daae40ad9e5ea1681eb412db7cd 100644 (file)
@@ -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);