Skip to content

Fix SIGFPE at startup when CPUID leaf 0x15 is unusable with tpause - #43

Merged
byrnedj merged 1 commit into
intel:mainfrom
byrnedj:fix/tpause-cpuid-sigfpe
Oct 27, 2026
Merged

byrnedj merged 1 commit into
intel:mainfrom
byrnedj:fix/tpause-cpuid-sigfpe

Conversation

@byrnedj

@byrnedj byrnedj commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Fixes a startup crash reported on systems without DSA.

With DTO_WAIT_METHOD=tpause, init_dto() converts the tpause wait from ns
to TSC cycles using CPUID leaf 0x15 and divides by the denominator
unconditionally. If the leaf is absent (__get_cpuid() returns 0 and leaves
its outputs uninitialized) or reports den=0, as on many VMs, the
constructor dies with SIGFPE before main(). It also ran after dsa_init()
had already failed and the library was falling back to CPU, where the value
is never used.

  • Only do the conversion when DSA is in use and tpause is selected; require
    leaf 0x15 to be present with non-zero den, num and crystal frequency,
    otherwise log an error and fall back to busypoll (matching the existing
    "tpause not supported" fallback).
  • Fix WAITPKG detection in dsa_init(), which queried CPUID leaf 0 instead
    of leaf 7. Leaf 0's ECX is the ASCII "ntel", which has bit 5 set, so
    waitpkg_support was always 1 and selecting tpause/umwait on a CPU
    without WAITPKG would SIGILL rather than fall back.

With DTO_WAIT_METHOD=tpause, init_dto() converts the wait from ns to TSC
cycles using CPUID leaf 0x15 and divides by the denominator
unconditionally. If the leaf is absent (__get_cpuid() returns 0 with the
outputs uninitialized) or reports den=0, as on many VMs, the constructor
dies with SIGFPE before main(). It also ran after dsa_init() had failed
and the library was falling back to CPU, where the value is unused.

Only do the conversion when DSA is in use and tpause is selected, and
require the leaf to be present with non-zero den, num and frequency.
Otherwise log an error and fall back to busypoll.

Also fix waitpkg detection in dsa_init(), which queried CPUID leaf 0
instead of leaf 7. Leaf 0's ECX is the ASCII "ntel", which has bit 5
set, so waitpkg_support was always 1 and tpause/umwait on a CPU without
WAITPKG would SIGILL instead of falling back.

@jsydir jsydir 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.

looks good

@byrnedj
byrnedj merged commit 7314599 into intel:main Oct 27, 2026
1 check passed
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.

2 participants