kselftest: arm64/mte: Tests for user-space MTE
v2 cover kselftest: arm64/mte: Tests for user-space MTE
These patch series adds below kselftests to test the user-space support for the ARMv8.5 Memory Tagging Extension present in arm64 tree [1]. This patch series is based on Linux v5.9-rc3.
1) This test-case verifies that the memory allocated by kernel mmap interface can support tagged memory access. It first checks the presence of tags at address[56:59] and then proceeds with read and write. The pass criteria for this test is that tag fault exception should not happen.
2) This test-case crosses the valid memory to the invalid memory. In this memory area valid tags are not inserted so read and write should not pass. The pass criteria for this test is that tag fault exception should happen for all the illegal addresses. This test also verfies that PSTATE.TCO works properly.
3) This test-case verifies that the memory inherited by child process from parent process should have same tags copied. The pass criteria for this test is that tag fault exception should not happen.
4) This test checks different mmap flags with PROT_MTE memory protection.
5) This testcase checks that KSM should not merge pages containing different MTE tag values. However, if the tags are same then the pages may merge. This testcase uses the generic ksm sysfs interfaces to verify the MTE behaviour, so this testcase is not fullproof and may be impacted due to other load in the system.
6) Fifth test verifies that syscalls read/write etc works by considering that user pointer has valid/invalid allocation tags.
Changes since v1 [2]:
* Redefined MTE kernel header definitions to decouple kselftest compilations.
* Removed gmi masking instructions in mte_insert_random_tag assembly function. This simplifies the tag inclusion mask test with only GCR mask register used.
* Created a new mte_insert_random_tag function with gmi instruction. This is useful for the 6th test which reuses the original tag.
* Now use /dev/shm/* to hold temporary files.
* Updated the 6th test to handle the error properly in case of failure in accessing memory with invalid tag in kernel.
* Code and comment clean-ups.
Thanks,
Amit Daniel
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/mte [2]: https://patchwork.kernel.org/patch/11747791/
Amit Daniel Kachhap (6):
kselftest/arm64: Add utilities and a test to validate mte memory kselftest/arm64: Verify mte tag inclusion via prctl kselftest/arm64: Check forked child mte memory accessibility kselftest/arm64: Verify all different mmap MTE options kselftest/arm64: Verify KSM page merge for MTE pages kselftest/arm64: Check mte tagged user address in kernel
tools/testing/selftests/arm64/Makefile | 2 +- tools/testing/selftests/arm64/mte/.gitignore | 6 + tools/testing/selftests/arm64/mte/Makefile | 29 ++ .../selftests/arm64/mte/check_buffer_fill.c | 475 ++++++++++++++++++ .../selftests/arm64/mte/check_child_memory.c | 195 +++++++ .../selftests/arm64/mte/check_ksm_options.c | 159 ++++++ .../selftests/arm64/mte/check_mmap_options.c | 262 ++++++++++ .../arm64/mte/check_tags_inclusion.c | 185 +++++++ .../selftests/arm64/mte/check_user_mem.c | 111 ++++ .../selftests/arm64/mte/mte_common_util.c | 341 +++++++++++++ .../selftests/arm64/mte/mte_common_util.h | 118 +++++ tools/testing/selftests/arm64/mte/mte_def.h | 60 +++ .../testing/selftests/arm64/mte/mte_helper.S | 128 +++++ 13 files changed, 2070 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/mte/.gitignore create mode 100644 tools/testing/selftests/arm64/mte/Makefile create mode 100644 tools/testing/selftests/arm64/mte/check_buffer_fill.c create mode 100644 tools/testing/selftests/arm64/mte/check_child_memory.c create mode 100644 tools/testing/selftests/arm64/mte/check_ksm_options.c create mode 100644 tools/testing/selftests/arm64/mte/check_mmap_options.c create mode 100644 tools/testing/selftests/arm64/mte/check_tags_inclusion.c create mode 100644 tools/testing/selftests/arm64/mte/check_user_mem.c create mode 100644 tools/testing/selftests/arm64/mte/mte_common_util.c create mode 100644 tools/testing/selftests/arm64/mte/mte_common_util.h create mode 100644 tools/testing/selftests/arm64/mte/mte_def.h create mode 100644 tools/testing/selftests/arm64/mte/mte_helper.S
Signature · 1 line
2.17.1
PATCH v2 1/6 kselftest/arm64: Add utilities and a test to validate mte memory
This test checks that the memory tag is present after mte allocation and the memory is accessible with those tags. This testcase verifies all sync, async and none mte error reporting mode. The allocated mte buffers are verified for Allocated range (no error expected while accessing buffer), Underflow range, and Overflow range.
Different test scenarios covered here are,
* Verify that mte memory are accessible at byte/block level.
* Force underflow and overflow to occur and check the data consistency.
* Check to/from between tagged and untagged memory.
* Check that initial allocated memory to have 0 tag.
This change also creates the necessary infrastructure to add mte test cases. MTE kselftests can use the several utility functions provided here to add wide variety of mte test scenarios.
GCC compiler need flag '-march=armv8.5-a+memtag' so those flags are verified before compilation.
The mte testcases can be launched with kselftest framework as,
make TARGETS=arm64 ARM64_SUBTARGETS=mte kselftest
or compiled as,
make -C tools/testing/selftests TARGETS=arm64 ARM64_SUBTARGETS=mte CC='compiler'
---
Changes in v2:
* Redefined MTE kernel header definitions to decouple kselftest compilations.
* Removed gmi masking instructions in mte_insert_random_tag assembly function. This simplifies the tag inclusion mask test with only GCR mask register used.
* Now use /dev/shm/* to hold temporary tmpfs files.
* Few Code and comment clean-ups.
tools/testing/selftests/arm64/Makefile | 2 +- tools/testing/selftests/arm64/mte/.gitignore | 1 + tools/testing/selftests/arm64/mte/Makefile | 29 ++ .../selftests/arm64/mte/check_buffer_fill.c | 475 ++++++++++++++++++ .../selftests/arm64/mte/mte_common_util.c | 341 +++++++++++++ .../selftests/arm64/mte/mte_common_util.h | 117 +++++ tools/testing/selftests/arm64/mte/mte_def.h | 60 +++ .../testing/selftests/arm64/mte/mte_helper.S | 114 +++++ 8 files changed, 1138 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/arm64/mte/.gitignore create mode 100644 tools/testing/selftests/arm64/mte/Makefile create mode 100644 tools/testing/selftests/arm64/mte/check_buffer_fill.c create mode 100644 tools/testing/selftests/arm64/mte/mte_common_util.c create mode 100644 tools/testing/selftests/arm64/mte/mte_common_util.h create mode 100644 tools/testing/selftests/arm64/mte/mte_def.h create mode 100644 tools/testing/selftests/arm64/mte/mte_helper.S
tools/testing/selftests/arm64/Makefile +1 -1
@@ -4,7 +4,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),aarch64 arm64)) -ARM64_SUBTARGETS ?= tags signal +ARM64_SUBTARGETS ?= tags signal mte else ARM64_SUBTARGETS := endif
tools/testing/selftests/arm64/mte/.gitignore new file +1 -0
@@ -0,0 +1 @@ +check_buffer_fill
tools/testing/selftests/arm64/mte/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2020 ARM Limited + +CFLAGS += -std=gnu99 -I. +SRCS := $(filter-out mte_common_util.c,$(wildcard *.c)) +PROGS := $(patsubst %.c,%,$(SRCS)) + +#Add mte compiler option +ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep gcc),) +CFLAGS += -march=armv8.5-a+memtag +endif + +#check if the compiler works well +mte_cc_support := $(shell if ($(CC) $(CFLAGS) -E -x c /dev/null -o /dev/null 2>&1) then echo "1"; fi) + +ifeq ($(mte_cc_support),1) +# Generated binaries to be installed by top KSFT script +TEST_GEN_PROGS := $(PROGS) + +# Get Kernel headers installed and use them. +KSFT_KHDR_INSTALL := 1 +endif + +# Include KSFT lib.mk. +include ../../lib.mk + +ifeq ($(mte_cc_support),1) +$(TEST_GEN_PROGS): mte_common_util.c mte_common_util.h mte_helper.S +endif
tools/testing/selftests/arm64/mte/check_buffer_fill.c new file +475 -0
475 lines not on this page · raw message
tools/testing/selftests/arm64/mte/mte_common_util.c new file +341 -0
341 lines not on this page · raw message
tools/testing/selftests/arm64/mte/mte_common_util.h new file +117 -0
117 lines not on this page · raw message
tools/testing/selftests/arm64/mte/mte_def.h new file +60 -0
60 lines not on this page · raw message
tools/testing/selftests/arm64/mte/mte_helper.S new file +114 -0
114 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 2/6 kselftest/arm64: Verify mte tag inclusion via prctl
In reply to Amit Daniel KachhapThis testcase verifies that the tag generated with "irg" instruction contains only included tags. This is done via prtcl call.
This test covers 4 scenarios,
* At least one included tag.
* More than one included tags.
* All included.
* None included.
---
Changes in v2:
* Small fix to check all tags in check_multiple_included_tags function.
tools/testing/selftests/arm64/mte/.gitignore | 1 + .../arm64/mte/check_tags_inclusion.c | 185 ++++++++++++++++++ 2 files changed, 186 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_tags_inclusion.c
tools/testing/selftests/arm64/mte/.gitignore +1 -0
@@ -1 +1,2 @@ check_buffer_fill +check_tags_inclusion
tools/testing/selftests/arm64/mte/check_tags_inclusion.c new file +185 -0
185 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 3/6 kselftest/arm64: Check forked child mte memory accessibility
In reply to Amit Daniel KachhapThis test covers the mte memory behaviour of the forked process with different mapping properties and flags. It checks that all bytes of forked child memory are accessible with the same tag as that of the parent and memory accessed outside the tag range causes fault to occur.
--- tools/testing/selftests/arm64/mte/.gitignore | 1 + .../selftests/arm64/mte/check_child_memory.c | 195 ++++++++++++++++++ 2 files changed, 196 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_child_memory.c
tools/testing/selftests/arm64/mte/.gitignore +1 -0
@@ -1,2 +1,3 @@ check_buffer_fill check_tags_inclusion +check_child_memory
tools/testing/selftests/arm64/mte/check_child_memory.c new file +195 -0
195 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 4/6 kselftest/arm64: Verify all different mmap MTE options
In reply to Amit Daniel KachhapThis testcase checks the different unsupported/supported options for mmap if used with PROT_MTE memory protection flag. These checks are,
* Either pstate.tco enable or prctl PR_MTE_TCF_NONE option should not cause any tag mismatch faults.
* Different combinations of anonymous/file memory mmap, mprotect, sync/async error mode and private/shared mappings should work.
* mprotect should not be able to clear the PROT_MTE page property.
--- tools/testing/selftests/arm64/mte/.gitignore | 1 + .../selftests/arm64/mte/check_mmap_options.c | 262 ++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_mmap_options.c
tools/testing/selftests/arm64/mte/.gitignore +1 -0
@@ -1,3 +1,4 @@ check_buffer_fill check_tags_inclusion check_child_memory +check_mmap_options
tools/testing/selftests/arm64/mte/check_mmap_options.c new file +262 -0
262 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 5/6 kselftest/arm64: Verify KSM page merge for MTE pages
In reply to Amit Daniel KachhapAdd a testcase to check that KSM should not merge pages containing same data with same/different MTE tag values.
This testcase has one positive tests and passes if page merging happens according to the above rule. It also saves and restores any modified ksm sysfs entries.
---
Changes in v2:
* Moved read/write sysfs functions from global to local functions.
tools/testing/selftests/arm64/mte/.gitignore | 1 + .../selftests/arm64/mte/check_ksm_options.c | 159 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_ksm_options.c
tools/testing/selftests/arm64/mte/.gitignore +1 -0
@@ -2,3 +2,4 @@ check_buffer_fill check_tags_inclusion check_child_memory check_mmap_options +check_ksm_options
tools/testing/selftests/arm64/mte/check_ksm_options.c new file +159 -0
159 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v2 6/6 kselftest/arm64: Check mte tagged user address in kernel
In reply to Amit Daniel KachhapAdd a testcase to check that user address with valid/invalid mte tag works in kernel mode. This test verifies that the kernel API's __arch_copy_from_user/__arch_copy_to_user works by considering if the user pointer has valid/invalid allocation tags.
In MTE sync mode, file memory read/write and other similar interfaces fails if a user memory with invalid tag is accessed in kernel. In async mode no such failure occurs.
---
Changes in v2:
* Updated the test to handle the error properly in case of failure in accessing memory with invalid tag in kernel. errno check is not done now and read length checks are sufficient.
tools/testing/selftests/arm64/mte/.gitignore | 1 + .../selftests/arm64/mte/check_user_mem.c | 111 ++++++++++++++++++ .../selftests/arm64/mte/mte_common_util.h | 1 + .../testing/selftests/arm64/mte/mte_helper.S | 14 +++ 4 files changed, 127 insertions(+) create mode 100644 tools/testing/selftests/arm64/mte/check_user_mem.c
tools/testing/selftests/arm64/mte/.gitignore +1 -0
@@ -3,3 +3,4 @@ check_tags_inclusion check_child_memory check_mmap_options check_ksm_options +check_user_mem
tools/testing/selftests/arm64/mte/check_user_mem.c new file +111 -0
111 lines not on this page · raw message
tools/testing/selftests/arm64/mte/mte_common_util.h +1 -0
@@ -64,6 +64,7 @@ int create_temp_file(void);/* Assembly MTE utility functions */ void *mte_insert_random_tag (void *ptr); +void *mte_insert_new_tag (void *ptr);void *mte_get_tag_address (void *ptr);void mte_set_tag_address_range (void *ptr,int range);void mte_clear_tag_address_range (void *ptr,int range);
tools/testing/selftests/arm64/mte/mte_helper.S +14 -0
@@ -26,6 +26,20 @@ ENTRY(mte_insert_random_tag) ret ENDPROC(mte_insert_random_tag) +/* + * mte_insert_new_tag: Insert new tag and different from the source tag if + * source pointer has it. + * Input: + * x0 - source pointer with a tag/no-tag + * Return: + * x0 - pointer with random tag + */ +ENTRY(mte_insert_new_tag) + gmi x1, x0, xzr + irg x0, x0, x1 + ret +ENDPROC(mte_insert_new_tag) + /* * mte_get_tag_address: Get the tag from given address. * Input:
Signature · 1 line
2.17.1
Quoted 7 lines · Amit Daniel Kachhap
Amit Daniel Kachhap (6):
kselftest/arm64: Add utilities and a test to validate mte memory kselftest/arm64: Verify mte tag inclusion via prctl kselftest/arm64: Check forked child mte memory accessibility kselftest/arm64: Verify all different mmap MTE options kselftest/arm64: Verify KSM page merge for MTE pages kselftest/arm64: Check mte tagged user address in kernel
Thanks Amit for respinning the series. Tested on FVP (some Qemu bugs get in the way and they fail).
Quoted 10 lines · Amit Daniel Kachhap
These patch series adds below kselftests to test the user-space support for the ARMv8.5 Memory Tagging Extension present in arm64 tree [1]. This patch series is based on Linux v5.9-rc3.
1) This test-case verifies that the memory allocated by kernel mmap interface can support tagged memory access. It first checks the presence of tags at address[56:59] and then proceeds with read and write. The pass criteria for this test is that tag fault exception should not happen.
[...]
Applied to arm64 (for-next/late-arrivals), thanks!
[1/6] kselftest/arm64: Add utilities and a test to validate mte memory
https://git.kernel.org/arm64/c/e9b60476bea0 [2/6] kselftest/arm64: Verify mte tag inclusion via prctl https://git.kernel.org/arm64/c/f3b2a26ca78d [3/6] kselftest/arm64: Check forked child mte memory accessibility https://git.kernel.org/arm64/c/dfe537cf4718 [4/6] kselftest/arm64: Verify all different mmap MTE options https://git.kernel.org/arm64/c/53ec81d23213 [5/6] kselftest/arm64: Verify KSM page merge for MTE pages https://git.kernel.org/arm64/c/f981d8fa2646 [6/6] kselftest/arm64: Check mte tagged user address in kernel https://git.kernel.org/arm64/c/4dafc08d0ba4
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev