aboutsummaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorBalint Dobszay <balint.dobszay@arm.com>2021-04-28 16:56:19 +0200
committerBalint Dobszay <balint.dobszay@arm.com>2021-06-30 13:46:20 +0200
commit8e3aa11987ab7db605d03aaa86a7699dbde4bc57 (patch)
tree9abe50b9ee793924e421e1b3758b62f726a030fa /components
parent2fc7e10c7c21e4dafbf63dc9d00dfc2a7a7fddad (diff)
downloadtrusted-services-8e3aa11987ab7db605d03aaa86a7699dbde4bc57.tar.gz
Add check of DebugFS driver API version
Currently the components in TS relying on the DebugFS PoC Linux driver don't check which version of the driver is actually loaded. This can lead to errors if the API version used by TS and the loaded module are different. This commit introduces a runtime compatibility check to have an informative error message and exit in case of incompatible APIs. Signed-off-by: Balint Dobszay <balint.dobszay@arm.com> Change-Id: I6e8ea4143ac08b106e60516461611004c0b0b8c2
Diffstat (limited to 'components')
-rw-r--r--components/rpc/ffarpc/caller/linux/ffarpc_caller.c63
-rw-r--r--components/rpc/ffarpc/caller/linux/ffarpc_caller.h1
-rw-r--r--components/service/locator/linux/ffa/linuxffa_location_strategy.c3
3 files changed, 67 insertions, 0 deletions
diff --git a/components/rpc/ffarpc/caller/linux/ffarpc_caller.c b/components/rpc/ffarpc/caller/linux/ffarpc_caller.c
index ac628a951..3ce80ff93 100644
--- a/components/rpc/ffarpc/caller/linux/ffarpc_caller.c
+++ b/components/rpc/ffarpc/caller/linux/ffarpc_caller.c
@@ -17,6 +17,10 @@
#include <stdlib.h>
#include <string.h>
+#define KERNEL_MOD_REQ_VER_MAJOR 1
+#define KERNEL_MOD_REQ_VER_MINOR 0
+#define KERNEL_MOD_REQ_VER_PATCH 0
+
#define DEFAULT_SHMEM_BUF_SIZE (4096)
static rpc_call_handle call_begin(void *context, uint8_t **req_buf, size_t req_len);
@@ -29,7 +33,66 @@ static int kernel_read_resp_buf(struct ffarpc_caller *s);
static int share_mem_with_partition(struct ffarpc_caller *s);
static int unshare_mem_with_partition(struct ffarpc_caller *s);
+bool ffarpc_caller_check_version(void)
+{
+ FILE *f;
+ char mod_name[64];
+ int ver_major, ver_minor, ver_patch;
+ bool mod_loaded = false;
+
+ f = fopen("/proc/modules", "r");
+ if (!f) {
+ printf("error: cannot open /proc/modules\n");
+ return false;
+ }
+
+ while (fscanf(f, "%64s %*[^\n]\n", mod_name) != EOF) {
+ if (!strcmp(mod_name, "arm_ffa_user")) {
+ mod_loaded = true;
+ break;
+ }
+ }
+
+ fclose(f);
+
+ if (!mod_loaded) {
+ printf("error: kernel module not loaded\n");
+ return false;
+ }
+ f = fopen("/sys/module/arm_ffa_user/version", "r");
+ if (f) {
+ fscanf(f, "%d.%d.%d", &ver_major, &ver_minor, &ver_patch);
+ fclose(f);
+ } else {
+ /*
+ * Fallback for the initial release of the kernel module, where
+ * the version definition was missing.
+ */
+ ver_major = 1;
+ ver_minor = 0;
+ ver_patch = 0;
+ }
+
+ if (ver_major != KERNEL_MOD_REQ_VER_MAJOR)
+ goto err;
+
+ if (ver_minor < KERNEL_MOD_REQ_VER_MINOR)
+ goto err;
+
+ if (ver_minor == KERNEL_MOD_REQ_VER_MINOR)
+ if (ver_patch < KERNEL_MOD_REQ_VER_PATCH)
+ goto err;
+
+ return true;
+
+err:
+ printf("error: kernel module is v%d.%d.%d but required v%d.%d.%d\n",
+ ver_major, ver_minor, ver_patch, KERNEL_MOD_REQ_VER_MAJOR,
+ KERNEL_MOD_REQ_VER_MINOR, KERNEL_MOD_REQ_VER_PATCH);
+
+ return false;
+}
struct rpc_caller *ffarpc_caller_init(struct ffarpc_caller *s, const char *device_path)
{
diff --git a/components/rpc/ffarpc/caller/linux/ffarpc_caller.h b/components/rpc/ffarpc/caller/linux/ffarpc_caller.h
index c81382e6a..b40e20bc3 100644
--- a/components/rpc/ffarpc/caller/linux/ffarpc_caller.h
+++ b/components/rpc/ffarpc/caller/linux/ffarpc_caller.h
@@ -35,6 +35,7 @@ struct ffarpc_caller {
bool is_call_transaction_in_progess;
};
+bool ffarpc_caller_check_version(void);
struct rpc_caller *ffarpc_caller_init(struct ffarpc_caller *s, const char *device_path);
void ffarpc_caller_deinit(struct ffarpc_caller *s);
size_t ffarpc_caller_discover(const struct ffarpc_caller *s, const struct uuid_canonical *uuid,
diff --git a/components/service/locator/linux/ffa/linuxffa_location_strategy.c b/components/service/locator/linux/ffa/linuxffa_location_strategy.c
index f7e78ad92..21468a97e 100644
--- a/components/service/locator/linux/ffa/linuxffa_location_strategy.c
+++ b/components/service/locator/linux/ffa/linuxffa_location_strategy.c
@@ -141,6 +141,9 @@ static bool discover_partition(const char *sn, struct uuid_canonical *uuid,
struct ffarpc_caller ffarpc_caller;
unsigned int required_instance = sn_get_service_instance(sn);
+ if (!ffarpc_caller_check_version())
+ return false;
+
ffarpc_caller_init(&ffarpc_caller, dev_path);
uint16_t discovered_partitions[MAX_PARTITION_INSTANCES];