All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Will Deacon <will@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Shuah Khan <shuah@kernel.org>
Cc: Amit Daniel Kachhap <amit.kachhap@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH 06/11] kselftest/arm64: mte: Fix MTE feature detection
Date: Fri, 19 Mar 2021 16:53:29 +0000	[thread overview]
Message-ID: <20210319165334.29213-7-andre.przywara@arm.com> (raw)
In-Reply-To: <20210319165334.29213-1-andre.przywara@arm.com>

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

diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c
index 4e887dad762d..aa8a8a6b8b6d 100644
--- a/tools/testing/selftests/arm64/mte/mte_common_util.c
+++ b/tools/testing/selftests/arm64/mte/mte_common_util.c
@@ -291,22 +291,13 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask)
 	return 0;
 }
 
-#define ID_AA64PFR1_MTE_SHIFT		8
-#define ID_AA64PFR1_MTE			2
-
 int mte_default_setup(void)
 {
-	unsigned long hwcaps = getauxval(AT_HWCAP);
+	unsigned long hwcaps2 = getauxval(AT_HWCAP2);
 	unsigned long en = 0;
 	int ret;
 
-	if (!(hwcaps & HWCAP_CPUID)) {
-		ksft_print_msg("FAIL: CPUID registers unavailable\n");
-		return KSFT_FAIL;
-	}
-	/* Read ID_AA64PFR1_EL1 register */
-	asm volatile("mrs %0, id_aa64pfr1_el1" : "=r"(hwcaps) : : "memory");
-	if (((hwcaps >> ID_AA64PFR1_MTE_SHIFT) & MT_TAG_MASK) != ID_AA64PFR1_MTE) {
+	if (!(hwcaps2 & HWCAP2_MTE)) {
 		ksft_print_msg("FAIL: MTE features unavailable\n");
 		return KSFT_SKIP;
 	}
-- 
2.17.5


WARNING: multiple messages have this Message-ID (diff)
From: Andre Przywara <andre.przywara@arm.com>
To: Will Deacon <will@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Shuah Khan <shuah@kernel.org>
Cc: Amit Daniel Kachhap <amit.kachhap@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Vincenzo Frascino <vincenzo.frascino@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kselftest@vger.kernel.org
Subject: [PATCH 06/11] kselftest/arm64: mte: Fix MTE feature detection
Date: Fri, 19 Mar 2021 16:53:29 +0000	[thread overview]
Message-ID: <20210319165334.29213-7-andre.przywara@arm.com> (raw)
In-Reply-To: <20210319165334.29213-1-andre.przywara@arm.com>

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

diff --git a/tools/testing/selftests/arm64/mte/mte_common_util.c b/tools/testing/selftests/arm64/mte/mte_common_util.c
index 4e887dad762d..aa8a8a6b8b6d 100644
--- a/tools/testing/selftests/arm64/mte/mte_common_util.c
+++ b/tools/testing/selftests/arm64/mte/mte_common_util.c
@@ -291,22 +291,13 @@ int mte_switch_mode(int mte_option, unsigned long incl_mask)
 	return 0;
 }
 
-#define ID_AA64PFR1_MTE_SHIFT		8
-#define ID_AA64PFR1_MTE			2
-
 int mte_default_setup(void)
 {
-	unsigned long hwcaps = getauxval(AT_HWCAP);
+	unsigned long hwcaps2 = getauxval(AT_HWCAP2);
 	unsigned long en = 0;
 	int ret;
 
-	if (!(hwcaps & HWCAP_CPUID)) {
-		ksft_print_msg("FAIL: CPUID registers unavailable\n");
-		return KSFT_FAIL;
-	}
-	/* Read ID_AA64PFR1_EL1 register */
-	asm volatile("mrs %0, id_aa64pfr1_el1" : "=r"(hwcaps) : : "memory");
-	if (((hwcaps >> ID_AA64PFR1_MTE_SHIFT) & MT_TAG_MASK) != ID_AA64PFR1_MTE) {
+	if (!(hwcaps2 & HWCAP2_MTE)) {
 		ksft_print_msg("FAIL: MTE features unavailable\n");
 		return KSFT_SKIP;
 	}
-- 
2.17.5


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

  parent reply	other threads:[~2021-03-19 16:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-19 16:53 [PATCH 00/11] kselftest/arm64: mte: Fix feature detection and compilation Andre Przywara
2021-03-19 16:53 ` Andre Przywara
2021-03-19 16:53 ` [PATCH 01/11] kselftest/arm64: mte: Fix compilation with native compiler Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 17:29   ` Nick Desaulniers
2021-03-19 17:29     ` Nick Desaulniers
2021-03-19 16:53 ` [PATCH 02/11] kselftest/arm64: mte: Fix pthread linking Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` [PATCH 03/11] kselftest/arm64: mte: ksm_options: Fix fscanf warning Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` [PATCH 04/11] kselftest/arm64: mte: user_mem: Fix write() warning Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` [PATCH 05/11] kselftest/arm64: mte: common: Fix write() warnings Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` Andre Przywara [this message]
2021-03-19 16:53   ` [PATCH 06/11] kselftest/arm64: mte: Fix MTE feature detection Andre Przywara
2021-03-19 16:53 ` [PATCH 07/11] kselftest/arm64: mte: Use cross-compiler if specified Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` [PATCH 08/11] kselftest/arm64: mte: Output warning about failing compiler Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` [PATCH 09/11] kselftest/arm64: mte: Makefile: Fix clang compilation Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 16:53 ` [PATCH 10/11] kselftest/arm64: mte: Fix clang warning Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 17:36   ` Nick Desaulniers
2021-03-19 17:36     ` Nick Desaulniers
2021-03-19 16:53 ` [PATCH 11/11] kselftest/arm64: mte: Report filename on failing temp file creation Andre Przywara
2021-03-19 16:53   ` Andre Przywara
2021-03-19 17:12 ` [PATCH 00/11] kselftest/arm64: mte: Fix feature detection and compilation Mark Brown
2021-03-19 17:12   ` Mark Brown
2021-03-23 17:54 ` Catalin Marinas
2021-03-23 17:54   ` Catalin Marinas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210319165334.29213-7-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=amit.kachhap@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=vincenzo.frascino@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.