From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Xiaogang Chen <xiaogang.chen@amd.com>,
Philip Yang <Philip.Yang@amd.com>,
Jesse Zhang <Jesse.Zhang@amd.com>,
Alex Deucher <alexander.deucher@amd.com>,
Sasha Levin <sashal@kernel.org>,
Felix.Kuehling@amd.com, christian.koenig@amd.com,
Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: [PATCH AUTOSEL 5.15 02/20] drm/amdkfd: Fix a race condition of vram buffer unref in svm code
Date: Tue, 7 Nov 2023 07:28:56 -0500 [thread overview]
Message-ID: <20231107122940.3762228-2-sashal@kernel.org> (raw)
In-Reply-To: <20231107122940.3762228-1-sashal@kernel.org>
From: Xiaogang Chen <xiaogang.chen@amd.com>
[ Upstream commit 709c348261618da7ed89d6c303e2ceb9e453ba74 ]
prange->svm_bo unref can happen in both mmu callback and a callback after
migrate to system ram. Both are async call in different tasks. Sync svm_bo
unref operation to avoid random "use-after-free".
Signed-off-by: Xiaogang Chen <xiaogang.chen@amd.com>
Reviewed-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Jesse Zhang <Jesse.Zhang@amd.com>
Tested-by: Jesse Zhang <Jesse.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
index 22a70aaccf13c..b7d32a5062b6c 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c
@@ -550,8 +550,15 @@ svm_range_vram_node_new(struct amdgpu_device *adev, struct svm_range *prange,
void svm_range_vram_node_free(struct svm_range *prange)
{
- svm_range_bo_unref(prange->svm_bo);
- prange->ttm_res = NULL;
+ /* serialize prange->svm_bo unref */
+ mutex_lock(&prange->lock);
+ /* prange->svm_bo has not been unref */
+ if (prange->ttm_res) {
+ prange->ttm_res = NULL;
+ mutex_unlock(&prange->lock);
+ svm_range_bo_unref(prange->svm_bo);
+ } else
+ mutex_unlock(&prange->lock);
}
struct amdgpu_device *
--
2.42.0
next prev parent reply other threads:[~2023-11-07 12:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 12:28 [PATCH AUTOSEL 5.15 01/20] drm/komeda: drop all currently held locks if deadlock happens Sasha Levin
2023-11-07 12:28 ` Sasha Levin [this message]
2023-11-07 12:28 ` [PATCH AUTOSEL 5.15 03/20] drm/amd/display: use full update for clip size increase of large plane source Sasha Levin
2023-11-07 12:28 ` [PATCH AUTOSEL 5.15 04/20] string.h: add array-wrappers for (v)memdup_user() Sasha Levin
2023-11-07 12:28 ` [PATCH AUTOSEL 5.15 05/20] kernel: kexec: copy user-array safely Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 06/20] kernel: watch_queue: " Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 07/20] drm: vmwgfx_surface.c: " Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 08/20] drm/msm/dp: skip validity check for DP CTS EDID checksum Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 09/20] drm/amd: Fix UBSAN array-index-out-of-bounds for SMU7 Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 10/20] drm/radeon: Fix UBSAN array-index-out-of-bounds for Radeon HD 5430 Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 11/20] drm/amd: Fix UBSAN array-index-out-of-bounds for Polaris and Tonga Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 12/20] drm/amdgpu: Fix potential null pointer derefernce Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 13/20] drm/panel: fix a possible null pointer dereference Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 14/20] drm/panel/panel-tpo-tpg110: " Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 15/20] drm/amdgpu/vkms: " Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 16/20] drm/panel: st7703: Pick different reset sequence Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 17/20] drm/amdkfd: Fix shift out-of-bounds issue Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 18/20] drm/amdgpu: Fix a null pointer access when the smc_rreg pointer is NULL Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 19/20] arm64: dts: ls208xa: use a pseudo-bus to constrain usb dma size Sasha Levin
2023-11-07 12:29 ` [PATCH AUTOSEL 5.15 20/20] selftests/efivarfs: create-read: fix a resource leak Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231107122940.3762228-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=Felix.Kuehling@amd.com \
--cc=Jesse.Zhang@amd.com \
--cc=Philip.Yang@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=xiaogang.chen@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox