From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 421E8C36014 for ; Thu, 3 Apr 2025 19:16:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D680110EAD9; Thu, 3 Apr 2025 19:16:48 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="sMNq1nYh"; dkim-atps=neutral Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id B5CAB10EAD2; Thu, 3 Apr 2025 19:16:46 +0000 (UTC) Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id 11EFC436F0; Thu, 3 Apr 2025 19:16:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DFE0BC4CEE3; Thu, 3 Apr 2025 19:16:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743707806; bh=mCS4l3tbN+LrbAUrpldLHlyevu2R5b92XL6t5aRvlmc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sMNq1nYh5N8pXawxsy8Y6tC4F/wU0Nmg2FSPpXJewVF7nFuTbtPWdj2i4Na2Edns1 HKaR4h5gej75CTIBAi112CK1JvvBahxlX7mChSg3jfXQYMle45fEBKDxnMWG7I6rIU 5SldhCGXHbTDpV3zXAN0OgFxVWy5oac0TWsWOLWeqMxeDiCDYrAsC6hwFxbBB5+Sp1 wEH3Imkj4pXKDTVAI65XpxQIzNZOMDj/+tS7y4u5D3bgvR2yxUkRqEWkiDiU42pb7o A7Bw1MbHVH4EUPxaaQYAFIoDjs1Y7DU3LLbyGXPFfxlEsNbF75VpAVaDxaLyWQgFWZ jve8i+Wf02lvQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Christian=20K=C3=B6nig?= , Srinivasan Shanmugam , Alex Deucher , Sasha Levin , airlied@gmail.com, simona@ffwll.ch, lijo.lazar@amd.com, sunil.khatri@amd.com, Hawking.Zhang@amd.com, Jun.Ma2@amd.com, Yunxiang.Li@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.13 32/37] drm/amdgpu: grab an additional reference on the gang fence v2 Date: Thu, 3 Apr 2025 15:15:08 -0400 Message-Id: <20250403191513.2680235-32-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250403191513.2680235-1-sashal@kernel.org> References: <20250403191513.2680235-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.13.9 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Christian König [ Upstream commit 0d9a95099dcb05b5f4719c830d15bf4fdcad0dc2 ] We keep the gang submission fence around in adev, make sure that it stays alive. v2: fix memory leak on retry Signed-off-by: Christian König Acked-by: Srinivasan Shanmugam Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 3780d50fd3ae8..61b3f676a5df0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -6707,18 +6707,26 @@ struct dma_fence *amdgpu_device_switch_gang(struct amdgpu_device *adev, { struct dma_fence *old = NULL; + dma_fence_get(gang); do { dma_fence_put(old); old = amdgpu_device_get_gang(adev); if (old == gang) break; - if (!dma_fence_is_signaled(old)) + if (!dma_fence_is_signaled(old)) { + dma_fence_put(gang); return old; + } } while (cmpxchg((struct dma_fence __force **)&adev->gang_submit, old, gang) != old); + /* + * Drop it once for the exchanged reference in adev and once for the + * thread local reference acquired in amdgpu_device_get_gang(). + */ + dma_fence_put(old); dma_fence_put(old); return NULL; } -- 2.39.5