Skip to content

gdb/amdgpu-tdep: Fix assertion in amdgpu_segment_address_to_core_address#146

Merged
lancesix merged 1 commit into
amd-stagingfrom
users/lancesix/fix-assert-odd-addresses
Jun 1, 2026
Merged

gdb/amdgpu-tdep: Fix assertion in amdgpu_segment_address_to_core_address#146
lancesix merged 1 commit into
amd-stagingfrom
users/lancesix/fix-assert-odd-addresses

Conversation

@lancesix
Copy link
Copy Markdown
Collaborator

The code in amdgpu_segment_address_to_core_address was assuming that it could not receive an address which had bits already set in the bits where it wants to store the address space ID. This is an invalid assumption, as a user input can forge any address that gets into this function.

I stumbled onto the issue while looking at sometging else. I wanted to inspect a wave's stack, but used the wrong register for the stack pointer, which ended up causing the assertion to trigger:

(gdb) x/32x private_wave#$s32
../../gdb/amdgpu-tdep.c:1488: internal-error: amdgpu_segment_address_to_core_address: Assertion `(significant_bits & address) == address' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

This triggered the invalid expectation in
amdgpu_segment_address_to_core_address. Because this is expressed as an assertion rather than a test triggering an error, this is not handled gracefully.

This patch fixes this by changing the assert into a "if (invalid_pred) errer (_(msg))" to gracefully handle invalid input. While at it, the patch also improved on the check to ensure that canonical addresses (where the address is sign-extended past the significant bits).

This also adds a test that exercises consuming invalid input as well as consuming sign extended addresses.

Change-Id: I3281f68b65eb817e949378f5548169c95cbf277c

@lancesix lancesix requested review from aktemur and palves May 29, 2026 11:06
@lancesix lancesix requested a review from a team as a code owner May 29, 2026 11:06
@lumachad lumachad changed the title gdb/amdgpu-tded: Fix assertion in amdgpu_segment_address_to_core_address gdb/amdgpu-tdep: Fix assertion in amdgpu_segment_address_to_core_address May 29, 2026
Copy link
Copy Markdown
Collaborator

@lumachad lumachad left a comment

Choose a reason for hiding this comment

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

A few comments. Otherwise LGTM if CI is good.

Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
Comment thread gdb/testsuite/gdb.rocm/aspace-user-input.exp Outdated
Comment thread gdb/amdgpu-tdep.c Outdated
@lancesix lancesix force-pushed the users/lancesix/fix-assert-odd-addresses branch from cfaf837 to c0d1870 Compare May 29, 2026 11:29
@lancesix
Copy link
Copy Markdown
Collaborator Author

Addressed comments, thanks (and sorry for the typos).

@lancesix lancesix requested a review from lumachad May 29, 2026 11:30
Copy link
Copy Markdown
Collaborator

@lumachad lumachad left a comment

Choose a reason for hiding this comment

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

Leaving an approval from my side.

@lancesix lancesix force-pushed the users/lancesix/fix-assert-odd-addresses branch from c0d1870 to ddfc21e Compare May 29, 2026 14:39
Comment thread gdb/testsuite/gdb.rocm/aspace-user-input.exp
Comment thread gdb/testsuite/gdb.rocm/aspace-user-input.exp Outdated
@lancesix lancesix force-pushed the users/lancesix/fix-assert-odd-addresses branch from ddfc21e to cf38b6f Compare May 29, 2026 15:46
The code in amdgpu_segment_address_to_core_address was assuming that it
could not receive an address which had bits already set in the bits
where it wants to store the address space ID.  This is an invalid
assumption, as a user input can forge any address that gets into this
function.

I stumbled onto the issue while looking at something else. I wanted to
inspect a wave's stack, but used the wrong register for the stack
pointer, which ended up causing the assertion to trigger:

    (gdb) x/32x private_wave#$s32
    ../../gdb/amdgpu-tdep.c:1488: internal-error: amdgpu_segment_address_to_core_address: Assertion `(significant_bits & address) == address' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.

This triggered the invalid expectation in
amdgpu_segment_address_to_core_address.  Because this is expressed as an
assertion rather than a test triggering an error, this is not handled
gracefully.

This patch fixes this by changing the assert into a "if (invalid_pred)
errer (_(msg))" to gracefully handle invalid input.  While at it, the
patch also improved on the check to ensure that canonical addresses
(where the address is sign-extended past the significant bits).

This also adds a test that exercises consuming invalid input as well as
consuming sign extended addresses.

Change-Id: I3281f68b65eb817e949378f5548169c95cbf277c
@lancesix lancesix force-pushed the users/lancesix/fix-assert-odd-addresses branch from cf38b6f to 70dce2c Compare May 29, 2026 15:48
@lancesix lancesix merged commit 7e50709 into amd-staging Jun 1, 2026
5 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.

3 participants