Skip to contentSkip to conversation

drm/amdgpu: convert userq UAPI _pad to flags

PATCH In review Alex Deucher 4 participants 28 messages Apr 10, 2025 – Apr 11, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/13 drm/amdgpu: convert userq UAPI _pad to flags

Reuse the _pad field for flags.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 4 ++--
 include/uapi/drm/amdgpu_drm.h                 | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -2
index 50317fbd40e0e..57a4ef64e0b8b 100644
@@ -377,7 +377,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
 	switch (args->in.op) {
 	case AMDGPU_USERQ_OP_CREATE:
-		if (args->in._pad)
+		if (args->in.flags)
 			return -EINVAL;
 		r = amdgpu_userqueue_create(filp, args);
 		if (r)
@@ -388,7 +388,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 		if (args->in.ip_type ||
 		    args->in.doorbell_handle ||
 		    args->in.doorbell_offset ||
-		    args->in._pad ||
+		    args->in.flags ||
 		    args->in.queue_va ||
 		    args->in.queue_size ||
 		    args->in.rptr_va ||
include/uapi/drm/amdgpu_drm.h +4 -1
index ef97c0d78b8a0..1a451907184cc 100644
@@ -355,7 +355,10 @@ struct drm_amdgpu_userq_in {
 	 * and doorbell_offset in the doorbell bo.
 	 */
 	__u32   doorbell_offset;
-	__u32 _pad;
+	/**
+	 * @flags: flags used for queue parameters
+	 */
+	__u32 flags;
 	/**
 	 * @queue_va: Virtual address of the GPU memory which holds the queue
 	 * object. The queue holds the workload packets.
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 2/13 drm/amdgpu/userq: add UAPI for setting queue priority

Allow the user to set a queue priority levels:
0 - normal low - most apps (maps to MES AMD_PRIORITY_LEVEL_NORMAL)
1 - low - background jobs (maps to MES AMD_PRIORITY_LEVEL_LOW)
2 - normal high - apps that need relative high (maps to MES AMD_PRIORITY_LEVEL_MEDIUM) 3 - high (admin only - for compositors) (maps to MES AMD_PRIORITY_LEVEL_HIGH)

---
 include/uapi/drm/amdgpu_drm.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/uapi/drm/amdgpu_drm.h +8 -0
index 1a451907184cc..8719754c777b4 100644
@@ -329,6 +329,14 @@ union drm_amdgpu_ctx {
 #define AMDGPU_USERQ_OP_CREATE	1
 #define AMDGPU_USERQ_OP_FREE	2
 
+/* queue priority levels */
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK  0x3
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT 0
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_LOW 0
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW 1
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH 2
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3 /* admin only */
+
 /*
  * This structure is a container to pass input configuration
  * info for all supported userqueue related operations.
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 2/13
#2 lore raw

Re: [PATCH 02/13] drm/amdgpu/userq: add UAPI for setting queue priority

Quoted 30 lines · Alex Deucher

Allow the user to set a queue priority levels:
0 - normal low - most apps (maps to MES AMD_PRIORITY_LEVEL_NORMAL)
1 - low - background jobs (maps to MES AMD_PRIORITY_LEVEL_LOW)
2 - normal high - apps that need relative high (maps to MES AMD_PRIORITY_LEVEL_MEDIUM) 3 - high (admin only - for compositors) (maps to MES AMD_PRIORITY_LEVEL_HIGH)

---
  include/uapi/drm/amdgpu_drm.h | 8 ++++++++
  1 file changed, 8 insertions(+)
include/uapi/drm/amdgpu_drm.h +8 -0
index 1a451907184cc..8719754c777b4 100644
@@ -329,6 +329,14 @@ union drm_amdgpu_ctx {
  #define AMDGPU_USERQ_OP_CREATE	1
  #define AMDGPU_USERQ_OP_FREE	2
 
+/* queue priority levels */
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK  0x3
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT 0
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_LOW 0
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW 1
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH 2
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3 /* admin only */
+
  /*
   * This structure is a container to pass input configuration
   * info for all supported userqueue related operations.
author maintainer
#3 lore raw

PATCH 3/13 drm/amdgpu/mes11: add conversion for priority levels

In reply to Alex Deucher

Convert driver priority levels to MES11 priority levels. At the moment they are the same, but they may not always be.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +19 -2
index 06b51867c9aac..b39a538cfc4e4 100644
@@ -287,6 +287,23 @@ static int convert_to_mes_queue_type(int queue_type)
 	return -1;
 }
 
+static int convert_to_mes_priority_level(int priority_level)
+{
+	switch (priority_level) {
+	case AMDGPU_MES_PRIORITY_LEVEL_LOW:
+		return AMD_PRIORITY_LEVEL_LOW;
+	case AMDGPU_MES_PRIORITY_LEVEL_NORMAL:
+	default:
+		return AMD_PRIORITY_LEVEL_NORMAL;
+	case AMDGPU_MES_PRIORITY_LEVEL_MEDIUM:
+		return AMD_PRIORITY_LEVEL_MEDIUM;
+	case AMDGPU_MES_PRIORITY_LEVEL_HIGH:
+		return AMD_PRIORITY_LEVEL_HIGH;
+	case AMDGPU_MES_PRIORITY_LEVEL_REALTIME:
+		return AMD_PRIORITY_LEVEL_REALTIME;
+	}
+}
+
 static int mes_v11_0_add_hw_queue(struct amdgpu_mes *mes,
 				  struct mes_add_queue_input *input)
 {
@@ -310,9 +327,9 @@ static int mes_v11_0_add_hw_queue(struct amdgpu_mes *mes,
 	mes_add_queue_pkt.gang_quantum = input->gang_quantum;
 	mes_add_queue_pkt.gang_context_addr = input->gang_context_addr;
 	mes_add_queue_pkt.inprocess_gang_priority =
-		input->inprocess_gang_priority;
+		convert_to_mes_priority_level(input->inprocess_gang_priority);
 	mes_add_queue_pkt.gang_global_priority_level =
-		input->gang_global_priority_level;
+		convert_to_mes_priority_level(input->gang_global_priority_level);
 	mes_add_queue_pkt.doorbell_offset = input->doorbell_offset;
 	mes_add_queue_pkt.mqd_addr = input->mqd_addr;
 
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 3/13
#4 lore raw

Re: [PATCH 03/13] drm/amdgpu/mes11: add conversion for priority levels

Do you expect priority level in MES11 12 and probably 13 too ? If they are same then we should be using the same conversion function for all versions of MES. For now its fine.

Quoted 49 lines · Alex Deucher

Convert driver priority levels to MES11 priority levels. At the moment they are the same, but they may not always be.

---
  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 21 +++++++++++++++++++--
  1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +19 -2
index 06b51867c9aac..b39a538cfc4e4 100644
@@ -287,6 +287,23 @@ static int convert_to_mes_queue_type(int queue_type)
  	return -1;
  }
 
+static int convert_to_mes_priority_level(int priority_level)
+{
+	switch (priority_level) {
+	case AMDGPU_MES_PRIORITY_LEVEL_LOW:
+		return AMD_PRIORITY_LEVEL_LOW;
+	case AMDGPU_MES_PRIORITY_LEVEL_NORMAL:
+	default:
+		return AMD_PRIORITY_LEVEL_NORMAL;
+	case AMDGPU_MES_PRIORITY_LEVEL_MEDIUM:
+		return AMD_PRIORITY_LEVEL_MEDIUM;
+	case AMDGPU_MES_PRIORITY_LEVEL_HIGH:
+		return AMD_PRIORITY_LEVEL_HIGH;
+	case AMDGPU_MES_PRIORITY_LEVEL_REALTIME:
+		return AMD_PRIORITY_LEVEL_REALTIME;
+	}
+}
+
  static int mes_v11_0_add_hw_queue(struct amdgpu_mes *mes,
  				  struct mes_add_queue_input *input)
  {
@@ -310,9 +327,9 @@ static int mes_v11_0_add_hw_queue(struct amdgpu_mes *mes,
  	mes_add_queue_pkt.gang_quantum = input->gang_quantum;
  	mes_add_queue_pkt.gang_context_addr = input->gang_context_addr;
  	mes_add_queue_pkt.inprocess_gang_priority =
-		input->inprocess_gang_priority;
+		convert_to_mes_priority_level(input->inprocess_gang_priority);
  	mes_add_queue_pkt.gang_global_priority_level =
-		input->gang_global_priority_level;
+		convert_to_mes_priority_level(input->gang_global_priority_level);
  	mes_add_queue_pkt.doorbell_offset = input->doorbell_offset;
  	mes_add_queue_pkt.mqd_addr = input->mqd_addr;
 
author maintainer
#5 lore raw

PATCH 4/13 drm/amdgpu/mes12: add conversion for priority levels

In reply to Alex Deucher

Convert driver priority levels to MES11 priority levels. At the moment they are the same, but they may not always be.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +19 -2
index 8892858cfd9ae..852b8f2a4e387 100644
@@ -274,6 +274,23 @@ static int convert_to_mes_queue_type(int queue_type)
 	return -1;
 }
 
+static int convert_to_mes_priority_level(int priority_level)
+{
+	switch (priority_level) {
+	case AMDGPU_MES_PRIORITY_LEVEL_LOW:
+		return AMD_PRIORITY_LEVEL_LOW;
+	case AMDGPU_MES_PRIORITY_LEVEL_NORMAL:
+	default:
+		return AMD_PRIORITY_LEVEL_NORMAL;
+	case AMDGPU_MES_PRIORITY_LEVEL_MEDIUM:
+		return AMD_PRIORITY_LEVEL_MEDIUM;
+	case AMDGPU_MES_PRIORITY_LEVEL_HIGH:
+		return AMD_PRIORITY_LEVEL_HIGH;
+	case AMDGPU_MES_PRIORITY_LEVEL_REALTIME:
+		return AMD_PRIORITY_LEVEL_REALTIME;
+	}
+}
+
 static int mes_v12_0_add_hw_queue(struct amdgpu_mes *mes,
 				  struct mes_add_queue_input *input)
 {
@@ -297,9 +314,9 @@ static int mes_v12_0_add_hw_queue(struct amdgpu_mes *mes,
 	mes_add_queue_pkt.gang_quantum = input->gang_quantum;
 	mes_add_queue_pkt.gang_context_addr = input->gang_context_addr;
 	mes_add_queue_pkt.inprocess_gang_priority =
-		input->inprocess_gang_priority;
+		convert_to_mes_priority_level(input->inprocess_gang_priority);
 	mes_add_queue_pkt.gang_global_priority_level =
-		input->gang_global_priority_level;
+		convert_to_mes_priority_level(input->gang_global_priority_level);
 	mes_add_queue_pkt.doorbell_offset = input->doorbell_offset;
 	mes_add_queue_pkt.mqd_addr = input->mqd_addr;
 
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 4/13
#6 lore raw

Re: [PATCH 04/13] drm/amdgpu/mes12: add conversion for priority levels

Same comment here as MES11 that once we have confirmation we might plan to use same function for all.

Quoted 49 lines · Alex Deucher

Convert driver priority levels to MES11 priority levels. At the moment they are the same, but they may not always be.

---
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 21 +++++++++++++++++++--
  1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +19 -2
index 8892858cfd9ae..852b8f2a4e387 100644
@@ -274,6 +274,23 @@ static int convert_to_mes_queue_type(int queue_type)
  	return -1;
  }
 
+static int convert_to_mes_priority_level(int priority_level)
+{
+	switch (priority_level) {
+	case AMDGPU_MES_PRIORITY_LEVEL_LOW:
+		return AMD_PRIORITY_LEVEL_LOW;
+	case AMDGPU_MES_PRIORITY_LEVEL_NORMAL:
+	default:
+		return AMD_PRIORITY_LEVEL_NORMAL;
+	case AMDGPU_MES_PRIORITY_LEVEL_MEDIUM:
+		return AMD_PRIORITY_LEVEL_MEDIUM;
+	case AMDGPU_MES_PRIORITY_LEVEL_HIGH:
+		return AMD_PRIORITY_LEVEL_HIGH;
+	case AMDGPU_MES_PRIORITY_LEVEL_REALTIME:
+		return AMD_PRIORITY_LEVEL_REALTIME;
+	}
+}
+
  static int mes_v12_0_add_hw_queue(struct amdgpu_mes *mes,
  				  struct mes_add_queue_input *input)
  {
@@ -297,9 +314,9 @@ static int mes_v12_0_add_hw_queue(struct amdgpu_mes *mes,
  	mes_add_queue_pkt.gang_quantum = input->gang_quantum;
  	mes_add_queue_pkt.gang_context_addr = input->gang_context_addr;
  	mes_add_queue_pkt.inprocess_gang_priority =
-		input->inprocess_gang_priority;
+		convert_to_mes_priority_level(input->inprocess_gang_priority);
  	mes_add_queue_pkt.gang_global_priority_level =
-		input->gang_global_priority_level;
+		convert_to_mes_priority_level(input->gang_global_priority_level);
  	mes_add_queue_pkt.doorbell_offset = input->doorbell_offset;
  	mes_add_queue_pkt.mqd_addr = input->mqd_addr;
 
author maintainer
#7 lore raw

PATCH 5/13 drm/amdgpu/user: add priorty to user queue structure

In reply to Alex Deucher

So we can track this when we create user queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1 -0
index fd0542f60433b..e0bc45e36dbc5 100644
@@ -56,6 +56,7 @@ struct amdgpu_usermode_queue {
 	struct xarray		fence_drv_xa;
 	struct amdgpu_userq_fence_driver *fence_drv;
 	struct dma_fence	*last_fence;
+	int			priority;
 };
 
 struct amdgpu_userq_funcs {
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 5/13
#8 lore raw

Re: [PATCH 05/13] drm/amdgpu/user: add priorty to user queue structure

Quoted 19 lines · Alex Deucher

So we can track this when we create user queues.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.h +1 -0
index fd0542f60433b..e0bc45e36dbc5 100644
@@ -56,6 +56,7 @@ struct amdgpu_usermode_queue {
  	struct xarray		fence_drv_xa;
  	struct amdgpu_userq_fence_driver *fence_drv;
  	struct dma_fence	*last_fence;
+	int			priority;
  };
 
  struct amdgpu_userq_funcs {
author maintainer
#9 lore raw

PATCH 6/13 drm/amdgpu/userq/mes: handle user queue priority

In reply to Alex Deucher

Handle the queue priority set by the user.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +16 -1
index e3c3fc160b799..f406a9a29bda5 100644
@@ -97,6 +97,21 @@ mes_userq_create_wptr_mapping(struct amdgpu_userq_mgr *uq_mgr,
 	return 0;
 }
 
+static int convert_to_mes_priority(int priority)
+{
+	switch (priority) {
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_LOW:
+	default:
+		return AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW:
+		return AMDGPU_MES_PRIORITY_LEVEL_LOW;
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH:
+		return AMDGPU_MES_PRIORITY_LEVEL_MEDIUM;
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH:
+		return AMDGPU_MES_PRIORITY_LEVEL_HIGH;
+	}
+}
+
 static int mes_userq_map(struct amdgpu_userq_mgr *uq_mgr,
 			 struct amdgpu_usermode_queue *queue)
 {
@@ -122,7 +137,7 @@ static int mes_userq_map(struct amdgpu_userq_mgr *uq_mgr,
 	queue_input.process_context_addr = ctx->gpu_addr;
 	queue_input.gang_context_addr = ctx->gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
 	queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
-	queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+	queue_input.gang_global_priority_level = convert_to_mes_priority(queue->priority);
 
 	queue_input.process_id = queue->vm->pasid;
 	queue_input.queue_type = queue->queue_type;
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 6/13
#10 lore raw

Re: [PATCH 06/13] drm/amdgpu/userq/mes: handle user queue priority

Quoted 42 lines · Alex Deucher

Handle the queue priority set by the user.

---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 17 ++++++++++++++++-
  1 file changed, 16 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +16 -1
index e3c3fc160b799..f406a9a29bda5 100644
@@ -97,6 +97,21 @@ mes_userq_create_wptr_mapping(struct amdgpu_userq_mgr *uq_mgr,
  	return 0;
  }
 
+static int convert_to_mes_priority(int priority)
+{
+	switch (priority) {
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_LOW:
+	default:
+		return AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW:
+		return AMDGPU_MES_PRIORITY_LEVEL_LOW;
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH:
+		return AMDGPU_MES_PRIORITY_LEVEL_MEDIUM;
+	case AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH:
+		return AMDGPU_MES_PRIORITY_LEVEL_HIGH;
+	}
+}
+
  static int mes_userq_map(struct amdgpu_userq_mgr *uq_mgr,
  			 struct amdgpu_usermode_queue *queue)
  {
@@ -122,7 +137,7 @@ static int mes_userq_map(struct amdgpu_userq_mgr *uq_mgr,
  	queue_input.process_context_addr = ctx->gpu_addr;
  	queue_input.gang_context_addr = ctx->gpu_addr + AMDGPU_USERQ_PROC_CTX_SZ;
  	queue_input.inprocess_gang_priority = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
-	queue_input.gang_global_priority_level = AMDGPU_MES_PRIORITY_LEVEL_NORMAL;
+	queue_input.gang_global_priority_level = convert_to_mes_priority(queue->priority);
 
  	queue_input.process_id = queue->vm->pasid;
  	queue_input.queue_type = queue->queue_type;
author maintainer
#11 lore raw

PATCH 7/13 drm/amdgpu/userq: enable support for queue priorities

In reply to Alex Deucher

Enable users to create queues at different priority levels. The highest level is restricted to drm master.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 26 ++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +25 -1
index 57a4ef64e0b8b..b8b13b6ab4631 100644
@@ -22,6 +22,7 @@
  *
  */
 
+#include <drm/drm_auth.h>
 #include <drm/drm_exec.h>
 #include "amdgpu.h"
 #include "amdgpu_vm.h"
@@ -260,6 +261,21 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
 	return r;
 }
 
+static int amdgpu_userq_priority_permit(struct drm_file *filp,
+					int priority)
+{
+	if (priority < AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH)
+		return 0;
+
+	if (capable(CAP_SYS_NICE))
+		return 0;
+
+	if (drm_is_current_master(filp))
+		return 0;
+
+	return -EACCES;
+}
+
 static int
 amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 {
@@ -271,6 +287,9 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	struct amdgpu_db_info db_info;
 	uint64_t index;
 	int qid, r = 0;
+	int priority =
+		(args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK) >>
+		AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT;
 
 	/* Usermode queues are only supported for GFX IP as of now */
 	if (args->in.ip_type != AMDGPU_HW_IP_GFX &&
@@ -280,6 +299,10 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 		return -EINVAL;
 	}
 
+	r = amdgpu_userq_priority_permit(filp, priority);
+	if (r)
+		return r;
+
 	/*
 	 * There could be a situation that we are creating a new queue while
 	 * the other queues under this UQ_mgr are suspended. So if there is any
@@ -305,6 +328,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	queue->doorbell_handle = args->in.doorbell_handle;
 	queue->queue_type = args->in.ip_type;
 	queue->vm = &fpriv->vm;
+	queue->priority = priority;
 
 	db_info.queue_type = queue->queue_type;
 	db_info.doorbell_handle = queue->doorbell_handle;
@@ -377,7 +401,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
 	switch (args->in.op) {
 	case AMDGPU_USERQ_OP_CREATE:
-		if (args->in.flags)
+		if (args->in.flags & ~AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK)
 			return -EINVAL;
 		r = amdgpu_userqueue_create(filp, args);
 		if (r)
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 7/13
#12 lore raw

Re: [PATCH 07/13] drm/amdgpu/userq: enable support for queue priorities

A small comment otherwise it looks great.

Quoted 81 lines · Alex Deucher

Enable users to create queues at different priority levels. The highest level is restricted to drm master.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 26 ++++++++++++++++++-
  1 file changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +3 -0
index 57a4ef64e0b8b..b8b13b6ab4631 100644
@@ -22,6 +22,7 @@
   *
   */
 
+#include <drm/drm_auth.h>
  #include <drm/drm_exec.h>
  #include "amdgpu.h"
  #include "amdgpu_vm.h"
@@ -260,6 +261,21 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
  	return r;
  }
 
+static int amdgpu_userq_priority_permit(struct drm_file *filp,
+					int priority)

Do we want this value of priority to be unsigned as we only want values >=0.

drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +22 -1
+{
+	if (priority < AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH)
+		return 0;
+
+	if (capable(CAP_SYS_NICE))
+		return 0;
+
+	if (drm_is_current_master(filp))
+		return 0;
+
+	return -EACCES;
+}
+
  static int
  amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  {
@@ -271,6 +287,9 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	struct amdgpu_db_info db_info;
  	uint64_t index;
  	int qid, r = 0;
+	int priority =
+		(args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK) >>
+		AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT;
 
  	/* Usermode queues are only supported for GFX IP as of now */
  	if (args->in.ip_type != AMDGPU_HW_IP_GFX &&
@@ -280,6 +299,10 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  		return -EINVAL;
  	}
 
+	r = amdgpu_userq_priority_permit(filp, priority);
+	if (r)
+		return r;
+
  	/*
  	 * There could be a situation that we are creating a new queue while
  	 * the other queues under this UQ_mgr are suspended. So if there is any
@@ -305,6 +328,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	queue->doorbell_handle = args->in.doorbell_handle;
  	queue->queue_type = args->in.ip_type;
  	queue->vm = &fpriv->vm;
+	queue->priority = priority;
 
  	db_info.queue_type = queue->queue_type;
  	db_info.doorbell_handle = queue->doorbell_handle;
@@ -377,7 +401,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
  	switch (args->in.op) {
  	case AMDGPU_USERQ_OP_CREATE:
-		if (args->in.flags)
+		if (args->in.flags & ~AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK)
  			return -EINVAL;
  		r = amdgpu_userqueue_create(filp, args);
  		if (r)
#13 lore raw

Re: [PATCH 07/13] drm/amdgpu/userq: enable support for queue priorities

Quoted 29 lines · Sunil

A small comment otherwise it looks great.

Quoted 24 lines · Alex Deucher

Enable users to create queues at different priority levels. The highest level is restricted to drm master.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 26 ++++++++++++++++++-
  1 file changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +1 -0
index 57a4ef64e0b8b..b8b13b6ab4631 100644
@@ -22,6 +22,7 @@
   *
   */
 
+#include <drm/drm_auth.h>
  #include <drm/drm_exec.h>
  #include "amdgpu.h"
  #include "amdgpu_vm.h"
@@ -260,6 +261,21 @@ amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
      return r;
  }
 
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -0
+static int amdgpu_userq_priority_permit(struct drm_file *filp,
+                                     int priority)

Do we want this value of priority to be unsigned as we only want values >=0.

The values we pass in will always be >=0.

Alex

Quoted 54 lines
Quoted 54 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +22 -1
+{
+     if (priority < AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH)
+             return 0;
+
+     if (capable(CAP_SYS_NICE))
+             return 0;
+
+     if (drm_is_current_master(filp))
+             return 0;
+
+     return -EACCES;
+}
+
  static int
  amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  {
@@ -271,6 +287,9 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
      struct amdgpu_db_info db_info;
      uint64_t index;
      int qid, r = 0;
+     int priority =
+             (args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK) >>
+             AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_SHIFT;
 
      /* Usermode queues are only supported for GFX IP as of now */
      if (args->in.ip_type != AMDGPU_HW_IP_GFX &&
@@ -280,6 +299,10 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
              return -EINVAL;
      }
 
+     r = amdgpu_userq_priority_permit(filp, priority);
+     if (r)
+             return r;
+
      /*
       * There could be a situation that we are creating a new queue while
       * the other queues under this UQ_mgr are suspended. So if there is any
@@ -305,6 +328,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
      queue->doorbell_handle = args->in.doorbell_handle;
      queue->queue_type = args->in.ip_type;
      queue->vm = &fpriv->vm;
+     queue->priority = priority;
 
      db_info.queue_type = queue->queue_type;
      db_info.doorbell_handle = queue->doorbell_handle;
@@ -377,7 +401,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
      switch (args->in.op) {
      case AMDGPU_USERQ_OP_CREATE:
-             if (args->in.flags)
+             if (args->in.flags & ~AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK)
                      return -EINVAL;
              r = amdgpu_userqueue_create(filp, args);
              if (r)
author maintainer
#14 lore raw

PATCH 8/13 drm/amdgpu/userq: add UAPI for setting up secure queues

In reply to Alex Deucher

If the queues needs to access TMZ surfaces, it must be set up as secure.

---
 include/uapi/drm/amdgpu_drm.h | 2 ++
 1 file changed, 2 insertions(+)
include/uapi/drm/amdgpu_drm.h +2 -0
index 8719754c777b4..0ca4b3b961eb3 100644
@@ -336,6 +336,8 @@ union drm_amdgpu_ctx {
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW 1
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH 2
 #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3 /* admin only */
+/* for queues that need access to protected content */
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE  (1 << 2)
 
 /*
  * This structure is a container to pass input configuration
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 8/13
#15 lore raw

Re: [PATCH 08/13] drm/amdgpu/userq: add UAPI for setting up secure queues

Quoted 21 lines · Alex Deucher

If the queues needs to access TMZ surfaces, it must be set up as secure.

---
  include/uapi/drm/amdgpu_drm.h | 2 ++
  1 file changed, 2 insertions(+)
include/uapi/drm/amdgpu_drm.h +2 -0
index 8719754c777b4..0ca4b3b961eb3 100644
@@ -336,6 +336,8 @@ union drm_amdgpu_ctx {
  #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_LOW 1
  #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_NORMAL_HIGH 2
  #define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_HIGH 3 /* admin only */
+/* for queues that need access to protected content */
+#define AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE  (1 << 2)
 
  /*
   * This structure is a container to pass input configuration
author maintainer
#16 lore raw

PATCH 9/13 drm/amdgpu: add tmz queue parameter to mqd props

In reply to Alex Deucher

Use this to track the whether we want TMZ for queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index b818ad63dc84f..364a65524cfdb 100644
@@ -835,6 +835,7 @@ struct amdgpu_mqd_prop {
 	uint64_t gds_bkup_addr;
 	uint64_t csa_addr;
 	uint64_t fence_address;
+	bool tmz_queue;
 };
 
 struct amdgpu_mqd {
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 9/13
#17 lore raw

Re: [PATCH 09/13] drm/amdgpu: add tmz queue parameter to mqd props

Quoted 19 lines · Alex Deucher

Use this to track the whether we want TMZ for queues.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index b818ad63dc84f..364a65524cfdb 100644
@@ -835,6 +835,7 @@ struct amdgpu_mqd_prop {
  	uint64_t gds_bkup_addr;
  	uint64_t csa_addr;
  	uint64_t fence_address;
+	bool tmz_queue;
  };
 
  struct amdgpu_mqd {
author maintainer
#18 lore raw

PATCH 10/13 drm/amdgpu/gfx11: add support for TMZ queues to mqd_init

In reply to Alex Deucher

Set up TMZ for queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -0
index 91d29f482c3ca..b204d0e6e816d 100644
@@ -4114,6 +4114,8 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 #ifdef __BIG_ENDIAN
 	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, BUF_SWAP, 1);
 #endif
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, TMZ_MATCH, 1);
 	mqd->cp_gfx_hqd_cntl = tmp;
 
 	/* set up cp_doorbell_control */
@@ -4268,6 +4270,8 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 			    prop->allow_tunneling);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TMZ, 1);
 	mqd->cp_hqd_pq_control = tmp;
 
 	/* set the wb address whether it's enabled or not */
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 10/13
#19 lore raw

Re: [PATCH 10/13] drm/amdgpu/gfx11: add support for TMZ queues to mqd_init

Quoted 29 lines · Alex Deucher

Set up TMZ for queues.

---
  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4 -0
index 91d29f482c3ca..b204d0e6e816d 100644
@@ -4114,6 +4114,8 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
  #ifdef __BIG_ENDIAN
  	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, BUF_SWAP, 1);
  #endif
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, TMZ_MATCH, 1);
  	mqd->cp_gfx_hqd_cntl = tmp;
 
  	/* set up cp_doorbell_control */
