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 0EFB9606A31A for ; Tue, 1 Dec 2026 14:15:33 +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=CmnRnHt0 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0A8B10F93C; Tue, 1 Dec 2026 14:15:27 +0000 (UTC) Received: from BL0PR03CU003.outbound.protection.outlook.com (mail-eastusazon11012048.outbound.protection.outlook.com [52.101.53.48]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3893B10F943 for ; Tue, 1 Dec 2026 14:15:21 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xyQXp1Xt4N3dUcY6sVKYsZIof5i45c/kc2Cye3H+HXdwyJpcaHrxn+qQuPVbHawe4Yfemul5NmrEnEk0njoSXHpKJuBXVpGeTcEc7bRZ7F5fTreZmOvspO/dBoYzQTM6qlJt7QD4IeoofNFVU/gATr5kj3PCYkM/rT6S9lMlkbr9ym57O75kpdSpbOBtviScEMdkQfPRfX9Rw3WifYD6U5Z+9gz12sBavDuWgHAEwnMcEPwHs2jYXYaFy4bJ41lQ80EN5wmibMOgmHDv73tfglPE7BQiEZ09HiK6vMZxXKGP6dUGtgaG5RdPm6dJYZ7WxA71zz9TV2t04r50Nk+3HA== 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=ruhQmRk2rLrd7NFUjsSyMaWoUsdZP7TFD18miSzxeqs=; b=uELcSq5X4CfkXdymUf4BUfAc/MKqmxbJpGcydTLSspEj/1AJ9KSnukF1Wfdxypdeirg2IkARFPe5VncyQJee8vbQN0RJyvBNpffCdtgEFNN9Ks1L8otLgCxfSZhB37F5ZwfR1E99Z7XiVg/MZqfN1DO9NZSnj0u+G1/4G6J3I+3cwFAvL4KKND/UH3i6yp7xi7wZlJcvIUR+F8ypGvms3OrfvxDzPGeZFioTVNuFYdAd20FX2soElyWbzj1P6X7hsGaivu2VcFdZqt5k00MCzrrlNguoSMG2N871fs4/l3TDrksikYDf5hC9y+g/d83m+p0jM7+46XnZcoYuScp7Bw== 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=ruhQmRk2rLrd7NFUjsSyMaWoUsdZP7TFD18miSzxeqs=; b=CmnRnHt0UvgLGJcCEetnn9GR90noQV5Fj12rBkfXzV4MNXVUwKVNAT3h6unwkB2Hfd+bKxh0rrYbCuDE41F3qDfPwf94G3NlnOtq/4XzjkTF4MLErEqBACXzE3R9Ai4Wuo0mWvzJ7DyzlViIqGa7U8uZTb5tpKsipT/7T9e1wdk= Received: from DS7P220CA0066.NAMP220.PROD.OUTLOOK.COM (2603:10b6:8:224::17) by SA5PPF530AE3851.namprd12.prod.outlook.com (2603:10b6:80f:fc04::8c9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.13; Tue, 1 Dec 2026 14:15:15 +0000 Received: from DS2PEPF00006E20.namprd05.prod.outlook.com (2603:10b6:8:224:cafe::52) by DS7P220CA0066.outlook.office365.com (2603:10b6:8:224::17) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.21.688.10 via Frontend Transport; Tue, 1 Dec 2026 14:15:14 +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 DS2PEPF00006E20.mail.protection.outlook.com (10.167.23.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.5 via Frontend Transport; Tue, 1 Dec 2026 14:15:13 +0000 Received: from jz-tester2.amd.com (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; Tue, 1 Dec 2026 08:15:13 -0600 From: James Zhu To: CC: , , , , , Subject: [PATCH 2/3] drm/amdkfd: rebuild CWSR TBA/TMA in VRAM after system resume Date: Tue, 1 Dec 2026 09:14:59 -0500 Message-ID: <20261201141500.3346608-2-James.Zhu@amd.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201141500.3346608-1-James.Zhu@amd.com> References: <20261201141500.3346608-1-James.Zhu@amd.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: satlexmb08.amd.com (10.181.42.217) To satlexmb07.amd.com (10.181.42.216) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS2PEPF00006E20:EE_|SA5PPF530AE3851:EE_ X-MS-Office365-Filtering-Correlation-Id: ba15a09a-7051-4a84-fc66-08df4fb5845d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|36860700016|1800799024|23010399003|82310400026|376014|10067099003|56012099006|261028144727099003|261026135527099003|261026121527099003|261022113327099003|261026140227099003|261026130827099003|261102123227099003|261022115727099003|261021133027099003|261021135927099003|261021123027099003|261021130227099003|261022105027099003|261021121427099003|261022075727099003|261009223027099003|18002099003|22082099003|5023799004|11063799006; X-Microsoft-Antispam-Message-Info: 47PTZBqWgVAsa1ejZnZ8f2owGJFma5nrMd0Nt7djByNEndj0ua0mwss7tK6HXqXebbYIdfQh5rsIhp4nQQRYydicHW/4mnpN8femsZkADDtkAjqvwn+btzkMWXq3rh3tPHNdlM5EzAKGxklmQpTcxMES+fQV/LDY8djbTLzcRHZiAxdNyDq0HSN8xBZl0bfgKdkYBLwVgbc+aaI1iFTNlrWSE+V/UCwfi21zcRsiph6Xzmrmckx19OPKCErU/sr4n0Gsyvj3nqB4WBF8wNl9mH97dtGXtI4tMT+i485idro00dD0yLEPa3nfb8FVf+F+P4eiFVneNeYUQHkQdavmS+kW2KJ7yIk566vpf3pI0TXiinvzYsggWSDGL2UrFmCukao8rZwP80LtDzZbmX81oQzSvGVCdgDbgdUSbeiLxKX/6tTiUtPm7huePDsefulsArkK/TOZePdk4sgqslpTppU0UxxQM9740iKroz5hk1WanHYXMDe/8O4jxjuiSS8UPAUDhMxXiC4bP3qvE3DKTmLOBXKPomb19ogVCat8chZ1dUK6Rkx1N1YNvsItxQ0vjhz3zk64GjSAaQCQNZPv9lOd7Ay6WOao1ND3qtGDr83cOJJdMDqicUSSwxk96y/ZF1gortl7vtOIZgcxyDLfZqKbGHifJfeGA5KCt3OyDw63+yWktYFJKxq93x+9sw+f0q9d1dPGIysbFNaRdTk9Hw== 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)(36860700016)(1800799024)(23010399003)(82310400026)(376014)(10067099003)(56012099006)(261028144727099003)(261026135527099003)(261026121527099003)(261022113327099003)(261026140227099003)(261026130827099003)(261102123227099003)(261022115727099003)(261021133027099003)(261021135927099003)(261021123027099003)(261021130227099003)(261022105027099003)(261021121427099003)(261022075727099003)(261009223027099003)(18002099003)(22082099003)(5023799004)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: N8ikqH8J0gWx5cvh3+Pqx3yuNwGNjOivIblxZtU9s5M7RAJe2DR4zBf7IPTtYUpwTiHwuO9dhIETv4ZE4F/5vhrL5DCR22ssCfqOvH+FvgfUst0iADetKADLaCpFfbYVRLenY4lWtoNPm9NLe1BtToi8NcIAOT4YOApqxtf5RGXu9LdAhA+TQbYsnTOASIuT+dHZcAzPk6K3roJMd0FVszat9O0uJNpSHWBun6mFMVW9XG+NmMiHE2Nr1L9ThxOcxOvy2wRnAmrFGI3foxmQG0QIn6klwhggKwApMeXkEroRj9p4/Tt/zfmfX2KCRrzA58pPB3Q0ngGKXVuyipGVCUVb06/Dhi6G7Sozd5z8gJjjdZ1Xvzf6rmxyXUwUeNf0/VmdPXuerlEYAfWXSgUD4VI4VXBBBJLRR6EJHp21XjR+aa/6lJPWk3KEfF/q6wyT X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2026 14:15:13.7576 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ba15a09a-7051-4a84-fc66-08df4fb5845d 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: DS2PEPF00006E20.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA5PPF530AE3851 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=-18.8 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 The CWSR TBA/TMA buffer is pinned, so it is not evicted on suspend. When it lives in VRAM its contents are lost once the GPU loses power, and nothing writes them again on resume. The first context switch after resume then runs a garbage trap handler and hangs the GPU. Only the kernel writes this buffer: the CWSR trap handler, the second-level TBA/TMA addresses and the debug trap flag. Keep a copy of the three TMA values and rebuild the whole buffer from kgd2kfd_resume() on system resume, before the queue manager is started, and flush HDP so that the GPU sees it. This is done once per kfd_dev, for the pdds of all its nodes. Until now the ioctls that write the buffer ran under p->mutex. The rebuild cannot take p->mutex: it walks the process table under kfd_processes_mutex, and p->mutex is already taken outside of kfd_processes_mutex. User space is frozen on system resume, but not when vga_switcheroo powers the GPU off and on, and there the rebuild would race with the set trap handler and debug trap ioctls. Add a per pdd cwsr_lock for the buffer, its mapping and the saved values. It is a leaf lock, nothing is taken under it. Runtime suspend would lose the contents the same way, so hold a runtime PM reference from the time a CWSR buffer is placed in VRAM until the pdd is destroyed, instead of rebuilding there. Fixes: fe5966d4fdcb ("drm/amdkfd: move TBA/TMA from system to device memory") Signed-off-by: James Zhu --- drivers/gpu/drm/amd/amdkfd/kfd_device.c | 11 +++ drivers/gpu/drm/amd/amdkfd/kfd_priv.h | 16 ++++ drivers/gpu/drm/amd/amdkfd/kfd_process.c | 100 +++++++++++++++++++++-- 3 files changed, 120 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device.c b/drivers/gpu/drm/amd/amdkfd/kfd_device.c index 2200f5c7c38d..8dc48a1eb5aa 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device.c @@ -1134,6 +1134,17 @@ int kgd2kfd_resume(struct kfd_dev *kfd, bool resume_proc) if (!kfd->init_complete) return 0; + /* + * A CWSR buffer pinned in VRAM is not saved across suspend, so rewrite + * it before any queue can be mapped. This also runs when vga_switcheroo + * powers the GPU back on, and in the unwind of a failed suspend, where + * it is merely redundant. Runtime resume is skipped: a pdd with such a + * buffer holds a runtime PM reference, so the device was never runtime + * suspended. + */ + if (kfd->adev->in_suspend && !kfd->adev->in_runpm) + kfd_process_restore_cwsr(kfd); + for (i = 0; i < kfd->num_nodes; i++) { ret = kfd_resume(kfd->nodes[i]); if (ret) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h index 8eac086aa108..c5cfd2d848fd 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_priv.h +++ b/drivers/gpu/drm/amd/amdkfd/kfd_priv.h @@ -733,6 +733,21 @@ struct qcm_process_device { uint64_t cwsr_base; uint64_t tba_addr; uint64_t tma_addr; + /* + * cwsr_lock protects cwsr_map and tba2_addr, tma2_addr and + * trap_debug_flag, which mirror what the kernel wrote into the + * first-level TMA so that it can be rebuilt. + * The ioctls that write them hold p->mutex, but that does not cover + * kfd_process_restore_cwsr(): it walks the process table under + * kfd_processes_mutex, where p->mutex cannot be taken (the Arcturus + * debug trap callback suspends and resumes KFD with p->mutex held), + * and it can run with user space not frozen (vga_switcheroo). + * Nothing is taken under this lock. + */ + struct mutex cwsr_lock; + uint64_t tba2_addr; + uint64_t tma2_addr; + bool trap_debug_flag; /* IB memory */ struct kgd_mem *ib_mem; @@ -1141,6 +1156,7 @@ int kfd_process_restore_queues(struct kfd_process *p); void kfd_suspend_all_processes(void); void kfd_process_wait_gpu_reset_complete(struct kfd_process *p); int kfd_resume_all_processes(void); +void kfd_process_restore_cwsr(struct kfd_dev *kfd); struct kfd_process_device *kfd_process_device_data_by_id(struct kfd_process *process, uint32_t gpu_id); diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 5dc657f32d38..7118ad38957f 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -1294,6 +1294,7 @@ static void kfd_process_destroy_pdds(struct kfd_process *p) mutex_destroy(&pdd->doorbell_mutex); kfree(pdd->vm_fault_exc_data); + mutex_destroy(&pdd->qpd.cwsr_lock); kfree(pdd); p->pdds[i] = NULL; } @@ -1582,6 +1583,65 @@ void kfd_cleanup_processes(void) mmu_notifier_synchronize(); } +/* + * Write the CWSR trap handler and the TMA fields. Only the kernel writes this + * buffer, so this also rebuilds it after VRAM lost its contents. + */ +static void kfd_process_device_fill_cwsr(struct kfd_process_device *pdd) +{ + struct qcm_process_device *qpd = &pdd->qpd; + struct kfd_dev *kfd = pdd->dev->kfd; + + lockdep_assert_held(&qpd->cwsr_lock); + + iosys_map_memset(&qpd->cwsr_map, 0, 0, KFD_CWSR_TBA_TMA_SIZE); + iosys_map_memcpy_to(&qpd->cwsr_map, 0, kfd->cwsr_isa, + kfd->cwsr_isa_size); + iosys_map_wr(&qpd->cwsr_map, KFD_CWSR_TMA_OFFSET, + uint64_t, qpd->tba2_addr); + iosys_map_wr(&qpd->cwsr_map, KFD_CWSR_TMA_OFFSET + sizeof(uint64_t), + uint64_t, qpd->tma2_addr); + iosys_map_wr(&qpd->cwsr_map, KFD_CWSR_TMA_OFFSET + 2 * sizeof(uint64_t), + uint64_t, qpd->trap_debug_flag); +} + +/* + * Rebuild the CWSR buffers that the nodes of this kfd_dev keep pinned in + * VRAM. kfd_processes_mutex keeps the processes in the table from being torn + * down. See cwsr_lock for why p->mutex is not used here. + */ +void kfd_process_restore_cwsr(struct kfd_dev *kfd) +{ + struct kfd_process *p; + bool rebuilt = false; + unsigned int temp; + int i, idx; + + mutex_lock(&kfd_processes_mutex); + idx = srcu_read_lock(&kfd_processes_srcu); + hash_for_each_rcu(kfd_processes_table, temp, p, kfd_processes) { + for (i = 0; i < p->n_pdds; i++) { + struct kfd_process_device *pdd = p->pdds[i]; + + if (pdd->dev->kfd != kfd) + continue; + + mutex_lock(&pdd->qpd.cwsr_lock); + if (pdd->qpd.cwsr_map.is_iomem) { + kfd_process_device_fill_cwsr(pdd); + rebuilt = true; + } + mutex_unlock(&pdd->qpd.cwsr_lock); + } + } + srcu_read_unlock(&kfd_processes_srcu, idx); + mutex_unlock(&kfd_processes_mutex); + + /* The GPU must see the CPU writes to VRAM before queues are mapped */ + if (rebuilt) + amdgpu_device_flush_hdp(kfd->adev, NULL); +} + static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd) { struct kfd_node *dev = pdd->dev; @@ -1605,6 +1665,17 @@ static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd) else flags |= KFD_IOC_ALLOC_MEM_FLAGS_GTT; + /* + * The buffer is pinned, so it is not evicted and its contents are lost + * when VRAM loses power. Keep the device out of runtime suspend from + * here until the pdd is destroyed; system resume rebuilds the buffer. + */ + if (flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) { + ret = kfd_process_device_runtime_get(pdd); + if (ret) + return ret; + } + /* Allocate CWSR TBA/TMA buffers */ ret = kfd_process_alloc_gpuvm(pdd, qpd->cwsr_base, KFD_CWSR_TBA_TMA_SIZE, flags, &mem, &kaddr); @@ -1613,20 +1684,20 @@ static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd) qpd->cwsr_mem = mem; + mutex_lock(&qpd->cwsr_lock); + /* Set up iosys_map based on whether memory is MMIO or system memory */ if (mem->bo->kmap.bo_kmap_type & TTM_BO_MAP_IOMEM_MASK) iosys_map_set_vaddr_iomem(&qpd->cwsr_map, kaddr); else iosys_map_set_vaddr(&qpd->cwsr_map, kaddr); - qpd->tba_addr = qpd->cwsr_base; + qpd->trap_debug_flag = pdd->process->debug_trap_enabled; + kfd_process_device_fill_cwsr(pdd); - /* Copy CWSR ISA to buffer using appropriate accessor */ - iosys_map_memcpy_to(&qpd->cwsr_map, 0, dev->kfd->cwsr_isa, - dev->kfd->cwsr_isa_size); + mutex_unlock(&qpd->cwsr_lock); - kfd_process_set_trap_debug_flag(&pdd->qpd, - pdd->process->debug_trap_enabled); + qpd->tba_addr = qpd->cwsr_base; qpd->tma_addr = qpd->tba_addr + KFD_CWSR_TMA_OFFSET; pr_debug("set tba :0x%llx, tma:0x%llx, cwsr_map:%s at %p for pqm.\n", @@ -1642,21 +1713,31 @@ static void kfd_process_device_destroy_cwsr_dgpu(struct kfd_process_device *pdd) { struct kfd_node *dev = pdd->dev; struct qcm_process_device *qpd = &pdd->qpd; + struct iosys_map map; if (!dev->kfd->cwsr_enabled || iosys_map_is_null(&qpd->cwsr_map) || !qpd->cwsr_base) return; - kfd_process_free_gpuvm_map(qpd->cwsr_mem, pdd, &qpd->cwsr_map); + /* Hide the mapping from kfd_process_restore_cwsr() before it goes */ + mutex_lock(&qpd->cwsr_lock); + map = qpd->cwsr_map; + iosys_map_clear(&qpd->cwsr_map); + mutex_unlock(&qpd->cwsr_lock); + + kfd_process_free_gpuvm_map(qpd->cwsr_mem, pdd, &map); } void kfd_process_set_trap_handler(struct qcm_process_device *qpd, uint64_t tba_addr, uint64_t tma_addr) { + mutex_lock(&qpd->cwsr_lock); if (!iosys_map_is_null(&qpd->cwsr_map)) { /* KFD trap handler is bound, record as second-level TBA/TMA * in first-level TMA. First-level trap will jump to second. */ + qpd->tba2_addr = tba_addr; + qpd->tma2_addr = tma_addr; iosys_map_wr(&qpd->cwsr_map, KFD_CWSR_TMA_OFFSET, uint64_t, tba_addr); iosys_map_wr(&qpd->cwsr_map, KFD_CWSR_TMA_OFFSET + sizeof(uint64_t), @@ -1666,6 +1747,7 @@ void kfd_process_set_trap_handler(struct qcm_process_device *qpd, qpd->tba_addr = tba_addr; qpd->tma_addr = tma_addr; } + mutex_unlock(&qpd->cwsr_lock); } bool kfd_process_xnack_mode(struct kfd_process *p, bool supported) @@ -1726,11 +1808,14 @@ bool kfd_process_xnack_mode(struct kfd_process *p, bool supported) void kfd_process_set_trap_debug_flag(struct qcm_process_device *qpd, bool enabled) { + mutex_lock(&qpd->cwsr_lock); if (!iosys_map_is_null(&qpd->cwsr_map)) { + qpd->trap_debug_flag = enabled; iosys_map_wr(&qpd->cwsr_map, KFD_CWSR_TMA_OFFSET + 2 * sizeof(uint64_t), uint64_t, enabled); } + mutex_unlock(&qpd->cwsr_lock); } /* @@ -1915,6 +2000,7 @@ struct kfd_process_device *kfd_create_process_device_data(struct kfd_node *dev, pdd->bound = PDD_UNBOUND; pdd->already_dequeued = false; pdd->runtime_inuse = false; + mutex_init(&pdd->qpd.cwsr_lock); atomic64_set(&pdd->vram_usage, 0); pdd->sdma_past_activity_counter = 0; pdd->user_gpu_id = dev->id; -- 2.56.1