Commit 7642bee
committed
Speedup identity, urandom, and clock_gettime
This introduces an EL1-only shim_data block holding a host-published
cache: identity slots (pid/ppid/uid/euid/gid/egid/tid), urandom-eligible
fd bitmap, a 4 KiB urandom ring with head/tail/lock, and a 32-bit
attention bitmask. The EL1 shim assembly serves identity and urandom
1-byte reads inline without trapping to the host; the existing HVC #5
forwarder is taken only when attention is raised, when a non-urandom fd
is consulted, or when the ring needs a host-side refill.
Measured at 1 M iterations under the new tests/bench-hot-syscalls.c :
getpid/getppid/getuid/geteuid/getgid/getegid/gettid : 47 ns/op
clock_gettime via __kernel_clock_gettime vDSO : 3.7 ns/op
read(/dev/urandom, 1 byte) : 134 ns/op
clock_gettime via SVC fallback : 2056 ns/op
The vDSO clock_gettime trampoline now seeds CLOCK_{MONOTONIC,REALTIME}
anchors back-to-back from a single SVC fallback, so the fast path serves
either clockid after one warm-up call. The X9/ELR_EL1 gate runs before
the host wall-clock samples so the anchor inherits no positive bias from
the seeding round trip.
Integrity boundary around the new cache:
- The shim_data block is mapped MEM_PERM_RW_EL1_ONLY (AP[2:1]=00) by
both bootstrap and execve so EL0 cannot read or store the bytes
directly. /proc/self/maps reports PROT_NONE for [shim-data] to
match what guest dereferences would observe.
- gva_translate_perm refuses MEM_PERM_EL1_ONLY descriptors on
guest-behalf access in both the L2 block and L3 page walk paths.
read(fd, shim_data_gva, n) now returns EFAULT instead of letting
the host spoof the cache.
- elf_map_segments takes an explicit infra reserve range and rejects
PT_PHDR copies or PT_LOAD segments whose page-aligned write extent
intersects it, closing a host-side overwrite path through the ELF
loader that bypassed page-table permissions.
- A new EL1 data-abort recover handler in shim.S catches strb faults
inside named urandom write ranges (caused by a racing EL0 munmap
or mprotect), drops the inner exception frame, releases the ring
lock, and returns EFAULT to EL0.
Cred publish is bracketed so concurrent fast-path readers see a
consistent snapshot. The attention word splits into ATTN_BIT_SIGTIMER
(0x1), ATTN_BIT_CRED (0x2), and ATTN_BIT_TRACE (0x4). CRED_BRACKETED
ORs the CRED bit, runs the setuid/setgid mutator, publishes the four
cred slots, then ANDs the CRED bit off. shim_globals_attn_or uses
__ATOMIC_SEQ_CST so the mutator's publish stores cannot become globally
visible before the attention bit on weakly-ordered ARM64; the AND clear
stays __ATOMIC_RELEASE because release pairs with the shim LDAR for the
publish-then-clear order. vdso_attention_or mirrors the same ordering.
Signal and itimer path support the lane discipline:
- attention_guest is now _Atomic so signal_init's NULL clear during
the execve reset window pairs with attention_raise's acquire load
on any sibling thread.
- signal_set_itimer writes expiry and interval before the release
store of .active, matching the field order already used by the
virt and prof setters. Consumers that ACQUIRE-load .active without
holding sig_lock now never observe armed=true with stale fields.
- New signal_attention_needed() OR-reads the three guest itimer
.active fields plus an unblocked-deliverable signal hint so the
HVC epilogue's recompute decides accurately whether the next call
may stay on the fast path.
The fd-table publication paths that feed the urandom bitmap are
serialized so a pathological sibling close+reopen on the same guest
fd cannot make the EL1 fast path consult a stale bit:
- fd_refresh_urandom_bitmap snapshots (type, linux_flags) AND publishes
the bitmap bit inside the same fd_lock critical section.
- fd_alloc_opened_host and duplicate_guest_fd install linux_flags,
dir, seals, and the urandom bit only after re-acquiring fd_lock and
confirming the slot's (type, host_fd) tuple still matches the just-
allocated values. On mismatch (the slot was reallocated by a
sibling) the install is skipped and any cloned DIR* is closed to
avoid a leak.
- The host-side urandom cache replaces its single global mutex with
a per-fd lock embedded in urandom_cache_t, initialized by io_init()
from syscall_init. Concurrent urandom reads on different fds no
longer serialize on one mutex.
- sys_readv on /dev/urandom now triggers shim_globals_refill_urandom_ring
on the slow path, matching sys_read so readv consumers do not leave
the shim ring drained.1 parent a24fc53 commit 7642bee
41 files changed
Lines changed: 3503 additions & 302 deletions
File tree
- src
- core
- runtime
- syscall
- tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
163 | 182 | | |
164 | 183 | | |
165 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
98 | | - | |
| 100 | + | |
99 | 101 | | |
100 | | - | |
101 | | - | |
102 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | 108 | | |
107 | 109 | | |
108 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
109 | 117 | | |
110 | | - | |
111 | | - | |
| 118 | + | |
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| |||
247 | 254 | | |
248 | 255 | | |
249 | 256 | | |
| 257 | + | |
| 258 | + | |
250 | 259 | | |
251 | | - | |
| 260 | + | |
| 261 | + | |
252 | 262 | | |
253 | 263 | | |
254 | 264 | | |
| |||
278 | 288 | | |
279 | 289 | | |
280 | 290 | | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
281 | 298 | | |
282 | | - | |
| 299 | + | |
| 300 | + | |
283 | 301 | | |
284 | 302 | | |
285 | 303 | | |
286 | 304 | | |
287 | 305 | | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
295 | 313 | | |
296 | 314 | | |
297 | 315 | | |
| |||
370 | 388 | | |
371 | 389 | | |
372 | 390 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
379 | 397 | | |
380 | 398 | | |
381 | 399 | | |
| |||
397 | 415 | | |
398 | 416 | | |
399 | 417 | | |
400 | | - | |
401 | | - | |
| 418 | + | |
| 419 | + | |
402 | 420 | | |
403 | 421 | | |
404 | 422 | | |
| |||
412 | 430 | | |
413 | 431 | | |
414 | 432 | | |
| 433 | + | |
| 434 | + | |
415 | 435 | | |
416 | | - | |
| 436 | + | |
| 437 | + | |
417 | 438 | | |
418 | 439 | | |
419 | 440 | | |
| |||
664 | 685 | | |
665 | 686 | | |
666 | 687 | | |
667 | | - | |
668 | | - | |
669 | | - | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
670 | 731 | | |
671 | 732 | | |
672 | 733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
211 | | - | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
212 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
213 | 221 | | |
214 | 222 | | |
215 | 223 | | |
| |||
264 | 272 | | |
265 | 273 | | |
266 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
267 | 286 | | |
268 | 287 | | |
269 | 288 | | |
| |||
308 | 327 | | |
309 | 328 | | |
310 | 329 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
316 | 335 | | |
317 | 336 | | |
318 | 337 | | |
319 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
320 | 358 | | |
321 | 359 | | |
322 | 360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
112 | 117 | | |
113 | 118 | | |
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
118 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
119 | 126 | | |
120 | 127 | | |
121 | 128 | | |
| |||
0 commit comments