test(nvidia): make the live payload gate prove compatibility
The verifier accepted one-byte placeholder modules, a caller-supplied version/flavor, any NVIDIA firmware file and a nouveau blacklist that happened to exist somewhere. It now establishes what it claims: - reject placeholder modules and userspace libraries (size floor); - require every module to be registered in the live kernel's modules.dep; - normalise the dpkg revision and require the userspace libnvidia-glcore and firmware directory versions to match the bundled driver; - infer the module flavor from the on-disk naming and reject a contradiction; - require the exact etc/modprobe.d/phoebus-nvidia.conf with nouveau blacklist and nvidia_drm modeset, not any blacklist; - keep every filesystem read rooted inside the build root. Negative tests cover placeholders, version mismatches, a stale modules.dep, a contradictory flavor and a missing final config.
This commit is contained in:
parent
b32683da99
commit
5103b57be9
3 changed files with 476 additions and 155 deletions
|
|
@ -106,17 +106,20 @@ fn kernel_version(rootfs: &Path) -> Result<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn walk(root: &Path, out: &mut Vec<String>) {
|
/// Walk `root` without following symlinks, collecting `(file name, path)`.
|
||||||
|
///
|
||||||
|
/// `DirEntry::file_type` does not follow symlinks, so a symlink inside the
|
||||||
|
/// rootfs can never make us walk the host, and every returned path is inside
|
||||||
|
/// `root` by construction.
|
||||||
|
fn walk_files(root: &Path, out: &mut Vec<(String, PathBuf)>) {
|
||||||
if let Ok(entries) = std::fs::read_dir(root) {
|
if let Ok(entries) = std::fs::read_dir(root) {
|
||||||
for entry in entries.flatten() {
|
for entry in entries.flatten() {
|
||||||
let path = entry.path();
|
let path = entry.path();
|
||||||
// `DirEntry::file_type` does not follow symlinks, so an absolute
|
|
||||||
// symlink inside the rootfs can never make us walk the host.
|
|
||||||
match entry.file_type() {
|
match entry.file_type() {
|
||||||
Ok(ft) if ft.is_dir() => walk(&path, out),
|
Ok(ft) if ft.is_dir() => walk_files(&path, out),
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
|
||||||
out.push(name.to_string());
|
out.push((name.to_string(), path));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {}
|
Err(_) => {}
|
||||||
|
|
@ -125,6 +128,26 @@ fn walk(root: &Path, out: &mut Vec<String>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// All files under `root`, as `(name, path)` pairs rooted inside it.
|
||||||
|
fn files_under(root: &Path) -> Vec<(String, PathBuf)> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
walk_files(root, &mut out);
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Directory names directly under `root`.
|
||||||
|
fn dirs_under(root: &Path) -> Vec<String> {
|
||||||
|
let mut out = Vec::new();
|
||||||
|
if let Ok(entries) = std::fs::read_dir(root) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
if entry.file_type().map(|t| t.is_dir()).unwrap_or(false) {
|
||||||
|
out.push(entry.file_name().to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
|
||||||
/// Read a rootfs-relative file, resolving symlinks **within** the rootfs.
|
/// Read a rootfs-relative file, resolving symlinks **within** the rootfs.
|
||||||
fn read_in_rootfs(rootfs: &Path, rel: &str) -> Option<String> {
|
fn read_in_rootfs(rootfs: &Path, rel: &str) -> Option<String> {
|
||||||
let mut current = rootfs.join(rel.trim_start_matches('/'));
|
let mut current = rootfs.join(rel.trim_start_matches('/'));
|
||||||
|
|
@ -145,35 +168,50 @@ fn read_in_rootfs(rootfs: &Path, rel: &str) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Whether `rel` (relative to the rootfs) resolves to a file, following
|
/// Size of a file, or 0 when it is missing or unreadable (a broken symlink
|
||||||
/// symlinks **within** the rootfs. Absolute symlinks are meaningless outside it,
|
/// included, because `metadata` follows symlinks).
|
||||||
/// so they are resolved against the rootfs, never the host.
|
fn size_of(path: &Path) -> u64 {
|
||||||
fn exists_in_rootfs(rootfs: &Path, rel: &str) -> bool {
|
std::fs::metadata(path).map(|m| m.len()).unwrap_or(0)
|
||||||
let mut current = rootfs.join(rel.trim_start_matches('/'));
|
|
||||||
for _ in 0..16 {
|
|
||||||
match std::fs::symlink_metadata(¤t) {
|
|
||||||
Err(_) => return false,
|
|
||||||
Ok(meta) if meta.file_type().is_symlink() => {
|
|
||||||
let Ok(target) = std::fs::read_link(¤t) else {
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
if target.is_absolute() {
|
|
||||||
current = rootfs.join(target.strip_prefix("/").unwrap_or(&target));
|
|
||||||
} else {
|
|
||||||
current = current.parent().unwrap_or(rootfs).join(target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(meta) => return meta.is_file(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// All file names under `root`, for a bounded, rootfs-relative search.
|
/// The upstream part of a driver version: Debian's `550.163.01-1~deb13u1`
|
||||||
fn names_under(root: &Path) -> Vec<String> {
|
/// becomes `550.163.01`.
|
||||||
let mut out = Vec::new();
|
fn upstream_version(version: &str) -> &str {
|
||||||
walk(root, &mut out);
|
version
|
||||||
out
|
.split(['-', '~', '+'])
|
||||||
|
.next()
|
||||||
|
.filter(|s| !s.is_empty())
|
||||||
|
.unwrap_or(version)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A dotted numeric version embedded in a shared-library name, e.g.
|
||||||
|
/// `libnvidia-glcore.so.550.163.01` -> `550.163.01`. `libGLX_nvidia.so.0`
|
||||||
|
/// yields `None` because a bare SONAME is not the driver version.
|
||||||
|
fn embedded_version(name: &str, prefix: &str) -> Option<String> {
|
||||||
|
let rest = name.strip_prefix(prefix)?;
|
||||||
|
let rest = rest.strip_prefix('.')?;
|
||||||
|
let version = rest.trim_end_matches(|c: char| c.is_ascii_alphabetic());
|
||||||
|
if version.is_empty()
|
||||||
|
|| !version.chars().next()?.is_ascii_digit()
|
||||||
|
|| !version.contains('.')
|
||||||
|
|| !version
|
||||||
|
.chars()
|
||||||
|
.all(|c| c.is_ascii_digit() || c == '.')
|
||||||
|
{
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
Some(version.trim_end_matches('.').to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The flavor a module name implies, when the name is Debian's renamed form.
|
||||||
|
fn flavor_from_module_name(name: &str) -> Option<&'static str> {
|
||||||
|
if name.contains("-open") || name.contains("nvidia-open") {
|
||||||
|
Some("open")
|
||||||
|
} else if name.starts_with("nvidia-current") {
|
||||||
|
Some("proprietary")
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The logical NVIDIA module and the on-disk names that may provide it. Debian's
|
/// The logical NVIDIA module and the on-disk names that may provide it. Debian's
|
||||||
|
|
@ -194,20 +232,54 @@ fn name_matches(file: &str, module: &str) -> bool {
|
||||||
file == format!("{module}.ko") || file.starts_with(&format!("{module}.ko."))
|
file == format!("{module}.ko") || file.starts_with(&format!("{module}.ko."))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The mounted-module name actually found on disk.
|
/// A real kernel module or shared library is far larger than this. A tiny file
|
||||||
fn find_module(names: &[String], module: &str) -> Option<String> {
|
/// is a placeholder that must never satisfy the build gate.
|
||||||
for candidate in module_candidates(module) {
|
const MIN_BINARY_BYTES: u64 = 4096;
|
||||||
if names.iter().any(|n| name_matches(n, candidate)) {
|
|
||||||
return Some(format!("{candidate}.ko"));
|
/// Resolve a rootfs-relative path *within* the rootfs. Absolute symlinks are
|
||||||
|
/// clamped to the rootfs, never resolved against the host.
|
||||||
|
fn resolve_in_rootfs(rootfs: &Path, rel: &str) -> Option<PathBuf> {
|
||||||
|
let mut current = rootfs.join(rel.trim_start_matches('/'));
|
||||||
|
for _ in 0..16 {
|
||||||
|
match std::fs::symlink_metadata(¤t) {
|
||||||
|
Err(_) => return None,
|
||||||
|
Ok(meta) if meta.file_type().is_symlink() => {
|
||||||
|
let target = std::fs::read_link(¤t).ok()?;
|
||||||
|
current = if target.is_absolute() {
|
||||||
|
rootfs.join(target.strip_prefix("/").unwrap_or(&target))
|
||||||
|
} else {
|
||||||
|
current.parent().unwrap_or(rootfs).join(target)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Ok(_) => return Some(current),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify that `rootfs` bundles a complete NVIDIA payload for its live kernel.
|
/// The on-disk module file for a logical module: `(recorded label, file name,
|
||||||
|
/// path)`. The label is the canonical `<candidate>.ko`; the file name keeps the
|
||||||
|
/// compression/renaming suffix for the `modules.dep` check.
|
||||||
|
fn find_module_file(
|
||||||
|
files: &[(String, PathBuf)],
|
||||||
|
module: &str,
|
||||||
|
) -> Option<(String, String, PathBuf)> {
|
||||||
|
for candidate in module_candidates(module) {
|
||||||
|
if let Some((name, path)) = files.iter().find(|(n, _)| name_matches(n, candidate)) {
|
||||||
|
return Some((format!("{candidate}.ko"), name.clone(), path.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Verify that `rootfs` bundles a complete and *self-consistent* NVIDIA payload
|
||||||
|
/// for the one kernel it boots.
|
||||||
///
|
///
|
||||||
/// Any missing or mismatched component is a hard error: the build fails rather
|
/// This is a compatibility gate, not a presence checklist: it rejects an
|
||||||
/// than shipping an image that cannot accelerate the GPU it advertises.
|
/// incomplete payload, placeholder files, a module tree built for another
|
||||||
|
/// kernel, a userspace/firmware version that does not match the bundled driver,
|
||||||
|
/// a flavor that contradicts the module naming, and a final boot configuration
|
||||||
|
/// that would not activate the driver. Any mismatch fails the build.
|
||||||
pub fn verify_live_nvidia(
|
pub fn verify_live_nvidia(
|
||||||
rootfs: &Path,
|
rootfs: &Path,
|
||||||
driver_version: &str,
|
driver_version: &str,
|
||||||
|
|
@ -220,26 +292,43 @@ pub fn verify_live_nvidia(
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let kernel = kernel_version(rootfs)?;
|
let kernel = kernel_version(rootfs)?;
|
||||||
|
let upstream = upstream_version(driver_version).to_string();
|
||||||
|
|
||||||
// Kernel modules built for exactly this kernel.
|
// Kernel modules built for exactly this kernel. Both module roots are
|
||||||
let mut module_names = Vec::new();
|
// scanned for a merged-usr image and deduplicated by name: `/lib` and
|
||||||
|
// `/usr/lib` describe the same tree, not two kernels.
|
||||||
|
let mut module_files: Vec<(String, PathBuf)> = Vec::new();
|
||||||
for modules_root in ["lib/modules", "usr/lib/modules"] {
|
for modules_root in ["lib/modules", "usr/lib/modules"] {
|
||||||
let dir = rootfs.join(modules_root).join(&kernel);
|
let dir = rootfs.join(modules_root).join(&kernel);
|
||||||
if dir.is_dir() {
|
if dir.is_dir() {
|
||||||
module_names.extend(names_under(&dir));
|
for (name, path) in files_under(&dir) {
|
||||||
|
if !module_files.iter().any(|(n, _)| n == &name) {
|
||||||
|
module_files.push((name, path));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if module_names.is_empty() {
|
if module_files.is_empty() {
|
||||||
return Err(fail(format!(
|
return Err(fail(format!(
|
||||||
"no modules found for kernel {kernel}; the driver was not built for the live kernel"
|
"no modules found for kernel {kernel}; the driver was not built for the live kernel"
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
let required = ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"];
|
let required = ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"];
|
||||||
let mut modules = Vec::new();
|
let mut modules = Vec::new();
|
||||||
|
let mut found: Vec<(String, PathBuf)> = Vec::new();
|
||||||
let mut missing = Vec::new();
|
let mut missing = Vec::new();
|
||||||
for module in required {
|
for module in required {
|
||||||
match find_module(&module_names, module) {
|
match find_module_file(&module_files, module) {
|
||||||
Some(name) => modules.push(name),
|
Some((label, file, path)) => {
|
||||||
|
let size = size_of(&path);
|
||||||
|
if size < MIN_BINARY_BYTES {
|
||||||
|
return Err(fail(format!(
|
||||||
|
"kernel module {file} is a placeholder ({size} bytes); the driver was not built"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
modules.push(label);
|
||||||
|
found.push((file, path));
|
||||||
|
}
|
||||||
None => missing.push(module),
|
None => missing.push(module),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,30 +339,64 @@ pub fn verify_live_nvidia(
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kernel compatibility: modules the kernel cannot resolve are useless. Every
|
||||||
|
// required module must be registered in this kernel's `modules.dep`.
|
||||||
|
let dep = read_in_rootfs(rootfs, &format!("lib/modules/{kernel}/modules.dep"))
|
||||||
|
.or_else(|| read_in_rootfs(rootfs, &format!("usr/lib/modules/{kernel}/modules.dep")))
|
||||||
|
.ok_or_else(|| {
|
||||||
|
fail(format!(
|
||||||
|
"kernel {kernel} has no readable modules.dep; the module tree is incomplete"
|
||||||
|
))
|
||||||
|
})?;
|
||||||
|
for (file, _) in &found {
|
||||||
|
if !dep.contains(file.as_str()) {
|
||||||
|
return Err(fail(format!(
|
||||||
|
"kernel {kernel} modules.dep does not register {file}; the driver was not built for this kernel"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establish the actual flavor from the on-disk naming and reject a payload
|
||||||
|
// whose naming contradicts the flavor the build claims.
|
||||||
|
if let Some(observed) = found
|
||||||
|
.iter()
|
||||||
|
.find_map(|(file, _)| flavor_from_module_name(file))
|
||||||
|
{
|
||||||
|
if observed != flavor.as_str() {
|
||||||
|
return Err(fail(format!(
|
||||||
|
"the modules are a {observed} build but a {} payload was expected",
|
||||||
|
flavor.as_str()
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Userspace: GLVND/GLX libraries, the management tool, and the Wayland/GBM
|
// Userspace: GLVND/GLX libraries, the management tool, and the Wayland/GBM
|
||||||
// EGL external-platform integration.
|
// EGL external-platform integration.
|
||||||
let lib_names = names_under(&rootfs.join("usr/lib"));
|
let lib_files = files_under(&rootfs.join("usr/lib"));
|
||||||
let mut userspace = Vec::new();
|
let mut userspace = Vec::new();
|
||||||
let mut missing_lib = Vec::new();
|
let mut missing_lib = Vec::new();
|
||||||
if let Some(name) = find_prefix(&lib_names, "libnvidia-glcore.so") {
|
let mut glcore_version: Option<String> = None;
|
||||||
userspace.push(name);
|
for prefix in [
|
||||||
} else {
|
"libnvidia-glcore.so",
|
||||||
missing_lib.push("libnvidia-glcore.so");
|
"libGLX_nvidia.so",
|
||||||
}
|
"libnvidia-egl-gbm.so",
|
||||||
if let Some(name) = find_prefix(&lib_names, "libGLX_nvidia.so") {
|
"libnvidia-egl-wayland.so",
|
||||||
userspace.push(name);
|
] {
|
||||||
} else {
|
match lib_files.iter().find(|(n, _)| n.starts_with(prefix)) {
|
||||||
missing_lib.push("libGLX_nvidia.so");
|
Some((name, path)) => {
|
||||||
}
|
let size = size_of(path);
|
||||||
if let Some(name) = find_prefix(&lib_names, "libnvidia-egl-gbm.so") {
|
if size < MIN_BINARY_BYTES {
|
||||||
userspace.push(name);
|
return Err(fail(format!(
|
||||||
} else {
|
"userspace library {name} is a placeholder ({size} bytes)"
|
||||||
missing_lib.push("libnvidia-egl-gbm.so");
|
)));
|
||||||
}
|
}
|
||||||
if let Some(name) = find_prefix(&lib_names, "libnvidia-egl-wayland.so") {
|
if prefix == "libnvidia-glcore.so" {
|
||||||
userspace.push(name);
|
glcore_version = embedded_version(name, prefix);
|
||||||
} else {
|
}
|
||||||
missing_lib.push("libnvidia-egl-wayland.so");
|
userspace.push(prefix.to_string());
|
||||||
|
}
|
||||||
|
None => missing_lib.push(prefix),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !missing_lib.is_empty() {
|
if !missing_lib.is_empty() {
|
||||||
return Err(fail(format!(
|
return Err(fail(format!(
|
||||||
|
|
@ -281,61 +404,98 @@ pub fn verify_live_nvidia(
|
||||||
missing_lib.join(", ")
|
missing_lib.join(", ")
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
if !exists_in_rootfs(rootfs, "usr/bin/nvidia-smi") {
|
// The userspace driver version must match the module/firmware version, or
|
||||||
return Err(fail(
|
// the accelerated stack fails with an API mismatch.
|
||||||
"usr/bin/nvidia-smi is missing (nvidia-smi package not installed)".into(),
|
if let Some(found_version) = &glcore_version {
|
||||||
));
|
if found_version != &upstream {
|
||||||
}
|
|
||||||
userspace.push("nvidia-smi".into());
|
|
||||||
|
|
||||||
// EGL external-platform manifests drive Wayland/GBM interop.
|
|
||||||
let egl_dir = rootfs.join("usr/share/egl/egl_external_platform.d");
|
|
||||||
let egl = names_under(&egl_dir);
|
|
||||||
for required_json in ["15_nvidia_gbm.json", "10_nvidia_wayland.json"] {
|
|
||||||
if !egl.iter().any(|n| n == required_json) {
|
|
||||||
return Err(fail(format!(
|
return Err(fail(format!(
|
||||||
"EGL external-platform manifest {required_json} is missing under usr/share/egl/egl_external_platform.d"
|
"userspace library version {found_version} does not match the bundled driver {upstream}"
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userspace.push("15_nvidia_gbm.json".into());
|
match resolve_in_rootfs(rootfs, "usr/bin/nvidia-smi") {
|
||||||
userspace.push("10_nvidia_wayland.json".into());
|
Some(path) if size_of(&path) > 0 => userspace.push("nvidia-smi".into()),
|
||||||
|
Some(_) => return Err(fail("usr/bin/nvidia-smi is empty".into())),
|
||||||
|
None => {
|
||||||
|
return Err(fail(
|
||||||
|
"usr/bin/nvidia-smi is missing (nvidia-smi package not installed)".into(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Firmware (GSP) is mandatory for the module to initialise.
|
// EGL external-platform manifests drive Wayland/GBM interop.
|
||||||
let firmware_names = names_under(&rootfs.join("usr/lib/firmware/nvidia"));
|
let egl = files_under(&rootfs.join("usr/share/egl/egl_external_platform.d"));
|
||||||
if firmware_names.is_empty() {
|
for required_json in ["15_nvidia_gbm.json", "10_nvidia_wayland.json"] {
|
||||||
|
match egl.iter().find(|(n, _)| n == required_json) {
|
||||||
|
Some((_, path)) if size_of(path) > 0 => userspace.push(required_json.to_string()),
|
||||||
|
_ => {
|
||||||
|
return Err(fail(format!(
|
||||||
|
"EGL external-platform manifest {required_json} is missing or empty under usr/share/egl/egl_external_platform.d"
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Firmware (GSP) is mandatory for the module to initialise, and its version
|
||||||
|
// directory names the driver it was built for.
|
||||||
|
let fw_root = rootfs.join("usr/lib/firmware/nvidia");
|
||||||
|
if files_under(&fw_root).is_empty() {
|
||||||
return Err(fail(
|
return Err(fail(
|
||||||
"no NVIDIA firmware found under usr/lib/firmware/nvidia (firmware-nvidia-gsp/graphics not installed)"
|
"no NVIDIA firmware found under usr/lib/firmware/nvidia (firmware-nvidia-gsp/graphics not installed)"
|
||||||
.into(),
|
.into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let firmware: Vec<String> = firmware_names.into_iter().take(16).collect();
|
let versions = dirs_under(&fw_root);
|
||||||
|
if !versions.is_empty() && !versions.iter().any(|v| v == &upstream) {
|
||||||
// The live-only load script and its unit must be present and gated so a
|
return Err(fail(format!(
|
||||||
// machine without an NVIDIA GPU never records a failed unit. Nouveau must be
|
"firmware directory {} does not match the bundled driver {upstream}",
|
||||||
// blacklisted by the distro's own nvidia-kernel-common configuration.
|
versions.join(", ")
|
||||||
if !exists_in_rootfs(rootfs, "usr/local/bin/phoebus-nvidia-load") {
|
)));
|
||||||
|
}
|
||||||
|
let gsp: Vec<(String, PathBuf)> = files_under(&fw_root)
|
||||||
|
.into_iter()
|
||||||
|
.filter(|(n, _)| n.starts_with("gsp"))
|
||||||
|
.collect();
|
||||||
|
if gsp.is_empty() || gsp.iter().all(|(_, p)| size_of(p) == 0) {
|
||||||
return Err(fail(
|
return Err(fail(
|
||||||
"usr/local/bin/phoebus-nvidia-load is missing (gated driver load)".into(),
|
"no non-empty GSP firmware (gsp_*.bin) found under usr/lib/firmware/nvidia".into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
let mut has_nouveau_blacklist = false;
|
let firmware: Vec<String> = files_under(&fw_root)
|
||||||
if let Ok(entries) = std::fs::read_dir(rootfs.join("etc/modprobe.d")) {
|
.into_iter()
|
||||||
for entry in entries.flatten() {
|
.filter(|(_, p)| size_of(p) > 0)
|
||||||
let rel = format!("etc/modprobe.d/{}", entry.file_name().to_string_lossy());
|
.map(|(n, _)| n)
|
||||||
if let Some(text) = read_in_rootfs(rootfs, &rel) {
|
.take(16)
|
||||||
if text.contains("blacklist nouveau") {
|
.collect();
|
||||||
has_nouveau_blacklist = true;
|
|
||||||
}
|
// The live-only load script must be present; a machine without an NVIDIA
|
||||||
}
|
// GPU must never record a failed unit.
|
||||||
}
|
let load = resolve_in_rootfs(rootfs, "usr/local/bin/phoebus-nvidia-load").filter(|p| {
|
||||||
}
|
size_of(p) > 0
|
||||||
if !has_nouveau_blacklist {
|
});
|
||||||
|
if load.is_none() {
|
||||||
return Err(fail(
|
return Err(fail(
|
||||||
"no nouveau blacklist found under etc/modprobe.d; the selected branch could be preempted"
|
"usr/local/bin/phoebus-nvidia-load is missing or empty (gated driver load)".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// The final boot configuration must carry the intended policy, not merely
|
||||||
|
// any nouveau blacklist somewhere: the load script and the fallback both
|
||||||
|
// depend on this exact file.
|
||||||
|
let conf = read_in_rootfs(rootfs, "etc/modprobe.d/phoebus-nvidia.conf").ok_or_else(|| {
|
||||||
|
fail("etc/modprobe.d/phoebus-nvidia.conf is missing; the live driver policy was not installed".into())
|
||||||
|
})?;
|
||||||
|
if !conf.contains("blacklist nouveau") {
|
||||||
|
return Err(fail(
|
||||||
|
"etc/modprobe.d/phoebus-nvidia.conf does not blacklist nouveau; the driver could be preempted"
|
||||||
.into(),
|
.into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if !conf.contains("modeset=1") {
|
||||||
|
return Err(fail(
|
||||||
|
"etc/modprobe.d/phoebus-nvidia.conf does not enable nvidia_drm modeset".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(LiveNvidiaPayload {
|
Ok(LiveNvidiaPayload {
|
||||||
kernel_version: kernel,
|
kernel_version: kernel,
|
||||||
|
|
@ -347,48 +507,71 @@ pub fn verify_live_nvidia(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Find the first name starting with `prefix`, returning a bounded label.
|
|
||||||
fn find_prefix(names: &[String], prefix: &str) -> Option<String> {
|
|
||||||
names
|
|
||||||
.iter()
|
|
||||||
.find(|n| n.starts_with(prefix))
|
|
||||||
.map(|_| prefix.to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn touch(path: &Path) {
|
const KVER: &str = "6.16.7-amd64";
|
||||||
|
const DRIVER: &str = "550.163.01";
|
||||||
|
|
||||||
|
fn write_bytes(path: &Path, len: usize) {
|
||||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||||
std::fs::write(path, b"x").unwrap();
|
std::fs::write(path, vec![0u8; len]).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn touch(path: &Path) {
|
||||||
|
write_bytes(path, 8192);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register every module file under `updates/dkms` in `modules.dep`, so a
|
||||||
|
/// fixture models a kernel whose module tree is coherent.
|
||||||
|
fn write_dep(kernel_dir: &Path) {
|
||||||
|
let dkms = kernel_dir.join("updates/dkms");
|
||||||
|
let mut lines = Vec::new();
|
||||||
|
if let Ok(entries) = std::fs::read_dir(&dkms) {
|
||||||
|
for entry in entries.flatten() {
|
||||||
|
lines.push(format!(
|
||||||
|
"updates/dkms/{}:",
|
||||||
|
entry.file_name().to_string_lossy()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.sort();
|
||||||
|
std::fs::write(kernel_dir.join("modules.dep"), lines.join("\n")).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn install_modules(root: &Path) {
|
||||||
|
let kernel = root.join(format!("lib/modules/{KVER}"));
|
||||||
|
std::fs::create_dir_all(&kernel).unwrap();
|
||||||
|
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
||||||
|
touch(&kernel.join(format!("updates/dkms/{m}.ko")));
|
||||||
|
}
|
||||||
|
write_dep(&kernel);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_rootfs(root: &Path) {
|
fn complete_rootfs(root: &Path) {
|
||||||
let kver = "6.16.7-amd64";
|
touch(&root.join(format!("boot/vmlinuz-{KVER}")));
|
||||||
touch(&root.join(format!("boot/vmlinuz-{kver}")));
|
install_modules(root);
|
||||||
let modules = root.join(format!("lib/modules/{kver}"));
|
|
||||||
std::fs::create_dir_all(&modules).unwrap();
|
|
||||||
std::fs::write(modules.join("modules.dep"), b"").unwrap();
|
|
||||||
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
|
||||||
touch(&modules.join(format!("updates/dkms/{m}.ko")));
|
|
||||||
}
|
|
||||||
for lib in [
|
for lib in [
|
||||||
"libnvidia-glcore.so.550.163.01",
|
format!("libnvidia-glcore.so.{DRIVER}"),
|
||||||
"libGLX_nvidia.so.0",
|
"libGLX_nvidia.so.0".to_string(),
|
||||||
"libnvidia-egl-gbm.so.1.1.2",
|
"libnvidia-egl-gbm.so.1.1.2".to_string(),
|
||||||
"libnvidia-egl-wayland.so.1.1.21",
|
"libnvidia-egl-wayland.so.1.1.21".to_string(),
|
||||||
] {
|
] {
|
||||||
touch(&root.join("usr/lib/x86_64-linux-gnu").join(lib));
|
touch(&root.join("usr/lib/x86_64-linux-gnu").join(lib));
|
||||||
}
|
}
|
||||||
touch(&root.join("usr/bin/nvidia-smi"));
|
touch(&root.join("usr/bin/nvidia-smi"));
|
||||||
touch(&root.join("usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json"));
|
touch(&root.join("usr/share/egl/egl_external_platform.d/15_nvidia_gbm.json"));
|
||||||
touch(&root.join("usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json"));
|
touch(&root.join("usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json"));
|
||||||
touch(&root.join("usr/lib/firmware/nvidia/550.163.01/gsp_ga10x.bin"));
|
touch(&root.join(format!("usr/lib/firmware/nvidia/{DRIVER}/gsp_ga10x.bin")));
|
||||||
touch(&root.join("usr/local/bin/phoebus-nvidia-load"));
|
touch(&root.join("usr/local/bin/phoebus-nvidia-load"));
|
||||||
let blacklist = root.join("etc/modprobe.d/nvidia-blacklists-nouveau.conf");
|
let conf = root.join("etc/modprobe.d/phoebus-nvidia.conf");
|
||||||
std::fs::create_dir_all(blacklist.parent().unwrap()).unwrap();
|
std::fs::create_dir_all(conf.parent().unwrap()).unwrap();
|
||||||
std::fs::write(&blacklist, b"blacklist nouveau\n").unwrap();
|
std::fs::write(
|
||||||
|
&conf,
|
||||||
|
b"blacklist nouveau\noptions nvidia_drm modeset=1\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
@ -396,24 +579,34 @@ mod tests {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
complete_rootfs(dir.path());
|
complete_rootfs(dir.path());
|
||||||
let payload =
|
let payload =
|
||||||
verify_live_nvidia(dir.path(), "550.163.01", NvidiaModuleFlavor::Proprietary).unwrap();
|
verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary).unwrap();
|
||||||
assert_eq!(payload.kernel_version, "6.16.7-amd64");
|
assert_eq!(payload.kernel_version, KVER);
|
||||||
assert_eq!(payload.modules.len(), 4);
|
assert_eq!(payload.modules.len(), 4);
|
||||||
let record = payload.record();
|
let record = payload.record();
|
||||||
assert!(record.contains("driver_version=550.163.01"));
|
assert!(record.contains("driver_version=550.163.01"));
|
||||||
assert!(record.contains("flavor=proprietary"));
|
assert!(record.contains("flavor=proprietary"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_debian_revision_in_the_version_is_normalised() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
// The dpkg version carries a Debian revision; the libs and firmware do
|
||||||
|
// not.
|
||||||
|
verify_live_nvidia(dir.path(), "550.163.01-1~deb13u1", NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn missing_kernel_module_fails_the_build() {
|
fn missing_kernel_module_fails_the_build() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
complete_rootfs(dir.path());
|
complete_rootfs(dir.path());
|
||||||
std::fs::remove_file(
|
std::fs::remove_file(
|
||||||
dir.path()
|
dir.path()
|
||||||
.join("lib/modules/6.16.7-amd64/updates/dkms/nvidia_drm.ko"),
|
.join(format!("lib/modules/{KVER}/updates/dkms/nvidia_drm.ko")),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let err = verify_live_nvidia(dir.path(), "550.163.01", NvidiaModuleFlavor::Proprietary)
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string();
|
.to_string();
|
||||||
assert!(err.contains("nvidia_drm"), "{err}");
|
assert!(err.contains("nvidia_drm"), "{err}");
|
||||||
|
|
@ -424,14 +617,14 @@ mod tests {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
complete_rootfs(dir.path());
|
complete_rootfs(dir.path());
|
||||||
std::fs::remove_file(dir.path().join("usr/bin/nvidia-smi")).unwrap();
|
std::fs::remove_file(dir.path().join("usr/bin/nvidia-smi")).unwrap();
|
||||||
assert!(verify_live_nvidia(dir.path(), "550", NvidiaModuleFlavor::Proprietary).is_err());
|
assert!(verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary).is_err());
|
||||||
|
|
||||||
let dir2 = tempfile::tempdir().unwrap();
|
let dir2 = tempfile::tempdir().unwrap();
|
||||||
std::fs::create_dir_all(dir2.path().join("usr/lib/firmware")).unwrap();
|
std::fs::create_dir_all(dir2.path().join("usr/lib/firmware")).unwrap();
|
||||||
complete_rootfs(dir2.path());
|
complete_rootfs(dir2.path());
|
||||||
// Remove the firmware tree.
|
// Remove the firmware tree.
|
||||||
std::fs::remove_dir_all(dir2.path().join("usr/lib/firmware/nvidia")).unwrap();
|
std::fs::remove_dir_all(dir2.path().join("usr/lib/firmware/nvidia")).unwrap();
|
||||||
let err = verify_live_nvidia(dir2.path(), "550", NvidiaModuleFlavor::Proprietary)
|
let err = verify_live_nvidia(dir2.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string();
|
.to_string();
|
||||||
assert!(err.contains("firmware"), "{err}");
|
assert!(err.contains("firmware"), "{err}");
|
||||||
|
|
@ -444,25 +637,23 @@ mod tests {
|
||||||
// Debian is merged-usr: the same kernel tree is visible under both
|
// Debian is merged-usr: the same kernel tree is visible under both
|
||||||
// /lib/modules and /usr/lib/modules. That must not look like two
|
// /lib/modules and /usr/lib/modules. That must not look like two
|
||||||
// kernels.
|
// kernels.
|
||||||
let kver = "6.16.7-amd64";
|
let dst = dir.path().join(format!("usr/lib/modules/{KVER}"));
|
||||||
let dst = dir.path().join(format!("usr/lib/modules/{kver}"));
|
|
||||||
std::fs::create_dir_all(dst.parent().unwrap()).unwrap();
|
|
||||||
std::fs::create_dir_all(&dst).unwrap();
|
std::fs::create_dir_all(&dst).unwrap();
|
||||||
std::fs::write(dst.join("modules.dep"), b"").unwrap();
|
std::fs::write(dst.join("modules.dep"), b"").unwrap();
|
||||||
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
||||||
touch(&dst.join(format!("updates/dkms/{m}.ko")));
|
touch(&dst.join(format!("updates/dkms/{m}.ko")));
|
||||||
}
|
}
|
||||||
let payload =
|
let payload =
|
||||||
verify_live_nvidia(dir.path(), "550.163.01", NvidiaModuleFlavor::Proprietary).unwrap();
|
verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary).unwrap();
|
||||||
assert_eq!(payload.kernel_version, kver);
|
assert_eq!(payload.kernel_version, KVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn debian_renamed_modules_are_accepted_and_recorded() {
|
fn debian_renamed_modules_are_accepted_and_recorded() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
complete_rootfs(dir.path());
|
complete_rootfs(dir.path());
|
||||||
let kver = "6.16.7-amd64";
|
let kernel = dir.path().join(format!("lib/modules/{KVER}"));
|
||||||
let dkms = dir.path().join(format!("lib/modules/{kver}/updates/dkms"));
|
let dkms = kernel.join("updates/dkms");
|
||||||
// Replace the upstream names with Debian's DKMS-renamed output.
|
// Replace the upstream names with Debian's DKMS-renamed output.
|
||||||
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
||||||
std::fs::remove_file(dkms.join(format!("{m}.ko"))).unwrap();
|
std::fs::remove_file(dkms.join(format!("{m}.ko"))).unwrap();
|
||||||
|
|
@ -475,8 +666,9 @@ mod tests {
|
||||||
] {
|
] {
|
||||||
touch(&dkms.join(format!("{m}.ko.xz")));
|
touch(&dkms.join(format!("{m}.ko.xz")));
|
||||||
}
|
}
|
||||||
|
write_dep(&kernel);
|
||||||
let payload =
|
let payload =
|
||||||
verify_live_nvidia(dir.path(), "550.163.01", NvidiaModuleFlavor::Proprietary).unwrap();
|
verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary).unwrap();
|
||||||
assert!(payload
|
assert!(payload
|
||||||
.modules
|
.modules
|
||||||
.contains(&"nvidia-current-drm.ko".to_string()));
|
.contains(&"nvidia-current-drm.ko".to_string()));
|
||||||
|
|
@ -486,11 +678,129 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn missing_kernel_is_reported() {
|
fn missing_kernel_is_reported() {
|
||||||
let dir = tempfile::tempdir().unwrap();
|
let dir = tempfile::tempdir().unwrap();
|
||||||
std::fs::create_dir_all(dir.path().join("lib/modules/6.16.7-amd64")).unwrap();
|
std::fs::create_dir_all(dir.path().join(format!("lib/modules/{KVER}"))).unwrap();
|
||||||
std::fs::write(dir.path().join("lib/modules/6.16.7-amd64/modules.dep"), b"").unwrap();
|
std::fs::write(
|
||||||
|
dir.path().join(format!("lib/modules/{KVER}/modules.dep")),
|
||||||
|
b"",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let err = verify_live_nvidia(dir.path(), "550", NvidiaModuleFlavor::Proprietary)
|
let err = verify_live_nvidia(dir.path(), "550", NvidiaModuleFlavor::Proprietary)
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.to_string();
|
.to_string();
|
||||||
assert!(err.contains("vmlinuz"), "{err}");
|
assert!(err.contains("vmlinuz"), "{err}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_one_byte_module_placeholder_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
write_bytes(
|
||||||
|
&dir.path()
|
||||||
|
.join(format!("lib/modules/{KVER}/updates/dkms/nvidia.ko")),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("placeholder"), "{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_one_byte_userspace_placeholder_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
write_bytes(
|
||||||
|
&dir.path()
|
||||||
|
.join(format!("usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.{DRIVER}")),
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("placeholder"), "{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_userspace_version_mismatch_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
std::fs::rename(
|
||||||
|
dir.path()
|
||||||
|
.join(format!("usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.{DRIVER}")),
|
||||||
|
dir.path()
|
||||||
|
.join("usr/lib/x86_64-linux-gnu/libnvidia-glcore.so.999.0.0"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("does not match"), "{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_firmware_version_mismatch_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
std::fs::rename(
|
||||||
|
dir.path().join(format!("usr/lib/firmware/nvidia/{DRIVER}")),
|
||||||
|
dir.path().join("usr/lib/firmware/nvidia/999.0"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("does not match"), "{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_stale_modules_dep_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
std::fs::write(
|
||||||
|
dir.path().join(format!("lib/modules/{KVER}/modules.dep")),
|
||||||
|
b"kernel/other.ko:\n",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("modules.dep"), "{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_contradictory_flavor_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
let kernel = dir.path().join(format!("lib/modules/{KVER}"));
|
||||||
|
let dkms = kernel.join("updates/dkms");
|
||||||
|
// Make the payload unmistakably Debian's proprietary build, then claim
|
||||||
|
// it is the open one.
|
||||||
|
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
||||||
|
std::fs::remove_file(dkms.join(format!("{m}.ko"))).unwrap();
|
||||||
|
}
|
||||||
|
for m in [
|
||||||
|
"nvidia-current",
|
||||||
|
"nvidia-current-modeset",
|
||||||
|
"nvidia-current-uvm",
|
||||||
|
"nvidia-current-drm",
|
||||||
|
] {
|
||||||
|
touch(&dkms.join(format!("{m}.ko.xz")));
|
||||||
|
}
|
||||||
|
write_dep(&kernel);
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Open)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("proprietary build"), "{err}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_missing_final_modprobe_config_is_rejected() {
|
||||||
|
let dir = tempfile::tempdir().unwrap();
|
||||||
|
complete_rootfs(dir.path());
|
||||||
|
std::fs::remove_file(dir.path().join("etc/modprobe.d/phoebus-nvidia.conf")).unwrap();
|
||||||
|
let err = verify_live_nvidia(dir.path(), DRIVER, NvidiaModuleFlavor::Proprietary)
|
||||||
|
.unwrap_err()
|
||||||
|
.to_string();
|
||||||
|
assert!(err.contains("phoebus-nvidia.conf"), "{err}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -66,19 +66,21 @@ fn every_bash_cli_mode_has_a_rust_flag() {
|
||||||
fn verify_live_nvidia_accepts_a_complete_payload_and_rejects_an_incomplete_one() {
|
fn verify_live_nvidia_accepts_a_complete_payload_and_rejects_an_incomplete_one() {
|
||||||
fn touch(path: &std::path::Path) {
|
fn touch(path: &std::path::Path) {
|
||||||
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
|
||||||
std::fs::write(path, b"x").unwrap();
|
std::fs::write(path, vec![0u8; 8192]).unwrap();
|
||||||
}
|
}
|
||||||
fn complete(root: &std::path::Path) {
|
fn complete(root: &std::path::Path) {
|
||||||
let kver = "6.16.7-amd64";
|
let kver = "6.16.7-amd64";
|
||||||
touch(&root.join(format!("boot/vmlinuz-{kver}")));
|
touch(&root.join(format!("boot/vmlinuz-{kver}")));
|
||||||
let modules = root.join(format!("lib/modules/{kver}"));
|
let modules = root.join(format!("lib/modules/{kver}"));
|
||||||
std::fs::create_dir_all(&modules).unwrap();
|
std::fs::create_dir_all(&modules).unwrap();
|
||||||
std::fs::write(modules.join("modules.dep"), b"").unwrap();
|
let mut dep = Vec::new();
|
||||||
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
for m in ["nvidia", "nvidia_modeset", "nvidia_uvm", "nvidia_drm"] {
|
||||||
touch(&modules.join(format!("updates/dkms/{m}.ko")));
|
touch(&modules.join(format!("updates/dkms/{m}.ko")));
|
||||||
|
dep.push(format!("updates/dkms/{m}.ko:"));
|
||||||
}
|
}
|
||||||
|
std::fs::write(modules.join("modules.dep"), dep.join("\n")).unwrap();
|
||||||
for lib in [
|
for lib in [
|
||||||
"libnvidia-glcore.so.550",
|
"libnvidia-glcore.so.550.163.01",
|
||||||
"libGLX_nvidia.so.0",
|
"libGLX_nvidia.so.0",
|
||||||
"libnvidia-egl-gbm.so.1",
|
"libnvidia-egl-gbm.so.1",
|
||||||
"libnvidia-egl-wayland.so.1",
|
"libnvidia-egl-wayland.so.1",
|
||||||
|
|
@ -90,9 +92,9 @@ fn verify_live_nvidia_accepts_a_complete_payload_and_rejects_an_incomplete_one()
|
||||||
touch(&root.join("usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json"));
|
touch(&root.join("usr/share/egl/egl_external_platform.d/10_nvidia_wayland.json"));
|
||||||
touch(&root.join("usr/lib/firmware/nvidia/550.163.01/gsp.bin"));
|
touch(&root.join("usr/lib/firmware/nvidia/550.163.01/gsp.bin"));
|
||||||
touch(&root.join("usr/local/bin/phoebus-nvidia-load"));
|
touch(&root.join("usr/local/bin/phoebus-nvidia-load"));
|
||||||
let blacklist = root.join("etc/modprobe.d/nvidia-blacklists-nouveau.conf");
|
let conf = root.join("etc/modprobe.d/phoebus-nvidia.conf");
|
||||||
std::fs::create_dir_all(blacklist.parent().unwrap()).unwrap();
|
std::fs::create_dir_all(conf.parent().unwrap()).unwrap();
|
||||||
std::fs::write(&blacklist, b"blacklist nouveau\n").unwrap();
|
std::fs::write(&conf, b"blacklist nouveau\noptions nvidia_drm modeset=1\n").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let run = |root: &std::path::Path| {
|
let run = |root: &std::path::Path| {
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,21 @@ fn live_build_bundles_and_verifies_the_nvidia_payload() {
|
||||||
assert!(build.contains("trixie"));
|
assert!(build.contains("trixie"));
|
||||||
assert!(build.contains("linux-kbuild-"));
|
assert!(build.contains("linux-kbuild-"));
|
||||||
assert!(build.contains("--setup-hook"));
|
assert!(build.contains("--setup-hook"));
|
||||||
// Nouveau blacklisting/module options come from nvidia-kernel-common; the
|
// The live driver policy file the verifier requires is actually produced,
|
||||||
// unconditional modules-load entry is removed in favour of the gated unit.
|
// and Debian's unconditional nouveau configuration is replaced so the
|
||||||
|
// explicit nouveau fallback can bind an unsupported GPU.
|
||||||
|
assert!(build.contains("etc/modprobe.d/phoebus-nvidia.conf"));
|
||||||
|
assert!(build.contains("nvidia-blacklists-nouveau.conf"));
|
||||||
|
assert!(build.contains("blacklist nouveau"));
|
||||||
|
// Nouveau blacklisting/module options no longer come solely from
|
||||||
|
// nvidia-kernel-common; its unconditional modules-load entry is removed in
|
||||||
|
// favour of the gated unit.
|
||||||
assert!(build.contains("nvidia-kernel-common"));
|
assert!(build.contains("nvidia-kernel-common"));
|
||||||
assert!(build.contains("modules-load.d/nvidia.conf"));
|
assert!(build.contains("modules-load.d/nvidia.conf"));
|
||||||
// A documented fail-safe entry disables NVIDIA for that boot.
|
// A documented fail-safe entry disables NVIDIA for that boot, and marks the
|
||||||
|
// command line so the load script and unit both stand down.
|
||||||
assert!(build.contains("nomodeset"));
|
assert!(build.contains("nomodeset"));
|
||||||
|
assert!(build.contains("phoebus.nvidia=off"));
|
||||||
assert!(build.contains("modprobe.blacklist=nvidia"));
|
assert!(build.contains("modprobe.blacklist=nvidia"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue