Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c97ab1169 | ||
|
|
2070cf63c5 | ||
|
|
09b0b614f7 |
No files matched your search
@@ -0,0 +1,2 @@
|
||||
# Unified diffs use a leading space for unchanged blank lines.
|
||||
*.patch text eol=lf whitespace=-blank-at-eol
|
||||
@@ -0,0 +1,2 @@
|
||||
/target/
|
||||
/runs/
|
||||
Generated
+711
@@ -0,0 +1,711 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85c097ce94629611e0a15ef1078a2fe2ce3b4a0f4b44708e85eeb09dd5f188eb"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c7a9e344b352bef7873e51ff425c2f90d5aa2a252db2b84289c93ff30beb3d7"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0571a23d2188b4aae7adc1df454cc81d6232cf37674fa717ac119f6c74d0dc1"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76a5cf9d05ffa9c878c447b33b069605e890ebcd36d2761f86367873c2ecaa7f"
|
||||
dependencies = [
|
||||
"windows-sys 0.101.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2c2d00c1b2d84cef823d89d4da02ad8ff1e76c969e029da990b40f16dc834221"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys 0.101.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cb931c189b85683d69a5cfad41d4d418671e1ac413dd209f3f2fc31e3cfd902"
|
||||
|
||||
[[package]]
|
||||
name = "bincode"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
|
||||
dependencies = [
|
||||
"bincode_derive",
|
||||
"serde",
|
||||
"unty",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bincode_derive"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
|
||||
dependencies = [
|
||||
"virtue",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb2907cc03d08cdb1c6724ad0670ce67c4a71e1c45a6d7635224011714cfc4b1"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.13.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34fb07aac3b9f547c7af8dc897dfe73c10847b6c71130c364bdd7891d979c816"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "cfg_aliases"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.6.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50066ca966813ca8957ee15361752f19424a8ff620dbe9c8993d9f99d99b04b3"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.6.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0ed97c96ef4efb3cc84e09fa388df4463e7cc3224ec38d7b1d9e45749333590"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.6.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b4c174f11f949b9ca8c60580925e282b9cbd5454750e506f08648b2038080cd7"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0921b3876b3a1df8a1c9f912e7f94342458022c2e84288015893d83c4d62a79"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f7f11958434c85b6efac08f8299dc08bd263184ce080232e2168940cda4368e"
|
||||
|
||||
[[package]]
|
||||
name = "crc"
|
||||
version = "3.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5eb8a2a1cd12ab0d987a5d5e825195d372001a4094a0376319d5a0ad71c1ba0d"
|
||||
dependencies = [
|
||||
"crc-catalog",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc-catalog"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "217698eaf96b4a3f0bc4f3662aaa55bdf913cd54d7204591faa790070c6d0853"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
|
||||
|
||||
[[package]]
|
||||
name = "fatfs"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05669f8e7e2d7badc545c513710f0eba09c2fbef683eb859fd79c46c355048e0"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"byteorder",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fscommon"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "315ce685aca5ddcc5a3e7e436ef47d4a5d0064462849b6f0f628c28140103531"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-core"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-task"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
|
||||
|
||||
[[package]]
|
||||
name = "futures-util"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-task",
|
||||
"pin-project-lite",
|
||||
"slab",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"r-efi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gptman"
|
||||
version = "2.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d5dcd4e9e48c72692b83e45284679794a7272eacd302825e6bff9abc53c6c17b"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"crc",
|
||||
"nix",
|
||||
"serde",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"futures-util",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.191"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.30.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"cfg-if",
|
||||
"cfg_aliases",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f120c8d5021b34abd2f2ffd7ee96687cbcd6c54a3e68d86b6169f4a5cd480ffe"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "743da816b98c921cdbe8628ef7381b76f25ecf4da599fc80aca90eae7ef70cc0"
|
||||
dependencies = [
|
||||
"ptr_meta_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ptr_meta_derive"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1c8d9ca532f185d5d4db7a7c9d51420b452168ea1c2b913953281bd6fe1fcbd0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "r-efi"
|
||||
version = "6.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
|
||||
|
||||
[[package]]
|
||||
name = "reims-efi-marker"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"uefi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "reims-openvmm-arm64"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"fatfs",
|
||||
"fscommon",
|
||||
"gptman",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"tempfile",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "1.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
|
||||
dependencies = [
|
||||
"serde_core",
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.154"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ucs2"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df79298e11f316400c57ec268f3c2c29ac3c4d4777687955cd3d4f3a35ce7eba"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uefi"
|
||||
version = "0.35.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da7569ceafb898907ff764629bac90ac24ba4203c38c33ef79ee88c74aa35b11"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"cfg-if",
|
||||
"log",
|
||||
"ptr_meta",
|
||||
"ucs2",
|
||||
"uefi-macros",
|
||||
"uefi-raw",
|
||||
"uguid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uefi-macros"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3dad47b3af8f99116c0f6d4d669c439487d9aaf1c8d9480d686cda6f3a8aa23"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uefi-raw"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7cad96b8baaf1615d3fdd0f03d04a0b487d857c1b51b19dcbfe05e2e3c447b78"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"uguid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uguid"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ab14ea9660d240e7865ce9d54ecdbd1cd9fa5802ae6f4512f093c7907e921533"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "unty"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "1.29.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "virtue"
|
||||
version = "0.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.10",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.130"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.101.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4e57b2aae53a240c62b65069a63eaf8d5fa747f5d0d8e670c5210a98847bce4"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link 0.2.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.101.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eed2df9f5f458664c87437f6758f0d93085b06433bf66b2b84c23c19f3d2012c"
|
||||
dependencies = [
|
||||
"windows-link 0.101.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "reims-openvmm-arm64"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[workspace]
|
||||
members = ["efi-marker"]
|
||||
default-members = ["."]
|
||||
resolver = "3"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
fatfs = { version = "0.3.6", default-features = false, features = ["std", "alloc"] }
|
||||
fscommon = "0.1"
|
||||
gptman = "2"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
uuid = { version = "1", features = ["v4"] }
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3"
|
||||
@@ -1,2 +1,40 @@
|
||||
# reims-openvmm-arm64
|
||||
OpenVMM and Stambha backend for ARM macOS guests on Windows x86-64
|
||||
|
||||
Validation and bringup harness for booting x64 Stambha EFI (`stela.efi`) and ARM64e macOS under `OpenVMM/WHP` (`MSVM.fd`).
|
||||
|
||||
## Verified Root Causes Resolved
|
||||
|
||||
1. **`native resource service unavailable` on NVMe drives (`--storage` vs `--system`)**:
|
||||
Standalone `--storage` mode invoked Stambha's probe with `NativeServices = None`. Switching the probe config to `--system` enters `engine/start.rs` with full post-EBS PCI/MMIO/DMA/IRQ service initialization.
|
||||
2. **Stambha NVMe Storage Identification (`STELAANS` + GPT Partition GUID)**:
|
||||
OpenVMM's `--nvme-pci` requires `--pcie-ecam-below-4gb`, `--pcie-root-complex rc0,low_mmio=128M,high_mmio=4G`, and explicit `serial=STELAANS`, while Stambha matches the **unique GPT Partition GUID** (not Partition Type GUID).
|
||||
3. **Host TSC Calibration (`HOST TSC hz=... source=cpuid`)**:
|
||||
`MSVM.fd` omits HPET and uses minimal ACPI FADT tables, so OpenVMM's `virt_whp` must populate CPUID leaf `0x15` (`1 / 1000 / tsc_khz`) and `0x80000007` invariant TSC.
|
||||
4. **Missing `EFI_MP_SERVICES_PROTOCOL` in `MSVM.fd`**:
|
||||
`MSVM.fd` (`mu_msvm`) does not install `EFI_MP_SERVICES_PROTOCOL`. Stambha's `native_smp/firmware.rs` fallback (`capture_from_madt`) reads enabled APIC/x2APIC processor IDs from ACPI MADT (`APIC`), synthesizes AP source snapshots from the live BSP snapshot, and brings APs up post-EBS via INIT/SIPI.
|
||||
|
||||
## Commands
|
||||
|
||||
```powershell
|
||||
# Pack a GPT FAT32 ESP image containing BOOTX64.EFI and EFI/stela/stela.cfg
|
||||
cargo +1.99.1 run -- pack --efi <stela.efi> --stambha-config <stela.cfg> --output <esp.img>
|
||||
|
||||
# Print the exact OpenVMM launch arguments
|
||||
cargo +1.99.1 run -- plan --openvmm <openvmm.exe> --firmware <MSVM.fd> --boot-image <esp.img> --boot-transport nvme --stambha-storage <disk.img> --memory-mib 8192 --vcpus 4
|
||||
|
||||
# Boot read-only storage and assert serial marker on COM1
|
||||
cargo +1.99.1 run -- run --openvmm <openvmm.exe> --firmware <MSVM.fd> --boot-image <esp.img> --boot-transport nvme --stambha-storage <disk.img> --memory-mib 8192 --vcpus 4 --log-dir <out-dir> --marker "STELA_SECTOR_VERIFY"
|
||||
|
||||
# Writable storage test (pass --stambha-storage-writable only on cloned test media)
|
||||
cargo +1.99.1 run -- run --openvmm <openvmm.exe> --firmware <MSVM.fd> --boot-image <esp-rw.img> --boot-transport nvme --stambha-storage <disk-rw.img> --stambha-storage-writable --memory-mib 8192 --vcpus 4 --log-dir <out-dir> --marker "readback_ok=true"
|
||||
```
|
||||
|
||||
## Verified Gates (4 vCPUs, 8192 MiB, `MSVM.fd` + `openvmm.exe`)
|
||||
|
||||
- **Post-EBS resource services + read-only known-sector readback**:
|
||||
- `STELA_POST_EBS|pci_cfg=OK|bar_mmio=OK|dma=OK|irq=OK|clock=OK_TSC`
|
||||
- `STELA_SECTOR_VERIFY|serial=STELAANS|lba=0..16|bytes=8192|sha256=77b2f4c2ef09f905cfce58f55ee1625dc893a2a13133b41b0dfe1368c88b71a6`
|
||||
- Clean guest ACPI S5 shutdown (`openvmm_exit_code: 0`); test disk SHA-256 unchanged.
|
||||
- **Writable sector write + NVMe flush + cold-reboot persistence**:
|
||||
- Boot 1: `STELA_SECTOR_WRITE|lba=0..16|bytes=8192|sha256=6d63a56be1e503f9622f529dea7a68c3b162d476eaf9af4bb0897f7f2a709a71|flush=OK|readback_ok=true` (`exit=0`)
|
||||
- Cold Boot 2 (read-only verify): `STELA_SECTOR_VERIFY|serial=STELAANS|lba=0..16|bytes=8192|sha256=6d63a56be1e503f9622f529dea7a68c3b162d476eaf9af4bb0897f7f2a709a71` (`exit=0`)
|
||||
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "reims-efi-marker"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[[bin]]
|
||||
name = "reims-efi-marker"
|
||||
path = "src/main.rs"
|
||||
test = false
|
||||
bench = false
|
||||
|
||||
[target.'cfg(target_os = "uefi")'.dependencies]
|
||||
uefi = { version = "0.35", features = ["panic_handler"] }
|
||||
@@ -0,0 +1,21 @@
|
||||
#![cfg_attr(target_os = "uefi", no_main)]
|
||||
#![cfg_attr(target_os = "uefi", no_std)]
|
||||
|
||||
#[cfg(target_os = "uefi")]
|
||||
use uefi::{Status, cstr16, entry, runtime, system};
|
||||
|
||||
#[cfg(target_os = "uefi")]
|
||||
#[entry]
|
||||
fn main() -> Status {
|
||||
if let Err(error) =
|
||||
system::with_stdout(|console| console.output_string(cstr16!("REIMS_EFI_HANDOFF\r\n")))
|
||||
{
|
||||
return error.status();
|
||||
}
|
||||
runtime::reset(runtime::ResetType::SHUTDOWN, Status::SUCCESS, None);
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "uefi"))]
|
||||
fn main() {
|
||||
eprintln!("build this probe for x86_64-unknown-uefi");
|
||||
}
|
||||
@@ -0,0 +1,562 @@
|
||||
diff --git a/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs b/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs
|
||||
index 0c372a7..92bd6ae 100644
|
||||
--- a/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs
|
||||
+++ b/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs
|
||||
@@ -1470,6 +1470,7 @@ async fn make_nvme_controller_config(
|
||||
max_io_queues: 64,
|
||||
msix_count: 64,
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
})
|
||||
diff --git a/openvmm/openvmm_entry/src/cli_args.rs b/openvmm/openvmm_entry/src/cli_args.rs
|
||||
index 8a4c76c..adab02b 100644
|
||||
--- a/openvmm/openvmm_entry/src/cli_args.rs
|
||||
+++ b/openvmm/openvmm_entry/src/cli_args.rs
|
||||
@@ -498,6 +498,7 @@ pub struct Options {
|
||||
`id=<name>` controller name (required)
|
||||
`pcie_port=<port>` present on PCIe under the specified port
|
||||
`vpci[=<guid>]` present via VPCI; optional instance GUID
|
||||
+ `serial=<value>` 1-20 printable ASCII bytes except comma and brackets
|
||||
`vtl2` assign to VTL2 (default VTL0)
|
||||
|
||||
Exactly one of `pcie_port` or `vpci` must be specified.
|
||||
@@ -2735,11 +2736,36 @@ pub struct NvmeControllerCli {
|
||||
/// Transport configuration.
|
||||
#[kv(flatten)]
|
||||
pub transport: NvmeControllerTransport,
|
||||
+ /// Guest-visible serial number.
|
||||
+ pub serial: Option<NvmeSerialCli>,
|
||||
/// VTL assignment (default VTL0).
|
||||
#[kv(flag, key = "vtl2", present = DeviceVtl::Vtl2, absent = DeviceVtl::Vtl0)]
|
||||
pub vtl: DeviceVtl,
|
||||
}
|
||||
|
||||
+/// A printable, space-padded NVMe controller serial number.
|
||||
+#[derive(Clone, Copy, Debug)]
|
||||
+pub struct NvmeSerialCli(pub [u8; 20]);
|
||||
+
|
||||
+impl FromStr for NvmeSerialCli {
|
||||
+ type Err = String;
|
||||
+
|
||||
+ fn from_str(serial: &str) -> Result<Self, Self::Err> {
|
||||
+ let mut padded = [b' '; 20];
|
||||
+ if !(1..=padded.len()).contains(&serial.len())
|
||||
+ || !serial
|
||||
+ .bytes()
|
||||
+ .all(|byte| (b' '..=b'~').contains(&byte) && !matches!(byte, b',' | b'[' | b']'))
|
||||
+ {
|
||||
+ return Err(
|
||||
+ "serial must be 1-20 printable ASCII bytes without commas or brackets".into(),
|
||||
+ );
|
||||
+ }
|
||||
+ padded[..serial.len()].copy_from_slice(serial.as_bytes());
|
||||
+ Ok(Self(padded))
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
/// CLI arguments for a named VMBus SCSI controller.
|
||||
#[derive(Clone, Debug, vmm_cli::KeyValueArgs)]
|
||||
pub struct ScsiControllerCli {
|
||||
@@ -6832,6 +6858,23 @@ fn test_nvme_controller_cli_pcie() {
|
||||
let c = NvmeControllerCli::from_str("id=nvme0,pcie_port=p0").unwrap();
|
||||
assert_eq!(c.id, "nvme0");
|
||||
assert_eq!(c.transport, NvmeControllerTransport::Pcie("p0".into()));
|
||||
+ assert!(c.serial.is_none());
|
||||
+ }
|
||||
+
|
||||
+ #[test]
|
||||
+ fn test_nvme_controller_cli_serial() {
|
||||
+ let controller =
|
||||
+ NvmeControllerCli::from_str("id=nvme0,pcie_port=p0,serial=STELAMEDIA").unwrap();
|
||||
+ assert_eq!(controller.serial.unwrap().0, *b"STELAMEDIA ");
|
||||
+ let controller =
|
||||
+ NvmeControllerCli::from_str("id=nvme0,pcie_port=p0,serial=12345678901234567890")
|
||||
+ .unwrap();
|
||||
+ assert_eq!(controller.serial.unwrap().0, *b"12345678901234567890");
|
||||
+
|
||||
+ for serial in ["", "123456789012345678901", "tab\t", "é", "[nested]", "x,y"] {
|
||||
+ let arg = format!("id=nvme0,pcie_port=p0,serial={serial}");
|
||||
+ assert!(NvmeControllerCli::from_str(&arg).is_err(), "{serial:?}");
|
||||
+ }
|
||||
}
|
||||
|
||||
#[test]
|
||||
diff --git a/openvmm/openvmm_entry/src/lib.rs b/openvmm/openvmm_entry/src/lib.rs
|
||||
index b24447d..e5c016d 100644
|
||||
--- a/openvmm/openvmm_entry/src/lib.rs
|
||||
+++ b/openvmm/openvmm_entry/src/lib.rs
|
||||
@@ -604,7 +604,13 @@ async fn vm_config_from_command_line(
|
||||
storage_builder::NvmeControllerTransport::Vpci(guid)
|
||||
}
|
||||
};
|
||||
- storage.add_nvme_controller(ctrl.id.clone(), ctrl.vtl, transport, None)?;
|
||||
+ storage.add_nvme_controller(
|
||||
+ ctrl.id.clone(),
|
||||
+ ctrl.vtl,
|
||||
+ transport,
|
||||
+ ctrl.serial.map(|serial| serial.0),
|
||||
+ None,
|
||||
+ )?;
|
||||
}
|
||||
|
||||
for ctrl in &opt.vmbus_scsi {
|
||||
@@ -726,6 +732,7 @@ async fn vm_config_from_command_line(
|
||||
DeviceVtl::Vtl0,
|
||||
storage_builder::NvmeControllerTransport::Pcie(port.clone()),
|
||||
None,
|
||||
+ None,
|
||||
).with_context(|| format!(
|
||||
"legacy --nvme flag conflicts with an explicit controller named '{port}'; \
|
||||
use --nvme-pci and --disk on=<name> instead"
|
||||
diff --git a/openvmm/openvmm_entry/src/storage_builder.rs b/openvmm/openvmm_entry/src/storage_builder.rs
|
||||
index 1607373..87ad3f7 100644
|
||||
--- a/openvmm/openvmm_entry/src/storage_builder.rs
|
||||
+++ b/openvmm/openvmm_entry/src/storage_builder.rs
|
||||
@@ -81,6 +81,7 @@ struct NvmeControllerEntry {
|
||||
vtl: DeviceVtl,
|
||||
transport: NvmeControllerTransport,
|
||||
namespaces: Vec<NamespaceDefinition>,
|
||||
+ serial_number: Option<[u8; 20]>,
|
||||
/// Optional pre-created channel for runtime namespace add/remove.
|
||||
requests: Option<mesh::Receiver<NvmeControllerRequest>>,
|
||||
}
|
||||
@@ -241,6 +242,7 @@ pub fn add_nvme_controller(
|
||||
name: String,
|
||||
vtl: DeviceVtl,
|
||||
transport: NvmeControllerTransport,
|
||||
+ serial_number: Option<[u8; 20]>,
|
||||
requests: Option<mesh::Receiver<NvmeControllerRequest>>,
|
||||
) -> anyhow::Result<()> {
|
||||
if let Some(existing) = self.controllers.get(&name) {
|
||||
@@ -258,6 +260,7 @@ pub fn add_nvme_controller(
|
||||
vtl,
|
||||
transport,
|
||||
namespaces: Vec::new(),
|
||||
+ serial_number,
|
||||
requests,
|
||||
}),
|
||||
);
|
||||
@@ -819,6 +822,7 @@ pub fn build_config(
|
||||
max_io_queues: 64,
|
||||
msix_count: 64,
|
||||
requests: ctrl.requests,
|
||||
+ serial_number: ctrl.serial_number,
|
||||
}
|
||||
.into_resource(),
|
||||
});
|
||||
@@ -833,6 +837,7 @@ pub fn build_config(
|
||||
max_io_queues: 64,
|
||||
msix_count: 64,
|
||||
requests: ctrl.requests,
|
||||
+ serial_number: ctrl.serial_number,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
@@ -863,6 +868,7 @@ pub fn build_config(
|
||||
max_io_queues: 64,
|
||||
msix_count: 64,
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
@@ -901,6 +907,7 @@ pub fn build_config(
|
||||
max_io_queues: 64,
|
||||
msix_count: 64,
|
||||
requests: Some(recv),
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
diff --git a/openvmm/openvmm_entry/src/ttrpc/mod.rs b/openvmm/openvmm_entry/src/ttrpc/mod.rs
|
||||
index 1e4d5e6..f09c1c5 100644
|
||||
--- a/openvmm/openvmm_entry/src/ttrpc/mod.rs
|
||||
+++ b/openvmm/openvmm_entry/src/ttrpc/mod.rs
|
||||
@@ -3029,6 +3029,7 @@ async fn build_nvme_controller(
|
||||
max_io_queues: 64,
|
||||
namespaces,
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource())
|
||||
}
|
||||
diff --git a/petri/src/vm/openvmm/construct.rs b/petri/src/vm/openvmm/construct.rs
|
||||
index 71e5211..b1ccc3a 100644
|
||||
--- a/petri/src/vm/openvmm/construct.rs
|
||||
+++ b/petri/src/vm/openvmm/construct.rs
|
||||
@@ -302,6 +302,7 @@ pub async fn new(
|
||||
disk,
|
||||
}],
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
});
|
||||
@@ -1598,6 +1599,7 @@ async fn vmbus_storage_controllers_to_openvmm(
|
||||
msix_count: 64,
|
||||
namespaces,
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
diff --git a/petri/src/vm/openvmm/modify.rs b/petri/src/vm/openvmm/modify.rs
|
||||
index e797720..4e614e6 100644
|
||||
--- a/petri/src/vm/openvmm/modify.rs
|
||||
+++ b/petri/src/vm/openvmm/modify.rs
|
||||
@@ -259,6 +259,7 @@ pub fn with_pcie_nvme(mut self, port_name: &str, subsystem_id: Guid) -> Self {
|
||||
read_only: false,
|
||||
}],
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
});
|
||||
diff --git a/vm/devices/storage/nvme/src/pci.rs b/vm/devices/storage/nvme/src/pci.rs
|
||||
index f47381e..f596536 100644
|
||||
--- a/vm/devices/storage/nvme/src/pci.rs
|
||||
+++ b/vm/devices/storage/nvme/src/pci.rs
|
||||
@@ -115,6 +115,16 @@ pub fn new(
|
||||
dma_target: &DmaTarget,
|
||||
register_mmio: &mut dyn RegisterMmioIntercept,
|
||||
caps: NvmeControllerCaps,
|
||||
+ ) -> Self {
|
||||
+ Self::new_with_serial(driver_source, dma_target, register_mmio, caps, None)
|
||||
+ }
|
||||
+
|
||||
+ pub(crate) fn new_with_serial(
|
||||
+ driver_source: &VmTaskDriverSource,
|
||||
+ dma_target: &DmaTarget,
|
||||
+ register_mmio: &mut dyn RegisterMmioIntercept,
|
||||
+ caps: NvmeControllerCaps,
|
||||
+ serial_number: Option<[u8; 20]>,
|
||||
) -> Self {
|
||||
let msi_target = dma_target.msi_target();
|
||||
let guest_memory = dma_target.guest_memory().clone();
|
||||
@@ -160,10 +170,9 @@ pub fn new(
|
||||
driver_source,
|
||||
guest_memory,
|
||||
interrupts,
|
||||
- caps.max_io_queues,
|
||||
- caps.max_io_queues,
|
||||
Arc::clone(&qe_sizes),
|
||||
- caps.subsystem_id,
|
||||
+ &caps,
|
||||
+ serial_number.unwrap_or(*b"SN: 000001 "),
|
||||
);
|
||||
|
||||
Self {
|
||||
diff --git a/vm/devices/storage/nvme/src/resolver.rs b/vm/devices/storage/nvme/src/resolver.rs
|
||||
index d6b989c..543bbf1 100644
|
||||
--- a/vm/devices/storage/nvme/src/resolver.rs
|
||||
+++ b/vm/devices/storage/nvme/src/resolver.rs
|
||||
@@ -58,7 +58,7 @@ async fn resolve(
|
||||
resource: NvmeControllerHandle,
|
||||
input: ResolvePciDeviceHandleParams<'_>,
|
||||
) -> Result<Self::Output, Self::Error> {
|
||||
- let controller = NvmeController::new(
|
||||
+ let controller = NvmeController::new_with_serial(
|
||||
input.driver_source,
|
||||
input.dma_target,
|
||||
input.register_mmio,
|
||||
@@ -67,6 +67,7 @@ async fn resolve(
|
||||
max_io_queues: resource.max_io_queues,
|
||||
subsystem_id: resource.subsystem_id,
|
||||
},
|
||||
+ resource.serial_number,
|
||||
);
|
||||
for NamespaceDefinition {
|
||||
nsid,
|
||||
diff --git a/vm/devices/storage/nvme/src/tests/controller_tests.rs b/vm/devices/storage/nvme/src/tests/controller_tests.rs
|
||||
index 0900279..d5d1e1f 100644
|
||||
--- a/vm/devices/storage/nvme/src/tests/controller_tests.rs
|
||||
+++ b/vm/devices/storage/nvme/src/tests/controller_tests.rs
|
||||
@@ -39,12 +39,13 @@ fn instantiate_controller(
|
||||
driver: DefaultDriver,
|
||||
gm: &GuestMemory,
|
||||
int_controller: Option<&TestPciInterruptController>,
|
||||
+ serial_number: Option<[u8; 20]>,
|
||||
) -> NvmeController {
|
||||
let mut mmio_reg = TestNvmeMmioRegistration {};
|
||||
let vm_task_driver = &VmTaskDriverSource::new(SingleDriverBackend::new(driver));
|
||||
let msi_conn = MsiConnection::new();
|
||||
let dma_target = DmaTarget::new(AssignedBusRange::new(), 0, gm.clone(), &msi_conn);
|
||||
- let controller = NvmeController::new(
|
||||
+ let controller = NvmeController::new_with_serial(
|
||||
vm_task_driver,
|
||||
&dma_target,
|
||||
&mut mmio_reg,
|
||||
@@ -53,6 +54,7 @@ fn instantiate_controller(
|
||||
max_io_queues: 64,
|
||||
subsystem_id: Guid::new_random(),
|
||||
},
|
||||
+ serial_number,
|
||||
);
|
||||
|
||||
if let Some(intc) = int_controller {
|
||||
@@ -118,7 +120,28 @@ pub async fn instantiate_and_build_admin_queue(
|
||||
driver: DefaultDriver,
|
||||
gm: &GuestMemory,
|
||||
) -> NvmeController {
|
||||
- let mut nvmec = instantiate_controller(driver.clone(), gm, int_controller);
|
||||
+ let nvmec = instantiate_controller(driver.clone(), gm, int_controller, None);
|
||||
+ build_admin_queue(
|
||||
+ nvmec,
|
||||
+ acq_buffer,
|
||||
+ acq_entries,
|
||||
+ asq_buffer,
|
||||
+ asq_entries,
|
||||
+ trigger_interrupt,
|
||||
+ driver,
|
||||
+ )
|
||||
+ .await
|
||||
+}
|
||||
+
|
||||
+async fn build_admin_queue(
|
||||
+ mut nvmec: NvmeController,
|
||||
+ acq_buffer: &PrpRange,
|
||||
+ acq_entries: u32,
|
||||
+ asq_buffer: &PrpRange,
|
||||
+ asq_entries: u32,
|
||||
+ trigger_interrupt: bool,
|
||||
+ driver: DefaultDriver,
|
||||
+) -> NvmeController {
|
||||
// Set the BARs.
|
||||
nvmec
|
||||
.pci_cfg_write(0x10, ByteEnabledDwordWrite::with_all_bytes_enabled(0))
|
||||
@@ -231,7 +254,7 @@ pub async fn instantiate_and_build_admin_queue(
|
||||
#[async_test]
|
||||
async fn test_basic_registers(driver: DefaultDriver) {
|
||||
let gm = test_memory();
|
||||
- let mut nvmec = instantiate_controller(driver, &gm, None);
|
||||
+ let mut nvmec = instantiate_controller(driver, &gm, None, None);
|
||||
let mut dword = 0u32;
|
||||
|
||||
// Read controller caps, version.
|
||||
@@ -255,7 +278,7 @@ async fn test_basic_registers(driver: DefaultDriver) {
|
||||
#[async_test]
|
||||
async fn test_invalid_configuration(driver: DefaultDriver) {
|
||||
let gm = test_memory();
|
||||
- let mut nvmec = instantiate_controller(driver, &gm, None);
|
||||
+ let mut nvmec = instantiate_controller(driver, &gm, None, None);
|
||||
let mut dword = 0u32;
|
||||
nvmec.read_bar0(0x14, dword.as_mut_bytes()).unwrap();
|
||||
// Set MPS to some disallowed value
|
||||
@@ -269,7 +292,7 @@ async fn test_invalid_configuration(driver: DefaultDriver) {
|
||||
#[async_test]
|
||||
async fn test_enable_controller(driver: DefaultDriver) {
|
||||
let gm = test_memory();
|
||||
- let mut nvmec = instantiate_controller(driver, &gm, None);
|
||||
+ let mut nvmec = instantiate_controller(driver, &gm, None, None);
|
||||
|
||||
// Set the ACQ base to 0x1000 and the ASQ base to 0x2000.
|
||||
let mut qword = 0x1000;
|
||||
@@ -296,7 +319,7 @@ async fn test_enable_controller(driver: DefaultDriver) {
|
||||
#[async_test]
|
||||
async fn test_multi_page_admin_queues(driver: DefaultDriver) {
|
||||
let gm = test_memory();
|
||||
- let mut nvmec = instantiate_controller(driver, &gm, None);
|
||||
+ let mut nvmec = instantiate_controller(driver, &gm, None, None);
|
||||
|
||||
// Set the ACQ base to 0x1000 and the ASQ base to 0x3000.
|
||||
let mut qword = 0x1000;
|
||||
@@ -362,6 +385,35 @@ async fn test_send_identify(driver: DefaultDriver) {
|
||||
assert_eq!(cqe.status.status(), spec::Status::SUCCESS.0);
|
||||
}
|
||||
|
||||
+#[async_test]
|
||||
+async fn test_identify_controller_serial(driver: DefaultDriver) {
|
||||
+ for (configured, expected) in [
|
||||
+ (None, *b"SN: 000001 "),
|
||||
+ (Some(*b"STELAANS "), *b"STELAANS "),
|
||||
+ ] {
|
||||
+ let acq = PrpRange::new(vec![0], 0, PAGE_SIZE64).unwrap();
|
||||
+ let asq = PrpRange::new(vec![0x1000], 0, PAGE_SIZE64).unwrap();
|
||||
+ let gm = test_memory();
|
||||
+ let int_controller = TestPciInterruptController::new();
|
||||
+ let nvmec = instantiate_controller(driver.clone(), &gm, Some(&int_controller), configured);
|
||||
+ let mut nvmec = build_admin_queue(nvmec, &acq, 64, &asq, 64, true, driver.clone()).await;
|
||||
+ let identify_gpa = 0x2000;
|
||||
+
|
||||
+ let mut entry = spec::Command::new_zeroed();
|
||||
+ entry.cdw0.set_opcode(spec::AdminOpcode::IDENTIFY.0);
|
||||
+ entry.cdw10 = u32::from(spec::Cdw10Identify::new().with_cns(spec::Cns::CONTROLLER.0));
|
||||
+ entry.dptr[0] = identify_gpa;
|
||||
+ write_command_to_queue(&gm, &asq, 0, &entry);
|
||||
+ nvmec.write_bar0(0x1000, 1u32.as_bytes()).unwrap();
|
||||
+
|
||||
+ wait_for_msi(driver.clone(), &int_controller, 1000, 0xfeed0000, 0x1111).await;
|
||||
+ let cqe = read_completion_from_queue(&gm, &acq, 0);
|
||||
+ assert_eq!(cqe.status.status(), spec::Status::SUCCESS.0);
|
||||
+ let identify: spec::IdentifyController = gm.read_plain(identify_gpa).unwrap();
|
||||
+ assert_eq!(identify.sn.as_bytes(), &expected);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
// =============================================================================
|
||||
// Regression tests for the I/O worker `io_count` accounting.
|
||||
//
|
||||
@@ -1188,7 +1240,7 @@ async fn test_async_event_config_masks_namespace_aen(driver: DefaultDriver) {
|
||||
#[async_test]
|
||||
async fn test_add_namespace_validation(driver: DefaultDriver) {
|
||||
let gm = test_memory();
|
||||
- let nvmec = instantiate_controller(driver, &gm, None);
|
||||
+ let nvmec = instantiate_controller(driver, &gm, None, None);
|
||||
let client = nvmec.client();
|
||||
|
||||
// NSID 0 is reserved and must be rejected as out of range.
|
||||
diff --git a/vm/devices/storage/nvme/src/workers/admin.rs b/vm/devices/storage/nvme/src/workers/admin.rs
|
||||
index b1970be..a24e6f8 100644
|
||||
--- a/vm/devices/storage/nvme/src/workers/admin.rs
|
||||
+++ b/vm/devices/storage/nvme/src/workers/admin.rs
|
||||
@@ -83,6 +83,8 @@ pub struct AdminConfig {
|
||||
pub doorbells: Arc<RwLock<DoorbellMemory>>,
|
||||
#[inspect(display)]
|
||||
pub subsystem_id: Guid,
|
||||
+ #[inspect(skip)]
|
||||
+ pub serial_number: [u8; 20],
|
||||
pub max_sqs: u16,
|
||||
pub max_cqs: u16,
|
||||
pub qe_sizes: Arc<Mutex<IoQueueEntrySizes>>,
|
||||
@@ -728,7 +730,7 @@ fn identify_controller(&self, state: &AdminState) -> spec::IdentifyController {
|
||||
ieee: [0x74, 0xe2, 0x8c], // Microsoft
|
||||
fr: (*b"v1.00000").into(),
|
||||
mn: (*b"MSFT NVMe Accelerator v1.0 ").into(),
|
||||
- sn: (*b"SN: 000001 ").into(),
|
||||
+ sn: self.config.serial_number.into(),
|
||||
aerl: MAX_ASYNC_EVENT_REQUESTS - 1,
|
||||
elpe: ERROR_LOG_PAGE_ENTRIES - 1,
|
||||
oaes: spec::Oaes::new().with_namespace_attribute(true),
|
||||
diff --git a/vm/devices/storage/nvme/src/workers/coordinator.rs b/vm/devices/storage/nvme/src/workers/coordinator.rs
|
||||
index f2de911..47d0e1b 100644
|
||||
--- a/vm/devices/storage/nvme/src/workers/coordinator.rs
|
||||
+++ b/vm/devices/storage/nvme/src/workers/coordinator.rs
|
||||
@@ -15,7 +15,6 @@
|
||||
use futures::StreamExt;
|
||||
use futures_concurrency::future::Race;
|
||||
use guestmem::GuestMemory;
|
||||
-use guid::Guid;
|
||||
use inspect::Inspect;
|
||||
use inspect::InspectMut;
|
||||
use mesh::rpc::PendingRpc;
|
||||
@@ -57,12 +56,11 @@ pub fn new(
|
||||
driver_source: &VmTaskDriverSource,
|
||||
mem: GuestMemory,
|
||||
interrupts: Vec<Interrupt>,
|
||||
- max_sqs: u16,
|
||||
- max_cqs: u16,
|
||||
qe_sizes: Arc<Mutex<IoQueueEntrySizes>>,
|
||||
- subsystem_id: Guid,
|
||||
+ caps: &crate::NvmeControllerCaps,
|
||||
+ serial_number: [u8; 20],
|
||||
) -> Self {
|
||||
- let num_qids = 2 + max_sqs.max(max_cqs) * 2;
|
||||
+ let num_qids = 2 + caps.max_io_queues * 2;
|
||||
let doorbells = Arc::new(RwLock::new(DoorbellMemory::new(num_qids)));
|
||||
let driver = driver_source.simple();
|
||||
let handler: AdminHandler = AdminHandler::new(
|
||||
@@ -72,9 +70,10 @@ pub fn new(
|
||||
mem,
|
||||
interrupts,
|
||||
doorbells: doorbells.clone(),
|
||||
- subsystem_id,
|
||||
- max_sqs,
|
||||
- max_cqs,
|
||||
+ subsystem_id: caps.subsystem_id,
|
||||
+ serial_number,
|
||||
+ max_sqs: caps.max_io_queues,
|
||||
+ max_cqs: caps.max_io_queues,
|
||||
qe_sizes,
|
||||
},
|
||||
);
|
||||
diff --git a/vm/devices/storage/nvme_resources/src/lib.rs b/vm/devices/storage/nvme_resources/src/lib.rs
|
||||
index a80eef0..caa5515 100644
|
||||
--- a/vm/devices/storage/nvme_resources/src/lib.rs
|
||||
+++ b/vm/devices/storage/nvme_resources/src/lib.rs
|
||||
@@ -33,6 +33,8 @@ pub struct NvmeControllerHandle {
|
||||
pub namespaces: Vec<NamespaceDefinition>,
|
||||
/// Runtime request channel for hot add/remove of namespaces.
|
||||
pub requests: Option<mesh::Receiver<NvmeControllerRequest>>,
|
||||
+ /// Optional controller serial number, padded with ASCII spaces to 20 bytes.
|
||||
+ pub serial_number: Option<[u8; 20]>,
|
||||
}
|
||||
|
||||
impl ResourceId<PciDeviceHandleKind> for NvmeControllerHandle {
|
||||
diff --git a/vmm_tests/vmm_tests/tests/tests/multiarch/numa.rs b/vmm_tests/vmm_tests/tests/tests/multiarch/numa.rs
|
||||
index e0fb54d..20e6c57 100644
|
||||
--- a/vmm_tests/vmm_tests/tests/tests/multiarch/numa.rs
|
||||
+++ b/vmm_tests/vmm_tests/tests/tests/multiarch/numa.rs
|
||||
@@ -375,6 +375,7 @@ async fn pcie_device_numa_affinity(
|
||||
read_only: false,
|
||||
}],
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
});
|
||||
diff --git a/vmm_tests/vmm_tests/tests/tests/multiarch/openhcl_servicing.rs b/vmm_tests/vmm_tests/tests/tests/multiarch/openhcl_servicing.rs
|
||||
index d103b57..7a0cecc 100644
|
||||
--- a/vmm_tests/vmm_tests/tests/tests/multiarch/openhcl_servicing.rs
|
||||
+++ b/vmm_tests/vmm_tests/tests/tests/multiarch/openhcl_servicing.rs
|
||||
@@ -1948,6 +1948,7 @@ fn mana_nic_servicing_config(
|
||||
.into_resource(),
|
||||
}],
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
diff --git a/vmm_tests/vmm_tests/tests/tests/multiarch/pcie.rs b/vmm_tests/vmm_tests/tests/tests/multiarch/pcie.rs
|
||||
index f2a1b3e..bc0aef9 100644
|
||||
--- a/vmm_tests/vmm_tests/tests/tests/multiarch/pcie.rs
|
||||
+++ b/vmm_tests/vmm_tests/tests/tests/multiarch/pcie.rs
|
||||
@@ -366,6 +366,7 @@ async fn pcie_hotplug(
|
||||
max_io_queues: 1,
|
||||
namespaces: vec![],
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
});
|
||||
vm.add_pcie_device("s0rc0rp0".into(), nvme_resource).await?;
|
||||
|
||||
diff --git a/vmm_tests/vmm_tests/tests/tests/x86_64.rs b/vmm_tests/vmm_tests/tests/tests/x86_64.rs
|
||||
index ec73c06..4a0aa7a 100644
|
||||
--- a/vmm_tests/vmm_tests/tests/tests/x86_64.rs
|
||||
+++ b/vmm_tests/vmm_tests/tests/tests/x86_64.rs
|
||||
@@ -262,6 +262,7 @@ async fn vpci_filter(config: PetriVmBuilder<OpenVmmPetriBackend>) -> anyhow::Res
|
||||
max_io_queues: 1,
|
||||
namespaces: Vec::new(),
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
@@ -351,6 +352,7 @@ async fn vpci_relay_hot_remove(
|
||||
Vec::new()
|
||||
},
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
)
|
||||
diff --git a/vmm_tests/vmm_tests/tests/tests/x86_64/storage.rs b/vmm_tests/vmm_tests/tests/tests/x86_64/storage.rs
|
||||
index 150b02b..32ca2df 100644
|
||||
--- a/vmm_tests/vmm_tests/tests/tests/x86_64/storage.rs
|
||||
+++ b/vmm_tests/vmm_tests/tests/tests/x86_64/storage.rs
|
||||
@@ -74,6 +74,7 @@ pub(crate) fn new_test_vtl2_nvme_device(
|
||||
read_only: false,
|
||||
}],
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
@@ -806,6 +807,7 @@ const fn disk_sectors(index: u32) -> u64 {
|
||||
})
|
||||
.collect(),
|
||||
requests: None,
|
||||
+ serial_number: None,
|
||||
}
|
||||
.into_resource(),
|
||||
vnode: None,
|
||||
@@ -0,0 +1,959 @@
|
||||
From 2bf24e4266850770f4555eff555554c51460caed Mon Sep 17 00:00:00 2001
|
||||
From: man-mumu <1044969205@qq.com>
|
||||
Date: Fri, 4 Dec 2026 17:09:05 +0800
|
||||
Subject: [PATCH] feat(stela-boot): hosted Reims vGPU OpenVMM support + BAR2 WB
|
||||
MTRR coalescing
|
||||
|
||||
---
|
||||
crates/stela-boot-core/src/options.rs | 6 +
|
||||
crates/stela-boot-core/src/options/parse.rs | 5 +
|
||||
.../stela-boot-core/src/options/validate.rs | 3 +
|
||||
crates/stela-boot/src/engine/services.rs | 31 +-
|
||||
crates/stela-boot/src/engine/start.rs | 88 +++-
|
||||
crates/stela-boot/src/native_memory/cache.rs | 411 ++++++++++++++----
|
||||
crates/stela-boot/src/native_smp/firmware.rs | 142 +++++-
|
||||
crates/stela-boot/src/system.rs | 2 +-
|
||||
8 files changed, 597 insertions(+), 91 deletions(-)
|
||||
|
||||
diff --git a/crates/stela-boot-core/src/options.rs b/crates/stela-boot-core/src/options.rs
|
||||
index 435eac9..d6005a8 100644
|
||||
--- a/crates/stela-boot-core/src/options.rs
|
||||
+++ b/crates/stela-boot-core/src/options.rs
|
||||
@@ -807,6 +807,8 @@ pub struct System {
|
||||
/// Answer device accesses no model implements and list them
|
||||
/// (`--survey`): research runs only.
|
||||
pub survey: bool,
|
||||
+ pub verify_sector: bool,
|
||||
+ pub verify_sector_write: bool,
|
||||
/// Leap the counter over waits of every PE (`--idle-skip`): boot and
|
||||
/// install runs, not interactive use.
|
||||
pub idle_skip: bool,
|
||||
@@ -1058,6 +1060,8 @@ impl Default for System {
|
||||
development_restore: false,
|
||||
development_board: false,
|
||||
survey: false,
|
||||
+ verify_sector: false,
|
||||
+ verify_sector_write: false,
|
||||
idle_skip: false,
|
||||
input: false,
|
||||
trackpad: None,
|
||||
@@ -1706,6 +1710,8 @@ impl fmt::Display for System {
|
||||
line.flag(BLUETOOTH_TRACE, self.bluetooth_trace)?;
|
||||
line.flag("--idle-skip", self.idle_skip)?;
|
||||
line.flag("--survey", self.survey)?;
|
||||
+ line.flag("--verify-sector", self.verify_sector)?;
|
||||
+ line.flag("--verify-sector-write", self.verify_sector_write)?;
|
||||
line.flag("--sep-observe", self.sep_observe)?;
|
||||
line.value(NATIVE_CORES, self.native_cores)?;
|
||||
line.value(GUEST_PES, self.guest_pes)?;
|
||||
diff --git a/crates/stela-boot-core/src/options/parse.rs b/crates/stela-boot-core/src/options/parse.rs
|
||||
index 1782817..a6bf44e 100644
|
||||
--- a/crates/stela-boot-core/src/options/parse.rs
|
||||
+++ b/crates/stela-boot-core/src/options/parse.rs
|
||||
@@ -320,6 +320,11 @@ impl ParseState<'_> {
|
||||
options.bundle_directory = Some(String::from(directory));
|
||||
}
|
||||
"--survey" => options.survey = true,
|
||||
+ "--verify-sector" => options.verify_sector = true,
|
||||
+ "--verify-sector-write" => {
|
||||
+ options.verify_sector = true;
|
||||
+ options.verify_sector_write = true;
|
||||
+ }
|
||||
VERIFY_ON_READ => options.verify_on_read = true,
|
||||
UPDATE_RESTORE => options.update_restore = true,
|
||||
"--development-restore" => options.development_restore = true,
|
||||
diff --git a/crates/stela-boot-core/src/options/validate.rs b/crates/stela-boot-core/src/options/validate.rs
|
||||
index 07353dc..c2747eb 100644
|
||||
--- a/crates/stela-boot-core/src/options/validate.rs
|
||||
+++ b/crates/stela-boot-core/src/options/validate.rs
|
||||
@@ -35,6 +35,9 @@ pub(super) fn system(options: &System) -> Result<(), Error> {
|
||||
if options.trackpad.is_some() && !options.input {
|
||||
return Err(Error::Constraint(Constraint::TrackpadDependency));
|
||||
}
|
||||
+ if (options.verify_sector || options.verify_sector_write) && options.storage.is_none() {
|
||||
+ return Err(Error::Constraint(Constraint::InstallConfiguration));
|
||||
+ }
|
||||
core_trial(options)
|
||||
}
|
||||
|
||||
diff --git a/crates/stela-boot/src/engine/services.rs b/crates/stela-boot/src/engine/services.rs
|
||||
index 9f57b3b..17298e7 100644
|
||||
--- a/crates/stela-boot/src/engine/services.rs
|
||||
+++ b/crates/stela-boot/src/engine/services.rs
|
||||
@@ -163,10 +163,15 @@ unsafe impl NativeServices for Services<'_> {
|
||||
/// driver's start outlasts it by adding bounded waits.
|
||||
fn minimum_delay(&self) -> Result<Rc<dyn Timer>, ServiceError> {
|
||||
let invariant = crate::cpu::INVARIANT_TSC.present();
|
||||
- crate::native_clock::tsc::Minimum::timer(self.tsc_hz, invariant)
|
||||
+ let res = crate::native_clock::tsc::Minimum::timer(self.tsc_hz, invariant)
|
||||
.map_or_else(|| self.mmio.pci_minimum(), Ok)
|
||||
.map(|minimum| Rc::new(stela_drivers::budget::Bounded(minimum)) as Rc<dyn Timer>)
|
||||
- .map_err(ServiceError::MinimumDelay)
|
||||
+ .map_err(ServiceError::MinimumDelay);
|
||||
+ match &res {
|
||||
+ Ok(_) => output::arguments(format_args!("STELA_SVC|clock|0000:00:00.0|OK\n")),
|
||||
+ Err(e) => output::arguments(format_args!("STELA_SVC|clock|0000:00:00.0|ERR:{e}\n")),
|
||||
+ }
|
||||
+ res
|
||||
}
|
||||
|
||||
fn entropy(&self) -> Result<Arc<dyn stela_drivers::entropy::Entropy>, ServiceError> {
|
||||
@@ -259,6 +264,7 @@ unsafe impl NativeServices for Services<'_> {
|
||||
drop(rejected.function);
|
||||
ServiceError::Claim(rejected.error)
|
||||
})?;
|
||||
+ output::arguments(format_args!("STELA_SVC|pci_cfg|{address}|OK\n"));
|
||||
// SAFETY: the same original source owns the bridge above this
|
||||
// function and excludes every other configuration writer.
|
||||
Ok(unsafe {
|
||||
@@ -276,10 +282,12 @@ unsafe impl NativeServices for Services<'_> {
|
||||
}
|
||||
|
||||
fn map_bar(&self, address: Address, bar: Bar) -> Result<Mapping, ServiceError> {
|
||||
- let resource = self.bar_resource(address, bar)?;
|
||||
+ let resource = self.bar_resource(address, bar).inspect_err(|e| {
|
||||
+ output::arguments(format_args!("STELA_SVC|bar_mmio|{address}|ERR:{e}\n"));
|
||||
+ })?;
|
||||
let bytes = usize::try_from(resource.physical_span().bytes())
|
||||
.map_err(|_| ServiceError::Refused("BAR too large"))?;
|
||||
- self.mmio
|
||||
+ let res = self.mmio
|
||||
.authority()
|
||||
.map(
|
||||
resource,
|
||||
@@ -288,7 +296,12 @@ unsafe impl NativeServices for Services<'_> {
|
||||
CacheAttribute::Uncached,
|
||||
Protection::ReadWrite,
|
||||
)
|
||||
- .map_err(ServiceError::Mapping)
|
||||
+ .map_err(ServiceError::Mapping);
|
||||
+ match &res {
|
||||
+ Ok(_) => output::arguments(format_args!("STELA_SVC|bar_mmio|{address}|OK\n")),
|
||||
+ Err(e) => output::arguments(format_args!("STELA_SVC|bar_mmio|{address}|ERR:{e}\n")),
|
||||
+ }
|
||||
+ res
|
||||
}
|
||||
|
||||
fn bar_resource(&self, address: Address, bar: Bar) -> Result<owned::Resource, ServiceError> {
|
||||
@@ -329,18 +342,24 @@ unsafe impl NativeServices for Services<'_> {
|
||||
let address = binding.address();
|
||||
let binding = match self.remappers.domain(self.mmio, binding) {
|
||||
Ok(domain) => {
|
||||
- return domain.map_err(|error| {
|
||||
+ let res = domain.map_err(|error| {
|
||||
output::arguments(format_args!(
|
||||
"HOST IOMMU domain for {address:?} refused: {error:?}\n"
|
||||
));
|
||||
ServiceError::Refused("the IOMMU refused the requester's domain")
|
||||
});
|
||||
+ match &res {
|
||||
+ Ok(_) => output::arguments(format_args!("STELA_SVC|dma|{address}|OK\n")),
|
||||
+ Err(e) => output::arguments(format_args!("STELA_SVC|dma|{address}|ERR:{e}\n")),
|
||||
+ }
|
||||
+ return res;
|
||||
}
|
||||
Err(binding) => binding,
|
||||
};
|
||||
if !PASSTHROUGH_REPORTED.swap(true, Ordering::Relaxed) {
|
||||
output::arguments(format_args!("no IOMMU: device DMA unrestricted\n"));
|
||||
}
|
||||
+ output::arguments(format_args!("STELA_SVC|dma|{address}|OK_PASSTHROUGH\n"));
|
||||
Ok(Arc::new(Passthrough::retaining(
|
||||
self.dma_regions(),
|
||||
binding,
|
||||
diff --git a/crates/stela-boot/src/engine/start.rs b/crates/stela-boot/src/engine/start.rs
|
||||
index 1c495b6..b69d27f 100644
|
||||
--- a/crates/stela-boot/src/engine/start.rs
|
||||
+++ b/crates/stela-boot/src/engine/start.rs
|
||||
@@ -680,6 +680,70 @@ fn open_host(
|
||||
Err(error) => output::fatal(format_args!("the network check failed: {error}")),
|
||||
}
|
||||
}
|
||||
+ if options.verify_sector {
|
||||
+ let mut dev = devices.services.into_iter().next().unwrap_or_else(|| {
|
||||
+ output::fatal("verify-sector: --storage target partition did not open")
|
||||
+ });
|
||||
+ let serial = options.storage.as_ref().map(|t| t.serial.as_str()).unwrap_or("");
|
||||
+ let mut buf = alloc::vec![0u8; 16 * 512];
|
||||
+ for s in 0u64..16 {
|
||||
+ let off = (s as usize) * 512;
|
||||
+ if let Err(err) = dev.read(s, &mut buf[off..off + 512]) {
|
||||
+ output::arguments(format_args!(
|
||||
+ "STELA_SECTOR_VERIFY|serial={serial}|lba={s}|error={err}\n"
|
||||
+ ));
|
||||
+ output::fatal(format_args!("verify-sector read failed at lba {s}: {err}"));
|
||||
+ }
|
||||
+ }
|
||||
+ let hash = stela_formats::sha256(&buf);
|
||||
+ output::arguments(format_args!(
|
||||
+ "STELA_SECTOR_VERIFY|serial={serial}|lba=0..16|bytes=8192|sha256={hash}\n"
|
||||
+ ));
|
||||
+ if options.verify_sector_write {
|
||||
+ let mut wbuf = alloc::vec![0u8; 16 * 512];
|
||||
+ for s in 0u64..16 {
|
||||
+ let tag = alloc::format!("REIMS-RW-SECTOR-{s:02}-OPENVMM\n");
|
||||
+ let tb = tag.as_bytes();
|
||||
+ let sec = &mut wbuf[(s as usize) * 512..((s as usize) + 1) * 512];
|
||||
+ for chunk in sec.chunks_mut(tb.len()) {
|
||||
+ chunk.copy_from_slice(&tb[..chunk.len()]);
|
||||
+ }
|
||||
+ if let Err(err) = dev.write(s, sec) {
|
||||
+ output::fatal(format_args!("verify-sector write failed at lba {s}: {err}"));
|
||||
+ }
|
||||
+ }
|
||||
+ let flush_status = match dev.flush_cache() {
|
||||
+ Ok(()) => "OK",
|
||||
+ Err(stela_drivers::block::BlockError::Unsupported(_)) => "UNSUPPORTED",
|
||||
+ Err(err) => {
|
||||
+ output::fatal(format_args!("verify-sector flush failed: {err}"));
|
||||
+ }
|
||||
+ };
|
||||
+ let whash = stela_formats::sha256(&wbuf);
|
||||
+ let mut rbuf = alloc::vec![0u8; 16 * 512];
|
||||
+ for s in 0u64..16 {
|
||||
+ let off = (s as usize) * 512;
|
||||
+ if let Err(err) = dev.read(s, &mut rbuf[off..off + 512]) {
|
||||
+ output::fatal(format_args!("verify-sector readback failed at lba {s}: {err}"));
|
||||
+ }
|
||||
+ }
|
||||
+ let readback_ok = rbuf == wbuf;
|
||||
+ output::arguments(format_args!(
|
||||
+ "STELA_SECTOR_WRITE|lba=0..16|bytes=8192|sha256={whash}|flush={flush_status}|readback_ok={readback_ok}\n"
|
||||
+ ));
|
||||
+ if !readback_ok {
|
||||
+ output::fatal("verify-sector readback mismatch");
|
||||
+ }
|
||||
+ }
|
||||
+ let power = super::power::HostPowerControl::new(
|
||||
+ handoff.power.clone(),
|
||||
+ host_acpi,
|
||||
+ super::power::EfiReset::new(handoff.efi_reset, handoff.root),
|
||||
+ handoff.tsc_hz,
|
||||
+ devices.host_disks,
|
||||
+ );
|
||||
+ power.power_off();
|
||||
+ }
|
||||
OpenedHost {
|
||||
owner: host_owner,
|
||||
apic_hz,
|
||||
@@ -3110,7 +3174,7 @@ fn start_platform(
|
||||
}
|
||||
}
|
||||
takeover_part("interrupt vectors", &VECTORS);
|
||||
- match host_owner
|
||||
+ let irq_ok = match host_owner
|
||||
.root_identity()
|
||||
.map_err(|_| stela_drivers::bus::irq::IrqError::WrongCpu)
|
||||
.and_then(|identity| {
|
||||
@@ -3124,11 +3188,17 @@ fn start_platform(
|
||||
)
|
||||
}
|
||||
}) {
|
||||
- Ok(()) => output::arguments(format_args!("NATIVE IRQ device vectors attached\n")),
|
||||
- Err(error) => output::arguments(format_args!("NATIVE IRQ unavailable: {error:?}\n")),
|
||||
- }
|
||||
+ Ok(()) => {
|
||||
+ output::arguments(format_args!("NATIVE IRQ device vectors attached\n"));
|
||||
+ true
|
||||
+ }
|
||||
+ Err(error) => {
|
||||
+ output::arguments(format_args!("NATIVE IRQ unavailable: {error:?}\n"));
|
||||
+ false
|
||||
+ }
|
||||
+ };
|
||||
takeover_part("clocks", &CLOCKS);
|
||||
- let clock = if options.boots_macos() {
|
||||
+ let clock = if options.boots_macos() || options.verify_sector {
|
||||
// SAFETY: this BSP owns the existing timer/IDT before any driver,
|
||||
// and the HPET only after its whole-controller handoff above.
|
||||
unsafe { service_clock(handoff, host_owner, native_mmio) }
|
||||
@@ -3334,6 +3404,14 @@ fn start_platform(
|
||||
super::step_watchdog::clear_stage();
|
||||
super::step_watchdog::leave();
|
||||
crate::status::done("");
|
||||
+ let pci_cfg_s = if contained_pci.is_some() { "OK" } else { "ERR:contain_pci" };
|
||||
+ let bar_mmio_s = if native_mmio.is_some() { "OK" } else { "ERR:native_mmio" };
|
||||
+ let dma_s = if handoff.storage.handoff().is_some() { "OK" } else { "ERR:no_handoff" };
|
||||
+ let irq_s = if irq_ok { "OK" } else { "ERR:native_irq" };
|
||||
+ let clock_s = if clock.is_some() { "OK" } else if crate::cpu::INVARIANT_TSC.present() { "OK_TSC" } else { "ERR:clock" };
|
||||
+ output::arguments(format_args!(
|
||||
+ "STELA_POST_EBS|pci_cfg={pci_cfg_s}|bar_mmio={bar_mmio_s}|dma={dma_s}|irq={irq_s}|clock={clock_s}\n"
|
||||
+ ));
|
||||
Platform {
|
||||
acpi: host_acpi,
|
||||
mmio: native_mmio,
|
||||
diff --git a/crates/stela-boot/src/native_memory/cache.rs b/crates/stela-boot/src/native_memory/cache.rs
|
||||
index 155aa69..c37df84 100644
|
||||
--- a/crates/stela-boot/src/native_memory/cache.rs
|
||||
+++ b/crates/stela-boot/src/native_memory/cache.rs
|
||||
@@ -118,12 +118,85 @@ pub(crate) fn verify_writeback(
|
||||
/// parked, before `root_identity` capture and AP startup so that `executor::start`
|
||||
/// replicates the updated MTRR image to every AP.
|
||||
pub(crate) unsafe fn ensure_writeback_mtrr(start: u64, bytes: u64) -> Result<(), MemoryError> {
|
||||
- use crate::cpu::msr::{MTRR_CAP, MTRR_DEFAULT, MTRR_PHYS_BASE, Msr};
|
||||
+ use crate::cpu::msr::{MTRR_CAP, MTRR_DEFAULT, MTRR_PHYS_BASE, Msr, PAT};
|
||||
+ use alloc::vec::Vec;
|
||||
use core::arch::{asm, x86_64::__cpuid};
|
||||
const VALID: u64 = 1 << 11;
|
||||
const MTRR_ENABLE: u64 = 1 << 11;
|
||||
const WRITE_BACK: u64 = 6;
|
||||
- if bytes == 0 || !bytes.is_power_of_two() || !start.is_multiple_of(bytes) || start < (1 << 20) {
|
||||
+ const FOUR_GIB: u64 = 1u64 << 32;
|
||||
+ const FIXED_TOP: u64 = 1u64 << 20;
|
||||
+
|
||||
+ fn decompose_pow2(mut cur: u64, limit: u64, kind: u8, out: &mut Vec<(u64, u64, u8)>) {
|
||||
+ while cur < limit {
|
||||
+ let remaining = limit - cur;
|
||||
+ let align_size = 1u64 << cur.trailing_zeros().min(62);
|
||||
+ let max_pow2 = 1u64 << (63 - remaining.leading_zeros());
|
||||
+ let chunk = align_size.min(max_pow2).max(4096);
|
||||
+ let end = cur.saturating_add(chunk).min(limit);
|
||||
+ out.push((cur, end, kind));
|
||||
+ cur = end;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ fn subtract_interval(base: &[(u64, u64)], sub_s: u64, sub_e: u64) -> Vec<(u64, u64)> {
|
||||
+ let mut out = Vec::new();
|
||||
+ for &(s, e) in base {
|
||||
+ if sub_e <= s || e <= sub_s {
|
||||
+ out.push((s, e));
|
||||
+ } else {
|
||||
+ if s < sub_s {
|
||||
+ out.push((s, sub_s));
|
||||
+ }
|
||||
+ if sub_e < e {
|
||||
+ out.push((sub_e, e));
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ out
|
||||
+ }
|
||||
+
|
||||
+ fn merge_intervals(mut ivs: Vec<(u64, u64)>) -> Vec<(u64, u64)> {
|
||||
+ if ivs.is_empty() {
|
||||
+ return ivs;
|
||||
+ }
|
||||
+ ivs.sort_unstable();
|
||||
+ let mut merged = Vec::with_capacity(ivs.len());
|
||||
+ let mut cur = ivs[0];
|
||||
+ for (s, e) in ivs.into_iter().skip(1) {
|
||||
+ if s <= cur.1 {
|
||||
+ cur.1 = cur.1.max(e);
|
||||
+ } else {
|
||||
+ merged.push(cur);
|
||||
+ cur = (s, e);
|
||||
+ }
|
||||
+ }
|
||||
+ merged.push(cur);
|
||||
+ merged
|
||||
+ }
|
||||
+
|
||||
+ fn policy_wb(policy: &Policy, entries: &[(u64, u64, u8)], pa: u64, len_u64: u64) -> bool {
|
||||
+ let Ok(len) = usize::try_from(len_u64) else {
|
||||
+ return false;
|
||||
+ };
|
||||
+ policy
|
||||
+ .writeback(
|
||||
+ pa,
|
||||
+ len,
|
||||
+ entries.iter().map(|&(rs, re, kind)| {
|
||||
+ Ok(Variable {
|
||||
+ range: rs..re,
|
||||
+ kind,
|
||||
+ })
|
||||
+ }),
|
||||
+ )
|
||||
+ .is_ok()
|
||||
+ }
|
||||
+
|
||||
+ if bytes == 0 || !bytes.is_power_of_two() || !start.is_multiple_of(bytes) || start < FIXED_TOP {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=invalid_size pa={start:#x} bytes={bytes:#x}\n"
|
||||
+ ));
|
||||
return Err(MemoryError::InvalidSize);
|
||||
}
|
||||
let vendor = __cpuid(0);
|
||||
@@ -132,6 +205,9 @@ pub(crate) unsafe fn ensure_writeback_mtrr(start: u64, bytes: u64) -> Result<(),
|
||||
}
|
||||
let features = __cpuid(1).edx;
|
||||
if features & (1 << 12) == 0 {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=no_mtrr_cpuid edx={features:#x}\n"
|
||||
+ ));
|
||||
return Err(MemoryError::CacheAttributeUnavailable);
|
||||
}
|
||||
let maximum = __cpuid(0x8000_0000).eax;
|
||||
@@ -141,120 +217,238 @@ pub(crate) unsafe fn ensure_writeback_mtrr(start: u64, bytes: u64) -> Result<(),
|
||||
36
|
||||
};
|
||||
if !(32..=52).contains(&physical_bits) {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=bad_phys_bits physical_bits={physical_bits}\n"
|
||||
+ ));
|
||||
return Err(MemoryError::CacheAttributeUnavailable);
|
||||
}
|
||||
let end = start.checked_add(bytes).ok_or(MemoryError::InvalidSize)?;
|
||||
if end > 1u64 << physical_bits {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=past_phys_bits end={end:#x} physical_bits={physical_bits}\n"
|
||||
+ ));
|
||||
return Err(MemoryError::CacheAttributeUnavailable);
|
||||
}
|
||||
let address_mask = ((1u64 << physical_bits) - 1) & !4095;
|
||||
let read_msr = |register: Msr| unsafe { register.read() };
|
||||
let default = read_msr(MTRR_DEFAULT);
|
||||
- let count = read_msr(MTRR_CAP) as u8;
|
||||
+ let cap = read_msr(MTRR_CAP);
|
||||
+ let count = cap as u8;
|
||||
+ let pat = read_msr(PAT);
|
||||
let cr0: u64;
|
||||
unsafe { asm!("mov {}, cr0", out(reg) cr0, options(nomem, nostack, preserves_flags)) };
|
||||
- let variables = (0..count).filter_map(|index| {
|
||||
+
|
||||
+ let mut free_count: usize = 0;
|
||||
+ let mut unaligned = false;
|
||||
+ let mut orig_entries: Vec<(u8, u64, u64, u8)> = Vec::new();
|
||||
+ for index in 0..count {
|
||||
let base = read_msr(MTRR_PHYS_BASE.at(2 * u32::from(index)));
|
||||
let mask = read_msr(MTRR_PHYS_BASE.at(2 * u32::from(index) + 1));
|
||||
if mask & VALID == 0 {
|
||||
- return None;
|
||||
+ free_count += 1;
|
||||
+ continue;
|
||||
}
|
||||
let size = ((!mask) & address_mask) + 4096;
|
||||
let base_addr = base & address_mask;
|
||||
- Some(if size.is_power_of_two() && base_addr.is_multiple_of(size) {
|
||||
- Ok(Variable {
|
||||
- range: base_addr..base_addr + size,
|
||||
- kind: base as u8,
|
||||
- })
|
||||
+ let kind = base as u8;
|
||||
+ let aligned = size.is_power_of_two() && base_addr.is_multiple_of(size);
|
||||
+ let v_end = base_addr.saturating_add(size);
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR pre slot={index} range={base_addr:#x}..{v_end:#x} kind={kind} aligned={aligned} base={base:#x} mask={mask:#x}\n"
|
||||
+ ));
|
||||
+ if !aligned {
|
||||
+ unaligned = true;
|
||||
} else {
|
||||
- Err(MemoryError::CacheAttributeUnavailable)
|
||||
- })
|
||||
- });
|
||||
+ orig_entries.push((index, base_addr, v_end, kind));
|
||||
+ }
|
||||
+ }
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR pre-check pa={start:#x} bytes={bytes:#x} edx={features:#x} phys_bits={physical_bits} pat={pat:#x} cr0={cr0:#x} default={default:#x} cap={cap:#x} count={count} free={free_count}\n"
|
||||
+ ));
|
||||
+
|
||||
+ if unaligned {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=unaligned_slot\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
+ if default & MTRR_ENABLE == 0 {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=mtrr_disabled default={default:#x}\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
+ if cr0 & (1 << 30 | 1 << 29) != 0 {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=caches_disabled cr0={cr0:#x}\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
let policy = Policy {
|
||||
- enabled: default & MTRR_ENABLE != 0,
|
||||
- caches_enabled: cr0 & (1 << 30 | 1 << 29) == 0,
|
||||
+ enabled: true,
|
||||
+ caches_enabled: true,
|
||||
default_kind: default as u8,
|
||||
physical_bits,
|
||||
};
|
||||
- if let Ok(len) = usize::try_from(bytes)
|
||||
- && policy.writeback(start, len, variables.clone()).is_ok()
|
||||
- {
|
||||
+ let orig_ranges: Vec<(u64, u64, u8)> = orig_entries
|
||||
+ .iter()
|
||||
+ .map(|&(_, s, e, k)| (s, e, k))
|
||||
+ .collect();
|
||||
+ if policy_wb(&policy, &orig_ranges, start, bytes) {
|
||||
crate::output::arguments(format_args!(
|
||||
"HOST Reims MTRR already WB pa={start:#x} bytes={bytes:#x} default={default:#x}\n"
|
||||
));
|
||||
return Ok(());
|
||||
}
|
||||
- if default & MTRR_ENABLE == 0 {
|
||||
- return Err(MemoryError::CacheAttributeUnavailable);
|
||||
- }
|
||||
- let mut free_slots = alloc::vec::Vec::new();
|
||||
- let mut conflict = None;
|
||||
- for index in 0..count {
|
||||
- let base = read_msr(MTRR_PHYS_BASE.at(2 * u32::from(index)));
|
||||
- let mask = read_msr(MTRR_PHYS_BASE.at(2 * u32::from(index) + 1));
|
||||
- if mask & VALID == 0 {
|
||||
- free_slots.push(index);
|
||||
- continue;
|
||||
- }
|
||||
- let size = ((!mask) & address_mask) + 4096;
|
||||
- let base_addr = base & address_mask;
|
||||
- let kind = base as u8;
|
||||
- if size.is_power_of_two() && base_addr.is_multiple_of(size) {
|
||||
- let v_end = base_addr.saturating_add(size);
|
||||
- if base_addr < end && start < v_end && kind != WRITE_BACK as u8 {
|
||||
- if conflict.is_some() || kind != 0 || base_addr > start || v_end < end {
|
||||
+
|
||||
+ let mut kept_wb_ivs: Vec<(u64, u64)> = Vec::new();
|
||||
+ let mut kept_non_wb: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ let mut uc_pieces: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ let mut orig_wb_ivs: Vec<(u64, u64)> = Vec::new();
|
||||
+ let mut orig_uc_ivs: Vec<(u64, u64)> = Vec::new();
|
||||
+
|
||||
+ for &(_, v_start, v_end, kind) in &orig_entries {
|
||||
+ if kind == WRITE_BACK as u8 {
|
||||
+ orig_wb_ivs.push((v_start, v_end));
|
||||
+ kept_wb_ivs.push((v_start, v_end));
|
||||
+ } else {
|
||||
+ if kind == 0 {
|
||||
+ orig_uc_ivs.push((v_start, v_end));
|
||||
+ }
|
||||
+ if v_start < end && start < v_end {
|
||||
+ if kind != 0 {
|
||||
crate::output::arguments(format_args!(
|
||||
- "HOST Reims MTRR uncarvable conflict slot={index} range={base_addr:#x}..{v_end:#x} kind={kind}\n"
|
||||
+ "HOST Reims MTRR refuse reason=non_uc_conflict range={v_start:#x}..{v_end:#x} kind={kind}\n"
|
||||
));
|
||||
return Err(MemoryError::CacheAttributeUnavailable);
|
||||
}
|
||||
- conflict = Some((index, base_addr, v_end, kind));
|
||||
+ if v_start < start {
|
||||
+ decompose_pow2(v_start, start, 0, &mut uc_pieces);
|
||||
+ }
|
||||
+ if end < v_end {
|
||||
+ decompose_pow2(end, v_end, 0, &mut uc_pieces);
|
||||
+ }
|
||||
+ } else {
|
||||
+ kept_non_wb.push((v_start, v_end, kind));
|
||||
}
|
||||
}
|
||||
}
|
||||
- let mut updates: alloc::vec::Vec<(u8, u64, u64)> = alloc::vec::Vec::new();
|
||||
- if let Some((slot, v_start, v_end, kind)) = conflict {
|
||||
- // Split [v_start, start) and [end, v_end) into aligned power-of-two UC MTRRs
|
||||
- // so [start, end) is carved cleanly out of the 64-bit PCI UC aperture.
|
||||
- let mut pieces: alloc::vec::Vec<(u64, u64)> = alloc::vec::Vec::new();
|
||||
- for (mut cur, limit) in [(v_start, start), (end, v_end)] {
|
||||
- while cur < limit {
|
||||
- let remaining = limit - cur;
|
||||
- let align_size = 1u64 << cur.trailing_zeros().min(62);
|
||||
- let max_pow2 = 1u64 << (63 - remaining.leading_zeros());
|
||||
- let chunk = align_size.min(max_pow2);
|
||||
- pieces.push((cur, chunk));
|
||||
- cur += chunk;
|
||||
- }
|
||||
+
|
||||
+ let slot_cap = usize::from(count);
|
||||
+ let mut kept_only: Vec<(u64, u64, u8)> = kept_wb_ivs
|
||||
+ .iter()
|
||||
+ .map(|&(s, e)| (s, e, WRITE_BACK as u8))
|
||||
+ .collect();
|
||||
+ kept_only.extend_from_slice(&kept_non_wb);
|
||||
+
|
||||
+ let need_bar2_wb = !policy_wb(&policy, &kept_only, start, bytes);
|
||||
+ let merged_wb = if need_bar2_wb {
|
||||
+ let mut all_wb = kept_wb_ivs.clone();
|
||||
+ all_wb.push((start, end));
|
||||
+ merge_intervals(all_wb)
|
||||
+ } else {
|
||||
+ merge_intervals(kept_wb_ivs)
|
||||
+ };
|
||||
+ let mut wb_entries: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ for &(s, e) in &merged_wb {
|
||||
+ decompose_pow2(s, e, WRITE_BACK as u8, &mut wb_entries);
|
||||
+ }
|
||||
+
|
||||
+ let mut non_wb_below_4g: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ let mut kept_non_wb_above_4g: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ let mut uc_pieces_above_4g: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ for &entry in &kept_non_wb {
|
||||
+ if entry.1 <= FOUR_GIB {
|
||||
+ non_wb_below_4g.push(entry);
|
||||
+ } else {
|
||||
+ kept_non_wb_above_4g.push(entry);
|
||||
}
|
||||
- let mut avail = alloc::vec::Vec::with_capacity(1 + free_slots.len());
|
||||
- avail.push(slot);
|
||||
- avail.extend_from_slice(&free_slots);
|
||||
- if pieces.len() <= avail.len() {
|
||||
- for (s, (p_start, p_len)) in avail.iter().copied().zip(pieces.iter().copied()) {
|
||||
- let b = (p_start & address_mask) | u64::from(kind);
|
||||
- let m = ((!(p_len - 1)) & address_mask) | VALID;
|
||||
- updates.push((s, b, m));
|
||||
+ }
|
||||
+ for &piece in &uc_pieces {
|
||||
+ if piece.1 <= FOUR_GIB {
|
||||
+ non_wb_below_4g.push(piece);
|
||||
+ } else {
|
||||
+ uc_pieces_above_4g.push(piece);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ let mut final_entries: Option<Vec<(u64, u64, u8)>> = None;
|
||||
+ let mandatory_len = wb_entries.len() + non_wb_below_4g.len() + kept_non_wb_above_4g.len();
|
||||
+ if mandatory_len <= slot_cap {
|
||||
+ let mut cand = Vec::with_capacity(slot_cap);
|
||||
+ cand.extend_from_slice(&wb_entries);
|
||||
+ cand.extend_from_slice(&non_wb_below_4g);
|
||||
+ cand.extend_from_slice(&kept_non_wb_above_4g);
|
||||
+ let rem = slot_cap - cand.len();
|
||||
+ cand.extend(uc_pieces_above_4g.iter().copied().take(rem));
|
||||
+ final_entries = Some(cand);
|
||||
+ } else if (default as u8) != WRITE_BACK as u8 {
|
||||
+ let max_end = merged_wb
|
||||
+ .iter()
|
||||
+ .map(|&(_, e)| e)
|
||||
+ .max()
|
||||
+ .unwrap_or(end)
|
||||
+ .max(end);
|
||||
+ let cover_len = max_end.next_power_of_two();
|
||||
+ if cover_len <= (1u64 << physical_bits) {
|
||||
+ let mut holes: Vec<(u64, u64)> = alloc::vec![(FIXED_TOP, cover_len)];
|
||||
+ for &(s, e) in &merged_wb {
|
||||
+ holes = subtract_interval(&holes, s, e);
|
||||
}
|
||||
- if pieces.is_empty() {
|
||||
- updates.push((slot, 0, 0));
|
||||
+ for &(s, e) in &orig_uc_ivs {
|
||||
+ holes.push((s.max(FIXED_TOP), e.min(cover_len)));
|
||||
}
|
||||
- free_slots = avail[pieces.len().max(1)..].to_vec();
|
||||
+ holes.retain(|&(s, e)| s < e);
|
||||
+ holes = merge_intervals(holes);
|
||||
+ let mut low_uc: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ let mut high_uc: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ for &(hs, he) in &holes {
|
||||
+ if hs < FOUR_GIB {
|
||||
+ decompose_pow2(hs, he.min(FOUR_GIB), 0, &mut low_uc);
|
||||
+ }
|
||||
+ if he > FOUR_GIB {
|
||||
+ decompose_pow2(hs.max(FOUR_GIB), he, 0, &mut high_uc);
|
||||
+ }
|
||||
+ }
|
||||
+ let mut cand = Vec::new();
|
||||
+ cand.push((0, cover_len, WRITE_BACK as u8));
|
||||
+ cand.extend_from_slice(&low_uc);
|
||||
+ for &entry in &kept_non_wb {
|
||||
+ if entry.1 <= FOUR_GIB && entry.2 != 0 {
|
||||
+ cand.push(entry);
|
||||
+ }
|
||||
+ }
|
||||
+ if cand.len() <= slot_cap {
|
||||
+ let rem = slot_cap - cand.len();
|
||||
+ cand.extend(high_uc.iter().copied().take(rem));
|
||||
+ final_entries = Some(cand);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ let Some(planned) = final_entries else {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=slot_budget_exceeded slots={slot_cap} wb={} non_wb_lo={} non_wb_hi={} uc_pieces={}\n",
|
||||
+ wb_entries.len(),
|
||||
+ non_wb_below_4g.len(),
|
||||
+ kept_non_wb_above_4g.len(),
|
||||
+ uc_pieces_above_4g.len(),
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ };
|
||||
+
|
||||
+ let mut updates: Vec<(u8, u64, u64)> = Vec::with_capacity(slot_cap);
|
||||
+ for slot in 0..count {
|
||||
+ if let Some(&(e_start, e_end, kind)) = planned.get(usize::from(slot)) {
|
||||
+ let len = e_end - e_start;
|
||||
+ let base_val = (e_start & address_mask) | u64::from(kind);
|
||||
+ let mask_val = ((!(len - 1)) & address_mask) | VALID;
|
||||
+ updates.push((slot, base_val, mask_val));
|
||||
} else {
|
||||
- // Fewer free variable MTRRs than carved chunks; clear the broad 64-bit UC window
|
||||
- // (all native MMIO mappings explicitly enforce UC via PAT).
|
||||
updates.push((slot, 0, 0));
|
||||
}
|
||||
}
|
||||
- if (default as u8) != WRITE_BACK as u8 {
|
||||
- let slot = free_slots
|
||||
- .first()
|
||||
- .copied()
|
||||
- .ok_or(MemoryError::CacheAttributeUnavailable)?;
|
||||
- let base_val = (start & address_mask) | WRITE_BACK;
|
||||
- let mask_val = ((!(bytes - 1)) & address_mask) | VALID;
|
||||
- updates.push((slot, base_val, mask_val));
|
||||
- }
|
||||
+
|
||||
// SAFETY: Intel SDM Vol. 3A 11.11.8 MTRR update on BSP with IF=0 and APs parked.
|
||||
unsafe {
|
||||
MTRR_DEFAULT.write(default & !MTRR_ENABLE);
|
||||
@@ -266,13 +460,74 @@ pub(crate) unsafe fn ensure_writeback_mtrr(start: u64, bytes: u64) -> Result<(),
|
||||
asm!("wbinvd", options(nostack, preserves_flags));
|
||||
MTRR_DEFAULT.write(default);
|
||||
}
|
||||
+
|
||||
+ // Read back live MSR state and verify BAR2, original WB RAM, and low MMIO.
|
||||
+ let post_default = read_msr(MTRR_DEFAULT);
|
||||
+ let mut live_ranges: Vec<(u64, u64, u8)> = Vec::new();
|
||||
+ for index in 0..count {
|
||||
+ let base = read_msr(MTRR_PHYS_BASE.at(2 * u32::from(index)));
|
||||
+ let mask = read_msr(MTRR_PHYS_BASE.at(2 * u32::from(index) + 1));
|
||||
+ if mask & VALID == 0 {
|
||||
+ continue;
|
||||
+ }
|
||||
+ let size = ((!mask) & address_mask) + 4096;
|
||||
+ let base_addr = base & address_mask;
|
||||
+ let kind = base as u8;
|
||||
+ let v_end = base_addr.saturating_add(size);
|
||||
+ let aligned = size.is_power_of_two() && base_addr.is_multiple_of(size);
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR post slot={index} range={base_addr:#x}..{v_end:#x} kind={kind} aligned={aligned}\n"
|
||||
+ ));
|
||||
+ if !aligned {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=self_check_failed detail=post_unaligned slot={index}\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
+ live_ranges.push((base_addr, v_end, kind));
|
||||
+ }
|
||||
+
|
||||
+ let post_policy = Policy {
|
||||
+ enabled: post_default & MTRR_ENABLE != 0,
|
||||
+ caches_enabled: cr0 & (1 << 30 | 1 << 29) == 0,
|
||||
+ default_kind: post_default as u8,
|
||||
+ physical_bits,
|
||||
+ };
|
||||
+ if !policy_wb(&post_policy, &live_ranges, start, bytes) {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=self_check_failed detail=bar2_not_wb post_default={post_default:#x}\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
+
|
||||
+ let mut expected_wb = orig_wb_ivs;
|
||||
+ for &(us, ue) in &orig_uc_ivs {
|
||||
+ expected_wb = subtract_interval(&expected_wb, us, ue);
|
||||
+ }
|
||||
+ for (ws_raw, we) in merge_intervals(expected_wb) {
|
||||
+ let ws = ws_raw.max(FIXED_TOP);
|
||||
+ if we > ws && !policy_wb(&post_policy, &live_ranges, ws, we - ws) {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=self_check_failed detail=ram_not_wb range={ws:#x}..{we:#x}\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
+ }
|
||||
+ for mmio_probe in [0xE000_0000u64, 0xFEC0_0000, 0xFEE0_0000] {
|
||||
+ if policy_wb(&post_policy, &live_ranges, mmio_probe, 4096) {
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST Reims MTRR refuse reason=self_check_failed detail=mmio_became_wb pa={mmio_probe:#x}\n"
|
||||
+ ));
|
||||
+ return Err(MemoryError::CacheAttributeUnavailable);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
crate::output::arguments(format_args!(
|
||||
- "HOST Reims MTRR carved WB pa={start:#x} bytes={bytes:#x} default={default:#x} updates={}\n",
|
||||
- updates.len()
|
||||
+ "HOST Reims MTRR updated WB pa={start:#x} bytes={bytes:#x} default={post_default:#x} active_slots={}\n",
|
||||
+ live_ranges.len()
|
||||
));
|
||||
Ok(())
|
||||
}
|
||||
-
|
||||
/// AMD's effective DRAM routing is additional to the common PAT/MTRR fields.
|
||||
/// Reuse the one native capture/query owner, including fixed-attribute visibility
|
||||
/// restoration. A captured image alone is never a live cache-policy grant.
|
||||
diff --git a/crates/stela-boot/src/native_smp/firmware.rs b/crates/stela-boot/src/native_smp/firmware.rs
|
||||
index c2fad92..5dc7dbe 100644
|
||||
--- a/crates/stela-boot/src/native_smp/firmware.rs
|
||||
+++ b/crates/stela-boot/src/native_smp/firmware.rs
|
||||
@@ -20,6 +20,7 @@ use core::{
|
||||
sync::atomic::{AtomicBool, Ordering},
|
||||
time::Duration,
|
||||
};
|
||||
+use stela_runtime::pc::acpi;
|
||||
use uefi::{
|
||||
boot,
|
||||
proto::pi::mp::{CPU_V2_EXTENDED_TOPOLOGY, MpServices},
|
||||
@@ -450,7 +451,9 @@ pub(crate) fn capture_inventory() -> Result<(Region, usize), Error> {
|
||||
}
|
||||
|
||||
pub(crate) fn capture(requested: usize) -> Result<Region, Error> {
|
||||
- let handle = boot::get_handle_for_protocol::<MpServices>().map_err(|_| Error::NoMpServices)?;
|
||||
+ let Ok(handle) = boot::get_handle_for_protocol::<MpServices>() else {
|
||||
+ return capture_from_madt(requested);
|
||||
+ };
|
||||
let mp =
|
||||
boot::open_protocol_exclusive::<MpServices>(handle).map_err(|_| Error::NoMpServices)?;
|
||||
let count = mp
|
||||
@@ -621,6 +624,143 @@ pub(crate) fn capture(requested: usize) -> Result<Region, Error> {
|
||||
})
|
||||
}
|
||||
|
||||
+
|
||||
+fn capture_from_madt(requested: usize) -> Result<Region, Error> {
|
||||
+ // SAFETY: UEFI executes the loader at CPL0 on the running BSP before EBS.
|
||||
+ let bsp_snapshot = unsafe { observe() }?;
|
||||
+ let bsp_apic_id = u64::from(bsp_snapshot.apic_id().ok_or(Error::ProcessorIdentity)?);
|
||||
+ let rsdp = crate::storage::rsdp().ok_or(Error::NoMpServices)?;
|
||||
+ // SAFETY: pre-EBS firmware ACPI root mapped readable.
|
||||
+ let madt = unsafe { acpi::find(rsdp, b"APIC") }.map_err(|_| Error::NoMpServices)?;
|
||||
+ if madt.len() < 44 {
|
||||
+ return Err(Error::ProcessorInventory);
|
||||
+ }
|
||||
+ let madt_len = u32::from_le_bytes(madt[4..8].try_into().unwrap()) as usize;
|
||||
+ if madt_len < 44 || madt_len > madt.len() {
|
||||
+ return Err(Error::ProcessorInventory);
|
||||
+ }
|
||||
+ let mut apics: Vec<u64> = Vec::new();
|
||||
+ let mut off = 44usize;
|
||||
+ while off + 2 <= madt_len {
|
||||
+ let kind = madt[off];
|
||||
+ let len = madt[off + 1] as usize;
|
||||
+ if len < 2 || off + len > madt_len {
|
||||
+ return Err(Error::ProcessorInventory);
|
||||
+ }
|
||||
+ if kind == 0 && len >= 8 {
|
||||
+ let apic_id = u64::from(madt[off + 3]);
|
||||
+ let flags = u32::from_le_bytes(madt[off + 4..off + 8].try_into().unwrap());
|
||||
+ if (flags & 1) != 0 && !apics.contains(&apic_id) {
|
||||
+ apics.push(apic_id);
|
||||
+ }
|
||||
+ } else if kind == 9 && len >= 16 {
|
||||
+ let flags = u32::from_le_bytes(madt[off + 4..off + 8].try_into().unwrap());
|
||||
+ let apic_id = u64::from(u32::from_le_bytes(madt[off + 8..off + 12].try_into().unwrap()));
|
||||
+ if (flags & 1) != 0 && !apics.contains(&apic_id) {
|
||||
+ apics.push(apic_id);
|
||||
+ }
|
||||
+ }
|
||||
+ off += len;
|
||||
+ }
|
||||
+ if apics.is_empty() {
|
||||
+ return Err(Error::ProcessorInventory);
|
||||
+ }
|
||||
+ if !apics.contains(&bsp_apic_id) {
|
||||
+ return Err(Error::WrongBootstrapProcessor);
|
||||
+ }
|
||||
+ let mut processors: Vec<Processor> = apics
|
||||
+ .into_iter()
|
||||
+ .enumerate()
|
||||
+ .map(|(number, apic_id)| {
|
||||
+ let mut flags = topology::ENABLED | topology::HEALTHY;
|
||||
+ if apic_id == bsp_apic_id {
|
||||
+ flags |= topology::BSP;
|
||||
+ }
|
||||
+ Processor {
|
||||
+ processor_number: number as u32,
|
||||
+ apic_id,
|
||||
+ flags,
|
||||
+ topology_version: 1,
|
||||
+ location: Location::default(),
|
||||
+ thread: 0,
|
||||
+ }
|
||||
+ })
|
||||
+ .collect();
|
||||
+ if topology::locations_collide(&processors) {
|
||||
+ let shifts = apic_id_shifts();
|
||||
+ topology::place_by_apic_id(&mut processors, shifts);
|
||||
+ }
|
||||
+ crate::output::arguments(format_args!(
|
||||
+ "HOST PROCESSORS UEFI MP Services absent; captured {} enabled processors from ACPI MADT (bsp_apic={bsp_apic_id:#x})\n",
|
||||
+ processors.len()
|
||||
+ ));
|
||||
+ let mut observations: Vec<Option<Snapshot>> = alloc::vec![None; processors.len()];
|
||||
+ let logical = topology::select_observed(
|
||||
+ &mut processors,
|
||||
+ |slot, index, processor| {
|
||||
+ let snapshot = if slot == 0 {
|
||||
+ bsp_snapshot
|
||||
+ } else {
|
||||
+ let mut s = bsp_snapshot;
|
||||
+ s.apic_base &= !(1 << 8);
|
||||
+ let apic_id = processor.apic_id as u32;
|
||||
+ for rec in &mut s.records[..s.count as usize] {
|
||||
+ if rec.leaf == 1 && rec.subleaf == 0 {
|
||||
+ rec.ebx = (rec.ebx & 0x00ff_ffff) | ((apic_id & 0xff) << 24);
|
||||
+ } else if rec.leaf == 0x0b || rec.leaf == 0x1f {
|
||||
+ rec.edx = apic_id;
|
||||
+ } else if rec.leaf == 0x8000_001e && rec.subleaf == 0 {
|
||||
+ rec.eax = apic_id;
|
||||
+ }
|
||||
+ }
|
||||
+ s
|
||||
+ };
|
||||
+ if !snapshot.matches(processor) {
|
||||
+ if slot == 0 {
|
||||
+ return Err(Error::ProcessorIdentity);
|
||||
+ }
|
||||
+ left_out(processor, Error::ProcessorIdentity);
|
||||
+ return Ok(false);
|
||||
+ }
|
||||
+ observations[index] = Some(snapshot);
|
||||
+ Ok(true)
|
||||
+ },
|
||||
+ Error::Topology,
|
||||
+ )?;
|
||||
+ let assignable =
|
||||
+ topology::assignment_count(None, logical.len()).map_err(|_| Error::CoreCount)?;
|
||||
+ if requested == 0 || requested > assignable {
|
||||
+ return Err(Error::CoreCount);
|
||||
+ }
|
||||
+ let selected = &logical[..assignable];
|
||||
+ let snapshots: Vec<Snapshot> = selected
|
||||
+ .iter()
|
||||
+ .map(|&index| observations[index].ok_or(Error::SnapshotCallback))
|
||||
+ .collect::<Result<_, _>>()?;
|
||||
+ let pages = record_pages(processors.len()).ok_or(Error::Memory)?;
|
||||
+ let memory = crate::firmware::any_pages(pages).map_err(|_| Error::Memory)?;
|
||||
+ let enabled_count = processors.len() as u32;
|
||||
+ unsafe {
|
||||
+ memory.as_ptr().write_bytes(0, pages * PAGE as usize);
|
||||
+ let capture = Capture::from_raw_mut(memory.as_ptr(), processors.len());
|
||||
+ capture.magic = MAGIC;
|
||||
+ capture.version = VERSION;
|
||||
+ capture.processor_count = processors.len() as u32;
|
||||
+ capture.enabled_count = enabled_count;
|
||||
+ capture.core_count = selected.len() as u32;
|
||||
+ capture.logical_count = logical.len() as u32;
|
||||
+ capture.processors.copy_from_slice(&processors);
|
||||
+ for (slot, &index) in selected.iter().enumerate() {
|
||||
+ capture.selected[slot] = index as u32;
|
||||
+ capture.snapshots[slot] = snapshots[slot];
|
||||
+ }
|
||||
+ }
|
||||
+ Ok(Region {
|
||||
+ physical: memory.as_ptr() as u64,
|
||||
+ bytes: (pages * PAGE as usize) as u64,
|
||||
+ })
|
||||
+}
|
||||
+
|
||||
/// Run Stela's observation on the AP at `processor` through MP Services,
|
||||
/// bounded at 500 ms.
|
||||
fn observe_one(mp: &MpServices, processor: Processor) -> Result<Snapshot, Error> {
|
||||
diff --git a/crates/stela-boot/src/system.rs b/crates/stela-boot/src/system.rs
|
||||
index b898637..a733059 100644
|
||||
--- a/crates/stela-boot/src/system.rs
|
||||
+++ b/crates/stela-boot/src/system.rs
|
||||
@@ -352,7 +352,7 @@ fn inputs(options: &[u8], mut volume: FileSystem) -> Result<Inputs> {
|
||||
} else {
|
||||
None
|
||||
};
|
||||
- let (source, mut files, bundle_pes) = if system.preboot.is_some() {
|
||||
+ let (source, mut files, bundle_pes) = if system.preboot.is_some() || system.verify_sector {
|
||||
drop(volume);
|
||||
(Vec::new(), Vec::new(), None)
|
||||
} else if let Some(directory) = system.bundle_directory.as_deref() {
|
||||
--
|
||||
2.55.0.windows.5
|
||||
|
||||
@@ -0,0 +1,764 @@
|
||||
import base64
|
||||
import gzip
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import struct
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
WORK = Path(os.environ.get("REIMS_OPENVMM_WORK", r"D:\ReimsOpenvmmWork"))
|
||||
BIN_DIR = WORK / "bin"
|
||||
BASE_DISK = WORK / "disks" / "arm64-finder-gold.raw"
|
||||
SSD_DIR = Path(r"C:\ReimsSsdLab")
|
||||
STELA_EFI = BIN_DIR / "stela-openvmm-arm64-gpu-stripped.efi"
|
||||
|
||||
|
||||
def next_run_dir() -> Path:
|
||||
runs_root = WORK / "runs"
|
||||
runs_root.mkdir(parents=True, exist_ok=True)
|
||||
n = 1
|
||||
while (runs_root / f"gate2c-arm64-r{n}").exists():
|
||||
n += 1
|
||||
d = runs_root / f"gate2c-arm64-r{n}"
|
||||
d.mkdir(parents=True)
|
||||
return d
|
||||
|
||||
|
||||
RUN_DIR = next_run_dir()
|
||||
|
||||
HID_USAGE = {
|
||||
**{chr(ord("a") + i): (0x04 + i, False) for i in range(26)},
|
||||
**{chr(ord("A") + i): (0x04 + i, True) for i in range(26)},
|
||||
"1": (0x1E, False), "!": (0x1E, True),
|
||||
"2": (0x1F, False), "@": (0x1F, True),
|
||||
"3": (0x20, False), "#": (0x20, True),
|
||||
"4": (0x21, False), "$": (0x21, True),
|
||||
"5": (0x22, False), "%": (0x22, True),
|
||||
"6": (0x23, False), "^": (0x23, True),
|
||||
"7": (0x24, False), "&": (0x24, True),
|
||||
"8": (0x25, False), "*": (0x25, True),
|
||||
"9": (0x26, False), "(": (0x26, True),
|
||||
"0": (0x27, False), ")": (0x27, True),
|
||||
"\n": (0x28, False), "\r": (0x28, False),
|
||||
" ": (0x2C, False),
|
||||
"-": (0x2D, False), "_": (0x2D, True),
|
||||
"=": (0x2E, False), "+": (0x2E, True),
|
||||
"[": (0x2F, False), "{": (0x2F, True),
|
||||
"]": (0x30, False), "}": (0x30, True),
|
||||
"\\": (0x31, False), "|": (0x31, True),
|
||||
";": (0x33, False), ":": (0x33, True),
|
||||
"'": (0x34, False), '"': (0x34, True),
|
||||
"`": (0x35, False), "~": (0x35, True),
|
||||
",": (0x36, False), "<": (0x36, True),
|
||||
".": (0x37, False), ">": (0x37, True),
|
||||
"/": (0x38, False), "?": (0x38, True),
|
||||
}
|
||||
MOD_LCTRL = 0xE0
|
||||
MOD_LSHIFT = 0xE1
|
||||
MOD_LGUI = 0xE3 # Cmd on macOS
|
||||
|
||||
|
||||
def ensure_no_running_vmm():
|
||||
for exe in ("openvmm.exe", "qemu-system-x86_64.exe", "qemu-system-aarch64.exe"):
|
||||
r = subprocess.run(["tasklist", "/FI", f"IMAGENAME eq {exe}", "/NH"], capture_output=True, text=True)
|
||||
if exe.lower() in r.stdout.lower():
|
||||
raise RuntimeError(f"Stale VM process running: {exe}\n{r.stdout}")
|
||||
|
||||
|
||||
def free_tcp_port() -> int:
|
||||
with socket.socket() as s:
|
||||
s.bind(("127.0.0.1", 0))
|
||||
return s.getsockname()[1]
|
||||
|
||||
|
||||
def bmp_stats(path: Path) -> dict:
|
||||
raw = path.read_bytes()
|
||||
assert raw[:2] == b"BM", f"Not BMP: {path}"
|
||||
data_off = struct.unpack_from("<I", raw, 10)[0]
|
||||
w, h = struct.unpack_from("<ii", raw, 18)
|
||||
bpp = struct.unpack_from("<H", raw, 28)[0]
|
||||
aw, ah = abs(w), abs(h)
|
||||
row_stride = ((aw * (bpp // 8) + 3) // 4) * 4
|
||||
total = 0
|
||||
nonblack = 0
|
||||
buckets = set()
|
||||
step_y = max(1, ah // 180)
|
||||
step_x = max(1, aw // 240)
|
||||
bypp = bpp // 8
|
||||
for y in range(0, ah, step_y):
|
||||
row_start = data_off + y * row_stride
|
||||
for x in range(0, aw, step_x):
|
||||
p = row_start + x * bypp
|
||||
b, g, r = raw[p], raw[p + 1], raw[p + 2]
|
||||
total += 1
|
||||
if r > 12 or g > 12 or b > 12:
|
||||
nonblack += 1
|
||||
buckets.add((r >> 4, g >> 4, b >> 4))
|
||||
return {
|
||||
"width": aw,
|
||||
"height": ah,
|
||||
"bpp": bpp,
|
||||
"bytes": len(raw),
|
||||
"sha": hashlib.sha256(raw).hexdigest()[:16],
|
||||
"nonblack_pct": round(100.0 * nonblack / max(1, total), 2),
|
||||
"color_buckets": len(buckets),
|
||||
}
|
||||
|
||||
|
||||
def inspect_desktop_bmp(path: Path) -> dict:
|
||||
"""Checks bottom dock region & top menu bar on the captured framebuffer."""
|
||||
raw = path.read_bytes()
|
||||
data_off = struct.unpack_from("<I", raw, 10)[0]
|
||||
w, h = struct.unpack_from("<ii", raw, 18)
|
||||
bpp = struct.unpack_from("<H", raw, 28)[0]
|
||||
aw, ah = abs(w), abs(h)
|
||||
top_down = h < 0
|
||||
row_stride = ((aw * (bpp // 8) + 3) // 4) * 4
|
||||
bypp = bpp // 8
|
||||
|
||||
def px(x: int, y: int):
|
||||
row_idx = y if top_down else (ah - 1 - y)
|
||||
p = data_off + row_idx * row_stride + x * bypp
|
||||
return raw[p + 2], raw[p + 1], raw[p] # r, g, b
|
||||
|
||||
blue_cnt = 0
|
||||
dock_y0 = max(0, int(ah * 0.945))
|
||||
dock_y1 = min(ah, int(ah * 0.975))
|
||||
for py in range(dock_y0, dock_y1, max(1, (dock_y1 - dock_y0) // 6)):
|
||||
for px_x in range(int(aw * 0.08), int(aw * 0.25), 2):
|
||||
r, g, b = px(px_x, py)
|
||||
if b > 175 and r < 120:
|
||||
blue_cnt += 1
|
||||
|
||||
white_cnt = 0
|
||||
for py in range(max(1, int(ah * 0.008)), min(ah, int(ah * 0.022)), 2):
|
||||
for px_x in range(int(aw * 0.02), int(aw * 0.08), 2):
|
||||
r, g, b = px(px_x, py)
|
||||
if r > 205 and g > 205 and b > 205:
|
||||
white_cnt += 1
|
||||
|
||||
st = bmp_stats(path)
|
||||
return {**st, "dock_blue": blue_cnt, "menu_white": white_cnt}
|
||||
|
||||
|
||||
def ctl_cmd(ctl_port: int, line: str) -> str:
|
||||
with socket.create_connection(("127.0.0.1", ctl_port), timeout=10.0) as cs:
|
||||
cs.sendall((line + "\n").encode("utf-8"))
|
||||
return cs.recv(4096).decode("utf-8", "replace").strip()
|
||||
|
||||
|
||||
def abs_click(ctl_port: int, x: int, y: int, post_s: float = 0.5):
|
||||
ctl_cmd(ctl_port, f"abs {x} {y} 0")
|
||||
time.sleep(0.15)
|
||||
ctl_cmd(ctl_port, f"abs {x} {y} 1")
|
||||
time.sleep(0.10)
|
||||
ctl_cmd(ctl_port, f"abs {x} {y} 0")
|
||||
if post_s > 0:
|
||||
time.sleep(post_s)
|
||||
|
||||
|
||||
def hid_tap(ctl_port: int, usage: int, hold_s: float = 0.08, post_s: float = 0.08, mods=()):
|
||||
for m in mods:
|
||||
ctl_cmd(ctl_port, f"hid {m} 1")
|
||||
time.sleep(0.03)
|
||||
ctl_cmd(ctl_port, f"hid {usage} 1")
|
||||
time.sleep(hold_s)
|
||||
ctl_cmd(ctl_port, f"hid {usage} 0")
|
||||
for m in reversed(mods):
|
||||
time.sleep(0.03)
|
||||
ctl_cmd(ctl_port, f"hid {m} 0")
|
||||
time.sleep(post_s)
|
||||
|
||||
|
||||
def hid_type(ctl_port: int, text: str, hold_s: float = 0.05, gap_s: float = 0.06):
|
||||
for ch in text:
|
||||
usage, shift = HID_USAGE[ch]
|
||||
mods = (MOD_LSHIFT,) if shift else ()
|
||||
hid_tap(ctl_port, usage, hold_s=hold_s, post_s=gap_s, mods=mods)
|
||||
|
||||
|
||||
def pack_arm_gpu_esp(esp_path: Path):
|
||||
cfg = RUN_DIR / "stela.cfg"
|
||||
lvg_uuid = os.environ.get("REIMS_ARM_LVG_UUID", "00000000-0000-0000-0000-000000000001")
|
||||
ecid = os.environ.get("REIMS_ARM_ECID", "0x1122334455667788")
|
||||
cfg.write_text(
|
||||
f"--system --preboot STELAANS:{lvg_uuid} "
|
||||
f"--storage STELAANS:{lvg_uuid} "
|
||||
f"--nor STELAANS:{lvg_uuid} "
|
||||
f"--guest-pes 8 --input --scanout-mirror --ecid {ecid} "
|
||||
"--hosted-reims-base 0x300000000 --hosted-reims-irq auto "
|
||||
"--tier2 on --tlbi-keep on --hle --hosted-reims-irq-mode event\n",
|
||||
encoding="ascii",
|
||||
newline="\n",
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
str(BIN_DIR / "reims-openvmm-arm64.exe"),
|
||||
"pack",
|
||||
"--efi", str(STELA_EFI),
|
||||
"--stambha-config", str(cfg),
|
||||
"--output", str(esp_path),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
|
||||
def get_guest_password() -> str:
|
||||
return os.environ.get("REIMS_GUEST_PASSWORD", "testpass")
|
||||
|
||||
|
||||
def build_guest_script(do_full_checks: bool) -> str:
|
||||
pw = get_guest_password()
|
||||
if not do_full_checks:
|
||||
return (r"""#!/bin/bash
|
||||
set -e
|
||||
SWV=$(sw_vers | tr '\n\t' '| ' | tr -s ' ')
|
||||
ARCH=$(uname -m)
|
||||
CSR=$(csrutil status 2>&1 | tr '\n\t' '| ' | tr -s ' ')
|
||||
METAL_DEV=$(osascript -l JavaScript -e '
|
||||
ObjC.import("Metal");
|
||||
var d = $.MTLCreateSystemDefaultDevice();
|
||||
d ? ObjC.unwrap(d.name) : "NIL";
|
||||
' 2>&1)
|
||||
PS_GUI=$(ps aux | grep -E 'Finder\.app|WindowServer' | grep -v grep | wc -l | tr -d ' ')
|
||||
RES="G2C_REBOOT_JSON={\"sw_vers\":\"$SWV\",\"arch\":\"$ARCH\",\"csrutil\":\"$CSR\",\"metal\":\"$METAL_DEV\",\"gui_procs\":$PS_GUI}"
|
||||
printf '%s\n' "$RES" > /tmp/g2c_reboot.txt
|
||||
echo __GUEST_PW__ | sudo -S sh -c 'cat /tmp/g2c_reboot.txt > /dev/console'
|
||||
defaults write com.apple.loginwindow TALLogoutSavesState -bool false || true
|
||||
sleep 3
|
||||
/bin/sync
|
||||
echo __GUEST_PW__ | sudo -S /sbin/shutdown -h now
|
||||
""").replace("__GUEST_PW__", pw)
|
||||
|
||||
return (r"""#!/bin/bash
|
||||
exec > /tmp/gate2c_guest.log 2>&1
|
||||
SWV=$(sw_vers | tr '\n\t' '| ' | tr -s ' ')
|
||||
ARCH=$(uname -m)
|
||||
CSR=$(csrutil status 2>&1 | tr '\n\t' '| ' | tr -s ' ')
|
||||
PS_GUI=$(ps aux | grep -E 'Finder\.app|WindowServer' | grep -v grep | wc -l | tr -d ' ')
|
||||
NCPU=$(sysctl -n hw.ncpu)
|
||||
|
||||
METAL_JSON=$(osascript -l JavaScript -e '
|
||||
ObjC.import("Foundation");
|
||||
ObjC.import("Metal");
|
||||
ObjC.import("CoreGraphics");
|
||||
var dev = $.MTLCreateSystemDefaultDevice();
|
||||
if (!dev || dev.isNil()) throw new Error("NO_METAL_DEVICE");
|
||||
var q = dev.newCommandQueue;
|
||||
var sz881 = $.NSData.alloc.initWithBase64EncodedStringOptions("CAAAAAAAAAAIAAAAAAAAAAEAAAAAAAAA", 0);
|
||||
function dispatch8x8(enc) {
|
||||
var sel = "dispatchThreadgroups:threadsPerThreadgroup:";
|
||||
var sig = enc.methodSignatureForSelector(sel);
|
||||
var inv = $.NSInvocation.invocationWithMethodSignature(sig);
|
||||
inv.setTarget(enc);
|
||||
inv.setSelector(sel);
|
||||
inv["setArgument:atIndex:"](sz881.bytes, 2);
|
||||
inv["setArgument:atIndex:"](sz881.bytes, 3);
|
||||
inv.invoke;
|
||||
}
|
||||
var msl = [
|
||||
"#include <metal_stdlib>",
|
||||
"using namespace metal;",
|
||||
"kernel void fill(device uint* buf [[buffer(0)]], texture2d<float, access::write> tex [[texture(0)]], uint2 gid [[thread_position_in_grid]]) {",
|
||||
" if (gid.x == 0 && gid.y == 0) { buf[0] = 0xCAFEBABEu; buf[1] = 0x13572468u; buf[2] = 0xDEADBEEFu; buf[3] = 0x99887766u; }",
|
||||
" if (gid.x < 32 && gid.y < 32) { tex.write(float4(float(gid.x)/31.0f, float(gid.y)/31.0f, 0.5f, 1.0f), gid); }",
|
||||
"}",
|
||||
"kernel void readback(device const uint* privBuf [[buffer(0)]], device uint* outBuf [[buffer(1)]], texture2d<float, access::read> privTex [[texture(0)]], device uint* outPx [[buffer(2)]], uint2 gid [[thread_position_in_grid]]) {",
|
||||
" if (gid.x == 0 && gid.y == 0) { for (uint i=0;i<4;i++) outBuf[i]=privBuf[i]; }",
|
||||
" if (gid.x == 10 && gid.y == 20) { float4 p = privTex.read(gid); outPx[0] = (uint(p.r*255.0f+0.5f)<<16)|(uint(p.g*255.0f+0.5f)<<8)|uint(p.b*255.0f+0.5f); }",
|
||||
"}"
|
||||
].join("\n");
|
||||
var err = Ref();
|
||||
var lib = dev.newLibraryWithSourceOptionsError(msl, $.MTLCompileOptions.alloc.init, err);
|
||||
if (!lib || lib.isNil()) throw new Error("LIB_FAIL");
|
||||
var p1 = dev.newComputePipelineStateWithFunctionError(lib.newFunctionWithName("fill"), err);
|
||||
var p2 = dev.newComputePipelineStateWithFunctionError(lib.newFunctionWithName("readback"), err);
|
||||
var privBuf = dev.newBufferWithLengthOptions(256, 2 << 4);
|
||||
var outBuf = dev.newBufferWithLengthOptions(256, 0);
|
||||
var outPx = dev.newBufferWithLengthOptions(64, 0);
|
||||
var td = $.MTLTextureDescriptor.texture2DDescriptorWithPixelFormatWidthHeightMipmapped(70, 32, 32, false);
|
||||
td.storageMode = 2; td.usage = 3;
|
||||
var privTex = dev.newTextureWithDescriptor(td);
|
||||
var cb1 = q.commandBuffer;
|
||||
var e1 = cb1.computeCommandEncoder;
|
||||
e1.setComputePipelineState(p1); e1["setBuffer:offset:atIndex:"](privBuf, 0, 0); e1["setTexture:atIndex:"](privTex, 0);
|
||||
dispatch8x8(e1);
|
||||
e1.endEncoding; cb1.commit; cb1.waitUntilCompleted;
|
||||
var cb2 = q.commandBuffer;
|
||||
var e2 = cb2.computeCommandEncoder;
|
||||
e2.setComputePipelineState(p2); e2["setBuffer:offset:atIndex:"](privBuf, 0, 0); e2["setBuffer:offset:atIndex:"](outBuf, 0, 1); e2["setTexture:atIndex:"](privTex, 0); e2["setBuffer:offset:atIndex:"](outPx, 0, 2);
|
||||
dispatch8x8(e2);
|
||||
e2.endEncoding; cb2.commit; cb2.waitUntilCompleted;
|
||||
$.NSData.dataWithBytesLength(outBuf.contents, 16).writeToFileAtomically("/tmp/g2c_buf.bin", true);
|
||||
$.NSData.dataWithBytesLength(outPx.contents, 4).writeToFileAtomically("/tmp/g2c_px.bin", true);
|
||||
var did = $.CGMainDisplayID();
|
||||
JSON.stringify({
|
||||
name: ObjC.unwrap(dev.name),
|
||||
regId: Number(dev.registryID),
|
||||
w0: Number($.CGDisplayPixelsWide(did)),
|
||||
h0: Number($.CGDisplayPixelsHigh(did))
|
||||
});
|
||||
' 2>&1)
|
||||
|
||||
INIT_DIM=$(osascript -l JavaScript -e '
|
||||
ObjC.import("CoreGraphics");
|
||||
var did = $.CGMainDisplayID();
|
||||
Number($.CGDisplayPixelsWide(did)) + "x" + Number($.CGDisplayPixelsHigh(did));
|
||||
' 2>&1)
|
||||
|
||||
echo "G2C_READY_RESIZE=$INIT_DIM" > /tmp/g2c_ready.txt
|
||||
echo __GUEST_PW__ | sudo -S sh -c 'cat /tmp/g2c_ready.txt > /dev/console'
|
||||
|
||||
RES_WAIT=$(INIT_DIM="$INIT_DIM" osascript -l JavaScript -e '
|
||||
ObjC.import("Foundation");
|
||||
ObjC.import("CoreGraphics");
|
||||
var initDim = (ObjC.unwrap($.NSProcessInfo.processInfo.environment.objectForKey("INIT_DIM")) || "").split("x");
|
||||
var w0 = Number(initDim[0] || 0), h0 = Number(initDim[1] || 0);
|
||||
var did = $.CGMainDisplayID();
|
||||
var w1 = Number($.CGDisplayPixelsWide(did));
|
||||
var h1 = Number($.CGDisplayPixelsHigh(did));
|
||||
for (var i = 0; i < 40; i++) {
|
||||
if (w1 !== w0 || h1 !== h0) break;
|
||||
$.NSThread.sleepForTimeInterval(0.5);
|
||||
w1 = Number($.CGDisplayPixelsWide(did));
|
||||
h1 = Number($.CGDisplayPixelsHigh(did));
|
||||
}
|
||||
JSON.stringify({w0: w0, h0: h0, w1: w1, h1: h1});
|
||||
' 2>&1)
|
||||
|
||||
BUF_HEX=$(od -An -tx4 /tmp/g2c_buf.bin 2>/dev/null | xargs)
|
||||
PX_HEX=$(od -An -tx4 /tmp/g2c_px.bin 2>/dev/null | xargs)
|
||||
|
||||
RES_PAYLOAD="G2C_JSON={\"sw_vers\":\"$SWV\",\"arch\":\"$ARCH\",\"ncpu\":$NCPU,\"csrutil\":\"$CSR\",\"gui_procs\":$PS_GUI,\"buf_hex\":\"$BUF_HEX\",\"px_hex\":\"$PX_HEX\",\"metal\":$METAL_JSON,\"res_switch\":$RES_WAIT}"
|
||||
printf '%s\n' "$RES_PAYLOAD" > /tmp/g2c_out.txt
|
||||
echo __GUEST_PW__ | sudo -S sh -c 'cat /tmp/g2c_out.txt > /dev/console'
|
||||
defaults write com.apple.loginwindow TALLogoutSavesState -bool false || true
|
||||
sleep 5
|
||||
/bin/sync
|
||||
echo __GUEST_PW__ | sudo -S /sbin/shutdown -h now
|
||||
""").replace("__GUEST_PW__", pw)
|
||||
|
||||
|
||||
def run_boot(boot_label: str, esp_img: Path, create_disk: bool, do_full_checks: bool, timeout_s: int = 480) -> dict:
|
||||
com1_port = free_tcp_port()
|
||||
ctl_port = free_tcp_port()
|
||||
|
||||
env = {
|
||||
**os.environ,
|
||||
"REIMS_VGPU_LOG": "info",
|
||||
"OPENVMM_LOG": "info",
|
||||
"RUST_LOG": "info,reims_vgpu=info,reims_vgpu_graphics=info,reims_vgpu_vulkan=info",
|
||||
"MESA_VK_DEVICE_SELECT": "10de:2231",
|
||||
"VK_LOADER_DEVICE_SELECT": "10de:2231",
|
||||
}
|
||||
env.pop("REIMS_VGPU_WINDOW", None)
|
||||
|
||||
vmgs_spec = "file:nvram.vmgs;create=VMGS_DEFAULT,fmt-on-fail" if create_disk else "file:nvram.vmgs"
|
||||
disk_spec = f"sqldiff:arm-sys-diff.sqlite;create:file:{BASE_DISK},on=storage" if create_disk else f"sqldiff:arm-sys-diff.sqlite:file:{BASE_DISK},on=storage"
|
||||
|
||||
cmd = [
|
||||
str(BIN_DIR / "openvmm.exe"),
|
||||
"--single-process",
|
||||
"--hypervisor", "whp",
|
||||
"--memory", "16G",
|
||||
"--processors", "8",
|
||||
"--uefi", f"firmware={BIN_DIR / 'MSVM.fd'},console=com1,disable_frontpage,default_boot_always_attempt",
|
||||
"--com1", f"listen=tcp:127.0.0.1:{com1_port}",
|
||||
"--vmgs", vmgs_spec,
|
||||
"--pcie-ecam-below-4gb",
|
||||
"--pcie-root-complex", "rc0,low_mmio=256M,high_mmio=16G",
|
||||
"--pcie-root-port", "rc0:boot",
|
||||
"--nvme-pci", "id=boot,pcie_port=boot,serial=STELAMEDIA",
|
||||
"--disk", f"file:{esp_img},ro,on=boot",
|
||||
"--pcie-root-port", "rc0:storage",
|
||||
"--nvme-pci", "id=storage,pcie_port=storage,serial=STELAANS",
|
||||
"--disk", disk_spec,
|
||||
"--pcie-root-port", "rc0:kbd",
|
||||
"--virtio-input", "keyboard,port=kbd",
|
||||
"--pcie-root-port", "rc0:tab",
|
||||
"--virtio-input", "tablet,port=tab",
|
||||
"--pcie-root-port", "rc0:gpu",
|
||||
"--reims-vgpu", f"port=gpu,window=1920x1080,hosted_arm64,dll={BIN_DIR / 'reims_vgpu_c.dll'}",
|
||||
"--reims-input-listen", f"127.0.0.1:{ctl_port}",
|
||||
"--guest-shutdown-action", "exit",
|
||||
"--guest-crash-action", "exit:2",
|
||||
]
|
||||
|
||||
com1_log = RUN_DIR / f"{boot_label}_com1.log"
|
||||
stdout_f = open(RUN_DIR / f"{boot_label}_stdout.log", "wb")
|
||||
stderr_f = open(RUN_DIR / f"{boot_label}_stderr.log", "wb")
|
||||
proc = subprocess.Popen(cmd, cwd=RUN_DIR, env=env, stdin=subprocess.PIPE, stdout=stdout_f, stderr=stderr_f)
|
||||
|
||||
buf_lock = threading.Lock()
|
||||
buf = bytearray()
|
||||
sock_holder = [None]
|
||||
stop = [False]
|
||||
|
||||
def reader():
|
||||
deadline = time.monotonic() + 30
|
||||
while time.monotonic() < deadline and not stop[0] and proc.poll() is None:
|
||||
try:
|
||||
sock = socket.create_connection(("127.0.0.1", com1_port), timeout=1.0)
|
||||
sock.settimeout(0.5)
|
||||
sock_holder[0] = sock
|
||||
break
|
||||
except OSError:
|
||||
time.sleep(0.05)
|
||||
sock = sock_holder[0]
|
||||
if not sock:
|
||||
return
|
||||
with open(com1_log, "wb") as lf:
|
||||
while not stop[0]:
|
||||
try:
|
||||
data = sock.recv(4096)
|
||||
if not data:
|
||||
break
|
||||
lf.write(data)
|
||||
lf.flush()
|
||||
with buf_lock:
|
||||
buf.extend(data)
|
||||
except TimeoutError:
|
||||
continue
|
||||
except OSError:
|
||||
break
|
||||
|
||||
t = threading.Thread(target=reader, daemon=True)
|
||||
t.start()
|
||||
|
||||
try:
|
||||
t0 = time.monotonic()
|
||||
milestones = {}
|
||||
shots = {}
|
||||
login_ready_at = None
|
||||
|
||||
while time.monotonic() - t0 < timeout_s:
|
||||
assert proc.poll() is None, f"[{boot_label}] openvmm exited early rc={proc.returncode}"
|
||||
with buf_lock:
|
||||
txt = buf.decode("utf-8", "replace")
|
||||
if "STELA FATAL" in txt or "STELA STOPPED" in txt or "GUEST| panic(" in txt:
|
||||
raise RuntimeError(f"[{boot_label}] Stambha/Guest fatal error seen in com1.log")
|
||||
|
||||
for key, marker in {
|
||||
"efi": "STELA UEFI MOUNT",
|
||||
"host_input": "INPUT host device ",
|
||||
"rmap": "GUEST Reims zero-copy RAM map ranges=",
|
||||
"kernel": "Darwin Kernel Version 27.",
|
||||
"reims_fb": "ReimsGraphics: start_hardware():",
|
||||
"accel": "RgfxAccelerator:",
|
||||
"ws_metal": "RGFX: newUserClient type=5 from WindowServer",
|
||||
"first_present": "ReimsGraphics: present ",
|
||||
}.items():
|
||||
if marker in txt and key not in milestones:
|
||||
milestones[key] = round(time.monotonic() - t0, 2)
|
||||
print(f"[{boot_label} +{milestones[key]}s] milestone: {key}", flush=True)
|
||||
|
||||
if "first_present" in milestones or "ws_metal" in milestones:
|
||||
probe = RUN_DIR / f"{boot_label}_login_probe.bmp"
|
||||
try:
|
||||
ans = ctl_cmd(ctl_port, f"screenshot {probe}")
|
||||
if ans.lower().startswith("ok") and probe.exists():
|
||||
st = bmp_stats(probe)
|
||||
print(f"[{boot_label} +{time.monotonic()-t0:.1f}s] UI probe: {st}", flush=True)
|
||||
if st["nonblack_pct"] >= 30.0 and st["color_buckets"] >= 20:
|
||||
login_ready_at = time.monotonic() - t0
|
||||
time.sleep(8.0)
|
||||
login_bmp = RUN_DIR / f"{boot_label}_01_login.bmp"
|
||||
ctl_cmd(ctl_port, f"screenshot {login_bmp}")
|
||||
shots["login"] = bmp_stats(login_bmp)
|
||||
print(f"[{boot_label}] Login screen ready: {shots['login']}", flush=True)
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
time.sleep(2.5)
|
||||
|
||||
assert login_ready_at is not None, f"[{boot_label}] Timed out waiting for login screen"
|
||||
|
||||
# Log in as Test User (`testpass`)
|
||||
print(f"[{boot_label}] Typing password testpass + Enter...", flush=True)
|
||||
hid_type(ctl_port, get_guest_password(), hold_s=0.06, gap_s=0.08)
|
||||
time.sleep(0.3)
|
||||
hid_tap(ctl_port, 0x28, hold_s=0.10, post_s=1.0)
|
||||
t_submit = time.monotonic()
|
||||
retried_avatar = False
|
||||
desk_bmp = RUN_DIR / f"{boot_label}_02_desktop.bmp"
|
||||
finder_ready = False
|
||||
while time.monotonic() - t_submit < 180:
|
||||
assert proc.poll() is None, f"[{boot_label}] openvmm exited during login rc={proc.returncode}"
|
||||
time.sleep(3.0)
|
||||
ctl_cmd(ctl_port, f"screenshot {desk_bmp}")
|
||||
dinfo = inspect_desktop_bmp(desk_bmp)
|
||||
with buf_lock:
|
||||
cur_txt = buf.decode("utf-8", "replace")
|
||||
has_finder = "from Finder[" in cur_txt
|
||||
print(f"[{boot_label} +{time.monotonic()-t0:.1f}s] desktop probe: {dinfo} finder={has_finder}", flush=True)
|
||||
if (has_finder and dinfo["nonblack_pct"] >= 50.0 and dinfo["color_buckets"] >= 80) or (
|
||||
dinfo["dock_blue"] >= 8 and dinfo["menu_white"] >= 10
|
||||
):
|
||||
print(f"[{boot_label}] Desktop ready! Settling 10s...", flush=True)
|
||||
time.sleep(10.0)
|
||||
ctl_cmd(ctl_port, f"screenshot {desk_bmp}")
|
||||
shots["desktop"] = inspect_desktop_bmp(desk_bmp)
|
||||
finder_ready = True
|
||||
break
|
||||
if (time.monotonic() - t_submit) >= 50.0 and not retried_avatar:
|
||||
retried_avatar = True
|
||||
print(f"[{boot_label}] Retrying login after Test User avatar click...", flush=True)
|
||||
abs_click(ctl_port, 16384, 27000, post_s=1.5)
|
||||
hid_type(ctl_port, get_guest_password(), hold_s=0.06, gap_s=0.08)
|
||||
time.sleep(0.3)
|
||||
hid_tap(ctl_port, 0x28, hold_s=0.10, post_s=1.0)
|
||||
assert finder_ready, f"[{boot_label}] Finder desktop did not appear after login"
|
||||
|
||||
print(f"[{boot_label}] Finder ready! Opening Terminal via Cmd+Space...", flush=True)
|
||||
time.sleep(5.0)
|
||||
abs_click(ctl_port, 16384, 16384, post_s=0.5)
|
||||
hid_tap(ctl_port, 0x2C, hold_s=0.12, post_s=2.0, mods=[MOD_LGUI])
|
||||
hid_type(ctl_port, "terminal", hold_s=0.05, gap_s=0.07)
|
||||
time.sleep(1.5)
|
||||
hid_tap(ctl_port, 0x28, hold_s=0.10, post_s=2.0)
|
||||
|
||||
term_opened = False
|
||||
for _ in range(25):
|
||||
with buf_lock:
|
||||
cur_txt = buf.decode("utf-8", "replace")
|
||||
if "from Terminal[" in cur_txt:
|
||||
term_opened = True
|
||||
break
|
||||
time.sleep(0.8)
|
||||
|
||||
if not term_opened:
|
||||
print(f"[{boot_label}] Trying Finder Cmd+Shift+G -> /System/Applications/Utilities/Terminal.app...", flush=True)
|
||||
abs_click(ctl_port, 16384, 16384, post_s=0.3)
|
||||
hid_tap(ctl_port, 0x29, hold_s=0.08, post_s=0.3)
|
||||
hid_tap(ctl_port, HID_USAGE["g"][0], hold_s=0.10, post_s=1.5, mods=[MOD_LGUI, MOD_LSHIFT])
|
||||
hid_type(ctl_port, "/System/Applications/Utilities/Terminal.app", hold_s=0.04, gap_s=0.05)
|
||||
time.sleep(0.8)
|
||||
hid_tap(ctl_port, 0x28, hold_s=0.10, post_s=1.5)
|
||||
hid_tap(ctl_port, HID_USAGE["o"][0], hold_s=0.10, post_s=3.0, mods=[MOD_LGUI])
|
||||
for _ in range(10):
|
||||
with buf_lock:
|
||||
cur_txt = buf.decode("utf-8", "replace")
|
||||
if "from Terminal[" in cur_txt:
|
||||
term_opened = True
|
||||
break
|
||||
time.sleep(0.8)
|
||||
|
||||
if not term_opened:
|
||||
print(f"[{boot_label}] No Terminal Metal log yet; trying Finder Cmd+Shift+U -> terminal -> Cmd+O...", flush=True)
|
||||
abs_click(ctl_port, 16384, 16384, post_s=0.3)
|
||||
hid_tap(ctl_port, 0x29, hold_s=0.08, post_s=0.3) # Esc
|
||||
hid_tap(ctl_port, HID_USAGE["u"][0], hold_s=0.10, post_s=3.5, mods=[MOD_LGUI, MOD_LSHIFT])
|
||||
hid_type(ctl_port, "terminal", hold_s=0.05, gap_s=0.07)
|
||||
time.sleep(1.0)
|
||||
hid_tap(ctl_port, HID_USAGE["o"][0], hold_s=0.10, post_s=4.0, mods=[MOD_LGUI])
|
||||
|
||||
time.sleep(6.0)
|
||||
hid_tap(ctl_port, HID_USAGE["n"][0], hold_s=0.10, post_s=1.5, mods=[MOD_LGUI])
|
||||
|
||||
gz_bytes = gzip.compress(build_guest_script(do_full_checks).encode("utf-8"), compresslevel=9)
|
||||
script_b64 = base64.b64encode(gz_bytes).decode("ascii")
|
||||
cmd_line = f"echo {script_b64} | base64 -D | gunzip | bash\n"
|
||||
hid_type(ctl_port, cmd_line, hold_s=0.035, gap_s=0.045)
|
||||
print(f"[{boot_label}] Sent gzip+base64 guest check ({len(cmd_line)} chars)", flush=True)
|
||||
|
||||
marker_prefix = "G2C_JSON=" if do_full_checks else "G2C_REBOOT_JSON="
|
||||
ready_marker = "G2C_READY_RESIZE=" if do_full_checks else marker_prefix
|
||||
payload_line = None
|
||||
resized_sent = False
|
||||
fallback_retried = False
|
||||
t_cmd_sent = time.monotonic()
|
||||
deadline_res = t_cmd_sent + 150
|
||||
while time.monotonic() < deadline_res:
|
||||
with buf_lock:
|
||||
cur_txt = buf.decode("utf-8", "replace")
|
||||
if (not do_full_checks or not resized_sent) and ready_marker not in cur_txt and not fallback_retried and (time.monotonic() - t_cmd_sent) > 45.0:
|
||||
fallback_retried = True
|
||||
if "from Terminal[" in cur_txt:
|
||||
print(f"[{boot_label}] Marker {ready_marker} not seen after 45s; Terminal is open, resetting prompt with Esc/Ctrl+C/Cmd+N...", flush=True)
|
||||
hid_tap(ctl_port, 0x29, hold_s=0.08, post_s=0.4)
|
||||
abs_click(ctl_port, 5000, 8000, post_s=0.5)
|
||||
hid_tap(ctl_port, HID_USAGE["c"][0], hold_s=0.10, post_s=0.5, mods=[MOD_LCTRL])
|
||||
hid_tap(ctl_port, HID_USAGE["n"][0], hold_s=0.10, post_s=1.5, mods=[MOD_LGUI])
|
||||
else:
|
||||
print(f"[{boot_label}] Marker {ready_marker} not seen after 45s; retrying via Finder Cmd+Shift+G -> Terminal.app -> Cmd+O -> Cmd+N...", flush=True)
|
||||
abs_click(ctl_port, 16384, 16384, post_s=0.5)
|
||||
hid_tap(ctl_port, 0x29, hold_s=0.08, post_s=0.3)
|
||||
hid_tap(ctl_port, HID_USAGE["g"][0], hold_s=0.10, post_s=1.5, mods=[MOD_LGUI, MOD_LSHIFT])
|
||||
hid_type(ctl_port, "/System/Applications/Utilities/Terminal.app", hold_s=0.04, gap_s=0.05)
|
||||
time.sleep(0.8)
|
||||
hid_tap(ctl_port, 0x28, hold_s=0.10, post_s=1.5)
|
||||
hid_tap(ctl_port, HID_USAGE["o"][0], hold_s=0.10, post_s=4.5, mods=[MOD_LGUI])
|
||||
hid_tap(ctl_port, HID_USAGE["n"][0], hold_s=0.10, post_s=1.5, mods=[MOD_LGUI])
|
||||
hid_type(ctl_port, cmd_line, hold_s=0.035, gap_s=0.045)
|
||||
if do_full_checks and not resized_sent and "G2C_READY_RESIZE=" in cur_txt:
|
||||
resized_sent = True
|
||||
rinfo = ctl_cmd(ctl_port, "resize 800 600")
|
||||
assert rinfo.startswith("ok"), f"CTL resize failed: {rinfo}"
|
||||
print(f"[{boot_label}] Resized Reims vGPU window via CTL: {rinfo}", flush=True)
|
||||
m = re.search(rf"{re.escape(marker_prefix)}(\{{.*\}})", cur_txt)
|
||||
if m:
|
||||
payload_line = m.group(1)
|
||||
break
|
||||
time.sleep(1.0)
|
||||
assert payload_line is not None, f"[{boot_label}] Timed out waiting for {marker_prefix} in com1.log"
|
||||
payload_line = payload_line.replace("\\x09", " ").replace("\t", " ")
|
||||
guest_info = json.loads(payload_line)
|
||||
print(f"[{boot_label}] Guest info: {json.dumps(guest_info)}", flush=True)
|
||||
|
||||
if do_full_checks:
|
||||
res_bmp = RUN_DIR / f"{boot_label}_03_res_switched.bmp"
|
||||
ctl_cmd(ctl_port, f"screenshot {res_bmp}")
|
||||
shots["res_switched"] = bmp_stats(res_bmp)
|
||||
ctl_status = ctl_cmd(ctl_port, "status")
|
||||
ctl_counts = ctl_cmd(ctl_port, "counts")
|
||||
print(f"[{boot_label}] Post-switch shot={shots['res_switched']} status={ctl_status} counts={ctl_counts}", flush=True)
|
||||
else:
|
||||
try:
|
||||
ctl_status = ctl_cmd(ctl_port, "status")
|
||||
except OSError:
|
||||
ctl_status = "exiting"
|
||||
ctl_counts = None
|
||||
|
||||
rc = proc.wait(timeout=90)
|
||||
with buf_lock:
|
||||
final_txt = buf.decode("utf-8", "replace")
|
||||
assert rc == 0, f"[{boot_label}] Expected clean rc=0 shutdown, got {rc}"
|
||||
assert "STELA POWER-OFF code=0x17" in final_txt, f"[{boot_label}] Missing STELA POWER-OFF code=0x17"
|
||||
return {
|
||||
"rc": rc,
|
||||
"milestones": milestones,
|
||||
"shots": shots,
|
||||
"guest": guest_info,
|
||||
"status": ctl_status,
|
||||
"counts": ctl_counts,
|
||||
}
|
||||
finally:
|
||||
if proc.poll() is None:
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=15)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait()
|
||||
stop[0] = True
|
||||
if sock_holder[0]:
|
||||
try:
|
||||
sock_holder[0].close()
|
||||
except OSError:
|
||||
pass
|
||||
t.join(timeout=2)
|
||||
stdout_f.close()
|
||||
stderr_f.close()
|
||||
|
||||
|
||||
def collect_bridge_evidence(boot_label: str) -> dict:
|
||||
com1_txt = (RUN_DIR / f"{boot_label}_com1.log").read_text("utf-8", "replace") if (RUN_DIR / f"{boot_label}_com1.log").exists() else ""
|
||||
stderr_txt = (RUN_DIR / f"{boot_label}_stderr.log").read_text("utf-8", "replace") if (RUN_DIR / f"{boot_label}_stderr.log").exists() else ""
|
||||
com1_lines = com1_txt.splitlines()
|
||||
stderr_lines = stderr_txt.splitlines()
|
||||
|
||||
rmap_serial = [l for l in com1_lines if any(k in l for k in ("HOST Reims BAR2 direct physmap", "HOST Reims PCI", "GUEST Reims zero-copy RAM map"))]
|
||||
rmap_host = [l for l in stderr_lines if "rmap" in l.lower() or "set_memory_map" in l.lower()]
|
||||
|
||||
ip_matches = list(re.finditer(
|
||||
r"IOSurface pages in place:\s*(\d+)\s+views made.*?;\s*(\d+)\s+pages blocks' views made.*?;\s*(\d+)\s+named by their runs;\s*refused:\s*(\d+)\s+for bad runs,\s*(\d+)\s+not mapped",
|
||||
stderr_txt,
|
||||
))
|
||||
iosurface_last = None
|
||||
if ip_matches:
|
||||
m_ip = ip_matches[-1]
|
||||
iosurface_last = {
|
||||
"line": m_ip.group(0),
|
||||
"views_made": int(m_ip.group(1)),
|
||||
"pages_blocks_views_made": int(m_ip.group(2)),
|
||||
"named_by_runs": int(m_ip.group(3)),
|
||||
"refused_bad_runs": int(m_ip.group(4)),
|
||||
"refused_not_mapped": int(m_ip.group(5)),
|
||||
}
|
||||
rt_diag = [l for l in stderr_lines if any(k in l for k in ("rt-diag", "rt-presents", "copy", "IOSurface"))]
|
||||
irq_serial = [l for l in com1_lines if l.startswith("HOST Reims MSI-X") or l.startswith("REIMS IRQ ")]
|
||||
mtrr_smp = [l for l in com1_lines if l.startswith("HOST Reims MTRR") or l.startswith("NATIVE MEMORY TYPES")]
|
||||
return {
|
||||
"rmap": {"serial": rmap_serial, "host": rmap_host[-15:]},
|
||||
"shared_pages_and_iosurface": {"in_place": iosurface_last, "host_rt_diag_tail": rt_diag[-20:]},
|
||||
"gpu_completion_irq": {"serial": irq_serial[-10:]},
|
||||
"mtrr_and_smp": mtrr_smp,
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
ensure_no_running_vmm()
|
||||
assert BASE_DISK.is_file(), f"Missing {BASE_DISK}"
|
||||
assert STELA_EFI.is_file(), f"Missing {STELA_EFI}"
|
||||
|
||||
ssd_before = {p.name: (p.stat().st_size, p.stat().st_mtime_ns) for p in sorted(SSD_DIR.glob("*.qcow2"))}
|
||||
raw_before = (BASE_DISK.stat().st_size, BASE_DISK.stat().st_mtime_ns)
|
||||
|
||||
summary = {"run_dir": str(RUN_DIR), "efi": str(STELA_EFI), "GATE2C_ARM64_PASSED": False}
|
||||
try:
|
||||
esp_img = RUN_DIR / "arm-gpu-esp.img"
|
||||
pack_arm_gpu_esp(esp_img)
|
||||
print(f"RUN_DIR={RUN_DIR} Packed {esp_img} ({esp_img.stat().st_size} B)", flush=True)
|
||||
|
||||
print("=== GATE 2C BOOT 1 (ARM64e 27.2.1 SIP Enabled Desktop + Metal + RMAP/SURFACE_PAGES + Res Switch) ===", flush=True)
|
||||
b1 = run_boot("boot1", esp_img, create_disk=True, do_full_checks=True)
|
||||
b1["evidence"] = collect_bridge_evidence("boot1")
|
||||
summary["boot1"] = b1
|
||||
|
||||
time.sleep(2.0)
|
||||
print("=== GATE 2C BOOT 2 (ARM64e Cold Reboot) ===", flush=True)
|
||||
b2 = run_boot("boot2", esp_img, create_disk=False, do_full_checks=False)
|
||||
b2["evidence"] = collect_bridge_evidence("boot2")
|
||||
summary["boot2"] = b2
|
||||
|
||||
ssd_after = {p.name: (p.stat().st_size, p.stat().st_mtime_ns) for p in sorted(SSD_DIR.glob("*.qcow2"))}
|
||||
raw_after = (BASE_DISK.stat().st_size, BASE_DISK.stat().st_mtime_ns)
|
||||
assert ssd_before == ssd_after, f"SSD qcows modified! {ssd_before} vs {ssd_after}"
|
||||
assert raw_before == raw_after, f"Base raw disk modified! {raw_before} vs {raw_after}"
|
||||
|
||||
g1 = b1["guest"]
|
||||
assert "27.2" in g1["sw_vers"], f"Unexpected sw_vers: {g1}"
|
||||
assert "arm64" in g1["arch"], f"Unexpected arch: {g1}"
|
||||
assert "enabled" in g1["csrutil"].lower(), f"SIP not enabled: {g1}"
|
||||
assert g1["gui_procs"] >= 2, f"Missing Finder/WindowServer: {g1}"
|
||||
assert "A5000" in g1["metal"]["name"], f"Wrong GPU: {g1}"
|
||||
assert g1["buf_hex"] == "cafebabe 13572468 deadbeef 99887766", f"Bad Metal compute readback: {g1}"
|
||||
assert g1["px_hex"] in ("0052a47f", "0054a47f"), f"Bad Metal texture readback: {g1}"
|
||||
assert g1["res_switch"]["w1"] != g1["res_switch"]["w0"] or g1["res_switch"]["h1"] != g1["res_switch"]["h0"], f"Guest resolution did not switch: {g1['res_switch']}"
|
||||
assert b1["shots"]["res_switched"]["width"] != b1["shots"]["desktop"]["width"], f"Host screenshot did not resize: {b1['shots']}"
|
||||
|
||||
ev1 = b1["evidence"]
|
||||
assert any("ranges=" in l for l in ev1["rmap"]["serial"]), f"Missing RMAP line: {ev1['rmap']}"
|
||||
stderr_txt = (RUN_DIR / "boot1_stderr.log").read_text("utf-8", "replace")
|
||||
assert 'window "Reims vGPU" open' in stderr_txt, "Reims vGPU SDL3 window did not open"
|
||||
assert "NVIDIA RTX A5000" in stderr_txt, "NVIDIA RTX A5000 not logged in boot1_stderr.log"
|
||||
ip = ev1["shared_pages_and_iosurface"]["in_place"]
|
||||
assert ip is not None, "Missing IOSurface pages in place log line in boot1_stderr.log"
|
||||
assert (ip["views_made"] + ip["pages_blocks_views_made"]) > 0 and ip["named_by_runs"] > 0, f"Expected >0 in-place views: {ip}"
|
||||
assert ip["refused_bad_runs"] == 0 and ip["refused_not_mapped"] == 0, f"Expected 0 refused/not-mapped: {ip}"
|
||||
|
||||
summary["in_place_line"] = ip["line"]
|
||||
summary["GATE2C_ARM64_PASSED"] = True
|
||||
print("GATE2C_ARM64_PASSED=True", flush=True)
|
||||
except Exception as exc:
|
||||
summary["first_error"] = repr(exc)
|
||||
for bl in ("boot1", "boot2"):
|
||||
if (RUN_DIR / f"{bl}_com1.log").exists():
|
||||
summary.setdefault("failure_evidence", {})[bl] = collect_bridge_evidence(bl)
|
||||
summary.setdefault("com1_tail", {})[bl] = (RUN_DIR / f"{bl}_com1.log").read_text("utf-8", "replace").splitlines()[-35:]
|
||||
if (RUN_DIR / f"{bl}_stderr.log").exists():
|
||||
summary.setdefault("stderr_tail", {})[bl] = (RUN_DIR / f"{bl}_stderr.log").read_text("utf-8", "replace").splitlines()[-35:]
|
||||
raise
|
||||
finally:
|
||||
(RUN_DIR / "gate2c_summary.json").write_text(json.dumps(summary, indent=2), encoding="utf-8")
|
||||
print(f"Summary written to {RUN_DIR / 'gate2c_summary.json'}", flush=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,197 @@
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import threading
|
||||
import time
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
WORK = Path(os.environ.get("REIMS_OPENVMM_WORK", r"D:\ReimsOpenvmmWork"))
|
||||
RUN_DIR = WORK / "runs" / "gate2c-bar2-xnu-smoke"
|
||||
BIN_DIR = WORK / "bin"
|
||||
BASE_DISK = WORK / "disks" / "arm64-finder-gold.raw"
|
||||
STELA_EFI = BIN_DIR / "stela-openvmm-arm64-gpu-stripped.efi"
|
||||
|
||||
|
||||
def ensure_no_running_vmm():
|
||||
for exe in ("openvmm.exe", "qemu-system-x86_64.exe", "qemu-system-aarch64.exe"):
|
||||
r = subprocess.run(["tasklist", "/FI", f"IMAGENAME eq {exe}", "/NH"], capture_output=True, text=True)
|
||||
if exe.lower() in r.stdout.lower():
|
||||
raise RuntimeError(f"Stale VM process running: {exe}\n{r.stdout}")
|
||||
|
||||
|
||||
def free_tcp_port() -> int:
|
||||
with socket.socket() as s:
|
||||
s.bind(("127.0.0.1", 0))
|
||||
return s.getsockname()[1]
|
||||
|
||||
|
||||
def main():
|
||||
ensure_no_running_vmm()
|
||||
assert BASE_DISK.is_file(), f"Missing {BASE_DISK}"
|
||||
assert STELA_EFI.is_file(), f"Missing {STELA_EFI}"
|
||||
|
||||
raw_before = (BASE_DISK.stat().st_size, BASE_DISK.stat().st_mtime_ns)
|
||||
if RUN_DIR.exists():
|
||||
shutil.rmtree(RUN_DIR)
|
||||
RUN_DIR.mkdir(parents=True)
|
||||
|
||||
cfg = RUN_DIR / "stela.cfg"
|
||||
cfg.write_text(
|
||||
f"--system --preboot STELAANS:{os.environ.get("REIMS_ARM_LVG_UUID", "00000000-0000-0000-0000-000000000001")} "
|
||||
f"--storage STELAANS:{os.environ.get("REIMS_ARM_LVG_UUID", "00000000-0000-0000-0000-000000000001")} "
|
||||
f"--nor STELAANS:{os.environ.get("REIMS_ARM_LVG_UUID", "00000000-0000-0000-0000-000000000001")} "
|
||||
f"--guest-pes 8 --scanout-mirror --ecid {os.environ.get("REIMS_ARM_ECID", "0x1122334455667788")} "
|
||||
"--hosted-reims-base 0x300000000 --hosted-reims-irq auto "
|
||||
"--tier2 on --tlbi-keep on --hle --hosted-reims-irq-mode event --single-user\n",
|
||||
encoding="ascii",
|
||||
newline="\n",
|
||||
)
|
||||
esp = RUN_DIR / "arm-smoke-esp.img"
|
||||
subprocess.run(
|
||||
[
|
||||
str(BIN_DIR / "reims-openvmm-arm64.exe"),
|
||||
"pack",
|
||||
"--efi", str(STELA_EFI),
|
||||
"--stambha-config", str(cfg),
|
||||
"--output", str(esp),
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
com1_port = free_tcp_port()
|
||||
com1 = RUN_DIR / "com1.log"
|
||||
stdout_f = open(RUN_DIR / "stdout.log", "wb")
|
||||
stderr_f = open(RUN_DIR / "stderr.log", "wb")
|
||||
env = {
|
||||
**__import__("os").environ,
|
||||
"REIMS_VGPU_LOG": "info",
|
||||
"OPENVMM_LOG": "info",
|
||||
"RUST_LOG": "info,reims_vgpu=info,reims_vgpu_graphics=info,reims_vgpu_vulkan=info",
|
||||
}
|
||||
args = [
|
||||
str(BIN_DIR / "openvmm.exe"),
|
||||
"--single-process",
|
||||
"--hypervisor", "whp",
|
||||
"--memory", "16G",
|
||||
"--processors", "8",
|
||||
"--uefi", f"firmware={BIN_DIR / 'MSVM.fd'},console=com1,disable_frontpage,default_boot_always_attempt",
|
||||
"--com1", f"listen=tcp:127.0.0.1:{com1_port}",
|
||||
"--pcie-ecam-below-4gb",
|
||||
"--pcie-root-complex", "rc0,low_mmio=256M,high_mmio=16G",
|
||||
"--pcie-root-port", "rc0:boot",
|
||||
"--nvme-pci", "id=boot,pcie_port=boot,serial=STELAMEDIA",
|
||||
"--disk", f"file:{esp},ro,on=boot",
|
||||
"--pcie-root-port", "rc0:storage",
|
||||
"--nvme-pci", "id=storage,pcie_port=storage,serial=STELAANS",
|
||||
"--disk", f"memdiff:file:{BASE_DISK},on=storage",
|
||||
"--pcie-root-port", "rc0:gpu",
|
||||
"--reims-vgpu", f"port=gpu,headless,hosted_arm64,dll={BIN_DIR / 'reims_vgpu_c.dll'}",
|
||||
"--guest-shutdown-action", "exit",
|
||||
"--guest-crash-action", "exit:2",
|
||||
]
|
||||
proc = subprocess.Popen(args, cwd=RUN_DIR, env=env, stdin=subprocess.PIPE, stdout=stdout_f, stderr=stderr_f)
|
||||
|
||||
buf_lock = threading.Lock()
|
||||
buf = bytearray()
|
||||
sock_holder = [None]
|
||||
stop = [False]
|
||||
|
||||
def reader():
|
||||
deadline = time.monotonic() + 30
|
||||
while time.monotonic() < deadline and not stop[0] and proc.poll() is None:
|
||||
try:
|
||||
sock = socket.create_connection(("127.0.0.1", com1_port), timeout=1.0)
|
||||
sock.settimeout(0.5)
|
||||
sock_holder[0] = sock
|
||||
break
|
||||
except OSError:
|
||||
time.sleep(0.05)
|
||||
sock = sock_holder[0]
|
||||
if not sock:
|
||||
return
|
||||
with open(com1, "wb") as lf:
|
||||
while not stop[0]:
|
||||
try:
|
||||
data = sock.recv(4096)
|
||||
if not data:
|
||||
break
|
||||
lf.write(data)
|
||||
lf.flush()
|
||||
with buf_lock:
|
||||
buf.extend(data)
|
||||
except TimeoutError:
|
||||
continue
|
||||
except OSError:
|
||||
break
|
||||
|
||||
t = threading.Thread(target=reader, daemon=True)
|
||||
t.start()
|
||||
|
||||
t0 = time.monotonic()
|
||||
sent_cmd = False
|
||||
su_prompt = False
|
||||
outcome = "timeout"
|
||||
try:
|
||||
while time.monotonic() - t0 < 220:
|
||||
with buf_lock:
|
||||
txt = buf.decode("utf-8", "replace")
|
||||
if not sent_cmd and ("Entering single-user mode." in txt or "sh-3.2#" in txt or "bash-" in txt):
|
||||
su_prompt = True
|
||||
sent_cmd = True
|
||||
time.sleep(1.5)
|
||||
sock = sock_holder[0]
|
||||
if sock:
|
||||
cmd_bytes = b"uname -a; sw_vers; csrutil status; echo BAR2_SMOKE_DONE; /bin/sync; /sbin/shutdown -h now\r"
|
||||
for ch in cmd_bytes:
|
||||
sock.sendall(bytes([ch]))
|
||||
time.sleep(0.008)
|
||||
if "STELA FATAL" in txt or "STELA STOPPED" in txt or "GUEST| panic(" in txt:
|
||||
time.sleep(1.0)
|
||||
outcome = "stela-or-guest-fatal"
|
||||
break
|
||||
rc = proc.poll()
|
||||
if rc is not None:
|
||||
outcome = "passed" if (rc == 0 and su_prompt) else f"exited-{rc}"
|
||||
break
|
||||
time.sleep(0.25)
|
||||
finally:
|
||||
rc = proc.poll()
|
||||
if rc is None:
|
||||
proc.kill()
|
||||
rc = proc.wait()
|
||||
stop[0] = True
|
||||
if sock_holder[0]:
|
||||
try:
|
||||
sock_holder[0].close()
|
||||
except OSError:
|
||||
pass
|
||||
t.join(timeout=2)
|
||||
stdout_f.close()
|
||||
stderr_f.close()
|
||||
|
||||
raw_after = (BASE_DISK.stat().st_size, BASE_DISK.stat().st_mtime_ns)
|
||||
assert raw_before == raw_after, f"Base raw disk modified: {raw_before} vs {raw_after}"
|
||||
|
||||
txt = com1.read_text("utf-8", "replace") if com1.exists() else ""
|
||||
mtrr_lines = [l for l in txt.splitlines() if "HOST Reims " in l or "NATIVE MEMORY TYPES" in l or "GUEST Reims zero-copy RAM map" in l]
|
||||
smoke = {
|
||||
"outcome": outcome,
|
||||
"rc": rc,
|
||||
"elapsed_sec": round(time.monotonic() - t0, 2),
|
||||
"single_user_prompt": su_prompt,
|
||||
"has_kernel_27": "Darwin Kernel Version 27." in txt,
|
||||
"has_power_off_0x17": "STELA POWER-OFF code=0x17" in txt,
|
||||
"has_smoke_done": "BAR2_SMOKE_DONE" in txt,
|
||||
"mtrr_and_rmap_lines": mtrr_lines,
|
||||
"com1_tail": txt.splitlines()[-40:],
|
||||
}
|
||||
(RUN_DIR / "smoke_result.json").write_text(json.dumps(smoke, indent=2), encoding="utf-8")
|
||||
print(json.dumps(smoke, indent=2), flush=True)
|
||||
assert outcome == "passed" and smoke["has_smoke_done"] and smoke["has_power_off_0x17"], f"Smoke failed: {outcome}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+456
@@ -0,0 +1,456 @@
|
||||
mod media;
|
||||
|
||||
use std::fs::{self, File, OpenOptions};
|
||||
use std::io::{BufReader, Read};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::{Command, Stdio};
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::{Context, Result, bail, ensure};
|
||||
use clap::{Args, Parser, Subcommand, ValueEnum};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(about = "Validate and probe x64 Stambha EFI boot media in local OpenVMM/WHP")]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
command: Action,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Action {
|
||||
/// Create a raw GPT image with an x64 EFI application and optional Stambha config.
|
||||
Pack {
|
||||
#[arg(long)]
|
||||
efi: PathBuf,
|
||||
#[arg(long)]
|
||||
stambha_config: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
output: PathBuf,
|
||||
},
|
||||
/// Validate the boot media and print the exact OpenVMM argument array as JSON.
|
||||
Plan(BootOptions),
|
||||
/// Boot read-only media in OpenVMM and verify the requested serial message.
|
||||
Run {
|
||||
#[command(flatten)]
|
||||
boot: BootOptions,
|
||||
/// Unique EFI payload message to search for in the COM1 log.
|
||||
#[arg(long)]
|
||||
marker: String,
|
||||
/// Directory for a new probe log. The directory must not already exist.
|
||||
#[arg(long)]
|
||||
log_dir: PathBuf,
|
||||
#[arg(long, default_value_t = 30, value_parser = clap::value_parser!(u64).range(1..=600))]
|
||||
timeout_secs: u64,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct BootOptions {
|
||||
/// x64 OpenVMM Windows executable.
|
||||
#[arg(long)]
|
||||
openvmm: PathBuf,
|
||||
/// x64 mu_msvm firmware matching the selected OpenVMM build.
|
||||
#[arg(long)]
|
||||
firmware: PathBuf,
|
||||
/// Whole 512-byte-sector raw GPT image containing EFI/BOOT/BOOTX64.EFI.
|
||||
#[arg(long)]
|
||||
boot_image: PathBuf,
|
||||
/// Boot media transport. NVMe uses STELAMEDIA and requires patched OpenVMM.
|
||||
#[arg(long, value_enum, default_value_t = BootTransport::Vmbus)]
|
||||
boot_transport: BootTransport,
|
||||
/// Optional raw test disk, attached read-only as STELAANS by default (patched OpenVMM required).
|
||||
#[arg(long)]
|
||||
stambha_storage: Option<PathBuf>,
|
||||
/// Attach the Stambha storage disk read-write instead of read-only.
|
||||
#[arg(long, default_value_t = false)]
|
||||
stambha_storage_writable: bool,
|
||||
#[arg(long, default_value_t = 512, value_parser = clap::value_parser!(u64).range(256..=16384))]
|
||||
memory_mib: u64,
|
||||
#[arg(long, default_value_t = 1, value_parser = clap::value_parser!(u64).range(1..=16))]
|
||||
vcpus: u64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)]
|
||||
enum BootTransport {
|
||||
Vmbus,
|
||||
Nvme,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct BootPlan {
|
||||
exe_path: PathBuf,
|
||||
args: Vec<String>,
|
||||
stambha_config: Option<media::StambhaConfig>,
|
||||
openvmm_nvme_serial_patch_required: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct RunReport {
|
||||
com1_log: PathBuf,
|
||||
stderr_log: PathBuf,
|
||||
marker_observed: bool,
|
||||
timed_out: bool,
|
||||
openvmm_exit_code: Option<i32>,
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
match Cli::parse().command {
|
||||
Action::Pack {
|
||||
efi,
|
||||
stambha_config,
|
||||
output,
|
||||
} => media::create(&efi, stambha_config.as_deref(), &output),
|
||||
Action::Plan(options) => {
|
||||
println!("{}", serde_json::to_string_pretty(&options.plan()?)?);
|
||||
Ok(())
|
||||
}
|
||||
Action::Run {
|
||||
boot,
|
||||
marker,
|
||||
log_dir,
|
||||
timeout_secs,
|
||||
} => run(
|
||||
&boot.plan()?,
|
||||
&marker,
|
||||
&log_dir,
|
||||
Duration::from_secs(timeout_secs),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
impl BootOptions {
|
||||
fn plan(&self) -> Result<BootPlan> {
|
||||
let exe_path = checked_file(&self.openvmm)?;
|
||||
let firmware = checked_file(&self.firmware)?;
|
||||
let boot_image = checked_file(&self.boot_image)?;
|
||||
let stambha_config = media::validate(&boot_image)?;
|
||||
let storage = self
|
||||
.stambha_storage
|
||||
.as_deref()
|
||||
.map(checked_file)
|
||||
.transpose()?;
|
||||
if let Some(storage) = &storage {
|
||||
ensure!(
|
||||
*storage != boot_image,
|
||||
"the Stambha storage disk must differ from boot media"
|
||||
);
|
||||
}
|
||||
let firmware = path_argument(&firmware)?;
|
||||
let boot_image_arg = path_argument(&boot_image)?;
|
||||
let storage_arg = storage.as_deref().map(path_argument).transpose()?;
|
||||
let args = build_openvmm_args(
|
||||
firmware,
|
||||
boot_image_arg,
|
||||
self.boot_transport,
|
||||
storage_arg,
|
||||
self.stambha_storage_writable,
|
||||
self.memory_mib,
|
||||
self.vcpus,
|
||||
)?;
|
||||
let uses_nvme = self.boot_transport == BootTransport::Nvme || storage.is_some();
|
||||
Ok(BootPlan {
|
||||
exe_path,
|
||||
args,
|
||||
stambha_config,
|
||||
openvmm_nvme_serial_patch_required: uses_nvme,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn build_openvmm_args(
|
||||
firmware: &str,
|
||||
boot_image: &str,
|
||||
boot_transport: BootTransport,
|
||||
storage: Option<&str>,
|
||||
storage_writable: bool,
|
||||
memory_mib: u64,
|
||||
vcpus: u64,
|
||||
) -> Result<Vec<String>> {
|
||||
let mut args = vec![
|
||||
"--single-process".into(),
|
||||
"--hypervisor".into(),
|
||||
"whp".into(),
|
||||
"--memory".into(),
|
||||
format!("{memory_mib}M"),
|
||||
"--processors".into(),
|
||||
vcpus.to_string(),
|
||||
"--uefi".into(),
|
||||
format!(
|
||||
"firmware={firmware},console=com1,disable_frontpage,default_boot_always_attempt"
|
||||
),
|
||||
"--com1".into(),
|
||||
"file=com1.log".into(),
|
||||
"--guest-shutdown-action".into(),
|
||||
"exit".into(),
|
||||
"--guest-crash-action".into(),
|
||||
"exit:2".into(),
|
||||
];
|
||||
let uses_nvme = boot_transport == BootTransport::Nvme || storage.is_some();
|
||||
if uses_nvme {
|
||||
args.extend([
|
||||
"--pcie-ecam-below-4gb".into(),
|
||||
"--pcie-root-complex".into(),
|
||||
"rc0,low_mmio=128M,high_mmio=4G".into(),
|
||||
]);
|
||||
}
|
||||
match boot_transport {
|
||||
BootTransport::Vmbus => args.extend([
|
||||
"--vmbus-scsi".into(),
|
||||
"id=boot".into(),
|
||||
"--disk".into(),
|
||||
format!("file:{boot_image},ro,on=boot"),
|
||||
]),
|
||||
BootTransport::Nvme => {
|
||||
append_nvme_disk(&mut args, Path::new(boot_image), "boot", "STELAMEDIA", false)?;
|
||||
}
|
||||
}
|
||||
if let Some(storage) = storage {
|
||||
append_nvme_disk(
|
||||
&mut args,
|
||||
Path::new(storage),
|
||||
"stambha-storage",
|
||||
"STELAANS",
|
||||
storage_writable,
|
||||
)?;
|
||||
}
|
||||
Ok(args)
|
||||
}
|
||||
|
||||
fn append_nvme_disk(
|
||||
args: &mut Vec<String>,
|
||||
disk: &Path,
|
||||
id: &str,
|
||||
serial: &str,
|
||||
writable: bool,
|
||||
) -> Result<()> {
|
||||
let path = path_argument(disk)?;
|
||||
let disk_arg = if writable {
|
||||
format!("file:{path},on={id}")
|
||||
} else {
|
||||
format!("file:{path},ro,on={id}")
|
||||
};
|
||||
args.extend([
|
||||
"--pcie-root-port".into(),
|
||||
format!("rc0:{id}"),
|
||||
"--nvme-pci".into(),
|
||||
format!("id={id},pcie_port={id},serial={serial}"),
|
||||
"--disk".into(),
|
||||
disk_arg,
|
||||
]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn checked_file(path: &Path) -> Result<PathBuf> {
|
||||
let absolute = path
|
||||
.canonicalize()
|
||||
.with_context(|| format!("resolve {}", path.display()))?;
|
||||
ensure!(
|
||||
absolute.is_file(),
|
||||
"expected a regular file at {}",
|
||||
path.display()
|
||||
);
|
||||
Ok(absolute)
|
||||
}
|
||||
|
||||
fn path_argument(path: &Path) -> Result<&str> {
|
||||
let arg = path
|
||||
.to_str()
|
||||
.context("OpenVMM option paths must be valid UTF-8")?;
|
||||
// Commas delimit OpenVMM options and semicolons delimit disk file modifiers.
|
||||
ensure!(
|
||||
!arg.contains([',', ';', '\r', '\n']),
|
||||
"OpenVMM option path contains a reserved delimiter: {}",
|
||||
path.display()
|
||||
);
|
||||
Ok(arg)
|
||||
}
|
||||
|
||||
fn run(plan: &BootPlan, marker: &str, log_dir: &Path, timeout: Duration) -> Result<()> {
|
||||
ensure!(
|
||||
cfg!(all(windows, target_arch = "x86_64")),
|
||||
"the probe runner requires Windows x64"
|
||||
);
|
||||
ensure!(
|
||||
(1..=256).contains(&marker.len())
|
||||
&& marker
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_graphic() || byte == b' '),
|
||||
"marker must be 1–256 printable ASCII bytes"
|
||||
);
|
||||
ensure!(
|
||||
!marker.trim().is_empty(),
|
||||
"marker must contain a visible character"
|
||||
);
|
||||
fs::create_dir(log_dir)
|
||||
.with_context(|| format!("create new log directory {}", log_dir.display()))?;
|
||||
let log_dir = log_dir.canonicalize()?;
|
||||
let stdout_path = log_dir.join("openvmm.stdout.log");
|
||||
let stderr_path = log_dir.join("openvmm.stderr.log");
|
||||
let com1_path = log_dir.join("com1.log");
|
||||
let stdout = OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&stdout_path)?;
|
||||
let stderr = OpenOptions::new()
|
||||
.write(true)
|
||||
.create_new(true)
|
||||
.open(&stderr_path)?;
|
||||
|
||||
let mut child = Command::new(&plan.exe_path)
|
||||
.args(&plan.args)
|
||||
.current_dir(&log_dir)
|
||||
// OpenVMM stops the VM when its REPL sees EOF. Retain the idle pipe
|
||||
// for the child lifetime while keeping the caller's input detached.
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(stdout)
|
||||
.stderr(stderr)
|
||||
.spawn()
|
||||
.with_context(|| format!("start {}", plan.exe_path.display()))?;
|
||||
let deadline = Instant::now() + timeout;
|
||||
let status = loop {
|
||||
match child.try_wait() {
|
||||
Ok(Some(status)) => break Some(status),
|
||||
Ok(None) if Instant::now() < deadline => thread::sleep(Duration::from_millis(50)),
|
||||
Ok(None) => {
|
||||
// If the child exited between polling and killing, wait still reaps it.
|
||||
let _ = child.kill();
|
||||
child.wait().context("reap OpenVMM after timeout")?;
|
||||
break None;
|
||||
}
|
||||
Err(error) => {
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
return Err(error).context("wait for OpenVMM");
|
||||
}
|
||||
}
|
||||
};
|
||||
let marker_found = match File::open(&com1_path) {
|
||||
Ok(file) => contains_marker(BufReader::new(file), marker.as_bytes())?,
|
||||
Err(error) if error.kind() == std::io::ErrorKind::NotFound => false,
|
||||
Err(error) => return Err(error).context("open COM1 log"),
|
||||
};
|
||||
let report = RunReport {
|
||||
com1_log: com1_path,
|
||||
stderr_log: stderr_path,
|
||||
marker_observed: marker_found,
|
||||
timed_out: status.is_none(),
|
||||
openvmm_exit_code: status.and_then(|status| status.code()),
|
||||
};
|
||||
println!("{}", serde_json::to_string_pretty(&report)?);
|
||||
if let Some(status) = status {
|
||||
ensure!(status.success(), "OpenVMM exited with {status}");
|
||||
} else if !marker_found {
|
||||
bail!("OpenVMM exceeded the probe timeout before emitting the requested EFI marker");
|
||||
}
|
||||
ensure!(
|
||||
marker_found,
|
||||
"OpenVMM exited before emitting the requested EFI marker"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn contains_marker(mut reader: impl Read, marker: &[u8]) -> Result<bool> {
|
||||
let mut chunk = [0; 8192];
|
||||
let mut window = Vec::with_capacity(chunk.len() + marker.len() - 1);
|
||||
loop {
|
||||
let count = reader.read(&mut chunk)?;
|
||||
if count == 0 {
|
||||
return Ok(false);
|
||||
}
|
||||
window.extend_from_slice(&chunk[..count]);
|
||||
if window.windows(marker.len()).any(|bytes| bytes == marker) {
|
||||
return Ok(true);
|
||||
}
|
||||
let keep_from = window.len().saturating_sub(marker.len() - 1);
|
||||
window.drain(..keep_from);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn serial_marker_may_cross_read_boundaries() -> Result<()> {
|
||||
let mut output = vec![b'x'; 8190];
|
||||
output.extend(b"marker-here");
|
||||
assert!(contains_marker(output.as_slice(), b"marker-here")?);
|
||||
assert!(!contains_marker(output.as_slice(), b"marker-absent")?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_syntax_delimiters_in_openvmm_option_paths() {
|
||||
assert!(path_argument(Path::new("firmware folder/MSVM.fd")).is_ok());
|
||||
assert!(path_argument(Path::new("firmware,debug/MSVM.fd")).is_err());
|
||||
assert!(path_argument(Path::new("disk.img;create=1G")).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn optional_storage_is_read_only_by_default_and_supports_writable() -> Result<()> {
|
||||
let mut ro_args = Vec::new();
|
||||
append_nvme_disk(
|
||||
&mut ro_args,
|
||||
Path::new("stambha disk.img"),
|
||||
"stambha-storage",
|
||||
"STELAANS",
|
||||
false,
|
||||
)?;
|
||||
assert_eq!(
|
||||
ro_args,
|
||||
[
|
||||
"--pcie-root-port",
|
||||
"rc0:stambha-storage",
|
||||
"--nvme-pci",
|
||||
"id=stambha-storage,pcie_port=stambha-storage,serial=STELAANS",
|
||||
"--disk",
|
||||
"file:stambha disk.img,ro,on=stambha-storage",
|
||||
]
|
||||
);
|
||||
|
||||
let mut rw_args = Vec::new();
|
||||
append_nvme_disk(
|
||||
&mut rw_args,
|
||||
Path::new("stambha disk.img"),
|
||||
"stambha-storage",
|
||||
"STELAANS",
|
||||
true,
|
||||
)?;
|
||||
assert_eq!(
|
||||
rw_args,
|
||||
[
|
||||
"--pcie-root-port",
|
||||
"rc0:stambha-storage",
|
||||
"--nvme-pci",
|
||||
"id=stambha-storage,pcie_port=stambha-storage,serial=STELAANS",
|
||||
"--disk",
|
||||
"file:stambha disk.img,on=stambha-storage",
|
||||
]
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nvme_plan_enables_ecam_below_4gb_and_mmio_windows() -> Result<()> {
|
||||
let args = build_openvmm_args(
|
||||
"MSVM.fd",
|
||||
"esp.img",
|
||||
BootTransport::Nvme,
|
||||
Some("store.img"),
|
||||
true,
|
||||
4096,
|
||||
4,
|
||||
)?;
|
||||
assert!(args.windows(2).any(|w| w == ["--memory", "4096M"]));
|
||||
assert!(args.windows(2).any(|w| w == ["--processors", "4"]));
|
||||
assert!(args.iter().any(|a| a == "--pcie-ecam-below-4gb"));
|
||||
assert!(args
|
||||
.windows(2)
|
||||
.any(|w| w == ["--pcie-root-complex", "rc0,low_mmio=128M,high_mmio=4G"]));
|
||||
assert!(args.iter().any(|a| a == "file:esp.img,ro,on=boot"));
|
||||
assert!(args.iter().any(|a| a == "file:store.img,on=stambha-storage"));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
+307
@@ -0,0 +1,307 @@
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||
use std::path::Path;
|
||||
|
||||
use anyhow::{Context, Result, ensure};
|
||||
use fatfs::{FatType, FileSystem, FormatVolumeOptions, FsOptions};
|
||||
use fscommon::StreamSlice;
|
||||
use gptman::{GPT, GPTHeader, GPTPartitionEntry};
|
||||
use uuid::{Uuid, uuid};
|
||||
|
||||
const SECTOR_BYTES: u64 = 512;
|
||||
const MIB: u64 = 1024 * 1024;
|
||||
const EFI_PARTITION_TYPE: [u8; 16] = uuid!("c12a7328-f81f-11d2-ba4b-00a0c93ec93b").to_bytes_le();
|
||||
const BOOT_FILE: &str = "EFI/BOOT/BOOTX64.EFI";
|
||||
const CONFIG_FILE: &str = "EFI/stela/stela.cfg";
|
||||
const MAX_CONFIG_BYTES: usize = 16 * 1024;
|
||||
|
||||
pub(crate) fn create(efi: &Path, config: Option<&Path>, output: &Path) -> Result<()> {
|
||||
let mut payload = File::open(efi).with_context(|| format!("open {}", efi.display()))?;
|
||||
let payload_meta = payload.metadata()?;
|
||||
ensure!(payload_meta.is_file(), "expected a regular EFI file");
|
||||
let disk_bytes = image_size(payload_meta.len())?;
|
||||
validate_pe(&mut payload).with_context(|| format!("invalid PE image {}", efi.display()))?;
|
||||
payload.rewind()?;
|
||||
let mut config = config
|
||||
.map(File::open)
|
||||
.transpose()
|
||||
.context("open Stambha config")?;
|
||||
if let Some(config) = &config {
|
||||
ensure!(
|
||||
config.metadata()?.is_file(),
|
||||
"expected a regular Stambha config file"
|
||||
);
|
||||
ensure!(
|
||||
config.metadata()?.len() <= MAX_CONFIG_BYTES as u64,
|
||||
"Stambha config exceeds {MAX_CONFIG_BYTES} bytes"
|
||||
);
|
||||
}
|
||||
|
||||
let mut disk = OpenOptions::new()
|
||||
.create_new(true)
|
||||
.read(true)
|
||||
.write(true)
|
||||
.open(output)
|
||||
.with_context(|| format!("create new image {}", output.display()))?;
|
||||
let result = write_media(&mut disk, disk_bytes, &mut payload, config.as_mut())
|
||||
.and_then(|()| disk.sync_all().context("sync output image"));
|
||||
drop(disk);
|
||||
if result.is_err() {
|
||||
let _ = std::fs::remove_file(output);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn image_size(payload_bytes: u64) -> Result<u64> {
|
||||
ensure!(
|
||||
payload_bytes <= 504 * MIB,
|
||||
"EFI application exceeds 504 MiB"
|
||||
);
|
||||
Ok((payload_bytes.div_ceil(MIB) + 8).max(64) * MIB)
|
||||
}
|
||||
|
||||
fn write_media(
|
||||
disk: &mut File,
|
||||
disk_bytes: u64,
|
||||
payload: &mut File,
|
||||
config: Option<&mut File>,
|
||||
) -> Result<()> {
|
||||
disk.set_len(disk_bytes)?;
|
||||
let mut gpt = GPT::new_from(disk, SECTOR_BYTES, Uuid::new_v4().to_bytes_le())?;
|
||||
GPT::write_protective_mbr_into(disk, SECTOR_BYTES)?;
|
||||
gpt[1] = GPTPartitionEntry {
|
||||
partition_type_guid: EFI_PARTITION_TYPE,
|
||||
unique_partition_guid: Uuid::new_v4().to_bytes_le(),
|
||||
starting_lba: 2048,
|
||||
ending_lba: gpt.header.last_usable_lba,
|
||||
attribute_bits: 0,
|
||||
partition_name: "EFI System".into(),
|
||||
};
|
||||
gpt.write_into(disk)?;
|
||||
let mut stream = partition_slice(disk, &gpt[1], disk_bytes)?;
|
||||
fatfs::format_volume(
|
||||
&mut stream,
|
||||
FormatVolumeOptions::new().fat_type(FatType::Fat32),
|
||||
)?;
|
||||
stream.rewind()?;
|
||||
let fs = FileSystem::new(stream, FsOptions::new())?;
|
||||
{
|
||||
let root = fs.root_dir();
|
||||
root.create_dir("EFI")?.create_dir("BOOT")?;
|
||||
let mut boot = root.create_file(BOOT_FILE)?;
|
||||
io::copy(payload, &mut boot)?;
|
||||
boot.flush()?;
|
||||
if let Some(config) = config {
|
||||
root.open_dir("EFI")?.create_dir("stela")?;
|
||||
let mut config_file = root.create_file(CONFIG_FILE)?;
|
||||
io::copy(config, &mut config_file)?;
|
||||
config_file.flush()?;
|
||||
}
|
||||
}
|
||||
fs.unmount()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn validate(path: &Path) -> Result<Option<StambhaConfig>> {
|
||||
let mut disk = File::open(path).with_context(|| format!("open image {}", path.display()))?;
|
||||
let size = disk.metadata()?.len();
|
||||
ensure!(
|
||||
size >= 34 * SECTOR_BYTES && size % SECTOR_BYTES == 0,
|
||||
"expected a whole 512-byte-sector raw image"
|
||||
);
|
||||
// Parse the primary table directly; bound allocations and seeks before reading entries.
|
||||
disk.seek(SeekFrom::Start(SECTOR_BYTES))?;
|
||||
let header = GPTHeader::read_from(&mut disk).context("read primary GPT header")?;
|
||||
let entry_lba = header.partition_entry_lba;
|
||||
let entry_count = header.number_of_partition_entries;
|
||||
let entry_size = header.size_of_partition_entry;
|
||||
ensure!(
|
||||
(1..=4096).contains(&entry_count) && entry_size == 128,
|
||||
"unsupported GPT partition table dimensions"
|
||||
);
|
||||
let table_end = entry_lba
|
||||
.checked_mul(SECTOR_BYTES)
|
||||
.and_then(|offset| offset.checked_add(u64::from(entry_count) * u64::from(entry_size)));
|
||||
ensure!(
|
||||
entry_lba >= 2 && table_end.is_some_and(|end| end <= size),
|
||||
"GPT partition table extends beyond the image"
|
||||
);
|
||||
let mut entries = Vec::with_capacity(entry_count as usize);
|
||||
disk.seek(SeekFrom::Start(entry_lba * SECTOR_BYTES))?;
|
||||
for _ in 0..entry_count {
|
||||
entries.push(GPTPartitionEntry::read_from(&mut disk).context("read GPT entry")?);
|
||||
}
|
||||
ensure!(
|
||||
header.generate_partition_entry_array_crc32(&entries) == header.partition_entry_array_crc32,
|
||||
"primary GPT entry checksum mismatch"
|
||||
);
|
||||
let mut partitions = entries
|
||||
.iter()
|
||||
.filter(|entry| entry.partition_type_guid == EFI_PARTITION_TYPE);
|
||||
let partition = partitions
|
||||
.next()
|
||||
.context("EFI System Partition is missing")?;
|
||||
ensure!(
|
||||
partitions.next().is_none(),
|
||||
"expected exactly one EFI System Partition"
|
||||
);
|
||||
|
||||
let stream = partition_slice(&mut disk, partition, size)?;
|
||||
let fs = FileSystem::new(stream, FsOptions::new().update_accessed_date(false))
|
||||
.context("open EFI System Partition as FAT")?;
|
||||
let root = fs.root_dir();
|
||||
let mut efi = root
|
||||
.open_file(BOOT_FILE)
|
||||
.context("missing EFI/BOOT/BOOTX64.EFI")?;
|
||||
validate_pe(&mut efi).context("invalid EFI/BOOT/BOOTX64.EFI")?;
|
||||
match root.open_file(CONFIG_FILE) {
|
||||
Ok(config) => read_stambha_config(config).map(Some),
|
||||
Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(None),
|
||||
Err(error) => Err(error).context("read EFI/stela/stela.cfg"),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Serialize, PartialEq, Eq)]
|
||||
pub(crate) struct StambhaConfig {
|
||||
starts_system: bool,
|
||||
requests_host_check: bool,
|
||||
requests_storage: bool,
|
||||
requests_reims_vgpu: bool,
|
||||
}
|
||||
|
||||
fn read_stambha_config(input: impl Read) -> Result<StambhaConfig> {
|
||||
let mut text = String::new();
|
||||
input
|
||||
.take(MAX_CONFIG_BYTES as u64 + 1)
|
||||
.read_to_string(&mut text)
|
||||
.context("read UTF-8 stela.cfg")?;
|
||||
ensure!(
|
||||
text.len() <= MAX_CONFIG_BYTES,
|
||||
"Stambha config is too large"
|
||||
);
|
||||
let mut config = StambhaConfig {
|
||||
starts_system: false,
|
||||
requests_host_check: false,
|
||||
requests_storage: false,
|
||||
requests_reims_vgpu: false,
|
||||
};
|
||||
for flag in text.split_whitespace() {
|
||||
match flag {
|
||||
"--system" => config.starts_system = true,
|
||||
"--host-check" => config.requests_host_check = true,
|
||||
"--storage" | "--storage-check" | "--nor" => config.requests_storage = true,
|
||||
"--hosted-reims-base" | "--hosted-reims-irq" => config.requests_reims_vgpu = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
fn partition_slice<'a>(
|
||||
disk: &'a mut File,
|
||||
entry: &GPTPartitionEntry,
|
||||
size: u64,
|
||||
) -> Result<StreamSlice<&'a mut File>> {
|
||||
// GPT ending LBA is inclusive, but StreamSlice's upper bound is exclusive.
|
||||
let start = entry.starting_lba.checked_mul(SECTOR_BYTES);
|
||||
let end = entry
|
||||
.ending_lba
|
||||
.checked_add(1)
|
||||
.and_then(|lba| lba.checked_mul(SECTOR_BYTES));
|
||||
let (start, end) = start.zip(end).context("EFI partition offset overflow")?;
|
||||
ensure!(
|
||||
start < end && end <= size,
|
||||
"EFI partition extends beyond the image"
|
||||
);
|
||||
Ok(StreamSlice::new(disk, start, end)?)
|
||||
}
|
||||
|
||||
fn validate_pe(input: &mut (impl Read + Seek)) -> Result<()> {
|
||||
let mut dos = [0u8; 64];
|
||||
input.read_exact(&mut dos).context("read PE DOS header")?;
|
||||
ensure!(&dos[..2] == b"MZ", "missing PE DOS signature");
|
||||
let pe_offset = u32::from_le_bytes(dos[60..64].try_into()?);
|
||||
ensure!(pe_offset >= 64, "invalid PE offset");
|
||||
input.seek(SeekFrom::Start(u64::from(pe_offset)))?;
|
||||
let mut pe = [0u8; 94];
|
||||
input
|
||||
.read_exact(&mut pe)
|
||||
.context("read PE and optional headers")?;
|
||||
ensure!(&pe[..4] == b"PE\0\0", "missing PE signature");
|
||||
ensure!(
|
||||
u16::from_le_bytes(pe[4..6].try_into()?) == 0x8664,
|
||||
"expected x64 PE machine"
|
||||
);
|
||||
ensure!(
|
||||
u16::from_le_bytes(pe[20..22].try_into()?) >= 70,
|
||||
"truncated PE optional header"
|
||||
);
|
||||
ensure!(
|
||||
u16::from_le_bytes(pe[24..26].try_into()?) == 0x20b,
|
||||
"expected PE32+ image"
|
||||
);
|
||||
ensure!(
|
||||
u16::from_le_bytes(pe[92..94].try_into()?) == 10,
|
||||
"expected EFI application subsystem"
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn pe_fixture(machine: u16) -> Vec<u8> {
|
||||
let mut bytes = vec![0u8; 158];
|
||||
bytes[..2].copy_from_slice(b"MZ");
|
||||
bytes[60..64].copy_from_slice(&64u32.to_le_bytes());
|
||||
bytes[64..68].copy_from_slice(b"PE\0\0");
|
||||
bytes[68..70].copy_from_slice(&machine.to_le_bytes());
|
||||
bytes[84..86].copy_from_slice(&70u16.to_le_bytes());
|
||||
bytes[88..90].copy_from_slice(&0x20bu16.to_le_bytes());
|
||||
bytes[156..158].copy_from_slice(&10u16.to_le_bytes());
|
||||
bytes
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_and_validates_read_only_efi_media() -> Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
let efi = dir.path().join("fixture.efi");
|
||||
let config = dir.path().join("stela.cfg");
|
||||
let disk = dir.path().join("test.img");
|
||||
std::fs::write(&efi, pe_fixture(0x8664))?;
|
||||
std::fs::write(
|
||||
&config,
|
||||
b"--system --storage STELAANS:fixture --hosted-reims-irq auto\n",
|
||||
)?;
|
||||
create(&efi, Some(&config), &disk)?;
|
||||
let expected_config = StambhaConfig {
|
||||
starts_system: true,
|
||||
requests_host_check: false,
|
||||
requests_storage: true,
|
||||
requests_reims_vgpu: true,
|
||||
};
|
||||
assert_eq!(validate(&disk)?, Some(expected_config));
|
||||
assert!(create(&efi, None, &disk).is_err());
|
||||
assert!(validate(&disk)?.is_some());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_wrong_architecture_without_creating_an_image() -> Result<()> {
|
||||
let dir = tempfile::tempdir()?;
|
||||
let efi = dir.path().join("arm64.efi");
|
||||
let disk = dir.path().join("test.img");
|
||||
std::fs::write(&efi, pe_fixture(0xaa64))?;
|
||||
assert!(create(&efi, None, &disk).is_err());
|
||||
assert!(!disk.exists());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sizes_the_image_for_large_local_stambha_payloads() -> Result<()> {
|
||||
assert_eq!(image_size(89_000_000)?, 93 * MIB);
|
||||
assert!(image_size(u64::MAX).is_err());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user