test(memory share): hypervisor's RX is realm on retrieve
The test validates that the SPMC is able to recover from a trapped
access to a realm RX buffer during the retrieve response. The
call to FFA_MEMORY_RETRIEVE_REQ should return FFA_ERROR_ABORTED.
Following, reset the RX buffer's PAS back to NS, and repeat the
retrieve request. This time the operation should succeed.
Relinquish the memory to allow the reclaim.
At the end of the operation, the sender shall still be able to reclaim
as the retrieve request should have failed to update any of the structures.
Signed-off-by: J-Alves <joao.alves@arm.com>
Change-Id: I5d0f2a3e5716a3ed27dda4b6592682c34841ed63
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
index 332d544..04c8fde 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_memory_sharing.c
@@ -1335,13 +1335,7 @@
return TEST_RESULT_SUCCESS;
}
-/**
- * Test that a retrieve request from the hypervisor would fail if the TX buffer
- * was in realm state. This is recreating the situation in which the Hyp doesn't
- * track the state of the operation, and it is forwarding the retrieve request
- * to the SPMC.
- */
-test_result_t test_ffa_memory_retrieve_request_fail_tx_realm(void)
+test_result_t base_ffa_memory_retrieve_request_fail_buffer_realm(bool delegate_rx)
{
struct mailbox_buffers mb;
struct ffa_memory_access receivers[2] = {
@@ -1354,9 +1348,12 @@
u_register_t ret_rmm;
struct ffa_value ret;
size_t descriptor_size;
+ void *to_delegate;
GET_TFTF_MAILBOX(mb);
+ to_delegate = delegate_rx ? mb.recv : mb.send;
+
if (get_armv9_2_feat_rme_support() == 0U) {
return TEST_RESULT_SKIPPED;
}
@@ -1375,8 +1372,8 @@
FFA_MEMORY_NORMAL_MEM, FFA_MEMORY_CACHE_WRITE_BACK,
FFA_MEMORY_INNER_SHAREABLE);
- /* Delegate TX buffer to realm. */
- ret_rmm = host_rmi_granule_delegate((u_register_t)mb.send);
+ /* Delegate buffer to realm. */
+ ret_rmm = host_rmi_granule_delegate((u_register_t)to_delegate);
if (ret_rmm != 0UL) {
ERROR("Delegate operation returns %#lx for address %p\n",
@@ -1391,7 +1388,7 @@
}
/* Undelegate to reestablish the same security state for PAS. */
- ret_rmm = host_rmi_granule_undelegate((u_register_t)mb.send);
+ ret_rmm = host_rmi_granule_undelegate((u_register_t)to_delegate);
if (ret_rmm != 0UL) {
ERROR("Undelegate operation returns %#lx for address %p\n",
@@ -1420,3 +1417,28 @@
return TEST_RESULT_SUCCESS;
}
+
+/**
+ * Test that a retrieve request from the hypervisor would fail if the TX buffer
+ * was in realm state. This is recreating the situation in which the Hyp doesn't
+ * track the state of the operation, and it is forwarding the retrieve request
+ * to the SPMC.
+ */
+test_result_t test_ffa_memory_retrieve_request_fail_tx_realm(void)
+{
+ return base_ffa_memory_retrieve_request_fail_buffer_realm(false);
+}
+
+/**
+ * Test that a retrieve request from the hypervisor would fail if the RX buffer
+ * was in realm state. This is recreating the situation in which the Hyp doesn't
+ * track the state of the operation, and it is forwarding the retrieve request
+ * to the SPMC. The operation shall fail at the point at which the SPMC is
+ * providing retrieve response. The SPMC should have reverted the change to any
+ * of its share state tracking structures, such that the final reclaim would be
+ * possible.
+ */
+test_result_t test_ffa_memory_retrieve_request_fail_rx_realm(void)
+{
+ return base_ffa_memory_retrieve_request_fail_buffer_realm(true);
+}
diff --git a/tftf/tests/tests-memory-access.xml b/tftf/tests/tests-memory-access.xml
index f0242f3..d671b51 100644
--- a/tftf/tests/tests-memory-access.xml
+++ b/tftf/tests/tests-memory-access.xml
@@ -73,6 +73,8 @@
function="test_ffa_mem_share_tx_realm_expect_fail" />
<testcase name="FF-A Memory Retrieve, NWd TX buffer is in realm PAS"
function="test_ffa_memory_retrieve_request_fail_tx_realm" />
+ <testcase name="FF-A Memory Retrieve, NWd RX buffer is in realm PAS"
+ function="test_ffa_memory_retrieve_request_fail_rx_realm" />
</testsuite>
</testsuites>