Skip to contentSkip to conversation

crypto: ccp: Avoid discarding errors in psp_send_platform_access_msg()

PATCH In review Mario Limonciello 2 participants 3 messages Feb 13, 2024 – Feb 24, 2024

Subsystems (3)
lore
Share & tools
lore

Mario Limonciello

author maintainer
#0 lore raw

PATCH v2 1/2 crypto: ccp: Avoid discarding errors in psp_send_platform_access_msg()

Errors can potentially occur in the "processing" of PSP commands or commands can be processed successfully but still return an error code in the header.

This second case was being discarded because PSP communication worked but the command returned an error code in the payload header.

Capture both cases and return them to the caller as -EIO for the caller to investigate. The caller can detect the latter by looking at req->header->status.

Fixes 7ccc4f4e2e50 ("crypto: ccp - Add support for an interface for platform features")

---
v1->v2:
* Update tag for Tim
* Reword commit message

---
 drivers/crypto/ccp/platform-access.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/crypto/ccp/platform-access.c +9 -2
index 94367bc49e35..1b8ed3389733 100644
@@ -118,9 +118,16 @@ int psp_send_platform_access_msg(enum psp_platform_access_msg msg,
 		goto unlock;
 	}
 
-	/* Store the status in request header for caller to investigate */
+	/*
+	 * Read status from PSP. If status is non-zero, it indicates an error
+	 * occurred during "processing" of the command.
+	 * If status is zero, it indicates the command was "processed"
+	 * successfully, but the result of the command is in the payload.
+	 * Return both cases to the caller as -EIO to investigate.
+	 */
 	cmd_reg = ioread32(cmd);
-	req->header.status = FIELD_GET(PSP_CMDRESP_STS, cmd_reg);
+	if (FIELD_GET(PSP_CMDRESP_STS, cmd_reg))
+		req->header.status = FIELD_GET(PSP_CMDRESP_STS, cmd_reg);
 	if (req->header.status) {
 		ret = -EIO;
 		goto unlock;
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH v2 2/2 crypto: ccp: Update return values for some unit tests

Until authenticated the platform enforces a state machine. Adjust unit tests with this in mind.

Correct the return codes for all the states the unit tests ends up hitting:

* Set Param / Get Param: DBC_ERROR_BAD_STATE
* Set UID: DBC_ERROR_SIGNATURE_INVALID
* Authencitated Nonce: DBC_ERROR_BAD_PARAMETERS

---
 tools/crypto/ccp/test_dbc.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/crypto/ccp/test_dbc.py +5 -3
index 79de3638a01a..bb0e671be96d 100755
@@ -138,12 +138,14 @@ class TestInvalidSignature(DynamicBoostControlTest):
 
     def test_authenticated_nonce(self) -> None:
         """fetch authenticated nonce"""
+        get_nonce(self.d, None)
         with self.assertRaises(OSError) as error:
             get_nonce(self.d, self.signature)
-        self.assertEqual(error.exception.errno, 1)
+        self.assertEqual(error.exception.errno, 22)
 
     def test_set_uid(self) -> None:
         """set uid"""
+        get_nonce(self.d, None)
         with self.assertRaises(OSError) as error:
             set_uid(self.d, self.uid, self.signature)
         self.assertEqual(error.exception.errno, 1)
@@ -152,13 +154,13 @@ class TestInvalidSignature(DynamicBoostControlTest):
         """fetch a parameter"""
         with self.assertRaises(OSError) as error:
             process_param(self.d, PARAM_GET_SOC_PWR_CUR, self.signature)
-        self.assertEqual(error.exception.errno, 1)
+        self.assertEqual(error.exception.errno, 11)
 
     def test_set_param(self) -> None:
         """set a parameter"""
         with self.assertRaises(OSError) as error:
             process_param(self.d, PARAM_SET_PWR_CAP, self.signature, 1000)
-        self.assertEqual(error.exception.errno, 1)
+        self.assertEqual(error.exception.errno, 11)
 
 
 class TestUnFusedSystem(DynamicBoostControlTest):
Signature · 1 line
2.34.1
maintainer
#2 lore raw
In reply to Mario Limonciello
Quoted 14 lines · Mario Limonciello

Errors can potentially occur in the "processing" of PSP commands or commands can be processed successfully but still return an error code in the header.

This second case was being discarded because PSP communication worked but the command returned an error code in the payload header.

Capture both cases and return them to the caller as -EIO for the caller to investigate. The caller can detect the latter by looking at req->header->status.

Fixes 7ccc4f4e2e50 ("crypto: ccp - Add support for an interface for platform features")
Quoted 7 lines

---
v1->v2:
* Update tag for Tim
* Reword commit message

---
 drivers/crypto/ccp/platform-access.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

All applied. 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