From patchwork Sat Nov 5 00:56:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mario Kleiner X-Patchwork-Id: 9413551 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 3D7D26022E for ; Sat, 5 Nov 2016 00:57:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 226262B1B5 for ; Sat, 5 Nov 2016 00:57:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 069B02B2D9; Sat, 5 Nov 2016 00:57:11 +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 2716E2B1B5 for ; Sat, 5 Nov 2016 00:57:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 657D06E0A9; Sat, 5 Nov 2016 00:57:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x241.google.com (mail-wm0-x241.google.com [IPv6:2a00:1450:400c:c09::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id E6FBA6E0A9; Sat, 5 Nov 2016 00:57:05 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id p190so6273626wmp.1; Fri, 04 Nov 2016 17:57:05 -0700 (PDT) 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=xpBmwbMdesU3P42JH2puZfbUo84GQeIftYZSziCpq7k=; b=bEMuzb9UkaYpC6Yc/N0Ksyfwo0Pv0b4FVnX6bHCxgJ/cmxpiPQ30+sOMD0K/gGV9Ba SH1nEFGRH+7nW0aigjq7fZUfEGty7Jzr8N0s3QRoNEjM58q5N7Vq16t3nu59yPaFXGBv AEpRCI9Jt+5q4ZxQJPt060FOrAgld+da+EmsDu4WDE0CDALVTR34mzgnuLDXKAklOgHt ckjkcreR2RZi4g60mXRUyaKTVKKNEPT214I3zlReVX82yneg5aCFhaDe3vfoWV5QM0OY Ms+bdvtaSG5HrOou4uOOEK0eSMgGpnoDTQnNgAsl1MK1Mm9lzoUfaWPZoHa9a/RJs9Kt HKKQ== 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=xpBmwbMdesU3P42JH2puZfbUo84GQeIftYZSziCpq7k=; b=m25pU5QoOukuerZCMs60g5UWd0A3hUMbnE2ujPjFMKKlFMHrcbumxcSH+fC152pyNt qLudXGY0AjcDOH4pHJ9oRa4oebcY7QRdhJjZugR1ojbpo84fYLBp0x2eM5fPQ6kIhwmU 2TNfTdf7OtAAkrX+XHawKxjWEhG2eqHzfaASOhRKfFXc9qqHljC0DMz2fmaiTw+DRy2Q FziajCt9BiJR5ov5oT0YJZmYFDu25+bFxUorg3dKaHGCvHPsFQAduLhdZSDXci66XFka 3KeKMuUdr1nqa5Ku8TSJDlgGwcMl5JwfzPhyxFuCFlASsYgZZUFb3IJa1RPRK8dzUkNB irUw== X-Gm-Message-State: ABUngvchdkYookxjHVxu05vUMSQk02mnyf4u8w2eBv/sqwGbO8aukptTM4Iyh2ce8wDSJA== X-Received: by 10.28.234.201 with SMTP id g70mr782373wmi.104.1478307424542; Fri, 04 Nov 2016 17:57:04 -0700 (PDT) Received: from twisty.fritz.box (x5f71adae.dyn.telefonica.de. [95.113.173.174]) by smtp.gmail.com with ESMTPSA id w65sm7184052wmd.23.2016.11.04.17.57.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Nov 2016 17:57:03 -0700 (PDT) From: Mario Kleiner To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm/amdgpu: Attach exclusive fence to prime exported bo's. (v2) Date: Sat, 5 Nov 2016 01:56:19 +0100 Message-Id: <1478307379-17697-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 such exported buffers as exclusive ones. 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. 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 | 11 +++++++++++ 3 files changed, 13 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..0ed92a1 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_prime.c @@ -117,9 +117,20 @@ struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev, int flags) { struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj); + long ret; if (amdgpu_ttm_tt_get_usermm(bo->tbo.ttm)) return ERR_PTR(-EPERM); + /* + * Wait for all shared fences to complete before we switch to future + * use of exclusive fence on this prime_exported bo. + */ + ret = reservation_object_wait_timeout_rcu(bo->tbo.resv, true, false, + MAX_SCHEDULE_TIMEOUT); + WARN(ret <= 0, "Fence wait returns %li\n", ret); + + bo->prime_exported = true; + return drm_gem_prime_export(dev, gobj, flags); }