Skip to content

Don't merge loads for xmm registers#4891

Merged
elliottt merged 3 commits intobytecodealliance:mainfrom
elliottt:trevor/stop-merging-loads-for-xmm-mem
Sep 12, 2022
Merged

Don't merge loads for xmm registers#4891
elliottt merged 3 commits intobytecodealliance:mainfrom
elliottt:trevor/stop-merging-loads-for-xmm-mem

Conversation

@elliottt
Copy link
Member

@elliottt elliottt commented Sep 9, 2022

Do not merge loads for xmm registers, as alignment requirements currently aren't satisfied with clif lowered from wasm.

Fixes #4890

@elliottt elliottt marked this pull request as ready for review September 9, 2022 20:44
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Thanks!

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen isle Related to the ISLE domain-specific language labels Sep 9, 2022
@github-actions
Copy link

github-actions bot commented Sep 9, 2022

Subscribe to Label Action

cc @cfallin, @fitzgen

Details This issue or pull request has been labeled: "cranelift", "cranelift:area:x64", "isle"

Thus the following users have been cc'd because of the following labels:

  • cfallin: isle
  • fitzgen: isle

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

@elliottt elliottt merged commit ad09c27 into bytecodealliance:main Sep 12, 2022
elliottt added a commit to elliottt/wasmtime that referenced this pull request Sep 12, 2022
Do not merge loads for xmm registers, as alignment requirements currently aren't satisfied with clif lowered from wasm.

Fixes bytecodealliance#4890
elliottt added a commit that referenced this pull request Sep 12, 2022
Back-port #4891 into the 1.0.0 release branch.
abrown added a commit to abrown/wasmtime that referenced this pull request Mar 17, 2025
In [bytecodealliance#10408], the new assembler re-opened an old issue related to
unaligned loads with SSE instructions. SSE instructions expect 128-bit
aligned loads when using the `m128` operand and fault if that is not the
case. This had been fixed previously by disallowing load-sinking for
`XmmMem` ([bytecodealliance#4891]) but more recently we had adopted the use of
`XmmMemAligned`. Since all the CI machines have AVX, these unaligned,
sunk loads would use the AVX lowering which can handle unaligned
accesses. This only appeared during fuzzing when AVX was disabled.

This change adopts the `XmmMemAligned` type in the generated assembler
code. This is temporary, though: a more lasting fix should pass along
an "alignment required" bit from the assembler AST. Closes bytecodealliance#10408.

[bytecodealliance#10408]: bytecodealliance#10408
[bytecodealliance#4891]: bytecodealliance#4891
abrown added a commit to abrown/wasmtime that referenced this pull request Mar 17, 2025
In [bytecodealliance#10408], the new assembler re-opened an old issue related to
unaligned loads with SSE instructions. SSE instructions expect 128-bit
aligned loads when using the `m128` operand and fault if that is not the
case. This had been fixed previously by disallowing load-sinking for
`XmmMem` ([bytecodealliance#4891]) but more recently we had adopted the use of
`XmmMemAligned` in `cranelift-codegen`. Since [bytecodealliance#10316] had no knowledge
of `XmmMemAligned` (only `XmmMem`), it caused the same kind fault--an
OOB trap that was in fact an unaligned load.

Why didn't CI catch this? Since all the CI machines have AVX and we do
not explicitly test the SSE-only case, these unaligned, sunk loads would
use the AVX lowering in CI. AVX loads handle unaligned accesses without
a fault. This was only discovered during fuzzing when AVX was disabled
(i.e., `--target x86_64-unknown-linux-gnu`).

To fix this, this change adopts the `XmmMemAligned` type in the
generated assembler code. This is temporary, though: a more lasting fix
should pass along an "alignment required" bit from the assembler AST.
In the meantime, this closes bytecodealliance#10408.

[bytecodealliance#10408]: bytecodealliance#10408
[bytecodealliance#4891]: bytecodealliance#4891
[bytecodealliance#10316]: bytecodealliance#10316
github-merge-queue bot pushed a commit that referenced this pull request Mar 18, 2025
…10417)

In [#10408], the new assembler re-opened an old issue related to
unaligned loads with SSE instructions. SSE instructions expect 128-bit
aligned loads when using the `m128` operand and fault if that is not the
case. This had been fixed previously by disallowing load-sinking for
`XmmMem` ([#4891]) but more recently we had adopted the use of
`XmmMemAligned` in `cranelift-codegen`. Since [#10316] had no knowledge
of `XmmMemAligned` (only `XmmMem`), it caused the same kind fault--an
OOB trap that was in fact an unaligned load.

Why didn't CI catch this? Since all the CI machines have AVX and we do
not explicitly test the SSE-only case, these unaligned, sunk loads would
use the AVX lowering in CI. AVX loads handle unaligned accesses without
a fault. This was only discovered during fuzzing when AVX was disabled
(i.e., `--target x86_64-unknown-linux-gnu`).

To fix this, this change adopts the `XmmMemAligned` type in the
generated assembler code. This is temporary, though: a more lasting fix
should pass along an "alignment required" bit from the assembler AST.
In the meantime, this closes #10408.

[#10408]: #10408
[#4891]: #4891
[#10316]: #10316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator isle Related to the ISLE domain-specific language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

x64: Incorrect out-of-bounds access reported for a misaligned float load

2 participants