Skip to content

Commit 3d40003

Browse files
orenc17Michael Schwarcz
authored andcommitted
Update SPM Core design - optimize for multi MCU systems
- Remove partition mutex - Introduce per secure function queues - asynchronous psa_close()
1 parent 4fc878e commit 3d40003

28 files changed

+789
-710
lines changed

TESTS/spm/client_tests/client_ipc_tests.cpp

Lines changed: 3 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ static void client_ipc_tests_call(
8383

8484
static void client_ipc_tests_close(psa_handle_t handle)
8585
{
86-
error_t status = PSA_SUCCESS;
87-
status = psa_close(handle);
86+
psa_close(handle);
8887

89-
TEST_ASSERT_EQUAL_INT(PSA_SUCCESS, status);
88+
// Wait for psa_close to finish on server side
89+
osDelay(50);
9090
}
9191

9292
//Testing iovec 0 sent as NULL
@@ -333,85 +333,6 @@ void multi_thread_diff_handles()
333333

334334
}
335335

336-
static void call_same_handle(th_struct_t *thr_attr)
337-
{
338-
client_ipc_tests_call(thr_attr->handle,
339-
thr_attr->iovec_temp,
340-
PSA_MAX_INVEC_LEN,
341-
CLIENT_RSP_BUF_SIZE,
342-
thr_attr->expected,
343-
thr_attr->expected_size);
344-
osDelay(10);
345-
}
346-
347-
//Testing multiple parallel calls to the same SFID with the same handle
348-
void multi_thread_same_handle()
349-
{
350-
Thread T1, T2, T3;
351-
th_struct_t thr_attr[] = {{0}, {0}, {0}};
352-
353-
psa_handle_t handle = client_ipc_tests_connect(PART1_SF1, MINOR_VER);
354-
355-
uint8_t meta_iovec_1[] = { 2, //expect_size
356-
2 //off
357-
};
358-
uint8_t buff1[] = {1, 2, 3};
359-
uint8_t buff2[] = {4, 5, 6};
360-
uint8_t expected_buff_1[] = {1, 2};
361-
362-
psa_invec_t iovec_temp_1[PSA_MAX_INVEC_LEN] = {{meta_iovec_1, sizeof(meta_iovec_1)},
363-
{buff1, sizeof(buff1)},
364-
{buff2, sizeof(buff2)}};
365-
366-
set_struct(&thr_attr[0], handle, iovec_temp_1, expected_buff_1, sizeof(expected_buff_1));
367-
osStatus err = T1.start(callback(call_same_handle, (th_struct_t *)&thr_attr[0]));
368-
if (err) {
369-
TEST_FAIL_MESSAGE("creating thread failed!");
370-
}
371-
372-
uint8_t meta_iovec_2[] = { 2, //expect_size
373-
3 //off
374-
};
375-
uint8_t expected_buff_2[] = {2, 3};
376-
377-
psa_invec_t iovec_temp_2[PSA_MAX_INVEC_LEN] = {{meta_iovec_2, sizeof(meta_iovec_2)},
378-
{buff1, sizeof(buff1)},
379-
{buff2, sizeof(buff2)}};
380-
set_struct(&thr_attr[1], handle, iovec_temp_2, expected_buff_2, sizeof(expected_buff_2));
381-
err = T2.start(callback(call_same_handle, (th_struct_t *)&thr_attr[1]));
382-
if (err) {
383-
TEST_FAIL_MESSAGE("creating thread failed!");
384-
}
385-
386-
uint8_t meta_iovec_3[] = { 2, //expect_size
387-
4 //off
388-
};
389-
uint8_t expected_buff_3[] = {3, 4};
390-
391-
psa_invec_t iovec_temp_3[PSA_MAX_INVEC_LEN] = {{meta_iovec_3, sizeof(meta_iovec_3)},
392-
{buff1, sizeof(buff1)},
393-
{buff2, sizeof(buff2)}};
394-
set_struct(&thr_attr[2], handle, iovec_temp_3, expected_buff_3, sizeof(expected_buff_3));
395-
err = T3.start(callback(call_same_handle, (th_struct *)&thr_attr[2]));
396-
if (err) {
397-
TEST_FAIL_MESSAGE("creating thread failed!");
398-
}
399-
400-
err = T1.join();
401-
if (err) {
402-
TEST_FAIL_MESSAGE("joining thread failed!");
403-
}
404-
err = T2.join();
405-
if (err) {
406-
TEST_FAIL_MESSAGE("joining thread failed!");
407-
}
408-
err = T3.join();
409-
if (err) {
410-
TEST_FAIL_MESSAGE("joining thread failed!");
411-
}
412-
413-
client_ipc_tests_close(handle);
414-
}
415336

416337
//Testing exceeding num of max channels allowed by psa_connect
417338
void exceed_num_of_max_channels()
@@ -449,7 +370,6 @@ Case cases[] = {
449370
Case("Testing client rx_tx_null", rx_tx_null),
450371
Case("Testing client multiple_call from a single thread", multiple_call),
451372
Case("Testing client multiple calls on different channels to the same SFID", multi_thread_diff_handles),
452-
Case("Testing client multiple calls on the same channel to the same SFID", multi_thread_same_handle),
453373
Case("Testing client exceed num of max channels allowed", exceed_num_of_max_channels),
454374
Case("Testing client close on NULL handle", client_close_null_handle),
455375
};

TESTS/spm/client_tests/server.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ void server_main(void *ptr)
2929
psa_msg_t msg = {0};
3030
psa_get(PART1_SF1_MSK, &msg);
3131
switch (msg.type) {
32-
case PSA_IPC_MSG_TYPE_CONNECT: {
32+
case PSA_IPC_MSG_TYPE_CONNECT:
33+
case PSA_IPC_MSG_TYPE_DISCONNECT:
3334
break;
34-
}
3535
case PSA_IPC_MSG_TYPE_CALL: {
3636
memset(data, 0, sizeof(data));
3737
if (msg.in_size[0] + msg.in_size[1] + msg.in_size[2] > 1) {
@@ -46,9 +46,6 @@ void server_main(void *ptr)
4646
}
4747
break;
4848
}
49-
case PSA_IPC_MSG_TYPE_DISCONNECT: {
50-
break;
51-
}
5249
default: {
5350
SPM_PANIC("Invalid msg type");
5451
}

TESTS/spm/neg_client_tests/neg_ipc_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ static void negative_client_ipc_tests_call( psa_handle_t handle,
7878

7979
static void negative_client_ipc_tests_close(psa_handle_t handle)
8080
{
81-
error_t status = PSA_SUCCESS;
82-
status = psa_close(handle);
81+
psa_close(handle);
8382

84-
TEST_ASSERT_EQUAL_INT(PSA_SUCCESS, status);
83+
// Wait for psa_close to finish on server side
84+
osDelay(50);
8585
}
8686

8787
//Testing client call with an invalid SFID

TESTS/spm/neg_client_tests/server1.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ void server_main1(void *ptr)
3232
psa_msg_t msg = {0};
3333
psa_get(NEG_CLIENT_PART1_SF1_MSK, &msg);
3434
switch (msg.type) {
35-
case PSA_IPC_MSG_TYPE_CONNECT: {
35+
case PSA_IPC_MSG_TYPE_CONNECT:
36+
case PSA_IPC_MSG_TYPE_DISCONNECT:
3637
break;
37-
}
3838
case PSA_IPC_MSG_TYPE_CALL: {
3939
memset(msg_buff, 0, msg_buff_SIZE);
4040
uint32_t bytes_read = 0;
@@ -47,13 +47,11 @@ void server_main1(void *ptr)
4747
}
4848
break;
4949
}
50-
case PSA_IPC_MSG_TYPE_DISCONNECT: {
51-
break;
52-
}
5350
default: {
5451
SPM_ASSERT(false);
5552
}
5653
}
54+
5755
psa_end(msg.handle, PSA_SUCCESS);
5856
}
5957
}

TESTS/spm/neg_client_tests/spm_reboot.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
15+
1616
#include <string.h>
1717
#include "spm_internal.h"
1818

19-
extern spm_t g_spm;
19+
extern spm_db_t g_spm;
2020
extern psa_handle_item_t g_channels_handle_storage[];
2121
extern psa_handle_item_t g_messages_handle_storage[];
22-
extern ipc_channel_t g_channel_data[];
22+
extern spm_ipc_channel_t g_channel_data[];
23+
extern spm_active_msg_t g_active_messages_data[];
2324

2425
void psa_spm_init(void);
2526

