Skip to content

Enable display-aware BAR1 P2P using runtime coverage - #35

Open
ducphuc wants to merge 15 commits into
aikitoria:610.43.03-p2pfrom
ducphuc:production/runtime-bar1-coverage
Open

Enable display-aware BAR1 P2P using runtime coverage#35
ducphuc wants to merge 15 commits into
aikitoria:610.43.03-p2pfrom
ducphuc:production/runtime-bar1-coverage

Conversation

@ducphuc

@ducphuc ducphuc commented Aug 5, 2026

Copy link
Copy Markdown

Important

Depends on #33. The commits through cc19db21 are the prerequisite safety fixes from that PR; please review the follow-up commits after that point. This branch will be rebased onto 610.43.03-p2p after #33 merges.

Summary

Enable display-aware static BAR1 placement using runtime aperture geometry rather than globally forcing static BAR1 or maintaining a device exception:

  • every property-enabled GPU is eligible when its aligned client framebuffer size and usable static BAR1 window are both nonzero;
  • the static map covers min(clientFbSizeAligned, maxStaticMapSize), so both full and partial runtime geometries use the same policy;
  • only allocations wholly inside the selected static window are supported; spanning and outside allocations fail closed with NV_ERR_NOT_SUPPORTED;
  • external BAR1 P2P addresses are validated against the DMA window;
  • PCIe mailbox setup is transactional and rejects an uninitialized mailbox address instead of leaving partial peer state;
  • UVM reports actual system-memory coherence while preventing non-coherent Blackwell static BAR1 from being registered as PCI P2PDMA memory.

Existing generated HAL routing, PDB_PROP_KBUS_SUPPORT_BAR1_P2P_BY_DEFAULT, the global pcieP2PType policy, registry precedence, explicit static-BAR1 overrides, BAR-disabled checks, and forced static-BAR behavior remain unchanged. No chip, architecture, marketing-family, or device-ID allowlist is added.

Motivation and relationship to other PRs

This supersedes closed PR #31 with corrected boundary semantics, broader runtime-geometry policy, and complete validation.

PR #34 reproduces the same display-attached failure class on GB202, but changes the global default from AUTO to forced ENABLE. This PR retains AUTO and uses measured runtime geometry to select display-aware placement. It also addresses the invalid-mailbox failure path and external-address bounds that a global policy change does not cover.

Runtime-scoped partial coverage

Partial coverage is a runtime geometry condition, not a GB206 capability. When the usable static window is smaller than aligned client framebuffer memory, allocations wholly inside that window can be represented safely; spanning or outside allocations cannot and are rejected by the shared static-aperture and DMA-window bounds checks.

GB206 is the hardware-validated partial-coverage example, not an eligibility exception. Its matrix covers both GPU directions and peer-enable orderings, inside, spanning, and fully outside placements, 100 rejection-and-recovery cycles, cleanup, driver reload, suspend/resume, and reboot. The generalized predicate was subsequently regressed on the same hardware with unchanged inside success and fail-closed boundary behavior.

Other property-enabled devices with partial runtime coverage use the same contract. Hardware validation on those implementations remains follow-up work and should repeat the boundary, recovery, cross-GPU, and lifecycle matrix; it is not a merge gate for this runtime-only generalization.

Related upstream issues

Validation

Validated on two RTX 5060 Ti 16 GB GPUs with natural BAR1 geometry and enrolled-MOK-signed modules:

  • complete five-module build and git diff --check passed;
  • the policy regression passed with make -C tests clean check, covering disabled policy, zero-sized geometry, partial coverage, exact coverage, and a static window larger than client FB;
  • source inspection found no remaining GB206 eligibility check and confirmed generated HAL and registry sources were unchanged;
  • inside mappings passed in both GPU directions and both peer-enable orderings, including peer kernels, cudaMemcpyPeer, and beginning/middle/end probes;
  • the original full-coverage run completed 1,969 peer tests before normal allocation exhaustion;
  • the original partial-coverage run completed 491 mappings before a classified 64 MiB spanning allocation was rejected;
  • a prepared fully outside mapping was rejected with local data intact and immediate three-iteration inside recovery;
  • 100 independent spanning/outside rejection-and-recovery cycles completed with zero data errors and zero retained GPU memory at each checkpoint;
  • after the policy generalization, a bounded regression produced 492 inside passes, rejected the established 64 MiB spanning and prepared 4 MiB outside candidates, and passed immediate recovery with no data errors;
  • simpleP2P passed before and after the generalized boundary run at 13.05 and 13.03 GB/s;
  • p2pBandwidthLatencyTest measured about 14.09 GB/s per direction and 27.79 GB/s bidirectional;
  • driver unload/reload, modeset/DRM loading, supported deep suspend/resume, updated-initramfs reboot, and post-resume/post-boot P2P passed in the original lifecycle run;
  • no Xids, assertions, IOMMU/MMU faults, AER errors, oopses, panics, or hung tasks appeared after loading the generalized modules. Expected fail-closed boundary diagnostics were present.

P2P atomics report NS, not registry-disabled DR, confirming that the branch default no longer disables atomics.

The complete durable evidence is in the GB206 BAR1 boundary validation record. That record is evidence for GB206 behavior under the generalized contract; it does not claim other partial-window implementations were hardware-tested.

Separately, the shared full-coverage AUTO-selection logic was independently validated on three RTX 5090 GPUs in PR #36.

Residual hardware scope

The runtime policy is additive and source-audited across existing HAL coverage. Runtime partial-window testing was performed on GB206. Other property-enabled implementations are supported by the same runtime predicate and fail-closed bounds, but their partial-window and mixed-implementation hardware matrices remain explicit follow-up validation work.

ducphuc added 13 commits August 4, 2026 11:27
BAR1 mappings already select SYS_COH or SYS_NONCOH before PTE construction, so the PEER-aperture rewrites and bar1BusAddr base assignment were unreachable. Keep the live BAR1 DMA address encoder unchanged.
Keep BAR1 reads and writes enabled, but encode the atomics field as DEFAULT instead of implicitly disabling it with 0x11. Preserve the branch-wide BAR1 protocol policy, including qualifying PCIe-only datacenter GPUs, and retain registry-key precedence.
Use the reduced page-array path only for non-empty, overflow-safe ranges that are hugepage aligned, exactly sized in hugepages, and contained in one hugetlb VMA. Fall back to the existing base-page path for every other layout.
Report leftover mappings and mappings that outlive their I/O VA space without triggering a debug breakpoint. Use the portable NvU64 format for mappingCount and retain null-safe teardown.
Dynamic-granularity page arrays already use the OS page size, so pass PageCount directly when unregistering them. The RM-to-OS conversion is only correct for ordinary RM-granularity arrays on 64K-page systems.
Match the inactive nv-reg.h mirror to the kernel-open definition. Only os-registry.c instantiates the active table, so this is source hygiene and does not change runtime behavior.
Keep IOMMU passthrough required while translated-IOMMU scatterlist merging remains unsafe, document the hugetlb eligibility fallback, and replace the broad ACS override recommendation with scoped upstream controls and an isolation warning.
Mailbox P2P setup used to assert-and-continue, so a failure while
programming the HSHUB peer masks or setting up the mailboxes left
half-programmed peer state behind. Convert the setup path to return
status and unwind on failure: tear down partially set up mailboxes,
invalidate peer masks programmed for a fresh mapping, and restore the
peer bookkeeping. When taking an additional reference on an existing
mapping, a failure only drops the newly taken references and leaves the
mapping intact.
Allow default-enabled GPUs to place static BAR1 above fixed console and mailbox mappings when the remaining aperture covers all aligned client framebuffer memory. Preserve the tested GB206 partial-window exception without generalizing partial coverage to other implementations.

Validate external BAR1 mapping addresses against the DMA window so spanning and outside allocations fail safely. Document the current CUDA API rejection behavior and add a source-level policy truth-table test.
Report coherence from the actual system-memory window again, but keep non-coherent Blackwell devices out of the static-BAR1 PCI P2PDMA registration path. Static BAR1 is also the GPU peer aperture there, and P2PDMA registration replaces its pagemap operations.

This intentionally leaves device P2PDMA unavailable on non-coherent Blackwell datacenter GPUs. It matches this branch’s effective behavior and does not remove GPU-to-GPU P2P support.
@ducphuc
ducphuc marked this pull request as ready for review August 5, 2026 16:21
Copilot AI lite review requested due to automatic review settings August 5, 2026 16:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enable display-aware static BAR1 placement for BAR1-based PCIe P2P using runtime aperture coverage (full coverage required except for the existing GB206 partial-window exception), while tightening BAR1 P2P address validation and hardening PCIe mailbox P2P setup/rollback behavior. This extends the BAR1 P2P enablement logic without changing generated HAL routing or the global BAR1 protocol selection policy.

Changes:

  • Add a runtime-coverage BAR1 policy predicate and use it to drive display-aware static BAR1 placement/clipping, including predictable rejection of spanning/outside mappings.
  • Validate BAR1 P2P encoded addresses against the DMA window and refactor external PTE/phys-addr construction to match the selected aperture semantics.
  • Make PCIe mailbox mapping setup transactional with cleanup/rollback, and add a small source-level regression test harness for the policy truth table.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
validation/gb206-bar1-boundary-2026-08-04.md Adds durable GB206 boundary validation record for the new runtime-coverage behavior.
tests/README.md Documents how to run the BAR1 policy regression test.
tests/Makefile Adds a minimal build/run harness for the BAR1 policy test.
tests/bar1_p2p_policy_test.c Introduces a truth-table regression test for the display-aware BAR1 policy predicate.
tests/.gitignore Ignores the policy test binary.
src/nvidia/src/kernel/rmapi/nv_gpu_ops.c Adds DMA-window bounds checks for BAR1 P2P address encoding and simplifies aperture handling for external mappings.
src/nvidia/src/kernel/mem_mgr/io_vaspace.c Adds warning diagnostics for dangling IOVAS/mappings during teardown.
src/nvidia/src/kernel/gpu/bus/arch/turing/kern_bus_tu102.c Implements runtime-coverage display-aware static BAR1 placement logic and updates boundary behavior semantics.
src/nvidia/src/kernel/gpu/bus/arch/turing/bar1_p2p_policy.h Adds the shared BAR1 policy predicate macro.
src/nvidia/src/kernel/gpu/bus/arch/maxwell/kern_bus_gm200.c Makes PCIe mailbox P2P setup transactional, with failure-path teardown and peer-mask rollback helpers.
src/nvidia/src/kernel/gpu/bif/kernel_bif.c Updates default P2P override encoding to avoid overriding atomic capability defaults.
src/nvidia/arch/nvalloc/unix/src/osmemdesc.c Adjusts OS page-count logic for hugepages and dynamic granularity descriptors.
src/nvidia/arch/nvalloc/unix/include/nv-reg.h Modifies the default value for the resizable BAR registry key.
README.md Updates user-facing documentation for runtime-coverage display-aware BAR1 and operational constraints.
kernel-open/nvidia/os-mlock.c Refactors and tightens eligibility checks for the hugetlb pinning fast path.
kernel-open/nvidia-uvm/uvm_gpu.h Removes unconditional coherence reporting for Blackwell+ and uses actual system-bus window reporting.
kernel-open/nvidia-uvm/uvm_devmem.c Skips PCI P2PDMA static BAR1 registration on non-coherent Blackwell to avoid conflicts with BAR1 peer access.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/nvidia/arch/nvalloc/unix/include/nv-reg.h
Comment thread src/nvidia/src/kernel/mem_mgr/io_vaspace.c
Comment thread src/nvidia/src/kernel/gpu/bus/arch/turing/bar1_p2p_policy.h
ducphuc and others added 2 commits August 5, 2026 22:15
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Allow every property-enabled GPU to use display-aware static BAR1 when runtime geometry leaves nonzero aligned client-FB and static-window ranges. Remove the GB206 implementation check while retaining the same inside-window behavior and fail-closed spanning/outside rejection.

Keep the GB206 record as the validated partial-coverage example without treating it as an eligibility allowlist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When having a 5090 connected to a monitor/screen, P2P fails between 5090s.

2 participants