On 2022-06-16 02:55, Suravee Suthikulpanit wrote:
Once SNP is enabled (by executing SNP_INIT command), IOMMU can no longer
support the passthrough domain (i.e. IOMMU_DOMAIN_IDENTITY).

The SNP_INIT command is called early in the boot process, and would fail
if the kernel is configure to default to passthrough mode.

After the system is already booted, users can try to change IOMMU domain
type of a particular IOMMU group. In this case, the IOMMU driver needs to
check the SNP-enable status and return failure when requesting to change
domain type to identity.

Therefore, return failure when trying to allocate identity domain.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
---
  drivers/iommu/amd/iommu.c | 9 +++++++++
  1 file changed, 9 insertions(+)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 4f4571d3ff61..d8a6df423b90 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2119,6 +2119,15 @@ static struct iommu_domain 
*amd_iommu_domain_alloc(unsigned type)
  {
        struct protection_domain *domain;
+ /*
+        * Since DTE[Mode]=0 is prohibited on SNP-enabled system,
+        * default to use IOMMU_DOMAIN_DMA[_FQ].
+        */
+       if (amd_iommu_snp_en && (type == IOMMU_DOMAIN_IDENTITY)) {
+               pr_warn("Cannot allocate identity domain due to SNP\n");

Maybe pr_warn_once? Although on the other hand, perhaps anyone with the privilege to be messing with the sysfs interface at all could be trusted not to flood their own logs :/

Either way,

Reviewed-by: Robin Murphy <robin.mur...@arm.com>

+               return NULL;
+       }
+
        domain = protection_domain_alloc(type);
        if (!domain)
                return NULL;
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Reply via email to