Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63BB1606A322 for ; Fri, 4 Dec 2026 20:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=amd.com header.i=@amd.com header.a=rsa-sha256 header.s=selector1 header.b=cGbMhtyB Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 04C2310E771; Fri, 4 Dec 2026 20:17:17 +0000 (UTC) Received: from CY3PR05CU001.outbound.protection.outlook.com (mail-westcentralusazon11013021.outbound.protection.outlook.com [40.93.201.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id D766D10E771 for ; Fri, 4 Dec 2026 20:17:10 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RXWqL0+RL54f6UNfy90ntlQKsQxHF9AhiXg4R9mO6tsIb8PCHrnXNOiTbmu/x9hW6KGq9P3VQY+yKPuLT527PGQiR1DvoMDJc10Ig6aWbiV8lmZgxvBXi5tG+hBm/hOMBQWmD9mfHl7jz5xzx7r2RqVoJ9GFa5uuqziipWUUGdnloyV3HBNcGJ6XNzSU6lm0aHq+PRhJGn0ZOzVfaWB+XgAsLlSlFT7UwoEAqprsVSkT15k+3E1PvvJvz+2VpqxLlrJEIwj841C7Uitq/jTREzUzNUluDz/e0cdK8kWGkhX9R5Ww8oraC5GN0hruou7pttTUtK2FjTPYshasdeItsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JW+4AtJsLRP4+ZLZ+0xXlX43B5CefM82aoMQbacoEbw=; b=O/Vz719A0J9zdGAjl+h1Vb0BJytvE+ir8mD/paGEkNcUG2OUJP8PUMNpawbK6hMwjzrUzR/x2Srly9EQ+bZVMZ09F9E0ks7W5KdKuo/iwv1RvqEzebTdOYxU3BXFR7fm98LjJv5WqRdh52wnelka3PnufKtzdE4JYN/30fSusQN/gYw0sUeA5VoqIL7aByQnjtwHiy57OVj8Ajn5d8aK/Q7at9V5Xkxs17KrMFgqQVckLXyuBldNOFIO+uCETewedak9+B8Wb4yrH7cEjMYrgQ6XCRfAZ+juErVqZX9wFeV6ogqni/L/otGPSdiWRIWldh2Rk2r9K4xIDr8Cz5qyvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.freedesktop.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JW+4AtJsLRP4+ZLZ+0xXlX43B5CefM82aoMQbacoEbw=; b=cGbMhtyBEv3zF23d2sesTED9vDRNztUXB4HC4sM9s++yais6hmBqKcGJqOLmSY4UF9cS0JBjTgTQLq3slIx3KIoe6Nb0dS5nErKnpnY3D/fxKdjOgDWRSR1vHewQVKSdAoRhuOvLU4Oc2SJQRNZ8can/gMwU8M/WRvGZTOVIw18= Received: from MN2PR06CA0005.namprd06.prod.outlook.com (2603:10b6:208:23d::10) by PH0PR12MB7470.namprd12.prod.outlook.com (2603:10b6:510:1e9::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Fri, 4 Dec 2026 20:17:05 +0000 Received: from BN7PEPF0000009D.namprd04.prod.outlook.com (2603:10b6:208:23d:cafe::ae) by MN2PR06CA0005.outlook.office365.com (2603:10b6:208:23d::10) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.13 via Frontend Transport; Fri, 4 Dec 2026 20:17:03 +0000 X-MS-Exchange-Authentication-Results: mx.microsoft.com 1; spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by BN7PEPF0000009D.mail.protection.outlook.com (10.167.248.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.709.6 via Frontend Transport; Fri, 4 Dec 2026 20:17:03 +0000 Received: from amir-devpc.tail3064dc.ts.net (10.180.168.240) by satlexmb07.amd.com (10.181.42.216) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Fri, 4 Dec 2026 14:17:02 -0600 From: Amir Shetaia To: CC: Alex Deucher , Harish Kasiviswanathan , Felix Kuehling , =?UTF-8?q?Christian=20K=C3=B6nig?= Subject: [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute Date: Fri, 4 Dec 2026 15:16:49 -0500 Message-ID: <20261204201649.375581-1-amir.shetaia@amd.com> X-Mailer: git-send-email 2.43.0 X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb07.amd.com (10.181.42.216) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN7PEPF0000009D:EE_|PH0PR12MB7470:EE_ X-MS-Office365-Filtering-Correlation-Id: fa0996cb-4226-484b-988d-08df52438f87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|36860700016|1800799024|23010399003|11063799006|6133799003|261009223027099003|18002099003|261028144727099003|260925021311599003|260925021911599003|56012099006|260925022911599003|261021123027099003|10067099003|261102123227099003|261022105027099003|261022075727099003|261026140227099003|261026121527099003|261021121427099003; X-Microsoft-Antispam-Message-Info: EEc1SjD8RgxGZxGJ9wIUf8ffy4dp7ACLg9AKK5zXXxmCvSss1AwelsHwMfXy+vkCYMcRkrr5A7FwAlkUHvZfqD66H3ljhUtQugRV2B8ZqhZ08tMAxYSuvIl8JsYH8IIbSjlPTNEsshuC34H/0OP6yq0uc2clk5U78afHn6pHfgLX3lE0aFB/9n9XPj0ccE0ADV28gZ04wtsvDGV1S7tydfnSuA7vjmkzgitNEfIWzjPHL5ZWk17cvK5c+daAbVIcVked06bThX2c3Lbu/U+XSuGO7nyjTzZNC/7PQGuyA0MiMv476DXgmiMrbWII6nbMxwrpZXqHNIJr1+qBl7XIzeIiG9On6LWdTrvydnR5DjIHHJBkshGGAJvJ9Y6m+nRfjYbRnvh4Jhp6wJiheIdr9D2F18+1fsPkaAI0DQCQpQpGYGGo+FVdffpkTvLOqDuosj1bYNCWNkQ8q3tky97G/9/Ivyn32GnG1w7VpYdIaEKAJm5IlURE1MwTLyKP4qfb7vi8RMIPFi31Czyf0mdQ7ioEn0x5M7vxhvi7pJFCG949SBNpY8FG712E20lrQtjj6/Ksw27if/cKpTO3U3V6iDwJ9idGlc/LrlWzd1Q6q00liDLYBgwb1Sqopjl3xK8gEH1YAdGsDyEcPx/56tIGxabfsLWzshN21CzJKCa5pZpyCtDEYSXifIwdAIRRd/QwPcZ2K2G7VfkOt/le9GokLw== X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(82310400026)(36860700016)(1800799024)(23010399003)(11063799006)(6133799003)(261009223027099003)(18002099003)(261028144727099003)(260925021311599003)(260925021911599003)(56012099006)(260925022911599003)(261021123027099003)(10067099003)(261102123227099003)(261022105027099003)(261022075727099003)(261026140227099003)(261026121527099003)(261021121427099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pela/wgIGtfIj7zcxcXMcmjBZZFxcRt7cMoz+KL/1whbvD7sGdvuvwjp2haqeakcIaiAYZFprQb1OXfPep/0LHOw40onbCDWgHVtS1w6ohoTCyCmzpKIVAWQ1mACzuvDwbQ0/Hon7dEVeM9pSxnCSiLS3MLPCCPZ5T7LFheX88nZjarDMU/Rn8/BneNpSbsOyC/m+c8/wE9l5Am4WhxqvhZX5pLMJ0rRLso+I11mnIAokpf3h9fto1miJJ1nqqonbJwdZty9F2FUommkP39Vmi4fsgDmWnApTNvXydnmQtazL4JnFXKGQdvRpyBzEkZg/KPa7s0JKGF0xiRnV+2shMkaVdTsuj6XizpGJkmnjgI3jDyFGXQz3ia9E4CyqoGP3ha5R5lDsmLgPdP4SLhBTx1TpApY4wIW6Z9GyceHD/A0NnlTWnk0PZUD0RruJ1XI X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 20:17:03.3773 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fa0996cb-4226-484b-988d-08df52438f87 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d; Ip=[165.204.84.17]; Helo=[satlexmb07.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN7PEPF0000009D.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB7470 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "amd-gfx" X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 amdgpu_vm_make_compute() switches a VM to CPU page table updates when compute VMs use the CPU path (vm_update_mode, the default when all of VRAM is CPU visible). Before switching it waits for the last SDMA update/clear of the root PD with amdgpu_bo_sync_wait(). That helper goes through amdgpu_sync_resv(), which only iterates DMA_RESV_USAGE_READ fences. Since commit 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") page table updates add their fence to the root reservation with DMA_RESV_USAGE_BOOKKEEP, so the wait no longer covers the clear of the root PD issued at VM creation. A process that maps memory right after AMDKFD_IOC_ACQUIRE_VM can then write a root PDE with the CPU before the pending SDMA clear of the root PD has executed, and the clear wipes the entry. The GPU later takes a not-present fault on the mapped address. We hit this as a CPC fault on a user queue's write pointer page; walking the VM with UMR while the fault was pending showed the root entry as 0x8000000000000000. Adding a short delay after ACQUIRE_VM made the fault go away. Wait for all fences on the root reservation, including BOOKKEEP, before switching to CPU updates. The dma_resv_wait_timeout() result is kept in a long, since MAX_SCHEDULE_TIMEOUT does not fit in an int. Tested on gfx1201 with a v7.0 based kernel and a reproducer that acquires a VM, maps buffers and creates an SDMA queue right away: 8 of 8 runs faulted without this patch, 0 of 8 with it. Fixes: 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") Signed-off-by: Amir Shetaia --- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c index 0b8a8f82ecab..cc743df64af6 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c @@ -2728,6 +2728,7 @@ int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm, */ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) { + long wait; int r; r = amdgpu_bo_reserve(vm->root.bo, true); @@ -2744,11 +2745,16 @@ int amdgpu_vm_make_compute(struct amdgpu_device *adev, struct amdgpu_vm *vm) "CPU update of VM recommended only for large BAR system\n"); if (vm->use_cpu_for_update) { - /* Sync with last SDMA update/clear before switching to CPU */ - r = amdgpu_bo_sync_wait(vm->root.bo, - AMDGPU_FENCE_OWNER_UNDEFINED, true); - if (r) + /* Sync with last SDMA update/clear before switching to CPU. + * PT updates are BOOKKEEP fences, amdgpu_bo_sync_wait() skips them. + */ + wait = dma_resv_wait_timeout(vm->root.bo->tbo.base.resv, + DMA_RESV_USAGE_BOOKKEEP, true, + MAX_SCHEDULE_TIMEOUT); + if (wait < 0) { + r = wait; goto unreserve_bo; + } vm->update_funcs = &amdgpu_vm_cpu_funcs; r = amdgpu_vm_pt_map_tables(adev, vm); -- 2.43.0