Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2298610imc; Tue, 12 Mar 2019 10:52:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1VggGc7qrcO3R/8MKkwscxhzEw1GOIbgJT5JHR/ovnrw/4v0nA6iW5mtenDS1KOlkpj/r X-Received: by 2002:a65:6383:: with SMTP id h3mr35639854pgv.11.1552413172659; Tue, 12 Mar 2019 10:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552413172; cv=none; d=google.com; s=arc-20160816; b=K49p8JekHq3nckuEp3TsoYFmi9IZOCJWkphGgdHXxI6ZbNbAL+qwdvPeXRyuNjDLj8 AxR+bOrCQy0QMOvl7H5demKCE0AiawkjakzdYkqAVBK0Q/OyvR9XzMyaRNd1Ow/B9PKA iLz74AmIQAVB3jAHCkKp9wwIuessAtfDKhhMY/7hGhpTEzzAF4bc3VgVMrREYHxAd2/u vI0BneS61WvwjXSZVGtLkPSNcg4Xru9qHOw0t98x64WaKxeaAbBVghU3qSwcikEY0/zG nHYJiR6tlqEh9jfZPwdW7zopp1S4wwlQhH/r6HvhE3P33CiZ60/kdB+hG6PQAW3yHu1N UmaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=rXaPtUIg/IqWt+Mr+Rticcf8U+F3NlaY9QhY7ySxPpI=; b=otOiXqAB3/KmVe/X0Fr39CdACPRXqJ8GSu/lH/xHTExk2tqY7men2TVjLvr65H+1cX C/Yi7X5lm7V6tI9RGDy50NuP4+VN11h+euGNhzDHJjRDNDs2NqaqiFgm2MNdYSBca2yP fD6uBgLsHSG57CG5+2F/cV7CGVuK1AQkPbKJkNts/IgSh7RPJdZ3f0OYUUhqNVCiNJHm QU974IrORJOXM+T1/OXsojY04Z5yn7K9mOr2X9i2g3TlydEbqClIlS0iHbHg2UH7rhDl HBq5mexxR2bbB56jMzV0AZK+yq/FmjNsQLBjdDWh1nMVBvLOsecCBH8hj6BIpt81VF7P Uhfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RePUYxhl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h8si8341480pls.365.2019.03.12.10.52.37; Tue, 12 Mar 2019 10:52:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RePUYxhl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729309AbfCLRu2 (ORCPT + 99 others); Tue, 12 Mar 2019 13:50:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:53840 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726451AbfCLROm (ORCPT ); Tue, 12 Mar 2019 13:14:42 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49AB5217D8; Tue, 12 Mar 2019 17:14:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552410881; bh=NLN703Z0n0WAgeZckF7FvZUgmfSgkv6STHR3WWHTWlM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RePUYxhlGtBepv397lOWSCY3fFqyLzIgOhhruVp07M1CrS5oBHzNo33L3SVvgMqd3 aMhW+c0NrrQvkwbEdFr63Taf1ML01oTCyDj6f9rD5/F4KL+iI5mJU5s9VYEjBrie78 IE0HmoerYjeBS+gy9zeyVZde6IY+OYZvBwaBkKPw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chris Wilson , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin Subject: [PATCH 4.19 087/149] drm/amdgpu: Transfer fences to dmabuf importer Date: Tue, 12 Mar 2019 10:08:25 -0700 Message-Id: <20190312170357.026389196@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170349.421581206@linuxfoundation.org> References: <20190312170349.421581206@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ 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 Cc: Alex Deucher Cc: "Christian König" Reviewed-by: "Christian König" Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- 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 1c5d97f4b4dd..8dcf6227ab99 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 #include +#include 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