* [PATCH] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges
@ 2026-11-17 19:23 Alex Deucher
2026-11-17 20:01 ` sashiko-bot
2026-11-18 9:35 ` Pierre-Eric Pelloux-Prayer
0 siblings, 2 replies; 3+ messages in thread
From: Alex Deucher @ 2026-11-17 19:23 UTC (permalink / raw)
To: amd-gfx; +Cc: Alex Deucher, Yogesh Mohan Marimuthu
Each IP gets a subset of each doorbell page. Add a query
so userspace can query the ranges.
Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 20 ++++++++++++++++++++
include/uapi/drm/amdgpu_drm.h | 6 ++++++
2 files changed, 26 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index d7872acb4d790..42109f7706294 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -1453,6 +1453,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;
+ 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;
+ return copy_to_user(out, &db_range,
+ min((size_t)size, sizeof(db_range))) ? -EFAULT : 0;
+ default:
+ return -EINVAL;
+ }
+ }
default:
DRM_DEBUG_KMS("Invalid request %d\n", info->query);
return -EINVAL;
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 29009f6aabde9..86d42a5d683c0 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -1289,6 +1289,7 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
#define AMDGPU_INFO_GPUVM_FAULT 0x23
/* query FW object size and alignment */
#define AMDGPU_INFO_UQ_FW_AREAS 0x24
+#define AMDGPU_INFO_UQ_DOORBELL_RANGE 0x25
#define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
#define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
@@ -1668,6 +1669,11 @@ struct drm_amdgpu_info_uq_metadata {
};
};
+struct drm_amdgpu_info_doorbell_range {
+ __u32 offset_bytes;
+ __u32 size_bytes;
+};
+
/*
* Supported GPU families
*/
--
2.56.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges
2026-11-17 19:23 [PATCH] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
@ 2026-11-17 20:01 ` sashiko-bot
2026-11-18 9:35 ` Pierre-Eric Pelloux-Prayer
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-17 20:01 UTC (permalink / raw)
To: Alex Deucher, amd-gfx
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 <alexander.deucher@amd.com>
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/20261117192304.809813-1-alexander.deucher@amd.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges
2026-11-17 19:23 [PATCH] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
2026-11-17 20:01 ` sashiko-bot
@ 2026-11-18 9:35 ` Pierre-Eric Pelloux-Prayer
1 sibling, 0 replies; 3+ messages in thread
From: Pierre-Eric Pelloux-Prayer @ 2026-11-18 9:35 UTC (permalink / raw)
To: Alex Deucher, amd-gfx; +Cc: Yogesh Mohan Marimuthu
Le 17/11/2026 à 20:23, Alex Deucher a écrit :
> Each IP gets a subset of each doorbell page. Add a query
> so userspace can query the ranges.
If the offset for each IP has to be inside a range then the kernel
should validate what UMD uses in amdgpu_userq_get_doorbell_index
>
> Cc: Yogesh Mohan Marimuthu <yogesh.mohanmarimuthu@amd.com>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 20 ++++++++++++++++++++
> include/uapi/drm/amdgpu_drm.h | 6 ++++++
> 2 files changed, 26 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> index d7872acb4d790..42109f7706294 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
> @@ -1453,6 +1453,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;
> + 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;
> + return copy_to_user(out, &db_range,
> + min((size_t)size, sizeof(db_range))) ? -EFAULT : 0;
> + default:
> + return -EINVAL;
> + }
> + }
> default:
> DRM_DEBUG_KMS("Invalid request %d\n", info->query);
> return -EINVAL;
> diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
> index 29009f6aabde9..86d42a5d683c0 100644
> --- a/include/uapi/drm/amdgpu_drm.h
> +++ b/include/uapi/drm/amdgpu_drm.h
> @@ -1289,6 +1289,7 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {
> #define AMDGPU_INFO_GPUVM_FAULT 0x23
> /* query FW object size and alignment */
> #define AMDGPU_INFO_UQ_FW_AREAS 0x24
> +#define AMDGPU_INFO_UQ_DOORBELL_RANGE 0x25
Should KMS_DRIVER_MINOR be incremented to let userspace know that this
query is available?
Thanks,
Pierre-Eric
>
> #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
> #define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
> @@ -1668,6 +1669,11 @@ struct drm_amdgpu_info_uq_metadata {
> };
> };
>
> +struct drm_amdgpu_info_doorbell_range {
> + __u32 offset_bytes;
> + __u32 size_bytes;
> +};
> +
> /*
> * Supported GPU families
> */
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 9:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 19:23 [PATCH] drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges Alex Deucher
2026-11-17 20:01 ` sashiko-bot
2026-11-18 9:35 ` Pierre-Eric Pelloux-Prayer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox