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 6/7] crypto/ccp: Register with fw_uploader and always fail
Date: Fri, 18 Sep 2026 16:41:00 +0000 [thread overview]
Message-ID: <7464499e7c352c1ab16c50700f9f68561f84ede5.1789749016.git.prsampat@amd.com> (raw)
In-Reply-To: <cover.1789749016.git.prsampat@amd.com>
In preparation for SEV-SNP DOWNLOAD_FIRMWARE_EX live firmware update
support, add an 'sev' firmware loader that always fails with EBUSY.
Co-developed-by: Tycho Andersen (AMD) <tycho@kernel.org>
Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
Signed-off-by: Pratik R. Sampat <prsampat@amd.com>
---
v1..v2:
Use an atomic to get sev->fwl state to ensure that isn't a race possible
while unregistering the interfaces - Sashiko
---
drivers/crypto/ccp/sev-dev.c | 79 ++++++++++++++++++++++++++++++++++++
drivers/crypto/ccp/sev-dev.h | 2 +
2 files changed, 81 insertions(+)
diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 3704f52bd08d..f3714e8f5ab1 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -2208,6 +2208,79 @@ static int sev_update_firmware(struct device *dev)
return ret;
}
+#ifdef CONFIG_FW_UPLOAD
+static enum fw_upload_err sev_fw_upload_prepare(struct fw_upload *fw_upload,
+ const u8 *data, u32 size)
+{
+ return FW_UPLOAD_ERR_NONE;
+}
+
+static enum fw_upload_err sev_fw_upload_write(struct fw_upload *fw_upload,
+ const u8 *data, u32 offset,
+ u32 size, u32 *written)
+{
+ return FW_UPLOAD_ERR_BUSY;
+}
+
+static enum fw_upload_err sev_fw_upload_poll_complete(struct fw_upload *fw_upload)
+{
+ return FW_UPLOAD_ERR_NONE;
+}
+
+static void sev_fw_upload_cancel(struct fw_upload *fw_upload)
+{
+ /* intentional no-op */
+}
+
+static const struct fw_upload_ops sev_fw_upload_ops = {
+ .prepare = sev_fw_upload_prepare,
+ .write = sev_fw_upload_write,
+ .poll_complete = sev_fw_upload_poll_complete,
+ .cancel = sev_fw_upload_cancel,
+};
+
+static void register_sev_fw_uploader(struct sev_device *sev)
+{
+ struct fw_upload *fwl;
+
+ /*
+ * SNP firmware update is a platform-wide operation; only the master
+ * PSP issues firmware commands. Register a single global interface.
+ */
+ if (sev->psp != psp_master || sev->fwl)
+ return;
+
+ fwl = firmware_upload_register(sev->dev, "sev", &sev_fw_upload_ops,
+ sev);
+ if (IS_ERR(fwl)) {
+ dev_err(sev->dev, "SEV firmware upload registration failure: %ld\n",
+ PTR_ERR(fwl));
+ return;
+ }
+
+ sev->fwl = fwl;
+}
+
+/*
+ * The upload ops issue PSP commands, so the interface has to be gone before
+ * the SEV firmware is shut down and the PSP interrupt handler is cleared.
+ * devm teardown on sev->dev runs after the driver's remove callback and is
+ * therefore too late. Both teardown paths call this, and a module removal can
+ * run concurrently with a sysfs unbind, so claim the pointer atomically to
+ * keep the unregister to a single caller.
+ */
+static void unregister_sev_fw_uploader(struct sev_device *sev)
+{
+ struct fw_upload *fwl = xchg(&sev->fwl, NULL);
+
+ if (fwl)
+ firmware_upload_unregister(fwl);
+}
+#else /* CONFIG_FW_UPLOAD */
+static void register_sev_fw_uploader(struct sev_device *sev) { }
+static void unregister_sev_fw_uploader(struct sev_device *sev) { }
+#endif /* CONFIG_FW_UPLOAD */
+
static int __sev_snp_shutdown_locked(int *error, bool panic)
{
struct psp_device *psp = psp_master;
@@ -3014,6 +3087,8 @@ void sev_dev_destroy(struct psp_device *psp)
if (!sev)
return;
+ unregister_sev_fw_uploader(sev);
+
sev_firmware_shutdown(sev);
if (sev->misc)
@@ -3077,6 +3152,8 @@ void sev_pci_init(void)
api_major, api_minor, build,
sev->api_major, sev->api_minor, sev->build);
+ register_sev_fw_uploader(sev);
+
return;
err:
@@ -3092,6 +3169,8 @@ void sev_pci_exit(void)
if (!sev)
return;
+ unregister_sev_fw_uploader(sev);
+
sev_firmware_shutdown(sev);
}
diff --git a/drivers/crypto/ccp/sev-dev.h b/drivers/crypto/ccp/sev-dev.h
index d5e596606def..7ec692e2147e 100644
--- a/drivers/crypto/ccp/sev-dev.h
+++ b/drivers/crypto/ccp/sev-dev.h
@@ -69,6 +69,8 @@ struct sev_device {
struct tsm_dev *tsmdev;
struct sev_tio_status *tio_status;
+
+ struct fw_upload *fwl;
};
int sev_dev_init(struct psp_device *psp);
--
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 ` [Patch v2 4/7] crypto: ccp - Factor out the release of the SEV firmware buffers Pratik R. Sampat
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 ` Pratik R. Sampat [this message]
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=7464499e7c352c1ab16c50700f9f68561f84ede5.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®