Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1082981ybt; Wed, 1 Jul 2020 18:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOBdq+1nfmmVnZHPQPDA0TTzQUXbR7nAvdW9VmvRdLyzW1GrLQ+i3oCrMFes+J8RX692ce X-Received: by 2002:a17:906:2304:: with SMTP id l4mr24867934eja.104.1593653159720; Wed, 01 Jul 2020 18:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593653159; cv=none; d=google.com; s=arc-20160816; b=Mp59OjQyar0TB1OrqsljTDAZUt4eZJ4kbaI4VieoEV4sFdg4wqaOcxooQH9yyKO0WW xKYQcJfpi2lgiLTbCKUqpQZoewFshzIRmWV/OMfPLIuMd5VfWG0mDrwKfaLCFmcp63Z1 EEYWu3hKMbgB8RcGQwkcQwcyYX64ZSQEzMUOzS11RZ/+NhTcDTN2P/IeiTLYuZSIECUL FccXbuY3b4qEQ2tnA9NyaQ9GWh8H/Tr/CsikKcNAayl0PZtLyReYZGbXdV4Lq8U6g6bF vBiPLKAd+5GPCLt5kvcrMN8SMBp/dpqT3I7Yidl6j78s/49J9orjK0cHvElyHROCHrvs 6lLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=SNlwVA5Gq8PrTG97OIxVAnvmqRcKD3lTEKFPyMx0Uyk=; b=kJNAMA7pji1Nh4+qsO7arpF6xSSaPqfUUGFMI+Nwb3XH4tFEM2MC9Y/4Z0apZziMXm 6kQjAg1zDUqgoRpMHYnqg83HZA22hVmR5aLCZAXk47+3zZwjSMJK9g3svmr4P+Vy+DoI yqqD/wDz53My6SVlPGwQUcdTQj3Z6SUJamTzPDvmAukBc3DkJptMe9JlYzP8cpuuHu7k 9C1jGw24HxECKFhjQzNbD/1qH1oKTngcZXmA1IUxoo/Aa7ekCq3RUmlwHm80V5Aj8k1B wj/fZkfuVGKQdBKm7aclEVqT6QQEzAmORT1xHp68QmlzcVCufuIrj8NnPt7yCDYZtDxR PV3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KMBLrFTT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 12si5827575edv.523.2020.07.01.18.25.37; Wed, 01 Jul 2020 18:25:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KMBLrFTT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728231AbgGBBXL (ORCPT + 99 others); Wed, 1 Jul 2020 21:23:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:53376 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728175AbgGBBXE (ORCPT ); Wed, 1 Jul 2020 21:23:04 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E6F5920748; Thu, 2 Jul 2020 01:23:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593652983; bh=/5tEx96xy1e4vi6a8sCn19YEYK/t5MtKMJLjxv8RtbY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KMBLrFTTWgmGJbCRnVFdgqAuWGcGnW+rafceudbV1+Sy9KoJjWC83fN9SQ5H2Kkwt BS4VPWly8zyKoIMhkCVOSnehRJ121wxMjhpbCl82P9E8PRCkVFKe45aQApftDPLBuu s4FGxCeKnU/1dNrjPcCi/jRMZmG/+Lc/qsQ5U/xU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiyu Yang , Xin Tan , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin , dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: [PATCH AUTOSEL 5.7 07/53] drm/ttm: Fix dma_fence refcnt leak when adding move fence Date: Wed, 1 Jul 2020 21:21:16 -0400 Message-Id: <20200702012202.2700645-7-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200702012202.2700645-1-sashal@kernel.org> References: <20200702012202.2700645-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xiyu Yang [ Upstream commit 11425c4519e2c974a100fc984867046d905b9380 ] ttm_bo_add_move_fence() invokes dma_fence_get(), which returns a reference of the specified dma_fence object to "fence" with increased refcnt. When ttm_bo_add_move_fence() returns, local variable "fence" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in one exception handling path of ttm_bo_add_move_fence(). When no_wait_gpu flag is equals to true, the function forgets to decrease the refcnt increased by dma_fence_get(), causing a refcnt leak. Fix this issue by calling dma_fence_put() when no_wait_gpu flag is equals to true. Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/370221/ Signed-off-by: Christian König Signed-off-by: Sasha Levin --- drivers/gpu/drm/ttm/ttm_bo.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 9e07c3f75156b..ef5bc00c73e23 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -881,8 +881,10 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo, if (!fence) return 0; - if (no_wait_gpu) + if (no_wait_gpu) { + dma_fence_put(fence); return -EBUSY; + } dma_resv_add_shared_fence(bo->base.resv, fence); -- 2.25.1