From: "Chang S. Bae" <chang.seok.bae@intel.com>
To: linux-kselftest@vger.kernel.org, shuah@kernel.org,
linux-kernel@vger.kernel.org
Cc: dave.hansen@linux.intel.com, tglx@linutronix.de, bp@suse.de,
chang.seok.bae@intel.com
Subject: [PATCH v2 2/2] selftests/x86/amx: Fix the test to avoid failure when AMX is unavailable
Date: Mon, 11 Jul 2022 10:03:30 -0700 [thread overview]
Message-ID: <20220711170330.27138-3-chang.seok.bae@intel.com> (raw)
In-Reply-To: <20220711170330.27138-1-chang.seok.bae@intel.com>
When a CPU does not have AMX, the test fails. But this is wrong as it
should be runnable regardless. Skip the test instead.
Also, simplify the feature check using arch_prctl() instead of CPUID. The
syscall is more trustworthy as the kernel controls the feature permission.
Reported-by: Thomas Gleixner <tglx@linutronix.de>
Fixes: 6a3e0651b4a ("selftests/x86/amx: Add test cases for AMX state management")
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Cc: linux-kselftest@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Changes from v1:
* Simplify the feature check code (Shuah Khan).
---
tools/testing/selftests/x86/amx.c | 31 ++++++++++---------------------
1 file changed, 10 insertions(+), 21 deletions(-)
diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index 625e42901237..52e7dec50018 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -99,24 +99,6 @@ static void clearhandler(int sig)
#define XFEATURE_MASK_XTILEDATA (1 << XFEATURE_XTILEDATA)
#define XFEATURE_MASK_XTILE (XFEATURE_MASK_XTILECFG | XFEATURE_MASK_XTILEDATA)
-#define CPUID_LEAF1_ECX_XSAVE_MASK (1 << 26)
-#define CPUID_LEAF1_ECX_OSXSAVE_MASK (1 << 27)
-static inline void check_cpuid_xsave(void)
-{
- uint32_t eax, ebx, ecx, edx;
-
- /*
- * CPUID.1:ECX.XSAVE[bit 26] enumerates general
- * support for the XSAVE feature set, including
- * XGETBV.
- */
- __cpuid_count(1, 0, eax, ebx, ecx, edx);
- if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK))
- fatal_error("cpuid: no CPU xsave support");
- if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK))
- fatal_error("cpuid: no OS xsave support");
-}
-
static uint32_t xbuf_size;
static struct {
@@ -348,6 +330,7 @@ enum expected_result { FAIL_EXPECTED, SUCCESS_EXPECTED };
/* arch_prctl() and sigaltstack() test */
+#define ARCH_GET_XCOMP_SUPP 0x1021
#define ARCH_GET_XCOMP_PERM 0x1022
#define ARCH_REQ_XCOMP_PERM 0x1023
@@ -828,10 +811,16 @@ static void test_context_switch(void)
int main(void)
{
- /* Check hardware availability at first */
- check_cpuid_xsave();
- check_cpuid_xtiledata();
+ unsigned long features;
+ long rc;
+ rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
+ if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
+ printf("[SKIP]\tno AMX support.\n");
+ exit(KSFT_FAIL);
+ }
+
+ check_cpuid_xtiledata();
init_stashed_xsave();
sethandler(SIGILL, handle_noperm, 0);
--
2.17.1
next prev parent reply other threads:[~2022-07-11 17:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 17:03 [PATCH v2 0/2] selftests/x86: AMX-related test improvements Chang S. Bae
2022-07-11 17:03 ` [PATCH v2 1/2] selftests/x86/signal: Adjust the test to the kernel's altstack check Chang S. Bae
2022-07-11 17:03 ` Chang S. Bae [this message]
2023-03-30 23:35 ` [PATCH v3 0/3] selftests/x86: AMX-related test improvements Chang S. Bae
2023-03-30 23:35 ` [PATCH v3 1/3] selftests/x86/sigaltstack: Adjust the test to the kernel's altstack check Chang S. Bae
2023-03-30 23:35 ` [PATCH v3 2/3] selftests/x86/amx: Fix the test to avoid failure when AMX is unavailable Chang S. Bae
2023-03-30 23:35 ` [PATCH v3 3/3] selftests/x86/amx: Remove unneeded code Chang S. Bae
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=20220711170330.27138-3-chang.seok.bae@intel.com \
--to=chang.seok.bae@intel.com \
--cc=bp@suse.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox