Skip to content

Commit f029591

Browse files
committed
iommu/amd: Add kernel parameters to limit V1 page-sizes
Add two new kernel command line parameters to limit the page-sizes used for v1 page-tables: nohugepages - Limits page-sizes to 4KiB v2_pgsizes_only - Limits page-sizes to 4Kib/2Mib/1GiB; The same as the sizes used with v2 page-tables This is needed for multiple scenarios. When assigning devices to SEV-SNP guests the IOMMU page-sizes need to match the sizes in the RMP table, otherwise the device will not be able to access all shared memory. Also, some ATS devices do not work properly with arbitrary IO page-sizes as supported by AMD-Vi, so limiting the sizes used by the driver is a suitable workaround. All-in-all, these parameters are only workarounds until the IOMMU core and related APIs gather the ability to negotiate the page-sizes in a better way. Signed-off-by: Joerg Roedel <[email protected]> Reviewed-by: Vasant Hegde <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2910a7f commit f029591

File tree

5 files changed

+25
-7
lines changed

5 files changed

+25
-7
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,17 @@
333333
allowed anymore to lift isolation
334334
requirements as needed. This option
335335
does not override iommu=pt
336-
force_enable - Force enable the IOMMU on platforms known
337-
to be buggy with IOMMU enabled. Use this
338-
option with care.
339-
pgtbl_v1 - Use v1 page table for DMA-API (Default).
340-
pgtbl_v2 - Use v2 page table for DMA-API.
341-
irtcachedis - Disable Interrupt Remapping Table (IRT) caching.
336+
force_enable - Force enable the IOMMU on platforms known
337+
to be buggy with IOMMU enabled. Use this
338+
option with care.
339+
pgtbl_v1 - Use v1 page table for DMA-API (Default).
340+
pgtbl_v2 - Use v2 page table for DMA-API.
341+
irtcachedis - Disable Interrupt Remapping Table (IRT) caching.
342+
nohugepages - Limit page-sizes used for v1 page-tables
343+
to 4 KiB.
344+
v2_pgsizes_only - Limit page-sizes used for v1 page-tables
345+
to 4KiB/2Mib/1GiB.
346+
342347

343348
amd_iommu_dump= [HW,X86-64]
344349
Enable AMD IOMMU driver option to dump the ACPI table

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ int amd_iommu_enable_faulting(unsigned int cpu);
4343
extern int amd_iommu_guest_ir;
4444
extern enum io_pgtable_fmt amd_iommu_pgtable;
4545
extern int amd_iommu_gpt_level;
46+
extern unsigned long amd_iommu_pgsize_bitmap;
4647

4748
/* Protection domain ops */
4849
struct protection_domain *protection_domain_alloc(unsigned int type, int nid);

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@
293293
* Page sizes >= the 52 bit max physical address of the CPU are not supported.
294294
*/
295295
#define AMD_IOMMU_PGSIZES (GENMASK_ULL(51, 12) ^ SZ_512G)
296+
297+
/* Special mode where page-sizes are limited to 4 KiB */
298+
#define AMD_IOMMU_PGSIZES_4K (PAGE_SIZE)
299+
296300
/* 4K, 2MB, 1G page sizes are supported */
297301
#define AMD_IOMMU_PGSIZES_V2 (PAGE_SIZE | (1ULL << 21) | (1ULL << 30))
298302

drivers/iommu/amd/init.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ bool amdr_ivrs_remap_support __read_mostly;
192192

193193
bool amd_iommu_force_isolation __read_mostly;
194194

195+
unsigned long amd_iommu_pgsize_bitmap __ro_after_init = AMD_IOMMU_PGSIZES;
196+
195197
/*
196198
* AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap
197199
* to know which ones are already in use.
@@ -3492,6 +3494,12 @@ static int __init parse_amd_iommu_options(char *str)
34923494
amd_iommu_pgtable = AMD_IOMMU_V2;
34933495
} else if (strncmp(str, "irtcachedis", 11) == 0) {
34943496
amd_iommu_irtcachedis = true;
3497+
} else if (strncmp(str, "nohugepages", 11) == 0) {
3498+
pr_info("Restricting V1 page-sizes to 4KiB");
3499+
amd_iommu_pgsize_bitmap = AMD_IOMMU_PGSIZES_4K;
3500+
} else if (strncmp(str, "v2_pgsizes_only", 15) == 0) {
3501+
pr_info("Restricting V1 page-sizes to 4KiB/2MiB/1GiB");
3502+
amd_iommu_pgsize_bitmap = AMD_IOMMU_PGSIZES_V2;
34953503
} else {
34963504
pr_notice("Unknown option - '%s'\n", str);
34973505
}

drivers/iommu/amd/io_pgtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ static struct io_pgtable *v1_alloc_pgtable(struct io_pgtable_cfg *cfg, void *coo
548548
return NULL;
549549
pgtable->mode = PAGE_MODE_3_LEVEL;
550550

551-
cfg->pgsize_bitmap = AMD_IOMMU_PGSIZES;
551+
cfg->pgsize_bitmap = amd_iommu_pgsize_bitmap;
552552
cfg->ias = IOMMU_IN_ADDR_BIT_SIZE;
553553
cfg->oas = IOMMU_OUT_ADDR_BIT_SIZE;
554554

0 commit comments

Comments
 (0)