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 C2057CAC5A7 for ; Mon, 22 Sep 2025 09:47:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 585B210E3B6; Mon, 22 Sep 2025 09:47:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="KXCd0F8V"; dkim-atps=neutral Received: from BN1PR04CU002.outbound.protection.outlook.com (mail-eastus2azon11010013.outbound.protection.outlook.com [52.101.56.13]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3FA1D10E3B6 for ; Mon, 22 Sep 2025 09:47:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Hgsw+HR3qfIFAy4o1eQrl9R8Y0gWRxAgwlGyZedMC3zFz9dLABPqRQLFM7SgtSJx62n7pkwkXkuMliGXRCRZu+2F2ThimlG85JyqM0KbAGTFIDormbYa55eByrCyHyYxGn6UYerWD5uLR+2JOazV0qfq/gBvRAiRQE6H7U9eNAdkCuoQe/v+lpxb32Rn3teZ/fv7IbjKTDxUxY0U9gXRgf8vLOMsHnTiBr5UHsZkg8GNZT5sYLSHmbNe+05C4lVbGu6KUfVxtHFCQFjCn5pp24Fx3AjDQ10M14ifmS7LVVGWyxtcoO2AG/2CosuwMJhG5fZ5hzRtUvxD+hnRpSwaHg== 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=rZlHdOARrem394lc/ccqZmW+v7jREOtRBYU68dNCqiI=; b=nlwMl7alAsfc6WSvsWbRu4o6anpcVO4cEYtMVlh7Tm7sCJnkSSoJmGeyWAUBHsmc5UCefZu2e6hhsnAYARl6l8vbQkEUI9VhKc0Hna/b/l74sOfnhdOcvADojIom/0KOxWKg8XnR6i+dL+E7InDvHFvEMClKISP8bmPHzma0ZnCnbETxwyapFsBkOQQv+u7vreCha4uXVppkKmKga6lr7fT70ZT078rx3FanC8J2L/vR0KeHWeMt4XMF5zNj955YeczzlOZ1ZIS4YY8RZV29ek3UMHgO3bBxEVUURaAoIeXJTr257M+M7YAkLyBNzBW2+anH99iv4GQ4m2JoV5Lr2Q== 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=rZlHdOARrem394lc/ccqZmW+v7jREOtRBYU68dNCqiI=; b=KXCd0F8VDwgDnr4r43AjOW0W554q8W3N+C/thi55jfadrLCkXiz56DxamBJz+sqpSkZrNeDUIylDmuVR6jgueKQd8ta1vc6qXpi0xdJNKPzK+LAxM33CRXG7zNSWcCVoQAGl1TfFcaG4jK0jk7FSaL1YPGX/Zvs01Coei7TfrsQ= Received: from CH2PR07CA0026.namprd07.prod.outlook.com (2603:10b6:610:20::39) by LV8PR12MB9407.namprd12.prod.outlook.com (2603:10b6:408:1f9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.20; Mon, 22 Sep 2025 09:47:35 +0000 Received: from DS3PEPF0000C37A.namprd04.prod.outlook.com (2603:10b6:610:20:cafe::51) by CH2PR07CA0026.outlook.office365.com (2603:10b6:610:20::39) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.9137.20 via Frontend Transport; Mon, 22 Sep 2025 09:47:35 +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=satlexmb07.amd.com; pr=C Received: from satlexmb07.amd.com (165.204.84.17) by DS3PEPF0000C37A.mail.protection.outlook.com (10.167.23.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9137.12 via Frontend Transport; Mon, 22 Sep 2025 09:47:34 +0000 Received: from satlexmb10.amd.com (10.181.42.219) 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.17; Mon, 22 Sep 2025 02:47:34 -0700 Received: from satlexmb08.amd.com (10.181.42.217) by satlexmb10.amd.com (10.181.42.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.17; Mon, 22 Sep 2025 02:47:34 -0700 Received: from JesseDEV.guestwireless.amd.com (10.180.168.240) by satlexmb08.amd.com (10.181.42.217) with Microsoft SMTP Server id 15.2.2562.17 via Frontend Transport; Mon, 22 Sep 2025 02:47:27 -0700 From: Jesse.Zhang To: CC: , Christian Koenig , Jesse.Zhang , Alex Deucher Subject: [v5 2/2] drm/amdgpu: Implement user queue reset functionality Date: Mon, 22 Sep 2025 17:47:18 +0800 Message-ID: <20250922094725.1971669-2-Jesse.Zhang@amd.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250922094725.1971669-1-Jesse.Zhang@amd.com> References: <20250922094725.1971669-1-Jesse.Zhang@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF0000C37A:EE_|LV8PR12MB9407:EE_ X-MS-Office365-Filtering-Correlation-Id: ad38701f-eb2f-4a24-4043-08ddf9bd0ecc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|82310400026|36860700013|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?mBmnUe7oeF0es4Lis9FkoSQLU+WGCCuHnTHwif/ZoKyEFYxgnm/uHOQllVI5?= =?us-ascii?Q?Id5RYw/r3fqdliySgpCPbKSZ80w+NQLXednpPXyk/W35UYtG70zpkAR9sNTY?= =?us-ascii?Q?PEaP+oGnRuObMhi6++X8UHjuUg25QT4/uFuVmo8DxkQzN2nKNfeXagb9i7VO?= =?us-ascii?Q?7VnJ/zUsAp6WpXqq63xKxzvtlkHt5Dak6/WiNvO1GBC/QuVYNWAWrrD1BBOt?= =?us-ascii?Q?j/d7EU1iRnLMeSIOu7m7CgzGTn9J9cAiXn5gtZjyBWKa/4nHwaJNKttoPSeO?= =?us-ascii?Q?k0nSpMYkMatUw/gIJnFaCLON5ylF+SQCcaV2d+Fc+nsIgr/eMP7TC4Me/WBj?= =?us-ascii?Q?il6oK0H9eL0APJWHwIPItnREXLnUYH6hOfVLdRCxbCt7qURviB6ji74/atZN?= =?us-ascii?Q?6NApAsdMpMDVjURH9hsLR670mrW9pHOcgaIzRJc60nY1h9THqW6otscd9Cip?= =?us-ascii?Q?kab3QyQoB8hIR1M+qUnJOpnzdVAROltdi2zi+hVXCcv58Sax77pRisJIFQ92?= =?us-ascii?Q?0AoqAsg7txkUTKGi/Cj7MHynfAgQRz/HslTZa84iK99QfoqIvHA9NfEXzCRd?= =?us-ascii?Q?lDX0AfSBbS9/PkghSL7E204wFlgkJNe27+e2jP/aGvPdLoBomkJ8/rdX7ibl?= =?us-ascii?Q?iK22wBeztE8hRRU2PSNFu1a/Xz+Wl5Xubl0nuPMep3MN9Fczhxa1ojdBzit7?= =?us-ascii?Q?o4fCLSq0Ut31Vy8UZKkltvDKAJcw6RwfREDeyJ7wwHKCaA5HH8O5H1hqFJ98?= =?us-ascii?Q?cpfZxZPCHGovlmHtGOabuDBAVCIi8tq1c/Y0BaZ8+REz/LoWotVD0GUGX2oV?= =?us-ascii?Q?vtUhi9VjQKtMO5G1IdI/0r2BPhJ+vaZhZEs/Nv0lJQma5GX6I+SRR/YcWl2N?= =?us-ascii?Q?qCkJWOYT96wUhU9Px71iPYPI5MAVze6yMwznG+rysSmHseLbuwHui3Oyvjfk?= =?us-ascii?Q?DAj6a4rSifs/8JiUXWuQ7ePOZ3B4MxdgD56jLWIRplLOHeTfDsmxdxIYVNbT?= =?us-ascii?Q?beiH5lIPD2UuDwG5NcTIZbCKxsxZi7wC5JHNCoinsQ2DVSaYACXAG8+O7O/V?= =?us-ascii?Q?BkmHNNge31isMfZon3+5ImmazJ5U7heLxP1ToEECDreeO//aks3XoxK1MYDW?= =?us-ascii?Q?fDT569/6ykOugWD4WLzKukqbhtFn5qS1wN8m5lpDlhFkVEGOJK3W3SjpI+p+?= =?us-ascii?Q?Q4HHGt/IGtA0ZhgFegmd6aGxTO6QoHzWfteJEFUpZwiaQs9giBOzj94l/MK1?= =?us-ascii?Q?UCdBD18U4PO7DDpKueWklAXwgnf7RfbP0jn2bmZhhaMk1r8GyFXLUvSYduzz?= =?us-ascii?Q?EgOP1+dLC80JN4NQT5dG8zSRDB+Mbaug4yW+1irkzZrYuFxJNDB3pBER9dXV?= =?us-ascii?Q?SCokHEpJtIagsBvsuMOtn7HXZn15F6yCNN8chRbjWBTh3VH4Pt9ukPze7C8o?= =?us-ascii?Q?PDTa6HPFx9M3dKR7xfHRqsKI7l0fRWEaCD5nX1l2dtAQBtLrHVJktxyXiMGz?= =?us-ascii?Q?IQjHdHYIweEs4QuUNVFDzAOIj8pNr1FET2HM?= X-Forefront-Antispam-Report: CIP:165.204.84.17; CTRY:US; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:satlexmb07.amd.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230040)(376014)(82310400026)(36860700013)(1800799024); DIR:OUT; SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2025 09:47:34.8076 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ad38701f-eb2f-4a24-4043-08ddf9bd0ecc 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: DS3PEPF0000C37A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV8PR12MB9407 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" This patch adds robust reset handling for user queues (userq) to improve recovery from queue failures. The key components include: 1. Queue detection and reset logic: - amdgpu_userq_detect_and_reset_queues() identifies failed queues - Per-IP detect_and_reset callbacks for targeted recovery - Falls back to full GPU reset when needed 2. Reset infrastructure: - Adds userq_reset_work workqueue for async reset handling - Implements pre/post reset handlers for queue state management - Integrates with existing GPU reset framework 3. Error handling improvements: - Enhanced state tracking with HUNG state - Automatic reset triggering on critical failures - VRAM loss handling during recovery 4. Integration points: - Added to device init/reset paths - Called during queue destroy, suspend, and isolation events - Handles both individual queue and full GPU resets The reset functionality works with both gfx/compute and sdma queues, providing better resilience against queue failures while minimizing disruption to unaffected queues. v2: add detection and reset calls when preemption/unmaped fails. add a per device userq counter for each user queue type.(Alex) v3: make sure we hold the adev->userq_mutex when we call amdgpu_userq_detect_and_reset_queues. (Alex) warn if the adev->userq_mutex is not held. v4: make sure we have all of the uqm->userq_mutex held. warn if the uqm->userq_mutex is not held. v5: Use array for user queue type counters.(Alex) all of the uqm->userq_mutex need to be held when calling detect and reset. (Alex) 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_ring.h | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c | 188 +++++++++++++++++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h | 5 + 5 files changed, 191 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h index ae10832a09f4..6f98428a6022 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h @@ -1315,6 +1315,7 @@ struct amdgpu_device { bool apu_prefer_gtt; bool userq_halt_for_enforce_isolation; + struct work_struct userq_reset_work; struct amdgpu_uid *uid_info; /* KFD diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index e066f7ff2a82..448decf07a24 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -4533,6 +4533,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; @@ -5954,6 +5955,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); /* @@ -6176,6 +6181,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); @@ -6296,6 +6302,8 @@ static void 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_ring.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h index b6b649179776..aba76ccc60a5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h @@ -83,6 +83,7 @@ enum amdgpu_ring_type { AMDGPU_RING_TYPE_MES, AMDGPU_RING_TYPE_UMSCH_MM, AMDGPU_RING_TYPE_CPER, + AMDGPU_RING_TYPE_MAX, }; enum amdgpu_ib_pool_type { diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c index a4fe422553db..6b83f5985ee3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c @@ -25,8 +25,10 @@ #include #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 +46,67 @@ 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); + /* Wait for the reset job to complete */ + flush_work(&adev->userq_reset_work); + } +} + +static int +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]; + const struct amdgpu_userq_funcs *userq_compute_funcs = + adev->userq_funcs[AMDGPU_RING_TYPE_COMPUTE]; + const struct amdgpu_userq_funcs *userq_sdma_funcs = + adev->userq_funcs[AMDGPU_RING_TYPE_SDMA]; + bool gpu_reset = false; + int r = 0; + + /* warning if current process mutex is not held */ + WARN_ON(!mutex_is_locked(&uq_mgr->userq_mutex)); + + 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 ((atomic_read(&uq_mgr->userq_count[AMDGPU_RING_TYPE_COMPUTE]) > 0) && userq_compute_funcs->detect_and_reset) { + r = userq_compute_funcs->detect_and_reset(adev, AMDGPU_RING_TYPE_COMPUTE); + if (r) { + gpu_reset = true; + goto gpu_reset; + } + } + + if ((atomic_read(&uq_mgr->userq_count[AMDGPU_RING_TYPE_GFX]) > 0) && userq_gfx_funcs->detect_and_reset) { + r = userq_gfx_funcs->detect_and_reset(adev, AMDGPU_RING_TYPE_GFX); + if (r) { + gpu_reset = true; + goto gpu_reset; + } + } + + if ((atomic_read(&uq_mgr->userq_count[AMDGPU_RING_TYPE_SDMA]) > 0) && userq_sdma_funcs->detect_and_reset) { + r = userq_sdma_funcs->detect_and_reset(adev, AMDGPU_RING_TYPE_SDMA); + if (r) { + gpu_reset = true; + goto gpu_reset; + } + } + } + +gpu_reset: + if (gpu_reset) + amdgpu_userq_gpu_reset(adev); + + return r; +} + int amdgpu_userq_input_va_validate(struct amdgpu_vm *vm, u64 addr, u64 expected_size) { @@ -83,17 +146,22 @@ amdgpu_userq_preempt_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 found_hung_queue = false; int r = 0; if (queue->state == AMDGPU_USERQ_STATE_MAPPED) { r = userq_funcs->preempt(uq_mgr, queue); if (r) { queue->state = AMDGPU_USERQ_STATE_HUNG; + found_hung_queue = true; } else { queue->state = AMDGPU_USERQ_STATE_PREEMPTED; } } + if (found_hung_queue) + amdgpu_userq_detect_and_reset_queues(uq_mgr); + return r; } @@ -125,16 +193,23 @@ 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 found_hung_queue = false; int r = 0; if ((queue->state == AMDGPU_USERQ_STATE_MAPPED) || (queue->state == AMDGPU_USERQ_STATE_PREEMPTED)) { r = userq_funcs->unmap(uq_mgr, queue); - if (r) + if (r) { queue->state = AMDGPU_USERQ_STATE_HUNG; - else + found_hung_queue = true; + } else { queue->state = AMDGPU_USERQ_STATE_UNMAPPED; + } } + + if (found_hung_queue) + amdgpu_userq_detect_and_reset_queues(uq_mgr); + return r; } @@ -145,16 +220,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; } @@ -386,10 +467,11 @@ amdgpu_userq_destroy(struct drm_file *filp, int queue_id) amdgpu_bo_unreserve(queue->db_obj.obj); } amdgpu_bo_unref(&queue->db_obj.obj); - + atomic_dec(&uq_mgr->userq_count[queue->queue_type]); #if defined(CONFIG_DEBUG_FS) debugfs_remove_recursive(queue->debugfs_queue); #endif + amdgpu_userq_detect_and_reset_queues(uq_mgr); r = amdgpu_userq_unmap_helper(uq_mgr, queue); /*TODO: It requires a reset for userq hw unmap error*/ if (unlikely(r != AMDGPU_USERQ_STATE_UNMAPPED)) { @@ -606,6 +688,7 @@ amdgpu_userq_create(struct drm_file *filp, union drm_amdgpu_userq *args) kfree(queue_name); args->out.queue_id = qid; + atomic_inc(&uq_mgr->userq_count[queue->queue_type]); unlock: mutex_unlock(&uq_mgr->userq_mutex); @@ -866,6 +949,7 @@ amdgpu_userq_evict_all(struct amdgpu_userq_mgr *uq_mgr) unsigned long queue_id; int ret = 0, r; + amdgpu_userq_detect_and_reset_queues(uq_mgr); /* Try to unmap all the queues in this process ctx */ xa_for_each(&uq_mgr->userq_mgr_xa, queue_id, queue) { r = amdgpu_userq_preempt_helper(uq_mgr, queue); @@ -878,6 +962,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) { @@ -905,22 +1006,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); @@ -937,11 +1035,18 @@ amdgpu_userq_evict(struct amdgpu_userq_mgr *uq_mgr, int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct drm_file *file_priv, struct amdgpu_device *adev) { + int i; + mutex_init(&userq_mgr->userq_mutex); xa_init_flags(&userq_mgr->userq_mgr_xa, XA_FLAGS_ALLOC); userq_mgr->adev = adev; userq_mgr->file = file_priv; + /* Initialize all queue type counters to zero */ + for (i = 0; i < AMDGPU_RING_TYPE_MAX; i++) { + atomic_set(&userq_mgr->userq_count[i], 0); + } + INIT_DELAYED_WORK(&userq_mgr->resume_work, amdgpu_userq_restore_worker); return 0; } @@ -954,6 +1059,7 @@ void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr) cancel_delayed_work_sync(&userq_mgr->resume_work); mutex_lock(&userq_mgr->userq_mutex); + amdgpu_userq_detect_and_reset_queues(userq_mgr); xa_for_each(&userq_mgr->userq_mgr_xa, queue_id, queue) { amdgpu_userq_wait_for_last_fence(userq_mgr, queue); amdgpu_userq_unmap_helper(userq_mgr, queue); @@ -980,6 +1086,7 @@ int amdgpu_userq_suspend(struct amdgpu_device *adev) uqm = queue->userq_mgr; cancel_delayed_work_sync(&uqm->resume_work); mutex_lock(&uqm->userq_mutex); + amdgpu_userq_detect_and_reset_queues(uqm); r = amdgpu_userq_unmap_helper(uqm, queue); if (r) ret = r; @@ -1032,6 +1139,7 @@ int amdgpu_userq_stop_sched_for_enforce_isolation(struct amdgpu_device *adev, cancel_delayed_work_sync(&uqm->resume_work); uqm = queue->userq_mgr; mutex_lock(&uqm->userq_mutex); + amdgpu_userq_detect_and_reset_queues(uqm); if (((queue->queue_type == AMDGPU_HW_IP_GFX) || (queue->queue_type == AMDGPU_HW_IP_COMPUTE)) && (queue->xcp_id == idx)) { @@ -1076,3 +1184,59 @@ int amdgpu_userq_start_sched_for_enforce_isolation(struct amdgpu_device *adev, 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; + unsigned long queue_id; + + xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) { + uqm = queue->userq_mgr; + cancel_delayed_work_sync(&uqm->resume_work); + 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); + } + } +} + +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. + */ + struct amdgpu_userq_mgr *uqm; + struct amdgpu_usermode_queue *queue; + const struct amdgpu_userq_funcs *userq_funcs; + unsigned long queue_id; + int r = 0; + + xa_for_each(&adev->userq_doorbell_xa, queue_id, queue) { + uqm = queue->userq_mgr; + mutex_lock(&uqm->userq_mutex); + if (queue->state == AMDGPU_USERQ_STATE_HUNG && !vram_lost) { + userq_funcs = adev->userq_funcs[queue->queue_type]; + /* Re-map queue */ + r = userq_funcs->map(uqm, queue); + if (r) { + dev_err(adev->dev, "Failed to remap queue %ld\n", queue_id); + continue; + } + queue->state = AMDGPU_USERQ_STATE_MAPPED; + } + mutex_lock(&uqm->userq_mutex); + } + + return r; +} diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h index c562c8d2b53a..7bde7fb0a0a0 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq.h @@ -98,6 +98,7 @@ struct amdgpu_userq_mgr { struct amdgpu_device *adev; struct delayed_work resume_work; struct drm_file *file; + atomic_t userq_count[AMDGPU_RING_TYPE_MAX]; }; struct amdgpu_db_info { @@ -141,6 +142,10 @@ 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); + int amdgpu_userq_input_va_validate(struct amdgpu_vm *vm, u64 addr, u64 expected_size); #endif -- 2.49.0