linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 0/7] add more tests to MTE kselftests
@ 2022-01-25 15:09 Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 1/7] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len Joey Gouly
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

This is a series which refactors and then adds some extra tests for MTE
in the kselftest framework.

The issue that these tests are for was was fixed by Robin in
295cf156231c ("arm64: Avoid premature usercopy failure") and based on a
simplified example by Catalin [1].

They test some combinations of pointer offsets, sizes and syscalls to
exercise different paths in the kernel.

Thanks,
Joey

[1] https://lore.kernel.org/all/20210624150911.GA25097@arm.com/

Joey Gouly (7):
  kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len
  kselftest/arm64: mte: user_mem: add tests using tag_offset
  kselftest/arm64: mte: user_mem: add test with mte tag inside a page
  kselftest/arm64: mte: user_mem: rework error handling
  kselftest/arm64: mte: user_mem: check different offsets and sizes
  kselftest/arm64: mte: add test type enum
  kselftest/arm64: mte: add more test types

 .../selftests/arm64/mte/check_user_mem.c      | 145 ++++++++++++++----
 1 file changed, 112 insertions(+), 33 deletions(-)

-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v1 1/7] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 2/7] kselftest/arm64: mte: user_mem: add tests using tag_offset Joey Gouly
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

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

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 2/7] kselftest/arm64: mte: user_mem: add tests using tag_offset
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 1/7] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 3/7] kselftest/arm64: mte: user_mem: add test with mte tag inside a page Joey Gouly
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

Add some tests that place the different tag at MT_GRANULE_SIZE to check
that less than a full page can also be read.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 .../selftests/arm64/mte/check_user_mem.c      | 38 ++++++++++++-------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index 3ad9d85ca9b7..d33b262ccdb0 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -84,8 +84,10 @@ static int check_usermem_access_fault_helper(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);
+static int check_usermem_access_fault(int mem_type, int mode, int mapping,
+                                      int tag_offset) {
+	return check_usermem_access_fault_helper(mem_type, mode, mapping,
+	                                         tag_offset, 0);
 }
 
 int main(int argc, char *argv[])
@@ -105,17 +107,27 @@ int main(int argc, char *argv[])
 	mte_register_signal(SIGSEGV, mte_default_handler);
 
 	/* Set test plan */
-	ksft_set_plan(4);
-
-	evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE),
-		"Check memory access from kernel in sync mode, private mapping and mmap memory\n");
-	evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_SHARED),
-		"Check memory access from kernel in sync mode, shared mapping and mmap memory\n");
-
-	evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_PRIVATE),
-		"Check memory access from kernel in async mode, private mapping and mmap memory\n");
-	evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_ASYNC_ERR, MAP_SHARED),
-		"Check memory access from kernel in async mode, shared mapping and mmap memory\n");
+	ksft_set_plan(8);
+
+	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");
 
 	mte_restore_setup();
 	ksft_print_cnts();
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 3/7] kselftest/arm64: mte: user_mem: add test with mte tag inside a page
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 1/7] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 2/7] kselftest/arm64: mte: user_mem: add tests using tag_offset Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 4/7] kselftest/arm64: mte: user_mem: rework error handling Joey Gouly
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

This new test has a tag that is only a single MT_GRANULE_SIZE large.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 tools/testing/selftests/arm64/mte/check_user_mem.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index d33b262ccdb0..3497960851a9 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
 	mte_register_signal(SIGSEGV, mte_default_handler);
 
 	/* Set test plan */
-	ksft_set_plan(8);
+	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");
@@ -129,6 +129,10 @@ int main(int argc, char *argv[])
 	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");
+
 	mte_restore_setup();
 	ksft_print_cnts();
 	return ksft_get_fail_cnt() == 0 ? KSFT_PASS : KSFT_FAIL;
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 4/7] kselftest/arm64: mte: user_mem: rework error handling
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
                   ` (2 preceding siblings ...)
  2022-01-25 15:09 ` [PATCH v1 3/7] kselftest/arm64: mte: user_mem: add test with mte tag inside a page Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes Joey Gouly
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

