Skip instead of failing when prerequisite conditions aren't fulfilled,
such as invalid xstate values etc. This patch would make the tests show
as skip when run by:
make -C tools/testing/selftests/ TARGETS=x86 run_tests
...
# timeout set to 45
# selftests: x86: amx_64
# # xstate cpuid: invalid tile data size/offset: 0/0
ok 42 selftests: x86: amx_64 # SKIP
# timeout set to 45
# selftests: x86: lam_64
# # Unsupported LAM feature!
ok 43 selftests: x86: lam_64 # SKIP
...
In amx test, Move away from check_cpuid_xsave() and start using
arch_prctl() to find out if amx support is present or not. In the
kernels where amx isn't present, arch_prctl returns -EINVAL. Hence it is
backward compatible.
Reviewed-by: Chang S. Bae <[email protected]>
Acked-by: Kirill A. Shutemov <[email protected]>
Reviewed-by: Binbin Wu <[email protected]>
Signed-off-by: Muhammad Usama Anjum <[email protected]>
---
Changes since v2:
- Update the changelog
Changes since v1:
- Use arch_prctl to check if amx is supported
---
tools/testing/selftests/x86/amx.c | 27 ++++++++++-----------------
tools/testing/selftests/x86/lam.c | 2 +-
2 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index d884fd69dd510..95aad6d8849be 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -103,21 +103,6 @@ static void clearhandler(int sig)
#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;
@@ -350,6 +335,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
@@ -928,8 +914,15 @@ static void test_ptrace(void)
int main(void)
{
- /* Check hardware availability at first */
- check_cpuid_xsave();
+ unsigned long features;
+ long rc;
+
+ rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
+ if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
+ ksft_print_msg("no AMX support\n");
+ return KSFT_SKIP;
+ }
+
check_cpuid_xtiledata();
init_stashed_xsave();
diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index 215b8150b7cca..c0f016f45ee17 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -1183,7 +1183,7 @@ int main(int argc, char **argv)
if (!cpu_has_lam()) {
ksft_print_msg("Unsupported LAM feature!\n");
- return -1;
+ return KSFT_SKIP;
}
while ((c = getopt(argc, argv, "ht:")) != -1) {
--
2.39.2
On 3/27/24 05:17, Muhammad Usama Anjum wrote:
> Skip instead of failing when prerequisite conditions aren't fulfilled,
> such as invalid xstate values etc. This patch would make the tests show
> as skip when run by:
> make -C tools/testing/selftests/ TARGETS=x86 run_tests
>
> ...
> # timeout set to 45
> # selftests: x86: amx_64
> # # xstate cpuid: invalid tile data size/offset: 0/0
> ok 42 selftests: x86: amx_64 # SKIP
> # timeout set to 45
> # selftests: x86: lam_64
> # # Unsupported LAM feature!
> ok 43 selftests: x86: lam_64 # SKIP
> ...
>
> In amx test, Move away from check_cpuid_xsave() and start using
> arch_prctl() to find out if amx support is present or not. In the
> kernels where amx isn't present, arch_prctl returns -EINVAL. Hence it is
> backward compatible.
>
> Reviewed-by: Chang S. Bae <[email protected]>
> Acked-by: Kirill A. Shutemov <[email protected]>
> Reviewed-by: Binbin Wu <[email protected]>
> Signed-off-by: Muhammad Usama Anjum <[email protected]>
> ---
> Changes since v2:
> - Update the changelog
>
Thank you - applied to linux-kselftest next for 6.10-rc1
thanks,
-- Shuah
* Shuah Khan <[email protected]> wrote:
> On 3/27/24 05:17, Muhammad Usama Anjum wrote:
> > Skip instead of failing when prerequisite conditions aren't fulfilled,
> > such as invalid xstate values etc. This patch would make the tests show
> > as skip when run by:
> > make -C tools/testing/selftests/ TARGETS=x86 run_tests
> >
> > ...
> > # timeout set to 45
> > # selftests: x86: amx_64
> > # # xstate cpuid: invalid tile data size/offset: 0/0
> > ok 42 selftests: x86: amx_64 # SKIP
> > # timeout set to 45
> > # selftests: x86: lam_64
> > # # Unsupported LAM feature!
> > ok 43 selftests: x86: lam_64 # SKIP
> > ...
> >
> > In amx test, Move away from check_cpuid_xsave() and start using
> > arch_prctl() to find out if amx support is present or not. In the
> > kernels where amx isn't present, arch_prctl returns -EINVAL. Hence it is
> > backward compatible.
> >
> > Reviewed-by: Chang S. Bae <[email protected]>
> > Acked-by: Kirill A. Shutemov <[email protected]>
> > Reviewed-by: Binbin Wu <[email protected]>
> > Signed-off-by: Muhammad Usama Anjum <[email protected]>
> > ---
> > Changes since v2:
> > - Update the changelog
> >
>
> Thank you - applied to linux-kselftest next for 6.10-rc1
Please don't, I've applied the patch to tip:x86/cpu with a tidied up
changelog.
Thanks,
Ingo
The following commit has been merged into the x86/cpu branch of tip:
Commit-ID: 99c84311e35f9399bdce666f6306a048e2a5b404
Gitweb: https://git.kernel.org/tip/99c84311e35f9399bdce666f6306a048e2a5b404
Author: Muhammad Usama Anjum <[email protected]>
AuthorDate: Wed, 27 Mar 2024 16:17:17 +05:00
Committer: Ingo Molnar <[email protected]>
CommitterDate: Fri, 29 Mar 2024 08:33:40 +01:00
x86/selftests: Skip the tests if prerequisites aren't fulfilled
Skip instead of failing when prerequisite conditions aren't fulfilled,
such as invalid xstate values etc.
Make the tests show as 'SKIP' when run:
make -C tools/testing/selftests/ TARGETS=x86 run_tests
...
# timeout set to 45
# selftests: x86: amx_64
# # xstate cpuid: invalid tile data size/offset: 0/0
ok 42 selftests: x86: amx_64 # SKIP
# timeout set to 45
# selftests: x86: lam_64
# # Unsupported LAM feature!
ok 43 selftests: x86: lam_64 # SKIP
...
In the AMX test, Move away from check_cpuid_xsave() and start using
arch_prctl() to find out if AMX support is present or not. In the
kernels where AMX isn't present, arch_prctl() returns -EINVAL, hence it is
backward compatible.
Signed-off-by: Muhammad Usama Anjum <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Reviewed-by: Chang S. Bae <[email protected]>
Reviewed-by: Binbin Wu <[email protected]>
Acked-by: Kirill A. Shutemov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
tools/testing/selftests/x86/amx.c | 27 ++++++++++-----------------
tools/testing/selftests/x86/lam.c | 2 +-
2 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c
index d884fd6..95aad6d 100644
--- a/tools/testing/selftests/x86/amx.c
+++ b/tools/testing/selftests/x86/amx.c
@@ -103,21 +103,6 @@ static void clearhandler(int sig)
#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;
@@ -350,6 +335,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
@@ -928,8 +914,15 @@ static void test_ptrace(void)
int main(void)
{
- /* Check hardware availability at first */
- check_cpuid_xsave();
+ unsigned long features;
+ long rc;
+
+ rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
+ if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
+ ksft_print_msg("no AMX support\n");
+ return KSFT_SKIP;
+ }
+
check_cpuid_xtiledata();
init_stashed_xsave();
diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index 215b815..c0f016f 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -1183,7 +1183,7 @@ int main(int argc, char **argv)
if (!cpu_has_lam()) {
ksft_print_msg("Unsupported LAM feature!\n");
- return -1;
+ return KSFT_SKIP;
}
while ((c = getopt(argc, argv, "ht:")) != -1) {
On 3/29/24 01:36, Ingo Molnar wrote:
>
> * Shuah Khan <[email protected]> wrote:
>
>> On 3/27/24 05:17, Muhammad Usama Anjum wrote:
>>> Skip instead of failing when prerequisite conditions aren't fulfilled,
>>> such as invalid xstate values etc. This patch would make the tests show
>>> as skip when run by:
>>> make -C tools/testing/selftests/ TARGETS=x86 run_tests
>>>
>>> ...
>>> # timeout set to 45
>>> # selftests: x86: amx_64
>>> # # xstate cpuid: invalid tile data size/offset: 0/0
>>> ok 42 selftests: x86: amx_64 # SKIP
>>> # timeout set to 45
>>> # selftests: x86: lam_64
>>> # # Unsupported LAM feature!
>>> ok 43 selftests: x86: lam_64 # SKIP
>>> ...
>>>
>>> In amx test, Move away from check_cpuid_xsave() and start using
>>> arch_prctl() to find out if amx support is present or not. In the
>>> kernels where amx isn't present, arch_prctl returns -EINVAL. Hence it is
>>> backward compatible.
>>>
>>> Reviewed-by: Chang S. Bae <[email protected]>
>>> Acked-by: Kirill A. Shutemov <[email protected]>
>>> Reviewed-by: Binbin Wu <[email protected]>
>>> Signed-off-by: Muhammad Usama Anjum <[email protected]>
>>> ---
>>> Changes since v2:
>>> - Update the changelog
>>>
>>
>> Thank you - applied to linux-kselftest next for 6.10-rc1
>
> Please don't, I've applied the patch to tip:x86/cpu with a tidied up
> changelog.
>
Thanks. I will drop it.
thanks,
-- Shuah
* Shuah Khan <[email protected]> wrote:
> On 3/29/24 01:36, Ingo Molnar wrote:
> >
> > * Shuah Khan <[email protected]> wrote:
> >
> > > On 3/27/24 05:17, Muhammad Usama Anjum wrote:
> > > > Skip instead of failing when prerequisite conditions aren't fulfilled,
> > > > such as invalid xstate values etc. This patch would make the tests show
> > > > as skip when run by:
> > > > make -C tools/testing/selftests/ TARGETS=x86 run_tests
> > > >
> > > > ...
> > > > # timeout set to 45
> > > > # selftests: x86: amx_64
> > > > # # xstate cpuid: invalid tile data size/offset: 0/0
> > > > ok 42 selftests: x86: amx_64 # SKIP
> > > > # timeout set to 45
> > > > # selftests: x86: lam_64
> > > > # # Unsupported LAM feature!
> > > > ok 43 selftests: x86: lam_64 # SKIP
> > > > ...
> > > >
> > > > In amx test, Move away from check_cpuid_xsave() and start using
> > > > arch_prctl() to find out if amx support is present or not. In the
> > > > kernels where amx isn't present, arch_prctl returns -EINVAL. Hence it is
> > > > backward compatible.
> > > >
> > > > Reviewed-by: Chang S. Bae <[email protected]>
> > > > Acked-by: Kirill A. Shutemov <[email protected]>
> > > > Reviewed-by: Binbin Wu <[email protected]>
> > > > Signed-off-by: Muhammad Usama Anjum <[email protected]>
> > > > ---
> > > > Changes since v2:
> > > > - Update the changelog
> > > >
> > >
> > > Thank you - applied to linux-kselftest next for 6.10-rc1
> >
> > Please don't, I've applied the patch to tip:x86/cpu with a tidied up
> > changelog.
> >
>
> Thanks. I will drop it.
Thank you!
Ingo