Skip to content

Commit 13b4ec7

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu/amd: Change amd_iommu_pgtable to use enum protection_domain_mode
Currently it uses enum io_pgtable_fmt which is from the io pagetable code and most of the enum values are invalid. protection_domain_mode is internal the driver and has the only two valid values. Fix some signatures and variables to use the right type as well. 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 55b237d commit 13b4ec7

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void amd_iommu_disable(void);
4040
int amd_iommu_reenable(int mode);
4141
int amd_iommu_enable_faulting(unsigned int cpu);
4242
extern int amd_iommu_guest_ir;
43-
extern enum io_pgtable_fmt amd_iommu_pgtable;
43+
extern enum protection_domain_mode amd_iommu_pgtable;
4444
extern int amd_iommu_gpt_level;
4545
extern unsigned long amd_iommu_pgsize_bitmap;
4646

drivers/iommu/amd/init.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ struct ivmd_header {
152152
bool amd_iommu_dump;
153153
bool amd_iommu_irq_remap __read_mostly;
154154

155-
enum io_pgtable_fmt amd_iommu_pgtable = AMD_IOMMU_V1;
155+
enum protection_domain_mode amd_iommu_pgtable = PD_MODE_V1;
156156
/* Guest page table level */
157157
int amd_iommu_gpt_level = PAGE_MODE_4_LEVEL;
158158

@@ -2164,7 +2164,7 @@ static void print_iommu_info(void)
21642164
if (amd_iommu_xt_mode == IRQ_REMAP_X2APIC_MODE)
21652165
pr_info("X2APIC enabled\n");
21662166
}
2167-
if (amd_iommu_pgtable == AMD_IOMMU_V2) {
2167+
if (amd_iommu_pgtable == PD_MODE_V2) {
21682168
pr_info("V2 page table enabled (Paging mode : %d level)\n",
21692169
amd_iommu_gpt_level);
21702170
}
@@ -3082,10 +3082,10 @@ static int __init early_amd_iommu_init(void)
30823082
FIELD_GET(FEATURE_GATS, amd_iommu_efr) == GUEST_PGTABLE_5_LEVEL)
30833083
amd_iommu_gpt_level = PAGE_MODE_5_LEVEL;
30843084

3085-
if (amd_iommu_pgtable == AMD_IOMMU_V2) {
3085+
if (amd_iommu_pgtable == PD_MODE_V2) {
30863086
if (!amd_iommu_v2_pgtbl_supported()) {
30873087
pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n");
3088-
amd_iommu_pgtable = AMD_IOMMU_V1;
3088+
amd_iommu_pgtable = PD_MODE_V1;
30893089
}
30903090
}
30913091

@@ -3208,7 +3208,7 @@ static void iommu_snp_enable(void)
32083208
goto disable_snp;
32093209
}
32103210

3211-
if (amd_iommu_pgtable != AMD_IOMMU_V1) {
3211+
if (amd_iommu_pgtable != PD_MODE_V1) {
32123212
pr_warn("SNP: IOMMU is configured with V2 page table mode, SNP cannot be supported.\n");
32133213
goto disable_snp;
32143214
}
@@ -3485,9 +3485,9 @@ static int __init parse_amd_iommu_options(char *str)
34853485
} else if (strncmp(str, "force_isolation", 15) == 0) {
34863486
amd_iommu_force_isolation = true;
34873487
} else if (strncmp(str, "pgtbl_v1", 8) == 0) {
3488-
amd_iommu_pgtable = AMD_IOMMU_V1;
3488+
amd_iommu_pgtable = PD_MODE_V1;
34893489
} else if (strncmp(str, "pgtbl_v2", 8) == 0) {
3490-
amd_iommu_pgtable = AMD_IOMMU_V2;
3490+
amd_iommu_pgtable = PD_MODE_V2;
34913491
} else if (strncmp(str, "irtcachedis", 11) == 0) {
34923492
amd_iommu_irtcachedis = true;
34933493
} else if (strncmp(str, "nohugepages", 11) == 0) {

drivers/iommu/amd/iommu.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,32 +2476,30 @@ struct protection_domain *protection_domain_alloc(int nid)
24762476
return domain;
24772477
}
24782478

2479-
static int pdom_setup_pgtable(struct protection_domain *domain, int pgtable)
2479+
static int pdom_setup_pgtable(struct protection_domain *domain)
24802480
{
24812481
struct io_pgtable_ops *pgtbl_ops;
2482+
enum io_pgtable_fmt fmt;
24822483

2483-
switch (pgtable) {
2484-
case AMD_IOMMU_V1:
2485-
domain->pd_mode = PD_MODE_V1;
2484+
switch (domain->pd_mode) {
2485+
case PD_MODE_V1:
2486+
fmt = AMD_IOMMU_V1;
24862487
break;
2487-
case AMD_IOMMU_V2:
2488-
domain->pd_mode = PD_MODE_V2;
2488+
case PD_MODE_V2:
2489+
fmt = AMD_IOMMU_V2;
24892490
break;
2490-
default:
2491-
return -EINVAL;
24922491
}
24932492

2494-
pgtbl_ops =
2495-
alloc_io_pgtable_ops(pgtable, &domain->iop.pgtbl.cfg, domain);
2493+
pgtbl_ops = alloc_io_pgtable_ops(fmt, &domain->iop.pgtbl.cfg, domain);
24962494
if (!pgtbl_ops)
24972495
return -ENOMEM;
24982496

24992497
return 0;
25002498
}
25012499

2502-
static inline u64 dma_max_address(int pgtable)
2500+
static inline u64 dma_max_address(enum protection_domain_mode pgtable)
25032501
{
2504-
if (pgtable == AMD_IOMMU_V1)
2502+
if (pgtable == PD_MODE_V1)
25052503
return ~0ULL;
25062504

25072505
/* V2 with 4/5 level page table */
@@ -2513,8 +2511,9 @@ static bool amd_iommu_hd_support(struct amd_iommu *iommu)
25132511
return iommu && (iommu->features & FEATURE_HDSUP);
25142512
}
25152513

2516-
static struct iommu_domain *do_iommu_domain_alloc(struct device *dev, u32 flags,
2517-
int pgtable)
2514+
static struct iommu_domain *
2515+
do_iommu_domain_alloc(struct device *dev, u32 flags,
2516+
enum protection_domain_mode pgtable)
25182517
{
25192518
bool dirty_tracking = flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING;
25202519
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
@@ -2525,7 +2524,8 @@ static struct iommu_domain *do_iommu_domain_alloc(struct device *dev, u32 flags,
25252524
if (!domain)
25262525
return ERR_PTR(-ENOMEM);
25272526

2528-
ret = pdom_setup_pgtable(domain, pgtable);
2527+
domain->pd_mode = pgtable;
2528+
ret = pdom_setup_pgtable(domain);
25292529
if (ret) {
25302530
pdom_id_free(domain->id);
25312531
kfree(domain);
@@ -2563,13 +2563,13 @@ amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
25632563
if (!amd_iommu_pasid_supported())
25642564
return ERR_PTR(-EOPNOTSUPP);
25652565

2566-
return do_iommu_domain_alloc(dev, flags, AMD_IOMMU_V2);
2566+
return do_iommu_domain_alloc(dev, flags, PD_MODE_V2);
25672567
}
25682568

25692569
/* Allocate domain with v1 page table for dirty tracking */
25702570
if (flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) {
25712571
if (amd_iommu_hd_support(iommu))
2572-
return do_iommu_domain_alloc(dev, flags, AMD_IOMMU_V1);
2572+
return do_iommu_domain_alloc(dev, flags, PD_MODE_V1);
25732573

25742574
return ERR_PTR(-EOPNOTSUPP);
25752575
}

0 commit comments

Comments
 (0)