fifo/load: take the runlist buffer aperture from its descriptor (GV11B sysmem) (#592)

* fifo/load: take the runlist buffer aperture from its descriptor (GV11B sysmem)

`load::submit` (OBJFIFO+3b0 _nv028192rm -> _nv028190rm -> +3b8 _nv028203rm)
built its context descriptor with a hardcoded framebuffer address space
(+70 = 2, +7c = 0), so a runlist buffer allocated in system memory -- the
only kind a zero-FB GPU such as GV11B (0x150:0xb, 40-bit sysmem) has --
would have been programmed into 0x2270 with the VID aperture (0) instead
of SYS coherent (2) / non-coherent (3).

`load::Buffers` now carries the descriptors' address space and coherency,
and `stop_runlist` passes them through to `context::Command::new`, whose
address-space -> aperture mapping and 40-bit bound are the existing
[A]/[E]-verified _nv028190rm leaf. `Buffers::at_init` keeps the traced
GV100 framebuffer descriptors, so the GV100 oracle/transcript paths and
`kernel/fifo_bringup.rs` are unchanged; `Buffers::at_init_in` takes the
caller's actual allocation's values.

Evidence: host unit tests only ([E]-style model). No REA session, QEMU
guest or silicon run was performed for GV11B; which address space the
original allocates runlist buffers in on a zero-FB GPU is not derived here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fifo/load: validate descriptor before acquiring LPWR reference

* test(fifo): enable LPWR engine mask bit in descriptor rejection ordering test

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
BlivionIaG
2026-12-05 16:21:22 +01:00
committed by GitHub
parent cae0b0d91b
commit f6274a00f6
2 changed files with 152 additions and 18 deletions

View File

@ -178,7 +178,8 @@ pub const fn config(
/// The request each of a runlist owner's buffers makes at InitLocked
/// (_nv040400rm with the size of _nv040339rm): the channel count of the
/// channel-id manager twice (channels and groups) times the entry size.
/// Contiguous framebuffer memory with tag `RUNLIST_BUFFER_TAG`.
/// Contiguous memory with tag `RUNLIST_BUFFER_TAG`: framebuffer on GV100;
/// a zero-FB GPU (GV11B) has no framebuffer, so the descriptor is SYSMEM.
pub const fn runlist_buffer_bytes(channels: u32) -> u64 {
(channels as u64 * 2) * RUNLIST_ENTRY_BYTES
}
@ -186,8 +187,14 @@ pub const fn runlist_buffer_bytes(channels: u32) -> u64 {
/// The buffer record of one runlist owner (the object _nv015974rm creates).
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Buffers {
/// Framebuffer addresses of the descriptors at +80 and +88.
/// Addresses of the descriptors at +80 and +88.
pub address: [u64; BUFFERS_PER_RUNLIST],
/// Address space (descriptor +70) of both descriptors, as _nv028190rm
/// reads it: 2 framebuffer, 1 system memory.
pub address_space_70: u32,
/// Coherency (descriptor +7c) of both descriptors; for system memory, 0
/// selects the coherent and non-zero the non-coherent aperture.
pub coherency_7c: u32,
/// +490: the buffer in use.
pub current: u32,
/// +4f8: entries in the buffer in use.
@ -200,10 +207,22 @@ pub struct Buffers {
pub byte_50c: bool,
}
impl Buffers {
/// The record as InitLocked leaves it (reports/gpu-fifo-load-original.json).
/// The record as InitLocked leaves it (reports/gpu-fifo-load-original.json)
/// for framebuffer descriptors, as on the traced GV100.
pub const fn at_init(address: [u64; BUFFERS_PER_RUNLIST]) -> Self {
Self::at_init_in(address, 2, 0)
}
/// The same record for descriptors in the given address space (+70) and
/// coherency (+7c): the values of the caller's actual allocation.
pub const fn at_init_in(
address: [u64; BUFFERS_PER_RUNLIST],
address_space_70: u32,
coherency_7c: u32,
) -> Self {
Self {
address,
address_space_70,
coherency_7c,
current: 0,
entries: 0,
word_504: 0,
@ -322,15 +341,17 @@ fn set_scheduling<S: Services>(
Ok(NvStatus::OK)
}
/// OBJFIFO+3b0 _nv028192rm with _nv028190rm and +3b8 _nv028203rm for a
/// framebuffer descriptor. The original ignores the result of _nv028190rm.
/// OBJFIFO+3b0 _nv028192rm with _nv028190rm and +3b8 _nv028203rm. The
/// aperture comes from the buffer descriptor's own address space and
/// coherency (`context::Command::new`), so a SYSMEM runlist buffer is not
/// programmed as framebuffer. The original ignores the result of _nv028190rm.
fn submit<S: Services>(
services: &mut S,
inputs: &Inputs<'_>,
reference: &mut lpwr::Reference,
runlists: u32,
runlist: u32,
address: u64,
descriptor: &context::Descriptor,
entries: u32,
) -> Result<NvStatus, NvStatus> {
restricted(services, &inputs.gpu, runlist)?;
@ -338,13 +359,8 @@ fn submit<S: Services>(
services.log(LOG_SUBMIT, 0x6b_4100)?;
return Ok(TIMEOUT);
}
let mut command = context::Command::new(descriptor, runlist as u8, runlists, entries)?;
let held = reference.acquire(services)?;
let descriptor = context::Descriptor {
address,
address_space_70: 2,
coherency_7c: 0,
};
let mut command = context::Command::new(&descriptor, runlist as u8, runlists, entries)?;
services.write_combine_flush()?;
let policy = inputs.gpu.policy();
// _nv028203rm asks again; the answer above was that it is not restricted.
@ -407,10 +423,14 @@ fn stop_runlist<S: Services>(
if buffers.byte_50c && buffers.word_504 != 0 {
return Err(NvStatus::NOT_SUPPORTED);
}
let address = *buffers
.address
.get(buffers.current as usize)
.ok_or(INVALID_STATE)?;
let descriptor = context::Descriptor {
address: *buffers
.address
.get(buffers.current as usize)
.ok_or(INVALID_STATE)?,
address_space_70: buffers.address_space_70,
coherency_7c: buffers.coherency_7c,
};
// _nv015976rm: length 0.
let first = submit(
services,
@ -418,7 +438,7 @@ fn stop_runlist<S: Services>(
&mut state.lpwr,
runlists,
runlist,
address,
&descriptor,
0,
)?;
if first != NvStatus::OK {
@ -432,7 +452,7 @@ fn stop_runlist<S: Services>(
&mut state.lpwr,
runlists,
runlist,
address,
&descriptor,
buffers.entries,
)?;
if second != NvStatus::OK {

View File

@ -521,6 +521,120 @@ fn preempt_wait_is_not_bounded_by_a_poll_count() {
);
}
/// A zero-FB GPU (GV11B, 40-bit sysmem) whose runlist buffers are SYSMEM
/// descriptors: stopping a runlist submits each buffer with the SYS aperture
/// of `context::Command::new` (2 coherent, 3 non-coherent), never VID (0).
#[test]
fn stop_runlist_submits_a_sysmem_buffer_with_its_own_aperture() {
for (coherency, aperture) in [(0, 2u32), (1, 3u32)] {
let mut model = Model::new();
let address = 0xab_cdef_0000u64; // below 1 << 40, page aligned
let mut buffers = Buffers::at_init_in([address, address + 0x1000], 1, coherency);
buffers.entries = 3;
let mut owners = vec![Some(Owner {
buffers: Some(buffers),
scheduler_50: true,
})];
let inputs = Inputs {
records: &[],
pbdma_count: 0,
objmc: false,
gpu: GpuFlags::default(),
mc: NO_MC,
clock: clock_gating::Inputs {
gpu_22c8: None,
gpu_6d41: false,
},
overrides: &[],
config: config(None, None, 0, 0).0,
flags: 0,
};
let mut state = State {
mc: MC_STATE,
gpu_99f: false,
fifo_7f0: 0,
debug_80d: 0,
owners: &mut owners,
lpwr: lpwr::Reference::default(),
};
assert_eq!(
stop_runlist(&mut model, &inputs, &mut state, 1, 0),
Ok(NvStatus::OK)
);
let pointer = format!(
"w:{:x}:{:x}",
context::INSTANCE,
(address >> 12) as u32 | aperture << 28
);
let writes: Vec<&String> = model
.events
.iter()
.filter(|event| event.starts_with("w:2270:") || event.starts_with("w:2274:"))
.collect();
assert_eq!(
writes,
[
&pointer,
&format!("w:{:x}:0", context::COMMAND),
&pointer,
&format!("w:{:x}:3", context::COMMAND),
]
);
assert!(!owners[0].unwrap().scheduler_50);
}
}
/// The traced GV100 record keeps its framebuffer descriptors.
#[test]
fn at_init_is_a_framebuffer_descriptor() {
let buffers = Buffers::at_init([0x1000, 0x2000]);
assert_eq!((buffers.address_space_70, buffers.coherency_7c), (2, 0));
assert_eq!(buffers, Buffers::at_init_in([0x1000, 0x2000], 2, 0));
}
#[test]
fn submit_rejects_unsupported_descriptor_before_acquiring_lpwr() {
let mut model = Model::new();
model.policy = Some((4, 0, true));
let mut buffers = Buffers::at_init_in([0x1000, 0x2000], 0, 0);
buffers.entries = 1;
let mut owners = vec![Some(Owner {
buffers: Some(buffers),
scheduler_50: true,
})];
let inputs = Inputs {
records: &[],
pbdma_count: 0,
objmc: false,
gpu: GpuFlags::default(),
mc: NO_MC,
clock: clock_gating::Inputs {
gpu_22c8: None,
gpu_6d41: false,
},
overrides: &[],
config: config(None, None, 0, 0).0,
flags: 0,
};
let mut state = State {
mc: MC_STATE,
gpu_99f: false,
fifo_7f0: 0,
debug_80d: 0,
owners: &mut owners,
lpwr: lpwr::Reference::default(),
};
assert_eq!(
stop_runlist(&mut model, &inputs, &mut state, 1, 0),
Err(NvStatus::NOT_SUPPORTED)
);
assert!(
!model.events.iter().any(|event| event.starts_with("ma:")),
"LPWR mutex must not be acquired on rejected descriptor: {:?}",
model.events
);
}
#[test]
#[ignore = "requires the hash-pinned original FIFO load oracle"]
fn compare_original_fifo_load() {