Skip to content

Commit b43a29d

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
iommu/amd: Add support for nest parent domain allocation
To support nested translation, the nest parent domain is allocated with IOMMU_HWPT_ALLOC_NEST_PARENT flag, and stores information of the v1 page table for stage 2 (i.e. GPA->SPA). Also, only support nest parent domain on AMD system, which can support the Guest CR3 Table (GCR3TRPMode) feature. This feature is required in order to program DTE[GCR3 Table Root Pointer] with the GPA. Reviewed-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent b2bb057 commit b43a29d

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

drivers/iommu/amd/iommu.c

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,23 +2769,43 @@ static struct iommu_domain *amd_iommu_domain_alloc_paging_v2(struct device *dev,
27692769
return &domain->domain;
27702770
}
27712771

2772+
static inline bool is_nest_parent_supported(u32 flags)
2773+
{
2774+
/* Only allow nest parent when these features are supported */
2775+
return check_feature(FEATURE_GT) &&
2776+
check_feature(FEATURE_GIOSUP) &&
2777+
check_feature2(FEATURE_GCR3TRPMODE);
2778+
}
2779+
27722780
static struct iommu_domain *
27732781
amd_iommu_domain_alloc_paging_flags(struct device *dev, u32 flags,
27742782
const struct iommu_user_data *user_data)
27752783

27762784
{
27772785
struct amd_iommu *iommu = get_amd_iommu_from_dev(dev);
27782786
const u32 supported_flags = IOMMU_HWPT_ALLOC_DIRTY_TRACKING |
2779-
IOMMU_HWPT_ALLOC_PASID;
2787+
IOMMU_HWPT_ALLOC_PASID |
2788+
IOMMU_HWPT_ALLOC_NEST_PARENT;
27802789

27812790
if ((flags & ~supported_flags) || user_data)
27822791
return ERR_PTR(-EOPNOTSUPP);
27832792

27842793
switch (flags & supported_flags) {
27852794
case IOMMU_HWPT_ALLOC_DIRTY_TRACKING:
2786-
/* Allocate domain with v1 page table for dirty tracking */
2787-
if (!amd_iommu_hd_support(iommu))
2795+
case IOMMU_HWPT_ALLOC_NEST_PARENT:
2796+
case IOMMU_HWPT_ALLOC_DIRTY_TRACKING | IOMMU_HWPT_ALLOC_NEST_PARENT:
2797+
/*
2798+
* Allocate domain with v1 page table for dirty tracking
2799+
* and/or Nest parent.
2800+
*/
2801+
if ((flags & IOMMU_HWPT_ALLOC_DIRTY_TRACKING) &&
2802+
!amd_iommu_hd_support(iommu))
2803+
break;
2804+
2805+
if ((flags & IOMMU_HWPT_ALLOC_NEST_PARENT) &&
2806+
!is_nest_parent_supported(flags))
27882807
break;
2808+
27892809
return amd_iommu_domain_alloc_paging_v1(dev, flags);
27902810
case IOMMU_HWPT_ALLOC_PASID:
27912811
/* Allocate domain with v2 page table if IOMMU supports PASID. */

0 commit comments

Comments
 (0)