Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] drm/amdgpu: wrong unit multipliers in amdgpu_info_ioctl() doorbell range - [Medium] drm/amdgpu: unsplit GFX and COMPUTE ranges in amdgpu_info_ioctl() --
commit e3f1d2882f95267baaa962bef8149a9b40b07bea Author: Alex Deucher <[email protected]> drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges This commit adds the AMDGPU_INFO_UQ_DOORBELL_RANGE query to amdgpu_info_ioctl() so userspace can query the per-IP doorbell byte offset and size. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > index 8e7e522a89e42..acc4d0a1ca14f 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > @@ -1452,6 +1452,26 @@ int amdgpu_info_ioctl(struct drm_device *dev, void > *data, struct drm_file *filp) > return -EINVAL; > } > } > + case AMDGPU_INFO_UQ_DOORBELL_RANGE: { > + struct drm_amdgpu_info_doorbell_range db_range = {}; > + > + switch (info->query_hw_ip.type) { > + case AMDGPU_HW_IP_GFX: > + case AMDGPU_HW_IP_COMPUTE: > + db_range.offset_bytes = adev->doorbell_index.kiq * 4; > + db_range.size_bytes = > (adev->doorbell_index.sdma_engine[0] - > + adev->doorbell_index.kiq) * 4; [Severity: Medium] Should AMDGPU_HW_IP_GFX and AMDGPU_HW_IP_COMPUTE report separate doorbell ranges instead of the combined [kiq, sdma_engine[0]) range? On GFX11 and GFX12, gfx_v11_0_cp_set_doorbell_range() and gfx_v12_0_cp_set_doorbell_range() program separate ranges for graphics and compute: drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c:gfx_v11_0_cp_set_doorbell_range() { /* set graphics engine doorbell range */ WREG32_SOC15(GC, 0, regCP_RB_DOORBELL_RANGE_LOWER, (adev->doorbell_index.gfx_ring0 * 2) << 2); WREG32_SOC15(GC, 0, regCP_RB_DOORBELL_RANGE_UPPER, (adev->doorbell_index.gfx_userqueue_end * 2) << 2); /* set compute engine doorbell range */ WREG32_SOC15(GC, 0, regCP_MEC_DOORBELL_RANGE_LOWER, (adev->doorbell_index.kiq * 2) << 2); WREG32_SOC15(GC, 0, regCP_MEC_DOORBELL_RANGE_UPPER, (adev->doorbell_index.userqueue_end * 2) << 2); } Reporting [kiq, sdma_engine[0]) for both IPs lets userspace place graphics userqueue doorbells inside the compute range (starting at kiq rather than gfx_ring0) and compute doorbells inside the graphics range, which breaks CP doorbell filtering and firmware workload detection. > + return copy_to_user(out, &db_range, > + min((size_t)size, > sizeof(db_range))) ? -EFAULT : 0; > + case AMDGPU_HW_IP_DMA: > + db_range.offset_bytes = > adev->doorbell_index.sdma_engine[0] * 4; > + db_range.size_bytes = > adev->doorbell_index.sdma_doorbell_range * adev->sdma.num_instances; [Severity: High] Are the unit multipliers for db_range.offset_bytes and db_range.size_bytes off by a factor of two for the qword indices and missing the dword-to-byte conversion for sdma_doorbell_range? In struct amdgpu_doorbell_index (drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h), doorbell_index fields such as kiq and sdma_engine[0] are 64-bit qword indices (8 bytes each) on Vega10 and later, whereas sdma_doorbell_range is a per-engine size in 32-bit dwords (4 bytes each): drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c:sdma_v6_0_sw_init() { ... ring->doorbell_index = (adev->doorbell_index.sdma_engine[i] << 1); // get DWORD offset ... } Multiplying kiq and sdma_engine[0] by 4 instead of 8 (or << 3) returns half the actual byte offset and size, placing AMDGPU_HW_IP_DMA doorbells at byte offset 1024 inside the CP doorbell aperture instead of 2048 at the NBIO SDMA aperture. In addition, adev->doorbell_index.sdma_doorbell_range * adev->sdma.num_instances is not multiplied by 4, so db_range.size_bytes is returned in dwords rather than bytes. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
