From: Jesse Zhang <Jesse.Zhang@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>,
Christian Koenig <christian.koenig@amd.com>,
Jesse.zhang <Jesse.zhang@amd.com>,
Jesse Zhang <Jesse.Zhang@amd.com>
Subject: [PATCH v2 02/11] drm/amdgpu/userq: route SDMA UMQ doorbells through the kernel pool
Date: Mon, 27 Apr 2026 16:34:28 +0800 [thread overview]
Message-ID: <20260427083543.1328533-2-Jesse.Zhang@amd.com> (raw)
In-Reply-To: <20260427083543.1328533-1-Jesse.Zhang@amd.com>
From: "Jesse.zhang" <Jesse.zhang@amd.com>
User-allocated DOORBELL BOs land at BAR offsets outside the
firmware-managed NBIO SDMA decode window and cannot reach the SDMA
back-end. For AMDGPU_HW_IP_DMA queues, ignore the user-supplied
doorbell index and allocate one from the per-device pool added in the
previous patch. Track the assigned slot id on the queue so it can be
returned to the bitmap on destroy.
Add a new sdma_doorbell_offset_bytes field to drm_amdgpu_userq_out
that tells userspace where its kernel-allocated qword slot lives
inside the BO it will mmap (the BO handle comes from the
AMDGPU_INFO_SDMA_USERQ_DOORBELL ioctl added later in the series).
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 47 +++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 7 ++++
include/uapi/drm/amdgpu_drm.h | 8 ++++
3 files changed, 62 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
index 8f48520cb822..cea0f9cb59d0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -662,6 +662,10 @@ amdgpu_userq_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_que
amdgpu_bo_unpin(queue->wptr_obj.obj);
amdgpu_bo_unreserve(queue->wptr_obj.obj);
amdgpu_bo_unref(&queue->wptr_obj.obj);
+
+ if (queue->sdma_userq_db_slot >= 0)
+ amdgpu_sdma_userq_doorbell_free(adev,
+ (u32)queue->sdma_userq_db_slot);
kfree(queue);
pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -762,6 +766,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
queue->queue_type = args->in.ip_type;
queue->vm = &fpriv->vm;
queue->priority = priority;
+ queue->sdma_userq_db_slot = -1;
db_info.queue_type = queue->queue_type;
db_info.doorbell_handle = queue->doorbell_handle;
@@ -792,6 +797,38 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
goto clean_mapping;
}
+ /*
+ * SDMA UMQ doorbell override: user-allocated DOORBELL BOs land at
+ * BAR offsets outside the firmware-managed NBIO SDMA decode window
+ * and cannot reach the SDMA back-end. Replace the user-supplied
+ * doorbell index with one allocated from the per-device
+ * sdma.userq_db_obj BO that sits inside the routable window.
+ * Userspace fetches a GEM handle for that BO via
+ * AMDGPU_INFO_SDMA_USERQ_DOORBELL and mmap()s it through the
+ * standard GEM_MMAP path; sdma_doorbell_offset_bytes (returned in
+ * args->out) tells userspace where inside that mapping its slot
+ * lives.
+ */
+ if (queue->queue_type == AMDGPU_HW_IP_DMA &&
+ adev->sdma.userq_db_obj) {
+ u32 slot_id;
+
+ r = amdgpu_sdma_userq_doorbell_alloc(adev, &slot_id);
+ if (r) {
+ drm_file_err(uq_mgr->file,
+ "SDMA UMQ doorbell pool exhausted (err=%d)\n",
+ r);
+ goto clean_mapping;
+ }
+ /*
+ * Slot id is a qword index inside the routable window;
+ * convert to absolute BAR dword index.
+ */
+ index = (u64)(adev->doorbell_index.sdma_engine[0] << 1) +
+ (u64)slot_id * 2;
+ queue->sdma_userq_db_slot = (int)slot_id;
+ }
+
queue->doorbell_index = index;
xa_init_flags(&queue->fence_drv_xa, XA_FLAGS_ALLOC);
r = amdgpu_userq_fence_driver_alloc(adev, &queue->fence_drv);
@@ -851,6 +888,16 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args)
amdgpu_userq_init_hang_detect_work(queue);
args->out.queue_id = qid;
+ if (queue->sdma_userq_db_slot >= 0) {
+ /*
+ * Tell userspace where inside its mmap of the SDMA UMQ
+ * doorbell BO (handle returned by
+ * AMDGPU_INFO_SDMA_USERQ_DOORBELL) the assigned qword slot
+ * lives.
+ */
+ args->out.sdma_doorbell_offset_bytes =
+ (u64)queue->sdma_userq_db_slot * sizeof(u64);
+ }
atomic_inc(&uq_mgr->userq_count[queue->queue_type]);
mutex_unlock(&uq_mgr->userq_mutex);
return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
index 675fe6395ac8..cdfced627dec 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h
@@ -59,6 +59,13 @@ struct amdgpu_usermode_queue {
uint64_t doorbell_handle;
uint64_t doorbell_index;
uint64_t flags;
+ /*
+ * For SDMA UMQs whose doorbell came from the kernel-managed pool
+ * (amdgpu_sdma_userq_doorbell_alloc), record the slot id so it can
+ * be returned to the bitmap on queue destroy. -1 means the queue
+ * is using a user-supplied doorbell BO.
+ */
+ int sdma_userq_db_slot;
struct amdgpu_mqd_prop *userq_prop;
struct amdgpu_userq_mgr *userq_mgr;
struct amdgpu_vm *vm;
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 9f3090db2f16..79e8bbda046b 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -421,6 +421,14 @@ struct drm_amdgpu_userq_out {
*/
__u32 queue_id;
__u32 _pad;
+ /**
+ * For SDMA usermode queues whose doorbell was assigned by the
+ * kernel from the per-device pool (see AMDGPU_INFO__USERQ_DOORBELL),
+ * this field carries the byte offset of the assigned slot inside
+ * the routable doorbell window so userspace can write there.
+ * 0 means the kernel did not override the user's doorbell.
+ */
+ __u64 sdma_doorbell_offset_bytes;
};
union drm_amdgpu_userq {
--
2.49.0
next prev parent reply other threads:[~2026-04-27 8:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 8:34 [PATCH v2 01/11] drm/amdgpu/sdma: add SDMA usermode-queue doorbell pool infra Jesse Zhang
2026-04-27 8:34 ` Jesse Zhang [this message]
2026-04-27 8:34 ` [PATCH v2 03/11] drm/amdgpu/gem: only enforce amdgpu_bo access checks on amdgpu_bo objects Jesse Zhang
2026-04-27 8:39 ` Christian König
2026-04-27 8:34 ` [PATCH v2 04/11] drm/amdgpu/sdma7: register SDMA UMQ doorbell pool Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 05/11] drm/amdgpu/sdma6: " Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 06/11] drm/amdgpu: add AMDGPU_INFO_USERQ_DOORBELL ioctl Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 07/11] drm/amdgpu/mes: add NOTIFY_WORK_ON_UNMAPPED_QUEUE op + ADD_QUEUE fields Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 08/11] drm/amdgpu/mes11: plumb unmap_flag_addr + NOTIFY_WORK_ON_UNMAPPED_QUEUE Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 09/11] drm/amdgpu/mes12: plumb is_user_mode_submission, unmap_flag_addr, NOTIFY Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 10/11] drm/amdgpu/mes_userqueue: mark SDMA UMQs as user-mode submission Jesse Zhang
2026-04-27 8:34 ` [PATCH v2 11/11] drm/amdgpu/userq_fence: wake gangs-out SDMA UMQs via NOTIFY Jesse Zhang
2026-04-27 8:42 ` [PATCH v2 01/11] drm/amdgpu/sdma: add SDMA usermode-queue doorbell pool infra Christian König
2026-04-28 9:39 ` Zhang, Jesse(Jie)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260427083543.1328533-2-Jesse.Zhang@amd.com \
--to=jesse.zhang@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox