Re: [PATCH v3 3/3] x86/sev: Fix broken SNP support with KVM module built-in

From: Sean Christopherson
Date: Wed Feb 05 2025 - 10:31:22 EST


On Wed, Feb 05, 2025, Vasant Hegde wrote:
> Hi Ashish,
>
> [Sorry. I didn't see this series and responded to v2].

Heh, and then I saw your other email first and did the same. Copying my response
here, too (and fixing a few typos in the process).

> > diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> > index c5cd92edada0..4bcb474e2252 100644
> > --- a/drivers/iommu/amd/init.c
> > +++ b/drivers/iommu/amd/init.c
> > @@ -3194,7 +3194,7 @@ static bool __init detect_ivrs(void)
> > return true;
> > }
> >
> > -static void iommu_snp_enable(void)
> > +static __init void iommu_snp_enable(void)
> > {
> > #ifdef CONFIG_KVM_AMD_SEV
> > if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
> > @@ -3219,6 +3219,14 @@ static void iommu_snp_enable(void)
> > goto disable_snp;
> > }
> >
> > + /*
> > + * Enable host SNP support once SNP support is checked on IOMMU.
> > + */
> > + if (snp_rmptable_init()) {
> > + pr_warn("SNP: RMP initialization failed, SNP cannot be supported.\n");
> > + goto disable_snp;
> > + }
> > +
> > pr_info("IOMMU SNP support enabled.\n");
> > return;
> >
> > @@ -3318,6 +3326,9 @@ static int __init iommu_go_to_state(enum iommu_init_state state)
> > ret = state_next();
> > }
> >
> > + if (ret && !amd_iommu_snp_en && cc_platform_has(CC_ATTR_HOST_SEV_SNP))
>
>
> I think we should clear when `amd_iommu_snp_en` is true.

That doesn't address the case where amd_iommu_prepare() fails, because amd_iommu_snp_en
will be %false (its init value) and the RMP will be uninitialized, i.e.
CC_ATTR_HOST_SEV_SNP will be incorrectly left set.

And conversely, IMO clearing CC_ATTR_HOST_SEV_SNP after initializing the IOMMU
and RMP is wrong as well. Such a host is probably hosed regardless, but from
the CPU's perspective, SNP is supported and enabled.

> May be below check is enough?
>
> if (ret && amd_iommu_snp_en)
>
>
> -Vasant
>
>