Enable display-aware BAR1 P2P using runtime coverage - #35
Open
ducphuc wants to merge 15 commits into
Open
Conversation
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.
There was a problem hiding this comment.
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.
2 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Depends on #33. The commits through
cc19db21are the prerequisite safety fixes from that PR; please review the follow-up commits after that point. This branch will be rebased onto610.43.03-p2pafter #33 merges.Summary
Enable display-aware static BAR1 placement using runtime aperture geometry rather than globally forcing static BAR1 or maintaining a device exception:
min(clientFbSizeAligned, maxStaticMapSize), so both full and partial runtime geometries use the same policy;NV_ERR_NOT_SUPPORTED;Existing generated HAL routing,
PDB_PROP_KBUS_SUPPORT_BAR1_P2P_BY_DEFAULT, the globalpcieP2PTypepolicy, 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
AUTOto forcedENABLE. This PR retainsAUTOand 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:
git diff --checkpassed;make -C tests clean check, covering disabled policy, zero-sized geometry, partial coverage, exact coverage, and a static window larger than client FB;cudaMemcpyPeer, and beginning/middle/end probes;simpleP2Ppassed before and after the generalized boundary run at 13.05 and 13.03 GB/s;p2pBandwidthLatencyTestmeasured about 14.09 GB/s per direction and 27.79 GB/s bidirectional;P2P atomics report
NS, not registry-disabledDR, 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.