From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:55:26
When trying to run the arm64 MTE (Memory Tagging Extension) selftests
on a model with the new FEAT_MTE3 capability, the MTE feature detection
failed, because it was overzealously checking for one exact feature
version only (0b0010). Trying to fix that (patch 06/11) led me into the
rabbit hole of userland tool compilation, which triggered patches
01-05/11, to let me actually compile the selftests on an arm64
machine running Ubuntu 20.04. Before I actually fixed that, I tried some
other compiler and distro; patches 07 and 08 are my witnesses.
Then I got brave and tried clang: entering patches 09/11 and 10/11.
Eventually I tried to run the whole thing on that model again, and,
you guessed it, patch 11/11 concludes this apparent "2 minute job".
Eventually I can now compile the mte selftests on Ubuntu 20.04 with both
the native gcc and clang without warnings, also with some custom made
cross compiler. And they even run now!
Please have a look, also you may try to compile it on your setup, if you
feel adventurous:
$ make -C tools/testing/selftests TARGETS=arm64 ARM64_SUBTARGETS=mte
Cheers,
Andre
Andre Przywara (11):
kselftest/arm64: mte: Fix compilation with native compiler
kselftest/arm64: mte: Fix pthread linking
kselftest/arm64: mte: ksm_options: Fix fscanf warning
kselftest/arm64: mte: user_mem: Fix write() warning
kselftest/arm64: mte: common: Fix write() warnings
kselftest/arm64: mte: Fix MTE feature detection
kselftest/arm64: mte: Use cross-compiler if specified
kselftest/arm64: mte: Output warning about failing compiler
kselftest/arm64: mte: Makefile: Fix clang compilation
kselftest/arm64: mte: Fix clang warning
kselftest/arm64: mte: Report filename on failing temp file creation
tools/testing/selftests/arm64/mte/Makefile | 15 +++++--
.../selftests/arm64/mte/check_ksm_options.c | 5 ++-
.../selftests/arm64/mte/check_user_mem.c | 3 +-
.../selftests/arm64/mte/mte_common_util.c | 39 +++++++++++--------
4 files changed, 39 insertions(+), 23 deletions(-)
--
2.17.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:55:23
The mte selftest Makefile contains a check for GCC, to add the memtag
-march flag to the compiler options. This check fails if the compiler
is not explicitly specified, so reverts to the standard "cc", in which
case --version doesn't mention the "gcc" string we match against:
$ cc --version | head -n 1
cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
This will not add the -march switch to the command line, so compilation
fails:
mte_helper.S: Assembler messages:
mte_helper.S:25: Error: selected processor does not support `irg x0,x0,xzr'
mte_helper.S:38: Error: selected processor does not support `gmi x1,x0,xzr'
...
Actually clang accepts the same -march option as well, so we can just
drop this check and add this unconditionally to the command line, to avoid
any future issues with this check altogether (gcc actually prints
basename(argv[0]) when called with --version).
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/Makefile | 2 --
1 file changed, 2 deletions(-)
From: Nick Desaulniers <ndesaulniers@google.com> Date: 2021-03-19 17:31:38
On Fri, Mar 19, 2021 at 9:53 AM Andre Przywara [off-list ref] wrote:
The mte selftest Makefile contains a check for GCC, to add the memtag
-march flag to the compiler options. This check fails if the compiler
is not explicitly specified, so reverts to the standard "cc", in which
case --version doesn't mention the "gcc" string we match against:
$ cc --version | head -n 1
cc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
This will not add the -march switch to the command line, so compilation
fails:
mte_helper.S: Assembler messages:
mte_helper.S:25: Error: selected processor does not support `irg x0,x0,xzr'
mte_helper.S:38: Error: selected processor does not support `gmi x1,x0,xzr'
...
Actually clang accepts the same -march option as well, so we can just
drop this check and add this unconditionally to the command line, to avoid
any future issues with this check altogether (gcc actually prints
basename(argv[0]) when called with --version).
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:55:38
The GCC manual suggests to use -pthread, when linking with the PThread
library, also to add this switch to both the compilation and linking
stages.
Do as the manual says, to fix compilation with Ubuntu's 20.04 toolchain,
which was getting -lpthread too early on the command line:
------------
/usr/bin/ld: /tmp/cc5zbo2A.o: in function `execute_test':
tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c:86:
undefined reference to `pthread_create'
/usr/bin/ld: tools/testing/selftests/arm64/mte/check_gcr_el1_cswitch.c:90:
undefined reference to `pthread_join'
------------
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/Makefile | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:55:41
Out of the box Ubuntu's 20.04 compiler warns about missing return value
checks for write() (sys)calls.
Make GCC happy by checking whether we actually managed to write "val".
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/check_user_mem.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
@@ -33,7 +33,8 @@ static int check_usermem_access_fault(int mem_type, int mode, int mapping)if(fd==-1)returnKSFT_FAIL;for(i=0;i<len;i++)-write(fd,&val,sizeof(val));+if(write(fd,&val,sizeof(val))!=sizeof(val))+returnKSFT_FAIL;lseek(fd,0,0);ptr=mte_allocate_memory(len,mem_type,mapping,true);if(check_allocated_memory(ptr,len,mem_type,true)!=KSFT_PASS){
--
2.17.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:55:58
Out of the box Ubuntu's 20.04 compiler warns about missing return value
checks for fscanf() calls.
Make GCC happy by checking whether we actually parsed one integer.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/check_ksm_options.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:56:04
To check whether the CPU and kernel support the MTE features we want
to test, we use an (emulated) CPU ID register read. However we only
check against a very particular feature version (0b0010), even though
the ARM ARM promises ID register features to be backwards compatible.
While this could be fixed by using ">=" instead of "==", we should
actually use the explicit HWCAP2_MTE hardware capability, exposed by the
kernel via the ELF auxiliary vectors.
That moves this responsibility to the kernel, and fixes running the
tests on machines with FEAT_MTE3 capability.
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/mte_common_util.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:56:21
Out of the box Ubuntu's 20.04 compiler warns about missing return value
checks for write() (sys)calls.
Make GCC happy by checking whether we actually managed to write out our
buffer.
Reviewed-by: Andre Przywara <andre.przywara@arm.com>
---
.../selftests/arm64/mte/mte_common_util.c | 23 +++++++++++++++----
1 file changed, 18 insertions(+), 5 deletions(-)
@@ -181,10 +181,17 @@ void *mte_allocate_file_memory(size_t size, int mem_type, int mapping, bool tags}/* Initialize the file for mappable size */lseek(fd,0,SEEK_SET);-for(index=INIT_BUFFER_SIZE;index<size;index+=INIT_BUFFER_SIZE)-write(fd,buffer,INIT_BUFFER_SIZE);+for(index=INIT_BUFFER_SIZE;index<size;index+=INIT_BUFFER_SIZE){+if(write(fd,buffer,INIT_BUFFER_SIZE)!=INIT_BUFFER_SIZE){+perror("initialising buffer");+returnNULL;+}+}index-=INIT_BUFFER_SIZE;-write(fd,buffer,size-index);+if(write(fd,buffer,size-index)!=size-index){+perror("initialising buffer");+returnNULL;+}return__mte_allocate_memory_range(size,mem_type,mapping,0,0,tags,fd);}
@@ -202,9 +209,15 @@ void *mte_allocate_file_memory_tag_range(size_t size, int mem_type, int mapping,/* Initialize the file for mappable size */lseek(fd,0,SEEK_SET);for(index=INIT_BUFFER_SIZE;index<map_size;index+=INIT_BUFFER_SIZE)-write(fd,buffer,INIT_BUFFER_SIZE);+if(write(fd,buffer,INIT_BUFFER_SIZE)!=INIT_BUFFER_SIZE){+perror("initialising buffer");+returnNULL;+}index-=INIT_BUFFER_SIZE;-write(fd,buffer,map_size-index);+if(write(fd,buffer,map_size-index)!=map_size-index){+perror("initialising buffer");+returnNULL;+}return__mte_allocate_memory_range(size,mem_type,mapping,range_before,range_after,true,fd);}
--
2.17.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:56:39
At the moment we either need to provide CC explicitly, or use a native
machine to get the ARM64 MTE selftest compiled.
It seems useful to use the same (cross-)compiler as we use for the
kernel, so copy the recipe we use in the pauth selftest.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/Makefile | 5 +++++
1 file changed, 5 insertions(+)
@@ -1,6 +1,11 @@# SPDX-License-Identifier: GPL-2.0# Copyright (C) 2020 ARM Limited+# preserve CC value from top level Makefile+ifeq ($(CC),cc)+CC:=$(CROSS_COMPILE)gcc+endif+CFLAGS+=-std=gnu99-I.-pthreadLDFLAGS+=-pthreadSRCS:=$(filter-outmte_common_util.c,$(wildcard*.c))
--
2.17.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:56:51
When clang finds a header file on the command line, it wants to
precompile that, which would end up in a separate output file.
Specifying -o on that same command line collides with that effort, so
the compiler complains:
clang: error: cannot specify -o when generating multiple output files
Since we are not really after a precompiled header, just drop the header
file from the command line, by removing it from the list of source
files in the Makefile.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/Makefile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:57:07
At the moment we check the compiler's ability to compile MTE enabled
code, but guard all the Makefile rules by it. As a consequence a broken
or not capable compiler just doesn't do anything, and make happily
returns without any error message, but with no programs created.
Since the MTE feature is only supported by recent aarch64 compilers (not
all stable distro compilers support it), having an explicit message
seems like a good idea. To not break building multiple targets, we let
make proceed without errors.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/Makefile | 3 +++
1 file changed, 3 insertions(+)
@@ -23,6 +23,9 @@ TEST_GEN_PROGS := $(PROGS)# Get Kernel headers installed and use them.KSFT_KHDR_INSTALL:=1+else+$(warningcompiler"$(CC)"doesnotsupporttheARMv8.5MTEextension.)+$(warningtestprogram"mte"willnotbecreated.)endif# Include KSFT lib.mk.
--
2.17.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:57:19
if (!prctl(...) == 0) is not only cumbersome to read, it also upsets
clang and triggers a warning:
------------
mte_common_util.c:287:6: warning: logical not is only applied to the
left hand side of this comparison [-Wlogical-not-parentheses]
....
Fix that by just comparing against "not 0" instead.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/mte_common_util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Nick Desaulniers <ndesaulniers@google.com> Date: 2021-03-19 17:38:16
On Fri, Mar 19, 2021 at 9:53 AM Andre Przywara [off-list ref] wrote:
quoted hunk
if (!prctl(...) == 0) is not only cumbersome to read, it also upsets
clang and triggers a warning:
------------
mte_common_util.c:287:6: warning: logical not is only applied to the
left hand side of this comparison [-Wlogical-not-parentheses]
....
Fix that by just comparing against "not 0" instead.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/mte_common_util.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
From: Andre Przywara <andre.przywara@arm.com> Date: 2021-03-19 16:57:32
The MTE selftests create temporary files in /dev/shm, for later mmap-ing
them. When there is no tmpfs mounted on /dev/shm, or /dev/shm does not
exist in the first place (on minimal filesystems), the error message is
not giving good hints:
# FAIL: Unable to open temporary file
# FAIL: memory allocation
not ok 17 Check initial tags with private mapping, ...
Add a perror() call, that gives both the filename and the actual error
reason, so that users get a chance of correcting that.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
tools/testing/selftests/arm64/mte/mte_common_util.c | 1 +
1 file changed, 1 insertion(+)
@@ -337,6 +337,7 @@ int create_temp_file(void)/* Create a file in the tmpfs filesystem */fd=mkstemp(&filename[0]);if(fd==-1){+perror(filename);ksft_print_msg("FAIL: Unable to open temporary file\n");return0;}
--
2.17.5
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
From: Mark Brown <broonie@kernel.org> Date: 2021-03-19 17:14:27
On Fri, Mar 19, 2021 at 04:53:23PM +0000, Andre Przywara wrote:
When trying to run the arm64 MTE (Memory Tagging Extension) selftests
on a model with the new FEAT_MTE3 capability, the MTE feature detection
failed, because it was overzealously checking for one exact feature
version only (0b0010). Trying to fix that (patch 06/11) led me into the
rabbit hole of userland tool compilation, which triggered patches
On Fri, 19 Mar 2021 16:53:23 +0000, Andre Przywara wrote:
When trying to run the arm64 MTE (Memory Tagging Extension) selftests
on a model with the new FEAT_MTE3 capability, the MTE feature detection
failed, because it was overzealously checking for one exact feature
version only (0b0010). Trying to fix that (patch 06/11) led me into the
rabbit hole of userland tool compilation, which triggered patches
01-05/11, to let me actually compile the selftests on an arm64
machine running Ubuntu 20.04. Before I actually fixed that, I tried some
other compiler and distro; patches 07 and 08 are my witnesses.
Then I got brave and tried clang: entering patches 09/11 and 10/11.
Eventually I tried to run the whole thing on that model again, and,
you guessed it, patch 11/11 concludes this apparent "2 minute job".
[...]