mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kim Phillips <kim.phillips@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>
Cc: Mario Limonciello <mario.limonciello@amd.com>,
	<linux-crypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Kim Phillips <kim.phillips@amd.com>
Subject: [PATCH] crypto: ccp - Run the destroy callbacks when psp_init() fails
Date: Wed, 21 Oct 2026 16:57:16 -0500	[thread overview]
Message-ID: <20261021215716.1076732-1-kim.phillips@amd.com> (raw)

psp_init() brings up SEV, TEE, SFS, platform access, DBC and HSTI in
turn, returning on the first failure.  psp_dev_init() then clears
sp->psp_data, and sp_init() ignores its return value, so the device stays
bound.  At unbind, sp_destroy() calls psp_dev_destroy(), which returns
early on the now NULL psp_data, and no subsystem destroy callback ever
runs.

Whatever came up before the failing subsystem is therefore abandoned.  Not
everything it owns is devres-managed: tee_dev_init() allocates its ring
with __get_free_pages() and it is freed only by tee_destroy_ring(), so a
failure anywhere after TEE leaks the ring.  DBC and SFS are worse than a
leak.  Both register a misc device during init, and both deregister it
from their destroy callback, so a psp_init_hsti() failure leaves a live
/dev node whose backing state devres frees at unbind.

Call psp_dev_destroy() on that path instead of open-coding the IRQ and
master device teardown.  Every destroy callback returns early when its
subsystem pointer is NULL, and psp is devm_kzalloc()'d, so unwinding a
partial init is safe.  This also fixes the teardown order: the callbacks
now run before the master device is cleared, which matters because
__sev_platform_shutdown_locked() reaches the device through psp_master.

sev_dev_destroy() is reachable here without interrupts having been enabled
yet, but it does not issue a command: firmware INIT happens later in
sev_pci_init(), so the state is still SEV_STATE_UNINIT and
__sev_platform_shutdown_locked() returns without touching the mailbox.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
---
 drivers/crypto/ccp/psp-dev.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/crypto/ccp/psp-dev.c b/drivers/crypto/ccp/psp-dev.c
index b14ce51065d5..4eb49eff9590 100644
--- a/drivers/crypto/ccp/psp-dev.c
+++ b/drivers/crypto/ccp/psp-dev.c
@@ -282,7 +282,7 @@ int psp_dev_init(struct sp_device *sp)
 
 	ret = psp_init(psp);
 	if (ret)
-		goto e_irq;
+		goto e_destroy;
 
 	/* Enable interrupt */
 	iowrite32(-1, psp->io_regs + psp->vdata->inten_reg);
@@ -291,11 +291,15 @@ int psp_dev_init(struct sp_device *sp)
 
 	return 0;
 
-e_irq:
-	if (sp->clear_psp_master_device)
-		sp->clear_psp_master_device(sp);
-
-	sp_free_psp_irq(psp->sp, psp);
+e_destroy:
+	/*
+	 * Subsystems that came up before the failure own resources devres
+	 * cannot reclaim - TEE's ring pages, the DBC and SFS misc devices -
+	 * and psp_data is cleared below, which puts them out of reach of
+	 * sp_destroy(). Each destroy no-ops on a subsystem that never
+	 * initialized, and this also drops the IRQ and master device.
+	 */
+	psp_dev_destroy(sp);
 e_err:
 	sp->psp_data = NULL;
 
-- 
2.43.0


             reply	other threads:[~2026-10-21 21:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 21:57 Kim Phillips [this message]
2026-10-22 17:26 ` Kim Phillips

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=20261021215716.1076732-1-kim.phillips@amd.com \
    --to=kim.phillips@amd.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=thomas.lendacky@amd.com \
    /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®