From: Jason Gunthorpe <jgg@nvidia.com>
To: iommu@lists.linux.dev, Joerg Roedel <joro@8bytes.org>,
Robin Murphy <robin.murphy@arm.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Will Deacon <will@kernel.org>
Cc: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>,
Joerg Roedel <jroedel@suse.de>, Kevin Tian <kevin.tian@intel.com>,
patches@lists.linux.dev, Vasant Hegde <vasant.hegde@amd.com>
Subject: [PATCH 4/7] iommu/amd: Remove type argument from do_iommu_domain_alloc() and related
Date: Thu, 5 Dec 2024 20:23:39 -0400 [thread overview]
Message-ID: <4-v1-cf88773f22d1+39bd-amd_paging_flags_jgg@nvidia.com> (raw)
In-Reply-To: <0-v1-cf88773f22d1+39bd-amd_paging_flags_jgg@nvidia.com>
do_iommu_domain_alloc() is only called from
amd_iommu_domain_alloc_paging_flags() so type is always
IOMMU_DOMAIN_UNMANAGED. Remove type and all the dead conditionals checking
it.
The caller of protection_domain_alloc() should set the type, fix the miss
in the SVA code.
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
drivers/iommu/amd/amd_iommu.h | 2 +-
drivers/iommu/amd/iommu.c | 35 ++++++++++-------------------------
drivers/iommu/amd/pasid.c | 3 ++-
3 files changed, 13 insertions(+), 27 deletions(-)
diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
index c38e02510cf737..1d384b2c6e28e7 100644
--- a/drivers/iommu/amd/amd_iommu.h
+++ b/drivers/iommu/amd/amd_iommu.h
@@ -47,7 +47,7 @@ extern unsigned long amd_iommu_pgsize_bitmap;
/* Protection domain ops */
void amd_iommu_init_identity_domain(void);
-struct protection_domain *protection_domain_alloc(unsigned int type, int nid);
+struct protection_domain *protection_domain_alloc(int nid);
void protection_domain_free(struct protection_domain *domain);
struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
struct mm_struct *mm);
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 12c416abdce7dc..081a5dbe7ba7bb 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2276,7 +2276,7 @@ static void protection_domain_init(struct protection_domain *domain, int nid)
domain->iop.pgtbl.cfg.amd.nid = nid;
}
-struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
+struct protection_domain *protection_domain_alloc(int nid)
{
struct protection_domain *domain;
int domid;
@@ -2297,15 +2297,10 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
return domain;
}
-static int pdom_setup_pgtable(struct protection_domain *domain,
- unsigned int type, int pgtable)
+static int pdom_setup_pgtable(struct protection_domain *domain, int pgtable)
{
struct io_pgtable_ops *pgtbl_ops;
- /* No need to allocate io pgtable ops in passthrough mode */
- if (!(type & __IOMMU_DOMAIN_PAGING))
- return 0;
-
switch (pgtable) {
case AMD_IOMMU_V1:
domain->pd_mode = PD_MODE_V1;
@@ -2339,27 +2334,19 @@ static bool amd_iommu_hd_support(struct amd_iommu *iommu)
return iommu && (iommu->features & FEATURE_HDSUP);
}
-static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
- struct device *dev,
- u32 flags, int pgtable)
+static struct iommu_domain *do_iommu_domain_alloc(struct device *dev, u32 flags,
+ int pgtable)
{
bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
struct protection_domain *domain;
int ret;
- /*
- * Since DTE[Mode]=0 is prohibited on SNP-enabled system,
- * default to use IOMMU_DOMAIN_DMA[_FQ].
- */
- if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY))
- return ERR_PTR(-EINVAL);
-
- domain = protection_domain_alloc(type, dev_to_node(dev));
+ domain = protection_domain_alloc(dev_to_node(dev));
if (!domain)
return ERR_PTR(-ENOMEM);
- ret = pdom_setup_pgtable(domain, type, pgtable);
+ ret = pdom_setup_pgtable(domain, pgtable);
if (ret) {
pdom_id_free(domain->id);
kfree(domain);
@@ -2371,7 +2358,7 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
domain->domain.geometry.force_aperture = true;
domain->domain.pgsize_bitmap = domain->iop.pgtbl.cfg.pgsize_bitmap;
- domain->domain.type = type;
+ domain->domain.type = IOMMU_DOMAIN_UNMANAGED;
domain->domain.ops = iommu->iommu.ops->default_domain_ops;
if (dirty_tracking)
@@ -2385,7 +2372,6 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
const struct iommu_user_data *user_data)
{
- unsigned int type = IOMMU_DOMAIN_UNMANAGED;
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
const u32 supported_flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
IOMMU_HWPT_ALLOC_PASID;
@@ -2398,20 +2384,19 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
if (!amd_iommu_pasid_supported())
return ERR_PTR(-EOPNOTSUPP);
- return do_iommu_domain_alloc(type, dev, flags, AMD_IOMMU_V2);
+ return do_iommu_domain_alloc(dev, flags, AMD_IOMMU_V2);
}
/* Allocate domain with v1 page table for dirty tracking */
if (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) {
if (amd_iommu_hd_support(iommu))
- return do_iommu_domain_alloc(type, dev, flags,
- AMD_IOMMU_V1);
+ return do_iommu_domain_alloc(dev, flags, AMD_IOMMU_V1);
return ERR_PTR(-EOPNOTSUPP);
}
/* If nothing specific is required use the kernel commandline default */
- return do_iommu_domain_alloc(type, dev, 0, amd_iommu_pgtable);
+ return do_iommu_domain_alloc(dev, 0, amd_iommu_pgtable);
}
void amd_iommu_domain_free(struct iommu_domain *dom)
diff --git a/drivers/iommu/amd/pasid.c b/drivers/iommu/amd/pasid.c
index 8c73a30c2800e7..9101d07b11d3f7 100644
--- a/drivers/iommu/amd/pasid.c
+++ b/drivers/iommu/amd/pasid.c
@@ -185,12 +185,13 @@ struct iommu_domain *amd_iommu_domain_alloc_sva(struct device *dev,
struct protection_domain *pdom;
int ret;
- pdom = protection_domain_alloc(IOMMU_DOMAIN_SVA, dev_to_node(dev));
+ pdom = protection_domain_alloc(dev_to_node(dev));
if (!pdom)
return ERR_PTR(-ENOMEM);
pdom->domain.ops = &amd_sva_domain_ops;
pdom->mn.ops = &sva_mn;
+ pdom->domain.type = IOMMU_DOMAIN_SVA;
ret = mmu_notifier_register(&pdom->mn, mm);
if (ret) {
--
2.43.0
next prev parent reply other threads:[~2024-12-06 0:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-06 0:23 [PATCH 0/7] iommu/amd: Cleanup some of the domain_alloc_paging path Jason Gunthorpe
2024-12-06 0:23 ` [PATCH 1/7] iommu/amd: Remove unused amd_iommu_domain_update() Jason Gunthorpe
2025-01-06 11:09 ` Vasant Hegde
2024-12-06 0:23 ` [PATCH 2/7] iommu/amd: Remove domain_alloc() Jason Gunthorpe
2025-01-06 14:04 ` Vasant Hegde
2024-12-06 0:23 ` [PATCH 3/7] iommu/amd: Remove dev == NULL checks Jason Gunthorpe
2025-01-06 14:33 ` Vasant Hegde
2024-12-06 0:23 ` Jason Gunthorpe [this message]
2025-01-06 14:54 ` [PATCH 4/7] iommu/amd: Remove type argument from do_iommu_domain_alloc() and related Vasant Hegde
2024-12-06 0:23 ` [PATCH 5/7] iommu/amd: Change amd_iommu_pgtable to use enum protection_domain_mode Jason Gunthorpe
2025-01-07 9:39 ` Vasant Hegde
2024-12-06 0:23 ` [PATCH 6/7] iommu/amd: Move the nid to pdom_setup_pgtable() Jason Gunthorpe
2025-01-07 9:43 ` Vasant Hegde
2024-12-06 0:23 ` [PATCH 7/7] iommu/amd: Fully decode all combinations of alloc_paging_flags Jason Gunthorpe
2025-01-07 10:47 ` Vasant Hegde
2025-01-09 17:17 ` Jason Gunthorpe
2025-01-07 10:51 ` [PATCH 0/7] iommu/amd: Cleanup some of the domain_alloc_paging path Vasant Hegde
2025-01-09 17:18 ` Jason Gunthorpe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4-v1-cf88773f22d1+39bd-amd_paging_flags_jgg@nvidia.com \
--to=jgg@nvidia.com \
--cc=alejandro.j.jimenez@oracle.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=jroedel@suse.de \
--cc=kevin.tian@intel.com \
--cc=patches@lists.linux.dev \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=vasant.hegde@amd.com \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).