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=1796380763; b=DDx93rliVbOnnIAxNJUkpWM5lMkUZxlLeZar3VUMB6ae0QStB/S2dNzwTIm/oacs2nTo OtPEVNhsyIbBHHwu6wJXokD5LFeMk1R7GOWWATfcpyta5hL/sJuYt0/wtIwd1t/U4yRgF +uCbrj6ZWe0H2lgVMLxc3Jqb1wug2DrjWC23upP3UOcCCNChG9bFW9yF8sa5VVo2z+Bt5 kOoui3wzipBTaQP5gE53QZ5ObQJPKz/6a4wR8+05syniflOeMPRAPXBJLqZULV732Ga5E 7q7yYHs/wPpd914h3CM1ViMFhqq44GF+2AJjGAB68P8ujqUDE0/90aDgr2qufnPcjUw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380763; 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=6MS9bO6kMlGRGZByD/l9UQO2/hfxQeqcb6zWge2RWL4=; b=PsqSghMgQdQ6fe0JdNa5LDg4mEjsMQbqhjHryLK+Rkecat8Og99+4hJqccACPg8FDR15 UWDwB4NhRvFp6iDfSfKkxZTUGTFfe5LuT+5qhDyyEwCGaMPSesurIbMjawJjvBBMDH7NL pHhFqcVKQK5qKlhkdIonweVIEQ0y1oXnP8aut284PX+s3PUsz9ZHG8K6OeaCxoGJZSn2T AGqsFSf2hxlJ6f6nEoNjels10hJpDyqjNy5+szBgYyBUjKIwa5uHm7sNTkRv8yEzttTRD UsyeYtlqSnnjAxBno2pRgZfISMQyb7j70Iz0JlaUzH36L27dxDO9VwAfPQryEeQItxg== 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=EHICAHqj; 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 385FB606A32C; Fri, 4 Dec 2026 10:39:23 +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=EHICAHqj Received: by smtp.kernel.org (Postfix) with ESMTPSA id A29D71F000C2; Fri, 4 Dec 2026 10:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380763; bh=6MS9bO6kMlGRGZByD/l9UQO2/hfxQeqcb6zWge2RWL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EHICAHqjWi9g3bdbObmGUOsJfzOKaQwCbv4JrkjgJkI49Orwx3eugz/QvVUvHCZqI CV4gABedV4u2CtInsgzim5a/HWnRXSt4Xd96+Tis9DvOzeEBKHYqqIqJ5gFoI2W0lY Fgk0jlzpwSgZRVTMtjjsY0aoGZ/eVQZb7efxe/Xc= 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 7.3 397/742] drm/amdkfd: keep the DMA addresses of a range intact if splitting fails Date: Fri, 4 Dec 2026 19:04:21 +0900 Message-ID: <20261204100645.640822630@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -1007,7 +1007,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; @@ -1018,19 +1018,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) { /*