From patchwork Mon Nov 7 02:47:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9414249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E353260585 for ; Mon, 7 Nov 2016 02:52:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4B4728542 for ; Mon, 7 Nov 2016 02:52:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C74FE28A4B; Mon, 7 Nov 2016 02:52:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C4D628542 for ; Mon, 7 Nov 2016 02:52:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7B6B56E2B7; Mon, 7 Nov 2016 02:52:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 422846E2B2; Mon, 7 Nov 2016 02:52:38 +0000 (UTC) Received: by mail-wm0-x242.google.com with SMTP id u144so14163314wmu.0; Sun, 06 Nov 2016 18:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rkB/0AO7v4IZghwMCQJW9kOJG6fLNQqt+sOrgNzSSmM=; b=CbFNkD1ER7GbNg81Q+5OSR+ODxkIcIP9jdxZob045fv7lyinOJnqN/3XY+7v3yhnn3 +rzGWKFcXXr03u2HmSuPGQLg+oTWn1PCJ4e5pm+SPRl4i1rGKISu0+iDsvOSlEG1/jR7 nk1FbA90DymjsZ8zqjanJgvuILQSf7v9YzekSbO27dDSY1kKG5RfvpW0o+8fkGkirkJT m5x+j+g/aSnEcPNKagFAYoyDdca+iQk6M85Q6h6sdvdlQwq0wrElTHgMko6/if3W335i k1t+YJbHvJD72JdEE6VWgzJ1un3mlJOfblqrtmNZ5yaNR0121YSE1USj6gEJsiH1AN5f V/+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rkB/0AO7v4IZghwMCQJW9kOJG6fLNQqt+sOrgNzSSmM=; b=miDL6u2RRcw/0iZ1KkFBE8XzmjF6PJfccSR+96RQF+wV89N5bUu3Fe++uwMrFbE7cR Bea8Hd+s19D8LGRBeX1tdl5E7OHzBsaRgF5/o77GbXB/Qps48nopOmHJtmLpqaiwGaX+ 9z1IErlw/VM6mpMu5nKHG8PyFclT/WxgvEhvfVrY37JKL/VbGOe0JI+zCys2KO08q4TX k6nAW+QR/yoVlD1LCe09wskUKVJv8/u9CSSl3XzyTgNaILIr/ItjDN4QjmJaC3sxC7li TbVhRtPfBYEDp4VwDoIU+oRwAxvDVlxGcPB++V7E+Ms5FkViQ1w+FVrqFOTVOlCYTF3I 8vhQ== X-Gm-Message-State: ABUngvffnc9qU3lY2AR2NCa+M1UlOasBQ1MVVbua4HwlUIGYmNp+POabuq21OXyTO8TNOQ== X-Received: by 10.28.199.71 with SMTP id x68mr4172264wmf.34.1478487156688; Sun, 06 Nov 2016 18:52:36 -0800 (PST) Received: from twisty.fritz.box (x4d02ddd1.dyn.telefonica.de. [77.2.221.209]) by smtp.gmail.com with ESMTPSA id p184sm10748747wmg.3.2016.11.06.18.52.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 06 Nov 2016 18:52:35 -0800 (PST) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/amdgpu: Attach exclusive fence to prime exported bo's. (v3) Date: Mon, 7 Nov 2016 03:47:34 +0100 Message-Id: <1478486854-30715-1-git-send-email-mario.kleiner.de@gmail.com> X-Mailer: git-send-email 2.7.0 MIME-Version: 1.0 Cc: =?UTF-8?q?Michel=20D=C3=A4nzer?= , =?UTF-8?q?Christian=20K=C3=B6nig?= , amd-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP External clients which import our bo's wait only for exclusive dmabuf-fences, not on shared ones, so attach fences on exported buffers as exclusive ones, if the buffers get imported by an external client. See discussion in thread: https://lists.freedesktop.org/archives/dri-devel/2016-October/122370.html Tested on Intel iGPU + AMD Tonga dGPU as DRI3/Present Prime render offload, and with the Tonga standalone as primary gpu. v2: Add a wait for all shared fences before prime export, as suggested by Christian Koenig. v3: - Mark buffer prime_exported in amdgpu_gem_prime_pin, so we only use the exclusive fence when exporting a bo to external clients like a separate iGPU, but not when exporting/importing from/to ourselves as part of regular DRI3 fd passing. - Propagate failure of reservation_object_wait_rcu back to caller. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=95472 (v1) Tested-by: Mike Lothian Signed-off-by: Mario Kleiner Cc: Christian König Cc: Michel Dänzer --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 039b57e..a337d56 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -459,6 +459,7 @@ struct amdgpu_bo { u64 metadata_flags; void *metadata; u32 metadata_size; + bool prime_exported; /* list of all virtual address to which this bo * is associated to */ diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c index 651115d..51c6f60 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_bo_list.c @@ -132,7 +132,7 @@ static int amdgpu_bo_list_set(struct amdgpu_device *adev, entry->priority = min(info[i].bo_priority, AMDGPU_BO_LIST_MAX_PRIORITY); entry->tv.bo = &entry->robj->tbo; - entry->tv.shared = true; + entry->tv.shared = !entry->robj->prime_exported; if (entry->robj->prefered_domains == AMDGPU_GEM_DOMAIN_GDS) gds_obj = entry->robj; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c index 7700dc2..c4494d0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c @@ -81,6 +81,20 @@ int amdgpu_gem_prime_pin(struct drm_gem_object *obj) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj); int ret = 0; + long lret; + + /* + * Wait for all shared fences to complete before we switch to future + * use of exclusive fence on this prime_exported bo. + */ + lret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false, + MAX_SCHEDULE_TIMEOUT); + if (unlikely(lret < 0)) { + DRM_DEBUG_PRIME("Fence wait failed: %li\n", lret); + return lret; + } + + bo->prime_exported = true; ret = amdgpu_bo_reserve(bo, false); if (unlikely(ret != 0))