| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2013 Red Hat |
|---|
| 3 | 4 | * Author: Rob Clark <robdclark@gmail.com> |
|---|
| 4 | | - * |
|---|
| 5 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 6 | | - * under the terms of the GNU General Public License version 2 as published by |
|---|
| 7 | | - * the Free Software Foundation. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 10 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 11 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 12 | | - * more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License along with |
|---|
| 15 | | - * this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 16 | 5 | */ |
|---|
| 17 | 6 | |
|---|
| 7 | +#include <linux/file.h> |
|---|
| 18 | 8 | #include <linux/sync_file.h> |
|---|
| 9 | +#include <linux/uaccess.h> |
|---|
| 10 | + |
|---|
| 11 | +#include <drm/drm_drv.h> |
|---|
| 12 | +#include <drm/drm_file.h> |
|---|
| 13 | +#include <drm/drm_syncobj.h> |
|---|
| 19 | 14 | |
|---|
| 20 | 15 | #include "msm_drv.h" |
|---|
| 21 | 16 | #include "msm_gpu.h" |
|---|
| 22 | 17 | #include "msm_gem.h" |
|---|
| 18 | +#include "msm_gpu_trace.h" |
|---|
| 23 | 19 | |
|---|
| 24 | 20 | /* |
|---|
| 25 | 21 | * Cmdstream submission: |
|---|
| .. | .. |
|---|
| 31 | 27 | #define BO_PINNED 0x2000 |
|---|
| 32 | 28 | |
|---|
| 33 | 29 | static struct msm_gem_submit *submit_create(struct drm_device *dev, |
|---|
| 34 | | - struct msm_gpu *gpu, struct msm_gpu_submitqueue *queue, |
|---|
| 35 | | - uint32_t nr_bos, uint32_t nr_cmds) |
|---|
| 30 | + struct msm_gpu *gpu, |
|---|
| 31 | + struct msm_gpu_submitqueue *queue, uint32_t nr_bos, |
|---|
| 32 | + uint32_t nr_cmds) |
|---|
| 36 | 33 | { |
|---|
| 37 | 34 | struct msm_gem_submit *submit; |
|---|
| 38 | | - uint64_t sz = sizeof(*submit) + ((u64)nr_bos * sizeof(submit->bos[0])) + |
|---|
| 39 | | - ((u64)nr_cmds * sizeof(submit->cmd[0])); |
|---|
| 35 | + uint64_t sz = struct_size(submit, bos, nr_bos) + |
|---|
| 36 | + ((u64)nr_cmds * sizeof(submit->cmd[0])); |
|---|
| 40 | 37 | |
|---|
| 41 | 38 | if (sz > SIZE_MAX) |
|---|
| 42 | 39 | return NULL; |
|---|
| .. | .. |
|---|
| 46 | 43 | return NULL; |
|---|
| 47 | 44 | |
|---|
| 48 | 45 | submit->dev = dev; |
|---|
| 46 | + submit->aspace = queue->ctx->aspace; |
|---|
| 49 | 47 | submit->gpu = gpu; |
|---|
| 50 | 48 | submit->fence = NULL; |
|---|
| 51 | | - submit->pid = get_pid(task_pid(current)); |
|---|
| 52 | 49 | submit->cmd = (void *)&submit->bos[nr_bos]; |
|---|
| 53 | 50 | submit->queue = queue; |
|---|
| 54 | 51 | submit->ring = gpu->rb[queue->prio]; |
|---|
| .. | .. |
|---|
| 59 | 56 | |
|---|
| 60 | 57 | INIT_LIST_HEAD(&submit->node); |
|---|
| 61 | 58 | INIT_LIST_HEAD(&submit->bo_list); |
|---|
| 62 | | - ww_acquire_init(&submit->ticket, &reservation_ww_class); |
|---|
| 63 | 59 | |
|---|
| 64 | 60 | return submit; |
|---|
| 65 | 61 | } |
|---|
| .. | .. |
|---|
| 74 | 70 | kfree(submit); |
|---|
| 75 | 71 | } |
|---|
| 76 | 72 | |
|---|
| 77 | | -static inline unsigned long __must_check |
|---|
| 78 | | -copy_from_user_inatomic(void *to, const void __user *from, unsigned long n) |
|---|
| 79 | | -{ |
|---|
| 80 | | - if (access_ok(VERIFY_READ, from, n)) |
|---|
| 81 | | - return __copy_from_user_inatomic(to, from, n); |
|---|
| 82 | | - return -EFAULT; |
|---|
| 83 | | -} |
|---|
| 84 | | - |
|---|
| 85 | 73 | static int submit_lookup_objects(struct msm_gem_submit *submit, |
|---|
| 86 | 74 | struct drm_msm_gem_submit *args, struct drm_file *file) |
|---|
| 87 | 75 | { |
|---|
| 88 | 76 | unsigned i; |
|---|
| 89 | 77 | int ret = 0; |
|---|
| 90 | 78 | |
|---|
| 91 | | - spin_lock(&file->table_lock); |
|---|
| 92 | | - pagefault_disable(); |
|---|
| 93 | | - |
|---|
| 94 | 79 | for (i = 0; i < args->nr_bos; i++) { |
|---|
| 95 | 80 | struct drm_msm_gem_submit_bo submit_bo; |
|---|
| 96 | | - struct drm_gem_object *obj; |
|---|
| 97 | | - struct msm_gem_object *msm_obj; |
|---|
| 98 | 81 | void __user *userptr = |
|---|
| 99 | 82 | u64_to_user_ptr(args->bos + (i * sizeof(submit_bo))); |
|---|
| 100 | 83 | |
|---|
| .. | .. |
|---|
| 103 | 86 | */ |
|---|
| 104 | 87 | submit->bos[i].flags = 0; |
|---|
| 105 | 88 | |
|---|
| 106 | | - if (copy_from_user_inatomic(&submit_bo, userptr, sizeof(submit_bo))) { |
|---|
| 107 | | - pagefault_enable(); |
|---|
| 108 | | - spin_unlock(&file->table_lock); |
|---|
| 109 | | - if (copy_from_user(&submit_bo, userptr, sizeof(submit_bo))) { |
|---|
| 110 | | - ret = -EFAULT; |
|---|
| 111 | | - goto out; |
|---|
| 112 | | - } |
|---|
| 113 | | - spin_lock(&file->table_lock); |
|---|
| 114 | | - pagefault_disable(); |
|---|
| 89 | + if (copy_from_user(&submit_bo, userptr, sizeof(submit_bo))) { |
|---|
| 90 | + ret = -EFAULT; |
|---|
| 91 | + i = 0; |
|---|
| 92 | + goto out; |
|---|
| 115 | 93 | } |
|---|
| 94 | + |
|---|
| 95 | +/* at least one of READ and/or WRITE flags should be set: */ |
|---|
| 96 | +#define MANDATORY_FLAGS (MSM_SUBMIT_BO_READ | MSM_SUBMIT_BO_WRITE) |
|---|
| 116 | 97 | |
|---|
| 117 | 98 | if ((submit_bo.flags & ~MSM_SUBMIT_BO_FLAGS) || |
|---|
| 118 | | - !(submit_bo.flags & MSM_SUBMIT_BO_FLAGS)) { |
|---|
| 99 | + !(submit_bo.flags & MANDATORY_FLAGS)) { |
|---|
| 119 | 100 | DRM_ERROR("invalid flags: %x\n", submit_bo.flags); |
|---|
| 120 | 101 | ret = -EINVAL; |
|---|
| 121 | | - goto out_unlock; |
|---|
| 102 | + i = 0; |
|---|
| 103 | + goto out; |
|---|
| 122 | 104 | } |
|---|
| 123 | 105 | |
|---|
| 106 | + submit->bos[i].handle = submit_bo.handle; |
|---|
| 124 | 107 | submit->bos[i].flags = submit_bo.flags; |
|---|
| 125 | 108 | /* in validate_objects() we figure out if this is true: */ |
|---|
| 126 | 109 | submit->bos[i].iova = submit_bo.presumed; |
|---|
| 110 | + } |
|---|
| 111 | + |
|---|
| 112 | + spin_lock(&file->table_lock); |
|---|
| 113 | + |
|---|
| 114 | + for (i = 0; i < args->nr_bos; i++) { |
|---|
| 115 | + struct drm_gem_object *obj; |
|---|
| 116 | + struct msm_gem_object *msm_obj; |
|---|
| 127 | 117 | |
|---|
| 128 | 118 | /* normally use drm_gem_object_lookup(), but for bulk lookup |
|---|
| 129 | 119 | * all under single table_lock just hit object_idr directly: |
|---|
| 130 | 120 | */ |
|---|
| 131 | | - obj = idr_find(&file->object_idr, submit_bo.handle); |
|---|
| 121 | + obj = idr_find(&file->object_idr, submit->bos[i].handle); |
|---|
| 132 | 122 | if (!obj) { |
|---|
| 133 | | - DRM_ERROR("invalid handle %u at index %u\n", submit_bo.handle, i); |
|---|
| 123 | + DRM_ERROR("invalid handle %u at index %u\n", submit->bos[i].handle, i); |
|---|
| 134 | 124 | ret = -EINVAL; |
|---|
| 135 | 125 | goto out_unlock; |
|---|
| 136 | 126 | } |
|---|
| .. | .. |
|---|
| 139 | 129 | |
|---|
| 140 | 130 | if (!list_empty(&msm_obj->submit_entry)) { |
|---|
| 141 | 131 | DRM_ERROR("handle %u at index %u already on submit list\n", |
|---|
| 142 | | - submit_bo.handle, i); |
|---|
| 132 | + submit->bos[i].handle, i); |
|---|
| 143 | 133 | ret = -EINVAL; |
|---|
| 144 | 134 | goto out_unlock; |
|---|
| 145 | 135 | } |
|---|
| 146 | 136 | |
|---|
| 147 | | - drm_gem_object_reference(obj); |
|---|
| 137 | + drm_gem_object_get(obj); |
|---|
| 148 | 138 | |
|---|
| 149 | 139 | submit->bos[i].obj = msm_obj; |
|---|
| 150 | 140 | |
|---|
| .. | .. |
|---|
| 152 | 142 | } |
|---|
| 153 | 143 | |
|---|
| 154 | 144 | out_unlock: |
|---|
| 155 | | - pagefault_enable(); |
|---|
| 156 | 145 | spin_unlock(&file->table_lock); |
|---|
| 157 | 146 | |
|---|
| 158 | 147 | out: |
|---|
| .. | .. |
|---|
| 167 | 156 | struct msm_gem_object *msm_obj = submit->bos[i].obj; |
|---|
| 168 | 157 | |
|---|
| 169 | 158 | if (submit->bos[i].flags & BO_PINNED) |
|---|
| 170 | | - msm_gem_put_iova(&msm_obj->base, submit->gpu->aspace); |
|---|
| 159 | + msm_gem_unpin_iova(&msm_obj->base, submit->aspace); |
|---|
| 171 | 160 | |
|---|
| 172 | 161 | if (submit->bos[i].flags & BO_LOCKED) |
|---|
| 173 | | - ww_mutex_unlock(&msm_obj->resv->lock); |
|---|
| 162 | + dma_resv_unlock(msm_obj->base.resv); |
|---|
| 174 | 163 | |
|---|
| 175 | 164 | if (backoff && !(submit->bos[i].flags & BO_VALID)) |
|---|
| 176 | 165 | submit->bos[i].iova = 0; |
|---|
| .. | .. |
|---|
| 193 | 182 | contended = i; |
|---|
| 194 | 183 | |
|---|
| 195 | 184 | if (!(submit->bos[i].flags & BO_LOCKED)) { |
|---|
| 196 | | - ret = ww_mutex_lock_interruptible(&msm_obj->resv->lock, |
|---|
| 197 | | - &submit->ticket); |
|---|
| 185 | + ret = dma_resv_lock_interruptible(msm_obj->base.resv, |
|---|
| 186 | + &submit->ticket); |
|---|
| 198 | 187 | if (ret) |
|---|
| 199 | 188 | goto fail; |
|---|
| 200 | 189 | submit->bos[i].flags |= BO_LOCKED; |
|---|
| .. | .. |
|---|
| 215 | 204 | if (ret == -EDEADLK) { |
|---|
| 216 | 205 | struct msm_gem_object *msm_obj = submit->bos[contended].obj; |
|---|
| 217 | 206 | /* we lost out in a seqno race, lock and retry.. */ |
|---|
| 218 | | - ret = ww_mutex_lock_slow_interruptible(&msm_obj->resv->lock, |
|---|
| 219 | | - &submit->ticket); |
|---|
| 207 | + ret = dma_resv_lock_slow_interruptible(msm_obj->base.resv, |
|---|
| 208 | + &submit->ticket); |
|---|
| 220 | 209 | if (!ret) { |
|---|
| 221 | 210 | submit->bos[contended].flags |= BO_LOCKED; |
|---|
| 222 | 211 | slow_locked = contended; |
|---|
| .. | .. |
|---|
| 241 | 230 | * strange place to call it. OTOH this is a |
|---|
| 242 | 231 | * convenient can-fail point to hook it in. |
|---|
| 243 | 232 | */ |
|---|
| 244 | | - ret = reservation_object_reserve_shared(msm_obj->resv); |
|---|
| 233 | + ret = dma_resv_reserve_shared(msm_obj->base.resv, |
|---|
| 234 | + 1); |
|---|
| 245 | 235 | if (ret) |
|---|
| 246 | 236 | return ret; |
|---|
| 247 | 237 | } |
|---|
| .. | .. |
|---|
| 269 | 259 | uint64_t iova; |
|---|
| 270 | 260 | |
|---|
| 271 | 261 | /* if locking succeeded, pin bo: */ |
|---|
| 272 | | - ret = msm_gem_get_iova(&msm_obj->base, |
|---|
| 273 | | - submit->gpu->aspace, &iova); |
|---|
| 262 | + ret = msm_gem_get_and_pin_iova(&msm_obj->base, |
|---|
| 263 | + submit->aspace, &iova); |
|---|
| 274 | 264 | |
|---|
| 275 | 265 | if (ret) |
|---|
| 276 | 266 | break; |
|---|
| .. | .. |
|---|
| 316 | 306 | uint32_t i, last_offset = 0; |
|---|
| 317 | 307 | uint32_t *ptr; |
|---|
| 318 | 308 | int ret = 0; |
|---|
| 309 | + |
|---|
| 310 | + if (!nr_relocs) |
|---|
| 311 | + return 0; |
|---|
| 319 | 312 | |
|---|
| 320 | 313 | if (offset % 4) { |
|---|
| 321 | 314 | DRM_ERROR("non-aligned cmdstream buffer: %u\n", offset); |
|---|
| .. | .. |
|---|
| 396 | 389 | struct msm_gem_object *msm_obj = submit->bos[i].obj; |
|---|
| 397 | 390 | submit_unlock_unpin_bo(submit, i, false); |
|---|
| 398 | 391 | list_del_init(&msm_obj->submit_entry); |
|---|
| 399 | | - drm_gem_object_unreference(&msm_obj->base); |
|---|
| 392 | + drm_gem_object_put_locked(&msm_obj->base); |
|---|
| 393 | + } |
|---|
| 394 | +} |
|---|
| 395 | + |
|---|
| 396 | + |
|---|
| 397 | +struct msm_submit_post_dep { |
|---|
| 398 | + struct drm_syncobj *syncobj; |
|---|
| 399 | + uint64_t point; |
|---|
| 400 | + struct dma_fence_chain *chain; |
|---|
| 401 | +}; |
|---|
| 402 | + |
|---|
| 403 | +static struct drm_syncobj **msm_wait_deps(struct drm_device *dev, |
|---|
| 404 | + struct drm_file *file, |
|---|
| 405 | + uint64_t in_syncobjs_addr, |
|---|
| 406 | + uint32_t nr_in_syncobjs, |
|---|
| 407 | + size_t syncobj_stride, |
|---|
| 408 | + struct msm_ringbuffer *ring) |
|---|
| 409 | +{ |
|---|
| 410 | + struct drm_syncobj **syncobjs = NULL; |
|---|
| 411 | + struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; |
|---|
| 412 | + int ret = 0; |
|---|
| 413 | + uint32_t i, j; |
|---|
| 414 | + |
|---|
| 415 | + syncobjs = kcalloc(nr_in_syncobjs, sizeof(*syncobjs), |
|---|
| 416 | + GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); |
|---|
| 417 | + if (!syncobjs) |
|---|
| 418 | + return ERR_PTR(-ENOMEM); |
|---|
| 419 | + |
|---|
| 420 | + for (i = 0; i < nr_in_syncobjs; ++i) { |
|---|
| 421 | + uint64_t address = in_syncobjs_addr + i * syncobj_stride; |
|---|
| 422 | + struct dma_fence *fence; |
|---|
| 423 | + |
|---|
| 424 | + if (copy_from_user(&syncobj_desc, |
|---|
| 425 | + u64_to_user_ptr(address), |
|---|
| 426 | + min(syncobj_stride, sizeof(syncobj_desc)))) { |
|---|
| 427 | + ret = -EFAULT; |
|---|
| 428 | + break; |
|---|
| 429 | + } |
|---|
| 430 | + |
|---|
| 431 | + if (syncobj_desc.point && |
|---|
| 432 | + !drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE)) { |
|---|
| 433 | + ret = -EOPNOTSUPP; |
|---|
| 434 | + break; |
|---|
| 435 | + } |
|---|
| 436 | + |
|---|
| 437 | + if (syncobj_desc.flags & ~MSM_SUBMIT_SYNCOBJ_FLAGS) { |
|---|
| 438 | + ret = -EINVAL; |
|---|
| 439 | + break; |
|---|
| 440 | + } |
|---|
| 441 | + |
|---|
| 442 | + ret = drm_syncobj_find_fence(file, syncobj_desc.handle, |
|---|
| 443 | + syncobj_desc.point, 0, &fence); |
|---|
| 444 | + if (ret) |
|---|
| 445 | + break; |
|---|
| 446 | + |
|---|
| 447 | + if (!dma_fence_match_context(fence, ring->fctx->context)) |
|---|
| 448 | + ret = dma_fence_wait(fence, true); |
|---|
| 449 | + |
|---|
| 450 | + dma_fence_put(fence); |
|---|
| 451 | + if (ret) |
|---|
| 452 | + break; |
|---|
| 453 | + |
|---|
| 454 | + if (syncobj_desc.flags & MSM_SUBMIT_SYNCOBJ_RESET) { |
|---|
| 455 | + syncobjs[i] = |
|---|
| 456 | + drm_syncobj_find(file, syncobj_desc.handle); |
|---|
| 457 | + if (!syncobjs[i]) { |
|---|
| 458 | + ret = -EINVAL; |
|---|
| 459 | + break; |
|---|
| 460 | + } |
|---|
| 461 | + } |
|---|
| 400 | 462 | } |
|---|
| 401 | 463 | |
|---|
| 402 | | - ww_acquire_fini(&submit->ticket); |
|---|
| 464 | + if (ret) { |
|---|
| 465 | + for (j = 0; j <= i; ++j) { |
|---|
| 466 | + if (syncobjs[j]) |
|---|
| 467 | + drm_syncobj_put(syncobjs[j]); |
|---|
| 468 | + } |
|---|
| 469 | + kfree(syncobjs); |
|---|
| 470 | + return ERR_PTR(ret); |
|---|
| 471 | + } |
|---|
| 472 | + return syncobjs; |
|---|
| 473 | +} |
|---|
| 474 | + |
|---|
| 475 | +static void msm_reset_syncobjs(struct drm_syncobj **syncobjs, |
|---|
| 476 | + uint32_t nr_syncobjs) |
|---|
| 477 | +{ |
|---|
| 478 | + uint32_t i; |
|---|
| 479 | + |
|---|
| 480 | + for (i = 0; syncobjs && i < nr_syncobjs; ++i) { |
|---|
| 481 | + if (syncobjs[i]) |
|---|
| 482 | + drm_syncobj_replace_fence(syncobjs[i], NULL); |
|---|
| 483 | + } |
|---|
| 484 | +} |
|---|
| 485 | + |
|---|
| 486 | +static struct msm_submit_post_dep *msm_parse_post_deps(struct drm_device *dev, |
|---|
| 487 | + struct drm_file *file, |
|---|
| 488 | + uint64_t syncobjs_addr, |
|---|
| 489 | + uint32_t nr_syncobjs, |
|---|
| 490 | + size_t syncobj_stride) |
|---|
| 491 | +{ |
|---|
| 492 | + struct msm_submit_post_dep *post_deps; |
|---|
| 493 | + struct drm_msm_gem_submit_syncobj syncobj_desc = {0}; |
|---|
| 494 | + int ret = 0; |
|---|
| 495 | + uint32_t i, j; |
|---|
| 496 | + |
|---|
| 497 | + post_deps = kmalloc_array(nr_syncobjs, sizeof(*post_deps), |
|---|
| 498 | + GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY); |
|---|
| 499 | + if (!post_deps) |
|---|
| 500 | + return ERR_PTR(-ENOMEM); |
|---|
| 501 | + |
|---|
| 502 | + for (i = 0; i < nr_syncobjs; ++i) { |
|---|
| 503 | + uint64_t address = syncobjs_addr + i * syncobj_stride; |
|---|
| 504 | + |
|---|
| 505 | + if (copy_from_user(&syncobj_desc, |
|---|
| 506 | + u64_to_user_ptr(address), |
|---|
| 507 | + min(syncobj_stride, sizeof(syncobj_desc)))) { |
|---|
| 508 | + ret = -EFAULT; |
|---|
| 509 | + break; |
|---|
| 510 | + } |
|---|
| 511 | + |
|---|
| 512 | + post_deps[i].point = syncobj_desc.point; |
|---|
| 513 | + post_deps[i].chain = NULL; |
|---|
| 514 | + |
|---|
| 515 | + if (syncobj_desc.flags) { |
|---|
| 516 | + ret = -EINVAL; |
|---|
| 517 | + break; |
|---|
| 518 | + } |
|---|
| 519 | + |
|---|
| 520 | + if (syncobj_desc.point) { |
|---|
| 521 | + if (!drm_core_check_feature(dev, |
|---|
| 522 | + DRIVER_SYNCOBJ_TIMELINE)) { |
|---|
| 523 | + ret = -EOPNOTSUPP; |
|---|
| 524 | + break; |
|---|
| 525 | + } |
|---|
| 526 | + |
|---|
| 527 | + post_deps[i].chain = |
|---|
| 528 | + kmalloc(sizeof(*post_deps[i].chain), |
|---|
| 529 | + GFP_KERNEL); |
|---|
| 530 | + if (!post_deps[i].chain) { |
|---|
| 531 | + ret = -ENOMEM; |
|---|
| 532 | + break; |
|---|
| 533 | + } |
|---|
| 534 | + } |
|---|
| 535 | + |
|---|
| 536 | + post_deps[i].syncobj = |
|---|
| 537 | + drm_syncobj_find(file, syncobj_desc.handle); |
|---|
| 538 | + if (!post_deps[i].syncobj) { |
|---|
| 539 | + ret = -EINVAL; |
|---|
| 540 | + break; |
|---|
| 541 | + } |
|---|
| 542 | + } |
|---|
| 543 | + |
|---|
| 544 | + if (ret) { |
|---|
| 545 | + for (j = 0; j <= i; ++j) { |
|---|
| 546 | + kfree(post_deps[j].chain); |
|---|
| 547 | + if (post_deps[j].syncobj) |
|---|
| 548 | + drm_syncobj_put(post_deps[j].syncobj); |
|---|
| 549 | + } |
|---|
| 550 | + |
|---|
| 551 | + kfree(post_deps); |
|---|
| 552 | + return ERR_PTR(ret); |
|---|
| 553 | + } |
|---|
| 554 | + |
|---|
| 555 | + return post_deps; |
|---|
| 556 | +} |
|---|
| 557 | + |
|---|
| 558 | +static void msm_process_post_deps(struct msm_submit_post_dep *post_deps, |
|---|
| 559 | + uint32_t count, struct dma_fence *fence) |
|---|
| 560 | +{ |
|---|
| 561 | + uint32_t i; |
|---|
| 562 | + |
|---|
| 563 | + for (i = 0; post_deps && i < count; ++i) { |
|---|
| 564 | + if (post_deps[i].chain) { |
|---|
| 565 | + drm_syncobj_add_point(post_deps[i].syncobj, |
|---|
| 566 | + post_deps[i].chain, |
|---|
| 567 | + fence, post_deps[i].point); |
|---|
| 568 | + post_deps[i].chain = NULL; |
|---|
| 569 | + } else { |
|---|
| 570 | + drm_syncobj_replace_fence(post_deps[i].syncobj, |
|---|
| 571 | + fence); |
|---|
| 572 | + } |
|---|
| 573 | + } |
|---|
| 403 | 574 | } |
|---|
| 404 | 575 | |
|---|
| 405 | 576 | int msm_ioctl_gem_submit(struct drm_device *dev, void *data, |
|---|
| 406 | 577 | struct drm_file *file) |
|---|
| 407 | 578 | { |
|---|
| 579 | + static atomic_t ident = ATOMIC_INIT(0); |
|---|
| 408 | 580 | struct msm_drm_private *priv = dev->dev_private; |
|---|
| 409 | 581 | struct drm_msm_gem_submit *args = data; |
|---|
| 410 | 582 | struct msm_file_private *ctx = file->driver_priv; |
|---|
| .. | .. |
|---|
| 413 | 585 | struct sync_file *sync_file = NULL; |
|---|
| 414 | 586 | struct msm_gpu_submitqueue *queue; |
|---|
| 415 | 587 | struct msm_ringbuffer *ring; |
|---|
| 588 | + struct msm_submit_post_dep *post_deps = NULL; |
|---|
| 589 | + struct drm_syncobj **syncobjs_to_reset = NULL; |
|---|
| 416 | 590 | int out_fence_fd = -1; |
|---|
| 591 | + struct pid *pid = get_pid(task_pid(current)); |
|---|
| 592 | + bool has_ww_ticket = false; |
|---|
| 417 | 593 | unsigned i; |
|---|
| 418 | | - int ret; |
|---|
| 419 | | - |
|---|
| 594 | + int ret, submitid; |
|---|
| 420 | 595 | if (!gpu) |
|---|
| 421 | 596 | return -ENXIO; |
|---|
| 597 | + |
|---|
| 598 | + if (args->pad) |
|---|
| 599 | + return -EINVAL; |
|---|
| 422 | 600 | |
|---|
| 423 | 601 | /* for now, we just have 3d pipe.. eventually this would need to |
|---|
| 424 | 602 | * be more clever to dispatch to appropriate gpu module: |
|---|
| .. | .. |
|---|
| 439 | 617 | if (!queue) |
|---|
| 440 | 618 | return -ENOENT; |
|---|
| 441 | 619 | |
|---|
| 620 | + /* Get a unique identifier for the submission for logging purposes */ |
|---|
| 621 | + submitid = atomic_inc_return(&ident) - 1; |
|---|
| 622 | + |
|---|
| 442 | 623 | ring = gpu->rb[queue->prio]; |
|---|
| 624 | + trace_msm_gpu_submit(pid_nr(pid), ring->id, submitid, |
|---|
| 625 | + args->nr_bos, args->nr_cmds); |
|---|
| 443 | 626 | |
|---|
| 444 | 627 | if (args->flags & MSM_SUBMIT_FENCE_FD_IN) { |
|---|
| 445 | 628 | struct dma_fence *in_fence; |
|---|
| .. | .. |
|---|
| 462 | 645 | return ret; |
|---|
| 463 | 646 | } |
|---|
| 464 | 647 | |
|---|
| 648 | + if (args->flags & MSM_SUBMIT_SYNCOBJ_IN) { |
|---|
| 649 | + syncobjs_to_reset = msm_wait_deps(dev, file, |
|---|
| 650 | + args->in_syncobjs, |
|---|
| 651 | + args->nr_in_syncobjs, |
|---|
| 652 | + args->syncobj_stride, ring); |
|---|
| 653 | + if (IS_ERR(syncobjs_to_reset)) |
|---|
| 654 | + return PTR_ERR(syncobjs_to_reset); |
|---|
| 655 | + } |
|---|
| 656 | + |
|---|
| 657 | + if (args->flags & MSM_SUBMIT_SYNCOBJ_OUT) { |
|---|
| 658 | + post_deps = msm_parse_post_deps(dev, file, |
|---|
| 659 | + args->out_syncobjs, |
|---|
| 660 | + args->nr_out_syncobjs, |
|---|
| 661 | + args->syncobj_stride); |
|---|
| 662 | + if (IS_ERR(post_deps)) { |
|---|
| 663 | + ret = PTR_ERR(post_deps); |
|---|
| 664 | + goto out_post_unlock; |
|---|
| 665 | + } |
|---|
| 666 | + } |
|---|
| 667 | + |
|---|
| 465 | 668 | ret = mutex_lock_interruptible(&dev->struct_mutex); |
|---|
| 466 | 669 | if (ret) |
|---|
| 467 | | - return ret; |
|---|
| 670 | + goto out_post_unlock; |
|---|
| 468 | 671 | |
|---|
| 469 | 672 | if (args->flags & MSM_SUBMIT_FENCE_FD_OUT) { |
|---|
| 470 | 673 | out_fence_fd = get_unused_fd_flags(O_CLOEXEC); |
|---|
| .. | .. |
|---|
| 474 | 677 | } |
|---|
| 475 | 678 | } |
|---|
| 476 | 679 | |
|---|
| 477 | | - submit = submit_create(dev, gpu, queue, args->nr_bos, args->nr_cmds); |
|---|
| 680 | + submit = submit_create(dev, gpu, queue, args->nr_bos, |
|---|
| 681 | + args->nr_cmds); |
|---|
| 478 | 682 | if (!submit) { |
|---|
| 479 | 683 | ret = -ENOMEM; |
|---|
| 480 | 684 | goto out_unlock; |
|---|
| 481 | 685 | } |
|---|
| 686 | + |
|---|
| 687 | + submit->pid = pid; |
|---|
| 688 | + submit->ident = submitid; |
|---|
| 482 | 689 | |
|---|
| 483 | 690 | if (args->flags & MSM_SUBMIT_SUDO) |
|---|
| 484 | 691 | submit->in_rb = true; |
|---|
| .. | .. |
|---|
| 487 | 694 | if (ret) |
|---|
| 488 | 695 | goto out; |
|---|
| 489 | 696 | |
|---|
| 697 | + /* copy_*_user while holding a ww ticket upsets lockdep */ |
|---|
| 698 | + ww_acquire_init(&submit->ticket, &reservation_ww_class); |
|---|
| 699 | + has_ww_ticket = true; |
|---|
| 490 | 700 | ret = submit_lock_objects(submit); |
|---|
| 491 | 701 | if (ret) |
|---|
| 492 | 702 | goto out; |
|---|
| .. | .. |
|---|
| 575 | 785 | } |
|---|
| 576 | 786 | } |
|---|
| 577 | 787 | |
|---|
| 578 | | - msm_gpu_submit(gpu, submit, ctx); |
|---|
| 788 | + msm_gpu_submit(gpu, submit); |
|---|
| 579 | 789 | |
|---|
| 580 | 790 | args->fence = submit->fence->seqno; |
|---|
| 581 | 791 | |
|---|
| .. | .. |
|---|
| 584 | 794 | args->fence_fd = out_fence_fd; |
|---|
| 585 | 795 | } |
|---|
| 586 | 796 | |
|---|
| 797 | + msm_reset_syncobjs(syncobjs_to_reset, args->nr_in_syncobjs); |
|---|
| 798 | + msm_process_post_deps(post_deps, args->nr_out_syncobjs, |
|---|
| 799 | + submit->fence); |
|---|
| 800 | + |
|---|
| 801 | + |
|---|
| 587 | 802 | out: |
|---|
| 588 | 803 | submit_cleanup(submit); |
|---|
| 804 | + if (has_ww_ticket) |
|---|
| 805 | + ww_acquire_fini(&submit->ticket); |
|---|
| 589 | 806 | if (ret) |
|---|
| 590 | 807 | msm_gem_submit_free(submit); |
|---|
| 591 | 808 | out_unlock: |
|---|
| 592 | 809 | if (ret && (out_fence_fd >= 0)) |
|---|
| 593 | 810 | put_unused_fd(out_fence_fd); |
|---|
| 594 | 811 | mutex_unlock(&dev->struct_mutex); |
|---|
| 812 | + |
|---|
| 813 | +out_post_unlock: |
|---|
| 814 | + if (!IS_ERR_OR_NULL(post_deps)) { |
|---|
| 815 | + for (i = 0; i < args->nr_out_syncobjs; ++i) { |
|---|
| 816 | + kfree(post_deps[i].chain); |
|---|
| 817 | + drm_syncobj_put(post_deps[i].syncobj); |
|---|
| 818 | + } |
|---|
| 819 | + kfree(post_deps); |
|---|
| 820 | + } |
|---|
| 821 | + |
|---|
| 822 | + if (!IS_ERR_OR_NULL(syncobjs_to_reset)) { |
|---|
| 823 | + for (i = 0; i < args->nr_in_syncobjs; ++i) { |
|---|
| 824 | + if (syncobjs_to_reset[i]) |
|---|
| 825 | + drm_syncobj_put(syncobjs_to_reset[i]); |
|---|
| 826 | + } |
|---|
| 827 | + kfree(syncobjs_to_reset); |
|---|
| 828 | + } |
|---|
| 829 | + |
|---|
| 595 | 830 | return ret; |
|---|
| 596 | 831 | } |
|---|