Skip to content

Commit c59c961

Browse files
committed
Merge branch 'drm-fixes' of git://people.freedesktop.org/~airlied/linux
Pull drm fixes from Dave Airlie: "This feels larger than I'd like but its for three reasons. a) amdkfd finalising the API more, this is a new feature introduced last merge window, and I'd prefer to make the tweaks to the API before it first gets into a stable release. b) radeon regression required splitting an internal API to fix properly, so it just changed a few more lines c) vmwgfx fix changes a lock from a mutex->spin lock, this is fallout from the new sleep checking. Otherwise there is just some tda998x fixes" * 'drm-fixes' of git://people.freedesktop.org/~airlied/linux: drm/radeon: Remove rdev->gart.pages_addr array drm/radeon: Restore GART table contents after pinning it in VRAM v3 drm/radeon: Split off gart_get_page_entry ASIC hook from set_page_entry drm/amdkfd: Fix bug in call to init_pipelines() drm/amdkfd: Fix bug in pipelines initialization drm/radeon: Don't increment pipe_id in kgd_init_pipeline drm/i2c: tda998x: set the CEC I2C address based on the slave I2C address drm/vmwgfx: Replace the hw mutex with a hw spinlock drm/amdkfd: Allow user to limit only queues per device drm/amdkfd: PQM handle queue creation fault drm: tda998x: Fix EDID read timeout on HDMI connect drm: tda998x: Protect the page register
2 parents 59343cd + 5159571 commit c59c961

29 files changed

Lines changed: 315 additions & 188 deletions

‎drivers/gpu/drm/amd/amdkfd/kfd_device.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/slab.h>
2727
#include "kfd_priv.h"
2828
#include "kfd_device_queue_manager.h"
29+
#include "kfd_pm4_headers.h"
2930

3031
#define MQD_SIZE_ALIGNED 768
3132

@@ -169,9 +170,8 @@ bool kgd2kfd_device_init(struct kfd_dev *kfd,
169170
kfd->shared_resources = *gpu_resources;
170171

171172
/* calculate max size of mqds needed for queues */
172-
size = max_num_of_processes *
173-
max_num_of_queues_per_process *
174-
kfd->device_info->mqd_size_aligned;
173+
size = max_num_of_queues_per_device *
174+
kfd->device_info->mqd_size_aligned;
175175

176176
/* add another 512KB for all other allocations on gart */
177177
size += 512 * 1024;

‎drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c‎

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,13 @@ static int create_queue_nocpsch(struct device_queue_manager *dqm,
183183

184184
mutex_lock(&dqm->lock);
185185

186+
if (dqm->total_queue_count >= max_num_of_queues_per_device) {
187+
pr_warn("amdkfd: Can't create new usermode queue because %d queues were already created\n",
188+
dqm->total_queue_count);
189+
mutex_unlock(&dqm->lock);
190+
return -EPERM;
191+
}
192+
186193
if (list_empty(&qpd->queues_list)) {
187194
retval = allocate_vmid(dqm, qpd, q);
188195
if (retval != 0) {
@@ -207,6 +214,14 @@ static int create_queue_nocpsch(struct device_queue_manager *dqm,
207214
list_add(&q->list, &qpd->queues_list);
208215
dqm->queue_count++;
209216

217+
/*
218+
* Unconditionally increment this counter, regardless of the queue's
219+
* type or whether the queue is active.
220+
*/
221+
dqm->total_queue_count++;
222+
pr_debug("Total of %d queues are accountable so far\n",
223+
dqm->total_queue_count);
224+
210225
mutex_unlock(&dqm->lock);
211226
return 0;
212227
}
@@ -326,6 +341,15 @@ static int destroy_queue_nocpsch(struct device_queue_manager *dqm,
326341
if (list_empty(&qpd->queues_list))
327342
deallocate_vmid(dqm, qpd, q);
328343
dqm->queue_count--;
344+
345+
/*
346+
* Unconditionally decrement this counter, regardless of the queue's
347+
* type
348+
*/
349+
dqm->total_queue_count--;
350+
pr_debug("Total of %d queues are accountable so far\n",
351+
dqm->total_queue_count);
352+
329353
out:
330354
mutex_unlock(&dqm->lock);
331355
return retval;
@@ -541,10 +565,14 @@ static int init_pipelines(struct device_queue_manager *dqm,
541565

542566
for (i = 0; i < pipes_num; i++) {
543567
inx = i + first_pipe;
568+
/*
569+
* HPD buffer on GTT is allocated by amdkfd, no need to waste
570+
* space in GTT for pipelines we don't initialize
571+
*/
544572
pipe_hpd_addr = dqm->pipelines_addr + i * CIK_HPD_EOP_BYTES;
545573
pr_debug("kfd: pipeline address %llX\n", pipe_hpd_addr);
546574
/* = log2(bytes/4)-1 */
547-
kfd2kgd->init_pipeline(dqm->dev->kgd, i,
575+
kfd2kgd->init_pipeline(dqm->dev->kgd, inx,
548576
CIK_HPD_EOP_BYTES_LOG2 - 3, pipe_hpd_addr);
549577
}
550578

@@ -560,7 +588,7 @@ static int init_scheduler(struct device_queue_manager *dqm)
560588

561589
pr_debug("kfd: In %s\n", __func__);
562590

563-
retval = init_pipelines(dqm, get_pipes_num(dqm), KFD_DQM_FIRST_PIPE);
591+
retval = init_pipelines(dqm, get_pipes_num(dqm), get_first_pipe(dqm));
564592
if (retval != 0)
565593
return retval;
566594

@@ -752,6 +780,21 @@ static int create_kernel_queue_cpsch(struct device_queue_manager *dqm,
752780
pr_debug("kfd: In func %s\n", __func__);
753781

754782
mutex_lock(&dqm->lock);
783+
if (dqm->total_queue_count >= max_num_of_queues_per_device) {
784+
pr_warn("amdkfd: Can't create new kernel queue because %d queues were already created\n",
785+
dqm->total_queue_count);
786+
mutex_unlock(&dqm->lock);
787+
return -EPERM;
788+
}
789+
790+
/*
791+
* Unconditionally increment this counter, regardless of the queue's
792+
* type or whether the queue is active.
793+
*/
794+
dqm->total_queue_count++;
795+
pr_debug("Total of %d queues are accountable so far\n",
796+
dqm->total_queue_count);
797+
755798
list_add(&kq->list, &qpd->priv_queue_list);
756799
dqm->queue_count++;
757800
qpd->is_debug = true;
@@ -775,6 +818,13 @@ static void destroy_kernel_queue_cpsch(struct device_queue_manager *dqm,
775818
dqm->queue_count--;
776819
qpd->is_debug = false;
777820
execute_queues_cpsch(dqm, false);
821+
/*
822+
* Unconditionally decrement this counter, regardless of the queue's
823+
* type.
824+
*/
825+
dqm->total_queue_count++;
826+
pr_debug("Total of %d queues are accountable so far\n",
827+
dqm->total_queue_count);
778828
mutex_unlock(&dqm->lock);
779829
}
780830

@@ -793,6 +843,13 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
793843

794844
mutex_lock(&dqm->lock);
795845

846+
if (dqm->total_queue_count >= max_num_of_queues_per_device) {
847+
pr_warn("amdkfd: Can't create new usermode queue because %d queues were already created\n",
848+
dqm->total_queue_count);
849+
retval = -EPERM;
850+
goto out;
851+
}
852+
796853
mqd = dqm->get_mqd_manager(dqm, KFD_MQD_TYPE_CIK_CP);
797854
if (mqd == NULL) {
798855
mutex_unlock(&dqm->lock);
@@ -810,6 +867,15 @@ static int create_queue_cpsch(struct device_queue_manager *dqm, struct queue *q,
810867
retval = execute_queues_cpsch(dqm, false);
811868
}
812869

870+
/*
871+
* Unconditionally increment this counter, regardless of the queue's
872+
* type or whether the queue is active.
873+
*/
874+
dqm->total_queue_count++;
875+
876+
pr_debug("Total of %d queues are accountable so far\n",
877+
dqm->total_queue_count);
878+
813879
out:
814880
mutex_unlock(&dqm->lock);
815881
return retval;
@@ -930,6 +996,14 @@ static int destroy_queue_cpsch(struct device_queue_manager *dqm,
930996

931997
mqd->uninit_mqd(mqd, q->mqd, q->mqd_mem_obj);
932998

999+
/*
1000+
* Unconditionally decrement this counter, regardless of the queue's
1001+
* type
1002+
*/
1003+
dqm->total_queue_count--;
1004+
pr_debug("Total of %d queues are accountable so far\n",
1005+
dqm->total_queue_count);
1006+
9331007
mutex_unlock(&dqm->lock);
9341008

9351009
return 0;

‎drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ struct device_queue_manager {
130130
struct list_head queues;
131131
unsigned int processes_count;
132132
unsigned int queue_count;
133+
unsigned int total_queue_count;
133134
unsigned int next_pipe_to_allocate;
134135
unsigned int *allocated_queues;
135136
unsigned int vmid_bitmap;

‎drivers/gpu/drm/amd/amdkfd/kfd_module.c‎

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,10 @@ module_param(sched_policy, int, 0444);
5050
MODULE_PARM_DESC(sched_policy,
5151
"Kernel cmdline parameter that defines the amdkfd scheduling policy");
5252

53-
int max_num_of_processes = KFD_MAX_NUM_OF_PROCESSES_DEFAULT;
54-
module_param(max_num_of_processes, int, 0444);
55-
MODULE_PARM_DESC(max_num_of_processes,
56-
"Kernel cmdline parameter that defines the amdkfd maximum number of supported processes");
57-
58-
int max_num_of_queues_per_process = KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT;
59-
module_param(max_num_of_queues_per_process, int, 0444);
60-
MODULE_PARM_DESC(max_num_of_queues_per_process,
61-
"Kernel cmdline parameter that defines the amdkfd maximum number of supported queues per process");
53+
int max_num_of_queues_per_device = KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT;
54+
module_param(max_num_of_queues_per_device, int, 0444);
55+
MODULE_PARM_DESC(max_num_of_queues_per_device,
56+
"Maximum number of supported queues per device (1 = Minimum, 4096 = default)");
6257

6358
bool kgd2kfd_init(unsigned interface_version,
6459
const struct kfd2kgd_calls *f2g,
@@ -100,16 +95,10 @@ static int __init kfd_module_init(void)
10095
}
10196

10297
/* Verify module parameters */
103-
if ((max_num_of_processes < 0) ||
104-
(max_num_of_processes > KFD_MAX_NUM_OF_PROCESSES)) {
105-
pr_err("kfd: max_num_of_processes must be between 0 to KFD_MAX_NUM_OF_PROCESSES\n");
106-
return -1;
107-
}
108-
109-
if ((max_num_of_queues_per_process < 0) ||
110-
(max_num_of_queues_per_process >
111-
KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)) {
112-
pr_err("kfd: max_num_of_queues_per_process must be between 0 to KFD_MAX_NUM_OF_QUEUES_PER_PROCESS\n");
98+
if ((max_num_of_queues_per_device < 0) ||
99+
(max_num_of_queues_per_device >
100+
KFD_MAX_NUM_OF_QUEUES_PER_DEVICE)) {
101+
pr_err("kfd: max_num_of_queues_per_device must be between 0 to KFD_MAX_NUM_OF_QUEUES_PER_DEVICE\n");
113102
return -1;
114103
}
115104

‎drivers/gpu/drm/amd/amdkfd/kfd_pasid.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static DEFINE_MUTEX(pasid_mutex);
3030

3131
int kfd_pasid_init(void)
3232
{
33-
pasid_limit = max_num_of_processes;
33+
pasid_limit = KFD_MAX_NUM_OF_PROCESSES;
3434

3535
pasid_bitmap = kcalloc(BITS_TO_LONGS(pasid_limit), sizeof(long), GFP_KERNEL);
3636
if (!pasid_bitmap)

‎drivers/gpu/drm/amd/amdkfd/kfd_priv.h‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,19 @@
5252
#define kfd_alloc_struct(ptr_to_struct) \
5353
((typeof(ptr_to_struct)) kzalloc(sizeof(*ptr_to_struct), GFP_KERNEL))
5454

55-
/* Kernel module parameter to specify maximum number of supported processes */
56-
extern int max_num_of_processes;
57-
58-
#define KFD_MAX_NUM_OF_PROCESSES_DEFAULT 32
5955
#define KFD_MAX_NUM_OF_PROCESSES 512
56+
#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024
6057

6158
/*
62-
* Kernel module parameter to specify maximum number of supported queues
63-
* per process
59+
* Kernel module parameter to specify maximum number of supported queues per
60+
* device
6461
*/
65-
extern int max_num_of_queues_per_process;
62+
extern int max_num_of_queues_per_device;
6663

67-
#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS_DEFAULT 128
68-
#define KFD_MAX_NUM_OF_QUEUES_PER_PROCESS 1024
64+
#define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096
65+
#define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE \
66+
(KFD_MAX_NUM_OF_PROCESSES * \
67+
KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)
6968

7069
#define KFD_KERNEL_QUEUE_SIZE 2048
7170

‎drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ static int find_available_queue_slot(struct process_queue_manager *pqm,
5454
pr_debug("kfd: in %s\n", __func__);
5555

5656
found = find_first_zero_bit(pqm->queue_slot_bitmap,
57-
max_num_of_queues_per_process);
57+
KFD_MAX_NUM_OF_QUEUES_PER_PROCESS);
5858

5959
pr_debug("kfd: the new slot id %lu\n", found);
6060

61-
if (found >= max_num_of_queues_per_process) {
61+
if (found >= KFD_MAX_NUM_OF_QUEUES_PER_PROCESS) {
6262
pr_info("amdkfd: Can not open more queues for process with pasid %d\n",
6363
pqm->process->pasid);
6464
return -ENOMEM;
@@ -76,7 +76,7 @@ int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p)
7676

7777
INIT_LIST_HEAD(&pqm->queues);
7878
pqm->queue_slot_bitmap =
79-
kzalloc(DIV_ROUND_UP(max_num_of_queues_per_process,
79+
kzalloc(DIV_ROUND_UP(KFD_MAX_NUM_OF_QUEUES_PER_PROCESS,
8080
BITS_PER_BYTE), GFP_KERNEL);
8181
if (pqm->queue_slot_bitmap == NULL)
8282
return -ENOMEM;
@@ -203,6 +203,7 @@ int pqm_create_queue(struct process_queue_manager *pqm,
203203
pqn->kq = NULL;
204204
retval = dev->dqm->create_queue(dev->dqm, q, &pdd->qpd,
205205
&q->properties.vmid);
206+
pr_debug("DQM returned %d for create_queue\n", retval);
206207
print_queue(q);
207208
break;
208209
case KFD_QUEUE_TYPE_DIQ:
@@ -222,7 +223,7 @@ int pqm_create_queue(struct process_queue_manager *pqm,
222223
}
223224

224225
if (retval != 0) {
225-
pr_err("kfd: error dqm create queue\n");
226+
pr_debug("Error dqm create queue\n");
226227
goto err_create_queue;
227228
}
228229

@@ -241,7 +242,10 @@ int pqm_create_queue(struct process_queue_manager *pqm,
241242
err_create_queue:
242243
kfree(pqn);
243244
err_allocate_pqn:
245+
/* check if queues list is empty unregister process from device */
244246
clear_bit(*qid, pqm->queue_slot_bitmap);
247+
if (list_empty(&pqm->queues))
248+
dev->dqm->unregister_process(dev->dqm, &pdd->qpd);
245249
return retval;
246250
}
247251

0 commit comments

Comments
 (0)