diff options
author | J-Alves <joao.alves@arm.com> | 2020-10-08 17:25:37 +0100 |
---|---|---|
committer | J-Alves <joao.alves@arm.com> | 2020-10-29 10:16:53 +0000 |
commit | 40618a311dd200c62cb6b6753edb93f22cb831c8 (patch) | |
tree | 7903d4a9fa36fcbc74d00d941865c7126080f496 /tftf | |
parent | 8f4a56f23ed26798402f3964a61fcd764bf7e539 (diff) | |
download | tf-a-tests-40618a311dd200c62cb6b6753edb93f22cb831c8.tar.gz |
TFTF: tests for FF-A memory sharing operations
Test FF-A memory sharing interfaces between tftf and cactus secure
partitions.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I837e44ab2cb10b42af23afbc9a94c726b4af7b64
Diffstat (limited to 'tftf')
-rw-r--r-- | tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c | 187 | ||||
-rw-r--r-- | tftf/tests/tests-spm.mk | 1 | ||||
-rw-r--r-- | tftf/tests/tests-spm.xml | 10 |
3 files changed, 198 insertions, 0 deletions
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c new file mode 100644 index 000000000..0ae8a8d30 --- /dev/null +++ b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2020, Arm Limited. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include <cactus_test_cmds.h> +#include <debug.h> +#include <ffa_endpoints.h> +#include <ffa_helpers.h> +#include <test_helpers.h> +#include <tftf_lib.h> +#include <xlat_tables_defs.h> + +#define MAILBOX_SIZE PAGE_SIZE + +#define SENDER HYP_ID +#define RECEIVER SP_ID(1) + +/* Memory section to be sent over mem management ABIs */ +static __aligned(PAGE_SIZE) uint8_t share_page[PAGE_SIZE]; + +static __aligned(PAGE_SIZE) uint8_t send_page[PAGE_SIZE]; +static __aligned(PAGE_SIZE) uint8_t recv_page[PAGE_SIZE]; + +/* Within the same test the RXTX Buffers only need to be shared once */ +static bool rxtx_mapped; + +static struct mailbox_buffers mb = { + .recv = (void *)recv_page, + .send = (void *)send_page, + }; + +static test_result_t test_memory_send_sp(uint32_t mem_func) +{ + smc_ret_values ret; + uint32_t remaining_constituent_count; + uint32_t total_length; + uint32_t fragment_length; + uint32_t sent_length; + ffa_memory_handle_t handle; + uint32_t *ptr; + + /********************************************************************** + * Verify that FFA is there and that it has the correct version. + **********************************************************************/ + SKIP_TEST_IF_FFA_VERSION_LESS_THAN(1, 0); + + /********************************************************************** + * If OPTEE is SPMC skip this test. + **********************************************************************/ + if (check_spmc_execution_level()) { + VERBOSE("OPTEE as SPMC at S-EL1. Skipping test!\n"); + return TEST_RESULT_SKIPPED; + } + + if (!rxtx_mapped) { + ret = ffa_rxtx_map((uintptr_t)mb.send, (uintptr_t)mb.recv, 1); + + if (ret.ret0 != FFA_SUCCESS_SMC32) { + ERROR("ffa_rxtx_map failed (%lx)\n", ret.ret0); + return TEST_RESULT_FAIL; + } + rxtx_mapped = true; + } + + /********************************************************************** + * Verify that cactus primary SP is deployed in the system. + **********************************************************************/ + SKIP_TEST_IF_FFA_ENDPOINT_NOT_DEPLOYED(mb, PRIMARY_UUID); + + struct ffa_memory_region_constituent constituents[] = { + {(void *)share_page, 1, 0} + }; + + const uint32_t constituents_count = sizeof(constituents) / + sizeof(struct ffa_memory_region_constituent); + + enum ffa_data_access data_access = (mem_func == FFA_MEM_DONATE_SMC32) ? + FFA_DATA_ACCESS_NOT_SPECIFIED : + FFA_DATA_ACCESS_RW; + + /* + * TODO: Revise shareability attribute in function call + * below. + * https://lists.trustedfirmware.org/pipermail/hafnium/2020-June/000023.html + */ + remaining_constituent_count = ffa_memory_region_init( + mb.send, MAILBOX_SIZE, SENDER, RECEIVER, constituents, + constituents_count, 0, 0, + data_access, + FFA_INSTRUCTION_ACCESS_NOT_SPECIFIED, + FFA_MEMORY_NORMAL_MEM, + FFA_MEMORY_CACHE_WRITE_BACK, + FFA_MEMORY_OUTER_SHAREABLE, + &total_length, + &fragment_length + ); + + switch (mem_func) { + case FFA_MEM_SHARE_SMC32: + ret = ffa_mem_share(total_length, fragment_length); + break; + case FFA_MEM_LEND_SMC32: + ret = ffa_mem_lend(total_length, fragment_length); + break; + case FFA_MEM_DONATE_SMC32: + ret = ffa_mem_donate(total_length, fragment_length); + break; + default: + NOTICE("TFTF - Invalid func id!\n"); + return TEST_RESULT_FAIL; + } + + sent_length = fragment_length; + + if (ret.ret0 != FFA_SUCCESS_SMC32) { + tftf_testcase_printf("Failed to send memory to SP %x.\n", + RECEIVER); + return TEST_RESULT_FAIL; + } + + if (sent_length != total_length) { + tftf_testcase_printf("Sent and Total lengths must be equal!\n"); + return TEST_RESULT_FAIL; + } + + if (remaining_constituent_count != 0) { + tftf_testcase_printf("Remaining constituent should be 0\n"); + return TEST_RESULT_FAIL; + } + + handle = ffa_mem_success_handle(ret); + + VERBOSE("TFTF - Handle: %llx\nTFTF - Address: %p\n", + handle, constituents[0].address); + + ptr = (uint32_t *)constituents[0].address; + + ret = CACTUS_MEM_SEND_CMD(SENDER, RECEIVER, mem_func, handle); + + if (ret.ret0 != FFA_MSG_SEND_DIRECT_RESP_SMC32) { + ERROR("Failed to send message. error: %lx\n", + ret.ret2); + return TEST_RESULT_FAIL; + } + + if (CACTUS_GET_RESPONSE(ret) != CACTUS_SUCCESS) { + tftf_testcase_printf("Failed memory send operation!\n"); + return TEST_RESULT_FAIL; + } + + /* + * Print 5 words from the memory region to validate SP wrote to the + * memory region. + */ + VERBOSE("TFTF - Memory contents after SP use:\n"); + for (unsigned int i = 0U; i < 5U; i++) + VERBOSE(" %u: %x\n", i, ptr[i]); + + /* To make the compiler happy in case it is not a verbose build */ + if (LOG_LEVEL < LOG_LEVEL_VERBOSE) + (void)ptr; + + if (mem_func != FFA_MEM_DONATE_SMC32 && + ffa_mem_reclaim(handle, 0).ret0 == FFA_ERROR) { + tftf_testcase_printf("Couldn't reclaim memory\n"); + return TEST_RESULT_FAIL; + } + + return TEST_RESULT_SUCCESS; +} + +test_result_t test_mem_share_sp(void) +{ + return test_memory_send_sp(FFA_MEM_SHARE_SMC32); +} + +test_result_t test_mem_lend_sp(void) +{ + return test_memory_send_sp(FFA_MEM_LEND_SMC32); +} + +test_result_t test_mem_donate_sp(void) +{ + return test_memory_send_sp(FFA_MEM_DONATE_SMC32); +} diff --git a/tftf/tests/tests-spm.mk b/tftf/tests/tests-spm.mk index bef373fbb..ee339b5a4 100644 --- a/tftf/tests/tests-spm.mk +++ b/tftf/tests/tests-spm.mk @@ -10,4 +10,5 @@ TESTS_SOURCES += \ test_ffa_direct_messaging.c \ test_ffa_version.c \ test_ffa_features.c \ + test_ffa_memory_sharing.c \ ) diff --git a/tftf/tests/tests-spm.xml b/tftf/tests/tests-spm.xml index e2f29bfe1..85001f22a 100644 --- a/tftf/tests/tests-spm.xml +++ b/tftf/tests/tests-spm.xml @@ -30,6 +30,16 @@ </testsuite> + <testsuite name="FF-A Memory Sharing" + description="Test FF-A Memory Sharing ABIs" > + <testcase name="Lend Memory to Secure World" + function="test_mem_lend_sp" /> + <testcase name="Share Memory with Secure World" + function="test_mem_share_sp" /> + <testcase name="Donate Memory to Secure World" + function="test_mem_donate_sp"/> + </testsuite> + <testsuite name="PSA FF-A features" description="Test FFA_FEATURES ABI" > <testcase name="Test FFA_FEATURES" |