From: "Pratik R. Sampat" <prsampat@amd.com>
To: <mcgrof@kernel.org>, <russ.weight@linux.dev>, <dakr@kernel.org>,
<ashish.kalra@amd.com>, <thomas.lendacky@amd.com>,
<herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<gregkh@linuxfoundation.org>, <rafael@kernel.org>,
<chao.gao@intel.com>, <aik@amd.com>, <tycho@kernel.org>,
<nikunj@amd.com>, <michael.roth@amd.com>, <shansinha@google.com>,
<prsampat@amd.com>
Subject: [Patch v2 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers
Date: Fri, 18 Sep 2026 16:40:58 +0000 [thread overview]
Message-ID: <fb9920e37b5c06fe841099331e6abe4c671a754f.1789749016.git.prsampat@amd.com> (raw)
In-Reply-To: <cover.1789749016.git.prsampat@amd.com>
__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@google.com>
Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
---
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);
}
--
2.43.0
next prev parent reply other threads:[~2026-09-18 16:42 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-18 16:40 [Patch v2 0/7] Implement SNP live firmware update support Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 1/7] firmware_loader: Stop pinning modules on registration Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 2/7] firmware_loader: Stop pinning parent device per workqueue invocation Pratik R. Sampat
2026-09-18 16:40 ` [Patch v2 3/7] treewide: firmware_loader: Drop the unused @module argument Pratik R. Sampat
2026-09-18 16:40 ` Pratik R. Sampat [this message]
2026-09-18 16:40 ` [Patch v2 5/7] crypto: ccp - Allow SNP platform data to be queried after SNP INIT Pratik R. Sampat
2026-09-18 16:41 ` [Patch v2 6/7] crypto/ccp: Register with fw_uploader and always fail Pratik R. Sampat
2026-09-18 16:41 ` [Patch v2 7/7] crypto/ccp: Implement SNP Download Firmware EX Pratik R. Sampat
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fb9920e37b5c06fe841099331e6abe4c671a754f.1789749016.git.prsampat@amd.com \
--to=prsampat@amd.com \
--cc=aik@amd.com \
--cc=ashish.kalra@amd.com \
--cc=chao.gao@intel.com \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=michael.roth@amd.com \
--cc=nikunj@amd.com \
--cc=rafael@kernel.org \
--cc=russ.weight@linux.dev \
--cc=shansinha@google.com \
--cc=thomas.lendacky@amd.com \
--cc=tycho@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®