@@ -32,26 +33,26 @@ void spm_reboot(void)
3233
MBED_ASSERT(status == osOK);
3334
status = osMutexDelete(g_spm.partitions[i].mutex);
3435
MBED_ASSERT(status == osOK);
35-
status = osSemaphoreDelete(g_spm.partitions[i].semaphore);
36-
MBED_ASSERT(status == osOK);
3736

38-
g_spm.partitions[i].thread_id = NULL;
3937
for (uint32_t j = 0; j < g_spm.partitions[i].sec_funcs_count; ++j) {
4038
g_spm.partitions[i].sec_funcs[j].partition = NULL;
39+
g_spm.partitions[i].sec_funcs[j].queue.head = NULL;
40+
g_spm.partitions[i].sec_funcs[j].queue.tail = NULL;
4141
}
4242

4343
g_spm.partitions[i].sec_funcs = NULL;
4444
g_spm.partitions[i].mutex = NULL;
45-
g_spm.partitions[i].semaphore = NULL;
46-
memset(&(g_spm.partitions[i].active_msg), 0, sizeof(active_msg_t));
47-
g_spm.partitions[i].msg_handle = PSA_NULL_HANDLE;
45+
g_spm.partitions[i].thread_id = NULL;
4846
}
4947

5048
status = osMemoryPoolDelete(g_spm.channel_mem_pool);
5149
MBED_ASSERT(status == osOK);
50+
status = osMemoryPoolDelete(g_spm.active_messages_mem_pool);
51+
MBED_ASSERT(status == osOK);
5252
memset(g_channels_handle_storage, 0, (sizeof(psa_handle_item_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_CHANNELS));
53-
memset(g_messages_handle_storage, 0, (sizeof(psa_handle_item_t) * g_spm.partition_count));
54-
memset(g_channel_data, 0, (sizeof(ipc_channel_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_CHANNELS));
53+
memset(g_messages_handle_storage, 0, (sizeof(psa_handle_item_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_MESSAGES));
54+
memset(g_channel_data, 0, (sizeof(spm_ipc_channel_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_CHANNELS));
55+
memset(g_active_messages_data, 0, (sizeof(spm_active_msg_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_MESSAGES));
5556
memset(&g_spm, 0, sizeof(g_spm));
5657

5758
psa_spm_init();

TESTS/spm/neg_dual_partition/spm_reboot.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
* See the License for the specific language governing permissions and
1313
* limitations under the License.
1414
*/
15-
15+
1616
#include <string.h>
1717
#include "spm_internal.h"
1818

19-
extern spm_t g_spm;
19+
extern spm_db_t g_spm;
2020
extern psa_handle_item_t g_channels_handle_storage[];
2121
extern psa_handle_item_t g_messages_handle_storage[];
22-
extern ipc_channel_t g_channel_data[];
22+
extern spm_ipc_channel_t g_channel_data[];
23+
extern spm_active_msg_t g_active_messages_data[];
2324

2425
void psa_spm_init(void);
2526

@@ -32,26 +33,26 @@ void spm_reboot(void)
3233
MBED_ASSERT(status == osOK);
3334
status = osMutexDelete(g_spm.partitions[i].mutex);
3435
MBED_ASSERT(status == osOK);
35-
status = osSemaphoreDelete(g_spm.partitions[i].semaphore);
36-
MBED_ASSERT(status == osOK);
3736

38-
g_spm.partitions[i].thread_id = NULL;
3937
for (uint32_t j = 0; j < g_spm.partitions[i].sec_funcs_count; ++j) {
4038
g_spm.partitions[i].sec_funcs[j].partition = NULL;
39+
g_spm.partitions[i].sec_funcs[j].queue.head = NULL;
40+
g_spm.partitions[i].sec_funcs[j].queue.tail = NULL;
4141
}
4242

4343
g_spm.partitions[i].sec_funcs = NULL;
4444
g_spm.partitions[i].mutex = NULL;
45-
g_spm.partitions[i].semaphore = NULL;
46-
memset(&(g_spm.partitions[i].active_msg), 0, sizeof(active_msg_t));
47-
g_spm.partitions[i].msg_handle = PSA_NULL_HANDLE;
45+
g_spm.partitions[i].thread_id = NULL;
4846
}
4947

5048
status = osMemoryPoolDelete(g_spm.channel_mem_pool);
5149
MBED_ASSERT(status == osOK);
50+
status = osMemoryPoolDelete(g_spm.active_messages_mem_pool);
51+
MBED_ASSERT(status == osOK);
5252
memset(g_channels_handle_storage, 0, (sizeof(psa_handle_item_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_CHANNELS));
53-
memset(g_messages_handle_storage, 0, (sizeof(psa_handle_item_t) * g_spm.partition_count));
54-
memset(g_channel_data, 0, (sizeof(ipc_channel_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_CHANNELS));
53+
memset(g_messages_handle_storage, 0, (sizeof(psa_handle_item_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_MESSAGES));
54+
memset(g_channel_data, 0, (sizeof(spm_ipc_channel_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_CHANNELS));
55+
memset(g_active_messages_data, 0, (sizeof(spm_active_msg_t) * MBED_CONF_SPM_IPC_MAX_NUM_OF_MESSAGES));
5556
memset(&g_spm, 0, sizeof(g_spm));
5657

5758
psa_spm_init();

TESTS/spm/neg_server_tests/neg_ipc_tests.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,17 @@ void server_end_invalid_handle()
234234
TEST_FAIL_MESSAGE("server_end_invalid_handle negative test failed at client side");
235235
}
236236

237-
//Testing server end handle is null (PSA_NULL_HANDLE)
238-
void server_end_null_handle()
239-
{
240-
psa_connect(PART2_END_NULL_HANDLE, MINOR_VER);
241-
242-
TEST_FAIL_MESSAGE("server_end_null_handle negative test failed at client side");
243-
}
244-
245237
//Testing server end rhandle is not NULL and msg type is disconnect
246-
void server_set_rhandle_invalid()
238+
void server_set_rhandle_during_disconnect()
247239
{
248240
psa_handle_t handle = 0;
249241

250-
handle = negative_server_ipc_tests_connect(PART2_SET_RHANDLE_INVALID, MINOR_VER);
242+
handle = negative_server_ipc_tests_connect(PART2_SET_RHANDLE_DURING_DISCONNECT, MINOR_VER);
251243

252244
psa_close(handle);
253-
254-
TEST_FAIL_MESSAGE("server_set_rhandle_invalid negative test failed at client side");
245+
// Wait for psa_close to finish on server side
246+
osDelay(50);
247+
TEST_FAIL_MESSAGE("server_set_rhandle_during_disconnect negative test failed at client side");
255248
}
256249

257250
//Testing server notify partition id doesnt exist
@@ -339,8 +332,7 @@ PSA_NEG_TEST(server_write_rx_buff_null)
339332
PSA_NEG_TEST(server_write_invalid_handle)
340333
PSA_NEG_TEST(server_write_null_handle)
341334
PSA_NEG_TEST(server_end_invalid_handle)
342-
PSA_NEG_TEST(server_end_null_handle)
343-
PSA_NEG_TEST(server_set_rhandle_invalid)
335+
PSA_NEG_TEST(server_set_rhandle_during_disconnect)
344336
PSA_NEG_TEST(server_notify_part_id_invalid)
345337
PSA_NEG_TEST(server_psa_identity_invalid_handle)
346338
PSA_NEG_TEST(server_psa_identity_null_handle)
@@ -381,8 +373,7 @@ Case cases[] = {
381373
SPM_UTEST_CASE("Testing server write handle does not exist on the platform", server_write_invalid_handle),
382374
SPM_UTEST_CASE("Testing server write handle is PSA_NULL_HANDLE", server_write_null_handle),
383375
SPM_UTEST_CASE("Testing server end handle does not exist on the platform", server_end_invalid_handle),
384-
SPM_UTEST_CASE("Testing server end handle is PSA_NULL_HANDLE", server_end_null_handle),
385-
SPM_UTEST_CASE("Testing server set rhandle is not NULL while msg type is disconnect", server_set_rhandle_invalid),
376+
SPM_UTEST_CASE("Testing server set rhandle during disconnect", server_set_rhandle_during_disconnect),
386377
SPM_UTEST_CASE("Testing server notify partition id doesnt exist", server_notify_part_id_invalid),
387378
SPM_UTEST_CASE("Testing server identify handle does not exist on the platform", server_psa_identity_invalid_handle),
388379
SPM_UTEST_CASE("Testing server identify handle is PSA_NULL_HANDLE", server_psa_identity_null_handle),

0 commit comments

Comments
 (0)