Skip to content

test(rccl): check config parsers keep the caller's strtok state - #12648

Open
thomas-huber wants to merge 2 commits into
developfrom
users/thomas-huber/strtok-reentrancy-test
Open

thomas-huber wants to merge 2 commits into
developfrom
users/thomas-huber/strtok-reentrancy-test

Conversation

@thomas-huber

@thomas-huber thomas-huber commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

NCCL 2.32.3 fixed config parsers that used strtok(), whose single process-wide state let a parse on one thread corrupt another thread's tokenization in progress (NVIDIA/nccl#2361). RCCL picks up the fix with the 2.32.3 sync in #12321. This PR adds a regression test that fails without the fix and passes with it.

Technical Details

  • Three InitMicrotest cases in test/host/init-test.cc (rccl-UnitTestsMicroInit) run the NCCL_CTA_POLICY parser, ncclStrToCpuset() and ncclStrListToCpuset() on a second thread while the calling thread is between strtok() calls on "a,b", then check that the caller's next token is still "b". The file now also includes cpuset.h; the ncclOsCpu* helpers its parsers call come from fakes/os_fakes.cc.
  • Without the fix the parsers' own strtok() calls leave the shared save pointer at the end of their string, so the caller gets NULL. Their free() is deferred through the existing g_microFree seam, so this is a clean assertion failure, not a use-after-free.
  • Control: the existing GetEnvCtaPolicy_TwoNamedModes_AccumulatesBoth and GetEnvCtaPolicy_UnknownTokenAmongValid_IgnoresOnlyTheUnknown tests.
  • Registration: already covered by InitMicrotest.* in test_categories_micro_init.yaml, used by all three rccl-UnitTestsMicroInit variants, which the host unit-test workflow runs.
  • Test-only; no source changes. The fix reached develop with the NCCL 2.32.3 sync (sync(rccl): Sync with NCCL v2.32.3-1 #12321). Upstream fix: NVIDIA/nccl@35512d6f6b73.

Issue Tracking

JIRA ID: AICOMRCCL-2712

Test Plan

  • test/host/build/rccl-UnitTestsMicroInit --gtest_filter='InitMicrotest.*_ConcurrentParse_KeepsCallerStrtokState' (built with test/host/run_host_tests.sh build) on develop (42e7f5d9cb8b), and on the same tree with the fix reverted (the parsers' strtok_r() calls in cpuset.h and init.cc back to strtok()), three runs each, in the rocm/dev-ubuntu-22.04:7.2 image the host unit-test workflow uses.
  • The full run_host_tests.sh build and run phases pass on the PR head.
  • Before the rebase: sync(rccl): Sync with NCCL v2.32.3-1 #12321 (b0299c14dd71) against develop before the sync (5e6a51f28579) on MI355X (gfx950) and MI300X (gfx942), ROCm 7.0.2, with the same results.

Test Result

  • With the fix: passes 3/3.
  • Without it: fails 3/3 (in all three cases the caller's next token is (null) instead of "b").
  • The two control tests pass on both trees.

Submission Checklist

@rahulvaidya20
rahulvaidya20 force-pushed the users/rahulvaidya20/nccl-sync-v2.32.3 branch 3 times, most recently from a217f56 to 5e4b885 Compare October 4, 2026 04:56
Base automatically changed from users/rahulvaidya20/nccl-sync-v2.32.3 to develop October 5, 2026 16:37
@therock-pr-bot

therock-pr-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/rccl/test/host/init-test.cc; no test file found
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

🎉 All policy checks passed!

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

🙋 Wish to Override Policy?

@thomas-huber
thomas-huber force-pushed the users/thomas-huber/strtok-reentrancy-test branch from a19c143 to 4f48764 Compare October 6, 2026 15:05
@thomas-huber
thomas-huber marked this pull request as ready for review October 6, 2026 17:53
@thomas-huber
thomas-huber requested review from a team October 6, 2026 17:53

@amd-argus amd-argus Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ARGUS

Bottom line: Looks approval ready. The inline notes are design questions on the new test helper, not defects.

Comment @argus review to re-run, or @argus re-review after pushing.

Comment thread projects/rccl/test/host/init-test.cc Resolved
Comment thread projects/rccl/test/host/init-test.cc Resolved
Comment thread projects/rccl/test/host/init-test.cc Resolved

@amd-argus amd-argus Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ARGUS

Bottom line: LGTM once ncclOsCpuZero and ncclOsCpuSet move to fakes/os_fakes.cc.

Comment @argus review to re-run, or @argus re-review after pushing.

Comment thread projects/rccl/test/host/init-test.cc Resolved

@amd-argus amd-argus Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ARGUS

Bottom line: LGTM.

Comment @argus review to re-run, or @argus re-review after pushing.

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label Nov 3, 2026
Runs the NCCL_CTA_POLICY parser, ncclStrToCpuset() and ncclStrListToCpuset()
on a second thread while the calling thread is between strtok() calls on its
own string, then checks the caller's next token. strtok() has one process-wide
save pointer: before the switch to strtok_r() the parser leaves it at the end
of its own string, so the caller gets NULL instead of "b".

Upstream fix: NVIDIA/nccl@35512d6f6b73 ("Squash commit for Fix strtok thread safety")
Follow-up to review feedback:
- Assert that the parser's free() went through the deferral hook. If the
  hook stopped engaging, a clobbered strtok pointer would point into freed
  memory while the tests still passed.
- Note that ncclStrListToCpuset reads "1,3" as a CPU list, not a mask.
@thomas-huber thomas-huber removed the Stale PR has no activity for 25+ days label Nov 6, 2026
@thomas-huber
thomas-huber force-pushed the users/thomas-huber/strtok-reentrancy-test branch from 02d842a to 80ca602 Compare November 6, 2026 08:42
@thomas-huber

Copy link
Copy Markdown
Contributor Author

Rebased onto develop (42e7f5d9cb8b). #13586 has since added the same ncclOsCpuZero and ncclOsCpuSet fakes to fakes/os_fakes.cc, so the previous head would have defined them twice and broken the host-test build once merged, although GitHub showed no conflict. This PR no longer touches os_fakes.cc: the first commit no longer defines them in init-test.cc, and the third commit, which only moved them into os_fakes.cc, is dropped.

The tests are unchanged. On the new base they pass 3/3, and fail 3/3 with the parsers' strtok_r() calls back to strtok(); the full host-test build and run pass. The description is updated to match.

@amd-argus amd-argus Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ARGUS

Bottom line: LGTM.

Comment @argus review to re-run, or @argus re-review after pushing.

@peymanr

peymanr commented Nov 6, 2026

Copy link
Copy Markdown

PR Pundit review

(Testing PR Pundit Code Review agent. Not all comments may be relevant. This is a one-time automated pass: please address what is useful, no need to request a re-review. Please reply to each point, whether it applies or not: we harvest these replies, and both kinds are enormously helpful for tuning the agent. Reach out to @peymanr for suggestions.)

# Finding Where
1 🟠 Cpuset-parser concurrency regressions report under init microtest binary: this PR adds cpuset tests to InitMicrotest projects/rccl/test/host/init-test.cc:1153

1. 🟠 Should fix: Cpuset-parser concurrency regressions report under init microtest binary: this PR adds cpuset tests to InitMicrotest

projects/rccl/test/host/init-test.cc:1153

StrToCpuset_ConcurrentParse_KeepsCallerStrtokState and StrListToCpuset_ConcurrentParse_KeepsCallerStrtokState test include/cpuset.h but sit in suite InitMicrotest in rccl-UnitTestsMicroInit. So the Cpuset* pattern in test_categories_micro_cpuset.yaml does not select them, and a cpuset.h regression would surface under the init unit. That departs from MICROTEST_README's naming rule that every suite in a test file starts with its unit's stem. Moving them is not a plain cut-and-paste: cpuset-test.cc has no g_microFree seam, and the tests need it to defer the parser's free(). Either add such a seam to cpuset-test.cc, or keep the tests here with a comment explaining the placement; note the ncclStrToCpuset case largely duplicates CpusetMicrotest.StrToCpuset_ConcurrentParsesDoNotInterfere.

Who is affected: Developers filtering or categorising host microtests by unit (the Cpuset* filter or the cpuset category); no runtime or user impact.

Checked against the code by an independent pass.

Related past reviews: #13840 on projects/rccl/test/host/net-ib-cast-init-test.cc, #12435 on projects/rccl/test/host/ras-diagnostics-env-test.cc

Shared from a pilot of PR Pundit, an agentic code reviewer that builds and tests the change and reads the project's past reviews. Reviewed at 80ca6022; findings checked and posted by @peymanr; points already raised on this PR are left out.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants