Skip to content

fix(amdsmi): initialize Device metrics fields to avoid uninitialized reads - #8182

Merged
marifamd merged 6 commits into
developfrom
users/ssaka/fix_uninitialized_read
Aug 28, 2026
Merged

marifamd merged 6 commits into
developfrom
users/ssaka/fix_uninitialized_read

Conversation

@SakaSitharammurthy

@SakaSitharammurthy SakaSitharammurthy commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Due to uninitialized read of few variables in this api's "amdsmi_topo_get_p2p_status () and amdsmi_get_gpu_memory_partition_config ()" creates memleak.

JIRA ID

ISSUE ID : ROCm/amdsmi#129

Test Result

->After running valgrind tool on this example "amd_smi_partition_example.cc" and observed no memory leaks.

@therock-pr-bot

therock-pr-bot Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ✅ Pass —
🚫 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?

@therock-pr-bot

therock-pr-bot Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ Unit Test

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

Copilot AI 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.

Pull request overview

This PR targets valgrind-reported issues in AMDSMI APIs by eliminating uninitialized reads and improving defensive initialization of output buffers/structures, aligning behavior with the PR’s stated goal of preventing memleaks/uninitialized-use patterns.

Changes:

  • Add null-output-parameter validation for amdsmi_topo_get_p2p_status().
  • Zero-initialize output structs/bitmasks and local char buffers used for partition capability queries; trim whitespace in returned capability strings.
  • Fix a debug log to report the correct status value for the rsmi_dev_memory_partition_capabilities_get call; initialize additional Device members in the constructor initializer list.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
projects/amdsmi/src/amd_smi/amd_smi.cc Adds null checks and broad zero-initialization to prevent uninitialized reads in topology and partition APIs; corrects status used in debug logging.
projects/amdsmi/rocm_smi/src/rocm_smi_device.cc Extends Device constructor member initialization to avoid uninitialized member state.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SakaSitharammurthy SakaSitharammurthy changed the title [#3:GITHUB-TRIAGE][AMDSMI]amdsmi_topo_get_p2p_status use-after-free and amds… fix(amdsmi): initialize Device metrics fields to avoid uninitialized reads Jul 7, 2026
…mi_get_gpu_memory_partition_config uninitialized read
@marifamd
marifamd force-pushed the users/ssaka/fix_uninitialized_read branch from ccc32bf to 5cdbff1 Compare July 15, 2026 21:23
Comment thread projects/amdsmi/src/amd_smi/amd_smi.cc Resolved
… tests

Initialize remaining Device POD members (bdfid_ to UINT64_MAX to preserve the
sentinel path selection in DiscoverAmdGpuKfdNodes), zero-init supported_nps_configs
and the resource-profile local, and collapse the redundant nps_caps union writes
to value-initialization.

Add a null check to amdsmi_topo_get_link_type mirroring amdsmi_topo_get_p2p_status,
and cover the p2p null-argument path with a C++ assertion and a Python binding test.

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Comment thread projects/amdsmi/src/amd_smi/amd_smi.cc Resolved

@gabrpham gabrpham 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.

Potential for out of bounds error has been addressed. Approved.

@marifamd
marifamd merged commit 80b04ca into develop Aug 28, 2026
177 of 182 checks passed
@marifamd
marifamd deleted the users/ssaka/fix_uninitialized_read branch August 28, 2026 15:26
@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

corey-derochie-amd pushed a commit that referenced this pull request Oct 8, 2026
…reads (#8182)

## Motivation

Due to uninitialized read of few variables in this api's
"amdsmi_topo_get_p2p_status() and
amdsmi_get_gpu_memory_partition_config()" creates memleak.

## JIRA ID

ISSUE ID : ROCm/amdsmi#129

## Test Result
->After running valgrind tool on this example
"amd_smi_partition_example.cc" and observed no memory leaks.

---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
corey-derochie-amd pushed a commit that referenced this pull request Oct 9, 2026
…reads (#8182)

## Motivation

Due to uninitialized read of few variables in this api's
"amdsmi_topo_get_p2p_status() and
amdsmi_get_gpu_memory_partition_config()" creates memleak.

## JIRA ID

ISSUE ID : ROCm/amdsmi#129

## Test Result
->After running valgrind tool on this example
"amd_smi_partition_example.cc" and observed no memory leaks.

---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
corey-derochie-amd pushed a commit that referenced this pull request Oct 14, 2026
…reads (#8182)

## Motivation

Due to uninitialized read of few variables in this api's
"amdsmi_topo_get_p2p_status() and
amdsmi_get_gpu_memory_partition_config()" creates memleak.

## JIRA ID

ISSUE ID : ROCm/amdsmi#129

## Test Result
->After running valgrind tool on this example
"amd_smi_partition_example.cc" and observed no memory leaks.

---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
corey-derochie-amd pushed a commit that referenced this pull request Oct 14, 2026
…reads (#8182)

## Motivation

Due to uninitialized read of few variables in this api's
"amdsmi_topo_get_p2p_status() and
amdsmi_get_gpu_memory_partition_config()" creates memleak.

## JIRA ID

ISSUE ID : ROCm/amdsmi#129

## Test Result
->After running valgrind tool on this example
"amd_smi_partition_example.cc" and observed no memory leaks.

---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
corey-derochie-amd pushed a commit that referenced this pull request Oct 15, 2026
…reads (#8182)

## Motivation

Due to uninitialized read of few variables in this api's
"amdsmi_topo_get_p2p_status() and
amdsmi_get_gpu_memory_partition_config()" creates memleak.

## JIRA ID

ISSUE ID : ROCm/amdsmi#129

## Test Result
->After running valgrind tool on this example
"amd_smi_partition_example.cc" and observed no memory leaks.

---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
corey-derochie-amd pushed a commit that referenced this pull request Oct 15, 2026
…reads (#8182)

## Motivation

Due to uninitialized read of few variables in this api's
"amdsmi_topo_get_p2p_status() and
amdsmi_get_gpu_memory_partition_config()" creates memleak.

## JIRA ID

ISSUE ID : ROCm/amdsmi#129

## Test Result
->After running valgrind tool on this example
"amd_smi_partition_example.cc" and observed no memory leaks.

---------

Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
Co-authored-by: Maisam Arif <Maisam.Arif@amd.com>
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.

4 participants