Re: [PATCH v1 03/26] iommu/amd: Don't rely on external callers to enable IOMMU SNP support

Borislav Petkov
2024-01-04T10:31:36Z

On Sat, Dec 30, 2023 at 10:19:31AM -0600, Michael Roth wrote:
> +static void iommu_snp_enable(void)
> +{
> +#ifdef CONFIG_KVM_AMD_SEV
> + if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP))
> + return;
> + /*
> + * The SNP support requires that IOMMU must be enabled, and is
> + * not configured in the passthrough mode.
> + */
> + if (no_iommu || iommu_default_passthrough()) {
> + pr_err("SNP: IOMMU is disabled or configured in passthrough mode, SNP cannot be supported.\n");
> + return;
> + }
> +
> + amd_iommu_snp_en = check_feature(FEATURE_SNP);
> + if (!amd_iommu_snp_en) {
> + pr_err("SNP: IOMMU SNP feature is not enabled, SNP cannot be supported.\n");
> + return;
> + }
> +
> + pr_info("IOMMU SNP support is enabled.\n");
> +
> + /* Enforce IOMMU v1 pagetable when SNP is enabled. */
> + if (amd_iommu_pgtable != AMD_IOMMU_V1) {
> + pr_warn("Forcing use of AMD IOMMU v1 page table due to SNP.\n");
> + amd_iommu_pgtable = AMD_IOMMU_V1;
> + }

Kernel code usually says simple "<bla> enabled" not "<bla> is enabled".
Other than that, LGTM.

---

diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 1ed2ef22a0fb..2f1517acaba0 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -3231,17 +3231,17 @@ static void iommu_snp_enable(void)
* not configured in the passthrough mode.
*/
if (no_iommu || iommu_default_passthrough()) {
- pr_err("SNP: IOMMU is disabled or configured in passthrough mode, SNP cannot be supported.\n");
+ pr_err("SNP: IOMMU disabled or configured in passthrough mode, SNP cannot be supported.\n");
return;
}

amd_iommu_snp_en = check_feature(FEATURE_SNP);
if (!amd_iommu_snp_en) {
- pr_err("SNP: IOMMU SNP feature is not enabled, SNP cannot be supported.\n");
+ pr_err("SNP: IOMMU SNP feature not enabled, SNP cannot be supported.\n");
return;
}

- pr_info("IOMMU SNP support is enabled.\n");
+ pr_info("IOMMU SNP support enabled.\n");

/* Enforce IOMMU v1 pagetable when SNP is enabled. */
if (amd_iommu_pgtable != AMD_IOMMU_V1) {

--
Regards/Gruss,
Boris.