Repository navigation
Fix GC on Windows with multiple CPU groups - #134127
Conversation
When there are multiple CPU groups on Windows, the OS can assign the current process into any of these groups. When CPU groups support is not enabled for GC (using DOTNET_GCCpuGroup=1 or other means), the CPU index that is computed from the group index and cpu number exceeds some of the preallocated arrays for mapping processor to heap or numa node to heap and it can result in writing past those arrays, corrupting other heap allocations. This change fixes it by getting the max processor count based on the max CPU group count.
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🟢 Approval recommended
The focused change correctly sizes mappings for all possible Windows processor groups without altering normal processor-count behavior.
Pull request overview
Fixes Windows GC array sizing when processes run across multiple CPU groups without GC CPU-group support.
Changes:
- Computes maximum processor capacity from the OS maximum processor-group count.
- Prevents processor and NUMA mapping arrays from being undersized.
File summaries
| File | Description |
|---|---|
src/coreclr/gc/windows/gcenv.windows.cpp |
Updates Windows maximum processor-count calculation. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
|
The affinity set is initialized using GetTotalProcessorCount in some places and using GetMaxProcessorCount in other places. Is that a problem? runtime/src/coreclr/gc/interface.cpp Line 247 in ee851da Can we capture the difference between GetTotalProcessorCount and GetMaxProcessorCount in a comment? It is not clear why we have two APIs. |
There was a problem hiding this comment.
🟡 Changes recommended
The new API call can return zero on failure, leading to zero-length arrays and out-of-bounds access.
Get a fresh assessment by requesting another Copilot review.
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
The comment on the methods attempt to describe it: runtime/src/coreclr/gc/env/gcenv.os.h Lines 480 to 491 in 7ffcaad |
|
Actually, no, it was correct. The g_processAffinitySet cannot be initialized by the |
|
/backport to release/11.0 |
|
/backport to release/10.0 |
|
Started backporting to |
|
Started backporting to |
|
@janvorli backporting to git am output$ git cherry-pick a540e47694dfa5a10444c8f0958366120bddf1cb
Auto-merging src/coreclr/gc/windows/gcenv.windows.cpp
CONFLICT (content): Merge conflict in src/coreclr/gc/windows/gcenv.windows.cpp
error: could not apply a540e47694d... Fix GC on Windows with multiple CPU groups (#134127)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Fix GC on Windows with multiple CPU groups
Applying: Reflect PR feedback
Using index info to reconstruct a base tree...
M src/coreclr/gc/windows/gcenv.windows.cpp
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/gc/windows/gcenv.windows.cpp
CONFLICT (content): Merge conflict in src/coreclr/gc/windows/gcenv.windows.cpp
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0002 Reflect PR feedback
Error: The process '/usr/bin/git' failed with exit code 128 |
Backport of #134127 to release/11.0. ## Customer Impact - [x] Customer reported - [ ] Found internally On Windows systems with multiple CPU groups, a process running in a nonzero processor group can use a packed processor index beyond the dynamically allocated GC processor-to-heap mapping. This can write past the allocation and cause heap corruption when GC CPU-group support is disabled. The fix sizes the relevant mappings and affinity set for the maximum possible processor-group index space. It also validates and caches the Windows processor-group count during GC OS initialization. This issue was reported by two 1st party customers independently. ## Regression - [x] Yes - [ ] No Regression introduced by #131740. ## Testing CoreCLR tests ## Risk Low. This is a direct backport of the fix merged into main in #134127. The change only increases Windows GC processor-indexed allocation capacity and fails initialization if the topology API unexpectedly returns zero. > [!NOTE] > This pull request description was generated with GitHub Copilot. Co-authored-by: Jan Vorlicek <[email protected]>
Backport of #134127 to release/10.0. ## Customer Impact - [x] Customer reported - [ ] Found internally On Windows systems with multiple CPU groups, a process running in a nonzero processor group can use a packed processor index beyond the dynamically allocated GC processor-to-heap mapping. This can write past the allocation and cause heap corruption when GC CPU-group support is disabled. The fix sizes the relevant mappings and affinity set for the maximum possible processor-group index space. It also validates and caches the Windows processor-group count during GC OS initialization. This issue was reported by two 1st party customers independently. ## Regression - [x] Yes - [ ] No Regression introduced by #131740. ## Testing Built the checked x64 CoreCLR runtime with: `src\coreclr\build-runtime.cmd -x64 -checked -component runtime` ## Risk Low. This is a direct backport of the fix merged into main in #134127. The change only increases Windows GC processor-indexed allocation capacity and fails initialization if the topology API unexpectedly returns zero. > [!NOTE] > This pull request description was generated with GitHub Copilot. Copilot-Session: da1e6e4c-bb17-4b8b-9962-b0b5f8b38bcb
When there are multiple CPU groups on Windows, the OS can assign the current process into any of these groups. When CPU groups support is not enabled for GC (using DOTNET_GCCpuGroup=1 or other means), the CPU index that is computed from the group index and cpu number exceeds some of the preallocated arrays for mapping processor to heap or numa node to heap and it can result in writing past those arrays, corrupting other heap allocations.
This change fixes it by getting the max processor count based on the max CPU group count. This max count includes even possibly hot-plugged CPU groups.