Skip to content

hint::spin_loop invokes undefined behavior on targets without SSE2 #59237

Closed

Description

@gnzlbg

Currently hint::spin_loop is implemented with the pause instruction on all x86 / x86_64 targets, but this instruction is only available on CPUs with SSE2. The behavior of pause on CPUs without SSE2 is undefined.


This hint should not be implemented with inline assembly, but should call the appropriate core::arch intrinsics instead. Those explicitly state which features are required for each operation on each target.

Activity

  1. added
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    on Mar 16, 2019
  2. Fanael commented on Mar 17, 2019

    @Fanael

    This is incorrect: pause is defined in a way that makes it a harmless NOP on all earlier CPUs, and is even explicitly defined as such in Intel manuals:

    This instruction was introduced in the Pentium 4 processors, but is backward compatible with all IA-32 processors. In earlier IA-32 processors, the PAUSE instruction operates like a NOP instruction.

  3. gnzlbg commented on Mar 17, 2019

    @gnzlbg
    ContributorAuthor

    @Fanael indeed. Is there an advantage to emitting pause in earlier processors with respect to emitting nothing ?

  4. Fanael commented on Mar 17, 2019

    @Fanael

    Not that I know, there is no advantage on any of Intel's old microarchitectures, they just interpret it as a nop and have no special way of handling spin loops. It might be different on AMD's K7 or VIA Nehemiah, but I don't have that hardware to test, and I doubt it makes any difference anyway. It lets you avoid an ugly compile time conditional and that's it I think.

  5. added
    O-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)
    on Mar 17, 2019
  6. gnzlbg commented on Mar 17, 2019

    @gnzlbg
    ContributorAuthor

    This bug report is invalid, thanks @Fanael .

  7. added a commit that references this issue on Mar 21, 2019
    830c98d
  8. added
    O-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)
    and removed on Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-x86_32Target: x86 processors, 32 bit (like i686-*) (also known as IA-32, i386, i586, i686)O-x86_64Target: x86-64 processors (like x86_64-*) (also known as amd64 and x64)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions