Commit 282daf7
committed
fix(amx): prevent SIGILL — use _xgetbv(0) + prctl XCOMP_PERM for detection
Root cause: amx_available() used __cpuid_count(0xD, 0) to check XCR0,
which reports what the CPU SUPPORTS for XSAVE, not what the OS ENABLED.
On hypervisors that advertise AMX in CPUID but don't enable tile state,
the old check returned true → LDTILECFG → SIGILL.
Fix (3 steps added to amx_available):
1. Check OSXSAVE bit (CPUID.01H:ECX bit 27) — OS supports XSAVE?
2. _xgetbv(0) — read ACTUAL XCR0 register for bits 17+18
(TILECFG + TILEDATA), not the CPUID-reported capability
3. prctl(ARCH_REQ_XCOMP_PERM, XFEATURE_XTILEDATA=18) — Linux 5.19+
requires processes to explicitly request tile permission.
Uses raw syscall (no libc dep). Idempotent.
Also documented VNNI dispatch hierarchy in matvec_dispatch():
avx512vnni (zmm, 64 MACs) checked first → avxvnniint8 (ymm, 32 MACs)
is NEVER reached when avx512vnni is present. This is correct:
EVEX VPDPBUSD ≠ VEX VPDPBUSD — different encodings, different ISA.
Updated AMX_GOTCHAS.md Gotcha 4 with correct detection pattern.
Before: cargo test --lib → SIGILL (signal 4) on test_tile_zero_and_release
After: cargo test --lib → 1612 passed, 0 failed, 36 ignored
https://claude.ai/code/session_01NYGrxVopyszZYgLBxe4hgj1 parent 8a9bcc6 commit 282daf7
2 files changed
Lines changed: 107 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | | - | |
72 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
73 | 76 | | |
74 | 77 | | |
75 | 78 | | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
81 | 104 | | |
82 | 105 | | |
83 | 106 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
34 | 47 | | |
35 | 48 | | |
| 49 | + | |
36 | 50 | | |
37 | 51 | | |
38 | 52 | | |
39 | 53 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
45 | 102 | | |
46 | 103 | | |
47 | 104 | | |
| |||
203 | 260 | | |
204 | 261 | | |
205 | 262 | | |
206 | | - | |
| 263 | + | |
207 | 264 | | |
208 | 265 | | |
209 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
210 | 278 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | 279 | | |
215 | 280 | | |
216 | | - | |
| 281 | + | |
217 | 282 | | |
218 | 283 | | |
219 | 284 | | |
| |||
0 commit comments