diff mbox series

[v1,5/7] kselftest/arm64: mte: user_mem: check different offsets and sizes

Message ID 20220125150920.23955-6-joey.gouly@arm.com (mailing list archive)
State New, archived
Headers show
Series add more tests to MTE kselftests | expand

Commit Message

Joey Gouly Jan. 25, 2022, 3:09 p.m. UTC
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(-)

Comments

Mark Brown Jan. 25, 2022, 4:33 p.m. UTC | #1
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?
Joey Gouly Jan. 26, 2022, 12:27 p.m. UTC | #2
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).
diff mbox series

Patch

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);