Skip to contentSkip to conversation

Fixes for dynamic boost control unit tests

PATCH Superseded Mario Limonciello 1 participant 4 messages Aug 28, 2023

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Mario Limonciello

author maintainer
#0 lore raw

cover Fixes for dynamic boost control unit tests

Further testing of the code being submitted to 6.6-rc1 against additional hardware found some problems with the unit tests and sample application.

These patches are produced and tested with the two patches already posted [1].

Mario Limonciello (3):
crypto: ccp: Fix DBC sample application error handling
crypto: ccp: Fix sample application signature passing
crypto: ccp: Fix some unfused tests

 tools/crypto/ccp/dbc.c       | 17 +++++++++--------
 tools/crypto/ccp/dbc.py      |  8 ++++----
 tools/crypto/ccp/test_dbc.py | 22 +++++++++++-----------
 3 files changed, 24 insertions(+), 23 deletions(-)

base-commit: 85b9bf9a514d991fcecb118d0a8a35e754ff9265
prerequisite-patch-id: 4bcf7f3ea21472e4e28c2457cc9827f6023ec6ca
prerequisite-patch-id: 903be53a20306f0188e52015dbfe5196738bb2eb

Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/3 crypto: ccp: Fix DBC sample application error handling

The sample application was taking values from ioctl() and treating those as the error codes to present to a user.

This is incorrect when ret is non-zero, the error is stored to errno. Use this value instead.

Fixes f40d42f116cf ("crypto: ccp - Add a sample python script for Dynamic Boost Control")
Fixes febe3ed3222f ("crypto: ccp - Add a sample library for ioctl use")
---
 tools/crypto/ccp/dbc.c  | 16 ++++++++--------
 tools/crypto/ccp/dbc.py |  3 +--
 2 files changed, 9 insertions(+), 10 deletions(-)
tools/crypto/ccp/dbc.c +8 -8
index 37e813175642..7774e981849f 100644
@@ -8,6 +8,7 @@
  */
 
 #include <assert.h>
+#include <errno.h>
 #include <string.h>
 #include <sys/ioctl.h>
 
@@ -22,16 +23,14 @@ int get_nonce(int fd, void *nonce_out, void *signature)
 	struct dbc_user_nonce tmp = {
 		.auth_needed = !!signature,
 	};
-	int ret;
 
 	assert(nonce_out);
 
 	if (signature)
 		memcpy(tmp.signature, signature, sizeof(tmp.signature));
 
-	ret = ioctl(fd, DBCIOCNONCE, &tmp);
-	if (ret)
-		return ret;
+	if (ioctl(fd, DBCIOCNONCE, &tmp))
+		return errno;
 	memcpy(nonce_out, tmp.nonce, sizeof(tmp.nonce));
 
 	return 0;
@@ -47,7 +46,9 @@ int set_uid(int fd, __u8 *uid, __u8 *signature)
 	memcpy(tmp.uid, uid, sizeof(tmp.uid));
 	memcpy(tmp.signature, signature, sizeof(tmp.signature));
 
-	return ioctl(fd, DBCIOCUID, &tmp);
+	if (ioctl(fd, DBCIOCUID, &tmp))
+		return errno;
+	return 0;
 }
 
 int process_param(int fd, int msg_index, __u8 *signature, int *data)
@@ -63,9 +64,8 @@ int process_param(int fd, int msg_index, __u8 *signature, int *data)
 
 	memcpy(tmp.signature, signature, sizeof(tmp.signature));
 
-	ret = ioctl(fd, DBCIOCPARAM, &tmp);
-	if (ret)
-		return ret;
+	if (ioctl(fd, DBCIOCPARAM, &tmp))
+		return errno;
 
 	*data = tmp.param;
 	return 0;
tools/crypto/ccp/dbc.py +1 -2
index 3f6a825ffc9e..3956efe7537a 100644
@@ -27,8 +27,7 @@ lib = ctypes.CDLL("./dbc_library.so", mode=ctypes.RTLD_GLOBAL)
 
 
 def handle_error(code):
-    val = code * -1
-    raise OSError(val, os.strerror(val))
+    raise OSError(code, os.strerror(code))
 
 
 def get_nonce(device, signature):
Signature · 1 line
2.34.1
author maintainer
#2 lore raw

PATCH 2/3 crypto: ccp: Fix sample application signature passing

In reply to Mario Limonciello

When parameters are sent the PSP returns back it's own signature for the application to verify the authenticity of the result.

Display this signature to the caller instead of the one the caller sent.

Fixes f40d42f116cf ("crypto: ccp - Add a sample python script for Dynamic Boost Control")
Fixes febe3ed3222f ("crypto: ccp - Add a sample library for ioctl use")
---
 tools/crypto/ccp/dbc.c  | 1 +
 tools/crypto/ccp/dbc.py | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)
tools/crypto/ccp/dbc.c +1 -0
index 7774e981849f..a807df0f0597 100644
@@ -68,5 +68,6 @@ int process_param(int fd, int msg_index, __u8 *signature, int *data)
 		return errno;
 
 	*data = tmp.param;
+	memcpy(signature, tmp.signature, sizeof(tmp.signature));
 	return 0;
 }
tools/crypto/ccp/dbc.py +3 -2
index 3956efe7537a..2b91415b1940 100644
@@ -57,7 +57,8 @@ def process_param(device, message, signature, data=None):
     if type(message) != tuple:
         raise ValueError("Expected message tuple")
     arg = ctypes.c_int(data if data else 0)
-    ret = lib.process_param(device.fileno(), message[0], signature, ctypes.pointer(arg))
+    sig = ctypes.create_string_buffer(signature, len(signature))
+    ret = lib.process_param(device.fileno(), message[0], ctypes.pointer(sig), ctypes.pointer(arg))
     if ret:
         handle_error(ret)
-    return arg, signature
+    return arg.value, sig.value
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 3/3 crypto: ccp: Fix some unfused tests

In reply to Mario Limonciello

Some of the tests for unfused parts referenced a named member parameter, but when the test suite was switched to call a python ctypes library they weren't updated. Adjust them to refer to the first argument of the process_param() call.

Fixes 15f8aa7bb3e5 ("crypto: ccp - Add unit tests for dynamic boost control")
---
 tools/crypto/ccp/test_dbc.py | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
tools/crypto/ccp/test_dbc.py +11 -11
index a28a1f94c1d2..18df031aa5e1 100755
@@ -192,12 +192,12 @@ class TestUnFusedSystem(DynamicBoostControlTest):
         # SOC power
         soc_power_max = process_param(self.d, PARAM_GET_SOC_PWR_MAX, self.signature)
         soc_power_min = process_param(self.d, PARAM_GET_SOC_PWR_MIN, self.signature)
-        self.assertGreater(soc_power_max.parameter, soc_power_min.parameter)
+        self.assertGreater(soc_power_max[0], soc_power_min[0])
 
         # fmax
         fmax_max = process_param(self.d, PARAM_GET_FMAX_MAX, self.signature)
         fmax_min = process_param(self.d, PARAM_GET_FMAX_MIN, self.signature)
-        self.assertGreater(fmax_max.parameter, fmax_min.parameter)
+        self.assertGreater(fmax_max[0], fmax_min[0])
 
         # cap values
         keys = {
@@ -208,7 +208,7 @@ class TestUnFusedSystem(DynamicBoostControlTest):
         }
         for k in keys:
             result = process_param(self.d, keys[k], self.signature)
-            self.assertGreater(result.parameter, 0)
+            self.assertGreater(result[0], 0)
 
     def test_get_invalid_param(self) -> None:
         """fetch an invalid parameter"""
@@ -226,17 +226,17 @@ class TestUnFusedSystem(DynamicBoostControlTest):
         original = process_param(self.d, PARAM_GET_FMAX_CAP, self.signature)
 
         # set the fmax
-        target = original.parameter - 100
+        target = original[0] - 100
         process_param(self.d, PARAM_SET_FMAX_CAP, self.signature, target)
         time.sleep(SET_DELAY)
         new = process_param(self.d, PARAM_GET_FMAX_CAP, self.signature)
-        self.assertEqual(new.parameter, target)
+        self.assertEqual(new[0], target)
 
         # revert back to current
-        process_param(self.d, PARAM_SET_FMAX_CAP, self.signature, original.parameter)
+        process_param(self.d, PARAM_SET_FMAX_CAP, self.signature, original[0])
         time.sleep(SET_DELAY)
         cur = process_param(self.d, PARAM_GET_FMAX_CAP, self.signature)
-        self.assertEqual(cur.parameter, original.parameter)
+        self.assertEqual(cur[0], original[0])
 
     def test_set_power_cap(self) -> None:
         """get/set power cap limit"""
@@ -244,17 +244,17 @@ class TestUnFusedSystem(DynamicBoostControlTest):
         original = process_param(self.d, PARAM_GET_PWR_CAP, self.signature)
 
         # set the fmax
-        target = original.parameter - 10
+        target = original[0] - 10
         process_param(self.d, PARAM_SET_PWR_CAP, self.signature, target)
         time.sleep(SET_DELAY)
         new = process_param(self.d, PARAM_GET_PWR_CAP, self.signature)
-        self.assertEqual(new.parameter, target)
+        self.assertEqual(new[0], target)
 
         # revert back to current
-        process_param(self.d, PARAM_SET_PWR_CAP, self.signature, original.parameter)
+        process_param(self.d, PARAM_SET_PWR_CAP, self.signature, original[0])
         time.sleep(SET_DELAY)
         cur = process_param(self.d, PARAM_GET_PWR_CAP, self.signature)
-        self.assertEqual(cur.parameter, original.parameter)
+        self.assertEqual(cur[0], original[0])
 
     def test_set_3d_graphics_mode(self) -> None:
         """set/get 3d graphics mode"""
Signature · 1 line
2.34.1