Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5BD6DC71136 for ; Mon, 16 Jun 2025 03:47:03 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 026A810E275; Mon, 16 Jun 2025 03:47:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="xMvrxsZY"; dkim-atps=neutral Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2089.outbound.protection.outlook.com [40.107.101.89]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B02210E267 for ; Mon, 16 Jun 2025 03:47:01 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M+aHIVzbgFYghz4LsnXLDOCjgFG/7lNbK9JNng9k8IJiMsotWEcCnZTqNS3oAM13de4wuzDxemT4YcFM508SLckjilrez+emUj4vkFr84YqD9Oo6J9AGHyS2rCACiUdhf7Os2nOzPSfwUSUz731Pz/Ly6lwtznqRXWsoL9E+QdZbJQFTMRtG3/hyRjnmE6diLAv/1ntWNrroAg3CSYME02uaZWwfvJ2VUNqOAJvsBAYdMJ5levTTsC/wxVPLNyy0qItcGgEp11XZXzMdV03GAPew5GNlmwvZbWuF66AAR45kFA/cwS2e79bnR9Zm0GtDJV1tiwFkc2/Itt43VJpP5w== 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=9DxLSHJVsBEngxlhEHS8f+kBgrg/gq5YAsQUp4ntZ6U=; b=TUOK9wR5G6eMAr6OGtV5VHe71qgUjnTjUAleC6fyq5ys9eAhjLyno5muWD+ryOpivCcR2zjf6IpSfDU/qAbIdgWJhYTYE6MIV5LX5B9F3fU+BRnJj6z0EeIWTPfH6ODF9dbLIe3N+LGGu0g1jhcyryjit8o2GcXg4Bz2azuFycKJYo8WBL6iqqmAiMJcQ6xzn6eHaP6fUo8x89C/9IMOkJxHHMzy7tcHY/Z32zZJp/5sHbzdTPK4nwMMH0eJ5S3xEzp95PzEidVHuiMnNqaa3dJylQ/lUpyZGvrW6u5ykS24SxrJlqt0egnUgJM3bvCPkrA2Rk+axm+HJhtFiqwh5w== 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=9DxLSHJVsBEngxlhEHS8f+kBgrg/gq5YAsQUp4ntZ6U=; b=xMvrxsZY07eDRxmhbN5cOmabrVOZKMLbo8qoVbVMCHlGiR2ZMXKATXl6fSwJ/ZiqmW3SBwHRRs3QZ30wl6v1naa6DDC/VT7L2zvo2QkKZnUXayQ494S6buY6Fn8/wHZAi8yp1sy9k9ra2DX4lHEOVIoiOejPAGb4Pgo9TjslsPY= Received: from BL1PR13CA0008.namprd13.prod.outlook.com (2603:10b6:208:256::13) by CH3PR12MB8353.namprd12.prod.outlook.com (2603:10b6:610:12c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8835.23; Mon, 16 Jun 2025 03:46:57 +0000 Received: from BL02EPF0001A0FC.namprd03.prod.outlook.com (2603:10b6:208:256:cafe::37) by BL1PR13CA0008.outlook.office365.com (2603:10b6:208:256::13) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8835.23 via Frontend Transport; Mon, 16 Jun 2025 03:46:57 +0000 X-MS-Exchange-Authentication-Results: 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=SATLEXMB03.amd.com; pr=C Received: from SATLEXMB03.amd.com (165.204.84.17) by BL02EPF0001A0FC.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8835.15 via Frontend Transport; Mon, 16 Jun 2025 03:46:57 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Sun, 15 Jun 2025 22:46:56 -0500 Received: from JesseDEV.guestwireless.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Sun, 15 Jun 2025 22:46:50 -0500 From: Jesse.Zhang To: CC: , Christian Koenig , Alex Deucher , Jesse Zhang Subject: [v2 9/9] drm/amdgpu: implements detect and reset Date: Mon, 16 Jun 2025 11:43:42 +0800 Message-ID: <20250616034605.2683434-9-Jesse.Zhang@amd.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250616034605.2683434-1-Jesse.Zhang@amd.com> References: <20250616034605.2683434-1-Jesse.Zhang@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Received-SPF: None (SATLEXMB03.amd.com: Jesse.Zhang@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A0FC:EE_|CH3PR12MB8353:EE_ X-MS-Office365-Filtering-Correlation-Id: 63d111ed-1c36-4fc8-3bd7-08ddac887141 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|82310400026|1800799024|36860700013|376014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?8Zpqn6hoQCXzbYbuYORHpDLkj90j8zSqx1ZgEHfn9mxXU6Z05bwswT152tHh?= =?us-ascii?Q?K0EfU9rbZiFSaQkZ822bPUgEjZAqnm/L5nKE7fWi8xGNXnupxlO2hQYevTsB?= =?us-ascii?Q?smYRDxk48fr2zOH8TftokNP5GB6yAfcXPLs269iSvbKH23hzN4ksSM2NXrPR?= =?us-ascii?Q?DhAOrBloy4QJmRdn6tny1zgRTRBKAqbYyIvFM8Rw4tta4+BhhexE1jTujNoU?= =?us-ascii?Q?9z8CUJy6cjOh02BqfY+b1mcO4lHHn5L3Fc/BB6/BG/xF+sNeI0NNC2Wre/W/?= =?us-ascii?Q?O+7FAi3HB/Sfnn73gA1/hg6tlVEvBkNmI9i0EHU2UvIDcQnUPlVjgUWR0pK1?= =?us-ascii?Q?d59KWW5/SpXBuA/0py1KLBwm1Wb7Q+/VFBlj3Z/IJYOqUGVqfCPLxMzs885q?= =?us-ascii?Q?sGL2IjIuKsJDg08J1KcwDmYRkQ1KDJONJ2ORBk+0wNs96NCks+fkHDREgCkr?= =?us-ascii?Q?Mf8KNBMYt4vFEM6DF+3tulMstfrV+9P6uC+ocs+1UL88M06JqhR5dD64iph1?= =?us-ascii?Q?FFnA/Cq66g0BX9v3UlegrjEuBoeinDIVq5/z6wyG/XVfw+rShqY0kpx2M4Jd?= =?us-ascii?Q?UqyO++thded8A1KzfYVcFTW2t0DilK10qGBCBUSAvaNSPyWGycvyKbDix3KF?= =?us-ascii?Q?w6H3tYS5KpJledIlLlXv49rhJq6d+7ijeEI8oelLBKOqTW31xX19NYMwyXJo?= =?us-ascii?Q?IN92qbzYCKcgrcbMjCs0IDpUa8Rs6EWrpp663aOeL0K/B2GlUhVtcdL0LzGw?= =?us-ascii?Q?EanVAD5hpndoElYpw4hqT3jwWDXNLtme9PdkSglzkeocbOVqBf4SOMiujfqz?= =?us-ascii?Q?qu6KaQkKzQ45GS+fPArvAk6zYECw/tTmuGvSWOXeOh2+QHQ8F4iPd26Q1EU2?= =?us-ascii?Q?sehXG2J6/gGTjmzwhX6iX+Vokt9tfuWWVdCNJa2TnCNkYZjJbfhEav6ruts2?= =?us-ascii?Q?9rkAkWzaTPdnIMu+0uy4hFUBZCy+65ZG5C+tr5lM+PngWQ9Z2txBr/ruVnFO?= =?us-ascii?Q?GgawYA+0wBiLrUC981/8ariE/M6dgBet8cZKvmzgcN1g8RdjVkqvKV1lZySO?= =?us-ascii?Q?IepRiTEadhfllaX+KhrDAK/KDNhErmhislwxNuxe9OcJ6gqeYK5CY7L4b4b2?= =?us-ascii?Q?j/xDetw1d0A4YM8ET7GBnEblXvLuNpkJcYK72dvSUKX+/JQHMzHyhlEi2BKq?= =?us-ascii?Q?LVcYHJd2uUCZ1YyuSXwYTAL04whQmD9hnvQG3m5EDd/aFk5HMdCImb7YAT+u?= =?us-ascii?Q?ZYsfLuOPX/ZIyannSMORgSoa8qyaB9wMTpcDBSwxiqKXmpVT43r708eGgCbx?= =?us-ascii?Q?3CoAevFx+4YNrg5xaT0BcWnmOcQaU8L1lLJbJOO0wZyU3zEUQPYtN7L1m7e2?= =?us-ascii?Q?ZqGF9CuyKWxmqAoWCUrQpE2aW3n3Z3BggJ92b1/tc+nRtsPlEQtmoBzQPbPQ?= =?us-ascii?Q?zii71VrHktm5rVEw/81i6f9RZBtcrcWnSK/GWjNvyZiUq58M5FSBqHTgErwY?= =?us-ascii?Q?Iur8V5TlWr/F+BhVRxruH9xGtU6RIuEwUNcw?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:SATLEXMB03.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(82310400026)(1800799024)(36860700013)(376014); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jun 2025 03:46:57.1671 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 63d111ed-1c36-4fc8-3bd7-08ddac887141 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=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A0FC.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8353 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Alex Deucher before unmap, attempt to detect and reset the hang queue. If that fails, schedule a GPU reset. Signed-off-by: Alex Deucher Signed-off-by: Jesse Zhang --- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 8 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 128 +++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 5 + 4 files changed, 131 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index 5e2f086d2c99..f1e520b81eae 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1304,6 +1304,7 @@ struct amdgpu_device { struct list_head userq_mgr_list; struct mutex userq_mutex; bool userq_halt_for_enforce_isolation; + struct work_struct userq_reset_work; }; static inline uint32_t amdgpu_ip_version(const struct amdgpu_device *adev, diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index 00174437b01e..6eae2dc2080b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -4432,6 +4432,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, } INIT_WORK(&adev->xgmi_reset_work, amdgpu_device_xgmi_reset_func); + INIT_WORK(&adev->userq_reset_work, amdgpu_userq_reset_work); adev->gfx.gfx_off_req_count = 1; adev->gfx.gfx_off_residency = 0; @@ -5828,6 +5829,10 @@ int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context) if (r) goto out; + r = amdgpu_userq_post_reset(tmp_adev, vram_lost); + if (r) + goto out; + drm_client_dev_resume(adev_to_drm(tmp_adev), false); /* @@ -6050,6 +6055,7 @@ static inline void amdgpu_device_stop_pending_resets(struct amdgpu_device *adev) if (!amdgpu_sriov_vf(adev)) cancel_work(&adev->reset_work); #endif + cancel_work(&adev->userq_reset_work); if (adev->kfd.dev) cancel_work(&adev->kfd.reset_work); @@ -6160,6 +6166,8 @@ static int amdgpu_device_halt_activities(struct amdgpu_device *adev, amdgpu_device_ip_need_full_reset(tmp_adev)) amdgpu_ras_suspend(tmp_adev); + amdgpu_userq_pre_reset(tmp_adev); + for (i = 0; i < AMDGPU_MAX_RINGS; ++i) { struct amdgpu_ring *ring = tmp_adev->rings[i]; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c index 295e7186e156..5a7c933adae7 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c @@ -26,7 +26,10 @@ #include #include +#include + #include "amdgpu.h" +#include "amdgpu_reset.h" #include "amdgpu_vm.h" #include "amdgpu_userq.h" #include "amdgpu_userq_fence.h" @@ -44,6 +47,39 @@ u32 amdgpu_userq_get_supported_ip_mask(struct amdgpu_device *adev) return userq_ip_mask; } +static void amdgpu_userq_gpu_reset(struct amdgpu_device *adev) +{ + + if (amdgpu_device_should_recover_gpu(adev)) + amdgpu_reset_domain_schedule(adev->reset_domain, + &adev->userq_reset_work); +} + +static bool +amdgpu_userq_detect_and_reset_queues(struct amdgpu_userq_mgr *uq_mgr) +{ + struct amdgpu_device *adev = uq_mgr->adev; + const struct amdgpu_userq_funcs *userq_gfx_funcs = + adev->userq_funcs[AMDGPU_RING_TYPE_GFX]; + + if (!!idr_is_empty(&uq_mgr->userq_idr)) + return false; + + if (unlikely(adev->debug_disable_gpu_ring_reset)) { + dev_err(adev->dev, "userq reset disabled by debug mask\n"); + } else if (amdgpu_gpu_recovery) { + if (userq_gfx_funcs->detect_and_reset) { + if (userq_gfx_funcs->detect_and_reset(adev, AMDGPU_RING_TYPE_GFX)) { + amdgpu_userq_gpu_reset(adev); + return true; + } + } + //TODO: support compute user queue detect and reset. + } + + return false; +} + static int amdgpu_userq_unmap_helper(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue) @@ -51,15 +87,22 @@ amdgpu_userq_unmap_helper(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_device *adev = uq_mgr->adev; const struct amdgpu_userq_funcs *userq_funcs = adev->userq_funcs[queue->queue_type]; + bool gpu_reset = false; int r = 0; if (queue->state == AMDGPU_USERQ_STATE_MAPPED) { r = userq_funcs->unmap(uq_mgr, queue); - if (r) + if (r) { queue->state = AMDGPU_USERQ_STATE_HUNG; - else + gpu_reset = true; + } else { queue->state = AMDGPU_USERQ_STATE_UNMAPPED; + } } + + if (gpu_reset) + amdgpu_userq_gpu_reset(adev); + return r; } @@ -70,16 +113,22 @@ amdgpu_userq_map_helper(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_device *adev = uq_mgr->adev; const struct amdgpu_userq_funcs *userq_funcs = adev->userq_funcs[queue->queue_type]; + bool gpu_reset = false; int r = 0; if (queue->state == AMDGPU_USERQ_STATE_UNMAPPED) { r = userq_funcs->map(uq_mgr, queue); if (r) { queue->state = AMDGPU_USERQ_STATE_HUNG; + gpu_reset = true; } else { queue->state = AMDGPU_USERQ_STATE_MAPPED; } } + + if (gpu_reset) + amdgpu_userq_gpu_reset(adev); + return r; } @@ -318,6 +367,7 @@ amdgpu_userq_destroy(struct drm_file *filp, int queue_id) amdgpu_bo_unreserve(queue->db_obj.obj); } amdgpu_bo_unref(&queue->db_obj.obj); + amdgpu_userq_detect_and_reset_queues(uq_mgr); r = amdgpu_userq_unmap_helper(uq_mgr, queue); amdgpu_userq_cleanup(uq_mgr, queue, queue_id); mutex_unlock(&uq_mgr->userq_mutex); @@ -691,6 +741,7 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) int queue_id; int ret = 0, r; + amdgpu_userq_detect_and_reset_queues(uq_mgr); /* Try to unmap all the queues in this process ctx */ idr_for_each_entry(&uq_mgr->userq_idr, queue, queue_id) { r = amdgpu_userq_unmap_helper(uq_mgr, queue); @@ -703,6 +754,23 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) return ret; } +void amdgpu_userq_reset_work(struct work_struct *work) +{ + struct amdgpu_device *adev = container_of(work, struct amdgpu_device, + userq_reset_work); + struct amdgpu_reset_context reset_context; + + memset(&reset_context, 0, sizeof(reset_context)); + + reset_context.method = AMD_RESET_METHOD_NONE; + reset_context.reset_req_dev = adev; + reset_context.src = AMDGPU_RESET_SRC_USERQ; + set_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags); + /*set_bit(AMDGPU_SKIP_COREDUMP, &reset_context.flags);*/ + + amdgpu_device_gpu_recover(adev, NULL, &reset_context); +} + static int amdgpu_userq_wait_for_signal(struct amdgpu_userq_mgr *uq_mgr) { @@ -729,22 +797,19 @@ void amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_eviction_fence *ev_fence) { - int ret; struct amdgpu_fpriv *fpriv = uq_mgr_to_fpriv(uq_mgr); struct amdgpu_eviction_fence_mgr *evf_mgr = &fpriv->evf_mgr; + struct amdgpu_device *adev = uq_mgr->adev; + int ret; /* Wait for any pending userqueue fence work to finish */ ret = amdgpu_userq_wait_for_signal(uq_mgr); - if (ret) { - drm_file_err(uq_mgr->file, "Not evicting userqueue, timeout waiting for work\n"); - return; - } + if (ret) + dev_err(adev->dev, "Not evicting userqueue, timeout waiting for work\n"); ret = amdgpu_userq_evict_all(uq_mgr); - if (ret) { - drm_file_err(uq_mgr->file, "Failed to evict userqueue\n"); - return; - } + if (ret) + dev_err(adev->dev, "Failed to evict userqueue\n"); /* Signal current eviction fence */ amdgpu_eviction_fence_signal(evf_mgr, ev_fence); @@ -785,6 +850,7 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr) mutex_lock(&adev->userq_mutex); mutex_lock(&userq_mgr->userq_mutex); + amdgpu_userq_detect_and_reset_queues(userq_mgr); idr_for_each_entry(&userq_mgr->userq_idr, queue, queue_id) { amdgpu_userq_wait_for_last_fence(userq_mgr, queue); amdgpu_userq_unmap_helper(userq_mgr, queue); @@ -818,6 +884,7 @@ int amdgpu_userq_suspend(struct amdgpu_device *adev) list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) { cancel_delayed_work_sync(&uqm->resume_work); mutex_lock(&uqm->userq_mutex); + amdgpu_userq_detect_and_reset_queues(uqm); idr_for_each_entry(&uqm->userq_idr, queue, queue_id) { r = amdgpu_userq_unmap_helper(uqm, queue); if (r) @@ -874,6 +941,7 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev, list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) { cancel_delayed_work_sync(&uqm->resume_work); mutex_lock(&uqm->userq_mutex); + amdgpu_userq_detect_and_reset_queues(uqm); idr_for_each_entry(&uqm->userq_idr, queue, queue_id) { if (((queue->queue_type == AMDGPU_HW_IP_GFX) || (queue->queue_type == AMDGPU_HW_IP_COMPUTE)) && @@ -922,3 +990,41 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev, mutex_unlock(&adev->userq_mutex); return ret; } + +void amdgpu_userq_pre_reset(struct amdgpu_device *adev) +{ + const struct amdgpu_userq_funcs *userq_funcs; + struct amdgpu_usermode_queue *queue; + struct amdgpu_userq_mgr *uqm, *tmp; + int queue_id; + + mutex_lock(&adev->userq_mutex); + list_for_each_entry_safe(uqm, tmp, &adev->userq_mgr_list, list) { + cancel_delayed_work_sync(&uqm->resume_work); + mutex_lock(&uqm->userq_mutex); + idr_for_each_entry(&uqm->userq_idr, queue, queue_id) { + if (queue->state == AMDGPU_USERQ_STATE_MAPPED) { + amdgpu_userq_wait_for_last_fence(uqm, queue); + userq_funcs = adev->userq_funcs[queue->queue_type]; + userq_funcs->unmap(uqm, queue); + /* just mark all queues as hung at this point. + * if unmap succeeds, we could map again + * in amdgpu_userq_post_reset() if vram is not lost + */ + queue->state = AMDGPU_USERQ_STATE_HUNG; + amdgpu_userq_fence_driver_force_completion(queue); + } + } + mutex_unlock(&uqm->userq_mutex); + } + mutex_unlock(&adev->userq_mutex); +} + +int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost) +{ + /* if any queue state is AMDGPU_USERQ_STATE_UNMAPPED + * at this point, we should be able to map it again + * and continue if vram is not lost. + */ + return 0; +} diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h index 0335ff03f65f..649ec25f4deb 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h @@ -135,4 +135,9 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev, int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev, u32 idx); +void amdgpu_userq_reset_work(struct work_struct *work); + +void amdgpu_userq_pre_reset(struct amdgpu_device *adev); +int amdgpu_userq_post_reset(struct amdgpu_device *adev, bool vram_lost); + #endif -- 2.49.0