Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for SMC Capability #85

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/sel4test-driver/include/test_init_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ typedef struct {
/* sched control cap */
seL4_CPtr sched_ctrl;

#ifdef CONFIG_ALLOW_SMC_CALLS
/* smc cap */
seL4_CPtr smc;
#endif /* CONFIG_ALLOW_SMC_CALLS */

/* device frame cap */
seL4_CPtr device_frame_cap;

Expand Down
5 changes: 5 additions & 0 deletions apps/sel4test-driver/src/testtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ void basic_set_up(uintptr_t e)
sel4utils_copy_cap_to_process(&(env->test_process), &env->vka, sched_ctrl);
}
}
#ifdef CONFIG_ALLOW_SMC_CALLS
env->init->smc = sel4utils_copy_cap_to_process(&(env->test_process), &env->vka, simple_get_init_cap(&env->simple,
seL4_CapSMC));
#endif /* CONFIG_ALLOW_SMC_CALLS */

/* setup data about untypeds */
env->init->untypeds = copy_untypeds_to_process(&(env->test_process), env->untypeds, env->num_untypeds, env);
/* copy the fault endpoint - we wait on the endpoint for a message
Expand Down
3 changes: 3 additions & 0 deletions apps/sel4test-tests/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ int main(int argc, char **argv)
env.asid_pool = init_data->asid_pool;
env.asid_ctrl = init_data->asid_ctrl;
env.sched_ctrl = init_data->sched_ctrl;
#ifdef CONFIG_ALLOW_SMC_CALLS
env.smc = init_data->smc;
#endif
#ifdef CONFIG_IOMMU
env.io_space = init_data->io_space;
#endif
Expand Down
77 changes: 77 additions & 0 deletions apps/sel4test-tests/src/tests/smc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2017, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <autoconf.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <sel4/sel4.h>
#include <sel4utils/arch/util.h>

#include <vka/object.h>
#include <vka/capops.h>

#include "../test.h"
#include "../helpers.h"
#include "sel4/simple_types.h"

#ifdef CONFIG_ALLOW_SMC_CALLS

#define ARM_STD_SVC_VERSION 0x8400ff03
#define UNASSIGNED_SMC 0x82000000

static int test_smc_calls(env_t env)
{
seL4_ARM_SMCContext smc_args;
seL4_ARM_SMCContext smc_results;
int error;

seL4_CPtr smc_cap = env->smc;
seL4_CPtr badged_smc_cap = get_free_slot(env);

error = cnode_mint(env, smc_cap, badged_smc_cap, seL4_AllRights, ARM_STD_SVC_VERSION);
test_error_eq(error, seL4_NoError);

/* Set function and arguments */
smc_args.x0 = ARM_STD_SVC_VERSION;
smc_args.x1 = 0;
smc_args.x2 = 2;
smc_args.x3 = 3;
smc_args.x4 = 0;
smc_args.x5 = 0;
smc_args.x6 = 0;
smc_args.x7 = 0;

/* This should succeed */
error = seL4_ARM_SMC_Call(badged_smc_cap, &smc_args, &smc_results);
test_error_eq(error, seL4_NoError);

/* Make sure the call returned something other than the input */
test_neq(smc_results.x0, smc_args.x0);

/* Check that the version returned is non-zero */
seL4_Word version_sum = smc_results.x0 + smc_results.x1;
test_geq(version_sum, 1UL);

/* Check that the remaining result registers are clobbered */
test_eq(smc_results.x2, 0UL);
test_eq(smc_results.x3, 0UL);
Indanz marked this conversation as resolved.
Show resolved Hide resolved

/* This should fail - SMC call with a different function id from badge */
smc_args.x0 = UNASSIGNED_SMC;
error = seL4_ARM_SMC_Call(badged_smc_cap, &smc_args, &smc_results);
test_error_eq(error, seL4_IllegalOperation);

/* This should fail - can't mint from cap with non-zero badge */
seL4_CPtr bad_badged_cap = get_free_slot(env);
error = cnode_mint(env, badged_smc_cap, bad_badged_cap, seL4_AllRights, UNASSIGNED_SMC);
test_error_eq(error, seL4_IllegalOperation);

return sel4test_get_result();
}
DEFINE_TEST(SMC0001, "Test SMC calls", test_smc_calls, true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it reasonable to assume that CONFIG_ALLOW_SMC_CALLS will only be enabled on sel4test runs when the test platform also has a compatible ATF running for this test to pass?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It seems reasonable to me)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so too. You really need to go looking to add it in.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought ARM mandates ATF for Aarch64, or at least strongly encourages it.


#endif