Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] x86/selftests: Skip the tests if prerequisites aren't fulfilled#835

Merged
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
Avenger-285714:selftests_amx_64
Jun 2, 2025
Merged

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] x86/selftests: Skip the tests if prerequisites aren't fulfilled#835
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
Avenger-285714:selftests_amx_64

Conversation

@Avenger-285714
Copy link
Copy Markdown
Member

@Avenger-285714 Avenger-285714 commented Jun 2, 2025

commit 99c8431 upstream.

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.

Reviewed-by: Chang S. Bae chang.seok.bae@intel.com
Reviewed-by: Binbin Wu binbin.wu@linux.intel.com
Acked-by: Kirill A. Shutemov kirill.shutemov@linux.intel.com
Link: https://lore.kernel.org/r/20240327111720.3509180-1-usama.anjum@collabora.com
[ Zelin Deng: ANBZ: #8853 ]
Link: https://gitee.com/anolis/cloud-kernel/pulls/3125

[ WangYuli: Edit commit msg. ]
[ Backport from v6.9 ]

Summary by Sourcery

Update x86 selftests to skip AMX and LAM tests when hardware or OS support is missing instead of failing.

Enhancements:

  • Return KSFT_SKIP in AMX and LAM selftests when the corresponding CPU feature is unavailable
  • Replace cpuid-based AMX detection with an arch_prctl syscall to check XFEATURE_MASK_XTILE support

commit 99c8431 upstream.

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 <usama.anjum@collabora.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Chang S. Bae <chang.seok.bae@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@linux.intel.com>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Link: https://lore.kernel.org/r/20240327111720.3509180-1-usama.anjum@collabora.com
[ Zelin Deng: ANBZ: #8853 ]
Link: https://gitee.com/anolis/cloud-kernel/pulls/3125
Signed-off-by: Zelin Deng <zelin.deng@linux.alibaba.com>
[ WangYuli: Edit commit msg. ]
[ Backport from v6.9 ]
Signed-off-by: WangYuli <wangyuli@uniontech.com>
@Avenger-285714 Avenger-285714 requested a review from Copilot June 2, 2025 00:20
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Jun 2, 2025

Reviewer's Guide

Updates x86 selftests to skip rather than fail when prerequisites aren’t met: AMX tests now use arch_prctl for feature detection and return KSFT_SKIP if AMX is unavailable; LAM tests similarly return KSFT_SKIP when unsupported.

Sequence Diagram for AMX Test Feature Detection Logic

sequenceDiagram
    participant TestRunner
    participant AMXTest as "amx.c main()"
    participant Kernel

    TestRunner->>AMXTest: Execute test
    AMXTest->>Kernel: syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features)
    Kernel-->>AMXTest: rc, features
    alt AMX not supported (rc != 0 or features & XFEATURE_MASK_XTILE != XFEATURE_MASK_XTILE)
        AMXTest->>AMXTest: ksft_print_msg("no AMX support")
        AMXTest-->>TestRunner: Return KSFT_SKIP
    else AMX supported
        AMXTest->>AMXTest: check_cpuid_xtiledata()
        AMXTest->>AMXTest: Proceed with AMX tests
        AMXTest-->>TestRunner: Return test result (e.g. KSFT_PASS)
    end
Loading

Sequence Diagram for LAM Test Prerequisite Check and Skip Logic

sequenceDiagram
    participant TestRunner
    participant LAMTest as "lam.c main()"

    TestRunner->>LAMTest: Execute test
    LAMTest->>LAMTest: Check if cpu_has_lam()
    alt LAM not supported
        LAMTest->>LAMTest: ksft_print_msg("Unsupported LAM feature!")
        LAMTest-->>TestRunner: Return KSFT_SKIP
    else LAM supported
        LAMTest->>LAMTest: Proceed with LAM tests
        LAMTest-->>TestRunner: Return test result (e.g. KSFT_PASS)
    end
Loading

Class Diagram of Modified x86 Selftest Files and Key Functions

classDiagram
    class `tools/testing/selftests/x86/amx.c` {
        +main() int
    }
    class `tools/testing/selftests/x86/lam.c` {
        +main(argc: int, argv: char**) int
    }
Loading

File-Level Changes

Change Details Files
AMX selftest uses arch_prctl to detect support and skips test if feature missing
  • Removed check_cpuid_xsave() implementation and invocation
  • Added ARCH_GET_XCOMP_SUPP constant and arch_prctl syscall to query XFEATURE_MASK_XTILE
  • Replaced cpuid‐based checks with arch_prctl error check and KSFT_SKIP return
tools/testing/selftests/x86/amx.c
LAM selftest now skips test when LAM feature is unsupported
  • Changed unsupported‐feature return from -1 to KSFT_SKIP
tools/testing/selftests/x86/lam.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot deepin-ci-robot requested review from huangbibo and myml June 2, 2025 00:20
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

代码审查意见:

  1. amx.c文件中,移除了check_cpuid_xsave函数,改用syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features)来检查AMX支持。这种改动提高了代码的简洁性和可读性,但需要确保新的系统调用在所有目标系统上都可用。

  2. amx.c文件中,添加了#define ARCH_GET_XCOMP_SUPP 0x1021,这是一个新的宏定义,用于表示arch_prctl系统调用的参数。需要确认这个宏定义是否已经在其他地方定义过,以避免命名冲突。

  3. amx.c文件中,ksft_print_msg("no AMX support\n");return KSFT_SKIP;用于处理AMX不支持的情况。KSFT_SKIP是一个宏,用于表示测试被跳过。需要确认KSFT_SKIP宏的定义是否正确,并且是否在所有相关的头文件中都有定义。

  4. lam.c文件中,return -1;被改为return KSFT_SKIP;。这表明KSFT_SKIP宏在lam.c文件中也应该被定义。需要确认KSFT_SKIP宏的定义是否正确,并且是否在所有相关的头文件中都有定义。

  5. lam.c文件中,ksft_print_msg("Unsupported LAM feature!\n");用于打印不支持LAM特性的消息。需要确认ksft_print_msg函数的定义是否正确,并且是否在所有相关的头文件中都有定义。

总体来说,这些改动提高了代码的可读性和可维护性,但需要确保所有新增的宏和函数都在正确的位置定义,并且与现有的代码库兼容。

@Avenger-285714 Avenger-285714 requested a review from opsiff June 2, 2025 00:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request updates the selftests for x86 by modifying the behavior when prerequisite conditions are not met, so tests now show as SKIP rather than failing.

  • In lam.c, the test now returns KSFT_SKIP instead of -1 for unsupported LAM.
  • In amx.c, the legacy check_cpuid_xsave function is removed and replaced with an arch_prctl() call to detect AMX support.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tools/testing/selftests/x86/lam.c Replaces a failing return value with KSFT_SKIP for unsupported LAM.
tools/testing/selftests/x86/amx.c Removes the cpuid-based check and adds an arch_prctl based check for AMX support.
Comments suppressed due to low confidence (2)

tools/testing/selftests/x86/lam.c:1186

  • Using KSFT_SKIP clearly indicates that the test is being skipped when LAM is unsupported; please ensure that this macro is documented and consistently used across the selftests.
return KSFT_SKIP;

tools/testing/selftests/x86/amx.c:920

  • Ensure that the XFEATURE_MASK_XTILE macro is defined and available in the appropriate header, since it is used to verify AMX support immediately afterward.
rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);

long rc;

rc = syscall(SYS_arch_prctl, ARCH_GET_XCOMP_SUPP, &features);
if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
Copy link

Copilot AI Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding explicit parentheses around '(features & XFEATURE_MASK_XTILE)' for clarity, e.g., 'if (rc || ((features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE))'.

Suggested change
if (rc || (features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE) {
if (rc || ((features & XFEATURE_MASK_XTILE) != XFEATURE_MASK_XTILE)) {

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Avenger-285714 - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@opsiff opsiff merged commit 04ebbc2 into deepin-community:linux-6.6.y Jun 2, 2025
5 of 7 checks passed
@Avenger-285714 Avenger-285714 deleted the selftests_amx_64 branch June 2, 2025 05:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants