crypto: ccp: Sanitize sev_platform_init() error messages
Subsystems (3)
PATCH v5 1/1 crypto: ccp: Sanitize 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 which SEV 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. As a side-effect, @error can be removed from the parameter list.
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.
---
v5:
* Address Tom's feedback:
https://lore.kernel.org/all/[email protected]/
* "failed error" -> "error"
* "SEV_CMD_" -> ""
v4:
* Sorry, v3 was malformed. Here's a proper patch.
v3:
* Address Tom Lendacky's feedback:
https://lore.kernel.org/kvm/[email protected]/
v2:
* Address David Rientjes's feedback:
https://lore.kernel.org/all/[email protected]/
* Remove @error.
* Remove "SEV_" prefix: it is obvious from context so no need to make klog line longer.
--- drivers/crypto/ccp/sev-dev.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
drivers/crypto/ccp/sev-dev.c +11 -6
@@ -478,17 +478,23 @@ static int __sev_platform_init_locked(int *error) }if (error) *error = psp_ret; - -if (rc) +if (rc) { +dev_err (sev->dev,"SEV: %s error %#x" , + sev_init_ex_buffer ?"INIT_EX" :"INIT" , 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) + rc =__sev_do_cmd_locked (SEV_CMD_DF_FLUSH ,NULL , &psp_ret); +if (error) + *error = psp_ret; +if (rc) { +dev_err (sev->dev,"SEV: DF_FLUSH error %#x" , psp_ret);return rc; + }dev_dbg (sev->dev,"SEV firmware initialized\n" );
@@ -1337,8 +1343,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);return ;
Signature · 1 line
2.38.1
Quoted 18 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 which SEV command failed.Address this by printing out the SEV command errors inside
__sev_platform_init_locked(), and differentiate betweenDF_FLUSH, INIT andINIT_EXcommands. As a side-effect, @error can be removed from the parameter list.
Quoted 5 lines
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.
Signed-off-by Jarkko Sakkinen <[email protected]>
Quoted 18 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 which SEV command failed.Address this by printing out the SEV command errors inside
__sev_platform_init_locked(), and differentiate betweenDF_FLUSH, INIT andINIT_EXcommands. As a side-effect, @error can be removed from the parameter list.
Quoted 5 lines
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.
Signed-off-by Jarkko Sakkinen <[email protected]>
Quoted 66 lines
---
v5:
* Address Tom's feedback:https://lore.kernel.org/all/[email protected]/* "failed error" -> "error"
* "SEV_CMD_" -> ""v4:
* Sorry, v3 was malformed. Here's a proper patch.v3:
* Address Tom Lendacky's feedback:https://lore.kernel.org/kvm/[email protected]/v2:
* Address David Rientjes's feedback:https://lore.kernel.org/all/[email protected]/ * Remove @error. * Remove "SEV_" prefix: it is obvious from context so no need to make klog line longer. --- drivers/crypto/ccp/sev-dev.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)drivers/crypto/ccp/sev-dev.c +11
-6@@ -478,17 +478,23 @@ static int __sev_platform_init_locked(int *error) }if (error) *error = psp_ret; - -if (rc) +if (rc) { +dev_err (sev->dev,"SEV: %s error %#x" , + sev_init_ex_buffer ?"INIT_EX" :"INIT" , 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) + rc =__sev_do_cmd_locked (SEV_CMD_DF_FLUSH ,NULL , &psp_ret); +if (error) + *error = psp_ret; +if (rc) { +dev_err (sev->dev,"SEV: DF_FLUSH error %#x" , psp_ret);return rc; + }dev_dbg (sev->dev,"SEV firmware initialized\n" );@@ -1337,8 +1343,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);return ;
Herbert Xu
maintainerdrivers/crypto/ccp/sev-dev.c void sev_pci_init(void) · line 1346
Quoted 8 lines · Jarkko Sakkinen
drivers/crypto/ccp/sev-dev.c +1
-2@@ -1337,8 +1343,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);
Please remove error and replace it with NULL.
Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt