[PATCH v1 6/7] kselftest/arm64: mte: add test type enum
Joey Gouly
joey.gouly at arm.com
Tue Jan 25 07:09:19 PST 2022
This enum will be used to parameterise the test to perform other syscalls
than 'read'.
Signed-off-by: Joey Gouly <joey.gouly at arm.com>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Will Deacon <will at kernel.org>
---
.../selftests/arm64/mte/check_user_mem.c | 83 +++++++++++--------
1 file changed, 50 insertions(+), 33 deletions(-)
diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index 8b1b586f3df8..d104feab4e86 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -19,12 +19,18 @@
static size_t page_sz;
+enum test_type {
+ READ_TEST,
+ LAST_TEST,
+};
+
static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping,
- int tag_offset, int tag_len)
+ int tag_offset, int tag_len,
+ enum test_type test_type)
{
int fd, i, err;
char val = 'A';
- size_t len, read_len;
+ ssize_t len, syscall_len;
void *ptr, *ptr_next;
int fileoff, ptroff, size;
int sizes[] = {1, 2, 3, 8, 16, 32, 4096};
@@ -46,9 +52,9 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
}
mte_initialize_current_context(mode, (uintptr_t)ptr, len);
/* Copy from file into buffer with valid tag */
- read_len = read(fd, ptr, len);
+ syscall_len = read(fd, ptr, len);
mte_wait_after_trig();
- if (cur_mte_cxt.fault_valid || read_len < len) {
+ if (cur_mte_cxt.fault_valid || syscall_len < len) {
err = KSFT_FAIL;
goto usermem_acc_err;
}
@@ -73,8 +79,16 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
for (i = 0; i < ARRAY_SIZE(sizes); i++) {
size = sizes[i];
lseek(fd, 0, 0);
- /* Copy from file into buffer with invalid tag */
- read_len = read(fd, ptr + ptroff, size);
+
+ /* perform file operation on buffer with invalid tag */
+ switch (test_type) {
+ case READ_TEST:
+ syscall_len = read(fd, ptr + ptroff, size);
+ break;
+ case LAST_TEST:
+ goto usermem_acc_err;
+ }
+
mte_wait_after_trig();
/*
* Accessing user memory in kernel with invalid tag should fail in sync
@@ -85,9 +99,9 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
err = KSFT_FAIL;
goto usermem_acc_err;
}
- if (mode == MTE_SYNC_ERR && read_len < len) {
+ if (mode == MTE_SYNC_ERR && syscall_len < len) {
/* test passed */
- } else if (mode == MTE_ASYNC_ERR && read_len == size) {
+ } else if (mode == MTE_ASYNC_ERR && syscall_len == size) {
/* test passed */
} else {
err = KSFT_FAIL;
@@ -103,14 +117,15 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
}
static int check_usermem_access_fault(int mem_type, int mode, int mapping,
- int tag_offset) {
+ int tag_offset, enum test_type test_type) {
return check_usermem_access_fault_helper(mem_type, mode, mapping,
- tag_offset, 0);
+ tag_offset, 0, test_type);
}
int main(int argc, char *argv[])
{
int err;
+ int t;
page_sz = getpagesize();
if (!page_sz) {
@@ -127,29 +142,31 @@ int main(int argc, char *argv[])
/* Set test plan */
ksft_set_plan(9);
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz),
- "Check memory access from kernel in sync mode, private mapping and mmap memory (tag_offset: page_sz)\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED, page_sz),
- "Check memory access from kernel in sync mode, shared mapping and mmap memory (tag_offset: page_sz)\n");
-
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE, page_sz),
- "Check memory access from kernel in async mode, private mapping and mmap memory (tag_offset: page_sz)\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED, page_sz),
- "Check memory access from kernel in async mode, shared mapping and mmap memory (tag_offset: page_sz)\n");
-
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, MT_GRANULE_SIZE),
- "Check memory access from kernel in sync mode, private mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED, MT_GRANULE_SIZE),
- "Check memory access from kernel in sync mode, shared mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
-
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE, MT_GRANULE_SIZE),
- "Check memory access from kernel in async mode, private mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
- evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED, MT_GRANULE_SIZE),
- "Check memory access from kernel in async mode, shared mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
-
- // In this test, the tag only covers MT_GRANULE_SIZE.
- evaluate_test(check_usermem_access_fault_helper(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, MT_GRANULE_SIZE, MT_GRANULE_SIZE),
- "Check memory access from kernel in sync mode, private mapping and mmap memory (tag_offset: MT_GRANULE_SIZE, tag_len: MT_GRANULE_SIZE)\n");
+ for (t = 0; t < LAST_TEST; t++) {
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz, t),
+ "Check memory access from kernel in sync mode, private mapping and mmap memory (tag_offset: page_sz)\n");
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED, page_sz, t),
+ "Check memory access from kernel in sync mode, shared mapping and mmap memory (tag_offset: page_sz)\n");
+
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE, page_sz, t),
+ "Check memory access from kernel in async mode, private mapping and mmap memory (tag_offset: page_sz)\n");
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED, page_sz, t),
+ "Check memory access from kernel in async mode, shared mapping and mmap memory (tag_offset: page_sz)\n");
+
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, MT_GRANULE_SIZE, t),
+ "Check memory access from kernel in sync mode, private mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED, MT_GRANULE_SIZE, t),
+ "Check memory access from kernel in sync mode, shared mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
+
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE, MT_GRANULE_SIZE, t),
+ "Check memory access from kernel in async mode, private mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
+ evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED, MT_GRANULE_SIZE, t),
+ "Check memory access from kernel in async mode, shared mapping and mmap memory (tag_offset: MT_GRANULE_SIZE)\n");
+
+ // In this test, the tag only covers MT_GRANULE_SIZE.
+ evaluate_test(check_usermem_access_fault_helper(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, MT_GRANULE_SIZE, MT_GRANULE_SIZE, t),
+ "Check memory access from kernel in sync mode, private mapping and mmap memory (tag_offset: MT_GRANULE_SIZE, tag_len: MT_GRANULE_SIZE)\n");
+ }
mte_restore_setup();
ksft_print_cnts();
--
2.17.1
More information about the linux-arm-kernel
mailing list