Repository navigation
Boot sources: the loader hands firmware's device paths, the kernel keeps them, userland resolves @boot - #1027
Merged
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every metal test image pinned usbd to one boot controller per bench (
pci:0c:03:30/8086:a0edfor the T14,pci:0c:03:30/1022:1639@03:00.3for the AMD bench). With the AMD's stick in its USB-C port (03:00.4), no usbd drove it, no disk was served, and the readback had noBoot: complete.Rounds 1 and 2 fixed this by having the kernel mark the boot controller in its inventory. The owner's ruling on item 63 moves that interpretation out of the kernel:
Round 3 implements that division.
Resulting behaviour
Loader (
loader/src/bootsource.rs). Before boot services end, it captures two sources:rootimage::boot_disk).For each source the loader:
toyos_devicepath::Path::parse);GetLocation().A source that has no path, a path that is too long or malformed, or no PCI function on its path, is said by name and carried as absent. Nothing is guessed. The loader logs, for example:
Boot source: the loader came off PciRoot(0x0)/Pci(0x1,0x0)/NVMe(0x1,00-…)/HD(2,GPT,C3FA1073-…,0x40800,0x11000), on PCI 0000:00:01.0.New pure crate
toyos-devicepath(lib/devicepath). It does a bounded, validating walk of UEFI device path bytes. A node shorter than its header, a node past the bytes, no End node, bytes after the End node and multi-instance paths are each refused by name. It decodes the nodes a boot source is made of: ACPI, PCI, USB, SATA, NVMe and HARDDRIVE. It also renders the UEFI text form. The loader'sHardDrivedecoder moved here, so there is one decoder.ABI.
KernelArgs::boot_sources: BootSources { loader, slot }replacesboot_function.BootSourceholds the path bytes, its length, and the controller.SYS_BOOT_SOURCES(136) answers the struct whole underRights::INVENTORY. All three structs areuser_safe!.Unwritten) rather than panicking, so the kernel and a reader both refuse it at their own boundary.Kernel (
kernel/src/loaded.rs). At handoff it checks each source. Any of the following panics with the reason, because they are loader bugs:presentout of range;The kernel then keeps the sources unchanged and answers them. It interprets no path.
Pci::boot_path, inventory byte 14, the inventory marking and the kernel'sboot: firmware loaded this boot throughline are all removed.Supervisor (
toyos_supervisor::boot, pure). It reads the sources once at start and says one line per source, the path in text form plus its controller. It then says eithersupervisor: \@boot` is PCI bb:dd.f (segment s)(toyos_manifest::device::BOOT_SAID) or why@boot` names nothing.@bootis the controller of the loader's own source only. The slot volume's controller is said but never used for@boot.PciMatch::matchesnow takes that controller as an argument. With none,@bootmatches nothing.Drives::decideandclaims::functionpass it through.Provenance, not authority. Nothing grants on a path or GUID. Storage still resolves partitions by the GUIDs the loader names (nvme: every image drives NVMe by its class, and a host's disk is left alone #1031), diskserver still refuses duplicate GUIDs, and the slot's signature still covers every byte read. usbd does not yet match the USB nodes of the path to the device it enumerates: nothing needs that today, and the ruling asks for no speculative transports.
Test images. Unchanged from round 2: the usbd row is
["pci:0c:03:30/1033:0194", "pci:0c:03:30@boot"]. Twodrivesentries of one row may still overlap.Judges.
spare_xhciandusbd_serves_the_boot_stickread the supervisor's@bootline from the programs' log.usbd_serves_the_boot_sticknow also requires that the controller serving the stick is the@bootone, and it prints both source lines.Harness. A boot that times out now prints the 16550's file as well as the console. Without it, a kernel that panics before virtio-console arrives timed out with "nothing at all" (the first run of the path control below).
Checks
Head
618588db7, base7eefbcb0b, macOS aarch64 host.17c0367f7isfbf436e04rebased over #1028; #1028 touched onlytoyos-metal, and the tree delta is identical.fbf436e04is949d59456plus the clippy fix in a test.cargo run -- --ci hostatfbf436e04: exit 0, "101 step(s), all green". The earlier run at949d59456was red only on clippy'sredundant_cloneinlib/devicepath's test.cargo run -- --build-onlyat949d59456: exit 0.949d59456:cargo test --test toyos-build -- the_log_lands_on_the_boot_stick usbd_drives_the_spare nvme_disk_boots a_usb_key_reaches_the_console a_bent_supervisor_is_refused_and_the_other_slot_boots virt_wall_clock_utc: exit 0, 6/6. That covers x86-64 (stick, NVMe and spare profiles) and AArch64 (virt_wall_clock_utc, and the bent-supervisor test on both architectures).toyos-devicepath: firmware paths decode and render. Every hostile shape is refused by name: empty, unterminated, truncated header, a zero or 3-byte node, a length past the bytes, a second instance, bytes after End, and an End with data.toyos-abi: the accessors, plus the refusal ofpath_len513 and 65535 and ofpresent2.toyos-supervisor::boot: the loader's controller is@boot. A slot volume's controller is said but not taken. Each hostile source names nothing and says why: an over-long length, an unterminated path, a zero-length node,present2, and no path.toyos-manifest:@bootmatches only the controller given, nothing when given none, and keeps its class.agents/usbd-boot/r3/controls.sh). Each patch was checked withgit apply --check, built, run, and reverted in the same run. They ran at the pre-commit tree of round 3, whose code is this head's apart from the judge, the harness message and the clippy fix.["pci:0c:03:30@boot"].the_log_lands_on_the_boot_stickexits 0. The chain from loader to kernel to syscall to supervisor alone puts usbd on QEMU's stick controller.None. Exit 1,STALLED: waiting for usbd to serve the boot stick.nvme_disk_bootsexits 1. The 16550 showsPANIC: … kernel/src/loaded.rs … boot: the loader handed the loader source, and bytes follow the End node at byte 76, so the kernel's check fires.PciRoot(0x0)/Pci(0x1,0x0)/NVMe(0x1,00-00-00-00-00-00-00-00)for its boot option, and the loader's rendering of the path it captured begins with the same nodes.Evidence: https://github.com/ToyOSOrg/evidence/tree/1386018208b1bfb58d9b2b5ad1206302d476c4d7/618588db7
A fix to main, superseded
tests: launch_unsent_stdio names each descriptor's kind(618588db7) repaired main'stests/guest/rust-testsbuild after #1012. #1024 carries the same fix, and this commit drops at rebase.Metal
Both runs used
testcasesat618588db7, flashed with main'stoyos-metalat 7eefbcb. Both verdicts passed.usbd_serves_the_boot_stick,amdvi_remaps_the_stick_controllerandamdvi_usbd_drives_its_own_entry.PciRoot(0x0)/Pci(0x8,0x1)/Pci(0x0,0x4)/USB(0x4,0x0)/HD(1,GPT,…), on PCI 03:00.4.@bootas 03:00.4, and usbd drove that controller.usbd_serves_the_boot_stickandusbd_drives_the_type_c_controller.PciRoot(0x0)/Pci(0x14,0x0)/USB(0x0,0x0)/HD(1,GPT,…), on 00:14.0, and@bootwas 00:14.0.Both paths parse within the 512-byte bound.
Not established
@bootnames nothing and a test image drives only QEMU's controller by id. That is explicit, not guessed.Round 4 (
cfe67a96b, base8d96a8a8b)DevicePath::path()walks at mostDEVICE_PATH_BYTESand holds the result toPath::parse. A failure is refused by name (Unread).boot_partition,boot_disk, bootnext's partition lookup and the boot sources all use it.nodes()is deleted, so theloader/Cargo.tomlcomment is now true.toyos-devicepathand the AMD fixture intoyos_supervisor::bootuse the nodes those firmwares named on the 618588d bench runs.Node::decode,KnownandHEADERare now private. The other two suggestions are declined:OnceLockstays.launch_unsent_stdiocommit was dropped; spawn: a plain spawn is a helper, and a launch is asked for #1024 carries that fix. One doc-comment conflict, with session: a login is a session under its owner #1035'ssessionsmodule, is resolved inlifecycle/src/lib.rs.cfe67a96b:cargo run -- --ci host: exit 0, 102 steps green.--build-only: exit 0.the_log_lands_on_the_boot_stick nvme_disk_boots a_bent_supervisor_is_refused_and_the_other_slot_boots virt_wall_clock_utc a_host_disk_beside_the_stick_is_left_alone: exit 0, 5/5 on x86-64 and AArch64.boot_diskandboot_partition, pass.Rebase onto #1039 and #1040 (
9e6beea46, basefc8875cd3)SYS_MACHINE_STOPS:SYS_BOOT_SOURCESis now 137 andSYSCALL_PROFILE_BINSis 139. The profile assert names the highest number.dispatch.rsimports both handlers.lifecycle/src/lib.rsheader names bothstopandboot.git range-diffagainstcfe67a96bshows no difference outside those hunks. The loader,kernel/src/loaded.rs,lib/devicepathandtoyos_supervisor::bootare identical.9e6beea46:--ci host: exit 0, 102 steps.--build-only: exit 0.the_log_lands_on_the_boot_stickandnvme_disk_bootson x86-64, andvirt_wall_clock_utcon AArch64. Exit 0, 3/3.cfe67a96bstill holds for the boot-source and loader code, which this rebase did not change. The renumbered syscall is one ABI constant that kernel and supervisor both compile fromtoyos-abi. QEMU's stick boot exercises it, since the supervisor reads the sources before@bootserves the stick.git merge-treemerges them cleanly.🤖 Generated with Claude Code