@@ -4268,6 +4270,8 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
  			    prop->allow_tunneling);
  	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
  	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TMZ, 1);
  	mqd->cp_hqd_pq_control = tmp;
 
  	/* set the wb address whether it's enabled or not */
author maintainer
#20 lore raw

PATCH 11/13 drm/amdgpu/gfx12: add support for TMZ queues to mqd_init

In reply to Alex Deucher

Set up TMZ for queues.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4 -0
index 2474006b1a340..da67f27d65a33 100644
@@ -3013,6 +3013,8 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 #ifdef __BIG_ENDIAN
 	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, BUF_SWAP, 1);
 #endif
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, TMZ_MATCH, 1);
 	mqd->cp_gfx_hqd_cntl = tmp;
 
 	/* set up cp_doorbell_control */
@@ -3164,6 +3166,8 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TUNNEL_DISPATCH, 0);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
 	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TMZ, 1);
 	mqd->cp_hqd_pq_control = tmp;
 
 	/* set the wb address whether it's enabled or not */
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 11/13
#21 lore raw

Re: [PATCH 11/13] drm/amdgpu/gfx12: add support for TMZ queues to mqd_init

Quoted 29 lines · Alex Deucher

Set up TMZ for queues.

---
  drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4 -0
index 2474006b1a340..da67f27d65a33 100644
@@ -3013,6 +3013,8 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
  #ifdef __BIG_ENDIAN
  	tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, BUF_SWAP, 1);
  #endif
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_GFX_HQD_CNTL, TMZ_MATCH, 1);
  	mqd->cp_gfx_hqd_cntl = tmp;
 
  	/* set up cp_doorbell_control */
@@ -3164,6 +3166,8 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
  	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TUNNEL_DISPATCH, 0);
  	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, PRIV_STATE, 1);
  	tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, KMD_QUEUE, 1);
+	if (prop->tmz_queue)
+		tmp = REG_SET_FIELD(tmp, CP_HQD_PQ_CONTROL, TMZ, 1);
  	mqd->cp_hqd_pq_control = tmp;
 
  	/* set the wb address whether it's enabled or not */
author maintainer
#22 lore raw

PATCH 12/13 drm/amdgpu/userq/mes: pass the secure flag to mqd init

In reply to Alex Deucher

So that we initialize the MQD as a secure queue.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +4 -0
index f406a9a29bda5..e175f05bba6a9 100644
@@ -267,6 +267,8 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 		userq_props->hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_NORMAL;
 		userq_props->hqd_queue_priority = AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM;
 		userq_props->hqd_active = false;
+		userq_props->tmz_queue =
+			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
 		kfree(compute_mqd);
 	} else if (queue->queue_type == AMDGPU_HW_IP_GFX) {
 		struct drm_amdgpu_userq_mqd_gfx11 *mqd_gfx_v11;
@@ -286,6 +288,8 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
 		userq_props->shadow_addr = mqd_gfx_v11->shadow_va;
 		userq_props->csa_addr = mqd_gfx_v11->csa_va;
+		userq_props->tmz_queue =
+			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
 		kfree(mqd_gfx_v11);
 	} else if (queue->queue_type == AMDGPU_HW_IP_DMA) {
 		struct drm_amdgpu_userq_mqd_sdma_gfx11 *mqd_sdma_v11;
Signature · 1 line
2.49.0
Reviewed-by Sunil Khatri on v1 12/13
#23 lore raw

Re: [PATCH 12/13] drm/amdgpu/userq/mes: pass the secure flag to mqd init

Quoted 29 lines · Alex Deucher

So that we initialize the MQD as a secure queue.

---
  drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +4 -0
index f406a9a29bda5..e175f05bba6a9 100644
@@ -267,6 +267,8 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
  		userq_props->hqd_pipe_priority = AMDGPU_GFX_PIPE_PRIO_NORMAL;
  		userq_props->hqd_queue_priority = AMDGPU_GFX_QUEUE_PRIORITY_MINIMUM;
  		userq_props->hqd_active = false;
+		userq_props->tmz_queue =
+			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
  		kfree(compute_mqd);
  	} else if (queue->queue_type == AMDGPU_HW_IP_GFX) {
  		struct drm_amdgpu_userq_mqd_gfx11 *mqd_gfx_v11;
@@ -286,6 +288,8 @@ static int mes_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
 
  		userq_props->shadow_addr = mqd_gfx_v11->shadow_va;
  		userq_props->csa_addr = mqd_gfx_v11->csa_va;
+		userq_props->tmz_queue =
+			mqd_user->flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
  		kfree(mqd_gfx_v11);
  	} else if (queue->queue_type == AMDGPU_HW_IP_DMA) {
  		struct drm_amdgpu_userq_mqd_sdma_gfx11 *mqd_sdma_v11;
author maintainer
#24 lore raw

PATCH 13/13 drm/amdgpu/userq: enable support for secure queues

In reply to Alex Deucher

Enable users to create secure GFX/compute queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10 -1
index b8b13b6ab4631..cd279f8164158 100644
@@ -303,6 +303,14 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
 	if (r)
 		return r;
 
+	if ((args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE) &&
+	    (args->in.ip_type != AMDGPU_HW_IP_GFX) &&
+	    (args->in.ip_type != AMDGPU_HW_IP_COMPUTE) &&
+	    !amdgpu_is_tmz(adev)) {
+		drm_err(adev_to_drm(adev), "Secure only supported on GFX/Compute queues\n");
+		return -EINVAL;
+	}
+
 	/*
 	 * There could be a situation that we are creating a new queue while
 	 * the other queues under this UQ_mgr are suspended. So if there is any
@@ -401,7 +409,8 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
 	switch (args->in.op) {
 	case AMDGPU_USERQ_OP_CREATE:
-		if (args->in.flags & ~AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK)
+		if (args->in.flags & ~(AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK |
+				       AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE))
 			return -EINVAL;
 		r = amdgpu_userqueue_create(filp, args);
 		if (r)
Signature · 1 line
2.49.0
#25 lore raw

RE: [PATCH 13/13] drm/amdgpu/userq: enable support for secure queues

[AMD Official Use Only - AMD Internal Distribution Only]

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, April 11, 2025 2:54 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 13/13] drm/amdgpu/userq: enable support for secure queues

Enable users to create secure GFX/compute queues.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +8 -0
index b8b13b6ab4631..cd279f8164158 100644
@@ -303,6 +303,14 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
        if (r)
                return r;
 
+       if ((args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE) &&
+           (args->in.ip_type != AMDGPU_HW_IP_GFX) &&
+           (args->in.ip_type != AMDGPU_HW_IP_COMPUTE) &&
+           !amdgpu_is_tmz(adev)) {
+               drm_err(adev_to_drm(adev), "Secure only supported on GFX/Compute queues\n");
+               return -EINVAL;
+       }
+
        /*
         * There could be a situation that we are creating a new queue while
         * the other queues under this UQ_mgr are suspended. So if there is any @@ -401,7 +409,8 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
        switch (args->in.op) {
        case AMDGPU_USERQ_OP_CREATE:
-               if (args->in.flags & ~AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK)
+               if (args->in.flags & ~(AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK |
+                                      AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE))
                        return -EINVAL;
                r = amdgpu_userqueue_create(filp, args);
                if (r)

--
2.49.0

Reviewed-by Sunil Khatri on v1 13/13
#26 lore raw

Re: [PATCH 13/13] drm/amdgpu/userq: enable support for secure queues

In reply to Alex Deucher
Quoted 36 lines · Alex Deucher

Enable users to create secure GFX/compute queues.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +10 -1
index b8b13b6ab4631..cd279f8164158 100644
@@ -303,6 +303,14 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
  	if (r)
  		return r;
 
+	if ((args->in.flags & AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE) &&
+	    (args->in.ip_type != AMDGPU_HW_IP_GFX) &&
+	    (args->in.ip_type != AMDGPU_HW_IP_COMPUTE) &&
+	    !amdgpu_is_tmz(adev)) {
+		drm_err(adev_to_drm(adev), "Secure only supported on GFX/Compute queues\n");
+		return -EINVAL;
+	}
+
  	/*
  	 * There could be a situation that we are creating a new queue while
  	 * the other queues under this UQ_mgr are suspended. So if there is any
@@ -401,7 +409,8 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
  	switch (args->in.op) {
  	case AMDGPU_USERQ_OP_CREATE:
-		if (args->in.flags & ~AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK)
+		if (args->in.flags & ~(AMDGPU_USERQ_CREATE_FLAGS_QUEUE_PRIORITY_MASK |
+				       AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE))
  			return -EINVAL;
  		r = amdgpu_userqueue_create(filp, args);
  		if (r)
Reviewed-by Sunil Khatri on v1 1/13
#27 lore raw
In reply to Alex Deucher
Quoted 46 lines · Alex Deucher

Reuse the _pad field for flags.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 4 ++--
  include/uapi/drm/amdgpu_drm.h                 | 5 ++++-
  2 files changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +2 -2
index 50317fbd40e0e..57a4ef64e0b8b 100644
@@ -377,7 +377,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
 
  	switch (args->in.op) {
  	case AMDGPU_USERQ_OP_CREATE:
-		if (args->in._pad)
+		if (args->in.flags)
  			return -EINVAL;
  		r = amdgpu_userqueue_create(filp, args);
  		if (r)
@@ -388,7 +388,7 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data,
  		if (args->in.ip_type ||
  		    args->in.doorbell_handle ||
  		    args->in.doorbell_offset ||
-		    args->in._pad ||
+		    args->in.flags ||
  		    args->in.queue_va ||
  		    args->in.queue_size ||
  		    args->in.rptr_va ||
include/uapi/drm/amdgpu_drm.h +4 -1
index ef97c0d78b8a0..1a451907184cc 100644
@@ -355,7 +355,10 @@ struct drm_amdgpu_userq_in {
  	 * and doorbell_offset in the doorbell bo.
  	 */
  	__u32   doorbell_offset;
-	__u32 _pad;
+	/**
+	 * @flags: flags used for queue parameters
+	 */
+	__u32 flags;
  	/**
  	 * @queue_va: Virtual address of the GPU memory which holds the queue
  	 * object. The queue holds the workload packets.