platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: "Mario Limonciello (AMD)" <superm1@kernel.org>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Shyam Sundar S K" <Shyam-sundar.S-k@amd.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: John Allen <john.allen@amd.com>,
	"David S . Miller" <davem@davemloft.net>,
	Hans de Goede <hansg@kernel.org>,
	"open list:AMD CRYPTOGRAPHIC COPROCESSOR (CCP) DRIVER"
	<linux-crypto@vger.kernel.org>,
	"open list:AMD PMF DRIVER" <platform-driver-x86@vger.kernel.org>,
	Lars Francke <lars.francke@gmail.com>
Subject: Re: [PATCH v2 3/4] crypto: ccp - Add an S4 restore flow
Date: Thu, 11 Dec 2025 16:03:23 -0600	[thread overview]
Message-ID: <41f436c5-d11a-4de1-b994-e88bf21047a5@amd.com> (raw)
In-Reply-To: <20251211212847.11980-4-superm1@kernel.org>

On 12/11/25 15:28, Mario Limonciello (AMD) wrote:
> The system will have lost power during S4.  The ring used for TEE
> communications needs to be initialized before use.
> 
> Fixes: f892a21f51162 ("crypto: ccp - use generic power management")
> Reported-by: Lars Francke <lars.francke@gmail.com>
> Closes: https://lore.kernel.org/platform-driver-x86/CAD-Ua_gfJnQSo8ucS_7ZwzuhoBRJ14zXP7s8b-zX3ZcxcyWePw@mail.gmail.com/
> Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> v2:
>  * Fix LKP errors
>  * Remove free phase
> ---
>  drivers/crypto/ccp/sp-dev.c  | 13 +++++++++++++
>  drivers/crypto/ccp/sp-dev.h  |  1 +
>  drivers/crypto/ccp/sp-pci.c  | 16 +++++++++++++++-
>  drivers/crypto/ccp/tee-dev.c |  5 +++++
>  drivers/crypto/ccp/tee-dev.h |  6 ++++++
>  5 files changed, 40 insertions(+), 1 deletion(-)

This should follow the same type of flow that initialization follows by
checking for psp_vdata and calling a restore function in psp-dev.c. The
restore function in psp-dev.c in turn calls tee.

Thanks,
Tom

> 
> diff --git a/drivers/crypto/ccp/sp-dev.c b/drivers/crypto/ccp/sp-dev.c
> index 3467f6db4f50..e3fa94d14026 100644
> --- a/drivers/crypto/ccp/sp-dev.c
> +++ b/drivers/crypto/ccp/sp-dev.c
> @@ -21,6 +21,7 @@
>  
>  #include "sev-dev.h"
>  #include "ccp-dev.h"
> +#include "tee-dev.h"
>  #include "sp-dev.h"
>  
>  MODULE_AUTHOR("Tom Lendacky <thomas.lendacky@amd.com>");
> @@ -230,6 +231,18 @@ int sp_resume(struct sp_device *sp)
>  	return 0;
>  }
>  
> +int sp_restore(struct sp_device *sp)
> +{
> +	if (sp->dev_vdata->psp_vdata->tee) {
> +		int r = tee_restore(sp->psp_data);
> +
> +		if (r)
> +			return r;
> +	}
> +
> +	return sp_resume(sp);
> +}
> +
>  struct sp_device *sp_get_psp_master_device(void)
>  {
>  	struct sp_device *i, *ret = NULL;
> diff --git a/drivers/crypto/ccp/sp-dev.h b/drivers/crypto/ccp/sp-dev.h
> index 6f9d7063257d..37b38afaab14 100644
> --- a/drivers/crypto/ccp/sp-dev.h
> +++ b/drivers/crypto/ccp/sp-dev.h
> @@ -141,6 +141,7 @@ void sp_destroy(struct sp_device *sp);
>  
>  int sp_suspend(struct sp_device *sp);
>  int sp_resume(struct sp_device *sp);
> +int sp_restore(struct sp_device *sp);
>  int sp_request_ccp_irq(struct sp_device *sp, irq_handler_t handler,
>  		       const char *name, void *data);
>  void sp_free_ccp_irq(struct sp_device *sp, void *data);
> diff --git a/drivers/crypto/ccp/sp-pci.c b/drivers/crypto/ccp/sp-pci.c
> index e7bb803912a6..ce55563b224d 100644
> --- a/drivers/crypto/ccp/sp-pci.c
> +++ b/drivers/crypto/ccp/sp-pci.c
> @@ -353,6 +353,13 @@ static int __maybe_unused sp_pci_resume(struct device *dev)
>  	return sp_resume(sp);
>  }
>  
> +static int __maybe_unused sp_pci_restore(struct device *dev)
> +{
> +	struct sp_device *sp = dev_get_drvdata(dev);
> +
> +	return sp_restore(sp);
> +}
> +
>  #ifdef CONFIG_CRYPTO_DEV_SP_PSP
>  static const struct sev_vdata sevv1 = {
>  	.cmdresp_reg		= 0x10580,	/* C2PMSG_32 */
> @@ -544,7 +551,14 @@ static const struct pci_device_id sp_pci_table[] = {
>  };
>  MODULE_DEVICE_TABLE(pci, sp_pci_table);
>  
> -static SIMPLE_DEV_PM_OPS(sp_pci_pm_ops, sp_pci_suspend, sp_pci_resume);
> +static const struct dev_pm_ops sp_pci_pm_ops = {
> +	.suspend = pm_sleep_ptr(sp_pci_suspend),
> +	.resume = pm_sleep_ptr(sp_pci_resume),
> +	.freeze = pm_sleep_ptr(sp_pci_suspend),
> +	.thaw = pm_sleep_ptr(sp_pci_resume),
> +	.poweroff = pm_sleep_ptr(sp_pci_suspend),
> +	.restore_early = pm_sleep_ptr(sp_pci_restore),
> +};
>  
>  static struct pci_driver sp_pci_driver = {
>  	.name = "ccp",
> diff --git a/drivers/crypto/ccp/tee-dev.c b/drivers/crypto/ccp/tee-dev.c
> index af881daa5855..11c4b05e2f3a 100644
> --- a/drivers/crypto/ccp/tee-dev.c
> +++ b/drivers/crypto/ccp/tee-dev.c
> @@ -366,3 +366,8 @@ int psp_check_tee_status(void)
>  	return 0;
>  }
>  EXPORT_SYMBOL(psp_check_tee_status);
> +
> +int tee_restore(struct psp_device *psp)
> +{
> +	return tee_init_ring(psp->tee_data);
> +}
> diff --git a/drivers/crypto/ccp/tee-dev.h b/drivers/crypto/ccp/tee-dev.h
> index ea9a2b7c05f5..3409253ac557 100644
> --- a/drivers/crypto/ccp/tee-dev.h
> +++ b/drivers/crypto/ccp/tee-dev.h
> @@ -112,4 +112,10 @@ struct tee_ring_cmd {
>  int tee_dev_init(struct psp_device *psp);
>  void tee_dev_destroy(struct psp_device *psp);
>  
> +#ifdef CONFIG_CRYPTO_DEV_SP_PSP
> +int tee_restore(struct psp_device *psp);
> +#else
> +static inline int tee_restore(struct psp_device *psp) { return 0; }
> +#endif /* CONFIG_CRYPTO_DEV_SP_PSP */
> +
>  #endif /* __TEE_DEV_H__ */


  reply	other threads:[~2025-12-11 22:03 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-11 21:28 [PATCH v2 0/4] Fixes for PMF and CCP drivers after S4 Mario Limonciello (AMD)
2025-12-11 21:28 ` [PATCH v2 1/4] platform/x86/amd/pmf: Prevent TEE errors after hibernate Mario Limonciello (AMD)
2025-12-11 21:28 ` [PATCH v2 2/4] crypto: ccp - Declare PSP dead if PSP_CMD_TEE_RING_INIT fails Mario Limonciello (AMD)
2025-12-11 21:28 ` [PATCH v2 3/4] crypto: ccp - Add an S4 restore flow Mario Limonciello (AMD)
2025-12-11 22:03   ` Tom Lendacky [this message]
2025-12-11 21:28 ` [PATCH v2 4/4] crypto: ccp - Send PSP_CMD_TEE_RING_DESTROY when PSP_CMD_TEE_RING_INIT fails Mario Limonciello (AMD)
2025-12-11 22:21   ` Tom Lendacky
2025-12-13 19:05   ` Shyam Sundar S K
2025-12-11 22:23 ` [PATCH v2 0/4] Fixes for PMF and CCP drivers after S4 Tom Lendacky

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=41f436c5-d11a-4de1-b994-e88bf21047a5@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=Shyam-sundar.S-k@amd.com \
    --cc=davem@davemloft.net \
    --cc=hansg@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=john.allen@amd.com \
    --cc=lars.francke@gmail.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=superm1@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;
as well as URLs for NNTP newsgroup(s).