From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382316; b=RFCqIuW3zMuNyMj8w4JQbTgMJ2zixlsKhSej2Jj3fy3LkTtNoFgaioOCowIoOK1Cd99R aFntzUBJ2THyWy+aedhc526Qx3WluK1tzByoU7f8gi64Cs9SBZmj6GtTTHbKQ/59qpPGK 9uFqyzv8cqeWIzENxC+l8yKSqX2tb5jutWjrLH49ZBX6WWVEDzawyS/cxKNLIiYzFJ6vE q7w2cbt533Xu1/Xti1/5KG+RETE4vKTe9EhGhug7G0xS85LB2Uq5S82entzNIkdm+LuWX E9RzwbcPUOvG/DJvKPkyMY0wvt5icH07SNrdUs4tiqNIttZKPGLuJjRTgBwgo7SnFxA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382316; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=5fW40OWMN0l41d7vgDkFu4fQK7LapztsQ/rU6dxkD4E=; b=u9JwywC+gKgKPWoSR2XB2RWtbsqwraTgJjyFhcUz5lrCmYf7Q51dTtkY8265j7lXcFGS xODoxzVySGYL4/F5HiQcZTv5+B61QDBGxHw0WZL1/eFASPNvfAkEMI54SzUS7GLqn2VQY rpFPy625T9ty5V5r6lczLzMVmxkDsQt9uB5Sbs7S/WbwNd7NH11BmyETLa1avrnIRuV91 D8zojX0EcU+ivWComQNNlHgHcz63NBV9pb+38evevkwY/SxKaIAOBDQCjbigAm8n8jbK5 RaxgcA8/GsbI2buUYquTEpQuETHu+UJrdkFJTp6Z5PR34ox2GrQfdgVaDI0TJxpMGOg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=K2NZC3PT; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EC75F606A32F; Fri, 4 Dec 2026 11:05:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=K2NZC3PT Received: by smtp.kernel.org (Postfix) with ESMTPSA id 629531F00939; Fri, 4 Dec 2026 11:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382315; bh=5fW40OWMN0l41d7vgDkFu4fQK7LapztsQ/rU6dxkD4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=K2NZC3PTua7ztiIdeEB0dGEc3DDUB1+YRqdY6pPkfaoWRObOoS0TqgF3mJaGcvS/0 Fl8gkkdycGdcpVYvqKntHfjbNuxYwZXwU2KUPj/ss0E5/aUt6NPGQ5BIKE9ty75GIW df/YFSa3vQxarPKIuxJjhzWkLEtg+41toPJacqrg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Felix Kuehling , Jesse Zhang , Alex Deucher Subject: [PATCH 6.18 364/703] drm/amdkfd: keep the DMA addresses of a range intact if splitting fails Date: Fri, 4 Dec 2026 19:04:23 +0900 Message-ID: <20261204100637.496107516@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jesse Zhang commit 63b42ad2fdd371ae4a86658295943d60a86a519b upstream. svm_range_split_pages() splits the DMA address array of one GPU after the other, and each split replaces the old range's array by a shorter one. If a later GPU's array can't be allocated, the old range is left with the arrays of the earlier GPUs already shortened, but with its old size. Unmapping it then walks past their end. On navi31 with its iGPU, an SVM range accessible by both GPUs, and unmapping a page in its middle with allocations failing in turn through failslab: BUG: KASAN: slab-out-of-bounds in svm_range_dma_unmap_dev+0x13f/0x170 [amdgpu] Read of size 8 at addr ffff88819ac32800 by task kworker/8:1/171 svm_range_dma_unmap_dev+0x13f/0x170 [amdgpu] svm_range_dma_unmap+0x119/0x2c0 [amdgpu] svm_range_free+0x312/0x520 [amdgpu] svm_range_handle_list_op+0x326/0x500 [amdgpu] svm_range_deferred_list_work+0x338/0x790 [amdgpu] Allocated by task 2749: svm_range_copy_array.constprop.0+0x55/0x190 [amdgpu] svm_range_split+0x388/0x17b0 [amdgpu] svm_range_unmap_split+0x254/0x370 [amdgpu] svm_range_cpu_invalidate_pagetables+0xb29/0x11d0 [amdgpu] The buggy address is located 0 bytes to the right of allocated 2048-byte region [ffff88819ac32000, ffff88819ac32800) Split the arrays of all GPUs first and only replace the old ones once all succeeded. With that the 2759 unmaps of the same sweep give no report. Fixes: f80fe9d3c114 ("drm/amdkfd: map svm range to GPUs") Reviewed-by: Felix Kuehling Signed-off-by: Jesse Zhang Signed-off-by: Alex Deucher (cherry picked from commit 3cbd0b498ac18821ec01c08e39050a4d22ea9eeb) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) --- a/drivers/gpu/drm/amd/amdkfd/kfd_svm.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_svm.c @@ -975,7 +975,7 @@ svm_range_split_array(void *ppnew, void kvfree(new); return -ENOMEM; } - kvfree(pold); + /* The caller frees pold once all arrays of the range are split */ *(void **)ppold = old; *(void **)ppnew = new; @@ -986,19 +986,36 @@ static int svm_range_split_pages(struct svm_range *new, struct svm_range *old, uint64_t start, uint64_t last) { + dma_addr_t *old_dma[MAX_GPU_INSTANCE]; uint64_t npages = last - start + 1; bool has_dma_addr = false; int i, r; + /* + * Split the arrays of all GPUs before replacing any of them, the old + * range must stay intact if one fails. + */ for (i = 0; i < MAX_GPU_INSTANCE; i++) { + old_dma[i] = old->dma_addr[i]; if (old->dma_addr[i]) has_dma_addr = true; - r = svm_range_split_array(&new->dma_addr[i], &old->dma_addr[i], + r = svm_range_split_array(&new->dma_addr[i], &old_dma[i], sizeof(*old->dma_addr[i]), old->start, npages, new->start, new->npages, old->actual_loc ? &new->vram_pages : NULL); - if (r) + if (r) { + /* new->dma_addr[] goes with the new range */ + while (i--) + if (old_dma[i] != old->dma_addr[i]) + kvfree(old_dma[i]); return r; + } + } + for (i = 0; i < MAX_GPU_INSTANCE; i++) { + if (old_dma[i] == old->dma_addr[i]) + continue; + kvfree(old->dma_addr[i]); + old->dma_addr[i] = old_dma[i]; } if (old->actual_loc) { /*