Skip to content

Fix SIGILL crash on ARM64 platforms with SME but no SVE - #127398

Merged
AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix/122608-sve-sigill
Apr 28, 2026
Merged

AndyAyersMS merged 3 commits into
dotnet:mainfrom
AndyAyersMS:fix/122608-sve-sigill

Conversation

@AndyAyersMS

Copy link
Copy Markdown
Member

Replace CONTEXT_GetSveLengthFromOS() calls in signal context handling with direct reads of sve->vl from the kernel-provided signal frame. The CONTEXT_GetSveLengthFromOS function executes the SVE 'rdvl' instruction, which causes SIGILL on platforms that have SME (streaming SVE) but not standalone SVE — such as Apple M4 under macOS Virtualization.Framework with Podman/Colima.

On these platforms, the Linux kernel includes an SVE_MAGIC record in signal frames (with vl=0 and minimal size) due to SME's streaming SVE mode, but the CPU does not support SVE instructions. When a signal fires (e.g. SIGUSR1 for activation injection), CONTEXTFromNativeContext sees the SVE record and calls rdvl, which triggers SIGILL. The SIGILL handler then tries to capture context again, hitting rdvl recursively.

The fix uses sve->vl from the signal frame directly, which is always available when an SVE context record is present. On real SVE hardware, sve->vl equals what rdvl would return. On SME-only platforms, sve->vl is 0, so the SVE register save/restore is correctly skipped.

Fixes #122608

Replace CONTEXT_GetSveLengthFromOS() calls in signal context handling with
direct reads of sve->vl from the kernel-provided signal frame. The
CONTEXT_GetSveLengthFromOS function executes the SVE 'rdvl' instruction,
which causes SIGILL on platforms that have SME (streaming SVE) but not
standalone SVE — such as Apple M4 under macOS Virtualization.Framework
with Podman/Colima.

On these platforms, the Linux kernel includes an SVE_MAGIC record in
signal frames (with vl=0 and minimal size) due to SME's streaming SVE
mode, but the CPU does not support SVE instructions. When a signal fires
(e.g. SIGUSR1 for activation injection), CONTEXTFromNativeContext sees
the SVE record and calls rdvl, which triggers SIGILL. The SIGILL handler
then tries to capture context again, hitting rdvl recursively.

The fix uses sve->vl from the signal frame directly, which is always
available when an SVE context record is present. On real SVE hardware,
sve->vl equals what rdvl would return. On SME-only platforms, sve->vl is
0, so the SVE register save/restore is correctly skipped.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings April 24, 2026 19:31
@github-actions github-actions Bot added the area-PAL-coreclr only for closed issues label Apr 24, 2026
@AndyAyersMS

Copy link
Copy Markdown
Member Author

@janvorli PTAL

Pre-fix, dotnet new classlib run in a linux container on an M4 would fail about 5% of the time. Post-fix no failures were observed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes an ARM64 SIGILL crash in CoreCLR PAL signal-context handling on platforms that provide an SVE signal-frame record but don’t support executing SVE instructions (e.g., SME-only environments). It does so by avoiding the SVE rdvl instruction and instead using the kernel-provided sve_context::vl value from the signal frame.

Changes:

  • Replace CONTEXT_GetSveLengthFromOS() (uses rdvl) with direct reads of sve->vl when handling SVE state in signal contexts.
  • Add explanatory comments documenting the SME-without-SVE scenario and why rdvl must be avoided in this path.

Comment thread src/coreclr/pal/src/thread/context.cpp Resolved
Comment thread src/coreclr/pal/src/thread/context.cpp Resolved

@janvorli janvorli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thank you!

Comment thread src/coreclr/pal/src/thread/context.cpp Resolved
- Remove the now-tautological _ASSERTE((sve->vl > 0) && (sve->vl % 16 == 0))
  inside the 'if (sve->vl == 16)' block (janvorli).
- In CONTEXTToNativeContext, derive vq from sve->vl (the signal frame's
  authoritative layout) instead of lpContext->Vl (copilot-reviewer).

Co-authored-by: Copilot <[email protected]>
@am11

am11 commented Apr 24, 2026

Copy link
Copy Markdown
Member

These are the only two usages, we can delete its definition:

src/coreclr/pal/src/arch/arm64/context2.S:303:    LEAF_ENTRY CONTEXT_GetSveLengthFromOS, _TEXT
src/coreclr/pal/src/arch/arm64/context2.S:306:    LEAF_END CONTEXT_GetSveLengthFromOS, _TEXT
src/coreclr/pal/src/include/pal/context.h:1628:    CONTEXT_GetSveLengthFromOS
src/coreclr/pal/src/include/pal/context.h:1637:CONTEXT_GetSveLengthFromOS(

Also, the comment can be reworded to avoid mentions of CONTEXT_GetSveLengthFromOS (after the definitions are deleted).

@am11

am11 commented Apr 24, 2026

Copy link
Copy Markdown
Member

Other places using rdvl:

src/coreclr/jit/codegenarm64test.cpp:6016:    theEmitter->emitIns_R_I(INS_sve_rdvl, EA_8BYTE, REG_R0, -32); // RDVL <Xd>, #<imm>
src/coreclr/jit/codegenarm64test.cpp:6017:    theEmitter->emitIns_R_I(INS_sve_rdvl, EA_8BYTE, REG_R5, 0);   // RDVL <Xd>, #<imm>
src/coreclr/jit/codegenarm64test.cpp:6018:    theEmitter->emitIns_R_I(INS_sve_rdvl, EA_8BYTE, REG_R10, 5);  // RDVL <Xd>, #<imm>
src/coreclr/jit/codegenarm64test.cpp:6019:    theEmitter->emitIns_R_I(INS_sve_rdvl, EA_8BYTE, REG_R15, 31); // RDVL <Xd>, #<imm>
src/coreclr/jit/emitarm64.cpp:1134:        case IF_SVE_BC_1A: // rdvl
src/coreclr/jit/emitarm64sve.cpp:1627:        case INS_sve_rdvl:
src/coreclr/jit/instrsarm64sve.h:2103:INST1(rdvl,              "rdvl",                  0,                       IF_SVE_BC_1A,            0x04BF5000                                   )
src/coreclr/vm/arm64/asmhelpers.S:29:        rdvl    x0, 1
src/coreclr/vm/arm64/asmhelpers.asm:92:        rdvl    x0, 1

- Remove unused CONTEXT_GetSveLengthFromOS definition (context2.S) and
  declaration (context.h) since all callers now use sve->vl (am11).
- Reword comments to not reference the deleted function (am11).
- Replace redundant assert with meaningful size check (janvorli/AndyAyersMS):
  _ASSERTE(sve->head.size >= SVE_SIG_CONTEXT_SIZE(sve_vq_from_vl(16)))

Co-authored-by: Copilot <[email protected]>
@AndyAyersMS

AndyAyersMS commented Apr 24, 2026 •

Copy link
Copy Markdown
Member Author

Other places using rdvl:

JIT usage should be ok. Let me check the helpers. Looks like they're only invoked after we have verified SVE support. So they seem ok too.

@AndyAyersMS
AndyAyersMS merged commit d99474c into dotnet:main Apr 28, 2026
109 checks passed
@AndyAyersMS

Copy link
Copy Markdown
Member Author

/backport to release/10.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

steveisok pushed a commit that referenced this pull request Apr 30, 2026
#127518)

Backport of #127398 to release/10.0

/cc @AndyAyersMS

## Customer Impact

- [x] Customer reported
- [ ] Found internally

When building .NET 10 applications in Docker on Apple M4 hardware, the
.NET 10 SDK (version 10.0.101) crashes with "Illegal instruction (core
dumped)" on ARM64 images. The crash occurs intermittently during various
.NET CLI operations including dotnet new, dotnet add package, and dotnet
build.

#122608

## Regression

- [x] Yes
- [ ] No

Regression over 9.0

## Testing

Verified creating new dotnet console projects in an Ubuntu container on
an M4 works reliably (previously it would fail 5-10% of the time).

## Risk

Low, handles a situation unique to running in a Linux container on a Mac
M4.

---------

Co-authored-by: Andrew Ayers <[email protected]>
Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators May 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-PAL-coreclr only for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET 10 SDK ARM64: Illegal instruction (SIGILL) on Apple M4 with macOS Virtualization.Framework

4 participants