Skip to content

Commit 025d137

Browse files
ankitvvsonijoergroedel
authored andcommitted
iommu/amd: Add efr[HATS] max v1 page table level
The EFR[HATS] bits indicate maximum host translation level supported by IOMMU. Adding support to set the maximum host page table level as indicated by EFR[HATS]. If the HATS=11b (reserved), the driver will attempt to use guest page table for DMA API. Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Ankit Soni <Ankit.Soni@amd.com> Link: https://lore.kernel.org/r/df0f8562c2a20895cc185c86f1a02c4d826fd597.1749016436.git.Ankit.Soni@amd.com Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent 7e5516e commit 025d137

5 files changed

Lines changed: 21 additions & 3 deletions

File tree

drivers/iommu/amd/amd_iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ int amd_iommu_enable_faulting(unsigned int cpu);
4242
extern int amd_iommu_guest_ir;
4343
extern enum protection_domain_mode amd_iommu_pgtable;
4444
extern int amd_iommu_gpt_level;
45+
extern u8 amd_iommu_hpt_level;
4546
extern unsigned long amd_iommu_pgsize_bitmap;
4647
extern bool amd_iommu_hatdis;
4748

drivers/iommu/amd/amd_iommu_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#define FEATURE_GA BIT_ULL(7)
9595
#define FEATURE_HE BIT_ULL(8)
9696
#define FEATURE_PC BIT_ULL(9)
97+
#define FEATURE_HATS GENMASK_ULL(11, 10)
9798
#define FEATURE_GATS GENMASK_ULL(13, 12)
9899
#define FEATURE_GLX GENMASK_ULL(15, 14)
99100
#define FEATURE_GAM_VAPIC BIT_ULL(21)

drivers/iommu/amd/init.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ bool amd_iommu_dump;
152152
bool amd_iommu_irq_remap __read_mostly;
153153

154154
enum protection_domain_mode amd_iommu_pgtable = PD_MODE_V1;
155+
/* Host page table level */
156+
u8 amd_iommu_hpt_level;
155157
/* Guest page table level */
156158
int amd_iommu_gpt_level = PAGE_MODE_4_LEVEL;
157159

@@ -3049,6 +3051,7 @@ static int __init early_amd_iommu_init(void)
30493051
struct acpi_table_header *ivrs_base;
30503052
int ret;
30513053
acpi_status status;
3054+
u8 efr_hats;
30523055

30533056
if (!amd_iommu_detected)
30543057
return -ENODEV;
@@ -3093,6 +3096,19 @@ static int __init early_amd_iommu_init(void)
30933096
FIELD_GET(FEATURE_GATS, amd_iommu_efr) == GUEST_PGTABLE_5_LEVEL)
30943097
amd_iommu_gpt_level = PAGE_MODE_5_LEVEL;
30953098

3099+
efr_hats = FIELD_GET(FEATURE_HATS, amd_iommu_efr);
3100+
if (efr_hats != 0x3) {
3101+
/*
3102+
* efr[HATS] bits specify the maximum host translation level
3103+
* supported, with LEVEL 4 being initial max level.
3104+
*/
3105+
amd_iommu_hpt_level = efr_hats + PAGE_MODE_4_LEVEL;
3106+
} else {
3107+
pr_warn_once(FW_BUG "Disable host address translation due to invalid translation level (%#x).\n",
3108+
efr_hats);
3109+
amd_iommu_hatdis = true;
3110+
}
3111+
30963112
if (amd_iommu_pgtable == PD_MODE_V2) {
30973113
if (!amd_iommu_v2_pgtbl_supported()) {
30983114
pr_warn("Cannot enable v2 page table for DMA-API. Fallback to v1.\n");

drivers/iommu/amd/io_pgtable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ static bool increase_address_space(struct amd_io_pgtable *pgtable,
125125
goto out;
126126

127127
ret = false;
128-
if (WARN_ON_ONCE(pgtable->mode == PAGE_MODE_6_LEVEL))
128+
if (WARN_ON_ONCE(pgtable->mode == amd_iommu_hpt_level))
129129
goto out;
130130

131131
*pte = PM_LEVEL_PDE(pgtable->mode, iommu_virt_to_phys(pgtable->root));
@@ -526,7 +526,7 @@ static void v1_free_pgtable(struct io_pgtable *iop)
526526

527527
/* Page-table is not visible to IOMMU anymore, so free it */
528528
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
529-
pgtable->mode > PAGE_MODE_6_LEVEL);
529+
pgtable->mode > amd_iommu_hpt_level);
530530

531531
free_sub_pt(pgtable->root, pgtable->mode, &freelist);
532532
iommu_put_pages_list(&freelist);

drivers/iommu/amd/iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ static int pdom_setup_pgtable(struct protection_domain *domain,
25342534
static inline u64 dma_max_address(enum protection_domain_mode pgtable)
25352535
{
25362536
if (pgtable == PD_MODE_V1)
2537-
return ~0ULL;
2537+
return PM_LEVEL_SIZE(amd_iommu_hpt_level);
25382538

25392539
/* V2 with 4/5 level page table */
25402540
return ((1ULL << PM_LEVEL_SHIFT(amd_iommu_gpt_level)) - 1);

0 commit comments

Comments
 (0)