Re: [PATCH v5 1/7] crypto: ccp: Move dev_info/err messages for SEV/SNP init and shutdown

Tom Lendacky
2025-03-03T14:38:54Z

On 2/25/25 14:59, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> Move dev_info and dev_err messages related to SEV/SNP initialization
> and shutdown into __sev_platform_init_locked(), __sev_snp_init_locked()
> and __sev_platform_shutdown_locked(), __sev_snp_shutdown_locked() so
> that they don't need to be issued from callers.
>
> This allows both _sev_platform_init_locked() and various SEV/SNP ioctls
> to call __sev_platform_init_locked(), __sev_snp_init_locked() and
> __sev_platform_shutdown_locked(), __sev_snp_shutdown_locked() for
> implicit SEV/SNP initialization and shutdown without additionally
> printing any errors/success messages.
>
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
> ---
> drivers/crypto/ccp/sev-dev.c | 44 ++++++++++++++++++++++++++----------
> 1 file changed, 32 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 2e87ca0e292a..8962a0dbc66f 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -1176,21 +1176,31 @@ static int __sev_snp_init_locked(int *error)
> wbinvd_on_all_cpus();
>
> rc = __sev_do_cmd_locked(cmd, arg, error);
> - if (rc)
> + if (rc) {
> + dev_err(sev->dev, "SEV-SNP: %s failed rc %d, error %#x\n",
> + cmd == SEV_CMD_SNP_INIT_EX ? "SNP_INIT_EX" : "SNP_INIT",
> + rc, *error);
> return rc;
> + }
>
> /* Prepare for first SNP guest launch after INIT. */
> wbinvd_on_all_cpus();
> rc = __sev_do_cmd_locked(SEV_CMD_SNP_DF_FLUSH, NULL, error);
> - if (rc)
> + if (rc) {
> + dev_err(sev->dev, "SEV-SNP: SNP_DF_FLUSH failed rc %d, error %#x\n",
> + rc, *error);
> return rc;
> + }
>
> sev->snp_initialized = true;
> dev_dbg(sev->dev, "SEV-SNP firmware initialized\n");
>
> + dev_info(sev->dev, "SEV-SNP API:%d.%d build:%d\n", sev->api_major,
> + sev->api_minor, sev->build);
> +
> sev_es_tmr_size = SNP_TMR_SIZE;
>
> - return rc;
> + return 0;
> }
>
> static void __sev_platform_init_handle_tmr(struct sev_device *sev)
> @@ -1287,16 +1297,22 @@ static int __sev_platform_init_locked(int *error)
> if (error)
> *error = psp_ret;
>
> - if (rc)
> + if (rc) {
> + dev_err(sev->dev, "SEV: %s failed %#x, rc %d\n",
> + sev_init_ex_buffer ? "INIT_EX" : "INIT", psp_ret, rc);
> return rc;
> + }
>
> sev->state = SEV_STATE_INIT;
>
> /* Prepare for first SEV guest launch after INIT */
> wbinvd_on_all_cpus();
> rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, error);
> - if (rc)
> + if (rc) {
> + dev_err(sev->dev, "SEV: DF_FLUSH failed %#x, rc %d\n",
> + *error, rc);
> return rc;
> + }
>
> dev_dbg(sev->dev, "SEV firmware initialized\n");
>
> @@ -1329,8 +1345,7 @@ static int _sev_platform_init_locked(struct sev_platform_init_args *args)
> * Don't abort the probe if SNP INIT failed,
> * continue to initialize the legacy SEV firmware.
> */
> - dev_err(sev->dev, "SEV-SNP: failed to INIT rc %d, error %#x\n",
> - rc, args->error);
> + dev_err(sev->dev, "SEV-SNP: failed to INIT, continue SEV INIT\n");
> }
>
> /* Defer legacy SEV/SEV-ES support if allowed by caller/module. */
> @@ -1367,8 +1382,11 @@ static int __sev_platform_shutdown_locked(int *error)
> return 0;
>
> ret = __sev_do_cmd_locked(SEV_CMD_SHUTDOWN, NULL, error);
> - if (ret)
> + if (ret) {
> + dev_err(sev->dev, "SEV: failed to SHUTDOWN error %#x, rc %d\n",
> + *error, ret);
> return ret;
> + }
>
> sev->state = SEV_STATE_UNINIT;
> dev_dbg(sev->dev, "SEV firmware shutdown\n");
> @@ -1654,7 +1672,7 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
> struct psp_device *psp = psp_master;
> struct sev_device *sev;
> struct sev_data_snp_shutdown_ex data;
> - int ret;
> + int ret, psp_error;

Move the psp_error variable into the if statement where it is used and
name it dfflush_error.

With that,

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

>
> if (!psp || !psp->sev_data)
> return 0;
> @@ -1682,9 +1700,10 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
> ret = __sev_do_cmd_locked(SEV_CMD_SNP_SHUTDOWN_EX, &data, error);
> /* SHUTDOWN may require DF_FLUSH */
> if (*error == SEV_RET_DFFLUSH_REQUIRED) {
> - ret = __sev_do_cmd_locked(SEV_CMD_SNP_DF_FLUSH, NULL, NULL);
> + ret = __sev_do_cmd_locked(SEV_CMD_SNP_DF_FLUSH, NULL, &psp_error);
> if (ret) {
> - dev_err(sev->dev, "SEV-SNP DF_FLUSH failed\n");
> + dev_err(sev->dev, "SEV-SNP DF_FLUSH failed, ret = %d, error = %#x\n",
> + ret, psp_error);
> return ret;
> }
> /* reissue the shutdown command */
> @@ -1692,7 +1711,8 @@ static int __sev_snp_shutdown_locked(int *error, bool panic)
> error);
> }
> if (ret) {
> - dev_err(sev->dev, "SEV-SNP firmware shutdown failed\n");
> + dev_err(sev->dev, "SEV-SNP firmware shutdown failed, rc %d, error %#x\n",
> + ret, *error);
> return ret;
> }
>