uvm: use SYSTEM_NON_COHERENT_MEMORY aperture for peer BAR1 PTEs (#522) (#588)

Co-authored-by: Eric Hartford <eric@quixi.ai>
This commit is contained in:
Eric Hartford
2026-12-05 02:30:43 -08:00
committed by GitHub
parent f3838d692d
commit 41e5c26994
3 changed files with 48 additions and 9 deletions

View File

@ -530,7 +530,14 @@ fn map_peer_bar1(
&& (bus + cur) & (PAGE_2M - 1) == 0
&& length - cur >= PAGE_2M
{
let pte = mmu_v2::make_pte_4k_kind(bus + cur, false, p, false, mmu_v2::PTE_KIND_PITCH);
// Peer BAR1 is PCIe MMIO: use SYSTEM_NON_COHERENT_MEMORY (aperture=3) so SM reads
// do not issue coherent snoops that stall/return 0xFFFFFFFF (#522).
let pte = mmu_v2::make_pte_sys_non_coherent_4k_kind(
bus + cur,
p,
false,
mmu_v2::PTE_KIND_PITCH,
);
match tree.write_pte_2m(base + cur, pte) {
HugeMapResult::Mapped => {
cur += PAGE_2M;
@ -546,14 +553,9 @@ fn map_peer_bar1(
HugeMapResult::HasSubtable => {}
}
}
if !tree.map_page_4k_kind(
base + cur,
bus + cur,
false,
p,
false,
mmu_v2::PTE_KIND_PITCH,
) {
let pte =
mmu_v2::make_pte_sys_non_coherent_4k_kind(bus + cur, p, false, mmu_v2::PTE_KIND_PITCH);
if !tree.write_pte_4k(base + cur, pte) {
if cur > 0 {
tree.unmap_range(base, cur);
unsafe { rmapi_node::flush_gpu_tlb(tree.gpu_id, tree.root_phys) };

View File

@ -24,6 +24,7 @@ pub const PTE_VALID_TRUE: u64 = 1 << 0;
pub const PTE_APERTURE_VIDEO_MEMORY: u64 = 0 << 1;
pub const PTE_APERTURE_PEER_MEMORY: u64 = 1 << 1;
pub const PTE_APERTURE_SYSTEM_COHERENT_MEMORY: u64 = 2 << 1;
pub const PTE_APERTURE_SYSTEM_NON_COHERENT_MEMORY: u64 = 3 << 1;
pub const PTE_VOL_TRUE: u64 = 1 << 3;
pub const PTE_PRIVILEGE_TRUE: u64 = 1 << 5;
pub const PTE_READ_ONLY_TRUE: u64 = 1 << 6;
@ -152,6 +153,36 @@ pub const fn make_pte_4k(phys: u64, is_video: bool, prot: Protection, cached: bo
make_pte_4k_kind(phys, is_video, prot, cached, PTE_KIND_PITCH)
}
/// Exact `make_pte_pascal` (`dev_mmu.h:609`) for `NV_MMU_VER2_PTE_APERTURE_SYSTEM_NON_COHERENT_MEMORY`
/// (`aperture = 3`), used when mapping peer PCIe BAR1 MMIO windows where coherent snooping never
/// receives a completion on Ampere/Ada/Blackwell (#522).
#[inline]
pub const fn make_pte_sys_non_coherent_4k_kind(
phys: u64,
prot: Protection,
cached: bool,
kind: u64,
) -> u64 {
let vol = if cached { 0 } else { PTE_VOL_TRUE };
let ro = match prot {
Protection::ReadOnly => PTE_READ_ONLY_TRUE,
Protection::ReadWrite | Protection::ReadWriteAtomic => 0,
};
let atomic_disable = match prot {
Protection::ReadWriteAtomic => 0,
Protection::ReadOnly | Protection::ReadWrite => PTE_ATOMIC_DISABLE_TRUE,
};
// NV_MMU_VER2_PTE_ADDRESS_SYS 53:8 (46 bits, dev_mmu.h:628)
let addr_bits = ((phys >> 12) & 0x0000_3fff_ffff_ffff) << 8;
PTE_VALID_TRUE
| PTE_APERTURE_SYSTEM_NON_COHERENT_MEMORY
| vol
| ro
| atomic_disable
| addr_bits
| ((kind & 0xff) << 56)
}
/// Exact `make_pte_pascal` (`uvm_pascal_mmu.c:244-311`, `gv100/dev_mmu.h:604-642`) for
/// `NV_MMU_VER2_PTE_APERTURE_PEER_MEMORY` (`aperture = 1`) with 3-bit `peer_id` in bits `35:33`
/// (`NV_MMU_VER2_PTE_ADDRESS_VID_PEER`) and remote VRAM address in bits `32:8`.

View File

@ -514,6 +514,12 @@ mod tests {
from_v2_pte(mmu_v2::make_pte_4k_kind(pa, false, prot, cached, GENERIC)),
make_pte(Aperture::SystemCoherent, pa, prot, cached, true)
);
assert_eq!(
from_v2_pte(mmu_v2::make_pte_sys_non_coherent_4k_kind(
pa, prot, cached, GENERIC
)),
make_pte(Aperture::SystemNonCoherent, pa, prot, cached, true)
);
let pa = 0x8000_1000;
assert_eq!(
from_v2_pte(mmu_v2::make_pte_peer_4k_kind(pa, 5, prot, cached, GENERIC)),