Files
nvdriver/tests/vm/small_vm.rs
LIghtJUNction 32c8728037 Migrate the workspace and kernel crates to Rust edition 2024
Mechanical, behavior-neutral: edition/resolver keys, unsafe extern blocks,
unsafe(no_mangle)/unsafe(export_name), unsafe blocks inside unsafe fn,
r#gen renames, --edition flags in Makefiles/tools, rustfmt style_edition
pinned to 2021 so formatting stays edition-independent, and clippy
collapsible_if allowed workspace-wide (let-chain churn).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-12-02 01:52:38 +08:00

105 lines
3.9 KiB
Rust

//! Actual Linux coherent DMA and production payload construction on EDU.
//! The synthetic GV100 probe identity admits CPU policy only. No GPU root,
//! runlist, GR context or doorbell is ever installed by this experiment.
use crate::{gpu::GpuLease, native_program, small_vm::*};
use core::{ffi::c_void, num::NonZeroU32};
use nv_rs_core::compute::gv100;
unsafe extern "C" {
fn fixture_small_vm_pte(address: u64, readonly: u32) -> u64;
}
pub unsafe fn run(lease: &GpuLease, pci: *mut c_void) -> i32 {
unsafe {
let mut checks = 0;
macro_rules! check {
($value:expr) => {
if !$value {
return -5;
}
checks += 1;
};
}
macro_rules! value {
($result:expr) => {
match $result {
Ok(value) => value,
Err(_) => return -5,
}
};
}
let cloned = value!(lease.try_clone());
let mut vm = match SmallVm::prepare(
cloned,
pci,
value!(Layout::from_base(0x100000)),
Program {
code: gv100::CODE,
constants: &[],
output_initial: &[],
qmd: &[],
},
) {
Ok(vm) => vm,
Err(mut failure) => {
if let Some(owner) = failure.owner.as_mut() {
let _ = owner.close();
}
return -5;
}
};
check!(vm.phase() == Ok(Phase::Writable));
check!(vm.matches_gpu(lease));
let payload = NonZeroU32::new(0x654321).unwrap();
let info = value!(native_program::populate(&mut vm, 0x12345678, payload, 0));
check!(info.pushbuffer_bytes == 48 && info.initial_gp_put == 1);
let mut code = [0; 256];
value!(vm.read_buffer(Role::Code, 0, &mut code));
check!(code
.iter()
.zip(gv100::CODE)
.all(|(actual, expected)| core::hint::black_box(*actual) == *expected));
let mut args = [0; 16];
value!(vm.read_buffer(Role::Constants, 0x160, &mut args));
check!(u64::from_le_bytes(args[..8].try_into().unwrap()) == 0x102000);
check!(
u32::from_le_bytes(args[8..12].try_into().unwrap()) == 0x12345678
&& u32::from_le_bytes(args[12..].try_into().unwrap()) == 64
);
let mut entry = [0; 8];
value!(vm.read_buffer(Role::Gpfifo, 0, &mut entry));
check!(u64::from_le_bytes(entry) == 0x3100_0010_5000);
for role in [
Role::Code,
Role::Constants,
Role::Output,
Role::Qmd,
Role::Completion,
Role::Pushbuffer,
Role::Gpfifo,
] {
let path = value!(vm.inspect_mapping(role));
let dma = value!(vm.buffer_dma_address(role));
let readonly = matches!(
role,
Role::Code | Role::Constants | Role::Pushbuffer | Role::Gpfifo
);
check!(path[4] == fixture_small_vm_pte(dma, u32::from(readonly)));
}
check!(value!(vm.instance_address()) & 4095 == 0);
check!(value!(vm.root_address()) & 4095 == 0);
check!(vm.freeze().is_ok());
check!(vm.close() == Err(Error::State));
check!(vm.completion_word(payload.get()) == Ok(0));
check!(vm.output_word_after_release(payload.get(), 0) == Err(Error::State));
check!(
native_program::populate(&mut vm, 1, payload, 0)
== Err(native_program::Error::Memory(Error::State))
);
// No address has been published to EDU or a NVIDIA device. This test's
// quiescence argument is absence of any hardware publication, not polling.
check!(vm.thaw_after_gpu_quiescence().is_ok());
check!(vm.close().is_ok());
check!(!lease.hardware_ready());
checks
}
}