Skip to contentSkip to conversation

crypto: ccp: Improve sev_platform_init() error messages

PATCH Superseded Jarkko Sakkinen 2 participants 3 messages Dec 31, 2022 – Jan 8, 2023

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 crypto: ccp: Improve sev_platform_init() error messages

The following functions end up calling sev_platform_init() or __sev_platform_init_locked():

* sev_guest_init()
* sev_ioctl_do_pek_csr
* sev_ioctl_do_pdh_export()
* sev_ioctl_do_pek_import()
* sev_ioctl_do_pek_pdh_gen()
* sev_pci_init()

However, only sev_pci_init() prints out the failed command error code, and even there the error message does not specify, SEV which command failed.

Address this by printing out the SEV command errors inside __sev_platform_init_locked(), and differentiate between DF_FLUSH, INIT and INIT_EX commands.

This extra information is particularly useful if firmware loading and/or initialization is going to be made more robust, e.g. by allowing firmware loading to be postponed.

---
 drivers/crypto/ccp/sev-dev.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/crypto/ccp/sev-dev.c +12 -7
index 5350eacaba3a..ac7385c12091 100644
@@ -963,6 +963,7 @@ static int __sev_init_ex_locked(int *error)
 
 static int __sev_platform_init_locked(int *error)
 {
+	const char *cmd = sev_init_ex_buffer ? "SEV_CMD_INIT_EX" : "SEV_CMD_INIT";
 	struct psp_device *psp = psp_master;
 	struct sev_device *sev;
 	int rc = 0, psp_ret = -1;
@@ -1008,18 +1009,23 @@ static int __sev_platform_init_locked(int *error)
 	if (error)
 		*error = psp_ret;
 
-	if (rc)
+	if (rc) {
+		dev_err(sev->dev, "SEV: %s failed error %#x", cmd, psp_ret);
 		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)
-		return rc;
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &psp_ret);
+	if (error)
+		*error = psp_ret;
 
-	dev_dbg(sev->dev, "SEV firmware initialized\n");
+	if (rc) {
+		dev_err(sev->dev, "SEV: SEV_CMD_DF_FLUSH failed error %#x", psp_ret);
+		return rc;
+	}
 
 	dev_info(sev->dev, "SEV API:%d.%d build:%d\n", sev->api_major,
 		 sev->api_minor, sev->build);
@@ -2354,8 +2360,7 @@ void sev_pci_init(void)
 	/* Initialize the platform */
 	rc = sev_platform_init(&error);
 	if (rc)
-		dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
-			error, rc);
+		dev_err(sev->dev, "SEV: failed to INIT rc %d\n", rc);
 
 skip_legacy:
 	dev_info(sev->dev, "SEV%s API:%d.%d build:%d\n", sev->snp_initialized ?
Signature · 1 line
2.38.1
#1 lore raw
Quoted 31 lines · Jarkko Sakkinen

The following functions end up calling sev_platform_init() or __sev_platform_init_locked():

* sev_guest_init()
* sev_ioctl_do_pek_csr
* sev_ioctl_do_pdh_export()
* sev_ioctl_do_pek_import()
* sev_ioctl_do_pek_pdh_gen()
* sev_pci_init()

However, only sev_pci_init() prints out the failed command error code, and even there the error message does not specify, SEV which command failed.

Address this by printing out the SEV command errors inside __sev_platform_init_locked(), and differentiate between DF_FLUSH, INIT and INIT_EX commands.

This extra information is particularly useful if firmware loading and/or initialization is going to be made more robust, e.g. by allowing firmware loading to be postponed.

---
 drivers/crypto/ccp/sev-dev.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/crypto/ccp/sev-dev.c +0 -0
index 5350eacaba3a..ac7385c12091 100644

drivers/crypto/ccp/sev-dev.c static int __sev_init_ex_locked(int *error) · line 969

Quoted 7 lines
drivers/crypto/ccp/sev-dev.c +1 -0
@@ -963,6 +963,7 @@ static int __sev_init_ex_locked(int *error)
 
 static int __sev_platform_init_locked(int *error)
 {
+	const char *cmd = sev_init_ex_buffer ? "SEV_CMD_INIT_EX" : "SEV_CMD_INIT";
 	struct psp_device *psp = psp_master;
 	struct sev_device *sev;
 	int rc = 0, psp_ret = -1;

I think this can just be handled directly in the dev_err() since it's only used once.

Quoted 12 lines
drivers/crypto/ccp/sev-dev.c +3 -1
@@ -1008,18 +1009,23 @@ static int __sev_platform_init_locked(int *error)
 	if (error)
 		*error = psp_ret;
 
-	if (rc)
+	if (rc) {
+		dev_err(sev->dev, "SEV: %s failed error %#x", cmd, psp_ret);
 		return rc;
+	}
 
 	sev->state = SEV_STATE_INIT;
 

drivers/crypto/ccp/sev-dev.c static int __sev_platform_init_locked(int *error) · line 1022

Quoted 10 lines
drivers/crypto/ccp/sev-dev.c +3 -4
 	/* 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)
-		return rc;
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &psp_ret);
+	if (error)
+		*error = psp_ret;
 
-	dev_dbg(sev->dev, "SEV firmware initialized\n");

Any reason to remove this dbg line? I assume the following dev_info() line is deemed sufficient?

Quoted 17 lines
drivers/crypto/ccp/sev-dev.c +5 -2
+	if (rc) {
+		dev_err(sev->dev, "SEV: SEV_CMD_DF_FLUSH failed error %#x", psp_ret);
+		return rc;
+	}
 
 	dev_info(sev->dev, "SEV API:%d.%d build:%d\n", sev->api_major,
 		 sev->api_minor, sev->build);
@@ -2354,8 +2360,7 @@ void sev_pci_init(void)
 	/* Initialize the platform */
 	rc = sev_platform_init(&error);
 	if (rc)
-		dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
-			error, rc);
+		dev_err(sev->dev, "SEV: failed to INIT rc %d\n", rc);
 
 skip_legacy:
 	dev_info(sev->dev, "SEV%s API:%d.%d build:%d\n", sev->snp_initialized ?
#2 lore raw
Quoted 34 lines · David Rientjes
Quoted 32 lines · Jarkko Sakkinen

The following functions end up calling sev_platform_init() or __sev_platform_init_locked():

* sev_guest_init()
* sev_ioctl_do_pek_csr
* sev_ioctl_do_pdh_export()
* sev_ioctl_do_pek_import()
* sev_ioctl_do_pek_pdh_gen()
* sev_pci_init()

However, only sev_pci_init() prints out the failed command error code, and even there the error message does not specify, SEV which command failed.

Address this by printing out the SEV command errors inside __sev_platform_init_locked(), and differentiate between DF_FLUSH, INIT and INIT_EX commands.

This extra information is particularly useful if firmware loading and/or initialization is going to be made more robust, e.g. by allowing firmware loading to be postponed.

---
 drivers/crypto/ccp/sev-dev.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/crypto/ccp/sev-dev.c +0 -0
index 5350eacaba3a..ac7385c12091 100644
@@ -963,6 +963,7 @@ static int __sev_init_ex_locked(int *error)
 
Quoted 9 lines

drivers/crypto/ccp/sev-dev.c static int __sev_init_ex_locked(int *error) · line 969

Quoted 6 lines
drivers/crypto/ccp/sev-dev.c +1 -0
 static int __sev_platform_init_locked(int *error)
 {
+	const char *cmd = sev_init_ex_buffer ? "SEV_CMD_INIT_EX" : "SEV_CMD_INIT";
 	struct psp_device *psp = psp_master;
 	struct sev_device *sev;
 	int rc = 0, psp_ret = -1;

I think this can just be handled directly in the dev_err() since it's only used once.

Ack.

Quoted 21 lines
Quoted 21 lines
drivers/crypto/ccp/sev-dev.c +6 -4
@@ -1008,18 +1009,23 @@ static int __sev_platform_init_locked(int *error)
 	if (error)
 		*error = psp_ret;
 
-	if (rc)
+	if (rc) {
+		dev_err(sev->dev, "SEV: %s failed error %#x", cmd, psp_ret);
 		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)
-		return rc;
+	rc = __sev_do_cmd_locked(SEV_CMD_DF_FLUSH, NULL, &psp_ret);
+	if (error)
+		*error = psp_ret;
 
Quoted 4 lines

drivers/crypto/ccp/sev-dev.c static int __sev_platform_init_locked(int *error) · line 1022

Quoted 1 line
drivers/crypto/ccp/sev-dev.c +0 -1
-	dev_dbg(sev->dev, "SEV firmware initialized\n");

Any reason to remove this dbg line? I assume the following dev_info() line is deemed sufficient?

Yes, but agreed that it is not in the scope of the patch so I'll remove it from the next version.

Quoted 16 lines
Quoted 16 lines
drivers/crypto/ccp/sev-dev.c +5 -2
+	if (rc) {
+		dev_err(sev->dev, "SEV: SEV_CMD_DF_FLUSH failed error %#x", psp_ret);
+		return rc;
+	}
 
 	dev_info(sev->dev, "SEV API:%d.%d build:%d\n", sev->api_major,
 		 sev->api_minor, sev->build);
@@ -2354,8 +2360,7 @@ void sev_pci_init(void)
 	/* Initialize the platform */
 	rc = sev_platform_init(&error);
 	if (rc)
-		dev_err(sev->dev, "SEV: failed to INIT error %#x, rc %d\n",
-			error, rc);
+		dev_err(sev->dev, "SEV: failed to INIT rc %d\n", rc);
 
Quoted 2 lines

drivers/crypto/ccp/sev-dev.c void sev_pci_init(void) · line 2366

Quoted 2 lines
drivers/crypto/ccp/sev-dev.c +0 -0
 skip_legacy:
 	dev_info(sev->dev, "SEV%s API:%d.%d build:%d\n", sev->snp_initialized ?

Thank you for the feedback.

BR, Jarkko