crypto: ccp - Name -1 return value as SEV_RET_NO_FW_CALL
authorPeter Gonda <pgonda@google.com>
Tue, 7 Mar 2023 19:24:39 +0000 (20:24 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 20 Nov 2023 10:52:13 +0000 (11:52 +0100)
[ Upstream commit efb339a83368ab25de1a18c0fdff85e01c13a1ea ]

The PSP can return a "firmware error" code of -1 in circumstances where
the PSP has not actually been called. To make this protocol unambiguous,
name the value SEV_RET_NO_FW_CALL.

  [ bp: Massage a bit. ]

Signed-off-by: Peter Gonda <pgonda@google.com>
Signed-off-by: Dionna Glaze <dionnaglaze@google.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20221207010210.2563293-2-dionnaglaze@google.com
Stable-dep-of: db10cb9b5746 ("virt: sevguest: Fix passing a stack buffer as a scatterlist target")
Signed-off-by: Sasha Levin <sashal@kernel.org>
Documentation/virt/coco/sev-guest.rst
drivers/crypto/ccp/sev-dev.c
include/uapi/linux/psp-sev.h

index bf593e88cfd9d737b62e1a82d66bf4f847594624..aa3e4c6a1f90cf7012e9ff56c673a68123c9d380 100644 (file)
@@ -40,8 +40,8 @@ along with a description:
 The guest ioctl should be issued on a file descriptor of the /dev/sev-guest device.
 The ioctl accepts struct snp_user_guest_request. The input and output structure is
 specified through the req_data and resp_data field respectively. If the ioctl fails
-to execute due to a firmware error, then fw_err code will be set otherwise the
-fw_err will be set to 0x00000000000000ff.
+to execute due to a firmware error, then fw_err code will be set. Otherwise, fw_err
+will be set to 0x00000000ffffffff, i.e., the lower 32-bits are -1.
 
 The firmware checks that the message sequence counter is one greater than
 the guests message sequence counter. If guest driver fails to increment message
index 3e583f0324874ee25d10520ba0ec27eca9de67dd..b8e02c3a19610c7828d7d9423c6f441e4a0ebe5a 100644 (file)
@@ -443,10 +443,10 @@ static int __sev_init_ex_locked(int *error)
 
 static int __sev_platform_init_locked(int *error)
 {
+       int rc = 0, psp_ret = SEV_RET_NO_FW_CALL;
        struct psp_device *psp = psp_master;
-       struct sev_device *sev;
-       int rc = 0, psp_ret = -1;
        int (*init_function)(int *error);
+       struct sev_device *sev;
 
        if (!psp || !psp->sev_data)
                return -ENODEV;
@@ -474,9 +474,11 @@ static int __sev_platform_init_locked(int *error)
                 * initialization function should succeed by replacing the state
                 * with a reset state.
                 */
-               dev_err(sev->dev, "SEV: retrying INIT command because of SECURE_DATA_INVALID error. Retrying once to reset PSP SEV state.");
+               dev_err(sev->dev,
+"SEV: retrying INIT command because of SECURE_DATA_INVALID error. Retrying once to reset PSP SEV state.");
                rc = init_function(&psp_ret);
        }
+
        if (error)
                *error = psp_ret;
 
index 91b4c63d5cbf4f5f319aa5e342172ae1aa7aa9dd..1c9da485318f93fe50e11a47f284d8fe81106066 100644 (file)
@@ -36,6 +36,13 @@ enum {
  * SEV Firmware status code
  */
 typedef enum {
+       /*
+        * This error code is not in the SEV spec. Its purpose is to convey that
+        * there was an error that prevented the SEV firmware from being called.
+        * The SEV API error codes are 16 bits, so the -1 value will not overlap
+        * with possible values from the specification.
+        */
+       SEV_RET_NO_FW_CALL = -1,
        SEV_RET_SUCCESS = 0,
        SEV_RET_INVALID_PLATFORM_STATE,
        SEV_RET_INVALID_GUEST_STATE,