From: Sasha Levin <sashal@kernel.org> To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "Chris Wilson" <chris@chris-wilson.co.uk>, "Alex Deucher" <alexander.deucher@amd.com>, "Christian König" <christian.koenig@amd.com>, "Sasha Levin" <sashal@kernel.org>, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.19 28/64] drm/amdgpu: Transfer fences to dmabuf importer Date: Thu, 28 Feb 2019 10:10:29 -0500 [thread overview] Message-ID: <20190228151105.11277-28-sashal@kernel.org> (raw) In-Reply-To: <20190228151105.11277-1-sashal@kernel.org> From: Chris Wilson <chris@chris-wilson.co.uk> [ Upstream commit 6e11ea9de9576a644045ffdc2067c09bc2012eda ] amdgpu only uses shared-fences internally, but dmabuf importers rely on implicit write hazard tracking via the reservation_object.fence_excl. For example, the importer use the write hazard for timing a page flip to only occur after the exporter has finished flushing its write into the surface. As such, on exporting a dmabuf, we must either flush all outstanding fences (for we do not know which are writes and should have been exclusive) or alternatively create a new exclusive fence that is the composite of all the existing shared fences, and so will only be signaled when all earlier fences are signaled (ensuring that we can not be signaled before the completion of any earlier write). v2: reservation_object is already locked by amdgpu_bo_reserve() v3: Replace looping with get_fences_rcu and special case the promotion of a single shared fence directly to an exclusive fence, bypassing the fence array. v4: Drop the fence array ref after assigning to reservation_object Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107341 Testcase: igt/amd_prime/amd-to-i915 References: 8e94a46c1770 ("drm/amdgpu: Attach exclusive fence to prime exported bo's. (v5)") Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: "Christian König" <christian.koenig@amd.com> Reviewed-by: "Christian König" <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org> --- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 59 ++++++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c index 1c5d97f4b4dde..8dcf6227ab990 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c @@ -37,6 +37,7 @@ #include "amdgpu_display.h" #include <drm/amdgpu_drm.h> #include <linux/dma-buf.h> +#include <linux/dma-fence-array.h> static const struct dma_buf_ops amdgpu_dmabuf_ops; @@ -188,6 +189,48 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev, return ERR_PTR(ret); } +static int +__reservation_object_make_exclusive(struct reservation_object *obj) +{ + struct dma_fence **fences; + unsigned int count; + int r; + + if (!reservation_object_get_list(obj)) /* no shared fences to convert */ + return 0; + + r = reservation_object_get_fences_rcu(obj, NULL, &count, &fences); + if (r) + return r; + + if (count == 0) { + /* Now that was unexpected. */ + } else if (count == 1) { + reservation_object_add_excl_fence(obj, fences[0]); + dma_fence_put(fences[0]); + kfree(fences); + } else { + struct dma_fence_array *array; + + array = dma_fence_array_create(count, fences, + dma_fence_context_alloc(1), 0, + false); + if (!array) + goto err_fences_put; + + reservation_object_add_excl_fence(obj, &array->base); + dma_fence_put(&array->base); + } + + return 0; + +err_fences_put: + while (count--) + dma_fence_put(fences[count]); + kfree(fences); + return -ENOMEM; +} + /** * amdgpu_gem_map_attach - &dma_buf_ops.attach implementation * @dma_buf: shared DMA buffer @@ -219,16 +262,16 @@ static int amdgpu_gem_map_attach(struct dma_buf *dma_buf, if (attach->dev->driver != adev->dev->driver) { /* - * Wait for all shared fences to complete before we switch to future - * use of exclusive fence on this prime shared bo. + * We only create shared fences for internal use, but importers + * of the dmabuf rely on exclusive fences for implicitly + * tracking write hazards. As any of the current fences may + * correspond to a write, we need to convert all existing + * fences on the reservation object into a single exclusive + * fence. */ - r = reservation_object_wait_timeout_rcu(bo->tbo.resv, - true, false, - MAX_SCHEDULE_TIMEOUT); - if (unlikely(r < 0)) { - DRM_DEBUG_PRIME("Fence wait failed: %li\n", r); + r = __reservation_object_make_exclusive(bo->tbo.resv); + if (r) goto error_unreserve; - } } /* pin buffer into GTT */ -- 2.19.1
WARNING: multiple messages have this Message-ID (diff)
From: Sasha Levin <sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Cc: "Sasha Levin" <sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, "Chris Wilson" <chris-Y6uKTt2uX1cEflXRtASbqLVCufUGDwFn@public.gmane.org>, amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, "Alex Deucher" <alexander.deucher-5C7GfCeVMHo@public.gmane.org>, "Christian König" <christian.koenig-5C7GfCeVMHo@public.gmane.org> Subject: [PATCH AUTOSEL 4.19 28/64] drm/amdgpu: Transfer fences to dmabuf importer Date: Thu, 28 Feb 2019 10:10:29 -0500 [thread overview] Message-ID: <20190228151105.11277-28-sashal@kernel.org> (raw) In-Reply-To: <20190228151105.11277-1-sashal-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> From: Chris Wilson <chris@chris-wilson.co.uk> [ Upstream commit 6e11ea9de9576a644045ffdc2067c09bc2012eda ] amdgpu only uses shared-fences internally, but dmabuf importers rely on implicit write hazard tracking via the reservation_object.fence_excl. For example, the importer use the write hazard for timing a page flip to only occur after the exporter has finished flushing its write into the surface. As such, on exporting a dmabuf, we must either flush all outstanding fences (for we do not know which are writes and should have been exclusive) or alternatively create a new exclusive fence that is the composite of all the existing shared fences, and so will only be signaled when all earlier fences are signaled (ensuring that we can not be signaled before the completion of any earlier write). v2: reservation_object is already locked by amdgpu_bo_reserve() v3: Replace looping with get_fences_rcu and special case the promotion of a single shared fence directly to an exclusive fence, bypassing the fence array. v4: Drop the fence array ref after assigning to reservation_object Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=107341 Testcase: igt/amd_prime/amd-to-i915 References: 8e94a46c1770 ("drm/amdgpu: Attach exclusive fence to prime exported bo's. (v5)") Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Alex Deucher <alexander.deucher@amd.com> Cc: "Christian König" <christian.koenig@amd.com> Reviewed-by: "Christian König" <christian.koenig@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org> --- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 59 ++++++++++++++++++++--- 1 file changed, 51 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c index 1c5d97f4b4dde..8dcf6227ab990 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c @@ -37,6 +37,7 @@ #include "amdgpu_display.h" #include <drm/amdgpu_drm.h> #include <linux/dma-buf.h> +#include <linux/dma-fence-array.h> static const struct dma_buf_ops amdgpu_dmabuf_ops; @@ -188,6 +189,48 @@ amdgpu_gem_prime_import_sg_table(struct drm_device *dev, return ERR_PTR(ret); } +static int +__reservation_object_make_exclusive(struct reservation_object *obj) +{ + struct dma_fence **fences; + unsigned int count; + int r; + + if (!reservation_object_get_list(obj)) /* no shared fences to convert */ + return 0; + + r = reservation_object_get_fences_rcu(obj, NULL, &count, &fences); + if (r) + return r; + + if (count == 0) { + /* Now that was unexpected. */ + } else if (count == 1) { + reservation_object_add_excl_fence(obj, fences[0]); + dma_fence_put(fences[0]); + kfree(fences); + } else { + struct dma_fence_array *array; + + array = dma_fence_array_create(count, fences, + dma_fence_context_alloc(1), 0, + false); + if (!array) + goto err_fences_put; + + reservation_object_add_excl_fence(obj, &array->base); + dma_fence_put(&array->base); + } + + return 0; + +err_fences_put: + while (count--) + dma_fence_put(fences[count]); + kfree(fences); + return -ENOMEM; +} + /** * amdgpu_gem_map_attach - &dma_buf_ops.attach implementation * @dma_buf: shared DMA buffer @@ -219,16 +262,16 @@ static int amdgpu_gem_map_attach(struct dma_buf *dma_buf, if (attach->dev->driver != adev->dev->driver) { /* - * Wait for all shared fences to complete before we switch to future - * use of exclusive fence on this prime shared bo. + * We only create shared fences for internal use, but importers + * of the dmabuf rely on exclusive fences for implicitly + * tracking write hazards. As any of the current fences may + * correspond to a write, we need to convert all existing + * fences on the reservation object into a single exclusive + * fence. */ - r = reservation_object_wait_timeout_rcu(bo->tbo.resv, - true, false, - MAX_SCHEDULE_TIMEOUT); - if (unlikely(r < 0)) { - DRM_DEBUG_PRIME("Fence wait failed: %li\n", r); + r = __reservation_object_make_exclusive(bo->tbo.resv); + if (r) goto error_unreserve; - } } /* pin buffer into GTT */ -- 2.19.1 _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx
next prev parent reply other threads:[~2019-02-28 15:12 UTC|newest] Thread overview: 89+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-02-28 15:10 [PATCH AUTOSEL 4.19 01/64] ARM: OMAP: dts: N950/N9: fix onenand timings Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 02/64] ARM: dts: omap4-droid4: Fix typo in cpcap IRQ flags Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 03/64] ARM: dts: sun8i: h3: Add ethernet0 alias to Beelink X2 Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 04/64] arm: dts: meson: Fix IRQ trigger type for macirq Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 05/64] ARM: dts: meson8b: odroidc1: mark the SD card detection GPIO active-low Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 06/64] ARM: dts: meson8m2: mxiii-plus: " Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 07/64] ARM: dts: imx6sx: correct backward compatible of gpt Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 08/64] arm64: dts: renesas: r8a7796: Enable DMA for SCIF2 Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 09/64] arm64: dts: renesas: r8a77965: " Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 10/64] soc: fsl: qbman: avoid race in clearing QMan interrupt Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 11/64] pinctrl: mcp23s08: spi: Fix regmap allocation for mcp23s18 Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 12/64] wlcore: sdio: Fixup power on/off sequence Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 13/64] bpftool: Fix prog dump by tag Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 14/64] bpftool: fix percpu maps updating Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 15/64] bpf: sock recvbuff must be limited by rmem_max in bpf_setsockopt() Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 16/64] ARM: pxa: ssp: unneeded to free devm_ allocated data Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 17/64] arm64: dts: add msm8996 compatible to gicv3 Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 18/64] batman-adv: release station info tidstats Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 19/64] DTS: CI20: Fix bugs in ci20's device tree Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 20/64] usb: phy: fix link errors Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 21/64] irqchip/gic-v4: Fix occasional VLPI drop Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 22/64] irqchip/gic-v3-its: Gracefully fail on LPI exhaustion Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 23/64] irqchip/mmp: Only touch the PJ4 IRQ & FIQ bits on enable/disable Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 24/64] drm/amdgpu: Add missing power attribute to APU check Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 25/64] drm/radeon: check if device is root before getting pci speed caps Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 26/64] debugfs: return error values, not NULL Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 27/64] debugfs: debugfs_lookup() should return NULL if not found Sasha Levin 2019-02-28 15:10 ` Sasha Levin [this message] 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 28/64] drm/amdgpu: Transfer fences to dmabuf importer Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 29/64] net: stmmac: Fallback to Platform Data clock in Watchdog conversion Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 30/64] net: stmmac: Send TSO packets always from Queue 0 Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 31/64] net: stmmac: Disable EEE mode earlier in XMIT callback Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 32/64] irqchip/gic-v3-its: Fix ITT_entry_size accessor Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 33/64] relay: check return of create_buf_file() properly Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 34/64] blk-mq: protect debugfs_create_files() from failures Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 35/64] bpf, selftests: fix handling of sparse CPU allocations Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` sashal 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 36/64] bpf: fix lockdep false positive in percpu_freelist Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 37/64] bpf: fix potential deadlock in bpf_prog_register Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 38/64] bpf: Fix syscall's stackmap lookup potential deadlock Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 39/64] drm/sun4i: tcon: Prepare and enable TCON channel 0 clock at init Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 40/64] dmaengine: at_xdmac: Fix wrongfull report of a channel as in use Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 41/64] vsock/virtio: fix kernel panic after device hot-unplug Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 42/64] vsock/virtio: reset connected sockets on device removal Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 43/64] dmaengine: dmatest: Abort test in case of mapping error Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 44/64] selftests: netfilter: fix config fragment CONFIG_NF_TABLES_INET Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` sashal 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 45/64] selftests: netfilter: add simple masq/redirect test cases Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` sashal 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 46/64] netfilter: nf_nat: skip nat clash resolution for same-origin entries Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 47/64] arm64: ptdump: Don't iterate kernel page tables using PTRS_PER_PXX Sasha Levin 2019-02-28 15:18 ` Will Deacon 2019-03-11 17:16 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 48/64] s390/qeth: release cmd buffer in error paths Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 49/64] s390/qeth: fix use-after-free in error path Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 50/64] s390/qeth: cancel close_dev work before removing a card Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 51/64] perf symbols: Filter out hidden symbols from labels Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 52/64] perf trace: Support multiple "vfs_getname" probes Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 53/64] MIPS: Loongson: Introduce and use loongson_llsc_mb() Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 54/64] MIPS: Remove function size check in get_frame_info() Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 55/64] Revert "scsi: libfc: Add WARN_ON() when deleting rports" Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 56/64] i2c: omap: Use noirq system sleep pm ops to idle device for suspend Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 57/64] drm/amdgpu: use spin_lock_irqsave to protect vm_manager.pasid_idr Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:10 ` [PATCH AUTOSEL 4.19 58/64] nvme: lock NS list changes while handling command effects Sasha Levin 2019-02-28 15:10 ` Sasha Levin 2019-02-28 15:11 ` [PATCH AUTOSEL 4.19 59/64] nvme-pci: fix rapid add remove sequence Sasha Levin 2019-02-28 15:11 ` Sasha Levin 2019-02-28 15:16 ` Keith Busch 2019-02-28 15:16 ` Keith Busch 2019-03-11 17:21 ` Sasha Levin 2019-03-11 17:21 ` Sasha Levin 2019-02-28 15:11 ` [PATCH AUTOSEL 4.19 60/64] fs: ratelimit __find_get_block_slow() failure message Sasha Levin 2019-02-28 15:11 ` [PATCH AUTOSEL 4.19 61/64] qed: Fix EQ full firmware assert Sasha Levin 2019-02-28 15:11 ` [PATCH AUTOSEL 4.19 62/64] qed: Consider TX tcs while deriving the max num_queues for PF Sasha Levin 2019-02-28 15:11 ` [PATCH AUTOSEL 4.19 63/64] qede: Fix system crash on configuring channels Sasha Levin 2019-02-28 15:11 ` [PATCH AUTOSEL 4.19 64/64] blk-iolatency: fix IO hang due to negative inflight counter Sasha Levin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190228151105.11277-28-sashal@kernel.org \ --to=sashal@kernel.org \ --cc=alexander.deucher@amd.com \ --cc=amd-gfx@lists.freedesktop.org \ --cc=chris@chris-wilson.co.uk \ --cc=christian.koenig@amd.com \ --cc=dri-devel@lists.freedesktop.org \ --cc=linux-kernel@vger.kernel.org \ --cc=stable@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.