2023-10-10 20:45:06

by John Allen

[permalink] [raw]
Subject: [PATCH] crypto: ccp - Dump SEV command buffer registers on SEV command error

PSP firmware may report additional error information in the SEV command
buffer registers in situations where an error occurs as the result of an
SEV command. In this case, check if the command buffer registers have been
modified and if so, dump the contents.

Signed-off-by: John Allen <[email protected]>
---
drivers/crypto/ccp/sev-dev.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index f97166fba9d9..fcaccd0b5a65 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -309,6 +309,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
{
struct psp_device *psp = psp_master;
struct sev_device *sev;
+ unsigned int cmdbuff_hi, cmdbuff_lo;
unsigned int phys_lsb, phys_msb;
unsigned int reg, ret = 0;
int buf_len;
@@ -371,6 +372,19 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
if (FIELD_GET(PSP_CMDRESP_STS, reg)) {
dev_dbg(sev->dev, "sev command %#x failed (%#010lx)\n",
cmd, FIELD_GET(PSP_CMDRESP_STS, reg));
+
+ /*
+ * PSP firmware may report additional error information in the
+ * command buffer registers on error. Print contents of command
+ * buffer registers if they changed.
+ */
+ cmdbuff_hi = ioread32(sev->io_regs + sev->vdata->cmdbuff_addr_hi_reg);
+ cmdbuff_lo = ioread32(sev->io_regs + sev->vdata->cmdbuff_addr_lo_reg);
+ if (cmdbuff_hi != phys_msb || cmdbuff_lo != phys_lsb) {
+ dev_dbg(sev->dev, "Additional error information reported in cmdbuff:");
+ dev_dbg(sev->dev, " cmdbuff hi: %#010x\n", cmdbuff_hi);
+ dev_dbg(sev->dev, " cmdbuff lo: %#010x\n", cmdbuff_lo);
+ }
ret = -EIO;
} else {
ret = sev_write_init_ex_file_if_required(cmd);
--
2.39.3


2023-10-11 15:51:12

by Mario Limonciello

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp - Dump SEV command buffer registers on SEV command error

On 10/10/2023 15:44, John Allen wrote:
> PSP firmware may report additional error information in the SEV command
> buffer registers in situations where an error occurs as the result of an
> SEV command. In this case, check if the command buffer registers have been
> modified and if so, dump the contents.
>
> Signed-off-by: John Allen <[email protected]>

Reviewed-by: Mario Limonciello <[email protected]>

> ---
> drivers/crypto/ccp/sev-dev.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index f97166fba9d9..fcaccd0b5a65 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -309,6 +309,7 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
> {
> struct psp_device *psp = psp_master;
> struct sev_device *sev;
> + unsigned int cmdbuff_hi, cmdbuff_lo;
> unsigned int phys_lsb, phys_msb;
> unsigned int reg, ret = 0;
> int buf_len;
> @@ -371,6 +372,19 @@ static int __sev_do_cmd_locked(int cmd, void *data, int *psp_ret)
> if (FIELD_GET(PSP_CMDRESP_STS, reg)) {
> dev_dbg(sev->dev, "sev command %#x failed (%#010lx)\n",
> cmd, FIELD_GET(PSP_CMDRESP_STS, reg));
> +
> + /*
> + * PSP firmware may report additional error information in the
> + * command buffer registers on error. Print contents of command
> + * buffer registers if they changed.
> + */
> + cmdbuff_hi = ioread32(sev->io_regs + sev->vdata->cmdbuff_addr_hi_reg);
> + cmdbuff_lo = ioread32(sev->io_regs + sev->vdata->cmdbuff_addr_lo_reg);
> + if (cmdbuff_hi != phys_msb || cmdbuff_lo != phys_lsb) {
> + dev_dbg(sev->dev, "Additional error information reported in cmdbuff:");
> + dev_dbg(sev->dev, " cmdbuff hi: %#010x\n", cmdbuff_hi);
> + dev_dbg(sev->dev, " cmdbuff lo: %#010x\n", cmdbuff_lo);
> + }
> ret = -EIO;
> } else {
> ret = sev_write_init_ex_file_if_required(cmd);

2023-10-20 05:54:19

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] crypto: ccp - Dump SEV command buffer registers on SEV command error

On Tue, Oct 10, 2023 at 08:44:32PM +0000, John Allen wrote:
> PSP firmware may report additional error information in the SEV command
> buffer registers in situations where an error occurs as the result of an
> SEV command. In this case, check if the command buffer registers have been
> modified and if so, dump the contents.
>
> Signed-off-by: John Allen <[email protected]>
> ---
> drivers/crypto/ccp/sev-dev.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)

Patch applied. Thanks.
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt