On 3/2/26 13:13, Tycho Andersen wrote:
> From: "Tycho Andersen (AMD)" <tycho@kernel.org>
>
> After SNP_SHUTDOWN, two architecture-level things should be done:
>
> 1. clear the RMP table
> 2. disable MFDM to prevent the FW_WARN in k8_check_syscfg_dram_mod_en() in
> the event of a kexec
>
> Create and export to the CCP driver a function that does them.
>
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
> ---
> arch/x86/include/asm/sev.h | 2 ++
> arch/x86/virt/svm/sev.c | 7 +++++++
> 2 files changed, 9 insertions(+)
>
> diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
> index 0bcd89d4fe90..36d2b1ea19c0 100644
> --- a/arch/x86/include/asm/sev.h
> +++ b/arch/x86/include/asm/sev.h
> @@ -662,6 +662,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int pages)
> __snp_leak_pages(pfn, pages, true);
> }
> void snp_prepare_for_snp_init(void);
> +void snp_x86_shutdown(void);
> #else
> static inline bool snp_probe_rmptable_info(void) { return false; }
> static inline int snp_rmptable_init(void) { return -ENOSYS; }
> @@ -679,6 +680,7 @@ static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
> static inline void kdump_sev_callback(void) { }
> static inline void snp_fixup_e820_tables(void) {}
> static inline void snp_prepare_for_snp_init(void) {}
> +static inline void snp_x86_shutdown(void) {}
> #endif
>
> #endif
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index cf984b8f4493..0524fc77b44d 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -544,6 +544,13 @@ void snp_prepare_for_snp_init(void)
> }
> EXPORT_SYMBOL_FOR_MODULES(snp_prepare_for_snp_init, "ccp");
>
> +void snp_x86_shutdown(void)
> +{
Would it make sense to check for SNP being enabled before calling the
functions below? I realize each of the functions in question will do
that, but it could save a bunch of IPI's with the on_each_cpu() if SNP
is still enabled. Not a big deal either way, so:
Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>
Thanks,
Tom
> + snp_clear_rmp();
> + on_each_cpu(mfd_reconfigure, 0, 1);
> +}
> +EXPORT_SYMBOL_FOR_MODULES(snp_x86_shutdown, "ccp");
> +
> /*
> * Do the necessary preparations which are verified by the firmware as
> * described in the SNP_INIT_EX firmware command description in the SNP