Skip to content

qemu: a TPM command completes inside the start write within 1 ms (0013) - #915

Merged
aledbf merged 2 commits into
mainfrom
qemu/860-crb-bounded
Dec 4, 2026
Merged

aledbf merged 2 commits into
mainfrom
qemu/860-crb-bounded

Conversation

@aledbf

@aledbf aledbf commented Dec 4, 2026

Copy link
Copy Markdown
Member

Why

Running every TPM command inside tpm-crb's START write took −30.4 ms off the first login, and was rejected because it holds the BQL for swtpm's whole time (#851, lever 3). This keeps most commands inside the write, and holds the BQL for 1 ms at most (#860).

What changes

  • qemu/patches/0013.
    • The START write hands the command to the thread pool as before, then waits up to 1 ms, BQL held, for the worker.
    • A command answered within the bound completes before the write returns. A slower one, or a TPM that never answers, completes on the main loop as before.
    • Each request carries its own record, so a late completion can't touch the next command.
    • The thread pool creates a missing worker from the main loop, so the first command after 10 s idle waits out the bound.
  • qemu/Dockerfile gains a qtest check for both halves:
    • Short TPM2_GetRandom commands are done when the write that started them returns. CI read 5 of 5.
    • With swtpm stopped by SIGSTOP, the write still returns, and the command completes once swtpm runs again.
  • Docs. The budget entry (written before the run) and the result go in docs/boot-time.md. There is a carried record, a log entry, and 0013's row in qemu/README.md.

Measured

Bench, spin's shape, 2026-12-03. Both arms run main's kernel and differ only in QEMU: main's from parts run 47231873254, and 0013's from parts run 47231867269.

main 0013 Δ p50 [95%]
first login p50/p95, 60 a side (lab 47234042415) 915/952 901/928 −13.3 [−19.9, −6.7]
restored login, evicted / cached, 20 a side (lab 47234045520) +1.4 [−0.1, +4.3] / −0.1 [−1.4, +2.8], within noise
commands a boot that slept in tpm_transmit, of 326 (ledger, lab 47234050891, 5 a side) 326 23
ms in tpm_transmit a boot 133.8 87.5

The commands that still slept were the boot's first, before the pool had a worker, and those swtpm took longer than 1 ms to answer (up to 2.2 ms). No command on the login's path took over 20 ms.

The gain is under the unbounded version's −30.4 ms. That number was measured with an older shirudo, on a 1236 ms login where today's is 915 ms. The two versions weren't run side by side.

The ledger ran from a one-off branch: main plus 245984e, which adds the TPM kprobes and is marked not for main. I deleted the branch after the run.

Prior art

I found no bounded or polled completion of a TPM command in qemu-devel, QEMU's GitLab or swtpm's issues. Cloud Hypervisor's synchronous version has the opposite problem: when swtpm takes over 100 ms, the guest's TPM fails for good (cloud-hypervisor/cloud-hypervisor#9053, still open).

Closes #860

🤖 Generated with Claude Code

aledbf and others added 2 commits December 3, 2026 20:56
The START write hands the command to the thread pool as before and
waits up to 1 ms, BQL held, for the worker; a short command is done
when the guest first reads START, and a slow one or a TPM that does
not answer completes on the main loop as before. qemu/Dockerfile's
qtest check holds both. The budget entry is written before the run.

Part of #860

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first login −13.3 [−19.9, −6.7] (lab 47234042415, 60 a side), the
restored login within noise (lab 47234045520). The ledger with the TPM
kprobes: 23 of a boot's 326 commands sleep in tpm_transmit instead of
all of them (lab 47234050891).

Closes #860

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aledbf
aledbf merged commit defbc5c into main Dec 4, 2026
16 checks passed
@aledbf
aledbf deleted the qemu/860-crb-bounded branch December 4, 2026 00:43
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.

qemu: complete a TPM command inside the start write when swtpm answers within a bound

1 participant