Skip to content

displayport: fix multiple dplib bugs found during exhaustive audit#2

Merged
coleleavitt merged 3 commits intomainfrom
fix/dplib-bug-fixes
Feb 23, 2026
Merged

displayport: fix multiple dplib bugs found during exhaustive audit#2
coleleavitt merged 3 commits intomainfrom
fix/dplib-bug-fixes

Conversation

@coleleavitt
Copy link
Owner

@coleleavitt coleleavitt commented Feb 23, 2026

Summary

Three verified bug fixes in the DisplayPort library (dplib), found during an exhaustive audit of the codebase. Each commit is independent and self-contained.

Commits

1. displayport: remove redundant interlane alignment check in isLinkLost()

isLinkLost() reads getInterlaneAlignDone() twice from the same cached DPCD register — once at the top of the function and again partway through. The second check always returns the same result as the first (same cache), making it dead code. Removes the redundant check and its unreachable early-return path.

File: dp_connectorimpl.cpp (isLinkLost)

2. displayport: clamp tunnel bandwidth request to prevent NvU8 truncation

In allocateDpTunnelBw(), the computed DPCD bandwidth value was directly cast to NvU8 without bounds checking. For high-bandwidth tunnel configurations (e.g., >64 Gbps with 0.25 Gbps granularity), the value can exceed 255, causing silent truncation and an incorrect bandwidth allocation request. Now computes in NvU64 first and clamps to NV_U8_MAX.

File: dp_connectorimpl.cpp (allocateDpTunnelBw)

3. displayport: detect RM link training fallback in MST optimized path

In the MST path of trainLinkOptimized(), when main->train() internally falls back to a lower link configuration (fewer lanes or lower rate), the function detects this via the lConfig != activeLinkConfig check in train() and returns false. The retry loop then attempts to restore highestAssessedLC up to DP_LT_MAX_FOR_MST_MAX_RETRIES times.

However, if retries exhaust without restoring the desired config, bLinkTrainingSuccessful remains true (from initialization) because the force-train path (which sets it to false) is only entered when activeLinkConfig is completely invalid (lanes=0). When RM falls back to a valid but lower config, the function returns success, and the caller proceeds to program DSC with PPS parameters computed for the higher highestAssessedLC bandwidth — a mismatch that can cause visual corruption or link instability on MST topologies.

File: dp_connectorimpl.cpp (trainLinkOptimized, MST path)

Testing

These are code-level fixes based on source analysis. Hardware testing on MST/DSC configurations would validate the behavioral improvements.

Context

Found during the same exhaustive dplib audit that produced PR NVIDIA#1025 (MST DSC unnecessary compression fix).


Summary by cubic

Fixes three DisplayPort bugs affecting bandwidth requests, link-loss checks, and MST link training. Improves stability and prevents DSC mismatches on MST.

  • Bug Fixes
    • Removed redundant interlane alignment check in isLinkLost(), eliminating dead code.
    • Clamped DPCD tunnel bandwidth value to NV_U8_MAX (computed in NvU64) to prevent NvU8 truncation on high-bandwidth links.
    • In MST trainLinkOptimized(), mark training as failed when RM falls back to a lower valid link config to avoid programming DSC with stale PPS.

Written for commit 27567d7. Summary will update on new commits.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed DisplayPort tunnel bandwidth allocation calculation to prevent overflow and ensure proper value handling
    • Improved link detection reliability by strengthening interlane alignment verification
    • Enhanced link training process with detection of configuration fallbacks to prevent stale parameters from being used

The interlane alignment status was checked twice in isLinkLost() -- once
before the per-lane status checks and once after. Both reads come from
the same SW cache (refreshed by hal->refreshLinkStatus() before the first
check), so the second check at the end of the function always returns the
same result as the first. Remove the duplicate to reduce unnecessary
code and eliminate any timing window for spurious false-positives on
systems where the HAL cache could be externally invalidated between
the two reads.

Signed-off-by: Cole Leavitt <cole.leavitt@proton.me>
In allocateDpTunnelBw(), the result of divide_ceil(bandwidth *
granularityMultiplier, 1e9) was directly cast to NvU8 without
bounds checking. For high-bandwidth links (e.g. >64 Gbps with
0.25 Gbps granularity), the computed DPCD value can exceed 255,
causing silent truncation and an incorrect bandwidth request.

Compute the result in NvU64 first and clamp to NV_U8_MAX before
the cast.
In trainLinkOptimized(), the MST path trains to highestAssessedLC and
retries up to DP_LT_MAX_FOR_MST_MAX_RETRIES times if the active config
does not match. However, when main->train() internally falls back to a
lower lane count or link rate (detected by train() comparing lConfig vs
activeLinkConfig), the retries may never restore the desired config.

After retries exhaust, the code proceeds with bLinkTrainingSuccessful
still set to true from initialization, even though activeLinkConfig is
lower than what was used to compute DSC PPS parameters during
compoundQuery. This can cause the caller to commit a mode with stale
DSC configuration computed for a higher bandwidth link.

Add a check after the retry loop: if activeLinkConfig is valid but
does not match highestAssessedLC, mark link training as failed. This
ensures the caller sees the mismatch and can handle it appropriately
(e.g. zombie mode) rather than silently programming incorrect DSC
parameters.
@coderabbitai
Copy link

coderabbitai bot commented Feb 23, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Modified three functions in the DisplayPort connector implementation to improve correctness: guarded bandwidth calculation against overflow, removed a code path that bypassed alignment checks, and added detection logic for link training fallbacks when RM forces lower configurations.

Changes

Cohort / File(s) Summary
DisplayPort Connector Logic Fixes
src/common/displayport/src/dp_connectorimpl.cpp
Three correctness improvements: bandwidth clamping to prevent overflow in allocateDpTunnelBw, removal of interlane alignment check bypass in isLinkLost, and new fallback detection logic in trainLinkOptimized to handle RM-induced link configuration downgrades during training.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Three fixes hopped into the code today,
Bandwidth now safely clamps the way,
Alignment checks won't skip about,
And fallbacks caught—no more doubt! ✨
Display Port tunnels flow just right!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'displayport: fix multiple dplib bugs found during exhaustive audit' clearly and accurately summarizes the main change—fixing multiple bugs in the DisplayPort library discovered through auditing.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/dplib-bug-fixes

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@coleleavitt coleleavitt merged commit 0988e04 into main Feb 23, 2026
2 checks passed
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.

1 participant