chore(hftest): use common secondary stack definition
Have multicore tests in different test setups refer to a common
definition of `secondary_ec_stack` for secondary execution context
stack allocations. Refactor `hftest_cpu_start` to no longer
receive `stack` and `stack_size` as arguments and to instead refer to
this common stack definition.
Signed-off-by: Kathleen Capella <kathleen.capella@arm.com>
Change-Id: I600f4c73e1c615c83a3c69003ce725087e066eab
diff --git a/test/hftest/power_mgmt.c b/test/hftest/power_mgmt.c
index afd1744..e77dfb3 100644
--- a/test/hftest/power_mgmt.c
+++ b/test/hftest/power_mgmt.c
@@ -55,18 +55,18 @@
arch_cpu_stop();
}
-bool hftest_cpu_start(uintptr_t id, void *stack, size_t stack_size,
- void (*entry)(uintptr_t arg), uintptr_t arg)
+bool hftest_cpu_start(uintptr_t id, void (*entry)(uintptr_t arg), uintptr_t arg)
{
struct cpu_start_state s;
struct arch_cpu_start_state s_arch;
+ size_t stack_size = sizeof(secondary_ec_stack[0]);
/*
* Config for arch_cpu_start() which will start a new CPU and
* immediately jump to cpu_entry(). This function must guarantee that
* the state struct is not be freed until cpu_entry() is called.
*/
- s_arch.initial_sp = (uintptr_t)stack + stack_size;
+ s_arch.initial_sp = (uintptr_t)secondary_ec_stack + stack_size;
s_arch.entry = cpu_entry;
s_arch.arg = (uintptr_t)&s;
diff --git a/test/inc/test/hftest.h b/test/inc/test/hftest.h
index 87e079e..b30a894 100644
--- a/test/inc/test/hftest.h
+++ b/test/inc/test/hftest.h
@@ -174,8 +174,8 @@
* with the provided argument. It is a wrapper around the generic cpu_start()
* and takes care of MMU initialization.
*/
-bool hftest_cpu_start(uintptr_t id, void *stack, size_t stack_size,
- void (*entry)(uintptr_t arg), uintptr_t arg);
+bool hftest_cpu_start(uintptr_t id, void (*entry)(uintptr_t arg),
+ uintptr_t arg);
uintptr_t hftest_get_cpu_id(size_t index);
diff --git a/test/vmapi/ffa_secure_partitions/dir_msg.c b/test/vmapi/ffa_secure_partitions/dir_msg.c
index ff39429..f93cd18 100644
--- a/test/vmapi/ffa_secure_partitions/dir_msg.c
+++ b/test/vmapi/ffa_secure_partitions/dir_msg.c
@@ -22,8 +22,6 @@
#define SP_SLEEP_LONG 2000U
-alignas(4096) static uint8_t secondary_ec_stack[MAX_CPUS - 1][PAGE_SIZE];
-
struct secondary_cpu_entry_args {
ffa_id_t receiver_id;
ffa_vcpu_count_t vcpu_count;
@@ -162,11 +160,9 @@
id = hftest_get_cpu_id(i);
HFTEST_LOG("Booting CPU %u - %x", i, id);
- EXPECT_EQ(
- hftest_cpu_start(id, secondary_ec_stack[i - 1],
- sizeof(secondary_ec_stack[0]),
- migrate_busy_up_sp, (uintptr_t)&args),
- true);
+ EXPECT_EQ(hftest_cpu_start(id, migrate_busy_up_sp,
+ (uintptr_t)&args),
+ true);
HFTEST_LOG("Done with CPU %u", i);
}
diff --git a/test/vmapi/ffa_secure_partitions/inc/ffa_secure_partitions.h b/test/vmapi/ffa_secure_partitions/inc/ffa_secure_partitions.h
index e1623e3..7e0d428 100644
--- a/test/vmapi/ffa_secure_partitions/inc/ffa_secure_partitions.h
+++ b/test/vmapi/ffa_secure_partitions/inc/ffa_secure_partitions.h
@@ -8,6 +8,8 @@
#pragma once
+#include "hf/mm.h"
+
#include "test/hftest.h"
#include "test/vmapi/ffa.h"
diff --git a/test/vmapi/ffa_secure_partitions/notifications.c b/test/vmapi/ffa_secure_partitions/notifications.c
index 0c6f539..8c8d381 100644
--- a/test/vmapi/ffa_secure_partitions/notifications.c
+++ b/test/vmapi/ffa_secure_partitions/notifications.c
@@ -185,7 +185,6 @@
static void base_per_cpu_notifications_test(void (*cpu_entry)(uintptr_t arg))
{
struct spinlock lock = SPINLOCK_INIT;
- alignas(4096) static uint8_t other_stack[MAX_CPUS - 1][4096];
struct notif_cpu_entry_args args = {.lock = &lock};
struct ffa_partition_info sp;
struct mailbox_buffers mb = set_up_mailbox();
@@ -206,9 +205,7 @@
args.vcpu_id = i;
- EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(i),
- other_stack[i - 1],
- sizeof(other_stack[0]), cpu_entry,
+ EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(i), cpu_entry,
(uintptr_t)&args),
true);
diff --git a/test/vmapi/ffa_secure_partitions/power_mgt.c b/test/vmapi/ffa_secure_partitions/power_mgt.c
index 5cf8387..0f8194f 100644
--- a/test/vmapi/ffa_secure_partitions/power_mgt.c
+++ b/test/vmapi/ffa_secure_partitions/power_mgt.c
@@ -19,8 +19,6 @@
#include "test/hftest.h"
#include "test/vmapi/ffa.h"
-alignas(4096) static uint8_t secondary_ec_stack[MAX_CPUS - 1][4096];
-
struct pwr_mgt_cpu_entry_args {
ffa_id_t receiver_id;
ffa_vcpu_count_t vcpu_count;
@@ -150,9 +148,7 @@
*/
args.vcpu_id = (ffa_vcpu_index_t)i;
- EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(i),
- secondary_ec_stack[i - 1],
- sizeof(secondary_ec_stack[0]), entry,
+ EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(i), entry,
(uintptr_t)&args),
true);
diff --git a/test/vmapi/ffa_secure_partitions/secure_interrupts.c b/test/vmapi/ffa_secure_partitions/secure_interrupts.c
index 127c9be..080183b 100644
--- a/test/vmapi/ffa_secure_partitions/secure_interrupts.c
+++ b/test/vmapi/ffa_secure_partitions/secure_interrupts.c
@@ -24,8 +24,6 @@
#define LAST_SECONDARY_VCPU_ID (MAX_CPUS - 1)
#define MID_SECONDARY_VCPU_ID (MAX_CPUS / 2)
-alignas(4096) static uint8_t secondary_ec_stack[MAX_CPUS - 1][PAGE_SIZE];
-
struct secondary_cpu_entry_args {
ffa_id_t receiver_id;
ffa_vcpu_count_t vcpu_count;
@@ -551,9 +549,7 @@
args.vcpu_id = i;
HFTEST_LOG("Booting CPU %u - %x", i, cpu_id);
- EXPECT_EQ(hftest_cpu_start(cpu_id, secondary_ec_stack[i - 1],
- sizeof(secondary_ec_stack[0]),
- cpu_entry_sp_sleep_loop,
+ EXPECT_EQ(hftest_cpu_start(cpu_id, cpu_entry_sp_sleep_loop,
(uintptr_t)&args),
true);
diff --git a/test/vmapi/primary_only/faults.c b/test/vmapi/primary_only/faults.c
index 4eb3644..0618674 100644
--- a/test/vmapi/primary_only/faults.c
+++ b/test/vmapi/primary_only/faults.c
@@ -57,7 +57,6 @@
TEST(faults, spurious_due_to_configure)
{
struct state s;
- alignas(4096) static uint8_t other_stack[4096];
sl_init(&s.lock);
s.done = false;
@@ -71,10 +70,9 @@
* MAX_CPUS - index internally. Since legacy VMs do not follow this
* convention, index 7 is passed into `hftest_cpu_get_id`.
*/
- EXPECT_EQ(
- hftest_cpu_start(hftest_get_cpu_id(7), other_stack,
- sizeof(other_stack), rx_reader, (uintptr_t)&s),
- true);
+ EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(7), rx_reader,
+ (uintptr_t)&s),
+ true);
/* Wait for CPU to release the lock. */
sl_lock(&s.lock);
diff --git a/test/vmapi/primary_only/primary_only.c b/test/vmapi/primary_only/primary_only.c
index e700679..01a2127 100644
--- a/test/vmapi/primary_only/primary_only.c
+++ b/test/vmapi/primary_only/primary_only.c
@@ -81,7 +81,6 @@
TEST(cpus, start)
{
struct spinlock lock = SPINLOCK_INIT;
- alignas(4096) static uint8_t other_stack[4096];
/* Start secondary while holding lock. */
sl_lock(&lock);
@@ -92,8 +91,7 @@
* MAX_CPUS - index internally. Since legacy VMs do not follow this
* convention, index 7 is passed into `hftest_cpu_get_id`.
*/
- EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(7), other_stack,
- sizeof(other_stack), vm_cpu_entry,
+ EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(7), vm_cpu_entry,
(uintptr_t)&lock),
true);
@@ -128,7 +126,6 @@
TEST(cpus, stop)
{
struct spinlock lock = SPINLOCK_INIT;
- alignas(4096) static uint8_t other_stack[4096];
/**
* `hftest_get_cpu_id` function makes the assumption that cpus are
@@ -142,7 +139,6 @@
sl_lock(&lock);
dlog("Starting second CPU.\n");
EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(secondary_cpu_index),
- other_stack, sizeof(other_stack),
vm_cpu_entry_stop, (uintptr_t)&lock),
true);
@@ -158,7 +154,6 @@
dlog("Starting second CPU again.\n");
EXPECT_EQ(hftest_cpu_start(hftest_get_cpu_id(secondary_cpu_index),
- other_stack, sizeof(other_stack),
vm_cpu_entry_stop, (uintptr_t)&lock),
true);
diff --git a/test/vmapi/primary_with_secondaries/dir_msg.c b/test/vmapi/primary_with_secondaries/dir_msg.c
index 3a9d2e0..a387f8f 100644
--- a/test/vmapi/primary_with_secondaries/dir_msg.c
+++ b/test/vmapi/primary_with_secondaries/dir_msg.c
@@ -1066,8 +1066,6 @@
HFTEST_LOG("Starting secondary core...\n");
ASSERT_TRUE(hftest_cpu_start(hftest_get_cpu_id(vcpu_id),
- secondary_ec_stack,
- sizeof(secondary_ec_stack),
cpu_entry_echo_mp, (uintptr_t)&args));
/* Wait for secondary core to return before finishing the test. */
@@ -1102,8 +1100,6 @@
HFTEST_LOG("Starting secondary core...\n");
ASSERT_TRUE(hftest_cpu_start(hftest_get_cpu_id(vcpu_id),
- secondary_ec_stack,
- sizeof(secondary_ec_stack),
cpu_entry_echo_mp, (uintptr_t)&args));
/* Wait for secondary core to return before finishing the test. */
diff --git a/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h b/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h
index 563ebb2..37b8577 100644
--- a/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h
+++ b/test/vmapi/primary_with_secondaries/inc/primary_with_secondary.h
@@ -96,5 +96,3 @@
/* Helpers common to the setup. */
bool exception_received(struct ffa_value* run_res, const void* recv_buf);
-
-extern uint8_t secondary_ec_stack[MAX_CPUS - 1][PAGE_SIZE];
diff --git a/test/vmapi/primary_with_secondaries/run_race.c b/test/vmapi/primary_with_secondaries/run_race.c
index e635fce..2a6705a 100644
--- a/test/vmapi/primary_with_secondaries/run_race.c
+++ b/test/vmapi/primary_with_secondaries/run_race.c
@@ -93,7 +93,6 @@
*/
TEST_LONG_RUNNING(vcpu_state, concurrent_save_restore)
{
- alignas(4096) static char stack[4096];
static struct mailbox_buffers mb;
struct cpu_state state;
@@ -112,8 +111,8 @@
* MAX_CPUS - index internally. Since legacy VMs do not follow this
* convention, index 7 is passed into `hftest_cpu_get_id`.
*/
- ASSERT_TRUE(hftest_cpu_start(hftest_get_cpu_id(7), stack, sizeof(stack),
- vm_cpu_entry, (uintptr_t)&state));
+ ASSERT_TRUE(hftest_cpu_start(hftest_get_cpu_id(7), vm_cpu_entry,
+ (uintptr_t)&state));
/* Run on a loop until the secondary VM is done. */
EXPECT_TRUE(run_loop(&mb));
diff --git a/test/vmapi/primary_with_secondaries/services/smp.c b/test/vmapi/primary_with_secondaries/services/smp.c
index 7da71be..e0530f4 100644
--- a/test/vmapi/primary_with_secondaries/services/smp.c
+++ b/test/vmapi/primary_with_secondaries/services/smp.c
@@ -23,12 +23,6 @@
#define ARG_VALUE 42
-/*
- * Secondary VM that starts a second vCPU and then sends messages from both.
- */
-
-alignas(4096) static char stack[4096];
-
/** Send a message back to the primary. */
void send_message(const char *message, uint32_t size)
{
@@ -62,8 +56,7 @@
/* Start second vCPU. */
dlog("Secondary starting second vCPU.\n");
- ASSERT_TRUE(hftest_cpu_start(1, stack, sizeof(stack), vm_cpu_entry,
- ARG_VALUE));
+ ASSERT_TRUE(hftest_cpu_start(1, vm_cpu_entry, ARG_VALUE));
dlog("Secondary started second vCPU.\n");
/* Check that vCPU statuses are as expected. */