Skip to content

budget: the decompressor's copy, LZ4 and parse_elf, 21 ms (bench) before the kernel's clock #645

Closed

Description

@aledbf

Budget entry (docs/boot-time.md, cold): this is the decompressor's copy, LZ4 and parse_elf. It comes from #611's split, where every stretch is a host timestamp from QEMU's trace of a marker kernel's port writes.

The phase. The marks tree, boots 2 to 12, traced:

stretch bench, lab 45177818419 metal, lab 45177817516
copy of the compressed kernel 3.5 [3.1, 3.6] 2.6 [2.2, 3.0]
LZ4 (__decompress), with the output's first touch 15.0 [14.5, 15.7] 13.2 [13.0, 14.3]
parse_elf 2.6 [2.5, 2.8] 2.5 [2.5, 2.6]
total 21.1 18.3
the KASLR choice and relocations ~1.4 ~1.4

The ceiling. The goal number gains what an uncompressed path removes: ~8-12 ms per the research comment on #611 (items 1 and 2). This split bounds it from above at 21 ms on bench, less the first touch of the ~40 MB output, which any path pays. How much of LZ4's 15 ms that first touch is was not measured. A marker after a pre-touch of the output buffer would split it.

Candidates, KASLR kept (research comment on #611, issuecomment-7099901391):

  1. The VMM applies KASLR to a vmlinux.
  2. The kernel randomizes itself from an uncompressed image. Hou Wenlong's RFC, 2026-01-26, not merged: PVH or the 64-bit entry, relocations kept in a section, about +2 ms over a plain vmlinux. It needs QEMU to honour XEN_ELFNOTE_PHYS32_RELOC, and KASLR_FLAG set under PVH.

Needs a new reason. "Measured and rejected" has an uncompressed bzImage payload with KASLR kept, refused for "+3.3 in qboot's copy and +6-7 in QEMU's start" (laptop, #326). The QEMU part is the bzImage read into QEMU's heap, 6-7 ms in #611's split, which has its own issue (mmap). A candidate here needs that answered first, or measured together with it.

Decided by. ssh-first cold first login, 40 a side, against the release on bench. restore-first beside it, unmoved.

From #611 (branch exp/firmware-split-611).

Activity

  1. added a commit that references this issue on Nov 23, 2026
  2. aledbf commented on Nov 23, 2026

    @aledbf
    MemberAuthor

    A lead from #646 (PR #652), not a decision: with QEMU mapping the bzImage, the "+6-7 in QEMU's start" half of #326's rejection is gone. #326's uncompressed payload (renumbered 0014, branch exp/646-uncompressed, parts run 45180892535) against LZ4, both on the patched QEMU, bench, spin's shape and login, 40 a side: first login −4.0 [−7.9, +0.3], within noise; sshd accepting −2.9 [−6.9, +2.4]; QEMU's RSS +32.0 MiB (+22.2 file, +9.9 anonymous) (lab 45183618987). Deciding it needs more boots, on a release that carries 0007.

  3. added a commit that references this issue on Nov 23, 2026
  4. aledbf commented on Nov 23, 2026

    @aledbf
    MemberAuthor

    The bound first, before choosing a path. Neither candidate (the VMM relocating a vmlinux, or Hou Wenlong's self-randomizing image) can beat the kernel entered with no decompressor and no KASLR at all. That bound is the PVH entry the machine used until 11-19, so it is measured before either is built.

    • Arms (one run, interleaved, bench, spin's shape and login): bz, v20261123.06 with the branch's kernel (the release's source and config plus CONFIG_PVH=y) booted as its bzImage; pvh, the same kernel build's vmlinux entered through pvh.bin, so _text is fixed and there is no decompressor; release, v20261123.06 as published, an anchor. bz and pvh share the QEMU, the firmware and the spin-machine. Only the way in differs.
    • Shape: 1 vCPU of 16, 128 MiB plugged to 2048 of 8 GiB, 4 hotplug disks, login=spin.
    • Decided by: ssh-first first login, 40 a side, Δp50 of pvh against bz. restore-first beside it, unmoved expected (a restore does not boot the kernel). If the interval does not clear ~8 ms (its lower bound above −8), neither path is worth carrying: the bound goes here and in docs/boot-time.md, and the issue closes.
    • Prior art for the bound: Holmes et al., EuroSys '22, measured VMM-applied KASLR at 1-3.7 ms over no KASLR (not nested). docs/log.md 11-19 read the bzImage against the PVH release at the first login 328 → 317 (lab 44583379559), but that comparison also changed main's login path and is not a bound.
    • Branch: exp/645-pvh-bound (lab-only: the kernel config, pvh.bin in QEMU's firmware, --kernel pvh:run:N in the lab, and the machine accepting an ELF kernel). Never merged.
  5. aledbf commented on Nov 23, 2026

    @aledbf
    MemberAuthor

    The bound, measured. bz (v20261123.06 with the branch's kernel, CONFIG_PVH=y, as its bzImage) against pvh (the same build's vmlinux through pvh.bin, no decompressor, no KASLR), one run each, interleaved, bench (c8id.4xlarge, nested), spin's shape (1 of 16 vCPUs, 128 of 8192 MiB, sized to 2048, 16 hotplug disks, spin's login), 40 a side, exp/645-pvh-bound, parts run 45192017068.

    bz p50 pvh p50 Δp50 [95%]
    first login (lab 45213668842) 379 360 −18.9 [−22.8, −12.4]
    sshd accepting 332 314 −18.4 [−22.9, −13.4]
    console prompt 508 493 −15.4 [−20.3, −11.1]
    QEMU RSS, MiB 225 209 −15.5 (anon −34.3, file +18.9)
    restored login, evicted (lab 45213683698) 73.9 70.4 −3.6 [−5.1, −2.1]
    restored login, cached 74.0 70.1 −3.9 [−5.8, −2.1]
    state, MiB 185 152 −33.1

    The cold bound clears the ~8 ms bar set before the run. The restore moved too, which was not expected: the state is 33 MiB smaller, because the bzImage's compressed copy and the decompressor's buffers are guest pages a booted guest has written and a checkpoint saves (inferred from the state's size; not traced). Either KASLR path that never decompresses should keep that half too (inferred).

    (a) the VMM relocates a vmlinux, against (b) the kernel relocates itself

    (a) QEMU applies KASLR (Holmes et al., EuroSys '22; Firecracker's design) (b) Hou Wenlong's RFC (lore cover.1769434279.git.houwenlong.hwl@antgroup.com, 2026-01-26) plus a QEMU patch
    Lines carried QEMU: read vmlinux.relocs (an internal, non-ABI format of arch/x86/tools/relocs), choose both bases, apply 32, inverse-32 and 64-bit relocations to the loaded segments, ~250 lines (inferred from linux-loader #84's size). Kernel: set KASLR_FLAG under PVH, which hvm_start_info has no field to carry, so a convention of our own. The release ships vmlinux.relocs and the machine hands it to QEMU Kernel: the RFC's 5 patches, 309+/32−, forward-ported to 7.3.5, plus ~3 lines that set KASLR_FLAG when it randomized. QEMU: ~60 lines honouring XEN_ELFNOTE_PHYS32_RELOC with a random aligned physical base in the PVH ELF loader. Nothing new ships but pvh.bin again
    Virtual base random, chosen by QEMU random, chosen by the kernel at startup_64 (find_random_virt_addr, the decompressor's slot rule)
    Physical base random, chosen by QEMU fixed at 16 MiB in the RFC; random with the QEMU patch, which 7.3's pvh_start_xen already follows (Andryuk, 6.12)
    RANDOMIZE_MEMORY only with a kernel change: kaslr_enabled() reads KASLR_FLAG, which PVH never sets the same, and the RFC does not set it either. Without the 3 lines it would silently be off: the direct map, vmalloc and vmemmap bases would not move
    Entropy the host's getrandom the guest's: kaslr_get_random_long (RDRAND, RDTSC, i8254, a hash of boot_params), the sources the decompressor uses today. No change in strength from the release (inferred: the same code)
    Checkpoints, CanResume the layout lives in guest RAM, which a checkpoint carries; a restore runs no loader. The record holds QEMU's version, devices and RAM blocks: on q35 pvh.bin is a fw_cfg file, not a RAM block (docs/log.md 11-19), so neither path moves it. An extra QEMU option for the relocs file would be a new -machine/fw_cfg property to check the same, and nothing new on QEMU's command line
    A cold boot after a restore each boot draws again each boot draws again

    Chosen: (b). It keeps the release's entropy code and the decision inside the kernel, carries no file format QEMU has to parse, and adds nothing to QEMU's command line. Its QEMU half is small and only places the ELF. Its cost is a forward port of an unmerged RFC, which hpa did not refuse (he asked for numbers, and the thread had none against a bzImage).

    What spin-machine-dev verify kernel and the boot check must assert. The build: the vmlinux has a non-empty .data.relocs and the PHYS32_RELOC note, and its config has RANDOMIZE_BASE, RANDOMIZE_MEMORY and PVH. That a section is there does not say KASLR ran, so an output check boots the built kernel ≥10 times and requires the _text from /proc/kallsyms, the physical "Kernel code" in /proc/iomem, and a vmalloc address from /proc/vmallocinfo (the RANDOMIZE_MEMORY base) each to take more than one value, and none to be the link-time default (ffffffff81000000, 0x1000000).

    Next: build (b) on exp/645-kaslr-pvh, prove it across ≥10 boots, then decide it at 60 a side against v20261123.06, cold and restored.

  6. aledbf commented on Nov 23, 2026

    @aledbf
    MemberAuthor

    Entropy: the self-randomizing vmlinux against the bzImage's KASLR, and what Hou meant.

    What "the security enhancement provided by KASLR is limited" means. It is one sentence of the RFC's cover letter (lkml): "Although the security enhancement provided by KASLR is limited, there is still a potential demand to allow uncompressed kernel images to perform virtual address randomization (for example, future support for x86 PIE)." It gives no reason and no number, and neither do hpa's two replies (1) or Hou's answer (2), which are about boot latency (~2 ms over a plain vmlinux). Read in context it is the usual remark that KASLR is a weak mitigation in general, not a claim that this path randomizes less than the decompressor (inferred: nothing in the thread or the patches says otherwise).

    What each path draws, read from the code and the boots:

    bzImage (v20261123.06) vmlinux through PVH (this change)
    Virtual base, slots find_random_virt_addr: 2 MiB slots from 16 MiB to 1 GiB less the image, ~480 (~8.9 bits) the same function, copied into arch/x86/boot/startup/kaslr.c (0017): the same slots
    Virtual base, seed kaslr_get_random_long: RDRAND, RDTSC, a hash of the build string and of boot_params the RFC as posted: the i8254 and the boot_params hash only. Its has_cpuflag() reads RDRAND from CPUID.1:EDX and TSC from ECX, the wrong way round, so it tests a reserved bit and DS-CPL; the guest has rdrand and tsc and no ds_cpl (lab 45225297602). 0020 reads them from ECX and EDX: RDRAND and RDTSC again, less the build string's hash, which is public
    Physical base the decompressor's find_random_phys_addr over the e820 RAM, 2 MiB slots, the same seed QEMU 0008, among the 2 MiB slots of low RAM from the note's minimum to below the initrd and the ACPI data, from qemu_guest_getrandom (the host's getrandom). In spin's 128 MiB the same range (inferred)
    RANDOMIZE_MEMORY (direct map, vmalloc, vmemmap) kernel_randomize_memory, in the kernel proper, its own kaslr_get_random_long with the real CPU flags the same code, once 0019 sets KASLR_FLAG. Without 0019 it never ran: the lowest vmalloc address ffffc90000000000 and the direct map ffff888000000000 at all 10 boots (lab 45225297602)

    So the RFC alone was a real loss on the virtual base's seed (RDRAND and RDTSC never mixed in), and two losses with RANDOMIZE_MEMORY (off). With 0019 and 0020 the sources are the bzImage's, the physical base's are better (the host's getrandom), and the slot counts are the same. Across 10 boots with 0019 (lab 45221660056): _text 10 distinct, the physical base 8, the direct map and vmalloc 10 distinct 1 GiB-aligned bases each.

    The relocation table. The RFC already fails the link when the table does not fit: the relocs tool dies with "Relocations overflow available space! Please adjust CONFIG_RELOCATION_TABLE_SIZE to at least 0x000c7000" (a 512 KiB reserve, parts run 45222305257). This kernel needs 0xc7000 of the 1 MiB reserved, and the build now prints what it uses. At boot it cannot overflow: the table is part of the image. A table never filled ends in the 0 it was reserved with, and 0019 then leaves the kernel where it was linked rather than marking it randomized; verify kernel refuses such a vmlinux.

    The swapped registers are in code the RFC adds (0017), and nothing in the thread mentions them; no later version of the series was looked for.

  7. 4 remaining items

  8. aledbf commented on Nov 23, 2026

    @aledbf
    MemberAuthor

    Kept and merged in #682: the kernel entered as a vmlinux through PVH, randomizing itself (Hou Wenlong's RFC as 0014-0018, our 0019 for RANDOMIZE_MEMORY and 0020 for the swapped CPUID registers, QEMU 0008 for a random physical base). Bench, spin's shape, 60 a side against v20261123.06: cold first login −16.8 [−20.9, −13.0], restore evicted −4.4 [−17.5, −2.0]. The record does not move. The next release measures it against v20261123.06 in its own run.

  9. aledbf commented on Nov 23, 2026

    @aledbf
    MemberAuthor

    The release holds the gain. The record's 20 a side did not see it. v20261123.07's record (release run 45241645340) read the cold first login at −3.5 [−12.9, +2.9] against v20261123.06, outside this issue's −16.8 [−20.9, −13.0]. Explained before spin is told what the bump gains.

    Same machine (read from the artefacts). The lab arm (pvh:run:45216245888) and the release boot byte-identical QEMU (f271a946…), qboot, pvh.bin and linuxboot_dma.bin. spin-machine args at 25434bb (the shim) and at 7635ade (OpenRelease picking vmlinux by its notes) print the same command line but for paths. Both vmlinux are stripped, 40,165,128 bytes, with the same LOAD segments and config. The release's adds 0020. QEMU's RSS moves identically in both (anonymous −34.0 MiB, file +20). The vmlinux's load cost in QEMU's start is the same in both arms, so it is not what separates them.

    Measured again, releases as published (bench, nested, spin's shape and login, each release with its own spin-machine, 60 a side, interleaved, lab 45252584128):

    v06 p50 v07 p50 Δp50 [95%]
    first login 378 359 −18.6 [−23.6, −14.0]
    sshd accepting 330 315 −15.3 [−21.2, −12.6]
    console prompt 512 493 −18.7 [−24.0, −12.8]
    QEMU RSS, MiB 226 212 −14.2

    The record's run was the outlier. Its own restore-first cold boot (40 a side, same run, same host) read −14.2 [−19.9, −8.6]. Its 20 .07 ssh-first boots sat at p50 370 (346-382), where the lab's 60 sit at 352 and 359. Drawing 20 a side from lab 45219785493's samples gives a Δ ≥ −3.5 in 5 of 100,000 draws. The record's sample size is #694.

    So the bump's cold gain is ~−17 to −19 ms (−18.6 [−23.6, −14.0] release against release), and its restore −3.8 [−4.8, −1.9] (the record) and −4.4 (lab 45219801969). No fix needed. The issue stays closed. Docs: #695.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions