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=1796383704; b=Gc2sjkn5mWK6gZy5FT7qWYzdOarh7sJbP36wn11+b+XS8d5gFnz3K2Sff+trRRjWrJh4 3/TkPFCFETXzbHdCMZWXvd6KvrDakcaqLQrRpDZ9OzH4bmNT9t2aA5HWBXvqaQUx9BaYm wT+pvtT7TBlcnrDkKZq2HQCC3ovfQesQFxNRfc1fuhSZfC0lWCJjqrqL85EMVQysc2Ysi XTXnCJYX2ufiqmrV4e0fc8VOljdbxyoRBnTF6kpWtnF8BXR4QrK3Rbbf2Kaj8T1E/bQwA p3/R7XJRCiK39Xjf/NKJzQ+t0yn+t/A+g4lg8roLIltn1eQbm25Hpd1VmIfyNBSZ8eA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383704; 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=arO7eSJpoKxlg2B220Dcc/HQWSvA7Nmw8PmS1+HXRHQ=; b=nbB6iXLPO19vnId2x3J7uEWOKsziHOmAHptu/8jfZG9pPQNStbfLLTn2Rqa9Ge/RBqYS UGHWBeV1Oo6dfDUvmCehMl4OHeRQEDAKKh7Fd81EyN3PLAm+gPbF6xpzk56jf5T6r4bQk Xd6r7o9kbWMAgNONaOqIqoRFoULWDuwRb1xg/gRWU13GTdOjeqda/Ad8PMwEXMiKLwOWt mhL6l9KoG81uXFg+wui8diPUbT83nR5bCQAD0gSRuI7ZJlXOSP/LXMJ+wXySlOhFo9Nyd QJ0hxcSE6QjqIwGfQJy8ljYEZD/fQLCeGhsLscIvMSpO2nZ1W3OQ6EQafvBXoVJr9QQ== 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=xYVTjBkB; 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 4BB1A606A322; Fri, 4 Dec 2026 11:28:24 +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=xYVTjBkB Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB69D1F000C2; Fri, 4 Dec 2026 11:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383704; bh=arO7eSJpoKxlg2B220Dcc/HQWSvA7Nmw8PmS1+HXRHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xYVTjBkBXMm3ZIOyfPawP0SDV3S/YTmEglfsbczTz9m5krIxU6c/6QOmOVy/LvCS0 BOuI7HsAEKfTJkrg2+hpF05cIiyrutx5LUDiyL/yAgwi3dgnCdIHN/Enm6BbjhuguW 25+5DBDI3NSlxLVEXuBslyfzMSMeZO7WR0BFd+4s= 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.12 337/555] drm/amdkfd: keep the DMA addresses of a range intact if splitting fails Date: Fri, 4 Dec 2026 19:06:20 +0900 Message-ID: <20261204100622.772426736@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 @@ -974,7 +974,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; @@ -985,19 +985,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) { /*