Skip to contentSkip to conversation

drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges

PATCH In review Alex Deucher 3 participants 3 messages Nov 17 – Nov 18

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu/userq: Add INFO IOCTL query for doorbell ranges

Each IP gets a subset of each doorbell page. Add a query so userspace can query the ranges.

Cc Yogesh Mohan Marimuthu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 20 ++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h           |  6 ++++++
 2 files changed, 26 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +20 -0
index d7872acb4d790..42109f7706294 100644
@@ -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;
include/uapi/drm/amdgpu_drm.h +6 -0
index 29009f6aabde9..86d42a5d683c0 100644
@@ -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
  */
Signature · 1 line
2.56.1
#1 lore raw
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…

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.

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -0
index 8e7e522a89e42..acc4d0a1ca14f 100644
@@ -1452,6 +1452,26 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 			return -EINVAL;
 		}

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1463

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9 -0
 	}
+	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.

drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) · line 1469

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +5 -0
+			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.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Alex Deucher

Le 17/11/2026 à 20:23, Alex Deucher a écrit :

Quoted 2 lines

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

Quoted 44 lines
Cc Yogesh Mohan Marimuthu <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 20 ++++++++++++++++++++
  include/uapi/drm/amdgpu_drm.h           |  6 ++++++
  2 files changed, 26 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +20 -0
index d7872acb4d790..42109f7706294 100644
@@ -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;
include/uapi/drm/amdgpu_drm.h +0 -0
index 29009f6aabde9..86d42a5d683c0 100644

include/uapi/drm/amdgpu_drm.h struct drm_amdgpu_cs_chunk_cp_gfx_shadow { · line 1292

Quoted 4 lines
include/uapi/drm/amdgpu_drm.h +1 -0
@@ -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

Quoted 15 lines
include/uapi/drm/amdgpu_drm.h +5 -0
  #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
   */