Skip to content

Commit 55b237d

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Remove type argument from do_iommu_domain_alloc() and related
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. IOMMU_DOMAIN_IDENTITY checks are similarly obsolete as the conversion to the global static identity domain removed those call paths. The caller of protection_domain_alloc() should set the type, fix the miss in the SVA code. 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 02bcd1a commit 55b237d

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
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(unsigned int type, int nid);
49+
struct protection_domain *protection_domain_alloc(int nid);
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: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,7 +2455,7 @@ static void protection_domain_init(struct protection_domain *domain, int nid)
24552455
domain->iop.pgtbl.cfg.amd.nid = nid;
24562456
}
24572457

2458-
struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
2458+
struct protection_domain *protection_domain_alloc(int nid)
24592459
{
24602460
struct protection_domain *domain;
24612461
int domid;
@@ -2476,15 +2476,10 @@ struct protection_domain *protection_domain_alloc(unsigned int type, int nid)
24762476
return domain;
24772477
}
24782478

2479-
static int pdom_setup_pgtable(struct protection_domain *domain,
2480-
unsigned int type, int pgtable)
2479+
static int pdom_setup_pgtable(struct protection_domain *domain, int pgtable)
24812480
{
24822481
struct io_pgtable_ops *pgtbl_ops;
24832482

2484-
/* No need to allocate io pgtable ops in passthrough mode */
2485-
if (!(type & __IOMMU_DOMAIN_PAGING))
2486-
return 0;
2487-
24882483
switch (pgtable) {
24892484
case AMD_IOMMU_V1:
24902485
domain->pd_mode = PD_MODE_V1;
@@ -2518,27 +2513,19 @@ static bool amd_iommu_hd_support(struct amd_iommu *iommu)
25182513
return iommu && (iommu->features & FEATURE_HDSUP);
25192514
}
25202515

2521-
static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
2522-
struct device *dev,
2523-
u32 flags, int pgtable)
2516+
static struct iommu_domain *do_iommu_domain_alloc(struct device *dev, u32 flags,
2517+
int pgtable)
25242518
{
25252519
bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
25262520
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
25272521
struct protection_domain *domain;
25282522
int ret;
25292523

2530-
/*
2531-
* Since DTE[Mode]=0 is prohibited on SNP-enabled system,
2532-
* default to use IOMMU_DOMAIN_DMA[_FQ].
2533-
*/
2534-
if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY))
2535-
return ERR_PTR(-EINVAL);
2536-
2537-
domain = protection_domain_alloc(type, dev_to_node(dev));
2524+
domain = protection_domain_alloc(dev_to_node(dev));
25382525
if (!domain)
25392526
return ERR_PTR(-ENOMEM);
25402527

2541-
ret = pdom_setup_pgtable(domain, type, pgtable);
2528+
ret = pdom_setup_pgtable(domain, pgtable);
25422529
if (ret) {
25432530
pdom_id_free(domain->id);
25442531
kfree(domain);
@@ -2550,7 +2537,7 @@ static struct iommu_domain *do_iommu_domain_alloc(unsigned int type,
25502537
domain->domain.geometry.force_aperture = true;
25512538
domain->domain.pgsize_bitmap = domain->iop.pgtbl.cfg.pgsize_bitmap;
25522539

2553-
domain->domain.type = type;
2540+
domain->domain.type = IOMMU_DOMAIN_UNMANAGED;
25542541
domain->domain.ops = iommu->iommu.ops->default_domain_ops;
25552542

25562543
if (dirty_tracking)
@@ -2564,7 +2551,6 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
25642551
const struct iommu_user_data *user_data)
25652552

25662553
{
2567-
unsigned int type = IOMMU_DOMAIN_UNMANAGED;
25682554
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
25692555
const u32 supported_flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
25702556
IOMMU_HWPT_ALLOC_PASID;
@@ -2577,20 +2563,19 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
25772563
if (!amd_iommu_pasid_supported())
25782564
return ERR_PTR(-EOPNOTSUPP);
25792565

2580-
return do_iommu_domain_alloc(type, dev, flags, AMD_IOMMU_V2);
2566+
return do_iommu_domain_alloc(dev, flags, AMD_IOMMU_V2);
25812567
}
25822568

25832569
/* Allocate domain with v1 page table for dirty tracking */
25842570
if (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) {
25852571
if (amd_iommu_hd_support(iommu))
2586-
return do_iommu_domain_alloc(type, dev, flags,
2587-
AMD_IOMMU_V1);
2572+
return do_iommu_domain_alloc(dev, flags, AMD_IOMMU_V1);
25882573

25892574
return ERR_PTR(-EOPNOTSUPP);
25902575
}
25912576

25922577
/* If nothing specific is required use the kernel commandline default */
2593-
return do_iommu_domain_alloc(type, dev, 0, amd_iommu_pgtable);
2578+
return do_iommu_domain_alloc(dev, 0, amd_iommu_pgtable);
25942579
}
25952580

25962581
void amd_iommu_domain_free(struct iommu_domain *dom)

drivers/iommu/amd/pasid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,13 @@ 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(IOMMU_DOMAIN_SVA, dev_to_node(dev));
188+
pdom = protection_domain_alloc(dev_to_node(dev));
189189
if (!pdom)
190190
return ERR_PTR(-ENOMEM);
191191

192192
pdom->domain.ops = &amd_sva_domain_ops;
193193
pdom->mn.ops = &sva_mn;
194+
pdom->domain.type = IOMMU_DOMAIN_SVA;
194195

195196
ret = mmu_notifier_register(&pdom->mn, mm);
196197
if (ret) {

0 commit comments

Comments
 (0)