]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: ccp - Reverse the cleanup order in psp_dev_destroy()
authorTycho Andersen (AMD) <tycho@kernel.org>
Wed, 8 Apr 2026 14:32:56 +0000 (08:32 -0600)
committerHerbert Xu <herbert@gondor.apana.org.au>
Thu, 7 May 2026 08:09:58 +0000 (16:09 +0800)
Before SNP x86 shutdown [1], all HV_FIXED pages were always leaked on
module unload. Now pages can be reclaimed if they are freed before SNP
shutdown.

The SFS driver does sfs_dev_destroy() -> snp_free_hv_fixed_pages(), marking
the command buffer as free. But this happens after sev_dev_destroy() in
psp_dev_destroy(), so the pages are always leaked.

Rearrange psp_dev_destroy() to destroy things in the reverse order from
psp_init(), so that any dependencies can be unwound accordingly. This lets
SFS free the page and the subsequent SNP shutdown release it.

This was identified with use of Chris Mason's review-prompts:
https://github.com/masoncl/review-prompts

[1]: https://lore.kernel.org/all/20260324161301.1353976-1-tycho@kernel.org/

Fixes: 648dbccc03a0 ("crypto: ccp - Add AMD Seamless Firmware Servicing (SFS) driver")
Reported-by: review-prompts
Assisted-by: Claude:claude-4.6-opus
Suggested-by: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
Reviewed-by: Ashish Kalra <ashish.kalra@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/ccp/psp-dev.c

index 5c7f7e02a7d8ab14b89cc26c4cce3c1fc97f193e..b14ce51065d5dac65b23596a4454d8456ec1d19e 100644 (file)
@@ -316,15 +316,15 @@ void psp_dev_destroy(struct sp_device *sp)
        if (!psp)
                return;
 
-       sev_dev_destroy(psp);
+       dbc_dev_destroy(psp);
 
-       tee_dev_destroy(psp);
+       platform_access_dev_destroy(psp);
 
        sfs_dev_destroy(psp);
 
-       dbc_dev_destroy(psp);
+       tee_dev_destroy(psp);
 
-       platform_access_dev_destroy(psp);
+       sev_dev_destroy(psp);
 
        sp_free_psp_irq(sp, psp);