.. | .. |
---|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note |
---|
2 | 2 | /* |
---|
3 | 3 | * |
---|
4 | | - * (C) COPYRIGHT 2018-2021 ARM Limited. All rights reserved. |
---|
| 4 | + * (C) COPYRIGHT 2018-2023 ARM Limited. All rights reserved. |
---|
5 | 5 | * |
---|
6 | 6 | * This program is free software and is provided to you under the terms of the |
---|
7 | 7 | * GNU General Public License version 2 as published by the Free Software |
---|
.. | .. |
---|
33 | 33 | static DEFINE_SPINLOCK(kbase_csf_fence_lock); |
---|
34 | 34 | #endif |
---|
35 | 35 | |
---|
| 36 | +#ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG |
---|
| 37 | +#define FENCE_WAIT_TIMEOUT_MS 3000 |
---|
| 38 | +#endif |
---|
| 39 | + |
---|
36 | 40 | static void kcpu_queue_process(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
37 | | - bool ignore_waits); |
---|
| 41 | + bool drain_queue); |
---|
38 | 42 | |
---|
39 | 43 | static void kcpu_queue_process_worker(struct work_struct *data); |
---|
40 | 44 | |
---|
.. | .. |
---|
45 | 49 | { |
---|
46 | 50 | struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
47 | 51 | struct kbase_va_region *reg; |
---|
| 52 | + struct kbase_mem_phy_alloc *alloc; |
---|
| 53 | + struct page **pages; |
---|
| 54 | + struct tagged_addr *pa; |
---|
| 55 | + long i; |
---|
48 | 56 | int ret = 0; |
---|
49 | 57 | |
---|
50 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 58 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
51 | 59 | |
---|
52 | 60 | /* Take the processes mmap lock */ |
---|
53 | 61 | down_read(kbase_mem_get_process_mmap_lock()); |
---|
.. | .. |
---|
72 | 80 | * on the physical pages tracking object. When the last |
---|
73 | 81 | * reference to the tracking object is dropped the pages |
---|
74 | 82 | * would be unpinned if they weren't unpinned before. |
---|
| 83 | + * |
---|
| 84 | + * Region should be CPU cached: abort if it isn't. |
---|
75 | 85 | */ |
---|
| 86 | + if (WARN_ON(!(reg->flags & KBASE_REG_CPU_CACHED))) { |
---|
| 87 | + ret = -EINVAL; |
---|
| 88 | + goto out; |
---|
| 89 | + } |
---|
| 90 | + |
---|
76 | 91 | ret = kbase_jd_user_buf_pin_pages(kctx, reg); |
---|
77 | 92 | if (ret) |
---|
78 | 93 | goto out; |
---|
| 94 | + |
---|
| 95 | + alloc = reg->gpu_alloc; |
---|
| 96 | + pa = kbase_get_gpu_phy_pages(reg); |
---|
| 97 | + pages = alloc->imported.user_buf.pages; |
---|
| 98 | + |
---|
| 99 | + for (i = 0; i < alloc->nents; i++) |
---|
| 100 | + pa[i] = as_tagged(page_to_phys(pages[i])); |
---|
79 | 101 | } |
---|
80 | 102 | |
---|
81 | 103 | current_command->type = BASE_KCPU_COMMAND_TYPE_MAP_IMPORT; |
---|
.. | .. |
---|
99 | 121 | struct kbase_va_region *reg; |
---|
100 | 122 | int ret = 0; |
---|
101 | 123 | |
---|
102 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 124 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
103 | 125 | |
---|
104 | 126 | kbase_gpu_vm_lock(kctx); |
---|
105 | 127 | |
---|
.. | .. |
---|
167 | 189 | &kctx->csf.kcpu_queues.jit_blocked_queues; |
---|
168 | 190 | struct kbase_kcpu_command_queue *blocked_queue; |
---|
169 | 191 | |
---|
170 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 192 | + lockdep_assert_held(&queue->lock); |
---|
| 193 | + lockdep_assert_held(&kctx->csf.kcpu_queues.jit_lock); |
---|
171 | 194 | |
---|
172 | 195 | list_for_each_entry(blocked_queue, |
---|
173 | 196 | &kctx->csf.kcpu_queues.jit_blocked_queues, |
---|
174 | 197 | jit_blocked) { |
---|
175 | | - struct kbase_kcpu_command const*const jit_alloc_cmd = |
---|
176 | | - &blocked_queue->commands[blocked_queue->start_offset]; |
---|
| 198 | + struct kbase_kcpu_command const *const jit_alloc_cmd = |
---|
| 199 | + &blocked_queue->commands[blocked_queue->start_offset]; |
---|
177 | 200 | |
---|
178 | 201 | WARN_ON(jit_alloc_cmd->type != BASE_KCPU_COMMAND_TYPE_JIT_ALLOC); |
---|
179 | 202 | if (cmd->enqueue_ts < jit_alloc_cmd->enqueue_ts) { |
---|
.. | .. |
---|
190 | 213 | * |
---|
191 | 214 | * @queue: The queue containing this JIT allocation |
---|
192 | 215 | * @cmd: The JIT allocation command |
---|
| 216 | + * |
---|
| 217 | + * Return: |
---|
| 218 | + * * 0 - allocation OK |
---|
| 219 | + * * -EINVAL - missing info or JIT ID still in use |
---|
| 220 | + * * -EAGAIN - Retry |
---|
| 221 | + * * -ENOMEM - no memory. unable to allocate |
---|
193 | 222 | */ |
---|
194 | 223 | static int kbase_kcpu_jit_allocate_process( |
---|
195 | 224 | struct kbase_kcpu_command_queue *queue, |
---|
.. | .. |
---|
206 | 235 | u32 i; |
---|
207 | 236 | int ret; |
---|
208 | 237 | |
---|
209 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
210 | | - |
---|
211 | | - if (alloc_info->blocked) { |
---|
212 | | - list_del(&queue->jit_blocked); |
---|
213 | | - alloc_info->blocked = false; |
---|
214 | | - } |
---|
| 238 | + lockdep_assert_held(&queue->lock); |
---|
215 | 239 | |
---|
216 | 240 | if (WARN_ON(!info)) |
---|
217 | 241 | return -EINVAL; |
---|
| 242 | + |
---|
| 243 | + mutex_lock(&kctx->csf.kcpu_queues.jit_lock); |
---|
218 | 244 | |
---|
219 | 245 | /* Check if all JIT IDs are not in use */ |
---|
220 | 246 | for (i = 0; i < count; i++, info++) { |
---|
221 | 247 | /* The JIT ID is still in use so fail the allocation */ |
---|
222 | 248 | if (kctx->jit_alloc[info->id]) { |
---|
223 | | - dev_warn(kctx->kbdev->dev, "JIT ID still in use\n"); |
---|
224 | | - return -EINVAL; |
---|
| 249 | + dev_dbg(kctx->kbdev->dev, "JIT ID still in use"); |
---|
| 250 | + ret = -EINVAL; |
---|
| 251 | + goto fail; |
---|
225 | 252 | } |
---|
| 253 | + } |
---|
| 254 | + |
---|
| 255 | + if (alloc_info->blocked) { |
---|
| 256 | + list_del(&queue->jit_blocked); |
---|
| 257 | + alloc_info->blocked = false; |
---|
226 | 258 | } |
---|
227 | 259 | |
---|
228 | 260 | /* Now start the allocation loop */ |
---|
.. | .. |
---|
238 | 270 | break; |
---|
239 | 271 | |
---|
240 | 272 | if (jit_cmd->type == BASE_KCPU_COMMAND_TYPE_JIT_FREE) { |
---|
241 | | - u8 const*const free_ids = jit_cmd->info.jit_free.ids; |
---|
| 273 | + u8 const *const free_ids = jit_cmd->info.jit_free.ids; |
---|
242 | 274 | |
---|
243 | 275 | if (free_ids && *free_ids && kctx->jit_alloc[*free_ids]) { |
---|
244 | 276 | /* |
---|
.. | .. |
---|
259 | 291 | */ |
---|
260 | 292 | dev_warn_ratelimited(kctx->kbdev->dev, "JIT alloc command failed: %pK\n", cmd); |
---|
261 | 293 | ret = -ENOMEM; |
---|
262 | | - goto fail; |
---|
| 294 | + goto fail_rollback; |
---|
263 | 295 | } |
---|
264 | 296 | |
---|
265 | 297 | /* There are pending frees for an active allocation |
---|
.. | .. |
---|
277 | 309 | kctx->jit_alloc[info->id] = NULL; |
---|
278 | 310 | } |
---|
279 | 311 | |
---|
280 | | - return -EAGAIN; |
---|
| 312 | + ret = -EAGAIN; |
---|
| 313 | + goto fail; |
---|
281 | 314 | } |
---|
282 | 315 | |
---|
283 | 316 | /* Bind it to the user provided ID. */ |
---|
.. | .. |
---|
289 | 322 | * Write the address of the JIT allocation to the user provided |
---|
290 | 323 | * GPU allocation. |
---|
291 | 324 | */ |
---|
292 | | - ptr = kbase_vmap(kctx, info->gpu_alloc_addr, sizeof(*ptr), |
---|
293 | | - &mapping); |
---|
| 325 | + ptr = kbase_vmap_prot(kctx, info->gpu_alloc_addr, sizeof(*ptr), |
---|
| 326 | + KBASE_REG_CPU_WR, &mapping); |
---|
294 | 327 | if (!ptr) { |
---|
295 | 328 | ret = -ENOMEM; |
---|
296 | | - goto fail; |
---|
| 329 | + goto fail_rollback; |
---|
297 | 330 | } |
---|
298 | 331 | |
---|
299 | 332 | reg = kctx->jit_alloc[info->id]; |
---|
.. | .. |
---|
302 | 335 | kbase_vunmap(kctx, &mapping); |
---|
303 | 336 | } |
---|
304 | 337 | |
---|
| 338 | + mutex_unlock(&kctx->csf.kcpu_queues.jit_lock); |
---|
| 339 | + |
---|
305 | 340 | return 0; |
---|
306 | 341 | |
---|
307 | | -fail: |
---|
| 342 | +fail_rollback: |
---|
308 | 343 | /* Roll back completely */ |
---|
309 | 344 | for (i = 0, info = alloc_info->info; i < count; i++, info++) { |
---|
310 | 345 | /* Free the allocations that were successful. |
---|
.. | .. |
---|
317 | 352 | |
---|
318 | 353 | kctx->jit_alloc[info->id] = KBASE_RESERVED_REG_JIT_ALLOC; |
---|
319 | 354 | } |
---|
| 355 | +fail: |
---|
| 356 | + mutex_unlock(&kctx->csf.kcpu_queues.jit_lock); |
---|
320 | 357 | |
---|
321 | 358 | return ret; |
---|
322 | 359 | } |
---|
.. | .. |
---|
328 | 365 | { |
---|
329 | 366 | struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
330 | 367 | void __user *data = u64_to_user_ptr(alloc_info->info); |
---|
331 | | - struct base_jit_alloc_info *info; |
---|
| 368 | + struct base_jit_alloc_info *info = NULL; |
---|
332 | 369 | u32 count = alloc_info->count; |
---|
333 | 370 | int ret = 0; |
---|
334 | 371 | u32 i; |
---|
335 | 372 | |
---|
336 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 373 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
337 | 374 | |
---|
338 | | - if (!data || count > kcpu_queue->kctx->jit_max_allocations || |
---|
339 | | - count > ARRAY_SIZE(kctx->jit_alloc)) { |
---|
| 375 | + if ((count == 0) || (count > ARRAY_SIZE(kctx->jit_alloc)) || |
---|
| 376 | + (count > kcpu_queue->kctx->jit_max_allocations) || (!data) || |
---|
| 377 | + !kbase_mem_allow_alloc(kctx)) { |
---|
340 | 378 | ret = -EINVAL; |
---|
341 | 379 | goto out; |
---|
342 | 380 | } |
---|
.. | .. |
---|
371 | 409 | } |
---|
372 | 410 | |
---|
373 | 411 | current_command->type = BASE_KCPU_COMMAND_TYPE_JIT_ALLOC; |
---|
374 | | - list_add_tail(¤t_command->info.jit_alloc.node, |
---|
375 | | - &kctx->csf.kcpu_queues.jit_cmds_head); |
---|
376 | 412 | current_command->info.jit_alloc.info = info; |
---|
377 | 413 | current_command->info.jit_alloc.count = count; |
---|
378 | 414 | current_command->info.jit_alloc.blocked = false; |
---|
| 415 | + mutex_lock(&kctx->csf.kcpu_queues.jit_lock); |
---|
| 416 | + list_add_tail(¤t_command->info.jit_alloc.node, |
---|
| 417 | + &kctx->csf.kcpu_queues.jit_cmds_head); |
---|
| 418 | + mutex_unlock(&kctx->csf.kcpu_queues.jit_lock); |
---|
379 | 419 | |
---|
380 | 420 | return 0; |
---|
381 | 421 | out_free: |
---|
.. | .. |
---|
394 | 434 | struct kbase_kcpu_command_queue *queue, |
---|
395 | 435 | struct kbase_kcpu_command *cmd) |
---|
396 | 436 | { |
---|
397 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 437 | + lockdep_assert_held(&queue->lock); |
---|
| 438 | + |
---|
| 439 | + mutex_lock(&queue->kctx->csf.kcpu_queues.jit_lock); |
---|
398 | 440 | |
---|
399 | 441 | /* Remove this command from the jit_cmds_head list */ |
---|
400 | 442 | list_del(&cmd->info.jit_alloc.node); |
---|
.. | .. |
---|
408 | 450 | cmd->info.jit_alloc.blocked = false; |
---|
409 | 451 | } |
---|
410 | 452 | |
---|
| 453 | + mutex_unlock(&queue->kctx->csf.kcpu_queues.jit_lock); |
---|
| 454 | + |
---|
411 | 455 | kfree(cmd->info.jit_alloc.info); |
---|
412 | 456 | } |
---|
413 | 457 | |
---|
.. | .. |
---|
420 | 464 | { |
---|
421 | 465 | struct kbase_kcpu_command_queue *blocked_queue; |
---|
422 | 466 | |
---|
423 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 467 | + lockdep_assert_held(&kctx->csf.kcpu_queues.jit_lock); |
---|
424 | 468 | |
---|
425 | 469 | /* |
---|
426 | 470 | * Reschedule all queues blocked by JIT_ALLOC commands. |
---|
427 | 471 | * NOTE: This code traverses the list of blocked queues directly. It |
---|
428 | 472 | * only works as long as the queued works are not executed at the same |
---|
429 | 473 | * time. This precondition is true since we're holding the |
---|
430 | | - * kbase_csf_kcpu_queue_context.lock . |
---|
| 474 | + * kbase_csf_kcpu_queue_context.jit_lock . |
---|
431 | 475 | */ |
---|
432 | | - list_for_each_entry(blocked_queue, |
---|
433 | | - &kctx->csf.kcpu_queues.jit_blocked_queues, jit_blocked) |
---|
434 | | - queue_work(kctx->csf.kcpu_queues.wq, &blocked_queue->work); |
---|
| 476 | + list_for_each_entry(blocked_queue, &kctx->csf.kcpu_queues.jit_blocked_queues, jit_blocked) |
---|
| 477 | + queue_work(blocked_queue->wq, &blocked_queue->work); |
---|
435 | 478 | } |
---|
436 | 479 | |
---|
437 | 480 | static int kbase_kcpu_jit_free_process(struct kbase_kcpu_command_queue *queue, |
---|
.. | .. |
---|
448 | 491 | if (WARN_ON(!ids)) |
---|
449 | 492 | return -EINVAL; |
---|
450 | 493 | |
---|
451 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 494 | + lockdep_assert_held(&queue->lock); |
---|
| 495 | + mutex_lock(&kctx->csf.kcpu_queues.jit_lock); |
---|
452 | 496 | |
---|
453 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_EXECUTE_JIT_FREE_END( |
---|
454 | | - queue->kctx->kbdev, queue); |
---|
| 497 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_EXECUTE_JIT_FREE_END(queue->kctx->kbdev, |
---|
| 498 | + queue); |
---|
455 | 499 | |
---|
456 | 500 | for (i = 0; i < count; i++) { |
---|
457 | 501 | u64 pages_used = 0; |
---|
458 | 502 | int item_err = 0; |
---|
459 | 503 | |
---|
460 | 504 | if (!kctx->jit_alloc[ids[i]]) { |
---|
461 | | - dev_warn(kctx->kbdev->dev, "invalid JIT free ID\n"); |
---|
| 505 | + dev_dbg(kctx->kbdev->dev, "invalid JIT free ID"); |
---|
462 | 506 | rc = -EINVAL; |
---|
463 | 507 | item_err = rc; |
---|
464 | 508 | } else { |
---|
.. | .. |
---|
480 | 524 | queue->kctx->kbdev, queue, item_err, pages_used); |
---|
481 | 525 | } |
---|
482 | 526 | |
---|
483 | | - /* Free the list of ids */ |
---|
484 | | - kfree(ids); |
---|
485 | | - |
---|
486 | 527 | /* |
---|
487 | 528 | * Remove this command from the jit_cmds_head list and retry pending |
---|
488 | 529 | * allocations. |
---|
489 | 530 | */ |
---|
490 | 531 | list_del(&cmd->info.jit_free.node); |
---|
491 | 532 | kbase_kcpu_jit_retry_pending_allocs(kctx); |
---|
| 533 | + |
---|
| 534 | + mutex_unlock(&kctx->csf.kcpu_queues.jit_lock); |
---|
| 535 | + |
---|
| 536 | + /* Free the list of ids */ |
---|
| 537 | + kfree(ids); |
---|
492 | 538 | |
---|
493 | 539 | return rc; |
---|
494 | 540 | } |
---|
.. | .. |
---|
505 | 551 | int ret; |
---|
506 | 552 | u32 i; |
---|
507 | 553 | |
---|
508 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 554 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
509 | 555 | |
---|
510 | 556 | /* Sanity checks */ |
---|
511 | 557 | if (!count || count > ARRAY_SIZE(kctx->jit_alloc)) { |
---|
.. | .. |
---|
551 | 597 | } |
---|
552 | 598 | |
---|
553 | 599 | current_command->type = BASE_KCPU_COMMAND_TYPE_JIT_FREE; |
---|
554 | | - list_add_tail(¤t_command->info.jit_free.node, |
---|
555 | | - &kctx->csf.kcpu_queues.jit_cmds_head); |
---|
556 | 600 | current_command->info.jit_free.ids = ids; |
---|
557 | 601 | current_command->info.jit_free.count = count; |
---|
| 602 | + mutex_lock(&kctx->csf.kcpu_queues.jit_lock); |
---|
| 603 | + list_add_tail(¤t_command->info.jit_free.node, |
---|
| 604 | + &kctx->csf.kcpu_queues.jit_cmds_head); |
---|
| 605 | + mutex_unlock(&kctx->csf.kcpu_queues.jit_lock); |
---|
558 | 606 | |
---|
559 | 607 | return 0; |
---|
560 | 608 | out_free: |
---|
.. | .. |
---|
563 | 611 | return ret; |
---|
564 | 612 | } |
---|
565 | 613 | |
---|
| 614 | +#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST |
---|
566 | 615 | static int kbase_csf_queue_group_suspend_prepare( |
---|
567 | 616 | struct kbase_kcpu_command_queue *kcpu_queue, |
---|
568 | 617 | struct base_kcpu_command_group_suspend_info *suspend_buf, |
---|
.. | .. |
---|
570 | 619 | { |
---|
571 | 620 | struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
572 | 621 | struct kbase_suspend_copy_buffer *sus_buf = NULL; |
---|
| 622 | + const u32 csg_suspend_buf_size = |
---|
| 623 | + kctx->kbdev->csf.global_iface.groups[0].suspend_size; |
---|
573 | 624 | u64 addr = suspend_buf->buffer; |
---|
574 | 625 | u64 page_addr = addr & PAGE_MASK; |
---|
575 | | - u64 end_addr = addr + suspend_buf->size - 1; |
---|
| 626 | + u64 end_addr = addr + csg_suspend_buf_size - 1; |
---|
576 | 627 | u64 last_page_addr = end_addr & PAGE_MASK; |
---|
577 | 628 | int nr_pages = (last_page_addr - page_addr) / PAGE_SIZE + 1; |
---|
578 | 629 | int pinned_pages = 0, ret = 0; |
---|
579 | 630 | struct kbase_va_region *reg; |
---|
580 | 631 | |
---|
581 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 632 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
582 | 633 | |
---|
583 | | - if (suspend_buf->size < |
---|
584 | | - kctx->kbdev->csf.global_iface.groups[0].suspend_size) |
---|
| 634 | + if (suspend_buf->size < csg_suspend_buf_size) |
---|
585 | 635 | return -EINVAL; |
---|
586 | 636 | |
---|
587 | 637 | ret = kbase_csf_queue_group_handle_is_valid(kctx, |
---|
.. | .. |
---|
593 | 643 | if (!sus_buf) |
---|
594 | 644 | return -ENOMEM; |
---|
595 | 645 | |
---|
596 | | - sus_buf->size = suspend_buf->size; |
---|
| 646 | + sus_buf->size = csg_suspend_buf_size; |
---|
597 | 647 | sus_buf->nr_pages = nr_pages; |
---|
598 | 648 | sus_buf->offset = addr & ~PAGE_MASK; |
---|
599 | 649 | |
---|
.. | .. |
---|
629 | 679 | struct tagged_addr *page_array; |
---|
630 | 680 | u64 start, end, i; |
---|
631 | 681 | |
---|
632 | | - if (!(reg->flags & BASE_MEM_SAME_VA) || |
---|
633 | | - reg->nr_pages < nr_pages || |
---|
634 | | - kbase_reg_current_backed_size(reg) != |
---|
635 | | - reg->nr_pages) { |
---|
| 682 | + if (((reg->flags & KBASE_REG_ZONE_MASK) != KBASE_REG_ZONE_SAME_VA) || |
---|
| 683 | + (kbase_reg_current_backed_size(reg) < nr_pages) || |
---|
| 684 | + !(reg->flags & KBASE_REG_CPU_WR) || |
---|
| 685 | + (reg->gpu_alloc->type != KBASE_MEM_TYPE_NATIVE) || |
---|
| 686 | + (kbase_is_region_shrinkable(reg)) || (kbase_va_region_is_no_user_free(reg))) { |
---|
636 | 687 | ret = -EINVAL; |
---|
637 | 688 | goto out_clean_pages; |
---|
638 | 689 | } |
---|
.. | .. |
---|
676 | 727 | { |
---|
677 | 728 | return kbase_csf_queue_group_suspend(kctx, sus_buf, group_handle); |
---|
678 | 729 | } |
---|
| 730 | +#endif |
---|
679 | 731 | |
---|
680 | 732 | static enum kbase_csf_event_callback_action event_cqs_callback(void *param) |
---|
681 | 733 | { |
---|
682 | 734 | struct kbase_kcpu_command_queue *kcpu_queue = |
---|
683 | 735 | (struct kbase_kcpu_command_queue *)param; |
---|
684 | | - struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
685 | 736 | |
---|
686 | | - queue_work(kctx->csf.kcpu_queues.wq, &kcpu_queue->work); |
---|
| 737 | + queue_work(kcpu_queue->wq, &kcpu_queue->work); |
---|
687 | 738 | |
---|
688 | 739 | return KBASE_CSF_EVENT_CALLBACK_KEEP; |
---|
689 | 740 | } |
---|
.. | .. |
---|
713 | 764 | { |
---|
714 | 765 | u32 i; |
---|
715 | 766 | |
---|
716 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 767 | + lockdep_assert_held(&queue->lock); |
---|
717 | 768 | |
---|
718 | 769 | if (WARN_ON(!cqs_wait->objs)) |
---|
719 | 770 | return -EINVAL; |
---|
.. | .. |
---|
727 | 778 | cqs_wait->objs[i].addr, &mapping); |
---|
728 | 779 | |
---|
729 | 780 | if (!queue->command_started) { |
---|
730 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_WAIT_START( |
---|
731 | | - kbdev, queue); |
---|
| 781 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_WAIT_START(kbdev, |
---|
| 782 | + queue); |
---|
732 | 783 | queue->command_started = true; |
---|
733 | | - KBASE_KTRACE_ADD_CSF_KCPU(kbdev, CQS_WAIT_START, |
---|
| 784 | + KBASE_KTRACE_ADD_CSF_KCPU(kbdev, KCPU_CQS_WAIT_START, |
---|
734 | 785 | queue, cqs_wait->nr_objs, 0); |
---|
735 | 786 | } |
---|
736 | 787 | |
---|
.. | .. |
---|
741 | 792 | return -EINVAL; |
---|
742 | 793 | } |
---|
743 | 794 | |
---|
744 | | - sig_set = evt[BASEP_EVENT_VAL_INDEX] > cqs_wait->objs[i].val; |
---|
| 795 | + sig_set = |
---|
| 796 | + evt[BASEP_EVENT32_VAL_OFFSET / sizeof(u32)] > cqs_wait->objs[i].val; |
---|
745 | 797 | if (sig_set) { |
---|
746 | 798 | bool error = false; |
---|
747 | 799 | |
---|
748 | 800 | bitmap_set(cqs_wait->signaled, i, 1); |
---|
749 | 801 | if ((cqs_wait->inherit_err_flags & (1U << i)) && |
---|
750 | | - evt[BASEP_EVENT_ERR_INDEX] > 0) { |
---|
| 802 | + evt[BASEP_EVENT32_ERR_OFFSET / sizeof(u32)] > 0) { |
---|
751 | 803 | queue->has_error = true; |
---|
752 | 804 | error = true; |
---|
753 | 805 | } |
---|
754 | 806 | |
---|
755 | | - KBASE_KTRACE_ADD_CSF_KCPU(kbdev, CQS_WAIT_END, |
---|
| 807 | + KBASE_KTRACE_ADD_CSF_KCPU(kbdev, KCPU_CQS_WAIT_END, |
---|
756 | 808 | queue, cqs_wait->objs[i].addr, |
---|
757 | 809 | error); |
---|
758 | 810 | |
---|
759 | 811 | KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_WAIT_END( |
---|
760 | | - kbdev, queue, |
---|
761 | | - evt[BASEP_EVENT_ERR_INDEX]); |
---|
| 812 | + kbdev, queue, evt[BASEP_EVENT32_ERR_OFFSET / sizeof(u32)]); |
---|
762 | 813 | queue->command_started = false; |
---|
763 | 814 | } |
---|
764 | 815 | |
---|
.. | .. |
---|
775 | 826 | return bitmap_full(cqs_wait->signaled, cqs_wait->nr_objs); |
---|
776 | 827 | } |
---|
777 | 828 | |
---|
| 829 | +static inline bool kbase_kcpu_cqs_is_data_type_valid(u8 data_type) |
---|
| 830 | +{ |
---|
| 831 | + return data_type == BASEP_CQS_DATA_TYPE_U32 || data_type == BASEP_CQS_DATA_TYPE_U64; |
---|
| 832 | +} |
---|
| 833 | + |
---|
| 834 | +static inline bool kbase_kcpu_cqs_is_aligned(u64 addr, u8 data_type) |
---|
| 835 | +{ |
---|
| 836 | + BUILD_BUG_ON(BASEP_EVENT32_ALIGN_BYTES != BASEP_EVENT32_SIZE_BYTES); |
---|
| 837 | + BUILD_BUG_ON(BASEP_EVENT64_ALIGN_BYTES != BASEP_EVENT64_SIZE_BYTES); |
---|
| 838 | + WARN_ON(!kbase_kcpu_cqs_is_data_type_valid(data_type)); |
---|
| 839 | + |
---|
| 840 | + switch (data_type) { |
---|
| 841 | + default: |
---|
| 842 | + return false; |
---|
| 843 | + case BASEP_CQS_DATA_TYPE_U32: |
---|
| 844 | + return (addr & (BASEP_EVENT32_ALIGN_BYTES - 1)) == 0; |
---|
| 845 | + case BASEP_CQS_DATA_TYPE_U64: |
---|
| 846 | + return (addr & (BASEP_EVENT64_ALIGN_BYTES - 1)) == 0; |
---|
| 847 | + } |
---|
| 848 | +} |
---|
| 849 | + |
---|
778 | 850 | static int kbase_kcpu_cqs_wait_prepare(struct kbase_kcpu_command_queue *queue, |
---|
779 | 851 | struct base_kcpu_command_cqs_wait_info *cqs_wait_info, |
---|
780 | 852 | struct kbase_kcpu_command *current_command) |
---|
781 | 853 | { |
---|
782 | 854 | struct base_cqs_wait_info *objs; |
---|
783 | 855 | unsigned int nr_objs = cqs_wait_info->nr_objs; |
---|
| 856 | + unsigned int i; |
---|
784 | 857 | |
---|
785 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 858 | + lockdep_assert_held(&queue->lock); |
---|
786 | 859 | |
---|
787 | 860 | if (nr_objs > BASEP_KCPU_CQS_MAX_NUM_OBJS) |
---|
788 | 861 | return -EINVAL; |
---|
.. | .. |
---|
798 | 871 | nr_objs * sizeof(*objs))) { |
---|
799 | 872 | kfree(objs); |
---|
800 | 873 | return -ENOMEM; |
---|
| 874 | + } |
---|
| 875 | + |
---|
| 876 | + /* Check the CQS objects as early as possible. By checking their alignment |
---|
| 877 | + * (required alignment equals to size for Sync32 and Sync64 objects), we can |
---|
| 878 | + * prevent overrunning the supplied event page. |
---|
| 879 | + */ |
---|
| 880 | + for (i = 0; i < nr_objs; i++) { |
---|
| 881 | + if (!kbase_kcpu_cqs_is_aligned(objs[i].addr, BASEP_CQS_DATA_TYPE_U32)) { |
---|
| 882 | + kfree(objs); |
---|
| 883 | + return -EINVAL; |
---|
| 884 | + } |
---|
801 | 885 | } |
---|
802 | 886 | |
---|
803 | 887 | if (++queue->cqs_wait_count == 1) { |
---|
.. | .. |
---|
836 | 920 | { |
---|
837 | 921 | unsigned int i; |
---|
838 | 922 | |
---|
839 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 923 | + lockdep_assert_held(&queue->lock); |
---|
840 | 924 | |
---|
841 | 925 | if (WARN_ON(!cqs_set->objs)) |
---|
842 | 926 | return; |
---|
.. | .. |
---|
848 | 932 | evt = (u32 *)kbase_phy_alloc_mapping_get( |
---|
849 | 933 | queue->kctx, cqs_set->objs[i].addr, &mapping); |
---|
850 | 934 | |
---|
851 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_SET(kbdev, queue, |
---|
852 | | - evt ? 0 : 1); |
---|
| 935 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_SET(kbdev, queue, evt ? 0 : 1); |
---|
853 | 936 | |
---|
854 | 937 | if (!evt) { |
---|
855 | 938 | dev_warn(kbdev->dev, |
---|
856 | 939 | "Sync memory %llx already freed", cqs_set->objs[i].addr); |
---|
857 | 940 | queue->has_error = true; |
---|
858 | 941 | } else { |
---|
859 | | - evt[BASEP_EVENT_ERR_INDEX] = queue->has_error; |
---|
| 942 | + evt[BASEP_EVENT32_ERR_OFFSET / sizeof(u32)] = queue->has_error; |
---|
860 | 943 | /* Set to signaled */ |
---|
861 | | - evt[BASEP_EVENT_VAL_INDEX]++; |
---|
| 944 | + evt[BASEP_EVENT32_VAL_OFFSET / sizeof(u32)]++; |
---|
862 | 945 | kbase_phy_alloc_mapping_put(queue->kctx, mapping); |
---|
863 | 946 | |
---|
864 | | - KBASE_KTRACE_ADD_CSF_KCPU(kbdev, CQS_SET, |
---|
865 | | - queue, cqs_set->objs[i].addr, |
---|
866 | | - evt[BASEP_EVENT_ERR_INDEX]); |
---|
| 947 | + KBASE_KTRACE_ADD_CSF_KCPU(kbdev, KCPU_CQS_SET, queue, cqs_set->objs[i].addr, |
---|
| 948 | + evt[BASEP_EVENT32_ERR_OFFSET / sizeof(u32)]); |
---|
867 | 949 | } |
---|
868 | 950 | } |
---|
869 | 951 | |
---|
.. | .. |
---|
878 | 960 | struct base_kcpu_command_cqs_set_info *cqs_set_info, |
---|
879 | 961 | struct kbase_kcpu_command *current_command) |
---|
880 | 962 | { |
---|
881 | | - struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
882 | 963 | struct base_cqs_set *objs; |
---|
883 | 964 | unsigned int nr_objs = cqs_set_info->nr_objs; |
---|
| 965 | + unsigned int i; |
---|
884 | 966 | |
---|
885 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 967 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
886 | 968 | |
---|
887 | 969 | if (nr_objs > BASEP_KCPU_CQS_MAX_NUM_OBJS) |
---|
888 | 970 | return -EINVAL; |
---|
.. | .. |
---|
898 | 980 | nr_objs * sizeof(*objs))) { |
---|
899 | 981 | kfree(objs); |
---|
900 | 982 | return -ENOMEM; |
---|
| 983 | + } |
---|
| 984 | + |
---|
| 985 | + /* Check the CQS objects as early as possible. By checking their alignment |
---|
| 986 | + * (required alignment equals to size for Sync32 and Sync64 objects), we can |
---|
| 987 | + * prevent overrunning the supplied event page. |
---|
| 988 | + */ |
---|
| 989 | + for (i = 0; i < nr_objs; i++) { |
---|
| 990 | + if (!kbase_kcpu_cqs_is_aligned(objs[i].addr, BASEP_CQS_DATA_TYPE_U32)) { |
---|
| 991 | + kfree(objs); |
---|
| 992 | + return -EINVAL; |
---|
| 993 | + } |
---|
901 | 994 | } |
---|
902 | 995 | |
---|
903 | 996 | current_command->type = BASE_KCPU_COMMAND_TYPE_CQS_SET; |
---|
.. | .. |
---|
932 | 1025 | { |
---|
933 | 1026 | u32 i; |
---|
934 | 1027 | |
---|
935 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 1028 | + lockdep_assert_held(&queue->lock); |
---|
936 | 1029 | |
---|
937 | 1030 | if (WARN_ON(!cqs_wait_operation->objs)) |
---|
938 | 1031 | return -EINVAL; |
---|
.. | .. |
---|
942 | 1035 | if (!test_bit(i, cqs_wait_operation->signaled)) { |
---|
943 | 1036 | struct kbase_vmap_struct *mapping; |
---|
944 | 1037 | bool sig_set; |
---|
945 | | - u64 *evt = (u64 *)kbase_phy_alloc_mapping_get(queue->kctx, |
---|
946 | | - cqs_wait_operation->objs[i].addr, &mapping); |
---|
| 1038 | + uintptr_t evt = (uintptr_t)kbase_phy_alloc_mapping_get( |
---|
| 1039 | + queue->kctx, cqs_wait_operation->objs[i].addr, &mapping); |
---|
| 1040 | + u64 val = 0; |
---|
947 | 1041 | |
---|
948 | | - /* GPUCORE-28172 RDT to review */ |
---|
949 | | - if (!queue->command_started) |
---|
| 1042 | + if (!queue->command_started) { |
---|
950 | 1043 | queue->command_started = true; |
---|
| 1044 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_WAIT_OPERATION_START( |
---|
| 1045 | + kbdev, queue); |
---|
| 1046 | + } |
---|
| 1047 | + |
---|
951 | 1048 | |
---|
952 | 1049 | if (!evt) { |
---|
953 | 1050 | dev_warn(kbdev->dev, |
---|
.. | .. |
---|
956 | 1053 | return -EINVAL; |
---|
957 | 1054 | } |
---|
958 | 1055 | |
---|
| 1056 | + switch (cqs_wait_operation->objs[i].data_type) { |
---|
| 1057 | + default: |
---|
| 1058 | + WARN_ON(!kbase_kcpu_cqs_is_data_type_valid( |
---|
| 1059 | + cqs_wait_operation->objs[i].data_type)); |
---|
| 1060 | + kbase_phy_alloc_mapping_put(queue->kctx, mapping); |
---|
| 1061 | + queue->has_error = true; |
---|
| 1062 | + return -EINVAL; |
---|
| 1063 | + case BASEP_CQS_DATA_TYPE_U32: |
---|
| 1064 | + val = *(u32 *)evt; |
---|
| 1065 | + evt += BASEP_EVENT32_ERR_OFFSET - BASEP_EVENT32_VAL_OFFSET; |
---|
| 1066 | + break; |
---|
| 1067 | + case BASEP_CQS_DATA_TYPE_U64: |
---|
| 1068 | + val = *(u64 *)evt; |
---|
| 1069 | + evt += BASEP_EVENT64_ERR_OFFSET - BASEP_EVENT64_VAL_OFFSET; |
---|
| 1070 | + break; |
---|
| 1071 | + } |
---|
| 1072 | + |
---|
959 | 1073 | switch (cqs_wait_operation->objs[i].operation) { |
---|
960 | 1074 | case BASEP_CQS_WAIT_OPERATION_LE: |
---|
961 | | - sig_set = *evt <= cqs_wait_operation->objs[i].val; |
---|
| 1075 | + sig_set = val <= cqs_wait_operation->objs[i].val; |
---|
962 | 1076 | break; |
---|
963 | 1077 | case BASEP_CQS_WAIT_OPERATION_GT: |
---|
964 | | - sig_set = *evt > cqs_wait_operation->objs[i].val; |
---|
| 1078 | + sig_set = val > cqs_wait_operation->objs[i].val; |
---|
965 | 1079 | break; |
---|
966 | 1080 | default: |
---|
967 | | - dev_warn(kbdev->dev, |
---|
| 1081 | + dev_dbg(kbdev->dev, |
---|
968 | 1082 | "Unsupported CQS wait operation %d", cqs_wait_operation->objs[i].operation); |
---|
969 | 1083 | |
---|
970 | 1084 | kbase_phy_alloc_mapping_put(queue->kctx, mapping); |
---|
.. | .. |
---|
973 | 1087 | return -EINVAL; |
---|
974 | 1088 | } |
---|
975 | 1089 | |
---|
976 | | - /* Increment evt up to the error_state value depending on the CQS data type */ |
---|
977 | | - switch (cqs_wait_operation->objs[i].data_type) { |
---|
978 | | - default: |
---|
979 | | - dev_warn(kbdev->dev, "Unreachable data_type=%d", cqs_wait_operation->objs[i].data_type); |
---|
980 | | - /* Fallthrough - hint to compiler that there's really only 2 options at present */ |
---|
981 | | - case BASEP_CQS_DATA_TYPE_U32: |
---|
982 | | - evt = (u64 *)((u8 *)evt + sizeof(u32)); |
---|
983 | | - break; |
---|
984 | | - case BASEP_CQS_DATA_TYPE_U64: |
---|
985 | | - evt = (u64 *)((u8 *)evt + sizeof(u64)); |
---|
986 | | - break; |
---|
987 | | - } |
---|
988 | | - |
---|
989 | 1090 | if (sig_set) { |
---|
990 | 1091 | bitmap_set(cqs_wait_operation->signaled, i, 1); |
---|
991 | 1092 | if ((cqs_wait_operation->inherit_err_flags & (1U << i)) && |
---|
992 | | - *evt > 0) { |
---|
| 1093 | + *(u32 *)evt > 0) { |
---|
993 | 1094 | queue->has_error = true; |
---|
994 | 1095 | } |
---|
995 | 1096 | |
---|
996 | | - /* GPUCORE-28172 RDT to review */ |
---|
| 1097 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_WAIT_OPERATION_END( |
---|
| 1098 | + kbdev, queue, *(u32 *)evt); |
---|
997 | 1099 | |
---|
998 | 1100 | queue->command_started = false; |
---|
999 | 1101 | } |
---|
.. | .. |
---|
1017 | 1119 | { |
---|
1018 | 1120 | struct base_cqs_wait_operation_info *objs; |
---|
1019 | 1121 | unsigned int nr_objs = cqs_wait_operation_info->nr_objs; |
---|
| 1122 | + unsigned int i; |
---|
1020 | 1123 | |
---|
1021 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 1124 | + lockdep_assert_held(&queue->lock); |
---|
1022 | 1125 | |
---|
1023 | 1126 | if (nr_objs > BASEP_KCPU_CQS_MAX_NUM_OBJS) |
---|
1024 | 1127 | return -EINVAL; |
---|
.. | .. |
---|
1034 | 1137 | nr_objs * sizeof(*objs))) { |
---|
1035 | 1138 | kfree(objs); |
---|
1036 | 1139 | return -ENOMEM; |
---|
| 1140 | + } |
---|
| 1141 | + |
---|
| 1142 | + /* Check the CQS objects as early as possible. By checking their alignment |
---|
| 1143 | + * (required alignment equals to size for Sync32 and Sync64 objects), we can |
---|
| 1144 | + * prevent overrunning the supplied event page. |
---|
| 1145 | + */ |
---|
| 1146 | + for (i = 0; i < nr_objs; i++) { |
---|
| 1147 | + if (!kbase_kcpu_cqs_is_data_type_valid(objs[i].data_type) || |
---|
| 1148 | + !kbase_kcpu_cqs_is_aligned(objs[i].addr, objs[i].data_type)) { |
---|
| 1149 | + kfree(objs); |
---|
| 1150 | + return -EINVAL; |
---|
| 1151 | + } |
---|
1037 | 1152 | } |
---|
1038 | 1153 | |
---|
1039 | 1154 | if (++queue->cqs_wait_count == 1) { |
---|
.. | .. |
---|
1066 | 1181 | return 0; |
---|
1067 | 1182 | } |
---|
1068 | 1183 | |
---|
| 1184 | +static void kbasep_kcpu_cqs_do_set_operation_32(struct kbase_kcpu_command_queue *queue, |
---|
| 1185 | + uintptr_t evt, u8 operation, u64 val) |
---|
| 1186 | +{ |
---|
| 1187 | + struct kbase_device *kbdev = queue->kctx->kbdev; |
---|
| 1188 | + |
---|
| 1189 | + switch (operation) { |
---|
| 1190 | + case BASEP_CQS_SET_OPERATION_ADD: |
---|
| 1191 | + *(u32 *)evt += (u32)val; |
---|
| 1192 | + break; |
---|
| 1193 | + case BASEP_CQS_SET_OPERATION_SET: |
---|
| 1194 | + *(u32 *)evt = val; |
---|
| 1195 | + break; |
---|
| 1196 | + default: |
---|
| 1197 | + dev_dbg(kbdev->dev, "Unsupported CQS set operation %d", operation); |
---|
| 1198 | + queue->has_error = true; |
---|
| 1199 | + break; |
---|
| 1200 | + } |
---|
| 1201 | +} |
---|
| 1202 | + |
---|
| 1203 | +static void kbasep_kcpu_cqs_do_set_operation_64(struct kbase_kcpu_command_queue *queue, |
---|
| 1204 | + uintptr_t evt, u8 operation, u64 val) |
---|
| 1205 | +{ |
---|
| 1206 | + struct kbase_device *kbdev = queue->kctx->kbdev; |
---|
| 1207 | + |
---|
| 1208 | + switch (operation) { |
---|
| 1209 | + case BASEP_CQS_SET_OPERATION_ADD: |
---|
| 1210 | + *(u64 *)evt += val; |
---|
| 1211 | + break; |
---|
| 1212 | + case BASEP_CQS_SET_OPERATION_SET: |
---|
| 1213 | + *(u64 *)evt = val; |
---|
| 1214 | + break; |
---|
| 1215 | + default: |
---|
| 1216 | + dev_dbg(kbdev->dev, "Unsupported CQS set operation %d", operation); |
---|
| 1217 | + queue->has_error = true; |
---|
| 1218 | + break; |
---|
| 1219 | + } |
---|
| 1220 | +} |
---|
| 1221 | + |
---|
1069 | 1222 | static void kbase_kcpu_cqs_set_operation_process( |
---|
1070 | 1223 | struct kbase_device *kbdev, |
---|
1071 | 1224 | struct kbase_kcpu_command_queue *queue, |
---|
.. | .. |
---|
1073 | 1226 | { |
---|
1074 | 1227 | unsigned int i; |
---|
1075 | 1228 | |
---|
1076 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 1229 | + lockdep_assert_held(&queue->lock); |
---|
1077 | 1230 | |
---|
1078 | 1231 | if (WARN_ON(!cqs_set_operation->objs)) |
---|
1079 | 1232 | return; |
---|
1080 | 1233 | |
---|
1081 | 1234 | for (i = 0; i < cqs_set_operation->nr_objs; i++) { |
---|
1082 | 1235 | struct kbase_vmap_struct *mapping; |
---|
1083 | | - u64 *evt; |
---|
| 1236 | + uintptr_t evt; |
---|
1084 | 1237 | |
---|
1085 | | - evt = (u64 *)kbase_phy_alloc_mapping_get( |
---|
| 1238 | + evt = (uintptr_t)kbase_phy_alloc_mapping_get( |
---|
1086 | 1239 | queue->kctx, cqs_set_operation->objs[i].addr, &mapping); |
---|
1087 | | - |
---|
1088 | | - /* GPUCORE-28172 RDT to review */ |
---|
1089 | 1240 | |
---|
1090 | 1241 | if (!evt) { |
---|
1091 | 1242 | dev_warn(kbdev->dev, |
---|
1092 | 1243 | "Sync memory %llx already freed", cqs_set_operation->objs[i].addr); |
---|
1093 | 1244 | queue->has_error = true; |
---|
1094 | 1245 | } else { |
---|
1095 | | - switch (cqs_set_operation->objs[i].operation) { |
---|
1096 | | - case BASEP_CQS_SET_OPERATION_ADD: |
---|
1097 | | - *evt += cqs_set_operation->objs[i].val; |
---|
1098 | | - break; |
---|
1099 | | - case BASEP_CQS_SET_OPERATION_SET: |
---|
1100 | | - *evt = cqs_set_operation->objs[i].val; |
---|
1101 | | - break; |
---|
1102 | | - default: |
---|
1103 | | - dev_warn(kbdev->dev, |
---|
1104 | | - "Unsupported CQS set operation %d", cqs_set_operation->objs[i].operation); |
---|
1105 | | - queue->has_error = true; |
---|
1106 | | - break; |
---|
1107 | | - } |
---|
| 1246 | + struct base_cqs_set_operation_info *obj = &cqs_set_operation->objs[i]; |
---|
1108 | 1247 | |
---|
1109 | | - /* Increment evt up to the error_state value depending on the CQS data type */ |
---|
1110 | | - switch (cqs_set_operation->objs[i].data_type) { |
---|
| 1248 | + switch (obj->data_type) { |
---|
1111 | 1249 | default: |
---|
1112 | | - dev_warn(kbdev->dev, "Unreachable data_type=%d", cqs_set_operation->objs[i].data_type); |
---|
1113 | | - /* Fallthrough - hint to compiler that there's really only 2 options at present */ |
---|
| 1250 | + WARN_ON(!kbase_kcpu_cqs_is_data_type_valid(obj->data_type)); |
---|
| 1251 | + queue->has_error = true; |
---|
| 1252 | + goto skip_err_propagation; |
---|
1114 | 1253 | case BASEP_CQS_DATA_TYPE_U32: |
---|
1115 | | - evt = (u64 *)((u8 *)evt + sizeof(u32)); |
---|
| 1254 | + kbasep_kcpu_cqs_do_set_operation_32(queue, evt, obj->operation, |
---|
| 1255 | + obj->val); |
---|
| 1256 | + evt += BASEP_EVENT32_ERR_OFFSET - BASEP_EVENT32_VAL_OFFSET; |
---|
1116 | 1257 | break; |
---|
1117 | 1258 | case BASEP_CQS_DATA_TYPE_U64: |
---|
1118 | | - evt = (u64 *)((u8 *)evt + sizeof(u64)); |
---|
| 1259 | + kbasep_kcpu_cqs_do_set_operation_64(queue, evt, obj->operation, |
---|
| 1260 | + obj->val); |
---|
| 1261 | + evt += BASEP_EVENT64_ERR_OFFSET - BASEP_EVENT64_VAL_OFFSET; |
---|
1119 | 1262 | break; |
---|
1120 | 1263 | } |
---|
1121 | 1264 | |
---|
1122 | | - /* GPUCORE-28172 RDT to review */ |
---|
| 1265 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_CQS_SET_OPERATION( |
---|
| 1266 | + kbdev, queue, *(u32 *)evt ? 1 : 0); |
---|
1123 | 1267 | |
---|
1124 | 1268 | /* Always propagate errors */ |
---|
1125 | | - *evt = queue->has_error; |
---|
| 1269 | + *(u32 *)evt = queue->has_error; |
---|
1126 | 1270 | |
---|
| 1271 | +skip_err_propagation: |
---|
1127 | 1272 | kbase_phy_alloc_mapping_put(queue->kctx, mapping); |
---|
1128 | 1273 | } |
---|
1129 | 1274 | } |
---|
.. | .. |
---|
1139 | 1284 | struct base_kcpu_command_cqs_set_operation_info *cqs_set_operation_info, |
---|
1140 | 1285 | struct kbase_kcpu_command *current_command) |
---|
1141 | 1286 | { |
---|
1142 | | - struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1143 | 1287 | struct base_cqs_set_operation_info *objs; |
---|
1144 | 1288 | unsigned int nr_objs = cqs_set_operation_info->nr_objs; |
---|
| 1289 | + unsigned int i; |
---|
1145 | 1290 | |
---|
1146 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 1291 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
1147 | 1292 | |
---|
1148 | 1293 | if (nr_objs > BASEP_KCPU_CQS_MAX_NUM_OBJS) |
---|
1149 | 1294 | return -EINVAL; |
---|
.. | .. |
---|
1159 | 1304 | nr_objs * sizeof(*objs))) { |
---|
1160 | 1305 | kfree(objs); |
---|
1161 | 1306 | return -ENOMEM; |
---|
| 1307 | + } |
---|
| 1308 | + |
---|
| 1309 | + /* Check the CQS objects as early as possible. By checking their alignment |
---|
| 1310 | + * (required alignment equals to size for Sync32 and Sync64 objects), we can |
---|
| 1311 | + * prevent overrunning the supplied event page. |
---|
| 1312 | + */ |
---|
| 1313 | + for (i = 0; i < nr_objs; i++) { |
---|
| 1314 | + if (!kbase_kcpu_cqs_is_data_type_valid(objs[i].data_type) || |
---|
| 1315 | + !kbase_kcpu_cqs_is_aligned(objs[i].addr, objs[i].data_type)) { |
---|
| 1316 | + kfree(objs); |
---|
| 1317 | + return -EINVAL; |
---|
| 1318 | + } |
---|
1162 | 1319 | } |
---|
1163 | 1320 | |
---|
1164 | 1321 | current_command->type = BASE_KCPU_COMMAND_TYPE_CQS_SET_OPERATION; |
---|
.. | .. |
---|
1182 | 1339 | struct kbase_kcpu_command_queue *kcpu_queue = fence_info->kcpu_queue; |
---|
1183 | 1340 | struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1184 | 1341 | |
---|
1185 | | - KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, FENCE_WAIT_END, kcpu_queue, |
---|
| 1342 | +#ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG |
---|
| 1343 | + /* Fence gets signaled. Deactivate the timer for fence-wait timeout */ |
---|
| 1344 | + del_timer(&kcpu_queue->fence_timeout); |
---|
| 1345 | +#endif |
---|
| 1346 | + KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_FENCE_WAIT_END, kcpu_queue, |
---|
1186 | 1347 | fence->context, fence->seqno); |
---|
1187 | 1348 | |
---|
1188 | 1349 | /* Resume kcpu command queue processing. */ |
---|
1189 | | - queue_work(kctx->csf.kcpu_queues.wq, &kcpu_queue->work); |
---|
| 1350 | + queue_work(kcpu_queue->wq, &kcpu_queue->work); |
---|
1190 | 1351 | } |
---|
1191 | 1352 | |
---|
1192 | | -static void kbase_kcpu_fence_wait_cancel( |
---|
1193 | | - struct kbase_kcpu_command_queue *kcpu_queue, |
---|
1194 | | - struct kbase_kcpu_command_fence_info *fence_info) |
---|
| 1353 | +static void kbasep_kcpu_fence_wait_cancel(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1354 | + struct kbase_kcpu_command_fence_info *fence_info) |
---|
1195 | 1355 | { |
---|
1196 | 1356 | struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1197 | 1357 | |
---|
1198 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 1358 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
1199 | 1359 | |
---|
1200 | 1360 | if (WARN_ON(!fence_info->fence)) |
---|
1201 | 1361 | return; |
---|
.. | .. |
---|
1204 | 1364 | bool removed = dma_fence_remove_callback(fence_info->fence, |
---|
1205 | 1365 | &fence_info->fence_cb); |
---|
1206 | 1366 | |
---|
| 1367 | +#ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG |
---|
| 1368 | + /* Fence-wait cancelled or fence signaled. In the latter case |
---|
| 1369 | + * the timer would already have been deactivated inside |
---|
| 1370 | + * kbase_csf_fence_wait_callback(). |
---|
| 1371 | + */ |
---|
| 1372 | + del_timer_sync(&kcpu_queue->fence_timeout); |
---|
| 1373 | +#endif |
---|
1207 | 1374 | if (removed) |
---|
1208 | | - KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, FENCE_WAIT_END, |
---|
| 1375 | + KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_FENCE_WAIT_END, |
---|
1209 | 1376 | kcpu_queue, fence_info->fence->context, |
---|
1210 | 1377 | fence_info->fence->seqno); |
---|
1211 | 1378 | } |
---|
.. | .. |
---|
1216 | 1383 | |
---|
1217 | 1384 | fence_info->fence = NULL; |
---|
1218 | 1385 | } |
---|
| 1386 | + |
---|
| 1387 | +#ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG |
---|
| 1388 | +/** |
---|
| 1389 | + * fence_timeout_callback() - Timeout callback function for fence-wait |
---|
| 1390 | + * |
---|
| 1391 | + * @timer: Timer struct |
---|
| 1392 | + * |
---|
| 1393 | + * Context and seqno of the timed-out fence will be displayed in dmesg. |
---|
| 1394 | + * If the fence has been signalled a work will be enqueued to process |
---|
| 1395 | + * the fence-wait without displaying debugging information. |
---|
| 1396 | + */ |
---|
| 1397 | +static void fence_timeout_callback(struct timer_list *timer) |
---|
| 1398 | +{ |
---|
| 1399 | + struct kbase_kcpu_command_queue *kcpu_queue = |
---|
| 1400 | + container_of(timer, struct kbase_kcpu_command_queue, fence_timeout); |
---|
| 1401 | + struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
| 1402 | + struct kbase_kcpu_command *cmd = &kcpu_queue->commands[kcpu_queue->start_offset]; |
---|
| 1403 | + struct kbase_kcpu_command_fence_info *fence_info; |
---|
| 1404 | +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) |
---|
| 1405 | + struct fence *fence; |
---|
| 1406 | +#else |
---|
| 1407 | + struct dma_fence *fence; |
---|
| 1408 | +#endif |
---|
| 1409 | + struct kbase_sync_fence_info info; |
---|
| 1410 | + |
---|
| 1411 | + if (cmd->type != BASE_KCPU_COMMAND_TYPE_FENCE_WAIT) { |
---|
| 1412 | + dev_err(kctx->kbdev->dev, |
---|
| 1413 | + "%s: Unexpected command type %d in ctx:%d_%d kcpu queue:%u", __func__, |
---|
| 1414 | + cmd->type, kctx->tgid, kctx->id, kcpu_queue->id); |
---|
| 1415 | + return; |
---|
| 1416 | + } |
---|
| 1417 | + |
---|
| 1418 | + fence_info = &cmd->info.fence; |
---|
| 1419 | + |
---|
| 1420 | + fence = kbase_fence_get(fence_info); |
---|
| 1421 | + if (!fence) { |
---|
| 1422 | + dev_err(kctx->kbdev->dev, "no fence found in ctx:%d_%d kcpu queue:%u", kctx->tgid, |
---|
| 1423 | + kctx->id, kcpu_queue->id); |
---|
| 1424 | + return; |
---|
| 1425 | + } |
---|
| 1426 | + |
---|
| 1427 | + kbase_sync_fence_info_get(fence, &info); |
---|
| 1428 | + |
---|
| 1429 | + if (info.status == 1) { |
---|
| 1430 | + queue_work(kcpu_queue->wq, &kcpu_queue->work); |
---|
| 1431 | + } else if (info.status == 0) { |
---|
| 1432 | + dev_warn(kctx->kbdev->dev, "fence has not yet signalled in %ums", |
---|
| 1433 | + FENCE_WAIT_TIMEOUT_MS); |
---|
| 1434 | + dev_warn(kctx->kbdev->dev, |
---|
| 1435 | + "ctx:%d_%d kcpu queue:%u still waiting for fence[%pK] context#seqno:%s", |
---|
| 1436 | + kctx->tgid, kctx->id, kcpu_queue->id, fence, info.name); |
---|
| 1437 | + } else { |
---|
| 1438 | + dev_warn(kctx->kbdev->dev, "fence has got error"); |
---|
| 1439 | + dev_warn(kctx->kbdev->dev, |
---|
| 1440 | + "ctx:%d_%d kcpu queue:%u faulty fence[%pK] context#seqno:%s error(%d)", |
---|
| 1441 | + kctx->tgid, kctx->id, kcpu_queue->id, fence, info.name, info.status); |
---|
| 1442 | + } |
---|
| 1443 | + |
---|
| 1444 | + kbase_fence_put(fence); |
---|
| 1445 | +} |
---|
| 1446 | + |
---|
| 1447 | +/** |
---|
| 1448 | + * fence_timeout_start() - Start a timer to check fence-wait timeout |
---|
| 1449 | + * |
---|
| 1450 | + * @cmd: KCPU command queue |
---|
| 1451 | + * |
---|
| 1452 | + * Activate a timer to check whether a fence-wait command in the queue |
---|
| 1453 | + * gets completed within FENCE_WAIT_TIMEOUT_MS |
---|
| 1454 | + */ |
---|
| 1455 | +static void fence_timeout_start(struct kbase_kcpu_command_queue *cmd) |
---|
| 1456 | +{ |
---|
| 1457 | + mod_timer(&cmd->fence_timeout, jiffies + msecs_to_jiffies(FENCE_WAIT_TIMEOUT_MS)); |
---|
| 1458 | +} |
---|
| 1459 | +#endif |
---|
1219 | 1460 | |
---|
1220 | 1461 | /** |
---|
1221 | 1462 | * kbase_kcpu_fence_wait_process() - Process the kcpu fence wait command |
---|
.. | .. |
---|
1236 | 1477 | #else |
---|
1237 | 1478 | struct dma_fence *fence; |
---|
1238 | 1479 | #endif |
---|
| 1480 | + struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1239 | 1481 | |
---|
1240 | | - lockdep_assert_held(&kcpu_queue->kctx->csf.kcpu_queues.lock); |
---|
| 1482 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
1241 | 1483 | |
---|
1242 | 1484 | if (WARN_ON(!fence_info->fence)) |
---|
1243 | 1485 | return -EINVAL; |
---|
.. | .. |
---|
1251 | 1493 | &fence_info->fence_cb, |
---|
1252 | 1494 | kbase_csf_fence_wait_callback); |
---|
1253 | 1495 | |
---|
1254 | | - KBASE_KTRACE_ADD_CSF_KCPU(kcpu_queue->kctx->kbdev, |
---|
1255 | | - FENCE_WAIT_START, kcpu_queue, |
---|
| 1496 | + KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, |
---|
| 1497 | + KCPU_FENCE_WAIT_START, kcpu_queue, |
---|
1256 | 1498 | fence->context, fence->seqno); |
---|
1257 | 1499 | fence_status = cb_err; |
---|
1258 | | - if (cb_err == 0) |
---|
| 1500 | + if (cb_err == 0) { |
---|
1259 | 1501 | kcpu_queue->fence_wait_processed = true; |
---|
1260 | | - else if (cb_err == -ENOENT) |
---|
| 1502 | +#ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG |
---|
| 1503 | + fence_timeout_start(kcpu_queue); |
---|
| 1504 | +#endif |
---|
| 1505 | + } else if (cb_err == -ENOENT) { |
---|
1261 | 1506 | fence_status = dma_fence_get_status(fence); |
---|
| 1507 | + if (!fence_status) { |
---|
| 1508 | + struct kbase_sync_fence_info info; |
---|
| 1509 | + |
---|
| 1510 | + kbase_sync_fence_info_get(fence, &info); |
---|
| 1511 | + dev_warn(kctx->kbdev->dev, |
---|
| 1512 | + "Unexpected status for fence %s of ctx:%d_%d kcpu queue:%u", |
---|
| 1513 | + info.name, kctx->tgid, kctx->id, kcpu_queue->id); |
---|
| 1514 | + } |
---|
| 1515 | + } |
---|
1262 | 1516 | } |
---|
1263 | 1517 | |
---|
1264 | 1518 | /* |
---|
.. | .. |
---|
1271 | 1525 | */ |
---|
1272 | 1526 | |
---|
1273 | 1527 | if (fence_status) |
---|
1274 | | - kbase_kcpu_fence_wait_cancel(kcpu_queue, fence_info); |
---|
| 1528 | + kbasep_kcpu_fence_wait_cancel(kcpu_queue, fence_info); |
---|
1275 | 1529 | |
---|
1276 | 1530 | return fence_status; |
---|
1277 | 1531 | } |
---|
1278 | 1532 | |
---|
1279 | | -static int kbase_kcpu_fence_wait_prepare( |
---|
1280 | | - struct kbase_kcpu_command_queue *kcpu_queue, |
---|
1281 | | - struct base_kcpu_command_fence_info *fence_info, |
---|
1282 | | - struct kbase_kcpu_command *current_command) |
---|
| 1533 | +static int kbase_kcpu_fence_wait_prepare(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1534 | + struct base_kcpu_command_fence_info *fence_info, |
---|
| 1535 | + struct kbase_kcpu_command *current_command) |
---|
1283 | 1536 | { |
---|
1284 | | - struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1285 | 1537 | #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) |
---|
1286 | 1538 | struct fence *fence_in; |
---|
1287 | 1539 | #else |
---|
.. | .. |
---|
1289 | 1541 | #endif |
---|
1290 | 1542 | struct base_fence fence; |
---|
1291 | 1543 | |
---|
1292 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 1544 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
1293 | 1545 | |
---|
1294 | | - if (copy_from_user(&fence, u64_to_user_ptr(fence_info->fence), |
---|
1295 | | - sizeof(fence))) |
---|
| 1546 | + if (copy_from_user(&fence, u64_to_user_ptr(fence_info->fence), sizeof(fence))) |
---|
1296 | 1547 | return -ENOMEM; |
---|
1297 | 1548 | |
---|
1298 | 1549 | fence_in = sync_file_get_fence(fence.basep.fd); |
---|
.. | .. |
---|
1303 | 1554 | current_command->type = BASE_KCPU_COMMAND_TYPE_FENCE_WAIT; |
---|
1304 | 1555 | current_command->info.fence.fence = fence_in; |
---|
1305 | 1556 | current_command->info.fence.kcpu_queue = kcpu_queue; |
---|
1306 | | - |
---|
1307 | 1557 | return 0; |
---|
1308 | 1558 | } |
---|
1309 | 1559 | |
---|
1310 | | -static int kbase_kcpu_fence_signal_process( |
---|
1311 | | - struct kbase_kcpu_command_queue *kcpu_queue, |
---|
1312 | | - struct kbase_kcpu_command_fence_info *fence_info) |
---|
| 1560 | +static int kbasep_kcpu_fence_signal_process(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1561 | + struct kbase_kcpu_command_fence_info *fence_info) |
---|
1313 | 1562 | { |
---|
1314 | 1563 | struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1315 | 1564 | int ret; |
---|
.. | .. |
---|
1320 | 1569 | ret = dma_fence_signal(fence_info->fence); |
---|
1321 | 1570 | |
---|
1322 | 1571 | if (unlikely(ret < 0)) { |
---|
1323 | | - dev_warn(kctx->kbdev->dev, |
---|
1324 | | - "fence_signal() failed with %d\n", ret); |
---|
| 1572 | + dev_warn(kctx->kbdev->dev, "dma_fence(%d) has been signalled already\n", ret); |
---|
| 1573 | + /* Treated as a success */ |
---|
| 1574 | + ret = 0; |
---|
1325 | 1575 | } |
---|
1326 | 1576 | |
---|
1327 | | - KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, FENCE_SIGNAL, kcpu_queue, |
---|
| 1577 | + KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_FENCE_SIGNAL, kcpu_queue, |
---|
1328 | 1578 | fence_info->fence->context, |
---|
1329 | 1579 | fence_info->fence->seqno); |
---|
1330 | 1580 | |
---|
1331 | | - dma_fence_put(fence_info->fence); |
---|
| 1581 | + /* dma_fence refcount needs to be decreased to release it. */ |
---|
| 1582 | + kbase_fence_put(fence_info->fence); |
---|
1332 | 1583 | fence_info->fence = NULL; |
---|
1333 | 1584 | |
---|
1334 | 1585 | return ret; |
---|
1335 | 1586 | } |
---|
1336 | 1587 | |
---|
1337 | | -static int kbase_kcpu_fence_signal_prepare( |
---|
1338 | | - struct kbase_kcpu_command_queue *kcpu_queue, |
---|
1339 | | - struct base_kcpu_command_fence_info *fence_info, |
---|
1340 | | - struct kbase_kcpu_command *current_command) |
---|
| 1588 | +static int kbasep_kcpu_fence_signal_init(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1589 | + struct kbase_kcpu_command *current_command, |
---|
| 1590 | + struct base_fence *fence, struct sync_file **sync_file, |
---|
| 1591 | + int *fd) |
---|
1341 | 1592 | { |
---|
1342 | | - struct kbase_context *const kctx = kcpu_queue->kctx; |
---|
1343 | 1593 | #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) |
---|
1344 | 1594 | struct fence *fence_out; |
---|
1345 | 1595 | #else |
---|
1346 | 1596 | struct dma_fence *fence_out; |
---|
1347 | 1597 | #endif |
---|
1348 | | - struct base_fence fence; |
---|
1349 | | - struct sync_file *sync_file; |
---|
| 1598 | + struct kbase_kcpu_dma_fence *kcpu_fence; |
---|
1350 | 1599 | int ret = 0; |
---|
1351 | | - int fd; |
---|
1352 | 1600 | |
---|
1353 | | - lockdep_assert_held(&kctx->csf.kcpu_queues.lock); |
---|
| 1601 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
1354 | 1602 | |
---|
1355 | | - if (copy_from_user(&fence, u64_to_user_ptr(fence_info->fence), |
---|
1356 | | - sizeof(fence))) |
---|
1357 | | - return -EFAULT; |
---|
1358 | | - |
---|
1359 | | - fence_out = kzalloc(sizeof(*fence_out), GFP_KERNEL); |
---|
1360 | | - if (!fence_out) |
---|
| 1603 | + kcpu_fence = kzalloc(sizeof(*kcpu_fence), GFP_KERNEL); |
---|
| 1604 | + if (!kcpu_fence) |
---|
1361 | 1605 | return -ENOMEM; |
---|
| 1606 | + |
---|
| 1607 | +#if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE) |
---|
| 1608 | + fence_out = (struct fence *)kcpu_fence; |
---|
| 1609 | +#else |
---|
| 1610 | + fence_out = (struct dma_fence *)kcpu_fence; |
---|
| 1611 | +#endif |
---|
1362 | 1612 | |
---|
1363 | 1613 | dma_fence_init(fence_out, |
---|
1364 | 1614 | &kbase_fence_ops, |
---|
.. | .. |
---|
1375 | 1625 | dma_fence_get(fence_out); |
---|
1376 | 1626 | #endif |
---|
1377 | 1627 | |
---|
| 1628 | + /* Set reference to KCPU metadata and increment refcount */ |
---|
| 1629 | + kcpu_fence->metadata = kcpu_queue->metadata; |
---|
| 1630 | + WARN_ON(!kbase_refcount_inc_not_zero(&kcpu_fence->metadata->refcount)); |
---|
| 1631 | + |
---|
1378 | 1632 | /* create a sync_file fd representing the fence */ |
---|
1379 | | - sync_file = sync_file_create(fence_out); |
---|
1380 | | - if (!sync_file) { |
---|
1381 | | -#if (KERNEL_VERSION(4, 9, 67) >= LINUX_VERSION_CODE) |
---|
1382 | | - dma_fence_put(fence_out); |
---|
1383 | | -#endif |
---|
| 1633 | + *sync_file = sync_file_create(fence_out); |
---|
| 1634 | + if (!(*sync_file)) { |
---|
1384 | 1635 | ret = -ENOMEM; |
---|
1385 | 1636 | goto file_create_fail; |
---|
1386 | 1637 | } |
---|
1387 | 1638 | |
---|
1388 | | - fd = get_unused_fd_flags(O_CLOEXEC); |
---|
1389 | | - if (fd < 0) { |
---|
1390 | | - ret = fd; |
---|
| 1639 | + *fd = get_unused_fd_flags(O_CLOEXEC); |
---|
| 1640 | + if (*fd < 0) { |
---|
| 1641 | + ret = *fd; |
---|
1391 | 1642 | goto fd_flags_fail; |
---|
1392 | 1643 | } |
---|
1393 | 1644 | |
---|
1394 | | - fd_install(fd, sync_file->file); |
---|
1395 | | - |
---|
1396 | | - fence.basep.fd = fd; |
---|
| 1645 | + fence->basep.fd = *fd; |
---|
1397 | 1646 | |
---|
1398 | 1647 | current_command->type = BASE_KCPU_COMMAND_TYPE_FENCE_SIGNAL; |
---|
1399 | 1648 | current_command->info.fence.fence = fence_out; |
---|
1400 | 1649 | |
---|
1401 | | - if (copy_to_user(u64_to_user_ptr(fence_info->fence), &fence, |
---|
1402 | | - sizeof(fence))) { |
---|
1403 | | - ret = -EFAULT; |
---|
1404 | | - goto fd_flags_fail; |
---|
1405 | | - } |
---|
1406 | | - |
---|
1407 | 1650 | return 0; |
---|
1408 | 1651 | |
---|
1409 | 1652 | fd_flags_fail: |
---|
1410 | | - fput(sync_file->file); |
---|
| 1653 | + fput((*sync_file)->file); |
---|
1411 | 1654 | file_create_fail: |
---|
1412 | | - dma_fence_put(fence_out); |
---|
| 1655 | + /* |
---|
| 1656 | + * Upon failure, dma_fence refcount that was increased by |
---|
| 1657 | + * dma_fence_get() or sync_file_create() needs to be decreased |
---|
| 1658 | + * to release it. |
---|
| 1659 | + */ |
---|
| 1660 | + kbase_fence_put(fence_out); |
---|
| 1661 | + current_command->info.fence.fence = NULL; |
---|
1413 | 1662 | |
---|
1414 | 1663 | return ret; |
---|
1415 | 1664 | } |
---|
| 1665 | + |
---|
| 1666 | +static int kbase_kcpu_fence_signal_prepare(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1667 | + struct base_kcpu_command_fence_info *fence_info, |
---|
| 1668 | + struct kbase_kcpu_command *current_command) |
---|
| 1669 | +{ |
---|
| 1670 | + struct base_fence fence; |
---|
| 1671 | + struct sync_file *sync_file = NULL; |
---|
| 1672 | + int fd; |
---|
| 1673 | + int ret = 0; |
---|
| 1674 | + |
---|
| 1675 | + lockdep_assert_held(&kcpu_queue->lock); |
---|
| 1676 | + |
---|
| 1677 | + if (copy_from_user(&fence, u64_to_user_ptr(fence_info->fence), sizeof(fence))) |
---|
| 1678 | + return -EFAULT; |
---|
| 1679 | + |
---|
| 1680 | + ret = kbasep_kcpu_fence_signal_init(kcpu_queue, current_command, &fence, &sync_file, &fd); |
---|
| 1681 | + if (ret) |
---|
| 1682 | + return ret; |
---|
| 1683 | + |
---|
| 1684 | + if (copy_to_user(u64_to_user_ptr(fence_info->fence), &fence, |
---|
| 1685 | + sizeof(fence))) { |
---|
| 1686 | + ret = -EFAULT; |
---|
| 1687 | + goto fail; |
---|
| 1688 | + } |
---|
| 1689 | + |
---|
| 1690 | + /* 'sync_file' pointer can't be safely dereferenced once 'fd' is |
---|
| 1691 | + * installed, so the install step needs to be done at the last |
---|
| 1692 | + * before returning success. |
---|
| 1693 | + */ |
---|
| 1694 | + fd_install(fd, sync_file->file); |
---|
| 1695 | + return 0; |
---|
| 1696 | + |
---|
| 1697 | +fail: |
---|
| 1698 | + fput(sync_file->file); |
---|
| 1699 | + kbase_fence_put(current_command->info.fence.fence); |
---|
| 1700 | + current_command->info.fence.fence = NULL; |
---|
| 1701 | + |
---|
| 1702 | + return ret; |
---|
| 1703 | +} |
---|
| 1704 | + |
---|
| 1705 | +int kbase_kcpu_fence_signal_process(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1706 | + struct kbase_kcpu_command_fence_info *fence_info) |
---|
| 1707 | +{ |
---|
| 1708 | + if (!kcpu_queue || !fence_info) |
---|
| 1709 | + return -EINVAL; |
---|
| 1710 | + |
---|
| 1711 | + return kbasep_kcpu_fence_signal_process(kcpu_queue, fence_info); |
---|
| 1712 | +} |
---|
| 1713 | +KBASE_EXPORT_TEST_API(kbase_kcpu_fence_signal_process); |
---|
| 1714 | + |
---|
| 1715 | +int kbase_kcpu_fence_signal_init(struct kbase_kcpu_command_queue *kcpu_queue, |
---|
| 1716 | + struct kbase_kcpu_command *current_command, |
---|
| 1717 | + struct base_fence *fence, struct sync_file **sync_file, int *fd) |
---|
| 1718 | +{ |
---|
| 1719 | + if (!kcpu_queue || !current_command || !fence || !sync_file || !fd) |
---|
| 1720 | + return -EINVAL; |
---|
| 1721 | + |
---|
| 1722 | + return kbasep_kcpu_fence_signal_init(kcpu_queue, current_command, fence, sync_file, fd); |
---|
| 1723 | +} |
---|
| 1724 | +KBASE_EXPORT_TEST_API(kbase_kcpu_fence_signal_init); |
---|
1416 | 1725 | #endif /* CONFIG_SYNC_FILE */ |
---|
1417 | 1726 | |
---|
1418 | 1727 | static void kcpu_queue_process_worker(struct work_struct *data) |
---|
.. | .. |
---|
1420 | 1729 | struct kbase_kcpu_command_queue *queue = container_of(data, |
---|
1421 | 1730 | struct kbase_kcpu_command_queue, work); |
---|
1422 | 1731 | |
---|
1423 | | - mutex_lock(&queue->kctx->csf.kcpu_queues.lock); |
---|
1424 | | - |
---|
| 1732 | + mutex_lock(&queue->lock); |
---|
1425 | 1733 | kcpu_queue_process(queue, false); |
---|
1426 | | - |
---|
1427 | | - mutex_unlock(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 1734 | + mutex_unlock(&queue->lock); |
---|
1428 | 1735 | } |
---|
1429 | 1736 | |
---|
1430 | 1737 | static int delete_queue(struct kbase_context *kctx, u32 id) |
---|
.. | .. |
---|
1437 | 1744 | struct kbase_kcpu_command_queue *queue = |
---|
1438 | 1745 | kctx->csf.kcpu_queues.array[id]; |
---|
1439 | 1746 | |
---|
1440 | | - KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_QUEUE_DESTROY, |
---|
| 1747 | + KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_QUEUE_DELETE, |
---|
1441 | 1748 | queue, queue->num_pending_cmds, queue->cqs_wait_count); |
---|
| 1749 | + |
---|
| 1750 | + /* Disassociate the queue from the system to prevent further |
---|
| 1751 | + * submissions. Draining pending commands would be acceptable |
---|
| 1752 | + * even if a new queue is created using the same ID. |
---|
| 1753 | + */ |
---|
| 1754 | + kctx->csf.kcpu_queues.array[id] = NULL; |
---|
| 1755 | + bitmap_clear(kctx->csf.kcpu_queues.in_use, id, 1); |
---|
| 1756 | + |
---|
| 1757 | + mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
| 1758 | + |
---|
| 1759 | + mutex_lock(&queue->lock); |
---|
| 1760 | + |
---|
| 1761 | + /* Metadata struct may outlive KCPU queue. */ |
---|
| 1762 | + kbase_kcpu_dma_fence_meta_put(queue->metadata); |
---|
1442 | 1763 | |
---|
1443 | 1764 | /* Drain the remaining work for this queue first and go past |
---|
1444 | 1765 | * all the waits. |
---|
.. | .. |
---|
1451 | 1772 | /* All CQS wait commands should have been cleaned up */ |
---|
1452 | 1773 | WARN_ON(queue->cqs_wait_count); |
---|
1453 | 1774 | |
---|
1454 | | - kctx->csf.kcpu_queues.array[id] = NULL; |
---|
1455 | | - bitmap_clear(kctx->csf.kcpu_queues.in_use, id, 1); |
---|
1456 | | - |
---|
1457 | 1775 | /* Fire the tracepoint with the mutex held to enforce correct |
---|
1458 | 1776 | * ordering with the summary stream. |
---|
1459 | 1777 | */ |
---|
1460 | 1778 | KBASE_TLSTREAM_TL_KBASE_DEL_KCPUQUEUE(kctx->kbdev, queue); |
---|
1461 | 1779 | |
---|
1462 | | - mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
| 1780 | + mutex_unlock(&queue->lock); |
---|
1463 | 1781 | |
---|
1464 | 1782 | cancel_work_sync(&queue->work); |
---|
| 1783 | + destroy_workqueue(queue->wq); |
---|
| 1784 | + |
---|
| 1785 | + mutex_destroy(&queue->lock); |
---|
1465 | 1786 | |
---|
1466 | 1787 | kfree(queue); |
---|
1467 | 1788 | } else { |
---|
1468 | | - dev_warn(kctx->kbdev->dev, |
---|
1469 | | - "Attempt to delete a non-existent KCPU queue\n"); |
---|
| 1789 | + dev_dbg(kctx->kbdev->dev, |
---|
| 1790 | + "Attempt to delete a non-existent KCPU queue"); |
---|
1470 | 1791 | mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
1471 | 1792 | err = -EINVAL; |
---|
1472 | 1793 | } |
---|
.. | .. |
---|
1481 | 1802 | { |
---|
1482 | 1803 | u8 i; |
---|
1483 | 1804 | |
---|
1484 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_EXECUTE_JIT_ALLOC_END( |
---|
1485 | | - kbdev, queue); |
---|
| 1805 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_EXECUTE_JIT_ALLOC_END(kbdev, queue); |
---|
1486 | 1806 | for (i = 0; i < jit_alloc->count; i++) { |
---|
1487 | 1807 | const u8 id = jit_alloc->info[i].id; |
---|
1488 | 1808 | const struct kbase_va_region *reg = queue->kctx->jit_alloc[id]; |
---|
.. | .. |
---|
1512 | 1832 | struct kbase_device *kbdev, |
---|
1513 | 1833 | const struct kbase_kcpu_command_queue *queue) |
---|
1514 | 1834 | { |
---|
1515 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_EXECUTE_JIT_ALLOC_END( |
---|
1516 | | - kbdev, queue); |
---|
| 1835 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_EXECUTE_JIT_ALLOC_END(kbdev, queue); |
---|
1517 | 1836 | } |
---|
1518 | 1837 | |
---|
1519 | 1838 | static void KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_FREE_END( |
---|
1520 | 1839 | struct kbase_device *kbdev, |
---|
1521 | 1840 | const struct kbase_kcpu_command_queue *queue) |
---|
1522 | 1841 | { |
---|
1523 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_EXECUTE_JIT_FREE_END( |
---|
1524 | | - kbdev, queue); |
---|
| 1842 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_EXECUTE_JIT_FREE_END(kbdev, queue); |
---|
1525 | 1843 | } |
---|
1526 | 1844 | |
---|
1527 | 1845 | static void kcpu_queue_process(struct kbase_kcpu_command_queue *queue, |
---|
1528 | | - bool ignore_waits) |
---|
| 1846 | + bool drain_queue) |
---|
1529 | 1847 | { |
---|
1530 | 1848 | struct kbase_device *kbdev = queue->kctx->kbdev; |
---|
1531 | 1849 | bool process_next = true; |
---|
1532 | 1850 | size_t i; |
---|
1533 | 1851 | |
---|
1534 | | - lockdep_assert_held(&queue->kctx->csf.kcpu_queues.lock); |
---|
| 1852 | + lockdep_assert_held(&queue->lock); |
---|
1535 | 1853 | |
---|
1536 | 1854 | for (i = 0; i != queue->num_pending_cmds; ++i) { |
---|
1537 | 1855 | struct kbase_kcpu_command *cmd = |
---|
.. | .. |
---|
1541 | 1859 | switch (cmd->type) { |
---|
1542 | 1860 | case BASE_KCPU_COMMAND_TYPE_FENCE_WAIT: |
---|
1543 | 1861 | if (!queue->command_started) { |
---|
1544 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_FENCE_WAIT_START( |
---|
1545 | | - kbdev, queue); |
---|
| 1862 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_FENCE_WAIT_START(kbdev, |
---|
| 1863 | + queue); |
---|
1546 | 1864 | queue->command_started = true; |
---|
1547 | 1865 | } |
---|
1548 | 1866 | |
---|
1549 | 1867 | status = 0; |
---|
1550 | 1868 | #if IS_ENABLED(CONFIG_SYNC_FILE) |
---|
1551 | | - if (ignore_waits) { |
---|
1552 | | - kbase_kcpu_fence_wait_cancel(queue, |
---|
1553 | | - &cmd->info.fence); |
---|
| 1869 | + if (drain_queue) { |
---|
| 1870 | + kbasep_kcpu_fence_wait_cancel(queue, &cmd->info.fence); |
---|
1554 | 1871 | } else { |
---|
1555 | 1872 | status = kbase_kcpu_fence_wait_process(queue, |
---|
1556 | 1873 | &cmd->info.fence); |
---|
.. | .. |
---|
1575 | 1892 | } |
---|
1576 | 1893 | break; |
---|
1577 | 1894 | case BASE_KCPU_COMMAND_TYPE_FENCE_SIGNAL: |
---|
1578 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_FENCE_SIGNAL_START( |
---|
1579 | | - kbdev, queue); |
---|
| 1895 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_FENCE_SIGNAL_START(kbdev, queue); |
---|
1580 | 1896 | |
---|
1581 | 1897 | status = 0; |
---|
1582 | 1898 | |
---|
1583 | 1899 | #if IS_ENABLED(CONFIG_SYNC_FILE) |
---|
1584 | | - status = kbase_kcpu_fence_signal_process( |
---|
1585 | | - queue, &cmd->info.fence); |
---|
| 1900 | + status = kbasep_kcpu_fence_signal_process(queue, &cmd->info.fence); |
---|
1586 | 1901 | |
---|
1587 | 1902 | if (status < 0) |
---|
1588 | 1903 | queue->has_error = true; |
---|
.. | .. |
---|
1594 | 1909 | queue->has_error = true; |
---|
1595 | 1910 | #endif |
---|
1596 | 1911 | |
---|
1597 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_FENCE_SIGNAL_END( |
---|
1598 | | - kbdev, queue, status); |
---|
| 1912 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_FENCE_SIGNAL_END(kbdev, queue, |
---|
| 1913 | + status); |
---|
1599 | 1914 | break; |
---|
1600 | 1915 | case BASE_KCPU_COMMAND_TYPE_CQS_WAIT: |
---|
1601 | 1916 | status = kbase_kcpu_cqs_wait_process(kbdev, queue, |
---|
1602 | 1917 | &cmd->info.cqs_wait); |
---|
1603 | 1918 | |
---|
1604 | | - if (!status && !ignore_waits) { |
---|
| 1919 | + if (!status && !drain_queue) { |
---|
1605 | 1920 | process_next = false; |
---|
1606 | 1921 | } else { |
---|
1607 | 1922 | /* Either all CQS objects were signaled or |
---|
.. | .. |
---|
1623 | 1938 | status = kbase_kcpu_cqs_wait_operation_process(kbdev, queue, |
---|
1624 | 1939 | &cmd->info.cqs_wait_operation); |
---|
1625 | 1940 | |
---|
1626 | | - if (!status && !ignore_waits) { |
---|
| 1941 | + if (!status && !drain_queue) { |
---|
1627 | 1942 | process_next = false; |
---|
1628 | 1943 | } else { |
---|
1629 | 1944 | /* Either all CQS objects were signaled or |
---|
.. | .. |
---|
1645 | 1960 | /* Clear the queue's error state */ |
---|
1646 | 1961 | queue->has_error = false; |
---|
1647 | 1962 | |
---|
1648 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_ERROR_BARRIER( |
---|
1649 | | - kbdev, queue); |
---|
| 1963 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_ERROR_BARRIER(kbdev, queue); |
---|
1650 | 1964 | break; |
---|
1651 | 1965 | case BASE_KCPU_COMMAND_TYPE_MAP_IMPORT: { |
---|
1652 | 1966 | struct kbase_ctx_ext_res_meta *meta = NULL; |
---|
1653 | 1967 | |
---|
1654 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_MAP_IMPORT_START( |
---|
1655 | | - kbdev, queue); |
---|
| 1968 | + if (!drain_queue) { |
---|
| 1969 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_MAP_IMPORT_START(kbdev, |
---|
| 1970 | + queue); |
---|
1656 | 1971 | |
---|
1657 | | - kbase_gpu_vm_lock(queue->kctx); |
---|
1658 | | - meta = kbase_sticky_resource_acquire( |
---|
1659 | | - queue->kctx, cmd->info.import.gpu_va); |
---|
1660 | | - kbase_gpu_vm_unlock(queue->kctx); |
---|
| 1972 | + kbase_gpu_vm_lock(queue->kctx); |
---|
| 1973 | + meta = kbase_sticky_resource_acquire( |
---|
| 1974 | + queue->kctx, cmd->info.import.gpu_va); |
---|
| 1975 | + kbase_gpu_vm_unlock(queue->kctx); |
---|
1661 | 1976 | |
---|
1662 | | - if (meta == NULL) { |
---|
1663 | | - queue->has_error = true; |
---|
1664 | | - dev_warn(kbdev->dev, |
---|
1665 | | - "failed to map an external resource\n"); |
---|
| 1977 | + if (meta == NULL) { |
---|
| 1978 | + queue->has_error = true; |
---|
| 1979 | + dev_dbg( |
---|
| 1980 | + kbdev->dev, |
---|
| 1981 | + "failed to map an external resource"); |
---|
| 1982 | + } |
---|
| 1983 | + |
---|
| 1984 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_MAP_IMPORT_END( |
---|
| 1985 | + kbdev, queue, meta ? 0 : 1); |
---|
1666 | 1986 | } |
---|
1667 | | - |
---|
1668 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_MAP_IMPORT_END( |
---|
1669 | | - kbdev, queue, meta ? 0 : 1); |
---|
1670 | 1987 | break; |
---|
1671 | 1988 | } |
---|
1672 | 1989 | case BASE_KCPU_COMMAND_TYPE_UNMAP_IMPORT: { |
---|
1673 | 1990 | bool ret; |
---|
1674 | 1991 | |
---|
1675 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_START( |
---|
1676 | | - kbdev, queue); |
---|
| 1992 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_START(kbdev, queue); |
---|
1677 | 1993 | |
---|
1678 | 1994 | kbase_gpu_vm_lock(queue->kctx); |
---|
1679 | 1995 | ret = kbase_sticky_resource_release( |
---|
.. | .. |
---|
1682 | 1998 | |
---|
1683 | 1999 | if (!ret) { |
---|
1684 | 2000 | queue->has_error = true; |
---|
1685 | | - dev_warn(kbdev->dev, |
---|
1686 | | - "failed to release the reference. resource not found\n"); |
---|
| 2001 | + dev_dbg(kbdev->dev, |
---|
| 2002 | + "failed to release the reference. resource not found"); |
---|
1687 | 2003 | } |
---|
1688 | 2004 | |
---|
1689 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_END( |
---|
1690 | | - kbdev, queue, ret ? 0 : 1); |
---|
| 2005 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_END(kbdev, queue, |
---|
| 2006 | + ret ? 0 : 1); |
---|
1691 | 2007 | break; |
---|
1692 | 2008 | } |
---|
1693 | 2009 | case BASE_KCPU_COMMAND_TYPE_UNMAP_IMPORT_FORCE: { |
---|
1694 | 2010 | bool ret; |
---|
1695 | 2011 | |
---|
1696 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_FORCE_START( |
---|
1697 | | - kbdev, queue); |
---|
| 2012 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_FORCE_START(kbdev, |
---|
| 2013 | + queue); |
---|
1698 | 2014 | |
---|
1699 | 2015 | kbase_gpu_vm_lock(queue->kctx); |
---|
1700 | 2016 | ret = kbase_sticky_resource_release_force( |
---|
.. | .. |
---|
1703 | 2019 | |
---|
1704 | 2020 | if (!ret) { |
---|
1705 | 2021 | queue->has_error = true; |
---|
1706 | | - dev_warn(kbdev->dev, |
---|
1707 | | - "failed to release the reference. resource not found\n"); |
---|
| 2022 | + dev_dbg(kbdev->dev, |
---|
| 2023 | + "failed to release the reference. resource not found"); |
---|
1708 | 2024 | } |
---|
1709 | 2025 | |
---|
1710 | 2026 | KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_UNMAP_IMPORT_FORCE_END( |
---|
.. | .. |
---|
1713 | 2029 | } |
---|
1714 | 2030 | case BASE_KCPU_COMMAND_TYPE_JIT_ALLOC: |
---|
1715 | 2031 | { |
---|
1716 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_ALLOC_START( |
---|
1717 | | - kbdev, queue); |
---|
1718 | | - |
---|
1719 | | - status = kbase_kcpu_jit_allocate_process(queue, cmd); |
---|
1720 | | - if (status == -EAGAIN) { |
---|
1721 | | - process_next = false; |
---|
1722 | | - } else { |
---|
1723 | | - if (status != 0) |
---|
1724 | | - queue->has_error = true; |
---|
1725 | | - |
---|
1726 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_ALLOC_INFO( |
---|
1727 | | - kbdev, queue, &cmd->info.jit_alloc, |
---|
1728 | | - status); |
---|
1729 | | - |
---|
| 2032 | + if (drain_queue) { |
---|
| 2033 | + /* We still need to call this function to clean the JIT alloc info up */ |
---|
1730 | 2034 | kbase_kcpu_jit_allocate_finish(queue, cmd); |
---|
1731 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_ALLOC_END( |
---|
| 2035 | + } else { |
---|
| 2036 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_ALLOC_START(kbdev, |
---|
| 2037 | + queue); |
---|
| 2038 | + |
---|
| 2039 | + status = kbase_kcpu_jit_allocate_process(queue, |
---|
| 2040 | + cmd); |
---|
| 2041 | + if (status == -EAGAIN) { |
---|
| 2042 | + process_next = false; |
---|
| 2043 | + } else { |
---|
| 2044 | + if (status != 0) |
---|
| 2045 | + queue->has_error = true; |
---|
| 2046 | + |
---|
| 2047 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_ALLOC_INFO( |
---|
| 2048 | + kbdev, queue, |
---|
| 2049 | + &cmd->info.jit_alloc, status); |
---|
| 2050 | + |
---|
| 2051 | + kbase_kcpu_jit_allocate_finish(queue, |
---|
| 2052 | + cmd); |
---|
| 2053 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_ALLOC_END( |
---|
1732 | 2054 | kbdev, queue); |
---|
| 2055 | + } |
---|
1733 | 2056 | } |
---|
| 2057 | + |
---|
1734 | 2058 | break; |
---|
1735 | 2059 | } |
---|
1736 | | - case BASE_KCPU_COMMAND_TYPE_JIT_FREE: |
---|
1737 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_FREE_START( |
---|
1738 | | - kbdev, queue); |
---|
| 2060 | + case BASE_KCPU_COMMAND_TYPE_JIT_FREE: { |
---|
| 2061 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_FREE_START(kbdev, queue); |
---|
1739 | 2062 | |
---|
1740 | 2063 | status = kbase_kcpu_jit_free_process(queue, cmd); |
---|
1741 | 2064 | if (status) |
---|
.. | .. |
---|
1744 | 2067 | KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_JIT_FREE_END( |
---|
1745 | 2068 | kbdev, queue); |
---|
1746 | 2069 | break; |
---|
| 2070 | + } |
---|
| 2071 | +#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST |
---|
1747 | 2072 | case BASE_KCPU_COMMAND_TYPE_GROUP_SUSPEND: { |
---|
1748 | 2073 | struct kbase_suspend_copy_buffer *sus_buf = |
---|
1749 | 2074 | cmd->info.suspend_buf_copy.sus_buf; |
---|
1750 | 2075 | |
---|
1751 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_GROUP_SUSPEND_START( |
---|
1752 | | - kbdev, queue); |
---|
| 2076 | + if (!drain_queue) { |
---|
| 2077 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_GROUP_SUSPEND_START( |
---|
| 2078 | + kbdev, queue); |
---|
1753 | 2079 | |
---|
1754 | | - status = kbase_csf_queue_group_suspend_process( |
---|
| 2080 | + status = kbase_csf_queue_group_suspend_process( |
---|
1755 | 2081 | queue->kctx, sus_buf, |
---|
1756 | 2082 | cmd->info.suspend_buf_copy.group_handle); |
---|
1757 | | - if (status) |
---|
1758 | | - queue->has_error = true; |
---|
| 2083 | + if (status) |
---|
| 2084 | + queue->has_error = true; |
---|
1759 | 2085 | |
---|
1760 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_GROUP_SUSPEND_END( |
---|
1761 | | - kbdev, queue, status); |
---|
| 2086 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_EXECUTE_GROUP_SUSPEND_END( |
---|
| 2087 | + kbdev, queue, status); |
---|
| 2088 | + } |
---|
1762 | 2089 | |
---|
1763 | 2090 | if (!sus_buf->cpu_alloc) { |
---|
1764 | 2091 | int i; |
---|
.. | .. |
---|
1768 | 2095 | } else { |
---|
1769 | 2096 | kbase_mem_phy_alloc_kernel_unmapped( |
---|
1770 | 2097 | sus_buf->cpu_alloc); |
---|
1771 | | - kbase_mem_phy_alloc_put(sus_buf->cpu_alloc); |
---|
| 2098 | + kbase_mem_phy_alloc_put( |
---|
| 2099 | + sus_buf->cpu_alloc); |
---|
1772 | 2100 | } |
---|
1773 | 2101 | |
---|
1774 | 2102 | kfree(sus_buf->pages); |
---|
1775 | 2103 | kfree(sus_buf); |
---|
1776 | 2104 | break; |
---|
1777 | 2105 | } |
---|
1778 | | -#if MALI_UNIT_TEST |
---|
1779 | | - case BASE_KCPU_COMMAND_TYPE_SAMPLE_TIME: { |
---|
1780 | | - u64 time = ktime_get_raw_ns(); |
---|
1781 | | - void *target_page = kmap(*cmd->info.sample_time.page); |
---|
1782 | | - |
---|
1783 | | - if (target_page) { |
---|
1784 | | - memcpy(target_page + |
---|
1785 | | - cmd->info.sample_time.page_offset, |
---|
1786 | | - &time, sizeof(time)); |
---|
1787 | | - kunmap(*cmd->info.sample_time.page); |
---|
1788 | | - } else { |
---|
1789 | | - dev_warn(kbdev->dev, |
---|
1790 | | - "Could not kmap target page\n"); |
---|
1791 | | - queue->has_error = true; |
---|
1792 | | - } |
---|
1793 | | - put_page(*cmd->info.sample_time.page); |
---|
1794 | | - kfree(cmd->info.sample_time.page); |
---|
1795 | | - break; |
---|
1796 | | - } |
---|
1797 | | -#endif /* MALI_UNIT_TEST */ |
---|
| 2106 | +#endif |
---|
1798 | 2107 | default: |
---|
1799 | | - dev_warn(kbdev->dev, |
---|
1800 | | - "Unrecognized command type\n"); |
---|
| 2108 | + dev_dbg(kbdev->dev, |
---|
| 2109 | + "Unrecognized command type"); |
---|
1801 | 2110 | break; |
---|
1802 | 2111 | } /* switch */ |
---|
1803 | 2112 | |
---|
.. | .. |
---|
1835 | 2144 | |
---|
1836 | 2145 | switch (cmd->type) { |
---|
1837 | 2146 | case BASE_KCPU_COMMAND_TYPE_FENCE_WAIT: |
---|
1838 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_FENCE_WAIT( |
---|
1839 | | - kbdev, queue, cmd->info.fence.fence); |
---|
| 2147 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_FENCE_WAIT(kbdev, queue, |
---|
| 2148 | + cmd->info.fence.fence); |
---|
1840 | 2149 | break; |
---|
1841 | 2150 | case BASE_KCPU_COMMAND_TYPE_FENCE_SIGNAL: |
---|
1842 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_FENCE_SIGNAL( |
---|
1843 | | - kbdev, queue, cmd->info.fence.fence); |
---|
| 2151 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_FENCE_SIGNAL(kbdev, queue, |
---|
| 2152 | + cmd->info.fence.fence); |
---|
1844 | 2153 | break; |
---|
1845 | 2154 | case BASE_KCPU_COMMAND_TYPE_CQS_WAIT: |
---|
1846 | 2155 | { |
---|
.. | .. |
---|
1862 | 2171 | unsigned int i; |
---|
1863 | 2172 | |
---|
1864 | 2173 | for (i = 0; i < cmd->info.cqs_set.nr_objs; i++) { |
---|
1865 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_CQS_SET( |
---|
1866 | | - kbdev, queue, sets[i].addr); |
---|
| 2174 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_CQS_SET(kbdev, queue, |
---|
| 2175 | + sets[i].addr); |
---|
1867 | 2176 | } |
---|
1868 | 2177 | break; |
---|
1869 | 2178 | } |
---|
1870 | 2179 | case BASE_KCPU_COMMAND_TYPE_CQS_WAIT_OPERATION: |
---|
1871 | 2180 | { |
---|
1872 | | - /* GPUCORE-28172 RDT to review */ |
---|
| 2181 | + const struct base_cqs_wait_operation_info *waits = |
---|
| 2182 | + cmd->info.cqs_wait_operation.objs; |
---|
| 2183 | + u32 inherit_err_flags = cmd->info.cqs_wait_operation.inherit_err_flags; |
---|
| 2184 | + unsigned int i; |
---|
| 2185 | + |
---|
| 2186 | + for (i = 0; i < cmd->info.cqs_wait_operation.nr_objs; i++) { |
---|
| 2187 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_CQS_WAIT_OPERATION( |
---|
| 2188 | + kbdev, queue, waits[i].addr, waits[i].val, |
---|
| 2189 | + waits[i].operation, waits[i].data_type, |
---|
| 2190 | + (inherit_err_flags & ((uint32_t)1 << i)) ? 1 : 0); |
---|
| 2191 | + } |
---|
1873 | 2192 | break; |
---|
1874 | 2193 | } |
---|
1875 | 2194 | case BASE_KCPU_COMMAND_TYPE_CQS_SET_OPERATION: |
---|
1876 | 2195 | { |
---|
1877 | | - /* GPUCORE-28172 RDT to review */ |
---|
| 2196 | + const struct base_cqs_set_operation_info *sets = cmd->info.cqs_set_operation.objs; |
---|
| 2197 | + unsigned int i; |
---|
| 2198 | + |
---|
| 2199 | + for (i = 0; i < cmd->info.cqs_set_operation.nr_objs; i++) { |
---|
| 2200 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_CQS_SET_OPERATION( |
---|
| 2201 | + kbdev, queue, sets[i].addr, sets[i].val, |
---|
| 2202 | + sets[i].operation, sets[i].data_type); |
---|
| 2203 | + } |
---|
1878 | 2204 | break; |
---|
1879 | 2205 | } |
---|
1880 | 2206 | case BASE_KCPU_COMMAND_TYPE_ERROR_BARRIER: |
---|
1881 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_ERROR_BARRIER(kbdev, |
---|
1882 | | - queue); |
---|
| 2207 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_ERROR_BARRIER(kbdev, queue); |
---|
1883 | 2208 | break; |
---|
1884 | 2209 | case BASE_KCPU_COMMAND_TYPE_MAP_IMPORT: |
---|
1885 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_MAP_IMPORT( |
---|
1886 | | - kbdev, queue, cmd->info.import.gpu_va); |
---|
| 2210 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_MAP_IMPORT(kbdev, queue, |
---|
| 2211 | + cmd->info.import.gpu_va); |
---|
1887 | 2212 | break; |
---|
1888 | 2213 | case BASE_KCPU_COMMAND_TYPE_UNMAP_IMPORT: |
---|
1889 | | - KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_UNMAP_IMPORT( |
---|
1890 | | - kbdev, queue, cmd->info.import.gpu_va); |
---|
| 2214 | + KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_UNMAP_IMPORT(kbdev, queue, |
---|
| 2215 | + cmd->info.import.gpu_va); |
---|
1891 | 2216 | break; |
---|
1892 | 2217 | case BASE_KCPU_COMMAND_TYPE_UNMAP_IMPORT_FORCE: |
---|
1893 | 2218 | KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_UNMAP_IMPORT_FORCE( |
---|
.. | .. |
---|
1897 | 2222 | { |
---|
1898 | 2223 | u8 i; |
---|
1899 | 2224 | |
---|
1900 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_ENQUEUE_JIT_ALLOC( |
---|
1901 | | - kbdev, queue); |
---|
| 2225 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_ENQUEUE_JIT_ALLOC(kbdev, queue); |
---|
1902 | 2226 | for (i = 0; i < cmd->info.jit_alloc.count; i++) { |
---|
1903 | 2227 | const struct base_jit_alloc_info *info = |
---|
1904 | 2228 | &cmd->info.jit_alloc.info[i]; |
---|
1905 | 2229 | |
---|
1906 | 2230 | KBASE_TLSTREAM_TL_KBASE_ARRAY_ITEM_KCPUQUEUE_ENQUEUE_JIT_ALLOC( |
---|
1907 | | - kbdev, queue, info->gpu_alloc_addr, |
---|
1908 | | - info->va_pages, info->commit_pages, |
---|
1909 | | - info->extension, info->id, info->bin_id, |
---|
1910 | | - info->max_allocations, info->flags, |
---|
1911 | | - info->usage_id); |
---|
| 2231 | + kbdev, queue, info->gpu_alloc_addr, info->va_pages, |
---|
| 2232 | + info->commit_pages, info->extension, info->id, info->bin_id, |
---|
| 2233 | + info->max_allocations, info->flags, info->usage_id); |
---|
1912 | 2234 | } |
---|
1913 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_ENQUEUE_JIT_ALLOC( |
---|
1914 | | - kbdev, queue); |
---|
| 2235 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_ENQUEUE_JIT_ALLOC(kbdev, queue); |
---|
1915 | 2236 | break; |
---|
1916 | 2237 | } |
---|
1917 | 2238 | case BASE_KCPU_COMMAND_TYPE_JIT_FREE: |
---|
1918 | 2239 | { |
---|
1919 | 2240 | u8 i; |
---|
1920 | 2241 | |
---|
1921 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_ENQUEUE_JIT_FREE( |
---|
1922 | | - kbdev, queue); |
---|
| 2242 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_BEGIN_KCPUQUEUE_ENQUEUE_JIT_FREE(kbdev, queue); |
---|
1923 | 2243 | for (i = 0; i < cmd->info.jit_free.count; i++) { |
---|
1924 | 2244 | KBASE_TLSTREAM_TL_KBASE_ARRAY_ITEM_KCPUQUEUE_ENQUEUE_JIT_FREE( |
---|
1925 | 2245 | kbdev, queue, cmd->info.jit_free.ids[i]); |
---|
1926 | 2246 | } |
---|
1927 | | - KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_ENQUEUE_JIT_FREE( |
---|
1928 | | - kbdev, queue); |
---|
| 2247 | + KBASE_TLSTREAM_TL_KBASE_ARRAY_END_KCPUQUEUE_ENQUEUE_JIT_FREE(kbdev, queue); |
---|
1929 | 2248 | break; |
---|
1930 | 2249 | } |
---|
| 2250 | +#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST |
---|
1931 | 2251 | case BASE_KCPU_COMMAND_TYPE_GROUP_SUSPEND: |
---|
1932 | 2252 | KBASE_TLSTREAM_TL_KBASE_KCPUQUEUE_ENQUEUE_GROUP_SUSPEND( |
---|
1933 | 2253 | kbdev, queue, cmd->info.suspend_buf_copy.sus_buf, |
---|
1934 | 2254 | cmd->info.suspend_buf_copy.group_handle); |
---|
1935 | 2255 | break; |
---|
1936 | | -#if MALI_UNIT_TEST |
---|
1937 | | - case BASE_KCPU_COMMAND_TYPE_SAMPLE_TIME: |
---|
1938 | | - /* |
---|
1939 | | - * This is test-only KCPU command, no need to have a timeline |
---|
1940 | | - * entry |
---|
1941 | | - */ |
---|
| 2256 | +#endif |
---|
| 2257 | + default: |
---|
| 2258 | + dev_dbg(kbdev->dev, "Unknown command type %u", cmd->type); |
---|
1942 | 2259 | break; |
---|
1943 | | -#endif /* MALI_UNIT_TEST */ |
---|
1944 | 2260 | } |
---|
1945 | 2261 | } |
---|
1946 | 2262 | |
---|
.. | .. |
---|
1954 | 2270 | |
---|
1955 | 2271 | /* The offset to the first command that is being processed or yet to |
---|
1956 | 2272 | * be processed is of u8 type, so the number of commands inside the |
---|
1957 | | - * queue cannot be more than 256. |
---|
| 2273 | + * queue cannot be more than 256. The current implementation expects |
---|
| 2274 | + * exactly 256, any other size will require the addition of wrapping |
---|
| 2275 | + * logic. |
---|
1958 | 2276 | */ |
---|
1959 | | - BUILD_BUG_ON(KBASEP_KCPU_QUEUE_SIZE > 256); |
---|
| 2277 | + BUILD_BUG_ON(KBASEP_KCPU_QUEUE_SIZE != 256); |
---|
1960 | 2278 | |
---|
1961 | 2279 | /* Whilst the backend interface allows enqueueing multiple commands in |
---|
1962 | 2280 | * a single operation, the Base interface does not expose any mechanism |
---|
.. | .. |
---|
1966 | 2284 | * in the set. |
---|
1967 | 2285 | */ |
---|
1968 | 2286 | if (enq->nr_commands != 1) { |
---|
1969 | | - dev_err(kctx->kbdev->dev, |
---|
1970 | | - "More than one commands enqueued\n"); |
---|
| 2287 | + dev_dbg(kctx->kbdev->dev, |
---|
| 2288 | + "More than one commands enqueued"); |
---|
1971 | 2289 | return -EINVAL; |
---|
1972 | 2290 | } |
---|
1973 | 2291 | |
---|
| 2292 | + /* There might be a race between one thread trying to enqueue commands to the queue |
---|
| 2293 | + * and other thread trying to delete the same queue. |
---|
| 2294 | + * This racing could lead to use-after-free problem by enqueuing thread if |
---|
| 2295 | + * resources for the queue has already been freed by deleting thread. |
---|
| 2296 | + * |
---|
| 2297 | + * To prevent the issue, two mutexes are acquired/release asymmetrically as follows. |
---|
| 2298 | + * |
---|
| 2299 | + * Lock A (kctx mutex) |
---|
| 2300 | + * Lock B (queue mutex) |
---|
| 2301 | + * Unlock A |
---|
| 2302 | + * Unlock B |
---|
| 2303 | + * |
---|
| 2304 | + * With the kctx mutex being held, enqueuing thread will check the queue |
---|
| 2305 | + * and will return error code if the queue had already been deleted. |
---|
| 2306 | + */ |
---|
1974 | 2307 | mutex_lock(&kctx->csf.kcpu_queues.lock); |
---|
1975 | | - |
---|
1976 | | - if (!kctx->csf.kcpu_queues.array[enq->id]) { |
---|
1977 | | - ret = -EINVAL; |
---|
1978 | | - goto out; |
---|
1979 | | - } |
---|
1980 | | - |
---|
1981 | 2308 | queue = kctx->csf.kcpu_queues.array[enq->id]; |
---|
| 2309 | + if (queue == NULL) { |
---|
| 2310 | + dev_dbg(kctx->kbdev->dev, "Invalid KCPU queue (id:%u)", enq->id); |
---|
| 2311 | + mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
| 2312 | + return -EINVAL; |
---|
| 2313 | + } |
---|
| 2314 | + mutex_lock(&queue->lock); |
---|
| 2315 | + mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
1982 | 2316 | |
---|
1983 | 2317 | if (kcpu_queue_get_space(queue) < enq->nr_commands) { |
---|
1984 | 2318 | ret = -EBUSY; |
---|
.. | .. |
---|
1993 | 2327 | * for the possibility to roll back. |
---|
1994 | 2328 | */ |
---|
1995 | 2329 | |
---|
1996 | | - for (i = 0; (i != enq->nr_commands) && !ret; ++i, ++kctx->csf.kcpu_queues.num_cmds) { |
---|
| 2330 | + for (i = 0; (i != enq->nr_commands) && !ret; ++i) { |
---|
1997 | 2331 | struct kbase_kcpu_command *kcpu_cmd = |
---|
1998 | 2332 | &queue->commands[(u8)(queue->start_offset + queue->num_pending_cmds + i)]; |
---|
1999 | 2333 | struct base_kcpu_command command; |
---|
.. | .. |
---|
2016 | 2350 | } |
---|
2017 | 2351 | } |
---|
2018 | 2352 | |
---|
2019 | | - kcpu_cmd->enqueue_ts = kctx->csf.kcpu_queues.num_cmds; |
---|
| 2353 | + kcpu_cmd->enqueue_ts = atomic64_inc_return(&kctx->csf.kcpu_queues.cmd_seq_num); |
---|
2020 | 2354 | switch (command.type) { |
---|
2021 | 2355 | case BASE_KCPU_COMMAND_TYPE_FENCE_WAIT: |
---|
2022 | 2356 | #if IS_ENABLED(CONFIG_SYNC_FILE) |
---|
.. | .. |
---|
2076 | 2410 | ret = kbase_kcpu_jit_free_prepare(queue, |
---|
2077 | 2411 | &command.info.jit_free, kcpu_cmd); |
---|
2078 | 2412 | break; |
---|
| 2413 | +#if IS_ENABLED(CONFIG_MALI_VECTOR_DUMP) || MALI_UNIT_TEST |
---|
2079 | 2414 | case BASE_KCPU_COMMAND_TYPE_GROUP_SUSPEND: |
---|
2080 | 2415 | ret = kbase_csf_queue_group_suspend_prepare(queue, |
---|
2081 | 2416 | &command.info.suspend_buf_copy, |
---|
2082 | 2417 | kcpu_cmd); |
---|
2083 | 2418 | break; |
---|
2084 | | -#if MALI_UNIT_TEST |
---|
2085 | | - case BASE_KCPU_COMMAND_TYPE_SAMPLE_TIME: { |
---|
2086 | | - int const page_cnt = 1; |
---|
2087 | | - |
---|
2088 | | - kcpu_cmd->type = BASE_KCPU_COMMAND_TYPE_SAMPLE_TIME; |
---|
2089 | | - kcpu_cmd->info.sample_time.page_addr = |
---|
2090 | | - command.info.sample_time.time & PAGE_MASK; |
---|
2091 | | - kcpu_cmd->info.sample_time.page_offset = |
---|
2092 | | - command.info.sample_time.time & ~PAGE_MASK; |
---|
2093 | | - kcpu_cmd->info.sample_time.page = kcalloc( |
---|
2094 | | - page_cnt, sizeof(struct page *), GFP_KERNEL); |
---|
2095 | | - if (!kcpu_cmd->info.sample_time.page) { |
---|
2096 | | - ret = -ENOMEM; |
---|
2097 | | - } else { |
---|
2098 | | - int pinned_pages = get_user_pages_fast( |
---|
2099 | | - kcpu_cmd->info.sample_time.page_addr, |
---|
2100 | | - page_cnt, 1, |
---|
2101 | | - kcpu_cmd->info.sample_time.page); |
---|
2102 | | - |
---|
2103 | | - if (pinned_pages < 0) { |
---|
2104 | | - ret = pinned_pages; |
---|
2105 | | - kfree(kcpu_cmd->info.sample_time.page); |
---|
2106 | | - } else if (pinned_pages != page_cnt) { |
---|
2107 | | - ret = -EINVAL; |
---|
2108 | | - kfree(kcpu_cmd->info.sample_time.page); |
---|
2109 | | - } |
---|
2110 | | - } |
---|
2111 | | - |
---|
2112 | | - break; |
---|
2113 | | - } |
---|
2114 | | -#endif /* MALI_UNIT_TEST */ |
---|
| 2419 | +#endif |
---|
2115 | 2420 | default: |
---|
2116 | | - dev_warn(queue->kctx->kbdev->dev, |
---|
2117 | | - "Unknown command type %u\n", command.type); |
---|
| 2421 | + dev_dbg(queue->kctx->kbdev->dev, |
---|
| 2422 | + "Unknown command type %u", command.type); |
---|
2118 | 2423 | ret = -EINVAL; |
---|
2119 | 2424 | break; |
---|
2120 | 2425 | } |
---|
.. | .. |
---|
2135 | 2440 | |
---|
2136 | 2441 | queue->num_pending_cmds += enq->nr_commands; |
---|
2137 | 2442 | kcpu_queue_process(queue, false); |
---|
2138 | | - } else { |
---|
2139 | | - /* Roll back the number of enqueued commands */ |
---|
2140 | | - kctx->csf.kcpu_queues.num_cmds -= i; |
---|
2141 | 2443 | } |
---|
2142 | 2444 | |
---|
2143 | 2445 | out: |
---|
2144 | | - mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
| 2446 | + mutex_unlock(&queue->lock); |
---|
2145 | 2447 | |
---|
2146 | 2448 | return ret; |
---|
2147 | 2449 | } |
---|
.. | .. |
---|
2155 | 2457 | for (idx = 0; idx < KBASEP_MAX_KCPU_QUEUES; ++idx) |
---|
2156 | 2458 | kctx->csf.kcpu_queues.array[idx] = NULL; |
---|
2157 | 2459 | |
---|
2158 | | - kctx->csf.kcpu_queues.wq = alloc_workqueue("mali_kbase_csf_kcpu", |
---|
2159 | | - WQ_UNBOUND | WQ_HIGHPRI, 0); |
---|
2160 | | - if (!kctx->csf.kcpu_queues.wq) |
---|
2161 | | - return -ENOMEM; |
---|
2162 | | - |
---|
2163 | 2460 | mutex_init(&kctx->csf.kcpu_queues.lock); |
---|
2164 | 2461 | |
---|
2165 | | - kctx->csf.kcpu_queues.num_cmds = 0; |
---|
| 2462 | + atomic64_set(&kctx->csf.kcpu_queues.cmd_seq_num, 0); |
---|
2166 | 2463 | |
---|
2167 | 2464 | return 0; |
---|
2168 | 2465 | } |
---|
.. | .. |
---|
2180 | 2477 | (void)delete_queue(kctx, id); |
---|
2181 | 2478 | } |
---|
2182 | 2479 | |
---|
2183 | | - destroy_workqueue(kctx->csf.kcpu_queues.wq); |
---|
2184 | 2480 | mutex_destroy(&kctx->csf.kcpu_queues.lock); |
---|
2185 | 2481 | } |
---|
| 2482 | +KBASE_EXPORT_TEST_API(kbase_csf_kcpu_queue_context_term); |
---|
2186 | 2483 | |
---|
2187 | 2484 | int kbase_csf_kcpu_queue_delete(struct kbase_context *kctx, |
---|
2188 | 2485 | struct kbase_ioctl_kcpu_queue_delete *del) |
---|
.. | .. |
---|
2195 | 2492 | { |
---|
2196 | 2493 | struct kbase_kcpu_command_queue *queue; |
---|
2197 | 2494 | int idx; |
---|
| 2495 | + int n; |
---|
2198 | 2496 | int ret = 0; |
---|
2199 | | - |
---|
| 2497 | +#if IS_ENABLED(CONFIG_SYNC_FILE) |
---|
| 2498 | + struct kbase_kcpu_dma_fence_meta *metadata; |
---|
| 2499 | +#endif |
---|
2200 | 2500 | /* The queue id is of u8 type and we use the index of the kcpu_queues |
---|
2201 | 2501 | * array as an id, so the number of elements in the array can't be |
---|
2202 | 2502 | * more than 256. |
---|
.. | .. |
---|
2224 | 2524 | goto out; |
---|
2225 | 2525 | } |
---|
2226 | 2526 | |
---|
| 2527 | + queue->wq = alloc_workqueue("mali_kbase_csf_kcpu_wq_%i", WQ_UNBOUND | WQ_HIGHPRI, 0, idx); |
---|
| 2528 | + if (queue->wq == NULL) { |
---|
| 2529 | + kfree(queue); |
---|
| 2530 | + ret = -ENOMEM; |
---|
| 2531 | + |
---|
| 2532 | + goto out; |
---|
| 2533 | + } |
---|
| 2534 | + |
---|
2227 | 2535 | bitmap_set(kctx->csf.kcpu_queues.in_use, idx, 1); |
---|
2228 | 2536 | kctx->csf.kcpu_queues.array[idx] = queue; |
---|
| 2537 | + mutex_init(&queue->lock); |
---|
2229 | 2538 | queue->kctx = kctx; |
---|
2230 | 2539 | queue->start_offset = 0; |
---|
2231 | 2540 | queue->num_pending_cmds = 0; |
---|
.. | .. |
---|
2233 | 2542 | queue->fence_context = dma_fence_context_alloc(1); |
---|
2234 | 2543 | queue->fence_seqno = 0; |
---|
2235 | 2544 | queue->fence_wait_processed = false; |
---|
2236 | | -#endif |
---|
| 2545 | + |
---|
| 2546 | + metadata = kzalloc(sizeof(*metadata), GFP_KERNEL); |
---|
| 2547 | + if (!metadata) { |
---|
| 2548 | + destroy_workqueue(queue->wq); |
---|
| 2549 | + kfree(queue); |
---|
| 2550 | + ret = -ENOMEM; |
---|
| 2551 | + goto out; |
---|
| 2552 | + } |
---|
| 2553 | + |
---|
| 2554 | + metadata->kbdev = kctx->kbdev; |
---|
| 2555 | + metadata->kctx_id = kctx->id; |
---|
| 2556 | + n = snprintf(metadata->timeline_name, MAX_TIMELINE_NAME, "%d-%d_%d-%lld-kcpu", |
---|
| 2557 | + kctx->kbdev->id, kctx->tgid, kctx->id, queue->fence_context); |
---|
| 2558 | + if (WARN_ON(n >= MAX_TIMELINE_NAME)) { |
---|
| 2559 | + destroy_workqueue(queue->wq); |
---|
| 2560 | + kfree(queue); |
---|
| 2561 | + kfree(metadata); |
---|
| 2562 | + ret = -EINVAL; |
---|
| 2563 | + goto out; |
---|
| 2564 | + } |
---|
| 2565 | + |
---|
| 2566 | + kbase_refcount_set(&metadata->refcount, 1); |
---|
| 2567 | + queue->metadata = metadata; |
---|
| 2568 | + atomic_inc(&kctx->kbdev->live_fence_metadata); |
---|
| 2569 | +#endif /* CONFIG_SYNC_FILE */ |
---|
2237 | 2570 | queue->enqueue_failed = false; |
---|
2238 | 2571 | queue->command_started = false; |
---|
2239 | 2572 | INIT_LIST_HEAD(&queue->jit_blocked); |
---|
.. | .. |
---|
2246 | 2579 | /* Fire the tracepoint with the mutex held to enforce correct ordering |
---|
2247 | 2580 | * with the summary stream. |
---|
2248 | 2581 | */ |
---|
2249 | | - KBASE_TLSTREAM_TL_KBASE_NEW_KCPUQUEUE( |
---|
2250 | | - kctx->kbdev, queue, kctx->id, queue->num_pending_cmds); |
---|
| 2582 | + KBASE_TLSTREAM_TL_KBASE_NEW_KCPUQUEUE(kctx->kbdev, queue, queue->id, kctx->id, |
---|
| 2583 | + queue->num_pending_cmds); |
---|
2251 | 2584 | |
---|
2252 | | - KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_QUEUE_NEW, queue, |
---|
| 2585 | + KBASE_KTRACE_ADD_CSF_KCPU(kctx->kbdev, KCPU_QUEUE_CREATE, queue, |
---|
2253 | 2586 | queue->fence_context, 0); |
---|
| 2587 | +#ifdef CONFIG_MALI_BIFROST_FENCE_DEBUG |
---|
| 2588 | + kbase_timer_setup(&queue->fence_timeout, fence_timeout_callback); |
---|
| 2589 | +#endif |
---|
2254 | 2590 | out: |
---|
2255 | 2591 | mutex_unlock(&kctx->csf.kcpu_queues.lock); |
---|
2256 | 2592 | |
---|
2257 | 2593 | return ret; |
---|
2258 | 2594 | } |
---|
| 2595 | +KBASE_EXPORT_TEST_API(kbase_csf_kcpu_queue_new); |
---|