When hardware/VM request a small VA limit, the generic page table code
clears PT_FEAT_DYNAMIC_TOP. This later causes domain initialization to
fail with -EOPNOTSUPP.
To properly enforce the domain VA limit, clamp amdv1pt_possible_sizes
using the requested max_vasz_lg2.
Signed-off-by: Ankit Soni <Ankit.Soni@amd.com>
---
drivers/iommu/generic_pt/fmt/amdv1.h | 4 +++-
drivers/iommu/generic_pt/iommu_pt.h | 4 ----
2 files changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/generic_pt/fmt/amdv1.h b/drivers/iommu/generic_pt/fmt/amdv1.h
index 3b2c41d9654d..bc04d482c12f 100644
--- a/drivers/iommu/generic_pt/fmt/amdv1.h
+++ b/drivers/iommu/generic_pt/fmt/amdv1.h
@@ -156,6 +156,7 @@ static inline unsigned int amdv1pt_num_items_lg2(const struct pt_state *pts)
static inline pt_vaddr_t amdv1pt_possible_sizes(const struct pt_state *pts)
{
unsigned int isz_lg2 = pt_table_item_lg2sz(pts);
+ pt_vaddr_t raw;
if (!amdv1pt_can_have_leaf(pts))
return 0;
@@ -168,8 +169,9 @@ static inline pt_vaddr_t amdv1pt_possible_sizes(const struct pt_state *pts)
* 512GB Pages are not supported due to a hardware bug.
* Otherwise every power of two size is supported.
*/
- return GENMASK_ULL(min(51, isz_lg2 + amdv1pt_num_items_lg2(pts) - 1),
+ raw = GENMASK_ULL(min(51, isz_lg2 + amdv1pt_num_items_lg2(pts) - 1),
isz_lg2) & ~SZ_512G;
+ return fvalog2_mod(raw, pts->range->common->max_vasz_lg2);
}
#define pt_possible_sizes amdv1pt_possible_sizes
diff --git a/drivers/iommu/generic_pt/iommu_pt.h b/drivers/iommu/generic_pt/iommu_pt.h
index 3e33fe64feab..a3dc5cf14aeb 100644
--- a/drivers/iommu/generic_pt/iommu_pt.h
+++ b/drivers/iommu/generic_pt/iommu_pt.h
@@ -1125,10 +1125,6 @@ static int pt_init_common(struct pt_common *common)
if (PT_WARN_ON(top_range.top_level > PT_MAX_TOP_LEVEL))
return -EINVAL;
- if (top_range.top_level == PT_MAX_TOP_LEVEL ||
- common->max_vasz_lg2 == top_range.max_vasz_lg2)
- common->features &= ~BIT(PT_FEAT_DYNAMIC_TOP);
-
if (top_range.max_vasz_lg2 == PT_VADDR_MAX_LG2)
common->features |= BIT(PT_FEAT_FULL_VA);
--
2.43.0