submit.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* Copyright (c) 2020 NVIDIA Corporation */
  3. #include <linux/dma-fence-array.h>
  4. #include <linux/dma-mapping.h>
  5. #include <linux/file.h>
  6. #include <linux/host1x.h>
  7. #include <linux/iommu.h>
  8. #include <linux/kref.h>
  9. #include <linux/list.h>
  10. #include <linux/nospec.h>
  11. #include <linux/pm_runtime.h>
  12. #include <linux/scatterlist.h>
  13. #include <linux/slab.h>
  14. #include <linux/sync_file.h>
  15. #include <drm/drm_drv.h>
  16. #include <drm/drm_file.h>
  17. #include <drm/drm_syncobj.h>
  18. #include "drm.h"
  19. #include "gem.h"
  20. #include "submit.h"
  21. #include "uapi.h"
  22. #define SUBMIT_ERR(context, fmt, ...) \
  23. dev_err_ratelimited(context->client->base.dev, \
  24. "%s: job submission failed: " fmt "\n", \
  25. current->comm, ##__VA_ARGS__)
  26. struct gather_bo {
  27. struct host1x_bo base;
  28. struct kref ref;
  29. struct device *dev;
  30. u32 *gather_data;
  31. dma_addr_t gather_data_dma;
  32. size_t gather_data_words;
  33. };
  34. static struct host1x_bo *gather_bo_get(struct host1x_bo *host_bo)
  35. {
  36. struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);
  37. kref_get(&bo->ref);
  38. return host_bo;
  39. }
  40. static void gather_bo_release(struct kref *ref)
  41. {
  42. struct gather_bo *bo = container_of(ref, struct gather_bo, ref);
  43. dma_free_attrs(bo->dev, bo->gather_data_words * 4, bo->gather_data, bo->gather_data_dma,
  44. 0);
  45. kfree(bo);
  46. }
  47. static void gather_bo_put(struct host1x_bo *host_bo)
  48. {
  49. struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);
  50. kref_put(&bo->ref, gather_bo_release);
  51. }
  52. static struct host1x_bo_mapping *
  53. gather_bo_pin(struct device *dev, struct host1x_bo *bo, enum dma_data_direction direction)
  54. {
  55. struct gather_bo *gather = container_of(bo, struct gather_bo, base);
  56. struct host1x_bo_mapping *map;
  57. int err;
  58. map = kzalloc(sizeof(*map), GFP_KERNEL);
  59. if (!map)
  60. return ERR_PTR(-ENOMEM);
  61. kref_init(&map->ref);
  62. map->bo = host1x_bo_get(bo);
  63. map->direction = direction;
  64. map->dev = dev;
  65. map->sgt = kzalloc(sizeof(*map->sgt), GFP_KERNEL);
  66. if (!map->sgt) {
  67. err = -ENOMEM;
  68. goto free;
  69. }
  70. err = dma_get_sgtable(gather->dev, map->sgt, gather->gather_data, gather->gather_data_dma,
  71. gather->gather_data_words * 4);
  72. if (err)
  73. goto free_sgt;
  74. err = dma_map_sgtable(dev, map->sgt, direction, 0);
  75. if (err)
  76. goto free_sgt;
  77. map->phys = sg_dma_address(map->sgt->sgl);
  78. map->size = gather->gather_data_words * 4;
  79. map->chunks = err;
  80. return map;
  81. free_sgt:
  82. sg_free_table(map->sgt);
  83. kfree(map->sgt);
  84. free:
  85. kfree(map);
  86. return ERR_PTR(err);
  87. }
  88. static void gather_bo_unpin(struct host1x_bo_mapping *map)
  89. {
  90. if (!map)
  91. return;
  92. dma_unmap_sgtable(map->dev, map->sgt, map->direction, 0);
  93. sg_free_table(map->sgt);
  94. kfree(map->sgt);
  95. host1x_bo_put(map->bo);
  96. kfree(map);
  97. }
  98. static void *gather_bo_mmap(struct host1x_bo *host_bo)
  99. {
  100. struct gather_bo *bo = container_of(host_bo, struct gather_bo, base);
  101. return bo->gather_data;
  102. }
  103. static void gather_bo_munmap(struct host1x_bo *host_bo, void *addr)
  104. {
  105. }
  106. const struct host1x_bo_ops gather_bo_ops = {
  107. .get = gather_bo_get,
  108. .put = gather_bo_put,
  109. .pin = gather_bo_pin,
  110. .unpin = gather_bo_unpin,
  111. .mmap = gather_bo_mmap,
  112. .munmap = gather_bo_munmap,
  113. };
  114. static struct tegra_drm_mapping *
  115. tegra_drm_mapping_get(struct tegra_drm_context *context, u32 id)
  116. {
  117. struct tegra_drm_mapping *mapping;
  118. xa_lock(&context->mappings);
  119. mapping = xa_load(&context->mappings, id);
  120. if (mapping)
  121. kref_get(&mapping->ref);
  122. xa_unlock(&context->mappings);
  123. return mapping;
  124. }
  125. static void *alloc_copy_user_array(void __user *from, size_t count, size_t size)
  126. {
  127. size_t copy_len;
  128. void *data;
  129. if (check_mul_overflow(count, size, &copy_len))
  130. return ERR_PTR(-EINVAL);
  131. if (copy_len > 0x4000)
  132. return ERR_PTR(-E2BIG);
  133. data = kvmalloc(copy_len, GFP_KERNEL);
  134. if (!data)
  135. return ERR_PTR(-ENOMEM);
  136. if (copy_from_user(data, from, copy_len)) {
  137. kvfree(data);
  138. return ERR_PTR(-EFAULT);
  139. }
  140. return data;
  141. }
  142. static int submit_copy_gather_data(struct gather_bo **pbo, struct device *dev,
  143. struct tegra_drm_context *context,
  144. struct drm_tegra_channel_submit *args)
  145. {
  146. struct gather_bo *bo;
  147. size_t copy_len;
  148. if (args->gather_data_words == 0) {
  149. SUBMIT_ERR(context, "gather_data_words cannot be zero");
  150. return -EINVAL;
  151. }
  152. if (check_mul_overflow((size_t)args->gather_data_words, (size_t)4, &copy_len)) {
  153. SUBMIT_ERR(context, "gather_data_words is too large");
  154. return -EINVAL;
  155. }
  156. bo = kzalloc(sizeof(*bo), GFP_KERNEL);
  157. if (!bo) {
  158. SUBMIT_ERR(context, "failed to allocate memory for bo info");
  159. return -ENOMEM;
  160. }
  161. host1x_bo_init(&bo->base, &gather_bo_ops);
  162. kref_init(&bo->ref);
  163. bo->dev = dev;
  164. bo->gather_data = dma_alloc_attrs(dev, copy_len, &bo->gather_data_dma,
  165. GFP_KERNEL | __GFP_NOWARN, 0);
  166. if (!bo->gather_data) {
  167. SUBMIT_ERR(context, "failed to allocate memory for gather data");
  168. kfree(bo);
  169. return -ENOMEM;
  170. }
  171. if (copy_from_user(bo->gather_data, u64_to_user_ptr(args->gather_data_ptr), copy_len)) {
  172. SUBMIT_ERR(context, "failed to copy gather data from userspace");
  173. dma_free_attrs(dev, copy_len, bo->gather_data, bo->gather_data_dma, 0);
  174. kfree(bo);
  175. return -EFAULT;
  176. }
  177. bo->gather_data_words = args->gather_data_words;
  178. *pbo = bo;
  179. return 0;
  180. }
  181. static int submit_write_reloc(struct tegra_drm_context *context, struct gather_bo *bo,
  182. struct drm_tegra_submit_buf *buf, struct tegra_drm_mapping *mapping)
  183. {
  184. /* TODO check that target_offset is within bounds */
  185. dma_addr_t iova = mapping->iova + buf->reloc.target_offset;
  186. u32 written_ptr;
  187. #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
  188. if (buf->flags & DRM_TEGRA_SUBMIT_RELOC_SECTOR_LAYOUT)
  189. iova |= BIT_ULL(39);
  190. #endif
  191. written_ptr = iova >> buf->reloc.shift;
  192. if (buf->reloc.gather_offset_words >= bo->gather_data_words) {
  193. SUBMIT_ERR(context,
  194. "relocation has too large gather offset (%u vs gather length %zu)",
  195. buf->reloc.gather_offset_words, bo->gather_data_words);
  196. return -EINVAL;
  197. }
  198. buf->reloc.gather_offset_words = array_index_nospec(buf->reloc.gather_offset_words,
  199. bo->gather_data_words);
  200. bo->gather_data[buf->reloc.gather_offset_words] = written_ptr;
  201. return 0;
  202. }
  203. static int submit_process_bufs(struct tegra_drm_context *context, struct gather_bo *bo,
  204. struct drm_tegra_channel_submit *args,
  205. struct tegra_drm_submit_data *job_data)
  206. {
  207. struct tegra_drm_used_mapping *mappings;
  208. struct drm_tegra_submit_buf *bufs;
  209. int err;
  210. u32 i;
  211. bufs = alloc_copy_user_array(u64_to_user_ptr(args->bufs_ptr), args->num_bufs,
  212. sizeof(*bufs));
  213. if (IS_ERR(bufs)) {
  214. SUBMIT_ERR(context, "failed to copy bufs array from userspace");
  215. return PTR_ERR(bufs);
  216. }
  217. mappings = kcalloc(args->num_bufs, sizeof(*mappings), GFP_KERNEL);
  218. if (!mappings) {
  219. SUBMIT_ERR(context, "failed to allocate memory for mapping info");
  220. err = -ENOMEM;
  221. goto done;
  222. }
  223. for (i = 0; i < args->num_bufs; i++) {
  224. struct drm_tegra_submit_buf *buf = &bufs[i];
  225. struct tegra_drm_mapping *mapping;
  226. if (buf->flags & ~DRM_TEGRA_SUBMIT_RELOC_SECTOR_LAYOUT) {
  227. SUBMIT_ERR(context, "invalid flag specified for buffer");
  228. err = -EINVAL;
  229. goto drop_refs;
  230. }
  231. mapping = tegra_drm_mapping_get(context, buf->mapping);
  232. if (!mapping) {
  233. SUBMIT_ERR(context, "invalid mapping ID '%u' for buffer", buf->mapping);
  234. err = -EINVAL;
  235. goto drop_refs;
  236. }
  237. err = submit_write_reloc(context, bo, buf, mapping);
  238. if (err) {
  239. tegra_drm_mapping_put(mapping);
  240. goto drop_refs;
  241. }
  242. mappings[i].mapping = mapping;
  243. mappings[i].flags = buf->flags;
  244. }
  245. job_data->used_mappings = mappings;
  246. job_data->num_used_mappings = i;
  247. err = 0;
  248. goto done;
  249. drop_refs:
  250. while (i--)
  251. tegra_drm_mapping_put(mappings[i].mapping);
  252. kfree(mappings);
  253. job_data->used_mappings = NULL;
  254. done:
  255. kvfree(bufs);
  256. return err;
  257. }
  258. static int submit_get_syncpt(struct tegra_drm_context *context, struct host1x_job *job,
  259. struct xarray *syncpoints, struct drm_tegra_channel_submit *args)
  260. {
  261. struct host1x_syncpt *sp;
  262. if (args->syncpt.flags) {
  263. SUBMIT_ERR(context, "invalid flag specified for syncpt");
  264. return -EINVAL;
  265. }
  266. /* Syncpt ref will be dropped on job release */
  267. sp = xa_load(syncpoints, args->syncpt.id);
  268. if (!sp) {
  269. SUBMIT_ERR(context, "syncpoint specified in syncpt was not allocated");
  270. return -EINVAL;
  271. }
  272. job->syncpt = host1x_syncpt_get(sp);
  273. job->syncpt_incrs = args->syncpt.increments;
  274. return 0;
  275. }
  276. static int submit_job_add_gather(struct host1x_job *job, struct tegra_drm_context *context,
  277. struct drm_tegra_submit_cmd_gather_uptr *cmd,
  278. struct gather_bo *bo, u32 *offset,
  279. struct tegra_drm_submit_data *job_data,
  280. u32 *class)
  281. {
  282. u32 next_offset;
  283. if (cmd->reserved[0] || cmd->reserved[1] || cmd->reserved[2]) {
  284. SUBMIT_ERR(context, "non-zero reserved field in GATHER_UPTR command");
  285. return -EINVAL;
  286. }
  287. /* Check for maximum gather size */
  288. if (cmd->words > 16383) {
  289. SUBMIT_ERR(context, "too many words in GATHER_UPTR command");
  290. return -EINVAL;
  291. }
  292. if (check_add_overflow(*offset, cmd->words, &next_offset)) {
  293. SUBMIT_ERR(context, "too many total words in job");
  294. return -EINVAL;
  295. }
  296. if (next_offset > bo->gather_data_words) {
  297. SUBMIT_ERR(context, "GATHER_UPTR command overflows gather data");
  298. return -EINVAL;
  299. }
  300. if (tegra_drm_fw_validate(context->client, bo->gather_data, *offset,
  301. cmd->words, job_data, class)) {
  302. SUBMIT_ERR(context, "job was rejected by firewall");
  303. return -EINVAL;
  304. }
  305. host1x_job_add_gather(job, &bo->base, cmd->words, *offset * 4);
  306. *offset = next_offset;
  307. return 0;
  308. }
  309. static struct host1x_job *
  310. submit_create_job(struct tegra_drm_context *context, struct gather_bo *bo,
  311. struct drm_tegra_channel_submit *args, struct tegra_drm_submit_data *job_data,
  312. struct xarray *syncpoints)
  313. {
  314. struct drm_tegra_submit_cmd *cmds;
  315. u32 i, gather_offset = 0, class;
  316. struct host1x_job *job;
  317. int err;
  318. /* Set initial class for firewall. */
  319. class = context->client->base.class;
  320. cmds = alloc_copy_user_array(u64_to_user_ptr(args->cmds_ptr), args->num_cmds,
  321. sizeof(*cmds));
  322. if (IS_ERR(cmds)) {
  323. SUBMIT_ERR(context, "failed to copy cmds array from userspace");
  324. return ERR_CAST(cmds);
  325. }
  326. job = host1x_job_alloc(context->channel, args->num_cmds, 0, true);
  327. if (!job) {
  328. SUBMIT_ERR(context, "failed to allocate memory for job");
  329. job = ERR_PTR(-ENOMEM);
  330. goto done;
  331. }
  332. err = submit_get_syncpt(context, job, syncpoints, args);
  333. if (err < 0)
  334. goto free_job;
  335. job->client = &context->client->base;
  336. job->class = context->client->base.class;
  337. job->serialize = true;
  338. for (i = 0; i < args->num_cmds; i++) {
  339. struct drm_tegra_submit_cmd *cmd = &cmds[i];
  340. if (cmd->flags) {
  341. SUBMIT_ERR(context, "unknown flags given for cmd");
  342. err = -EINVAL;
  343. goto free_job;
  344. }
  345. if (cmd->type == DRM_TEGRA_SUBMIT_CMD_GATHER_UPTR) {
  346. err = submit_job_add_gather(job, context, &cmd->gather_uptr, bo,
  347. &gather_offset, job_data, &class);
  348. if (err)
  349. goto free_job;
  350. } else if (cmd->type == DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT) {
  351. if (cmd->wait_syncpt.reserved[0] || cmd->wait_syncpt.reserved[1]) {
  352. SUBMIT_ERR(context, "non-zero reserved value");
  353. err = -EINVAL;
  354. goto free_job;
  355. }
  356. host1x_job_add_wait(job, cmd->wait_syncpt.id, cmd->wait_syncpt.value,
  357. false, class);
  358. } else if (cmd->type == DRM_TEGRA_SUBMIT_CMD_WAIT_SYNCPT_RELATIVE) {
  359. if (cmd->wait_syncpt.reserved[0] || cmd->wait_syncpt.reserved[1]) {
  360. SUBMIT_ERR(context, "non-zero reserved value");
  361. err = -EINVAL;
  362. goto free_job;
  363. }
  364. if (cmd->wait_syncpt.id != args->syncpt.id) {
  365. SUBMIT_ERR(context, "syncpoint ID in CMD_WAIT_SYNCPT_RELATIVE is not used by the job");
  366. err = -EINVAL;
  367. goto free_job;
  368. }
  369. host1x_job_add_wait(job, cmd->wait_syncpt.id, cmd->wait_syncpt.value,
  370. true, class);
  371. } else {
  372. SUBMIT_ERR(context, "unknown cmd type");
  373. err = -EINVAL;
  374. goto free_job;
  375. }
  376. }
  377. if (gather_offset == 0) {
  378. SUBMIT_ERR(context, "job must have at least one gather");
  379. err = -EINVAL;
  380. goto free_job;
  381. }
  382. goto done;
  383. free_job:
  384. host1x_job_put(job);
  385. job = ERR_PTR(err);
  386. done:
  387. kvfree(cmds);
  388. return job;
  389. }
  390. static void release_job(struct host1x_job *job)
  391. {
  392. struct tegra_drm_client *client = container_of(job->client, struct tegra_drm_client, base);
  393. struct tegra_drm_submit_data *job_data = job->user_data;
  394. u32 i;
  395. if (job->memory_context)
  396. host1x_memory_context_put(job->memory_context);
  397. for (i = 0; i < job_data->num_used_mappings; i++)
  398. tegra_drm_mapping_put(job_data->used_mappings[i].mapping);
  399. kfree(job_data->used_mappings);
  400. kfree(job_data);
  401. pm_runtime_mark_last_busy(client->base.dev);
  402. pm_runtime_put_autosuspend(client->base.dev);
  403. }
  404. int tegra_drm_ioctl_channel_submit(struct drm_device *drm, void *data,
  405. struct drm_file *file)
  406. {
  407. struct tegra_drm_file *fpriv = file->driver_priv;
  408. struct drm_tegra_channel_submit *args = data;
  409. struct tegra_drm_submit_data *job_data;
  410. struct drm_syncobj *syncobj = NULL;
  411. struct tegra_drm_context *context;
  412. struct host1x_job *job;
  413. struct gather_bo *bo;
  414. u32 i;
  415. int err;
  416. mutex_lock(&fpriv->lock);
  417. context = xa_load(&fpriv->contexts, args->context);
  418. if (!context) {
  419. mutex_unlock(&fpriv->lock);
  420. pr_err_ratelimited("%s: %s: invalid channel context '%#x'", __func__,
  421. current->comm, args->context);
  422. return -EINVAL;
  423. }
  424. if (args->syncobj_in) {
  425. struct dma_fence *fence;
  426. err = drm_syncobj_find_fence(file, args->syncobj_in, 0, 0, &fence);
  427. if (err) {
  428. SUBMIT_ERR(context, "invalid syncobj_in '%#x'", args->syncobj_in);
  429. goto unlock;
  430. }
  431. err = dma_fence_wait_timeout(fence, true, msecs_to_jiffies(10000));
  432. dma_fence_put(fence);
  433. if (err) {
  434. SUBMIT_ERR(context, "wait for syncobj_in timed out");
  435. goto unlock;
  436. }
  437. }
  438. if (args->syncobj_out) {
  439. syncobj = drm_syncobj_find(file, args->syncobj_out);
  440. if (!syncobj) {
  441. SUBMIT_ERR(context, "invalid syncobj_out '%#x'", args->syncobj_out);
  442. err = -ENOENT;
  443. goto unlock;
  444. }
  445. }
  446. /* Allocate gather BO and copy gather words in. */
  447. err = submit_copy_gather_data(&bo, drm->dev, context, args);
  448. if (err)
  449. goto unlock;
  450. job_data = kzalloc(sizeof(*job_data), GFP_KERNEL);
  451. if (!job_data) {
  452. SUBMIT_ERR(context, "failed to allocate memory for job data");
  453. err = -ENOMEM;
  454. goto put_bo;
  455. }
  456. /* Get data buffer mappings and do relocation patching. */
  457. err = submit_process_bufs(context, bo, args, job_data);
  458. if (err)
  459. goto free_job_data;
  460. /* Allocate host1x_job and add gathers and waits to it. */
  461. job = submit_create_job(context, bo, args, job_data, &fpriv->syncpoints);
  462. if (IS_ERR(job)) {
  463. err = PTR_ERR(job);
  464. goto free_job_data;
  465. }
  466. /* Map gather data for Host1x. */
  467. err = host1x_job_pin(job, context->client->base.dev);
  468. if (err) {
  469. SUBMIT_ERR(context, "failed to pin job: %d", err);
  470. goto put_job;
  471. }
  472. if (context->client->ops->get_streamid_offset) {
  473. err = context->client->ops->get_streamid_offset(
  474. context->client, &job->engine_streamid_offset);
  475. if (err) {
  476. SUBMIT_ERR(context, "failed to get streamid offset: %d", err);
  477. goto unpin_job;
  478. }
  479. }
  480. if (context->memory_context && context->client->ops->can_use_memory_ctx) {
  481. bool supported;
  482. err = context->client->ops->can_use_memory_ctx(context->client, &supported);
  483. if (err) {
  484. SUBMIT_ERR(context, "failed to detect if engine can use memory context: %d", err);
  485. goto unpin_job;
  486. }
  487. if (supported) {
  488. job->memory_context = context->memory_context;
  489. host1x_memory_context_get(job->memory_context);
  490. }
  491. } else if (context->client->ops->get_streamid_offset) {
  492. #ifdef CONFIG_IOMMU_API
  493. struct iommu_fwspec *spec;
  494. /*
  495. * Job submission will need to temporarily change stream ID,
  496. * so need to tell it what to change it back to.
  497. */
  498. spec = dev_iommu_fwspec_get(context->client->base.dev);
  499. if (spec && spec->num_ids > 0)
  500. job->engine_fallback_streamid = spec->ids[0] & 0xffff;
  501. else
  502. job->engine_fallback_streamid = 0x7f;
  503. #else
  504. job->engine_fallback_streamid = 0x7f;
  505. #endif
  506. }
  507. /* Boot engine. */
  508. err = pm_runtime_resume_and_get(context->client->base.dev);
  509. if (err < 0) {
  510. SUBMIT_ERR(context, "could not power up engine: %d", err);
  511. goto put_memory_context;
  512. }
  513. job->user_data = job_data;
  514. job->release = release_job;
  515. job->timeout = 10000;
  516. /*
  517. * job_data is now part of job reference counting, so don't release
  518. * it from here.
  519. */
  520. job_data = NULL;
  521. /* Submit job to hardware. */
  522. err = host1x_job_submit(job);
  523. if (err) {
  524. SUBMIT_ERR(context, "host1x job submission failed: %d", err);
  525. goto unpin_job;
  526. }
  527. /* Return postfences to userspace and add fences to DMA reservations. */
  528. args->syncpt.value = job->syncpt_end;
  529. if (syncobj) {
  530. struct dma_fence *fence = host1x_fence_create(job->syncpt, job->syncpt_end);
  531. if (IS_ERR(fence)) {
  532. err = PTR_ERR(fence);
  533. SUBMIT_ERR(context, "failed to create postfence: %d", err);
  534. }
  535. drm_syncobj_replace_fence(syncobj, fence);
  536. }
  537. goto put_job;
  538. put_memory_context:
  539. if (job->memory_context)
  540. host1x_memory_context_put(job->memory_context);
  541. unpin_job:
  542. host1x_job_unpin(job);
  543. put_job:
  544. host1x_job_put(job);
  545. free_job_data:
  546. if (job_data && job_data->used_mappings) {
  547. for (i = 0; i < job_data->num_used_mappings; i++)
  548. tegra_drm_mapping_put(job_data->used_mappings[i].mapping);
  549. kfree(job_data->used_mappings);
  550. }
  551. if (job_data)
  552. kfree(job_data);
  553. put_bo:
  554. gather_bo_put(&bo->base);
  555. unlock:
  556. if (syncobj)
  557. drm_syncobj_put(syncobj);
  558. mutex_unlock(&fpriv->lock);
  559. return err;
  560. }