[PATCH v1 1/7] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len

Joey Gouly joey.gouly at arm.com
Tue Jan 25 07:09:14 PST 2022


These can be used to place a different tag not at a page size boundary.

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>
---
 .../testing/selftests/arm64/mte/check_user_mem.c  | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index 1de7a0abd0ae..3ad9d85ca9b7 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -19,7 +19,8 @@
 
 static size_t page_sz;
 
-static int check_usermem_access_fault(int mem_type, int mode, int mapping)
+static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping,
+                                             int tag_offset, int tag_len)
 {
 	int fd, i, err;
 	char val = 'A';
@@ -54,10 +55,12 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping)
 	if (i < len)
 		goto usermem_acc_err;
 
-	/* Tag the next half of memory with different value */
-	ptr_next = (void *)((unsigned long)ptr + page_sz);
+	if (!tag_len)
+		tag_len = len - tag_offset;
+	/* Tag a part of memory with different value */
+	ptr_next = (void *)((unsigned long)ptr + tag_offset);
 	ptr_next = mte_insert_new_tag(ptr_next);
-	mte_set_tag_address_range(ptr_next, page_sz);
+	mte_set_tag_address_range(ptr_next, tag_len);
 
 	lseek(fd, 0, 0);
 	/* Copy from file into buffer with invalid tag */
@@ -81,6 +84,10 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping)
 	return err;
 }
 
+static int check_usermem_access_fault(int mem_type, int mode, int mapping) {
+	return check_usermem_access_fault_helper(mem_type, mode, mapping, page_sz, 0);
+}
+
 int main(int argc, char *argv[])
 {
 	int err;
-- 
2.17.1




More information about the linux-arm-kernel mailing list