[v4,1/4] ccp: Name -1 return value as SEV_RET_NO_FW_CALL

Message ID 20221024224657.2917482-2-dionnaglaze@google.com
State New
Headers
Series Add throttling detection to sev-guest |

Commit Message

Dionna Amalie Glaze Oct. 24, 2022, 10:46 p.m. UTC
  The PSP can return a "firmware error" code of -1 in circumstances where
the PSP is not actually called. To make this protocol unambiguous, we
add a constant naming the return value.

From: Peter Gonda <pgonda@google.com>
Cc: Thomas Lendacky <Thomas.Lendacky@amd.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Joerg Roedel <jroedel@suse.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Andy Lutomirsky <luto@kernel.org>

Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
---
 drivers/crypto/ccp/sev-dev.c | 2 +-
 include/uapi/linux/psp-sev.h | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
  

Comments

Tom Lendacky Oct. 28, 2022, 2:35 p.m. UTC | #1
On 10/24/22 17:46, Dionna Glaze wrote:
> The PSP can return a "firmware error" code of -1 in circumstances where
> the PSP is not actually called. To make this protocol unambiguous, we
> add a constant naming the return value.
> 
> From: Peter Gonda <pgonda@google.com>
> Cc: Thomas Lendacky <Thomas.Lendacky@amd.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Joerg Roedel <jroedel@suse.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Andy Lutomirsky <luto@kernel.org>
> 
> Signed-off-by: Dionna Glaze <dionnaglaze@google.com>

Just one minor comment below, otherwise...

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

> ---
>   drivers/crypto/ccp/sev-dev.c | 2 +-
>   include/uapi/linux/psp-sev.h | 7 +++++++
>   2 files changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
> index 06fc7156c04f..97eb3544ab36 100644
> --- a/drivers/crypto/ccp/sev-dev.c
> +++ b/drivers/crypto/ccp/sev-dev.c
> @@ -444,7 +444,7 @@ static int __sev_platform_init_locked(int *error)
>   {
>   	struct psp_device *psp = psp_master;
>   	struct sev_device *sev;
> -	int rc = 0, psp_ret = -1;
> +	int rc = 0, psp_ret = SEV_RET_NO_FW_CALL;
>   	int (*init_function)(int *error);
>   
>   	if (!psp || !psp->sev_data)
> diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h
> index 91b4c63d5cbf..fb61e083d42e 100644
> --- a/include/uapi/linux/psp-sev.h
> +++ b/include/uapi/linux/psp-sev.h
> @@ -36,6 +36,13 @@ enum {
>    * SEV Firmware status code
>    */
>   typedef enum {
> +	/*
> +	 * This error code is not in the SEV spec but is added to convey that
> +	 * there was an error that prevented the SEV Firmware from being called.
> +	 * This is (u32)-1 since the firmware error code part of EXIT_INFO_2 is
> +	 * the lower 32 bits.

These codes are used for /dev/sev access on the HV side, too, where 
EXIT_INFO_2 doesn't exist. I would change this to something like:

This is (u32)-1 since the firwmare error code is represented as a 32-bit 
integer.

Thanks,
Tom

> +	 */
> +	SEV_RET_NO_FW_CALL = 0xffffffff,
>   	SEV_RET_SUCCESS = 0,
>   	SEV_RET_INVALID_PLATFORM_STATE,
>   	SEV_RET_INVALID_GUEST_STATE,
  

Patch

diff --git a/drivers/crypto/ccp/sev-dev.c b/drivers/crypto/ccp/sev-dev.c
index 06fc7156c04f..97eb3544ab36 100644
--- a/drivers/crypto/ccp/sev-dev.c
+++ b/drivers/crypto/ccp/sev-dev.c
@@ -444,7 +444,7 @@  static int __sev_platform_init_locked(int *error)
 {
 	struct psp_device *psp = psp_master;
 	struct sev_device *sev;
-	int rc = 0, psp_ret = -1;
+	int rc = 0, psp_ret = SEV_RET_NO_FW_CALL;
 	int (*init_function)(int *error);
 
 	if (!psp || !psp->sev_data)
diff --git a/include/uapi/linux/psp-sev.h b/include/uapi/linux/psp-sev.h
index 91b4c63d5cbf..fb61e083d42e 100644
--- a/include/uapi/linux/psp-sev.h
+++ b/include/uapi/linux/psp-sev.h
@@ -36,6 +36,13 @@  enum {
  * SEV Firmware status code
  */
 typedef enum {
+	/*
+	 * This error code is not in the SEV spec but is added to convey that
+	 * there was an error that prevented the SEV Firmware from being called.
+	 * This is (u32)-1 since the firmware error code part of EXIT_INFO_2 is
+	 * the lower 32 bits.
+	 */
+	SEV_RET_NO_FW_CALL = 0xffffffff,
 	SEV_RET_SUCCESS = 0,
 	SEV_RET_INVALID_PLATFORM_STATE,
 	SEV_RET_INVALID_GUEST_STATE,