This makes it easier to have multiple iterations in the test.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 .../selftests/arm64/mte/check_user_mem.c      | 27 ++++++++++++-------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index 3497960851a9..f54143ec057a 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -27,7 +27,7 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
 	size_t len, read_len;
 	void *ptr, *ptr_next;
 
-	err = KSFT_FAIL;
+	err = KSFT_PASS;
 	len = 2 * page_sz;
 	mte_switch_mode(mode, MTE_ALLOW_NON_ZERO_TAG);
 	fd = create_temp_file();
@@ -46,14 +46,18 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
 	/* Copy from file into buffer with valid tag */
 	read_len = read(fd, ptr, len);
 	mte_wait_after_trig();
-	if (cur_mte_cxt.fault_valid || read_len < len)
+	if (cur_mte_cxt.fault_valid || read_len < len) {
+		err = KSFT_FAIL;
 		goto usermem_acc_err;
+	}
 	/* Verify same pattern is read */
 	for (i = 0; i < len; i++)
 		if (*(char *)(ptr + i) != val)
 			break;
-	if (i < len)
+	if (i < len) {
+		err = KSFT_FAIL;
 		goto usermem_acc_err;
+	}
 
 	if (!tag_len)
 		tag_len = len - tag_offset;
@@ -71,12 +75,17 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
 	 * mode without fault but may not fail in async mode as per the
 	 * implemented MTE userspace support in Arm64 kernel.
 	 */
-	if (mode == MTE_SYNC_ERR &&
-	    !cur_mte_cxt.fault_valid && read_len < len) {
-		err = KSFT_PASS;
-	} else if (mode == MTE_ASYNC_ERR &&
-		   !cur_mte_cxt.fault_valid && read_len == len) {
-		err = KSFT_PASS;
+	if (cur_mte_cxt.fault_valid) {
+		err = KSFT_FAIL;
+		goto usermem_acc_err;
+	}
+	if (mode == MTE_SYNC_ERR && read_len < len) {
+		/* test passed */
+	} else if (mode == MTE_ASYNC_ERR && read_len == len) {
+		/* test passed */
+	} else {
+		err = KSFT_FAIL;
+		goto usermem_acc_err;
 	}
 usermem_acc_err:
 	mte_free_memory((void *)ptr, len, mem_type, true);
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
                   ` (3 preceding siblings ...)
  2022-01-25 15:09 ` [PATCH v1 4/7] kselftest/arm64: mte: user_mem: rework error handling Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  2022-01-25 16:33   ` Mark Brown
  2022-01-25 15:09 ` [PATCH v1 6/7] kselftest/arm64: mte: add test type enum Joey Gouly
  2022-01-25 15:09 ` [PATCH v1 7/7] kselftest/arm64: mte: add more test types Joey Gouly
  6 siblings, 1 reply; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

Iterate over different file offsets, pointer offsets and buffer sizes to exercise
and test different behaviour.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 .../selftests/arm64/mte/check_user_mem.c      | 49 +++++++++++--------
 1 file changed, 29 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index f54143ec057a..8b1b586f3df8 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -26,6 +26,8 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
 	char val = 'A';
 	size_t len, read_len;
 	void *ptr, *ptr_next;
+	int fileoff, ptroff, size;
+	int sizes[] = {1, 2, 3, 8, 16, 32, 4096};
 
 	err = KSFT_PASS;
 	len = 2 * page_sz;
@@ -66,26 +68,33 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
 	ptr_next = mte_insert_new_tag(ptr_next);
 	mte_set_tag_address_range(ptr_next, tag_len);
 
-	lseek(fd, 0, 0);
-	/* Copy from file into buffer with invalid tag */
-	read_len = read(fd, ptr, len);
-	mte_wait_after_trig();
-	/*
-	 * Accessing user memory in kernel with invalid tag should fail in sync
-	 * mode without fault but may not fail in async mode as per the
-	 * implemented MTE userspace support in Arm64 kernel.
-	 */
-	if (cur_mte_cxt.fault_valid) {
-		err = KSFT_FAIL;
-		goto usermem_acc_err;
-	}
-	if (mode == MTE_SYNC_ERR && read_len < len) {
-		/* test passed */
-	} else if (mode == MTE_ASYNC_ERR && read_len == len) {
-		/* test passed */
-	} else {
-		err = KSFT_FAIL;
-		goto usermem_acc_err;
+	for (fileoff = 0; fileoff < 16; fileoff++) {
+		for (ptroff = 0; ptroff < 16; ptroff++) {
+			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);
+				mte_wait_after_trig();
+				/*
+				 * Accessing user memory in kernel with invalid tag should fail in sync
+				 * mode without fault but may not fail in async mode as per the
+				 * implemented MTE userspace support in Arm64 kernel.
+				 */
+				if (cur_mte_cxt.fault_valid) {
+					err = KSFT_FAIL;
+					goto usermem_acc_err;
+				}
+				if (mode == MTE_SYNC_ERR && read_len < len) {
+					/* test passed */
+				} else if (mode == MTE_ASYNC_ERR && read_len == size) {
+					/* test passed */
+				} else {
+					err = KSFT_FAIL;
+					goto usermem_acc_err;
+				}
+			}
+		}
 	}
 usermem_acc_err:
 	mte_free_memory((void *)ptr, len, mem_type, true);
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 6/7] kselftest/arm64: mte: add test type enum
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
                   ` (4 preceding siblings ...)
  2022-01-25 15:09 ` [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  2022-01-26 16:33   ` Mark Brown
  2022-01-25 15:09 ` [PATCH v1 7/7] kselftest/arm64: mte: add more test types Joey Gouly
  6 siblings, 1 reply; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

This enum will be used to parameterise the test to perform other syscalls
than 'read'.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v1 7/7] kselftest/arm64: mte: add more test types
  2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
                   ` (5 preceding siblings ...)
  2022-01-25 15:09 ` [PATCH v1 6/7] kselftest/arm64: mte: add test type enum Joey Gouly
@ 2022-01-25 15:09 ` Joey Gouly
  6 siblings, 0 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-25 15:09 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: broonie, nd, catalin.marinas, joey.gouly, will

Add test support for write, readv, and writev.

Signed-off-by: Joey Gouly <joey.gouly@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
---
 .../selftests/arm64/mte/check_user_mem.c      | 23 ++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/arm64/mte/check_user_mem.c b/tools/testing/selftests/arm64/mte/check_user_mem.c
index d104feab4e86..df4c8d8c9c17 100644
--- a/tools/testing/selftests/arm64/mte/check_user_mem.c
+++ b/tools/testing/selftests/arm64/mte/check_user_mem.c
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <ucontext.h>
 #include <unistd.h>
+#include <sys/uio.h>
 #include <sys/mman.h>
 
 #include "kselftest.h"
@@ -21,6 +22,9 @@ static size_t page_sz;
 
 enum test_type {
 	READ_TEST,
+	WRITE_TEST,
+	READV_TEST,
+	WRITEV_TEST,
 	LAST_TEST,
 };
 
@@ -85,6 +89,23 @@ static int check_usermem_access_fault_helper(int mem_type, int mode, int mapping
 				case READ_TEST:
 					syscall_len = read(fd, ptr + ptroff, size);
 					break;
+				case WRITE_TEST:
+					syscall_len = write(fd, ptr + ptroff, size);
+					break;
+				case READV_TEST: {
+					struct iovec iov[1];
+					iov[0].iov_base = ptr + ptroff;
+					iov[0].iov_len = size;
+					syscall_len = readv(fd, iov, 1);
+					break;
+				}
+				case WRITEV_TEST: {
+					struct iovec iov[1];
+					iov[0].iov_base = ptr + ptroff;
+					iov[0].iov_len = size;
+					syscall_len = writev(fd, iov, 1);
+					break;
+				}
 				case LAST_TEST:
 					goto usermem_acc_err;
 				}
@@ -140,7 +161,7 @@ int main(int argc, char *argv[])
 	mte_register_signal(SIGSEGV, mte_default_handler);
 
 	/* Set test plan */
-	ksft_set_plan(9);
+	ksft_set_plan(36);
 
 	for (t = 0; t < LAST_TEST; t++) {
 		evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz, t),
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes
  2022-01-25 15:09 ` [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes Joey Gouly
@ 2022-01-25 16:33   ` Mark Brown
  2022-01-26 12:27     ` Joey Gouly
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Brown @ 2022-01-25 16:33 UTC (permalink / raw)
  To: Joey Gouly; +Cc: linux-arm-kernel, nd, catalin.marinas, will


[-- Attachment #1.1: Type: text/plain, Size: 280 bytes --]

On Tue, Jan 25, 2022 at 03:09:18PM +0000, Joey Gouly wrote:

> +	int fileoff, ptroff, size;
> +	int sizes[] = {1, 2, 3, 8, 16, 32, 4096};

Assuming the goal is to go up to PAGE_SIZE might it be worth extending
this to cover the case where the kernel has been built for 64K pages?

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes
  2022-01-25 16:33   ` Mark Brown
@ 2022-01-26 12:27     ` Joey Gouly
  0 siblings, 0 replies; 11+ messages in thread
From: Joey Gouly @ 2022-01-26 12:27 UTC (permalink / raw)
  To: Mark Brown; +Cc: linux-arm-kernel, nd, catalin.marinas, will

On Tue, Jan 25, 2022 at 04:33:12PM +0000, Mark Brown wrote:
> On Tue, Jan 25, 2022 at 03:09:18PM +0000, Joey Gouly wrote:
> 
> > +	int fileoff, ptroff, size;
> > +	int sizes[] = {1, 2, 3, 8, 16, 32, 4096};
> 
> Assuming the goal is to go up to PAGE_SIZE might it be worth extending
> this to cover the case where the kernel has been built for 64K pages?

Good idea, I will do that for v2 (and 16K).

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v1 6/7] kselftest/arm64: mte: add test type enum
  2022-01-25 15:09 ` [PATCH v1 6/7] kselftest/arm64: mte: add test type enum Joey Gouly
@ 2022-01-26 16:33   ` Mark Brown
  0 siblings, 0 replies; 11+ messages in thread
From: Mark Brown @ 2022-01-26 16:33 UTC (permalink / raw)
  To: Joey Gouly; +Cc: linux-arm-kernel, nd, catalin.marinas, will


[-- Attachment #1.1: Type: text/plain, Size: 900 bytes --]

On Tue, Jan 25, 2022 at 03:09:19PM +0000, Joey Gouly wrote:

> This enum will be used to parameterise the test to perform other syscalls
> than 'read'.

> -	evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz),

> +	for (t = 0; t < LAST_TEST; t++) {
> +		evaluate_test(check_usermem_access_fault(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, page_sz, t),

I appreciate that the lines were already over 80 columns here but
between the extra parameter and the extra indentation we're getting some
very long lines here.  Some line breaks wouldn't go amiss?

Alternatively I wonder if it wouldn't be better to restructure this so
that the list of tests is stored in a data structure, or indeed it looks
like as well as the enum for syscalls we could also be generating the
various combinations of shared/private, sync/async and tag offsets.
That seems more maintainable overall.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-01-26 17:20 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-25 15:09 [PATCH v1 0/7] add more tests to MTE kselftests Joey Gouly
2022-01-25 15:09 ` [PATCH v1 1/7] kselftest/arm64: mte: user_mem: introduce tag_offset and tag_len Joey Gouly
2022-01-25 15:09 ` [PATCH v1 2/7] kselftest/arm64: mte: user_mem: add tests using tag_offset Joey Gouly
2022-01-25 15:09 ` [PATCH v1 3/7] kselftest/arm64: mte: user_mem: add test with mte tag inside a page Joey Gouly
2022-01-25 15:09 ` [PATCH v1 4/7] kselftest/arm64: mte: user_mem: rework error handling Joey Gouly
2022-01-25 15:09 ` [PATCH v1 5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes Joey Gouly
2022-01-25 16:33   ` Mark Brown
2022-01-26 12:27     ` Joey Gouly
2022-01-25 15:09 ` [PATCH v1 6/7] kselftest/arm64: mte: add test type enum Joey Gouly
2022-01-26 16:33   ` Mark Brown
2022-01-25 15:09 ` [PATCH v1 7/7] kselftest/arm64: mte: add more test types Joey Gouly

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).