Skip to content

[None][fix] Unmap a unicast virtual-memory chunk whose access grant fails - #22386

Closed
arusli-nv wants to merge 1 commit into
NVIDIA:mainfrom
arusli-nv:ft/F5-vmm-unicast-unmap
Closed

arusli-nv wants to merge 1 commit into
NVIDIA:mainfrom
arusli-nv:ft/F5-vmm-unicast-unmap

Conversation

@arusli-nv

@arusli-nv arusli-nv commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • UnicastConfigurator::setup in cpp/include/tensorrt_llm/runtime/virtualMemory.h now handles a cuMemSetAccess failure. It unmaps the range, then rethrows the original exception. This fixes a leak where a failed setup left the range mapped.
  • If the unmap also fails, the code logs a warning. The original cuMemSetAccess error is still the one propagated. Confirm that the warning does not replace the exception.
  • Successful access grants are unchanged, per the PR description and the change summary.
  • Risk: if cuMemSetAccess fails for a partially granted range, the unmap must still be valid. Check this path. The source was not inspected in this review.
  • No public declarations changed.

QA Engineer Review

Test files changed:

  • cpp/tests/unit_tests/runtime/virtualMemoryTest.cpp (modified, +29 lines): adds VirtualMemoryTest.TestUnicastAccessFailureUnmaps.

Test function added:

  • TestUnicastAccessFailureUnmaps. It reserves a 256 MiB virtual address range and creates an allocation handle. It requests access for device index tc::getDeviceCount(), which does not exist, and expects setup to throw. It then calls setup for device 0 on the same range, which must succeed. Finally, it tears down the mapping, releases the handle, and frees the reservation.

Coverage:

  • Covers the failed-access-grant path and the regression where the range stayed mapped.
  • Does not cover the path where the unmap also fails and only logs a warning.
  • Test-list membership was not verified. The test is a gtest unit test. Confirm that the unit test binary runs it in CI.
  • Reported results: the PR author states the test fails without the fix and that all 22 tests pass with it. CI results were not verified in this review.

Coverage verdict: needs follow-up (the unmap-failure warning path is untested).

Per-File QA Perspective

  • cpp/include/tensorrt_llm/runtime/virtualMemory.h (source): After a failed access grant, the range is now unmapped before the error propagates. QA should confirm that a later materialization at the same address succeeds after such a failure.
  • cpp/tests/unit_tests/runtime/virtualMemoryTest.cpp (test): Covers the failed-access regression. Test-list membership not verified.

Description

Bug. UnicastConfigurator::setup (virtualMemory.h) maps the allocation at a fixed virtual address and then
grants access with cuMemSetAccess. If the access grant fails, setup throws with the range still mapped.
CUDAVirtualMemoryChunk runs teardown() only for configurators whose setup() succeeded, so nothing unmaps the
range, and the next materialize of the chunk fails in cuMemMap. This breaks the "setup() shall not leak"
contract of Configurator.

Who hits it. Users of CUDA virtual memory chunks (for example virtual-memory sleep and wake-up), when an
access grant fails: the chunk can then no longer be mapped at its address.

Fix. UnicastConfigurator::setup unmaps the range before it rethrows the failed cuMemSetAccess. A failed
unmap is logged as a warning instead of thrown (TLLM_CU_CHECK_FREE_RESOURCE would throw and replace the
original error), so the cuMemSetAccess error is the one that propagates.

 setup: cuMemMap(addr) --> cuMemSetAccess --ok--> mapped (unchanged)
                                         --fails--> cuMemUnmap(addr); log a failed unmap; rethrow the original error

Risk. Very low. Nothing changes when the access grant succeeds.

Test Coverage

  • cpp/tests/unit_tests/runtime/virtualMemoryTest.cpp: VirtualMemoryTest.TestUnicastAccessFailureUnmaps (one
    GPU) grants access to a device that does not exist, expects the throw, then maps the same range with a valid
    descriptor and tears it down.

With and without the fix: virtualMemoryTest built from main plus the new test fails
TestUnicastAccessFailureUnmaps (the other 21 tests pass); with the fix all 22 pass.

