From patchwork Tue Feb 14 10:37:44 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: 9571677 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 93EAC60586 for ; Tue, 14 Feb 2017 10:38:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F9BA27D45 for ; Tue, 14 Feb 2017 10:38:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9460628391; Tue, 14 Feb 2017 10:38:08 +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 99B6827D45 for ; Tue, 14 Feb 2017 10:38:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CBC186E669; Tue, 14 Feb 2017 10:38:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x244.google.com (mail-wm0-x244.google.com [IPv6:2a00:1450:400c:c09::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 156E46E658; Tue, 14 Feb 2017 10:38:02 +0000 (UTC) Received: by mail-wm0-x244.google.com with SMTP id v77so2849281wmv.0; Tue, 14 Feb 2017 02:38:02 -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=QVPBdGwqCblYYcUZE8LcnFKV3C6VgcLN4UeOObrZ87E=; b=lSAUL1JN6i0LJUjAhv9891X4F/FvAwx994N2Ni86KlVhPLZGvoDek/AmQJesoHwuZb Qw2s071ZecqynqHBIT3NQ4J+nOf7k2GxFPkZYjDTSVSbi39uhKLKdeiybI2A53w5BvKs vCgkVBLuGrC7xqOaPwtJJIwWWYBRm3V1tDHtcCoVeillOp/z3K71Tpc3Aff4ZhilxEr/ qsFJiwHMXMa9jYIjlycAVvY1LG/Vngjjxp+iTxid+FoJhNc7+JEPCEC37X+fdjHFknhX AkD8KfC/Hp0eIzDZAmZpyqqVwjefgWKT5xReeQzqv38P+94ByrfoqZR2nk6EYYQGKkKw ta5A== 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=QVPBdGwqCblYYcUZE8LcnFKV3C6VgcLN4UeOObrZ87E=; b=Ni4grS+XSIbtBwL0DoOLTTcQBr+pMO0lweNev2c35W09svzd6kxAiOmuIPb2kRUALB UQRhXoPtv+PQfS/ClaQK/0wbPLMTcHbWTMxxzDpMMZpNp5wsvZ1qSOwuxA2KMX9HnvGo 6Qf4rshbvl9IqO4WP1AF3d6/knc6Bh+iDJWdWLTdN2UENK/ioqE75cBxQMwK17HE9+i5 ERXmm9gkExUrJocq1eEHGq+/Q2fYLkxnTW6bRJhY5kCUerutJizf9mUKmswaL5zneBFb JkawhmO9WI5aNjvyOspQJQJjq2+/pLhoBVvW6bLG+U57GX8eLoHbBRDSPiCnTEmNhF2j 99Qw== X-Gm-Message-State: AMke39lmz916xJkcZWtlO+WvGqNza85N7ThX2QDv/d3AaRFI6aP/0NvbSD1L6J+ulkD86Q== X-Received: by 10.28.136.68 with SMTP id k65mr2652482wmd.48.1487068680641; Tue, 14 Feb 2017 02:38:00 -0800 (PST) Received: from capella.localdomain (x5ce2e06e.dyn.telefonica.de. [92.226.224.110]) by smtp.gmail.com with ESMTPSA id a13sm2929241wma.13.2017.02.14.02.37.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Feb 2017 02:38:00 -0800 (PST) From: =?UTF-8?q?Nicolai=20H=C3=A4hnle?= To: amd-gfx@lists.freedesktop.org Subject: [PATCH 3/3] drm/amdgpu: fix lock cleanup during buffer creation Date: Tue, 14 Feb 2017 11:37:44 +0100 Message-Id: <20170214103744.4133-3-nhaehnle@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170214103744.4133-1-nhaehnle@gmail.com> References: <20170214103744.4133-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. 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 | 32 +++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c index d1ef1d0..bea845f 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c @@ -399,12 +399,34 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev, locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock); WARN_ON(!locked); } - 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); - if (unlikely(r != 0)) + 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 (unlikely(r != 0)) { + if (!resv) { + ww_mutex_unlock(&bo->tbo.ttm_resv.lock); + reservation_object_fini(&bo->tbo.ttm_resv); + } + amdgpu_ttm_bo_destroy(&bo->tbo); + return r; + } + + 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; + } + + 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)