From patchwork Wed Jun 16 06:30:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 12324189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 407C3C48BE5 for ; Wed, 16 Jun 2021 06:30:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3B91610A3 for ; Wed, 16 Jun 2021 06:30:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3B91610A3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 55B8D6E1B5; Wed, 16 Jun 2021 06:30:33 +0000 (UTC) Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3720B6E1B5 for ; Wed, 16 Jun 2021 06:30:32 +0000 (UTC) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15G6GK6x001082; Wed, 16 Jun 2021 06:30:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : in-reply-to; s=corp-2020-01-29; bh=o/BEHhVMiN5l5PBSjswnmAEwrbJUT7EB9erm/zp0qRA=; b=LN7BFO6UYmb+EvNPV7qT0cstbDdrmBFDdsokA8qt6MpZVxU7QFzQA+c+MfJXZr1XzVfr kQZX7SUo3StgF032uxoeqOlGYEpjWcsXHqaj/aEpYon6lGGTpgydlqXeSCg4AksW0T8y PRRL0kfspQQnLPu+W6/BE+Cj6+6PgKkoNNi/LGTYFSXHCewTPxq2+afaimvO8RUhikdX jn7uWVTnsg9seEFApc4OpxczR3M7Iw/YcA2kHlThMhTazFILtRFzE6uMNq0y6G5lG2wf +Zz4M+ywbO7Qt1NPQPQZxHMQvNnFdhbBWCS5Gk8zouoMWYCly9CE+sIqhrJEKK6Rrt0A pg== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by mx0b-00069f02.pphosted.com with ESMTP id 395x06j00k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Jun 2021 06:30:27 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 15G6F1Tv101965; Wed, 16 Jun 2021 06:30:26 GMT Received: from pps.reinject (localhost [127.0.0.1]) by aserp3020.oracle.com with ESMTP id 396wasdrd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Jun 2021 06:30:26 +0000 Received: from aserp3020.oracle.com (aserp3020.oracle.com [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 15G6RnNn160728; Wed, 16 Jun 2021 06:30:25 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserp3020.oracle.com with ESMTP id 396wasdrc8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Jun 2021 06:30:25 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 15G6UKPX022948; Wed, 16 Jun 2021 06:30:20 GMT Received: from mwanda (/41.212.42.34) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 16 Jun 2021 06:30:19 +0000 Date: Wed, 16 Jun 2021 09:30:12 +0300 From: Dan Carpenter To: Christian Koenig , Thomas Hellstr , B6@mwanda, m Subject: [PATCH] drm/ttm: fix error handling in ttm_bo_handle_move_mem() Message-ID: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210610154113.GJ1955@kadam> X-Mailer: git-send-email haha only kidding X-Proofpoint-ORIG-GUID: iEKfwd0av4OdkwdZPfO2LOoQ8kX7B0s6 X-Proofpoint-GUID: iEKfwd0av4OdkwdZPfO2LOoQ8kX7B0s6 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , Huang Rui , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There are three bugs here: 1) We need to call unpopulate() if ttm_tt_populate() succeeds. 2) The "new_man = ttm_manager_type(bdev, bo->mem.mem_type);" assignment was wrong and it was really assigning "new_mem = old_mem;". There is no need for this assignment anyway as we already have the value for "new_mem". 3) The (!new_man->use_tt) condition is reversed. Fixes: ba4e7d973dd0 ("drm: Add the TTM GPU memory manager subsystem.") Signed-off-by: Dan Carpenter --- This is from reading the code and I can't swear that I have understood it correctly. My nouveau driver is currently unusable and this patch has not helped. But hopefully if I fix enough bugs eventually it will start to work. drivers/gpu/drm/ttm/ttm_bo.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index ebcffe794adb..72dde093f754 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -180,12 +180,12 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, */ ret = ttm_tt_create(bo, old_man->use_tt); if (ret) - goto out_err; + return ret; if (mem->mem_type != TTM_PL_SYSTEM) { ret = ttm_tt_populate(bo->bdev, bo->ttm, ctx); if (ret) - goto out_err; + goto err_destroy; } } @@ -193,15 +193,17 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo, if (ret) { if (ret == -EMULTIHOP) return ret; - goto out_err; + goto err_unpopulate; } ctx->bytes_moved += bo->base.size; return 0; -out_err: - new_man = ttm_manager_type(bdev, bo->mem.mem_type); - if (!new_man->use_tt) +err_unpopulate: + if (new_man->use_tt) + ttm_tt_unpopulate(bo->bdev, bo->ttm); +err_destroy: + if (new_man->use_tt) ttm_bo_tt_destroy(bo); return ret;