virtualMemoryTest --gtest_filter=VirtualMemoryTest.TestUnicastAccessFailureUnmaps

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

…ails

UnicastConfigurator::setup left the range mapped when cuMemSetAccess failed, and teardown is not called for a
failed setup, so the next materialize at that address failed. Unmap the range before rethrowing.

Signed-off-by: Andrew Rusli <[email protected]>
@arusli-nv
arusli-nv requested a review from a team as a code owner November 16, 2026 18:58
@arusli-nv

Copy link
Copy Markdown
Collaborator Author

/bot run

@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

UnicastConfigurator::setup now attempts to unmap the range when cuMemSetAccess fails. A new test checks that setup for a valid device succeeds on the same range after the failed attempt.

Changes

Unicast access failure cleanup

Layer / File(s) Summary
Failure cleanup and regression test
cpp/include/tensorrt_llm/runtime/virtualMemory.h, cpp/tests/unit_tests/runtime/virtualMemoryTest.cpp
If cuMemSetAccess throws, setup attempts to unmap the range, logs an unmap failure, and rethrows the original exception. The test checks that a subsequent setup for device 0 succeeds on the same range and cleans up the mapping.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: zhaoyangwang-nvidia

Merge Risk: Minimal · up to 1eab3

This fixes a leaked virtual-memory mapping when granting device access fails during unicast setup. The fix is small and local, successful paths are unchanged, and a regression test covers the failure. Merge risk is minimal.

Security architecture risk: Minimal · up to 1eab3

Failed access setup now attempts to remove its own mapping while preserving the original error. Successful behavior and access permissions are unchanged. No introduced or worsened material design risk was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new cleanup targets only the address and size used by the same setup invocation after mapping succeeded. In the inspected allocation path, that address comes from cuMemAddressReserve and device access comes from the allocation request. No new caller, device-selection path, or broader unmap scope is introduced.

Trust Boundaries and Controls

  • observed — The CUDA access-grant call still uses the same descriptor, and its failure still escapes to the caller rather than being converted to success. The added behavior removes a mapping on failure; it does not retry with weaker permissions or bypass the access check.

Resilience and Maintainability Implications

  • inferred — Rollback is best effort: an unmap error is logged while the original access error propagates. A mapping may therefore remain unrecovered if cleanup fails, as was already possible before this change. The existing release path skips unsuccessful configurators and makes the chunk terminally errored if a later teardown or handle release throws; this PR does not add a separate recovery mechanism.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a unicast virtual-memory chunk is unmapped when its access grant fails. It follows the [None][fix] template and matches the raw summary, which describes unmapping the …
Description check Passed The description follows the repository template. It has a Description section that explains the bug, the fix, and the risk. It has a Test Coverage section that names the new test and gives the validat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a unicast virtual-memory chunk is unmapped when its access grant fails. It follows the [None][fix] template and matches the raw summary, which describes unmapping the range after a cuMemSetAccess failure in UnicastConfigurator::setup.

Full details: Description check

Explanation

The description follows the repository template. It has a Description section that explains the bug, the fix, and the risk. It has a Test Coverage section that names the new test and gives the validation command. The PR checklist is present and checked. The template's '@coderabbitai summary' header is present, and the description does not add an explicit NVBugs, JIRA, or GitHub ticket reference. The description is complete enough to pass.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b9a6b5b and 1eab328.

Files selected for processing: 2

  • cpp/include/tensorrt_llm/runtime/virtualMemory.h
  • cpp/tests/unit_tests/runtime/virtualMemoryTest.cpp

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 6 remain after this review.

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85237 [ run ] triggered by Bot. Commit: 1eab328 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #85237 [ run ] completed with state SUCCESS. Commit: 1eab328
/LLM/main/L0_MergeRequest_PR pipeline #70556 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@arusli-nv

Copy link
Copy Markdown
Collaborator Author

Superseded by #22507, which combines the runtime and serving fixes (#22381, #22382, #22384, #22386, #22392, #22393) for one review.

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.

2 participants