From patchwork Wed Feb 15 19:10:56 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: 9574833 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 0C18B60493 for ; Wed, 15 Feb 2017 19:11:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2DBA284CE for ; Wed, 15 Feb 2017 19:11:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E7805284DA; Wed, 15 Feb 2017 19:11:15 +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 952D3284CE for ; Wed, 15 Feb 2017 19:11:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AB4D86E9DA; Wed, 15 Feb 2017 19:11:13 +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 D02AA6E9D9; Wed, 15 Feb 2017 19:11:11 +0000 (UTC) Received: by mail-wm0-x241.google.com with SMTP id u63so9682901wmu.2; Wed, 15 Feb 2017 11:11:11 -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=r4mco7uXWwNEHkiFQMUYLq6Mtz5vV+aKkP086sIJ628=; b=mB5iNA4kQmUC4a4iJiyxRs75bBa8KKKw8jK2Wx9vmAE4YhoQOx+lZpAqMYa+mo70XY X6+jfVTJy3y3ILljVXnFPz9edr8s1WyGlWm2Ehp2pO7U5mnG2yBbRCt2JGFdCrlW1Q7H opkJL3JniFuOIQ7w+dg20MzhV7+aApeLXYib/sLogKmUvzC958Z+DebwMpIM0k5FXEu5 4ptHPlmx2YC2JhInFabMkD1JwtWvyxJz9pN/FVOC9FxFzo2AjvNtmlmY0r+Cg2NiSqAH iMZI2j21Sx3KAa5L/1Z7HgdAbg8XDMpvoj/h8gIke/XmjYzfdjBs2zAuuK493JxkM+dH z1AQ== 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=r4mco7uXWwNEHkiFQMUYLq6Mtz5vV+aKkP086sIJ628=; b=dJKz2oOmhIz4RzGGR5YzhDGK7Hzi0qgpxvucIXWukARKlOWKyZWdrAwnjWQ8TwTRUZ do59P8mEu0yUJR7T8IHZrLvZnpx5NjO/CYqsDoUVdwbhDBYKsUV0zHU7TVY30jYtPpKI Ics9vY0KoN8ApttXISDlQmmA1k734XzGFP5csKnHxPCgPiL1krPqQtCOryNUBtB26Cfx UOkFOBFpMmfbsnVeWfemHWc1s+XajsaErRop7BkZJCLOWtv5fH1RBfGtzQO/C+ptA9wL ABstSG2c/bzWsc8o/BXz4tUq3zmzVnKa6EikdNbXN9grwWm7ff6hgVv+5nu7ojZGYH3g 9pBA== X-Gm-Message-State: AMke39kG0hae2ejywm5mdNynGg5bF26V+myDHKwtW6E5L/VZkTxZMNg4FYwMv4G0A9HkIA== X-Received: by 10.28.189.195 with SMTP id n186mr8819540wmf.77.1487185870256; Wed, 15 Feb 2017 11:11:10 -0800 (PST) Received: from capella.localdomain (x55b54b64.dyn.telefonica.de. [85.181.75.100]) by smtp.gmail.com with ESMTPSA id w204sm440510wmd.17.2017.02.15.11.11.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Feb 2017 11:11:09 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: amd-gfx@lists.freedesktop.org Subject: [PATCH v2 3/3] drm/amdgpu: fix lock cleanup during buffer creation Date: Wed, 15 Feb 2017 20:10:56 +0100 Message-Id: <20170215191056.17718-3-nhaehnle@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170215191056.17718-1-nhaehnle@gmail.com> References: <20170215191056.17718-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 Open-code the initial ttm_bo_validate call, so that we can properly unlock the reservation lock when it fails. Also, properly destruct the reservation object when the first part of 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. v2: use ttm_bo_unref for error handling, and rebase on latest changes Fixes: 12a852219583 ("drm/amdgpu: improve AMDGPU_GEM_CREATE_VRAM_CLEARED handling (v2)") Signed-off-by: Nicolai Hähnle --- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index c2e57f7..15944ea 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -404,15 +404,31 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, } 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_top(&adev->mman.bdev, &bo->tbo, size, type, + page_align, NULL, + acc_size, sg, resv ? resv : &bo->tbo.ttm_resv, + &amdgpu_ttm_bo_destroy); + + if (likely(r == 0)) + r = ttm_bo_validate(&bo->tbo, &bo->placement, !kernel, false); + + if (unlikely(r != 0)) { + struct ttm_buffer_object *tbo = &bo->tbo; + + if (!resv) + ww_mutex_unlock(&bo->tbo.ttm_resv.lock); + ttm_bo_unref(&tbo); + return r; + } + amdgpu_cs_report_moved_bytes(adev, atomic64_read(&adev->num_bytes_moved) - initial_bytes_moved); - if (unlikely(r != 0)) - return r; + if (!(bo->tbo.mem.placement & TTM_PL_FLAG_NO_EVICT)) { + spin_lock(&bo->tbo.glob->lru_lock); + ttm_bo_add_to_lru(&bo->tbo); + spin_unlock(&bo->tbo.glob->lru_lock); + } bo->tbo.priority = ilog2(bo->tbo.num_pages); if (kernel)