Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion qemu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand All @@ -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 \
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion qemu/qboot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
18 changes: 18 additions & 0 deletions qemu/qboot/no-pci-walk.patch
Original file line number Diff line number Diff line change
@@ -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();
}