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=1796382290; b=KLoLGtTz+XZk8ZOXvM8SrUZnxUXjP/zo+CflOSQrGRG1y7C4w+2ic70PD/rlIvDXtR0v WoP25gQjPOE5MSG0unV9fGxqGa4lrqeAkqfffSMOC9O8WWDxu6PhPVTz4dGPt7044xUoM EceJ2hO681VBRCpWUofGEQIoxfOrpSjJCjwcnhxQjr50g+0O6E8Nv6OJlUc/jVH5FsmUT MnWDZJeU+8Bl42/RFuFIXFnG73elGOHAx/jsv+IvvfUT2U1je//bHFkpIHv/lc8VXD6Il Xmffe4B97ky/7QsfIpj6MVmxoYu6t4ad8lkyIfVgz6gl4hElyIK6sto7M6KlGQ56Mfw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382290; 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=6wfsPApmpoNavW/n+Y53TAj06oEmmPkmNILq2+1J148=; b=Q87dhYEEuN26GTX3aCdDj77HkQsOnjxUUWHtrIG1YpVSVb8wTl7bm+ctnVKhaqs5ptpt edZt2hHhftKg+RIkOAoHpXPYsp5Q0JlHuKa6RJC6IASe6Rsgr2a9hPcB7MvCEpU8VgFZo NKVqSeSEC5bsDK+jZ5Q/tA29ztM1zJlJjos1jhlzRIrDOaxFylHAZl9Gci1NN0pZ6Hr4w N8+08yXApFOOUspappk9CsAep0KOcd11DQn5z+thBjvj9VECv+lCwq6n2yx2WeXcX5orn uLirly1GXQsSLwOOomlaGfSArmJIE6hUIoG9Lu+1nUYZfOqjZkkTrYkbOGg53FxFoQQ== 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=zCPmpT0K; 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 C18A9606A322; Fri, 4 Dec 2026 11:04:50 +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=zCPmpT0K Received: by smtp.kernel.org (Postfix) with ESMTPSA id E49661F000C2; Fri, 4 Dec 2026 11:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382290; bh=6wfsPApmpoNavW/n+Y53TAj06oEmmPkmNILq2+1J148=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zCPmpT0K+uHA3ZZapQdjuRIva8X6G9ipwY9Dwx9lQE3PFJHX56vpP6/vAqXGnm56c rqbs1woRRp29MLp7TChr1cNddRBS21gutX20x81hQ7P55BusSMeBG+yqSxShLnI03b xWWD66I71MPtRIObofg1leEs6A2w7GpzoLR+ijSE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Apurv Mishra , Philip Yang , Alex Deucher Subject: [PATCH 6.18 363/703] drm/amdkfd: Dont reuse a VRAM page that is still referenced Date: Fri, 4 Dec 2026 19:04:22 +0900 Message-ID: <20261204100637.468999134@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: patches@lists.linux.dev 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: Apurv Mishra commit 8cd5429d429eced2441173b3306f7e137a4dc31f upstream. In svm_migrate_copy_to_vram(), skip VRAM pages with a non-zero refcount and leave those pages in system memory for this migration. When an svm_bo is reused, a VRAM page can still be held by an in-flight CPU fault (do_swap_page -> svm_migrate_to_ram). Migrating to VRAM then re-initializes the page via zone_device_page_init(), resetting its refcount. The fault's late put_page() frees the page mid-migration, so migrate_vma_finalize() never restores that PTE. It is left pointing at a freed system page and hmm_range_fault() hits BUG_ON in pfn_swap_entry_to_page() (swapops.h). Signed-off-by: Apurv Mishra Reviewed-by: Philip Yang Signed-off-by: Alex Deucher (cherry picked from commit 1f19aa7acacbce35584dd8f75a30880096fda6a4) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) --- a/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_migrate.c @@ -289,16 +289,26 @@ svm_migrate_copy_to_vram(struct kfd_node amdgpu_res_first(prange->ttm_res, ttm_res_offset, npages << PAGE_SHIFT, &cursor); for (i = j = 0; (i < npages) && (mpages < migrate->cpages); i++) { - struct page *spage; + struct page *spage = migrate_pfn_to_page(migrate->src[i]); if (migrate->src[i] & MIGRATE_PFN_MIGRATE) { dst[i] = cursor.start + (j << PAGE_SHIFT); migrate->dst[i] = svm_migrate_addr_to_pfn(adev, dst[i]); - svm_migrate_get_vram_page(prange, migrate->dst[i]); - migrate->dst[i] = migrate_pfn(migrate->dst[i]); - mpages++; + /* + * A reused svm_bo page may still be held by a CPU fault. + * Reinitializing it would free it under this migration, + * so leave this page in system memory. + */ + if (page_ref_count(pfn_to_page(migrate->dst[i]))) { + dst[i] = 0; + migrate->dst[i] = 0; + spage = NULL; + } else { + svm_migrate_get_vram_page(prange, migrate->dst[i]); + migrate->dst[i] = migrate_pfn(migrate->dst[i]); + mpages++; + } } - spage = migrate_pfn_to_page(migrate->src[i]); if (spage && !is_zone_device_page(spage)) { src[i] = dma_map_page(dev, spage, 0, PAGE_SIZE, DMA_BIDIRECTIONAL);