drm/amdgpu: Fix __rcu fence pointer accesses
Subsystems (3)
PATCH 1/2 drm/amdgpu: Fix __rcu fence pointer accesses
Building for ARCH=um with W=1 C=1 makes sparse report "incompatible types in comparison expression (different address spaces)" warnings in the KFD code, exposed after UML builds were enabled:
- amdgpu_amdkfd_fence.c compares the __rcu-annotated dma_fence.ops pointer directly in to_amdgpu_amdkfd_fence().
- amdgpu_amdkfd_gpuvm.c compares the __rcu eviction fence pointer directly in amdgpu_amdkfd_gpuvm_restore_process_bos().
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +1 -1
@@ -92,7 +92,7 @@ struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f)return NULL ; fence = container_of(f, struct amdgpu_amdkfd_fence, base); -if (f->ops == &amdkfd_fence_ops) +if (rcu_access_pointer (f->ops) == &amdkfd_fence_ops)return fence;return NULL ;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -1
@@ -3096,7 +3096,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu * process_info->eviction_fence = new_fence;replace_eviction_fence (ef,dma_fence_get (&new_fence->base)); }else { -WARN_ONCE (*ef != &process_info->eviction_fence->base, +WARN_ONCE (rcu_access_pointer (*ef) != &process_info->eviction_fence->base,"KFD eviction fence doesn't match KGD process_info" ); }
--
2.43.0
PATCH 2/2 drm/amdgpu: Pack nested ucode_info struct
Building for ARCH=um with W=1 C=1 makes the "amd_sriov_msg_vf2pf_info must be 1 KB" static assertion in amdgv_sriovmsg.h fail under sparse, exposed after UML builds were enabled.
Sparse does not honor #pragma pack(push, 1) for the nested ucode_info struct, so it sizes each element as 8 bytes instead of 5 and computes the surrounding structure as larger than 1 KB. The compilers get this right via the enclosing pragma, but the annotation should be explicit.
--- drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h +1 -1
@@ -379,7 +379,7 @@ struct amd_sriov_msg_vf2pf_info {struct {uint8_t id;uint32_t version; - } ucode_info[AMD_SRIOV_MSG_RESERVE_UCODE ]; + } __packed ucode_info[AMD_SRIOV_MSG_RESERVE_UCODE];uint64_t dummy_page_addr;/* FB allocated for guest MES to record UQ info */ uint64_t mes_info_addr;
Signature · 1 line
2.43.0
Re: [PATCH 2/2] drm/amdgpu: Pack nested ucode_info struct
Quoted 9 lines · Alex Hung
Building for ARCH=um with W=1 C=1 makes the "
amd_sriov_msg_vf2pf_infomust be 1 KB" static assertion inamdgv_sriovmsg.hfail under sparse, exposed after UML builds were enabled.Sparse does not honor #pragma
pack(push, 1)for the nesteducode_infostruct, so it sizes each element as 8 bytes instead of 5 and computes the surrounding structure as larger than 1 KB. The compilers get this right via the enclosing pragma, but the annotation should be explicit.
Quoted 6 lines
Fixes af3f2f5db265 ("drm/amdgpu: Remove UML build exclusion from Kconfig")Reported-by kernel test robot <[email protected]>Cc Harry Wentland <[email protected]>Assisted-by Copilot:Claude-Opus-4.8Signed-off-by Alex Hung <[email protected]>
Harry
Quoted 17 lines
--- drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgv_sriovmsg.h +1
-1@@ -379,7 +379,7 @@ struct amd_sriov_msg_vf2pf_info {struct {uint8_t id;uint32_t version; - } ucode_info[AMD_SRIOV_MSG_RESERVE_UCODE ]; + } __packed ucode_info[AMD_SRIOV_MSG_RESERVE_UCODE];uint64_t dummy_page_addr;/* FB allocated for guest MES to record UQ info */ uint64_t mes_info_addr;
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Misuse of rcu_access_pointer() on a non-RCU annotated pointer (f->ops), which actively triggers a…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Misuse of rcu_access_pointer() on a non-RCU annotated pointer (f->ops), which actively triggers a Sparse warning. --
--- Patch [1]: [PATCH 1/2] drm/amdgpu: Fix __rcu fence pointer accesses --- commit 5448af797b4d872eec1209aac5ec209c3c2b6b4a
Author: Alex Hung <[email protected]>
drm/amdgpu: Fix __rcu fence pointer accesses
This commit uses rcu_access_pointer() to resolve sparse warnings when comparing fence pointers in the KFD code. It wraps f->ops and an eviction fence pointer to address 'incompatible types in comparison expression' warnings.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f) · line 95
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +1
-1@@ -92,7 +92,7 @@ struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f)return NULL ; fence = container_of(f, struct amdgpu_amdkfd_fence, base); -if (f->ops == &amdkfd_fence_ops) +if (rcu_access_pointer (f->ops) == &amdkfd_fence_ops)
[Severity: Low]
Is f->ops actually an __rcu-annotated pointer?
Looking at struct dma_fence, the ops field is a standard const struct dma_fence_ops * without the __rcu annotation.
Does wrapping a non-RCU pointer in rcu_access_pointer() trigger the exact Sparse warning ("different address spaces") this commit aims to fix, since the macro expects an __rcu pointer?
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +0
-0return fence;return NULL ;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 9 lines · Alex Hung
Building for ARCH=um with W=1 C=1 makes sparse report "incompatible types in comparison expression (different address spaces)" warnings in the KFD code, exposed after UML builds were enabled:
-
amdgpu_amdkfd_fence.ccompares the __rcu-annotated dma_fence.ops pointer directly into_amdgpu_amdkfd_fence().
-amdgpu_amdkfd_gpuvm.ccompares the__rcueviction fence pointer directly inamdgpu_amdkfd_gpuvm_restore_process_bos().
Quoted 6 lines
Fixes af3f2f5db265 ("drm/amdgpu: Remove UML build exclusion from Kconfig")Reported-by kernel test robot <[email protected]>Cc Harry Wentland <[email protected]>Assisted-by Copilot:Claude-Opus-4.8Signed-off-by Alex Hung <[email protected]>
Quoted 34 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_fence.c +1
-1@@ -92,7 +92,7 @@ struct amdgpu_amdkfd_fence *to_amdgpu_amdkfd_fence(struct dma_fence *f)return NULL ; fence = container_of(f, struct amdgpu_amdkfd_fence, base); -if (f->ops == &amdkfd_fence_ops) +if (rcu_access_pointer (f->ops) == &amdkfd_fence_ops)return fence;return NULL ;drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-2@@ -3096,7 +3096,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence __rcu * process_info->eviction_fence = new_fence;replace_eviction_fence (ef,dma_fence_get (&new_fence->base)); }else { -WARN_ONCE (*ef != &process_info->eviction_fence->base, +WARN_ONCE (rcu_access_pointer (*ef) != &process_info->eviction_fence->base,"KFD eviction fence doesn't match KGD process_info" ); } --2.43.0