[SPM] checks if SIMD vectors are preserved
Populates the SIMD registers in the normal world, then modifies those in
the secure world. Upon return to the normal world checks that vectors
are restored to the original values.
Note: Does not check if SIMD vectors are preserved when returning back
to the secure world.
Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
Signed-off-by: Max Shvetsov <maksims.svecovs@arm.com>
Change-Id: I3ae223af64597f83afa6624122109db2cf0077f7
diff --git a/spm/cactus/aarch64/cactus_entrypoint.S b/spm/cactus/aarch64/cactus_entrypoint.S
index 383c319..b0f89d4 100644
--- a/spm/cactus/aarch64/cactus_entrypoint.S
+++ b/spm/cactus/aarch64/cactus_entrypoint.S
@@ -1,9 +1,10 @@
/*
- * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <arch.h>
#include <asm_macros.S>
#include <cactus_def.h>
#include <platform_def.h>
@@ -27,6 +28,16 @@
msr sctlr_el1, x0
isb
+ /*
+ * Set CPACR_EL1.FPEN=11 no EL1/0 trapping of
+ * SVE/Adv. SIMD/FP instructions.
+ */
+ mov x1, CPACR_EL1_FPEN(CPACR_EL1_FP_TRAP_NONE)
+ mrs x0, cpacr_el1
+ orr x0, x0, x1
+ msr cpacr_el1, x0
+ isb
+
/* Relocate symbols */
pie_fixup:
ldr x0, =pie_fixup
diff --git a/spm/cactus/cactus_ffa_tests.c b/spm/cactus/cactus_ffa_tests.c
index a5acc56..8e9605d 100644
--- a/spm/cactus/cactus_ffa_tests.c
+++ b/spm/cactus/cactus_ffa_tests.c
@@ -26,6 +26,22 @@
static const uint32_t null_uuid[4] = {0};
/*
+ * Fill SIMD vectors from secure world side with a unique value.
+ * 0x22 is just a dummy value to be distinguished from the value
+ * in the normal world.
+ */
+void fill_simd_vectors(void)
+{
+ simd_vector_t simd_vectors[SIMD_NUM_VECTORS];
+
+ for (unsigned int num = 0U; num < SIMD_NUM_VECTORS; num++) {
+ memset(simd_vectors[num], 0x22 * num, sizeof(simd_vector_t));
+ }
+
+ fill_simd_vector_regs(simd_vectors);
+}
+
+/*
* Test FFA_FEATURES interface.
*/
static void ffa_features_test(void)
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index 1d81988..87ef837 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -282,6 +282,10 @@
ffa_ret = cactus_error_resp(vm_id, source);
break;
}
+ case CACTUS_REQ_SIMD_FILL_CMD:
+ fill_simd_vectors();
+ ffa_ret = cactus_success_resp(vm_id, source);
+ break;
default:
/*
* Currently direct message test is handled here.
diff --git a/spm/cactus/cactus_test_cmds.h b/spm/cactus/cactus_test_cmds.h
index 0db523e..c662d27 100644
--- a/spm/cactus/cactus_test_cmds.h
+++ b/spm/cactus/cactus_test_cmds.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -175,6 +175,21 @@
}
/**
+ * Request to fill SIMD vectors with dummy values with purpose to check a
+ * save/restore routine during the context switches between secure world and
+ * normal world.
+ *
+ * The command id is the hex representation of the string "SIMD"
+ */
+#define CACTUS_REQ_SIMD_FILL_CMD U(0x53494d44)
+
+static inline smc_ret_values cactus_req_simd_fill_send_cmd(
+ ffa_vm_id_t source, ffa_vm_id_t dest)
+{
+ return cactus_send_cmd(source, dest, CACTUS_REQ_SIMD_FILL_CMD, 0, 0, 0, 0);
+}
+
+/**
* Template for responses to CACTUS commands.
*/
static inline smc_ret_values cactus_response(
diff --git a/spm/cactus/cactus_tests.h b/spm/cactus/cactus_tests.h
index 8e838cc..c0c235e 100644
--- a/spm/cactus/cactus_tests.h
+++ b/spm/cactus/cactus_tests.h
@@ -14,6 +14,12 @@
*/
/*
+ * Alter SIMD vectors to check saving of the context while switching between
+ * the normal world and the secure world.
+ */
+void fill_simd_vectors(void);
+
+/*
* Test to FFA interfaces.
*/
void ffa_memory_management_test(struct mailbox_buffers *mb, ffa_vm_id_t vm_id,