From: Chaitanya S Prakash chaitanyas.prakash@arm.com
As Morello kselftests are standalone and don't make use of standard C libraries at the moment, a get_pagesize() function has been added to retrieve the page size of a system at runtime. The morello_auxv struct originally defined in bootstrap.c, has been moved to freestanding.h to facilitate its access from multiple files.
Make use of the get_pagesize function to define a fixed address that can be used as needed among the tests.
Signed-off-by: Chaitanya S Prakash chaitanyas.prakash@arm.com --- tools/testing/selftests/arm64/morello/bootstrap.c | 6 ------ .../selftests/arm64/morello/freestanding.c | 15 +++++++++++++++ .../selftests/arm64/morello/freestanding.h | 9 +++++++++ tools/testing/selftests/arm64/morello/mmap.c | 11 ++++++++++- 4 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/arm64/morello/bootstrap.c b/tools/testing/selftests/arm64/morello/bootstrap.c index a2719fe5e883..111ccd2204ce 100644 --- a/tools/testing/selftests/arm64/morello/bootstrap.c +++ b/tools/testing/selftests/arm64/morello/bootstrap.c @@ -37,12 +37,6 @@ #define ASSERT_CAP_EQ(exp, seen) \ ASSERT_TRUE(__builtin_cheri_equal_exact(exp, seen))
-struct morello_auxv { - long a_type; - long _padding; - uintcap_t a_val; -}; - struct initial_data { int argc; char **argv; diff --git a/tools/testing/selftests/arm64/morello/freestanding.c b/tools/testing/selftests/arm64/morello/freestanding.c index 45c0fa8b0914..78b9c077a233 100644 --- a/tools/testing/selftests/arm64/morello/freestanding.c +++ b/tools/testing/selftests/arm64/morello/freestanding.c @@ -6,6 +6,7 @@ #include <stdbool.h>
#include <linux/errno.h> +#include <linux/auxvec.h>
#include "freestanding.h"
@@ -93,6 +94,20 @@ static ssize_t __write_all(const char *str, size_t len) return written; }
+unsigned long get_pagesize(struct morello_auxv *auxv) +{ + unsigned long page_size = 0; + + while (auxv->a_type != AT_NULL) { + if (auxv->a_type == AT_PAGESZ) { + page_size = auxv->a_val; + break; + } + ++auxv; + } + return page_size; +} + /* * formats supported: %d, %x, %s, %p, * modifiers l/z/u are accepted and ignored. To compensate, values are always diff --git a/tools/testing/selftests/arm64/morello/freestanding.h b/tools/testing/selftests/arm64/morello/freestanding.h index 6ec299ed4cae..616f5bb3e438 100644 --- a/tools/testing/selftests/arm64/morello/freestanding.h +++ b/tools/testing/selftests/arm64/morello/freestanding.h @@ -31,6 +31,7 @@ typedef __uintcap_t uintcap_t; #endif
#define EXIT_SUCCESS 0 +#define __maybe_unused __attribute__((__unused__))
#ifndef WIFEXITED #define WIFEXITED(status) (((status) & 0x7f) == 0) @@ -43,6 +44,14 @@ struct __test_meta { int message; };
+struct morello_auxv { + long a_type; + long _padding; + uintcap_t a_val; +}; + +unsigned long get_pagesize(struct morello_auxv *auxv); + void install_kernel_stack(void); uintcap_t __syscall(uintcap_t, uintcap_t, uintcap_t, uintcap_t, uintcap_t, uintcap_t, uintcap_t);
diff --git a/tools/testing/selftests/arm64/morello/mmap.c b/tools/testing/selftests/arm64/morello/mmap.c index 2dd4ccdb0d2a..ff5391b5b65b 100644 --- a/tools/testing/selftests/arm64/morello/mmap.c +++ b/tools/testing/selftests/arm64/morello/mmap.c @@ -19,6 +19,12 @@ #define PROBE_MODE_TOUCH 0x01 #define PROBE_MODE_VERIFY 0x02
+/* As the minimum address is configurable, consider the default value of + * CONFIG_LSM_MMAP_MIN_ADDR which is 65536 (64K) for a fixed address. + */ +#define min_addr (1ULL << 16) + +static unsigned long pagesize;
static inline int probe_mem_range(void *addr, size_t size, int mode) { @@ -127,8 +133,11 @@ TEST(test_syscall_mmap2) syscall_mmap2(); }
-int main(void) +int main(int argc __maybe_unused, char **argv __maybe_unused, char **envp __maybe_unused, + struct morello_auxv *auxv) { + pagesize = get_pagesize(auxv); + test_syscall_mmap(); test_syscall_mmap2(); return 0;