Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1082028ybt; Wed, 1 Jul 2020 18:24:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFgjGoyexM67S0N8IWb0UdpuNglCHt07FIrfSiDlqiZcdJ5NlEnMLUxYW3qoYS+LzY85OB X-Received: by 2002:a17:907:7290:: with SMTP id dt16mr24679392ejc.63.1593653040493; Wed, 01 Jul 2020 18:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593653040; cv=none; d=google.com; s=arc-20160816; b=ky7RtoDJn2QaLvTIYSbmAkb1485s9L7wnq3e8VM8d/7FuN4WLBZkYYPtL6xwjqUFyc ZljrRTavNKZoUMWM9MrG8iBAvsaxXeJM3Hzx+HjmEHkkGgTzYINzq/YqGqpVxteCmmEc BNwsYS8z7yZuyjKQ6ziBbAX7+DYdRqx4WYHJ9ThPL5Co8NFYYtdXW/6tBNHUqs9aCgpB voxtc93eCoemWRAn0Sp2jALyk8WOG+Rm64jJz8yzkJlMjV9uMy3AaMNeSw2f35UJxFjb mXSZZprPPZGX32yjlGa/y3G8pnCV9bx2HiXxvq+mgwN56Fze8iaZudM+8mtAGzm0rHEf U1mQ== 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=qvm4bcmCk/b2iPGcaFDB9V0JocMrDCrdT1DtNb3eXo0=; b=aqqy88l2rNST60cMEgEqU8IASnYkDULRJW5/mu5JC333+8mJIBU8ppWH7uHJvsa5LA IXVbC5w53Lv6/Ew8ZZ55yhJdX50BAF6Gt6YorWFJLyhZuLbXVVAVc2mA1qp2BOzj4jlz NS41/vqScVt8Mo1zonJwbL86LFxw7TFMzETpz22ABzfCe0+63sbmgmVUU6J6K6pQgpds IRAMkDQNIj2JjBZwuf8hTdfFI4i2qNdfGm1SciY7+pZDNkktXin45vEahIT6CgK71+XG Vi5fKAP+oRiuq0puzEctZB40y1jMR37jkdE4hGXAuGQvHqfbZEpbpGfu0FqBBkWjSrbx xvIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=RsBmcNxW; 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 d5si4929619ejm.223.2020.07.01.18.23.37; Wed, 01 Jul 2020 18:24:00 -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=RsBmcNxW; 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 S1728211AbgGBBXI (ORCPT + 99 others); Wed, 1 Jul 2020 21:23:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:53346 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728174AbgGBBXD (ORCPT ); Wed, 1 Jul 2020 21:23:03 -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 8AAAA20874; Thu, 2 Jul 2020 01:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593652982; bh=H6E1ErTHKdU8VDL/lt494z9m+g1stL2ziOwVXwpMVPw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RsBmcNxWvcFx8Qd0eTxU8HcHpfbmrYWP3whfaXxMqJJgJ/fIVfN4kC5Vr8OjHGNI7 8v5eCp5xz1u9XkDTBf34C1IvnEhRySFyBksWYTJf9cLV1A6IK+qGgDjNdKARoB0bnx C6g3FlX7XZ9dxdLqx5fQ05/xOz5esjdVUEQCnXh8= 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 06/53] drm/ttm: Fix dma_fence refcnt leak in ttm_bo_vm_fault_reserved Date: Wed, 1 Jul 2020 21:21:15 -0400 Message-Id: <20200702012202.2700645-6-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 37cc4b95d13f311c04aa8e9daacca3905ad45ca7 ] ttm_bo_vm_fault_reserved() invokes dma_fence_get(), which returns a reference of the specified dma_fence object to "moving" with increased refcnt. When ttm_bo_vm_fault_reserved() returns, local variable "moving" becomes invalid, so the refcount should be decreased to keep refcount balanced. The reference counting issue happens in several exception handling paths of ttm_bo_vm_fault_reserved(). When those error scenarios occur such as "err" equals to -EBUSY, 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/370219/ Signed-off-by: Christian König Signed-off-by: Sasha Levin --- drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c index 0ad30b1129821..72100b84c7a90 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -300,8 +300,10 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf, break; case -EBUSY: case -ERESTARTSYS: + dma_fence_put(moving); return VM_FAULT_NOPAGE; default: + dma_fence_put(moving); return VM_FAULT_SIGBUS; } -- 2.25.1