starkernel: fix lidt() inline-asm constraint hazard, land -O2

FABRIC.md item 4.5d Finding 4: lidt()'s inline asm used a register-only
("r") constraint on the idtr pointer, never telling GCC the asm
dereferences the pointee. At -O2 this let the compiler treat the
256-entry idt[] population loop and idtr_desc's field writes as dead
stores and eliminate them entirely, loading IDTR from uninitialized
stack instead of the real table -- a #GP on the first APIC timer tick
that happened to land on garbage. Same bug class as the earlier
muldiv64 fix (b43e51a): an inline-asm constraint too weak for what the
asm actually touches, invisible at -O0, live at -O2.

Fixed by switching to a memory operand ("m"(*idtr_desc)), matching how
Linux's own load_idt() is written. aarch64/riscv64 checked for the same
pattern -- neither has it, both install their vector/trap tables
entirely in hand-written .S.

Verified: all three architectures boot clean to ok>, POST Failed: 0,
identical dict-hashes across all three under -O2, zero new warnings
vs an -O0 baseline (amd64 3040/3040, aarch64 3041/3041 serial,
riscv64 3037/3037). -O2/-U_FORTIFY_SOURCE landed permanently in
COMMON_CFLAGS.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Robert Allan James
2026-08-11 16:57:20 -04:00
co-authored by Claude Sonnet 5
parent 065ab50240
commit a1c9fc7330
13 changed files with 54912 additions and 87 deletions
+12 -12
View File
@@ -78,33 +78,33 @@ tick_number,elapsed_ns,tick_interval_ns,cache_hits_delta,bucket_hits_delta,word_
4,40000,10000,0,0,63,19,8,4096,0,0,0,16,65536,0,0,65536,0,0
5,50000,10000,0,0,92,25,8,4096,2,0,0,19,65536,0,0,65536,0,0
6,60000,10000,0,0,64,27,8,4096,2,0,0,20,65536,0,0,65536,0,0
7,70000,10000,0,0,228,32,8,4096,210,0,0,27,65536,0,0,65536,0,0
8,80000,10000,0,0,256,34,9,4096,466,0,0,33,65536,0,0,65536,0,0
9,90000,10000,0,0,256,36,10,4096,722,0,0,40,65536,0,0,65536,0,0
10,100000,10000,0,0,256,36,11,4096,978,0,0,46,65536,0,0,65536,0,0
7,70000,10000,0,0,228,32,8,4096,210,0,0,26,65536,0,0,65536,0,0
8,80000,10000,0,0,256,34,9,4096,466,0,0,32,65536,0,0,65536,0,0
9,90000,10000,0,0,256,36,10,4096,722,0,0,39,65536,0,0,65536,0,0
10,100000,10000,0,0,256,36,11,4096,978,0,0,45,65536,0,0,65536,0,0
11,110000,10000,0,0,256,36,11,4096,1234,0,0,52,65536,0,0,65536,0,0
12,120000,10000,0,0,256,36,12,4096,1490,0,0,59,65536,0,0,65536,0,0
12,120000,10000,0,0,256,36,12,4096,1490,0,0,58,65536,0,0,65536,0,0
13,130000,10000,0,0,256,37,12,4096,1746,0,0,65,65536,0,0,65536,0,0
14,140000,10000,0,0,230,39,12,4096,1949,0,0,71,65536,0,0,65536,0,0
15,150000,10000,0,0,256,39,13,4096,2204,0,0,78,65536,0,0,65536,0,0
16,160000,10000,0,0,256,39,14,4096,2459,0,0,84,65536,0,0,65536,0,0
17,170000,10000,0,0,256,39,15,4096,2713,0,0,91,65536,0,0,65536,0,0
17,170000,10000,0,0,256,39,15,4096,2713,0,0,90,65536,0,0,65536,0,0
18,180000,10000,0,0,256,39,15,4096,2969,0,0,97,65536,0,0,65536,0,0
19,190000,10000,0,0,256,39,16,4096,3224,0,0,104,65536,0,1,65536,0,0
19,190000,10000,0,0,256,39,16,4096,3224,0,0,103,65536,0,1,65536,0,0
20,200000,10000,0,0,256,41,17,4096,3480,0,0,110,65536,0,1,65536,0,0
21,210000,10000,0,0,256,41,17,4096,3736,0,0,118,65536,0,1,65536,0,0
22,220000,10000,0,0,256,41,18,4096,3992,0,0,125,65536,0,1,65536,0,0
23,230000,10000,0,0,256,41,19,4096,4096,0,0,132,65536,0,1,65536,0,0
23,230000,10000,0,0,256,41,19,4096,4096,0,0,131,65536,0,1,65536,0,0
24,240000,10000,0,0,256,41,20,4096,4096,0,0,138,65536,0,1,65536,0,0
25,250000,10000,0,0,256,43,20,2048,2048,0,0,145,65536,0,1,65536,0,0
26,260000,10000,0,0,256,45,21,2048,2048,0,0,152,65536,0,1,65536,0,0
26,260000,10000,0,0,256,45,21,2048,2048,0,0,151,65536,0,1,65536,0,0
27,270000,10000,0,0,256,45,22,1024,1024,0,0,158,65536,0,1,65536,0,0
28,280000,10000,0,0,256,45,23,1024,1024,0,0,165,65536,0,1,65536,0,0
28,280000,10000,0,0,256,45,23,1024,1024,0,0,164,65536,0,1,65536,0,0
29,290000,10000,0,0,256,45,24,512,512,0,0,171,65536,0,1,65536,0,0
30,300000,10000,0,0,256,45,24,512,512,0,0,178,65536,0,1,65536,0,0
30,300000,10000,0,0,256,45,24,512,512,0,0,177,65536,0,1,65536,0,0
31,310000,10000,0,0,256,45,25,256,256,0,0,184,65536,0,1,65536,0,0
32,320000,10000,0,0,255,45,26,256,256,0,0,190,65536,0,1,65536,0,0
33,330000,10000,0,0,256,45,27,256,256,0,0,197,65536,0,1,65536,0,0
33,330000,10000,0,0,256,45,27,256,256,0,0,196,65536,0,1,65536,0,0
34,340000,10000,0,0,256,45,27,256,256,0,0,203,65536,0,1,65536,0,0
35,350000,10000,0,0,256,45,28,256,256,0,0,209,65536,0,1,65536,0,0
36,360000,10000,0,0,256,45,29,256,256,0,0,216,65536,0,1,65536,0,0
1 tick_number elapsed_ns tick_interval_ns cache_hits_delta bucket_hits_delta word_executions_delta hot_word_count avg_word_heat_q48 window_width actual_window_size predicted_label_hits jitter_bits apic_ticks time_trust_q48 variance_q48 vm_call_depth_max hera_heat_q48 hermes_heat_q48 artemis_heat_q48
78 4 40000 10000 0 0 63 19 8 4096 0 0 0 16 65536 0 0 65536 0 0
79 5 50000 10000 0 0 92 25 8 4096 2 0 0 19 65536 0 0 65536 0 0
80 6 60000 10000 0 0 64 27 8 4096 2 0 0 20 65536 0 0 65536 0 0
81 7 70000 10000 0 0 228 32 8 4096 210 0 0 27 26 65536 0 0 65536 0 0
82 8 80000 10000 0 0 256 34 9 4096 466 0 0 33 32 65536 0 0 65536 0 0
83 9 90000 10000 0 0 256 36 10 4096 722 0 0 40 39 65536 0 0 65536 0 0
84 10 100000 10000 0 0 256 36 11 4096 978 0 0 46 45 65536 0 0 65536 0 0
85 11 110000 10000 0 0 256 36 11 4096 1234 0 0 52 65536 0 0 65536 0 0
86 12 120000 10000 0 0 256 36 12 4096 1490 0 0 59 58 65536 0 0 65536 0 0
87 13 130000 10000 0 0 256 37 12 4096 1746 0 0 65 65536 0 0 65536 0 0
88 14 140000 10000 0 0 230 39 12 4096 1949 0 0 71 65536 0 0 65536 0 0
89 15 150000 10000 0 0 256 39 13 4096 2204 0 0 78 65536 0 0 65536 0 0
90 16 160000 10000 0 0 256 39 14 4096 2459 0 0 84 65536 0 0 65536 0 0
91 17 170000 10000 0 0 256 39 15 4096 2713 0 0 91 90 65536 0 0 65536 0 0
92 18 180000 10000 0 0 256 39 15 4096 2969 0 0 97 65536 0 0 65536 0 0
93 19 190000 10000 0 0 256 39 16 4096 3224 0 0 104 103 65536 0 1 65536 0 0
94 20 200000 10000 0 0 256 41 17 4096 3480 0 0 110 65536 0 1 65536 0 0
95 21 210000 10000 0 0 256 41 17 4096 3736 0 0 118 65536 0 1 65536 0 0
96 22 220000 10000 0 0 256 41 18 4096 3992 0 0 125 65536 0 1 65536 0 0
97 23 230000 10000 0 0 256 41 19 4096 4096 0 0 132 131 65536 0 1 65536 0 0
98 24 240000 10000 0 0 256 41 20 4096 4096 0 0 138 65536 0 1 65536 0 0
99 25 250000 10000 0 0 256 43 20 2048 2048 0 0 145 65536 0 1 65536 0 0
100 26 260000 10000 0 0 256 45 21 2048 2048 0 0 152 151 65536 0 1 65536 0 0
101 27 270000 10000 0 0 256 45 22 1024 1024 0 0 158 65536 0 1 65536 0 0
102 28 280000 10000 0 0 256 45 23 1024 1024 0 0 165 164 65536 0 1 65536 0 0
103 29 290000 10000 0 0 256 45 24 512 512 0 0 171 65536 0 1 65536 0 0
104 30 300000 10000 0 0 256 45 24 512 512 0 0 178 177 65536 0 1 65536 0 0
105 31 310000 10000 0 0 256 45 25 256 256 0 0 184 65536 0 1 65536 0 0
106 32 320000 10000 0 0 255 45 26 256 256 0 0 190 65536 0 1 65536 0 0
107 33 330000 10000 0 0 256 45 27 256 256 0 0 197 196 65536 0 1 65536 0 0
108 34 340000 10000 0 0 256 45 27 256 256 0 0 203 65536 0 1 65536 0 0
109 35 350000 10000 0 0 256 45 28 256 256 0 0 209 65536 0 1 65536 0 0
110 36 360000 10000 0 0 256 45 29 256 256 0 0 216 65536 0 1 65536 0 0