From patchwork Thu Feb 16 11:39:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Nicolai_H=C3=A4hnle?= X-Patchwork-Id: 9576893 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 80F5F600C5 for ; Thu, 16 Feb 2017 11:40:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75C85201F3 for ; Thu, 16 Feb 2017 11:40:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A87B285BE; Thu, 16 Feb 2017 11:40:05 +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 29FD5201F3 for ; Thu, 16 Feb 2017 11:40:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C0D9C6EAC3; Thu, 16 Feb 2017 11:40:03 +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 2E6676EAC1; Thu, 16 Feb 2017 11:40:01 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id c85so2691417wmi.1; Thu, 16 Feb 2017 03:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=91mjuhULJKM6nGklAglwEVY9eARQowE48grLk7Rlvhg=; b=RkGu9q+X8qlv0oHbUxnlpXgUrZnZsweru/AyHgufdEZpu/TmuPD9gWEngJNjWva7SB LYwDbQ39aPGsceR4K7yTgbYY6k2O+mXRn9pdSkAfZE1lgsjptjS1wH0ZY1e8IuaodeOK ToKU1F+9mhl+cpNFdZUc5e+wV1UtWEUje4LmDAS44Gt0ENnfqO4iZAeowZcFMsLD15wu 9cnnzE669TM1cfNojLz2f0z2TgMrSPg03mOhIymOV8sxq+P5Er1r4zcebQJStFV690EX lunqN9cbQCzR43WwJgnOsh9ztcdCu4BC7atLP98FE+0VCAvQP/OudBL7SLLQes8iMAMw 1SZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=91mjuhULJKM6nGklAglwEVY9eARQowE48grLk7Rlvhg=; b=GbBVxmvgbD3o0LQJB76zwUqic11gPi7/6A+7NvVFwVhqFymsgusnstCLChWtQZen26 z9YPEyZjSWvfvwpzdxqyNGYc794EwbiGnvJtW5FH6c2GJUYLuzNGwiDjLK+szziNeYZl /5xBQfHO3Ri0MXxyPEYSJrFnkLNsafcrlovcOv7t0rJNwa3Lsffb3R3juoMepYEZfFR+ jOW+ENaKy9Xz+HNy0e/m0ps1bJYzgNuhIHav3PQL3pTsVjnbBpREhExuf21h9LJ+mnPn aRWxGSJYPfpM/wuaBi4ebG7UKlrFBgLgX32pi+B+O3zTY46V4MlFf69K1fouGvS0PrJY +0Zw== X-Gm-Message-State: AMke39njstgeyzcWyyGsocMmD7y/chGff2PBXUd46L6qRy3KFoqg9FcNRBriVHaJ0dFM9w== X-Received: by 10.28.69.17 with SMTP id s17mr2113606wma.60.1487245199880; Thu, 16 Feb 2017 03:39:59 -0800 (PST) Received: from capella.localdomain (x55b544e3.dyn.telefonica.de. [85.181.68.227]) by smtp.gmail.com with ESMTPSA id c202sm3167038wmd.10.2017.02.16.03.39.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Feb 2017 03:39:59 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: amd-gfx@lists.freedesktop.org Subject: [PATCH v3 3/3] drm/amdgpu: simplify reservation handling during buffer creation Date: Thu, 16 Feb 2017 12:39:46 +0100 Message-Id: <20170216113946.22046-3-nhaehnle@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170216113946.22046-1-nhaehnle@gmail.com> References: <20170216113946.22046-1-nhaehnle@gmail.com> MIME-Version: 1.0 Cc: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= , dri-devel@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 From: Nicolai Hähnle By using ttm_bo_init_reserved instead of the manual initialization of the reservation object, the reservation lock will be properly unlocked and destroyed when the TTM BO initialization fails. Actual deadlocks caused by the missing unlock should have been fixed by "drm/ttm: never add BO that failed to validate to the LRU list", superseding the flawed fix in commit 38fc4856ad98 ("drm/amdgpu: fix a potential deadlock in amdgpu_bo_create_restricted()"). This change fixes remaining recursive locking errors that can be seen with lock debugging enabled, and avoids the error of freeing a locked mutex. As an additional minor bonus, buffers created with resv == NULL and the AMDGPU_GEM_CREATE_VRAM_CLEARED flag are now only added to the global LRU list after the fill commands have been issued. Fixes: 12a852219583 ("drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling (v2)") Signed-off-by: Nicolai Hähnle Reviewed-by: Chunming Zhou as well --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index c2e57f7..4d0536d 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -395,19 +395,10 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, amdgpu_fill_placement_to_bo(bo, placement); /* Kernel allocation are uninterruptible */ - if (!resv) { - bool locked; - - reservation_object_init(&bo->tbo.ttm_resv); - locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock); - WARN_ON(!locked); - } - initial_bytes_moved = atomic64_read(&adev->num_bytes_moved); - r = ttm_bo_init(&adev->mman.bdev, &bo->tbo, size, type, - &bo->placement, page_align, !kernel, NULL, - acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, - &amdgpu_ttm_bo_destroy); + r = ttm_bo_init_reserved(&adev->mman.bdev, &bo->tbo, size, type, + &bo->placement, page_align, !kernel, NULL, + acc_size, sg, resv, &amdgpu_ttm_bo_destroy); amdgpu_cs_report_moved_bytes(adev, atomic64_read(&adev->num_bytes_moved) - initial_bytes_moved); @@ -433,7 +424,7 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, fence_put(fence); } if (!resv) - ww_mutex_unlock(&bo->tbo.resv->lock); + ttm_bo_unreserve(&bo->tbo); *bo_ptr = bo; trace_amdgpu_bo_create(bo);