Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BFC4125A2B5; Mon, 9 Jun 2025 13:46:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749476776; cv=none; b=ffJwc0DbRUcTSPZ9SEPUpJTA+PzySAtS/EaRSh611qKtVlD37W7SiaWCQ4lm0XXxgshtmREZqUPltByrVWspRvAeEKjfyEHVp52O8cTn0BcMNxPBHnmDRAeEKtDnDJbC2OHy687vyd/mPigmEMfiXuMpkEUlD2QMrDj9eWiQDl8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749476776; c=relaxed/simple; bh=tX7BSk49bEYM9xus6wbkHgH5F7CFpJmvecHwAWG5Vs0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HHn/wdfED9orzKTjQIDXYWqV4hJaL+RmkMDtRrpuP7R05Y6hsRp5RjCATFWyY0c2M1EFParpcjSfBlwcx3liugjCTaGWSb/IQqlHBxUiItDQRQxvQgmRCLfgDn6hkEVa+DRN0MXB/l+PF8j7ooXPXmAGqpwEZuxWU7uLr2QI/u0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lgNMaoAi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lgNMaoAi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9AA4C4CEEB; Mon, 9 Jun 2025 13:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1749476776; bh=tX7BSk49bEYM9xus6wbkHgH5F7CFpJmvecHwAWG5Vs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lgNMaoAiCMBjDguMTUsZe+sCK4S++fSUAXDdKjaFrD0pq+DWPTbpvNJRLdcCmNgRJ 1RpagaaEhn85EmGwpCbcUJpbyN3ohpG0KdOQObhi1U20B9wsJlPuhK62v3ttH10DlU IKZNuqRbEsIZ/fTjaUUaRboJkNK6IInLCAWGI8ei4WkYkCH9oPKbx0wFuGZ1/AXg5G rbHEXxCEV2tmnWndHtRUSy1WFxJIizeSEXWaem18PVKZO4ofVKSylxPRNrbXo19V87 cwctLJ0kPd586XQE85c/KAnT3bvz3oW1R61EdJRHOs1AT4RslfWftHIbkGY+6upQqj 88DIHMXyjjDVw== From: Sasha Levin To: patches@lists.linux.dev, stable@vger.kernel.org Cc: Yifan Zhang , Philip Yang , Alex Deucher , Sasha Levin , Felix.Kuehling@amd.com, amd-gfx@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.12 04/23] amd/amdkfd: fix a kfd_process ref leak Date: Mon, 9 Jun 2025 09:45:51 -0400 Message-Id: <20250609134610.1343777-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250609134610.1343777-1-sashal@kernel.org> References: <20250609134610.1343777-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.12.32 Content-Transfer-Encoding: 8bit From: Yifan Zhang [ Upstream commit 90237b16ec1d7afa16e2173cc9a664377214cdd9 ] This patch is to fix a kfd_prcess ref leak. Signed-off-by: Yifan Zhang Reviewed-by: Philip Yang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- **YES** This commit should be backported to stable kernel trees. Here's my detailed analysis: ## Bug Analysis This patch fixes a clear **resource leak bug** where a reference count is not properly decremented in an error path. Specifically: 1. **The leak occurs in `kfd_signal_poison_consumed_event()`** at line 1334 where the function returns early without calling `kfd_unref_process(p)`: ```c if (unlikely(user_gpu_id == -EINVAL)) { WARN_ONCE(1, "Could not get user_gpu_id from dev->id:%x\n", dev->id); return; // BUG: Missing kfd_unref_process(p) } ``` 2. **The function `kfd_lookup_process_by_pasid()` increments the reference count** on the kfd_process object (as confirmed by examining the kernel source). This means every successful call must be paired with `kfd_unref_process()`. 3. **The fix is minimal and correct**: It simply adds the missing `kfd_unref_process(p)` call before the early return, ensuring the reference count is properly decremented. ## Why This Should Be Backported 1. **It's a clear bug fix**: This fixes a reference count leak that will cause memory to be leaked every time this error path is hit. Over time, this could lead to significant memory exhaustion. 2. **The fix is minimal and contained**: Only one line is added, making it low-risk for regression. The change doesn't alter any logic or introduce new features. 3. **It affects user-visible behavior**: When GPU errors occur and this code path is triggered repeatedly, the memory leak could impact system stability and performance. 4. **Similar to previously backported commits**: Looking at the historical examples, commit #4 which also fixed a memory leak in create_process failure was marked for backporting and included "Cc: stable@vger.kernel.org". 5. **The bug is in error handling code**: While the error condition might be rare (invalid GPU ID), when it does occur, the leak happens every time. Error handling bugs are particularly important to fix because they can accumulate unnoticed. 6. **No architectural changes**: This is a simple bug fix that doesn't change any APIs, data structures, or introduce new functionality. The commit follows the stable kernel rules perfectly: it fixes a real bug, is minimal in scope, has clear consequences if not fixed (memory leak), and doesn't introduce new features or risky changes. drivers/gpu/drm/amd/amdkfd/kfd_events.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_events.c b/drivers/gpu/drm/amd/amdkfd/kfd_events.c index ea37922492093..6798510c4a707 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_events.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_events.c @@ -1315,6 +1315,7 @@ void kfd_signal_poison_consumed_event(struct kfd_node *dev, u32 pasid) user_gpu_id = kfd_process_get_user_gpu_id(p, dev->id); if (unlikely(user_gpu_id == -EINVAL)) { WARN_ONCE(1, "Could not get user_gpu_id from dev->id:%x\n", dev->id); + kfd_unref_process(p); return; } -- 2.39.5