From 52c81a42bb0ed0dd968e73ff2ee2c1480e3ab3a9 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 19 Nov 2026 13:32:34 -0300 Subject: [PATCH] qboot: no walk of the PCI bus qboot read each function's interrupt pin and class, wrote an INTx line into PCI_INTERRUPT_LINE and numbered bridges; it never assigned BARs. Nothing here reads what it left: Linux routes interrupts from ACPI's _PRT, every device it drives uses MSI-X, bus 0 has no bridge. The walk was 173 config-space exits, 5.0 ms nested against 2.2 on metal (boot:firmware-stages, labs 44535161371, 44535156851). The build asserts the patch is in the tree it compiled; boot:firmware (vmgenid, restore), boot:roms, boot:logind, boot:hotadd and boot:lockdown pass. Co-Authored-By: Claude Opus 5.5 --- qemu/Dockerfile | 4 +++- qemu/qboot/README.md | 12 +++++++++++- qemu/qboot/no-pci-walk.patch | 18 ++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 qemu/qboot/no-pci-walk.patch diff --git a/qemu/Dockerfile b/qemu/Dockerfile index 9451b33..83e2041 100644 --- a/qemu/Dockerfile +++ b/qemu/Dockerfile @@ -501,7 +501,7 @@ RUN git clone --quiet --branch "${QBOOT_VERSION}" https://github.com/bonzini/qbo git -C upstream archive "${QBOOT_COMMIT}" > upstream.tar && \ echo "${QBOOT_ARCHIVE_SHA256} upstream.tar" | sha256sum -c - -COPY qemu/qboot/write-pointer.patch qemu/qboot/pam.patch qemu/qboot/mtrr.patch /build/ +COPY qemu/qboot/write-pointer.patch qemu/qboot/pam.patch qemu/qboot/mtrr.patch qemu/qboot/no-pci-walk.patch /build/ # Upstream's meson.build flags, with -Os fixed rather than taken from a build type. RUN set -eux; \ @@ -510,6 +510,7 @@ RUN set -eux; \ patch -p1 --fuzz=0 -d src < write-pointer.patch; \ patch -p1 --fuzz=0 -d src < pam.patch; \ patch -p1 --fuzz=0 -d src < mtrr.patch; \ + patch -p1 --fuzz=0 -d src < no-pci-walk.patch; \ cd src; \ for f in *.c *.S; do \ gcc -Os -m32 -march=i386 -mregparm=3 -fno-stack-protector \ @@ -532,6 +533,7 @@ RUN set -eux; \ grep -q 'CMD_WRITE_PTR' src/tables.c && grep -q 'fw_cfg_write_file' src/fw_cfg.c || { echo "the WRITE_POINTER patch is not in the tree that was compiled" >&2; exit 1; }; \ grep -q '0x33333330' src/hwsetup.c || { echo "the PAM patch is not in the tree that was compiled" >&2; exit 1; }; \ grep -q 'setup_mtrr();' src/main.c || { echo "the MTRR patch is not in the tree that was compiled" >&2; exit 1; }; \ + ! grep -q '^ do_setup_pci_bus();$' src/pci.c && grep -q 'spin-machine: no walk of the bus' src/pci.c || { echo "the no-PCI-walk patch is not in the tree that was compiled" >&2; exit 1; }; \ sha256sum /build/qboot.bin # The runtime image: the binaries and the firmware on a base that exists only so a human can diff --git a/qemu/qboot/README.md b/qemu/qboot/README.md index e6dbf18..7a46c06 100644 --- a/qemu/qboot/README.md +++ b/qemu/qboot/README.md @@ -34,12 +34,22 @@ write-back by default, and the 32-bit PCI hole, from the top of low RAM to 4 GiB naturally aligned power-of-two ranges. Fixed-range MTRRs stay off. If the hole does not fit the variable ranges the CPU has, they are left disabled rather than caching MMIO. +## No walk of the PCI bus + +Stock qboot walks the bus at every boot: it reads each function's interrupt pin and class, +writes an INTx line into its `PCI_INTERRUPT_LINE`, and numbers bridges. It does not assign BARs; +Linux does. Nothing on this machine reads what the walk leaves: Linux routes interrupts from +ACPI's `_PRT`, every device it drives uses MSI-X, and bus 0 carries no bridge. The walk was 173 +configuration-space exits, 5.0 ms on nested KVM against 2.2 on bare metal (boot:firmware-stages, +lab runs 44535161371 and 44535156851, 2026-11-19). `no-pci-walk.patch` keeps the chipset check, +MMCONFIG and the BIOS32 entry, and drops the walk. + ## Build `task qemu:build` builds it, in the `qboot` stage of `qemu/Dockerfile`, and it lands beside the SeaBIOS blobs as `_output/qemu/qboot.bin`, where a release, `task qemu:fetch` and CI all find it. The stage clones the pinned commit, verifies the SHA-256 of the tar `git archive` -writes for it, applies `write-pointer.patch`, `pam.patch` and `mtrr.patch` with no fuzz, and compiles with upstream's +writes for it, applies `write-pointer.patch`, `pam.patch`, `mtrr.patch` and `no-pci-walk.patch` with no fuzz, and compiles with upstream's meson.build flags plus `-Os`. It asserts on what came out: 65536 bytes, the ROM window it is linked for, and the patch's code in the tree that was compiled. diff --git a/qemu/qboot/no-pci-walk.patch b/qemu/qboot/no-pci-walk.patch new file mode 100644 index 0000000..6ac235d --- /dev/null +++ b/qemu/qboot/no-pci-walk.patch @@ -0,0 +1,18 @@ +diff --git a/pci.c b/pci.c +index 63ebda6..f56b938 100644 +--- a/pci.c ++++ b/pci.c +@@ -172,6 +172,12 @@ void setup_pci(void) + else + panic(); + +- do_setup_pci_bus(); ++ /* ++ * spin-machine: no walk of the bus. What it did - an INTx line written into each function's ++ * PCI_INTERRUPT_LINE, and bridges numbered - nothing on this machine reads: Linux routes ++ * interrupts from ACPI's _PRT, every device it drives uses MSI-X, and bus 0 carries no ++ * bridge. The walk was 173 config-space exits, 5.0 ms on nested KVM against 2.2 on metal ++ * (boot:firmware-stages, lab runs 44535161371 and 44535156851, 2026-11-19). ++ */ + setup_bios32(); + }