Skip to content

Commit 785565d

Browse files
author
CKI Backport Bot
committed
iommu/amd: Add efr[HATS] max v1 page table level
JIRA: https://issues.redhat.com/browse/RHEL-107079 commit 025d137 Author: Ankit Soni <Ankit.Soni@amd.com> Date: Wed Jun 4 06:13:25 2025 +0000 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> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent 18f46ec commit 785565d

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

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
@@ -96,6 +96,7 @@
9696
#define FEATURE_GA BIT_ULL(7)
9797
#define FEATURE_HE BIT_ULL(8)
9898
#define FEATURE_PC BIT_ULL(9)
99+
#define FEATURE_HATS GENMASK_ULL(11, 10)
99100
#define FEATURE_GATS GENMASK_ULL(13, 12)
100101
#define FEATURE_GLX GENMASK_ULL(15, 14)
101102
#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

@@ -3060,6 +3062,7 @@ static int __init early_amd_iommu_init(void)
30603062
struct acpi_table_header *ivrs_base;
30613063
int ret;
30623064
acpi_status status;
3065+
u8 efr_hats;
30633066

30643067
if (!amd_iommu_detected)
30653068
return -ENODEV;
@@ -3104,6 +3107,19 @@ static int __init early_amd_iommu_init(void)
31043107
FIELD_GET(FEATURE_GATS, amd_iommu_efr) == GUEST_PGTABLE_5_LEVEL)
31053108
amd_iommu_gpt_level = PAGE_MODE_5_LEVEL;
31063109

3110+
efr_hats = FIELD_GET(FEATURE_HATS, amd_iommu_efr);
3111+
if (efr_hats != 0x3) {
3112+
/*
3113+
* efr[HATS] bits specify the maximum host translation level
3114+
* supported, with LEVEL 4 being initial max level.
3115+
*/
3116+
amd_iommu_hpt_level = efr_hats + PAGE_MODE_4_LEVEL;
3117+
} else {
3118+
pr_warn_once(FW_BUG "Disable host address translation due to invalid translation level (%#x).\n",
3119+
efr_hats);
3120+
amd_iommu_hatdis = true;
3121+
}
3122+
31073123
if (amd_iommu_pgtable == PD_MODE_V2) {
31083124
if (!amd_iommu_v2_pgtbl_supported()) {
31093125
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
@@ -132,7 +132,7 @@ static bool increase_address_space(struct amd_io_pgtable *pgtable,
132132
goto out;
133133

134134
ret = false;
135-
if (WARN_ON_ONCE(pgtable->mode == PAGE_MODE_6_LEVEL))
135+
if (WARN_ON_ONCE(pgtable->mode == amd_iommu_hpt_level))
136136
goto out;
137137

138138
*pte = PM_LEVEL_PDE(pgtable->mode, iommu_virt_to_phys(pgtable->root));
@@ -531,7 +531,7 @@ static void v1_free_pgtable(struct io_pgtable *iop)
531531

532532
/* Page-table is not visible to IOMMU anymore, so free it */
533533
BUG_ON(pgtable->mode < PAGE_MODE_NONE ||
534-
pgtable->mode > PAGE_MODE_6_LEVEL);
534+
pgtable->mode > amd_iommu_hpt_level);
535535

536536
free_sub_pt(pgtable->root, pgtable->mode, &freelist);
537537
iommu_put_pages_list(&freelist);

drivers/iommu/amd/iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,7 @@ static int pdom_setup_pgtable(struct protection_domain *domain,
25032503
static inline u64 dma_max_address(enum protection_domain_mode pgtable)
25042504
{
25052505
if (pgtable == PD_MODE_V1)
2506-
return ~0ULL;
2506+
return PM_LEVEL_SIZE(amd_iommu_hpt_level);
25072507

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

0 commit comments

Comments
 (0)