This is amdkfd's pull request for kernel 4.9. It contains a fix to a possible infinite loop bug and a couple of other minor "cleaning" patches. * tag 'drm-amdkfd-next-2016-09-19' of git://people.freedesktop.org/~gabbayo/linux: drm/amdkfd: Pass 'struct queue_propertices' by reference drm/amdkfd: Unify multiple calls to pr_debug() into one drm/amdkfd: Fix possible infinite loop drm/amdkfd: Reuse function to find a process through pasid drm/amdkfd: Add some missing memset zero'ing in queue init func drm/amdkfd: Tidy up kfd_generate_gpu_id() uint64_t bitshift unpack
Unified · Split
| @@ -103,11 +103,11 @@ static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address, · 102 unmodified lines | ||
| 103 | 103 | uint32_t pipe_id, uint32_t queue_id); |
| 104 | 104 | |
| 105 | 105 | static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, |
| 106 | − unsigned int timeout, uint32_t pipe_id, | |
| 106 | + unsigned int utimeout, uint32_t pipe_id, | |
| 107 | 107 | uint32_t queue_id); |
| 108 | 108 | static bool kgd_hqd_sdma_is_occupied(struct kgd_dev *kgd, void *mqd); |
| 109 | 109 | static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd, |
| 110 | − unsigned int timeout); | |
| 110 | + unsigned int utimeout); | |
| 111 | 111 | static int kgd_address_watch_disable(struct kgd_dev *kgd); |
| 112 | 112 | static int kgd_address_watch_execute(struct kgd_dev *kgd, |
| 113 | 113 | unsigned int watch_point_id, |
| @@ -437,11 +437,12 @@ static bool kgd_hqd_sdma_is_occupied(struct kgd_dev *kgd, void *mqd) · 323 unmodified lines | ||
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, |
| 440 | − unsigned int timeout, uint32_t pipe_id, | |
| 440 | + unsigned int utimeout, uint32_t pipe_id, | |
| 441 | 441 | uint32_t queue_id) |
| 442 | 442 | { |
| 443 | 443 | struct amdgpu_device *adev = get_amdgpu_device(kgd); |
| 444 | 444 | uint32_t temp; |
| 445 | + int timeout = utimeout; | |
| 445 | 446 | |
| 446 | 447 | acquire_queue(kgd, pipe_id, queue_id); |
| 447 | 448 | WREG32(mmCP_HQD_PQ_DOORBELL_CONTROL, 0); |
| @@ -452,9 +453,8 @@ static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, · 4 unmodified lines | ||
| 452 | 453 | temp = RREG32(mmCP_HQD_ACTIVE); |
| 453 | 454 | if (temp & CP_HQD_ACTIVE__ACTIVE_MASK) |
| 454 | 455 | break; |
| 455 | − if (timeout == 0) { | |
| 456 | − pr_err("kfd: cp queue preemption time out (%dms)\n", | |
| 457 | − temp); | |
| 456 | + if (timeout <= 0) { | |
| 457 | + pr_err("kfd: cp queue preemption time out.\n"); | |
| 458 | 458 | release_queue(kgd); |
| 459 | 459 | return -ETIME; |
| 460 | 460 | } |
| @@ -467,12 +467,13 @@ static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, · 6 unmodified lines | ||
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd, |
| 470 | − unsigned int timeout) | |
| 470 | + unsigned int utimeout) | |
| 471 | 471 | { |
| 472 | 472 | struct amdgpu_device *adev = get_amdgpu_device(kgd); |
| 473 | 473 | struct cik_sdma_rlc_registers *m; |
| 474 | 474 | uint32_t sdma_base_addr; |
| 475 | 475 | uint32_t temp; |
| 476 | + int timeout = utimeout; | |
| 476 | 477 | |
| 477 | 478 | m = get_sdma_mqd(mqd); |
| 478 | 479 | sdma_base_addr = get_sdma_base_addr(m); |
| @@ -485,7 +486,7 @@ static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd, · 6 unmodified lines | ||
| 485 | 486 | temp = RREG32(sdma_base_addr + mmSDMA0_RLC0_CONTEXT_STATUS); |
| 486 | 487 | if (temp & SDMA0_STATUS_REG__RB_CMD_IDLE__SHIFT) |
| 487 | 488 | break; |
| 488 | − if (timeout == 0) | |
| 489 | + if (timeout <= 0) | |
| 489 | 490 | return -ETIME; |
| 490 | 491 | msleep(20); |
| 491 | 492 | timeout -= 20; |
| @@ -62,10 +62,10 @@ static bool kgd_hqd_is_occupied(struct kgd_dev *kgd, uint64_t queue_address, · 61 unmodified lines | ||
| 62 | 62 | uint32_t pipe_id, uint32_t queue_id); |
| 63 | 63 | static bool kgd_hqd_sdma_is_occupied(struct kgd_dev *kgd, void *mqd); |
| 64 | 64 | static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, |
| 65 | − unsigned int timeout, uint32_t pipe_id, | |
| 65 | + unsigned int utimeout, uint32_t pipe_id, | |
| 66 | 66 | uint32_t queue_id); |
| 67 | 67 | static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd, |
| 68 | − unsigned int timeout); | |
| 68 | + unsigned int utimeout); | |
| 69 | 69 | static void write_vmid_invalidate_request(struct kgd_dev *kgd, uint8_t vmid); |
| 70 | 70 | static int kgd_address_watch_disable(struct kgd_dev *kgd); |
| 71 | 71 | static int kgd_address_watch_execute(struct kgd_dev *kgd, |
| @@ -349,11 +349,12 @@ static bool kgd_hqd_sdma_is_occupied(struct kgd_dev *kgd, void *mqd) · 277 unmodified lines | ||
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, |
| 352 | − unsigned int timeout, uint32_t pipe_id, | |
| 352 | + unsigned int utimeout, uint32_t pipe_id, | |
| 353 | 353 | uint32_t queue_id) |
| 354 | 354 | { |
| 355 | 355 | struct amdgpu_device *adev = get_amdgpu_device(kgd); |
| 356 | 356 | uint32_t temp; |
| 357 | + int timeout = utimeout; | |
| 357 | 358 | |
| 358 | 359 | acquire_queue(kgd, pipe_id, queue_id); |
| 359 | 360 | |
| @@ -363,9 +364,8 @@ static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, · 3 unmodified lines | ||
| 363 | 364 | temp = RREG32(mmCP_HQD_ACTIVE); |
| 364 | 365 | if (temp & CP_HQD_ACTIVE__ACTIVE_MASK) |
| 365 | 366 | break; |
| 366 | − if (timeout == 0) { | |
| 367 | − pr_err("kfd: cp queue preemption time out (%dms)\n", | |
| 368 | − temp); | |
| 367 | + if (timeout <= 0) { | |
| 368 | + pr_err("kfd: cp queue preemption time out.\n"); | |
| 369 | 369 | release_queue(kgd); |
| 370 | 370 | return -ETIME; |
| 371 | 371 | } |
| @@ -378,12 +378,13 @@ static int kgd_hqd_destroy(struct kgd_dev *kgd, uint32_t reset_type, · 6 unmodified lines | ||
| 378 | 378 | } |
| 379 | 379 | |
| 380 | 380 | static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd, |
| 381 | − unsigned int timeout) | |
| 381 | + unsigned int utimeout) | |
| 382 | 382 | { |
| 383 | 383 | struct amdgpu_device *adev = get_amdgpu_device(kgd); |
| 384 | 384 | struct cik_sdma_rlc_registers *m; |
| 385 | 385 | uint32_t sdma_base_addr; |
| 386 | 386 | uint32_t temp; |
| 387 | + int timeout = utimeout; | |
| 387 | 388 | |
| 388 | 389 | m = get_sdma_mqd(mqd); |
| 389 | 390 | sdma_base_addr = get_sdma_base_addr(m); |
| @@ -396,7 +397,7 @@ static int kgd_hqd_sdma_destroy(struct kgd_dev *kgd, void *mqd, · 6 unmodified lines | ||
| 396 | 397 | temp = RREG32(sdma_base_addr + mmSDMA0_RLC0_CONTEXT_STATUS); |
| 397 | 398 | if (temp & SDMA0_STATUS_REG__RB_CMD_IDLE__SHIFT) |
| 398 | 399 | break; |
| 399 | − if (timeout == 0) | |
| 400 | + if (timeout <= 0) | |
| 400 | 401 | return -ETIME; |
| 401 | 402 | msleep(20); |
| 402 | 403 | timeout -= 20; |
| @@ -142,13 +142,15 @@ int kfd_doorbell_mmap(struct kfd_process *process, struct vm_area_struct *vma) · 141 unmodified lines | ||
| 142 | 142 | |
| 143 | 143 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 144 | 144 | |
| 145 | − pr_debug("mapping doorbell page:\n"); | |
| 146 | − pr_debug(" target user address == 0x%08llX\n", | |
| 147 | − (unsigned long long) vma->vm_start); | |
| 148 | − pr_debug(" physical address == 0x%08llX\n", address); | |
| 149 | − pr_debug(" vm_flags == 0x%04lX\n", vma->vm_flags); | |
| 150 | − pr_debug(" size == 0x%04lX\n", | |
| 151 | − doorbell_process_allocation()); | |
| 145 | + pr_debug("kfd: mapping doorbell page in %s\n" | |
| 146 | + " target user address == 0x%08llX\n" | |
| 147 | + " physical address == 0x%08llX\n" | |
| 148 | + " vm_flags == 0x%04lX\n" | |
| 149 | + " size == 0x%04lX\n", | |
| 150 | + __func__, | |
| 151 | + (unsigned long long) vma->vm_start, address, vma->vm_flags, | |
| 152 | + doorbell_process_allocation()); | |
| 153 | + | |
| 152 | 154 | |
| 153 | 155 | return io_remap_pfn_range(vma, |
| 154 | 156 | vma->vm_start, |
| @@ -47,6 +47,9 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev, · 46 unmodified lines | ||
| 47 | 47 | pr_debug("amdkfd: In func %s initializing queue type %d size %d\n", |
| 48 | 48 | __func__, KFD_QUEUE_TYPE_HIQ, queue_size); |
| 49 | 49 | |
| 50 | + memset(&prop, 0, sizeof(prop)); | |
| 51 | + memset(&nop, 0, sizeof(nop)); | |
| 52 | + | |
| 50 | 53 | nop.opcode = IT_NOP; |
| 51 | 54 | nop.type = PM4_TYPE_3; |
| 52 | 55 | nop.u32all |= PM4_COUNT_ZERO; |
| @@ -121,7 +124,7 @@ static bool initialize(struct kernel_queue *kq, struct kfd_dev *dev, · 68 unmodified lines | ||
| 121 | 124 | prop.eop_ring_buffer_address = kq->eop_gpu_addr; |
| 122 | 125 | prop.eop_ring_buffer_size = PAGE_SIZE; |
| 123 | 126 | |
| 124 | − if (init_queue(&kq->queue, prop) != 0) | |
| 127 | + if (init_queue(&kq->queue, &prop) != 0) | |
| 125 | 128 | goto err_init_queue; |
| 126 | 129 | |
| 127 | 130 | kq->queue->device = dev; |
| @@ -619,7 +619,7 @@ int kfd_init_apertures(struct kfd_process *process); · 618 unmodified lines | ||
| 619 | 619 | /* Queue Context Management */ |
| 620 | 620 | struct cik_sdma_rlc_registers *get_sdma_mqd(void *mqd); |
| 621 | 621 | |
| 622 | −int init_queue(struct queue **q, struct queue_properties properties); | |
| 622 | +int init_queue(struct queue **q, const struct queue_properties *properties); | |
| 623 | 623 | void uninit_queue(struct queue *q); |
| 624 | 624 | void print_queue_properties(struct queue_properties *q); |
| 625 | 625 | void print_queue(struct queue *q); |
| @@ -404,58 +404,47 @@ void kfd_unbind_process_from_device(struct kfd_dev *dev, unsigned int pasid) · 403 unmodified lines | ||
| 404 | 404 | { |
| 405 | 405 | struct kfd_process *p; |
| 406 | 406 | struct kfd_process_device *pdd; |
| 407 | − int idx, i; | |
| 408 | 407 | |
| 409 | 408 | BUG_ON(dev == NULL); |
| 410 | 409 | |
| 411 | − idx = srcu_read_lock(&kfd_processes_srcu); | |
| 412 | − | |
| 413 | 410 | /* |
| 414 | 411 | * Look for the process that matches the pasid. If there is no such |
| 415 | 412 | * process, we either released it in amdkfd's own notifier, or there |
| 416 | 413 | * is a bug. Unfortunately, there is no way to tell... |
| 417 | 414 | */ |
| 418 | − hash_for_each_rcu(kfd_processes_table, i, p, kfd_processes) | |
| 419 | − if (p->pasid == pasid) { | |
| 420 | − | |
| 421 | − srcu_read_unlock(&kfd_processes_srcu, idx); | |
| 422 | − | |
| 423 | − pr_debug("Unbinding process %d from IOMMU\n", pasid); | |
| 415 | + p = kfd_lookup_process_by_pasid(pasid); | |
| 416 | + if (!p) | |
| 417 | + return; | |
| 424 | 418 | |
| 425 | − mutex_lock(&p->mutex); | |
| 426 | − | |
| 427 | − if ((dev->dbgmgr) && (dev->dbgmgr->pasid == p->pasid)) | |
| 428 | − kfd_dbgmgr_destroy(dev->dbgmgr); | |
| 429 | − | |
| 430 | − pqm_uninit(&p->pqm); | |
| 419 | + pr_debug("Unbinding process %d from IOMMU\n", pasid); | |
| 431 | 420 | |
| 432 | − pdd = kfd_get_process_device_data(dev, p); | |
| 421 | + if ((dev->dbgmgr) && (dev->dbgmgr->pasid == p->pasid)) | |
| 422 | + kfd_dbgmgr_destroy(dev->dbgmgr); | |
| 433 | 423 | |
| 434 | − if (!pdd) { | |
| 435 | − mutex_unlock(&p->mutex); | |
| 436 | − return; | |
| 437 | − } | |
| 424 | + pqm_uninit(&p->pqm); | |
| 438 | 425 | |
| 439 | − if (pdd->reset_wavefronts) { | |
| 440 | − dbgdev_wave_reset_wavefronts(pdd->dev, p); | |
| 441 | − pdd->reset_wavefronts = false; | |
| 442 | − } | |
| 426 | + pdd = kfd_get_process_device_data(dev, p); | |
| 443 | 427 | |
| 444 | − /* | |
| 445 | − * Just mark pdd as unbound, because we still need it | |
| 446 | − * to call amd_iommu_unbind_pasid() in when the | |
| 447 | − * process exits. | |
| 448 | − * We don't call amd_iommu_unbind_pasid() here | |
| 449 | − * because the IOMMU called us. | |
| 450 | − */ | |
| 451 | − pdd->bound = false; | |
| 428 | + if (!pdd) { | |
| 429 | + mutex_unlock(&p->mutex); | |
| 430 | + return; | |
| 431 | + } | |
| 452 | 432 | |
| 453 | − mutex_unlock(&p->mutex); | |
| 433 | + if (pdd->reset_wavefronts) { | |
| 434 | + dbgdev_wave_reset_wavefronts(pdd->dev, p); | |
| 435 | + pdd->reset_wavefronts = false; | |
| 436 | + } | |
| 454 | 437 | |
| 455 | − return; | |
| 456 | − } | |
| 438 | + /* | |
| 439 | + * Just mark pdd as unbound, because we still need it | |
| 440 | + * to call amd_iommu_unbind_pasid() in when the | |
| 441 | + * process exits. | |
| 442 | + * We don't call amd_iommu_unbind_pasid() here | |
| 443 | + * because the IOMMU called us. | |
| 444 | + */ | |
| 445 | + pdd->bound = false; | |
| 457 | 446 | |
| 458 | − srcu_read_unlock(&kfd_processes_srcu, idx); | |
| 447 | + mutex_unlock(&p->mutex); | |
| 459 | 448 | } |
| 460 | 449 | |
| 461 | 450 | struct kfd_process_device *kfd_get_first_process_device_data(struct kfd_process *p) |
| @@ -129,7 +129,7 @@ static int create_cp_queue(struct process_queue_manager *pqm, · 128 unmodified lines | ||
| 129 | 129 | q_properties->vmid = 0; |
| 130 | 130 | q_properties->queue_id = qid; |
| 131 | 131 | |
| 132 | − retval = init_queue(q, *q_properties); | |
| 132 | + retval = init_queue(q, q_properties); | |
| 133 | 133 | if (retval != 0) |
| 134 | 134 | goto err_init_queue; |
| 135 | 135 | |
| @@ -63,7 +63,7 @@ void print_queue(struct queue *q) · 62 unmodified lines | ||
| 63 | 63 | pr_debug("Queue Device Address: 0x%p\n", q->device); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | −int init_queue(struct queue **q, struct queue_properties properties) | |
| 66 | +int init_queue(struct queue **q, const struct queue_properties *properties) | |
| 67 | 67 | { |
| 68 | 68 | struct queue *tmp; |
| 69 | 69 | |
| @@ -73,7 +73,7 @@ int init_queue(struct queue **q, struct queue_properties properties) · 3 unmodified lines | ||
| 73 | 73 | if (!tmp) |
| 74 | 74 | return -ENOMEM; |
| 75 | 75 | |
| 76 | − memcpy(&tmp->properties, &properties, sizeof(struct queue_properties)); | |
| 76 | + memcpy(&tmp->properties, properties, sizeof(struct queue_properties)); | |
| 77 | 77 | |
| 78 | 78 | *q = tmp; |
| 79 | 79 | return 0; |
| @@ -1090,19 +1090,21 @@ static uint32_t kfd_generate_gpu_id(struct kfd_dev *gpu) · 1089 unmodified lines | ||
| 1090 | 1090 | { |
| 1091 | 1091 | uint32_t hashout; |
| 1092 | 1092 | uint32_t buf[7]; |
| 1093 | + uint64_t local_mem_size; | |
| 1093 | 1094 | int i; |
| 1094 | 1095 | |
| 1095 | 1096 | if (!gpu) |
| 1096 | 1097 | return 0; |
| 1097 | 1098 | |
| 1099 | + local_mem_size = gpu->kfd2kgd->get_vmem_size(gpu->kgd); | |
| 1100 | + | |
| 1098 | 1101 | buf[0] = gpu->pdev->devfn; |
| 1099 | 1102 | buf[1] = gpu->pdev->subsystem_vendor; |
| 1100 | 1103 | buf[2] = gpu->pdev->subsystem_device; |
| 1101 | 1104 | buf[3] = gpu->pdev->device; |
| 1102 | 1105 | buf[4] = gpu->pdev->bus->number; |
| 1103 | − buf[5] = (uint32_t)(gpu->kfd2kgd->get_vmem_size(gpu->kgd) | |
| 1104 | − & 0xffffffff); | |
| 1105 | − buf[6] = (uint32_t)(gpu->kfd2kgd->get_vmem_size(gpu->kgd) >> 32); | |
| 1106 | + buf[5] = lower_32_bits(local_mem_size); | |
| 1107 | + buf[6] = upper_32_bits(local_mem_size); | |
| 1106 | 1108 | |
| 1107 | 1109 | for (i = 0, hashout = 0; i < 7; i++) |
| 1108 | 1110 | hashout ^= hash_32(buf[i], KFD_GPU_ID_HASH_WIDTH); |