From c565646c0d3ca2b7a8541ec514913b34d20cde1a Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 3 Dec 2026 20:56:18 -0300 Subject: [PATCH 1/2] qemu: a TPM command completes inside the start write within 1 ms (0013) 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 --- docs/boot-time.md | 19 ++ qemu/Dockerfile | 28 +++ ...ete-a-command-inside-the-start-write.patch | 164 ++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch diff --git a/docs/boot-time.md b/docs/boot-time.md index b6d8c5ef..76b94dcd 100644 --- a/docs/boot-time.md +++ b/docs/boot-time.md @@ -560,6 +560,25 @@ it, and a swtpm that never answers hangs the machine where the guest's driver us bounded wait, the command completed in the write when swtpm answers within a millisecond and on the thread pool otherwise, would keep the gain without the hold (#860). +**A bounded wait in the start write (#860).** *The budget entry, written before the run.* The +phase is the same: what a command costs the guest inside `tpm_transmit` beyond swtpm's work. On +main (0012, 0033), the unbounded start write took −30.4 [−37.3, −22.6] off the first login (lab +46275881507, 60 a side), so that is the ceiling. The START write hands the command to the thread +pool as today and then waits, BQL held, up to 1 ms for the worker to finish `handle_request`. If it +finished, the write completes the command; if not, the write returns and the thread pool's +completion runs on the main loop as before. The BQL is held at most 1 ms a command. A worker the +pool has to create is made by a bottom half on the main loop, which cannot run while the vCPU holds +the BQL, so the first command after 10 s idle waits out the bound and completes as before. It is +decided by the first login against main's QEMU, interleaved, 60 a side (the effect is ~30 ms, +under the ±7-9 ms of 20 a side), with the restored login no worse, and the ledger with the TPM +kprobes shows the short commands do not sleep and the RSA primaries still do. Prior art: Cloud +Hypervisor's CRB runs the command in the write with a 100 ms receive timeout, and a slower answer +fails the guest's TPM for good (cloud-hypervisor/cloud-hypervisor#9053, 2026-10-11, open; its fix +#9054, a worker as QEMU has, closed unmerged). QEMU's backend has used its thread pool since +c4fb8561bcec (2018), whose completion bottom half `tpm_backend_finish_sync` waits on. I found no +bounded or polled completion of a TPM command in qemu-devel, QEMU's GitLab or swtpm's issues +(searched 2026-12-03), and no measurement of either path in a guest besides lever 3's. + ## What the machine carries This table lists every change the tree makes for boot time, with what it earns in spin's shape. diff --git a/qemu/Dockerfile b/qemu/Dockerfile index e58c27d4..df230f23 100644 --- a/qemu/Dockerfile +++ b/qemu/Dockerfile @@ -745,6 +745,34 @@ RUN d=$(mktemp -d) && \ *) echo "ERROR: tpm-crb's command buffer is not a page of RAM at 0xFED41000 that the control area names: qemu/patches/0012 is lost"; echo "$out"; exit 1 ;; \ esac +# qemu/patches/0013 waits up to 1 ms in the guest's START write for the TPM's answer, so the guest's +# first read of START after the write finds a short command done, and no longer, so a TPM that does +# not answer leaves the machine running. qtest stands in for the guest. After a TPM2_Startup, which +# also gives the thread pool its worker, five TPM2_GetRandom are each started and START read at once: +# the write and the read arrive in one read of qtest's input, so without the patch the main loop +# cannot complete the command between them, and with it most are done (one is enough, for a busy +# builder). Then swtpm is stopped: the START write returns, START reads set, and once swtpm runs +# again the command completes on the main loop with its answer in the buffer (#860). +RUN d=$(mktemp -d) && \ + { /opt/swtpm/bin/swtpm socket --tpm2 --tpmstate dir="$d" --ctrl type=unixio,path="$d/ctrl" & } && sp=$! && \ + for i in $(seq 500); do [ -S "$d/ctrl" ] && break; sleep 0.01; done; \ + rand='write 0xfed41000 12 0x80010000000c0000017b0008\nwritel 0xfed4004c 0x1\nreadl 0xfed4004c\n'; \ + out=$({ printf 'writel 0xfed40008 0x1\nwritel 0xfed40040 0x1\nwrite 0xfed41000 12 0x80010000000c000001440000\nwritel 0xfed4004c 0x1\n'; \ + sleep 0.5; for i in 1 2 3 4 5; do printf "$rand"; sleep 0.2; done; \ + kill -STOP $sp; printf "$rand"; sleep 0.5; kill -CONT $sp; sleep 0.5; \ + printf 'readl 0xfed4004c\nread 0xfed41000 10\n'; sleep 0.2; } | \ + timeout 10 /opt/qemu-tcg/bin/qemu-system-x86_64 -machine q35 -accel qtest -m 128M -nodefaults \ + -display none -L /build/pc-bios -chardev socket,id=tpm,path="$d/ctrl" \ + -tpmdev emulator,id=tpm,chardev=tpm -device tpm-crb,tpmdev=tpm -qtest stdio 2>/dev/null | tr '\n' ' '); \ + kill -CONT $sp 2>/dev/null; kill $sp 2>/dev/null; wait $sp 2>/dev/null; rm -rf "$d"; \ + done=$(echo "$out" | grep -o 'OK OK OK 0x0000000000000000' | wc -l); \ + case "$out" in \ + *"OK OK OK 0x0000000000000001 OK 0x0000000000000000 OK 0x80010000001400000000 ") ;; \ + *) echo "ERROR: with swtpm stopped, the START write did not return, or the command did not complete once swtpm ran: qemu/patches/0013 is lost or holds the BQL until the TPM answers"; echo "$out"; exit 1 ;; \ + esac; \ + [ "$done" -ge 1 ] || { echo "ERROR: no TPM2_GetRandom of five was done when the write that started it returned: qemu/patches/0013 is lost"; echo "$out"; exit 1; }; \ + echo "OK: $done of 5 short TPM commands were done when the write that started them returned, and a TPM that does not answer leaves the write returning" + # passt, the network of a NIC on passt (machine.NIC.Passt): one beside each QEMU whose machine has # one, which machine.Start runs on a socket pair. Not QEMU's --enable-passt, which has QEMU spawn # it, nor slirp, which puts a network stack inside the QEMU process every machine runs (both stay diff --git a/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch b/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch new file mode 100644 index 00000000..6fd5161a --- /dev/null +++ b/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch @@ -0,0 +1,164 @@ +From: Manuel de Brito Fontes +Date: Thu, 3 Dec 2026 21:00:00 -0300 +Subject: [PATCH] hw/tpm/tpm_crb: complete a command inside the start write within a bound + +tpm-crb hands a command to its backend on a thread-pool worker and +completes it from a bottom half on the main loop. Linux's +tpm_try_transmit() reads the status once, right after the write that +starts the command, so that read always finds it running, and the guest +waits before it reads again. swtpm answers most commands in about +0.1 ms. + +After handing the command to the worker, wait on the vCPU thread, with +the BQL held, up to 1 ms for the worker to finish. If it did, complete +the command before the write returns, and the thread pool's completion +only frees the request. If not, return, and the main loop completes +the command as before. The guest's first status read finds a short +command done, and the BQL is held for at most 1 ms a command, so a slow +command (an RSA primary, a state write to a busy disk) or a TPM that +never answers stops the main loop and the other vCPUs for no longer +than that. + +Running the command on the vCPU thread for as long as it takes, as +Cloud Hypervisor's CRB does, gained as much on the first login and was +not carried for that hold. Dropping the BQL around the wait instead is +not an option: a reset from the main loop waits in +tpm_backend_finish_sync() for the command's completion, which needs the +BQL. + +The thread pool creates a missing worker from a bottom half on the main +loop, which cannot run while the vCPU holds the BQL, so the first +command after the pool's 10 s idle timeout waits out the bound and +completes as before. + +Local patch for this machine. Not upstream. + +Assisted-by: LLM +--- + backends/tpm/tpm_backend.c | 55 ++++++++++++++++++++++++++++++++++++ + hw/tpm/tpm_crb.c | 13 ++++++++- + include/system/tpm_backend.h | 14 +++++++++ + 3 files changed, 81 insertions(+), 1 deletion(-) + +diff --git a/backends/tpm/tpm_backend.c b/backends/tpm/tpm_backend.c +index 8cf80043a..5f9c7c48d 100644 +--- a/backends/tpm/tpm_backend.c ++++ b/backends/tpm/tpm_backend.c +@@ -111,6 +111,61 @@ void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd) + tpm_backend_request_completed, s); + } + ++/* ++ * A request tpm_backend_deliver_request_bounded() delivered: the worker posts ++ * @done once the backend has answered, and the thread pool's completion frees ++ * it. @early is set, with the BQL held, when the caller completed it. ++ */ ++typedef struct TPMBackendRequest { ++ TPMBackend *s; ++ QemuSemaphore done; ++ int ret; ++ bool early; ++} TPMBackendRequest; ++ ++static int tpm_backend_bounded_worker(void *opaque) ++{ ++ TPMBackendRequest *req = opaque; ++ ++ req->ret = tpm_backend_worker_thread(req->s); ++ qemu_sem_post(&req->done); ++ return req->ret; ++} ++ ++static void tpm_backend_bounded_completed(void *opaque, int ret) ++{ ++ TPMBackendRequest *req = opaque; ++ ++ if (!req->early) { ++ tpm_backend_request_completed(req->s, ret); ++ } ++ qemu_sem_destroy(&req->done); ++ g_free(req); ++} ++ ++void tpm_backend_deliver_request_bounded(TPMBackend *s, TPMBackendCmd *cmd, ++ int ms) ++{ ++ TPMBackendRequest *req; ++ ++ if (s->cmd != NULL) { ++ error_report("There is a TPM request pending"); ++ return; ++ } ++ ++ s->cmd = cmd; ++ object_ref(OBJECT(s)); ++ req = g_new0(TPMBackendRequest, 1); ++ req->s = s; ++ qemu_sem_init(&req->done, 0); ++ thread_pool_submit_aio(tpm_backend_bounded_worker, req, ++ tpm_backend_bounded_completed, req); ++ if (qemu_sem_timedwait(&req->done, ms) == 0) { ++ req->early = true; ++ tpm_backend_request_completed(s, req->ret); ++ } ++} ++ + void tpm_backend_reset(TPMBackend *s) + { + TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s); +diff --git a/hw/tpm/tpm_crb.c b/hw/tpm/tpm_crb.c +index 2c41c267b..6f916e9a7 100644 +--- a/hw/tpm/tpm_crb.c ++++ b/hw/tpm/tpm_crb.c +@@ -60,6 +60,9 @@ typedef struct CRBState CRBState; + DECLARE_INSTANCE_CHECKER(CRBState, CRB, + TYPE_TPM_CRB) + ++/* How long the START write waits for the TPM's answer. */ ++#define TPM_CRB_START_WAIT_MS 1 ++ + #define CRB_INTF_TYPE_CRB_ACTIVE 0b1 + #define CRB_INTF_VERSION_CRB 0b1 + #define CRB_INTF_CAP_LOCALITY_0_ONLY 0b0 +@@ -251,7 +254,15 @@ static void tpm_crb_mmio_write(void *opaque, hwaddr addr, + .out = s->response_buffer->data, + .out_len = s->response_buffer->len, + }; +- tpm_backend_deliver_request(s->tpmbe, &s->cmd); ++ /* ++ * Most commands are answered well inside this bound, so the ++ * guest's first read of START after this write finds them done ++ * and the guest does not sleep before it reads again. The BQL ++ * is held for at most the bound; a slower command completes on ++ * the main loop as before. ++ */ ++ tpm_backend_deliver_request_bounded(s->tpmbe, &s->cmd, ++ TPM_CRB_START_WAIT_MS); + } else if (val & CRB_START_NEXT_CHUNK) { + if (!s->cap_chunk) { + break; +diff --git a/include/system/tpm_backend.h b/include/system/tpm_backend.h +index 01b11f629..5de35abf8 100644 +--- a/include/system/tpm_backend.h ++++ b/include/system/tpm_backend.h +@@ -133,6 +133,20 @@ bool tpm_backend_had_startup_error(TPMBackend *s); + */ + void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd); + ++/** ++ * tpm_backend_deliver_request_bounded: ++ * @s: the backend to send the request to ++ * @cmd: the command to deliver ++ * @ms: how long to wait for the response ++ * ++ * Send a request to the backend as tpm_backend_deliver_request() does, then ++ * wait up to @ms milliseconds on the calling thread, which holds the BQL, for ++ * the response. If it arrived, the frontend's request_completed() has run ++ * when this returns; if not, it runs later, on the main loop. ++ */ ++void tpm_backend_deliver_request_bounded(TPMBackend *s, TPMBackendCmd *cmd, ++ int ms); ++ + /** + * tpm_backend_reset: + * @s: the backend to reset From 8d053cf9451d1dfc9f4bb8a2412e3e83538dcb0e Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 3 Dec 2026 21:25:37 -0300 Subject: [PATCH 2/2] docs: 0013 measured and carried, record and log entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- docs/boot-time.md | 15 +++++++++++++++ ...qemu-0013-tpm-crb-bounded-start-write.json | 19 +++++++++++++++++++ ...etes-inside-the-start-write-within-1-ms.md | 9 +++++++++ qemu/README.md | 1 + ...ete-a-command-inside-the-start-write.patch | 12 ++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 docs/experiments/860-qemu-0013-tpm-crb-bounded-start-write.json create mode 100644 docs/log/2026-12-03-a-tpm-command-completes-inside-the-start-write-within-1-ms.md diff --git a/docs/boot-time.md b/docs/boot-time.md index 76b94dcd..a28b65a7 100644 --- a/docs/boot-time.md +++ b/docs/boot-time.md @@ -579,6 +579,21 @@ c4fb8561bcec (2018), whose completion bottom half `tpm_backend_finish_sync` wait bounded or polled completion of a TPM command in qemu-devel, QEMU's GitLab or swtpm's issues (searched 2026-12-03), and no measurement of either path in a guest besides lever 3's. +*Measured* (bench, spin's shape, the release's image, main's kernel and QEMU of parts run +47231873254 against the same with 0013, parts run 47231867269, shirudo 412dc8f3, 2026-12-03). The +first login −13.3 [−19.9, −6.7], p50/p95 915/952 to 901/928 (lab 47234042415, 60 a side); restored ++1.4 [−0.1, +4.3] evicted and −0.1 [−1.4, +2.8] cached, within noise (lab 47234045520, 20 a side). +The ledger with the TPM kprobes (lab 47234050891, 5 a side): a boot's 326 commands slept in +`tpm_transmit` 23 times instead of 326, and spent 87.5 ms there instead of 133.8, a command 0.20 ms +instead of 0.30 at the median. The ones that still slept were the boot's first, before the thread +pool had a worker, and those swtpm took longer than the bound to answer, 0.6-0.9 ms at the median +and up to 2.2. No command on this login's path took over 20 ms, so the BQL held a millisecond at +most where an RSA primary would have held it for its whole time. The gain is under the −30.4 the +unbounded write measured, which was with shirudo 88f9888 on a first login of 1236 ms at the median; +with 412dc8f3 it is 915, and the bounded write leaves 23 commands a boot sleeping that the +unbounded one did not (inferred: the two were not run side by side). **Carried** (qemu/patches/0013, "What +the machine carries"). + ## What the machine carries This table lists every change the tree makes for boot time, with what it earns in spin's shape. diff --git a/docs/experiments/860-qemu-0013-tpm-crb-bounded-start-write.json b/docs/experiments/860-qemu-0013-tpm-crb-bounded-start-write.json new file mode 100644 index 00000000..371ea2f2 --- /dev/null +++ b/docs/experiments/860-qemu-0013-tpm-crb-bounded-start-write.json @@ -0,0 +1,19 @@ +{ + "decision": "carried", + "order": 39, + "change": "QEMU 0013: tpm-crb's START write waits up to 1 ms, BQL held, for the thread pool's worker, so a command swtpm answers within it completes before the write returns and the guest's first status read finds it done; a slower one, or a TPM that does not answer, completes on the main loop as before (#860)", + "where": "qemu/patches", + "result": "the shirudo machine's first login −13.3 [−19.9, −6.7], p50/p95 915/952 to 901/928 (lab 47234042415, 60 a side); restored +1.4 [−0.1, +4.3] evicted and −0.1 [−1.4, +2.8] cached, within noise (lab 47234045520, 20 a side). The ledger with the TPM kprobes: a boot's 326 commands slept in `tpm_transmit` 23 times instead of 326, 133.8 to 87.5 ms there, a command 0.30 to 0.20 ms at the median; those that still slept were the boot's first, before the pool had a worker, and the ones longer than the bound (lab 47234050891, 5 a side)", + "evidence": "measured, 60 a side", + "source": "labs 47234042415, 47234045520, 47234050891; parts 47231867269, 47231873254", + "issues": [ + 860 + ], + "runs": [ + 47231867269, + 47231873254, + 47234042415, + 47234045520, + 47234050891 + ] +} diff --git a/docs/log/2026-12-03-a-tpm-command-completes-inside-the-start-write-within-1-ms.md b/docs/log/2026-12-03-a-tpm-command-completes-inside-the-start-write-within-1-ms.md new file mode 100644 index 00000000..950833f8 --- /dev/null +++ b/docs/log/2026-12-03-a-tpm-command-completes-inside-the-start-write-within-1-ms.md @@ -0,0 +1,9 @@ +--- +date: "2026-12-03" +order: 10 +area: qemu +title: a TPM command completes inside the start write within 1 ms (0013, #860) +issues: [851, 860] +runs: [47231867269, 47231873254, 47234042415, 47234045520, 47234050891] +--- +*Why:* running every TPM command inside tpm-crb's START write took −30.4 ms off the first login and was rejected for holding the BQL for swtpm's whole time (#851, lever 3). *Done:* qemu/patches/0013 hands the command to the thread pool as before and waits up to 1 ms, BQL held, for the worker; a command answered within it completes before the write returns, a slower one on the main loop as before (#860). The build holds both halves under qtest: short TPM2_GetRandom commands are done when the write returns, and with swtpm stopped the write returns and the command completes once it runs. *Measured* (bench, spin's shape, the release's image, main's kernel and QEMU of parts run 47231873254 against the same with 0013, parts run 47231867269, shirudo 412dc8f3, 2026-12-03): the first login −13.3 [−19.9, −6.7], p50/p95 915/952 to 901/928 (lab 47234042415, 60 a side); restored within noise, +1.4 [−0.1, +4.3] evicted and −0.1 [−1.4, +2.8] cached (lab 47234045520, 20 a side). The ledger with the TPM kprobes (lab 47234050891, 5 a side): a boot's 326 commands slept in `tpm_transmit` 23 times instead of 326, and spent 87.5 ms there instead of 133.8. The ones that still slept were the boot's first, before the pool had a worker, and those longer than the bound, up to 2.2 ms. No command on this login's path took over 20 ms, so no RSA primary was among them. *Status:* carried. diff --git a/qemu/README.md b/qemu/README.md index 166d216a..9660b256 100644 --- a/qemu/README.md +++ b/qemu/README.md @@ -29,6 +29,7 @@ posted upstream. | 0010 | `-userfaultfd PATH`: the device postcopy makes its userfaultfds from is opened through `qemu_open`, so `/dev/fdset/N` works, opened for each userfaultfd and closed once it is made. `machine.QEMU.Resume` hands a fast load the descriptor it opened with `add-fd` and takes it back with `remove-fd` before it returns, so QEMU holds the device only while that load starts, and a load in full is never handed it (#789). A QEMU run as a user of its own loads fast with `/dev/userfaultfd` root's 0600 and `vm.unprivileged_userfaultfd` 0, and no other process on the host is granted either (spin-stack/spin#1711). Upstream has no way to hand QEMU the device (qemu-devel's 2023 `/dev/userfaultfd` series opens it by path) | correctness: a fast load without granting userfaultfd to the host | the build: postcopy-ram on a held TCG restore handed /dev/null for the device is refused with ENOTTY, which neither the device by path nor the system call answers, and asked again once the set is removed finds none (ENOENT); `boot:fastload`: a QEMU run as nobody loads a 1.7 GiB state fast with the device open to root alone and the sysctl 0 | | 0011 | A fast load's fault thread and eager thread place pages without allocating: each page is read with `qio_channel_pread`, where `qemu_get_buffer_at` allocated an iovec in `qio_channel_preadv_all_eof`, and a faulting page is placed without adding it to `page_requested`, a GTree, which is for pages asked of a source. musl's malloc has one lock for every thread. io_uring runs a read that missed the host's page cache again from task work on QEMU's main thread, the disks' submitter, at whatever instruction that thread had reached, malloc's included, and the read's copy into a guest page not placed yet waits for the fault thread. The fault thread waited for malloc's lock, the guest's vCPUs for pages nobody placed, and the monitors answered nothing (spin-stack/spin#1747). postcopy-blocktime no longer counts a fast load's faults, as its accounting allocates too | correctness: without it, each of three runs of `boot:fastload-reads` stopped at its first load (labs 46015140066, 46016828489, 46016833115) and spin's suspend and resume loop stopped at 8 of 608 fast loads (kvm.yml 46004238975, 46014308166, 46018501292); with it, 35 of 35 lane loads (labs 46015145265, 46016838150, 46019688290, compat 46019149732) and 299 of 299 loop loads (kvm.yml 46018501292) read to their end. restore-first within noise (lab 46014684857) | `boot:fastload-reads` (compat.yml, five loads): a guest reading its disk through fast loads made long and cold (QEMU's reads through io.max, the disk dropped from the host's cache every 100 ms, query-blockstats meanwhile) reads on, and its state is read to its end every time | | 0012 | tpm-crb's command buffer is a page of its own at 0xFED41000, which KVM maps, named in the control area and in a second `_CRS` resource of the DSDT; its size stays 0xF80. At 0x80 in the registers' page it had no memory slot, and each 4-byte store of a command was a full exit, 14,002 a boot on the shirudo machine (#851). Its RAM block is renamed `tpm-crb-buffer`, so a migration across the two layouts is refused, and a machine with a TPM refuses a checkpoint from before (`ram tpm-crb-cmd`) | the shirudo machine's cold −350.8 [−377.0, −314.7], 1730 to 1379 ms (lab 46274812245), and −193.9 [−207.9, −181.9] with shirudo 88f9888 (lab 46276747177); its time in `tpm_transmit` 537 to 239 ms a boot (lab 46274837561), `memcpy_toio`'s exits 14,002 to 0 (lab 46274837821); restored within noise (labs 46274837838, 46276747157) | the build: a held TCG machine with the swtpm it built maps a page of RAM at 0xFED41000 and nothing of the buffer at 0x80, and its control area names 0xFED41000; `boot:record`: a machine with a TPM is refused by one without, by `ram tpm-crb-buffer` | +| 0013 | tpm-crb's START write hands the command to the thread pool as before, then waits up to 1 ms, BQL held, for the worker: a command swtpm answers within it completes before the write returns, so the guest's first status read finds it done and the guest does not sleep; a slower one, or a TPM that does not answer, completes on the main loop as before. The thread pool makes a missing worker from the main loop, so the first command after 10 s idle waits out the bound (#860) | the shirudo machine's cold −13.3 [−19.9, −6.7], p50 915 to 901 ms (lab 47234042415, 60 a side); restored within noise (lab 47234045520); a boot's 326 commands slept in `tpm_transmit` 23 times instead of 326, 133.8 to 87.5 ms there (ledger with the TPM kprobes, lab 47234050891) | the build: under qtest, with the swtpm it built, short TPM2_GetRandom commands are done when the write that started them returns, and with swtpm stopped the write returns and the command completes once it runs | `docs/boot-time.md`, "What the machine carries", says what each earns among everything else the machine carries. The qemu entry of `versions.yaml` says what a bump runs. diff --git a/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch b/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch index 6fd5161a..3e0a4011 100644 --- a/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch +++ b/qemu/patches/0013-hw-tpm-crb-complete-a-command-inside-the-start-write.patch @@ -31,6 +31,18 @@ loop, which cannot run while the vCPU holds the BQL, so the first command after the pool's 10 s idle timeout waits out the bound and completes as before. +Measured in a nested KVM guest (Xeon 6975P-C, one vCPU, 2048 MiB, +swtpm and libtpms 0.10.2, Linux 7.4-rc5) whose boot sends 326 TPM +commands before its first SSH login, against the same machine without +this patch, 2026-12-03. The guest's task slept in tpm_transmit() in 23 +commands a boot instead of all 326, and spent 87.5 ms there instead of +133.8, a command 0.20 ms instead of 0.30 at the median (5 boots each). +The commands that still slept were the boot's first, before the pool +had a worker, and those swtpm took longer than the bound to answer. +The first SSH login came 13.3 ms sooner at the median of 60 boots each, +95% interval [6.7, 19.9]; a guest restored from a checkpoint logged in +as soon as before. + Local patch for this machine. Not upstream. Assisted-by: LLM