Re: [Patch v4 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers

From: Tom Lendacky

Date: Thu Oct 15 2026 - 14:02:37 EST


On 10/14/26 21:14, Pratik R. Sampat wrote:
> __sev_firmware_shutdown() reclaims and frees the TMR and the INIT_EX NV
> area once the platform has been taken down. Move that into a helper so
> that other paths which de-initialize the platform can reuse the same
> path.
>
> No functional change intended.
>
> Suggested-by: Shantanu Sinha <shansinha@xxxxxxxxxx>
> Signed-off-by: Pratik R. Sampat <prsampat@xxxxxxx>

Reviewed-by: Tom Lendacky <thomas.lendacky@xxxxxxx>

> ---
> v3..v4:
> No change
> ---
> drivers/crypto/ccp/sev-dev.c | 55 ++++++++++++++++++++----------------
> 1 file changed, 30 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index f833cb7e4da3..1ed9e61a95cc 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1881,6 +1881,35 @@ static int __sev_platform_shutdown_locked(int *error)
> return ret;
> }
>
> +static void __sev_release_firmware_buffers(bool panic)
> +{
> + if (sev_es_tmr) {
> + /*
> + * The TMR area was encrypted, flush it from the cache.
> + *
> + * If invoked during panic handling, local interrupts are
> + * disabled and all CPUs are stopped, so wbinvd_on_all_cpus()
> + * can't be used. In that case, wbinvd() is done on remote CPUs
> + * via the NMI callback, and done for this CPU later during
> + * SNP shutdown, so wbinvd_on_all_cpus() can be skipped.
> + */
> + if (!panic)
> + wbinvd_on_all_cpus();
> +
> + __snp_free_firmware_pages(virt_to_page(sev_es_tmr),
> + get_order(sev_es_tmr_size),
> + true);
> + sev_es_tmr = NULL;
> + }
> +
> + if (sev_init_ex_buffer) {
> + __snp_free_firmware_pages(virt_to_page(sev_init_ex_buffer),
> + get_order(NV_LENGTH),
> + true);
> + sev_init_ex_buffer = NULL;
> + }
> +}
> +
> static int sev_get_platform_state(int *state, int *error)
> {
> struct sev_user_data_status data;
> @@ -2906,31 +2935,7 @@ static void __sev_firmware_shutdown(struct sev_device *sev, bool panic)
>
> __sev_platform_shutdown_locked(&error);
>
> - if (sev_es_tmr) {
> - /*
> - * The TMR area was encrypted, flush it from the cache.
> - *
> - * If invoked during panic handling, local interrupts are
> - * disabled and all CPUs are stopped, so wbinvd_on_all_cpus()
> - * can't be used. In that case, wbinvd() is done on remote CPUs
> - * via the NMI callback, and done for this CPU later during
> - * SNP shutdown, so wbinvd_on_all_cpus() can be skipped.
> - */
> - if (!panic)
> - wbinvd_on_all_cpus();
> -
> - __snp_free_firmware_pages(virt_to_page(sev_es_tmr),
> - get_order(sev_es_tmr_size),
> - true);
> - sev_es_tmr = NULL;
> - }
> -
> - if (sev_init_ex_buffer) {
> - __snp_free_firmware_pages(virt_to_page(sev_init_ex_buffer),
> - get_order(NV_LENGTH),
> - true);
> - sev_init_ex_buffer = NULL;
> - }
> + __sev_release_firmware_buffers(panic);
>
> __sev_snp_shutdown_locked(&error, panic);
> }