From mboxrd@z Thu Jan 1 00:00:00 1970 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 9D764606A33C for ; Fri, 4 Dec 2026 09:13:02 +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=LlksgwMr Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2F70C112DD8; Fri, 4 Dec 2026 09:12:57 +0000 (UTC) Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010028.outbound.protection.outlook.com [52.101.46.28]) by gabe.freedesktop.org (Postfix) with ESMTPS id C7C51112D8D for ; Fri, 4 Dec 2026 09:12:45 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=KPUlJ1snoBj6it4H5gn5oEjPZE/VN10/Db9r8WB1zeM3zx6n8oPunDnIPVa5rFc2eqeEoNb+Jw7IcKM6JZN9OrEI342lpGGq31oLMNczCDufpwz4TNwMwIRwnDwsWHCkUNEUL4Xug/4a6oNvM/I7TuKm0d693MjMztPHWe+WFYo/QdypxSKfkcbzpVwlthDNHDwNXiT0/FEKs64xANeg1EhJOU6EKsYw0e3+VqsfcUeNp7A+ckP0DOmmO/IWlqzk/XoC2iBohusPL7bLHEWPBypVQ9bzqI79ULzcj5FAnskxCVT870Y4IIOQWR+K1GUH4/h6Cmt+x1+b9CgVYVyRRQ== 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=2Epmzk8s9P7yD0QTyuWmefd0UekntTdcGRDtVj15HsU=; b=dQWP0uT70SFypl+WR41VC4ZXumJ7lxI4tvJiMnuKzLpjNsXpTvhPSNbgiQeUz0EFCNM5VPlmR8Xu21dx+0Alj30wcOTUoMGLZbEQTDQpJiSsYAaZhvMJODDu0M3hldM/HL+JnEKECGDXdmPHRcjW+TtSrLC3t1do1Fzi6Xrw0e/oZ5/u1O2V7UbhwtF0mxzr5UKQsXMg+q+bb3pqVit7wZIzrRSyY0W5m0Gx3H8PCMhVCLaJEIjRu5/dAIzaJBByKvh01fSdcZlXXiLsnUS2jPLRSqQoNKjmrCL+mjf/szNDTCuaimwLXqJnY0q/dGIu/pYFmcAgz0p+MD7I5jx47g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none 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=2Epmzk8s9P7yD0QTyuWmefd0UekntTdcGRDtVj15HsU=; b=LlksgwMrfzsm/SWjDhkmEpn5RpijwkWyAxRjv4uG07cw8VHLpeghiw+PtS38HUbz/+mST+VotwgKvPpjlie3BpLUtqH+5Y5indsPyMNnb9CcdjIJNvu0R4Mt6NW2DVdPPQSHb40Wky3ow7ZtJNNMJnVkRKPHTd612vGGJCXa/dU= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from CH3PR12MB504406.namprd12.prod.outlook.com (2603:10b6:610:34b::7) by SJ5PPFC41ACEE7B.namprd12.prod.outlook.com (2603:10b6:a0f:fc02::9a0) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.11; Fri, 4 Dec 2026 09:12:43 +0000 Received: from CH3PR12MB504406.namprd12.prod.outlook.com ([fe80::570c:1c4d:5cd:97f7]) by CH3PR12MB504406.namprd12.prod.outlook.com ([fe80::570c:1c4d:5cd:97f7%3]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 09:12:42 +0000 Message-ID: <6bf24fcf-8235-4cef-87f2-d0d3545bc4b2@amd.com> Date: Fri, 4 Dec 2026 17:12:37 +0800 User-Agent: Mozilla Thunderbird Subject: Re: [PATCHv2 2/2] drm/amdkfd: remove all queues of a process with a single MES call To: Mukul Joshi , amd-gfx@lists.freedesktop.org Cc: Felix.Kuehling@amd.com, Harish.Kasiviswanathan@amd.com References: <20261204033433.939162-1-mukul.joshi@amd.com> <20261204033433.939162-2-mukul.joshi@amd.com> Content-Language: en-US From: "Lin, Amber" In-Reply-To: <20261204033433.939162-2-mukul.joshi@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: TPYP295CA0007.TWNP295.PROD.OUTLOOK.COM (2603:1096:7d0:9::12) To CH3PR12MB504406.namprd12.prod.outlook.com (2603:10b6:610:34b::7) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH3PR12MB504406:EE_|SJ5PPFC41ACEE7B:EE_ X-MS-Office365-Filtering-Correlation-Id: b1a00a58-395d-48a7-053e-08df51e6c08d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|376014|1800799024|366016|23010399003|4143699003|261009223027099003|18002099003|22082099003|261022075727099003|261028144727099003|11063799006|261022105027099003|10067099003|261026121527099003|261102123227099003|56012099006|261026140227099003|261021123027099003|261021121427099003; X-Microsoft-Antispam-Message-Info: imEvsIsRK3yN9hqwhd1gaqfpW3e+w5g7dXj5VYMw+oEAXbGPq5i1AEVUcv3yjPTriKLo5xh5Z4cmaTCjqbRs+k6hsIkzxaypGDNKFZ7M+JvLqtVlKF4mtwUZVxav0W4AWoEgCiMDnnOZ/9VhZ4J4tzCXEO2aOzyR91SJkHTKBFbxeE7RyscRe7qE+YD+gAfCbLdUX0aC+4ZbdJfKoPuIkColqKexW8+3f3JjkX+N1AdUVDK1Y4GBqgGluYs0rjM02vbcr2QwoRCep8ch/KV9AAVZyYAPT2g8k1vLQ4t7PCrkpqMJ5bwfEpTRoel+ComW9qsasSowIZhPOj97TqHZwvEvyyTTtfir2HSfuqOSRZv8OUm4OIZtNABZJmms2x6aco5Z1eA7byBLoHzqxTeJq2s9vonOycAweMiua0FFb/YBX3ymagIs/g9/zViifYNnU92T066yWMWDiKtWrlk2QHOo4x6EDsA9cHefV0PIrW3HdhIpRM+p8ZPrB3BIvka46h4kLUL5sh/Op5lNlIJ55Zog3Au0LHI4wjLc6z3tU9kTASmX90pNiTiPsK68iOugqbYWipgxUt8PoppK1uklKvPGxY3W0vu72zVu/M1rhMTzTtPV+937Ypob/mxMwfL2Rs+ntqIcOz+6D1f8iSN5rYTLihPUj0LdXM9WJUY17SE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH3PR12MB504406.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(23010399003)(4143699003)(261009223027099003)(18002099003)(22082099003)(261022075727099003)(261028144727099003)(11063799006)(261022105027099003)(10067099003)(261026121527099003)(261102123227099003)(56012099006)(261026140227099003)(261021123027099003)(261021121427099003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?SEJ2WGlZemF0UEJmc09pZkk0Y0hjbm90a0tVT2hKY0hiNEZsVElYdmV6aTdS?= =?utf-8?B?UEpacW9ucDVBZVo3aU9MZ3NUK1FQR2dHay8vUzROTzlmUUp0NDN5bmhzLzYz?= =?utf-8?B?dUFP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oay8xMmdw?= =?utf-8?B?V0wzU3diSXl3WVhiakhqYjdWWXcrcnBGM2F4ZlMxOGgzUXQ3cGFkblJzdnhT?= =?utf-8?B?RGpUbTdlbG9hQUZRSlM3d0s5dEdQNHN0d2VjY3BnWVVyaHNuS2ZIb2lLSkFq?= =?utf-8?B?V0Q5cG8ydHQwU01keFVoNlRubjArRTM3ZXU3MEIvNGtpOUVYYmpDQ0x3YjdR?= =?utf-8?B?eHMwTW15TE84UjFzVFR0UWN6Rk95RVc4d2ZZWkk4b2lXVUxvaWxoeDdCL3ds?= =?utf-8?B?S3RJT0ppQ0xVQkZGalVhdkpycmt3emVWbFpVTXlnbUFGYUN6MDYrZ0ZrRG5k?= =?utf-8?B?YXdEdDk2MGY1bmpCMXJ0Tjc3Sm5rWlovbmpLNXBMYmlXRmVma2tDeHJ1Z3Fx?= =?utf-8?Q?KrQNpUq7eDet4no0J+?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: b1a00a58-395d-48a7-053e-08df51e6c08d X-MS-Exchange-CrossTenant-AuthSource: CH3PR12MB504406.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 09:12:42.6607 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tdKLPkwX8ptMJM5cFvWM+qp0+SLwPJ9RogyngnH/+103DjEidNPxbJFu3MvqXOG5 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ5PPFC41ACEE7B 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=-17.7 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_SANE_1 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 Series is Reviewed-by: Amber Lin On 12/4/2026 11:33 AM, Mukul Joshi wrote: > On process eviction, termination and scheduler halt/stop, KFD sends one > MES REMOVE_QUEUE per active queue. If MES supports it, remove all queues > of a process, by PASID, with a single request instead. > > remove_queue_mes() sends this request when called with a NULL queue. On > failure, the same request is passed to the MES queue reset path, which > sends it again if no hung queue is found. If hung queues were reset > instead, the other queues of the process are resumed, so send the > request once more. > > Signed-off-by: Mukul Joshi > --- > .../drm/amd/amdkfd/kfd_device_queue_manager.c | 139 ++++++++++++++---- > 1 file changed, 113 insertions(+), 26 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > index 58c7da599752..35d7aef68f62 100644 > --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > @@ -79,7 +79,10 @@ static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager * > u32 doorbell_offset); > static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q, > struct qcm_process_device *qpd, bool verbose); > -static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q); > +static int reset_queues_mes(struct device_queue_manager *dqm, > + struct kfd_process_device *pdd, > + struct mes_remove_queue_input *queue_input, > + unsigned int *hung_queue_count); > > static inline > enum KFD_MQD_TYPE get_mqd_type_from_queue_type(enum kfd_queue_type type) > @@ -299,17 +302,35 @@ static int add_queue_mes(struct device_queue_manager *dqm, struct queue *q, > return r; > } > > +/* A queue that is active and not reset is still in MES */ > +static bool qpd_has_mes_queue(struct qcm_process_device *qpd) > +{ > + struct queue *q; > + > + list_for_each_entry(q, &qpd->queues_list, list) > + if (q->properties.is_active && !q->properties.is_reset) > + return true; > + > + return false; > +} > + > +/* > + * Remove queue q from MES. If q is NULL, remove all queues of the process > + * with a single request, see amdgpu_mes_remove_all_process_queues_supported(). > + * This must be done while the queues are still marked active. > + */ > static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, struct queue *q, > struct qcm_process_device *qpd, > bool is_for_reset, > bool flush_mes_queue) > { > struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev; > + unsigned int num_hung = 0; > int r; > struct mes_remove_queue_input queue_input; > > - /* queue was already removed during reset */ > - if (q->properties.is_reset) > + /* queue(s) already removed during reset */ > + if (q ? q->properties.is_reset : !qpd_has_mes_queue(qpd)) > return 0; > > if (!dqm->sched_running || dqm->sched_halt) > @@ -318,12 +339,17 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, st > return -EIO; > > memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input)); > - queue_input.doorbell_offset = q->properties.doorbell_off; > - queue_input.gang_context_addr = q->gang_ctx_gpu_addr; > - queue_input.queue_type = convert_to_amdgpu_ring_type(q->properties.type); > - queue_input.remove_queue_after_reset = flush_mes_queue; > + if (q) { > + queue_input.doorbell_offset = q->properties.doorbell_off; > + queue_input.gang_context_addr = q->gang_ctx_gpu_addr; > + queue_input.queue_type = convert_to_amdgpu_ring_type(q->properties.type); > + queue_input.remove_queue_after_reset = flush_mes_queue; > + queue_input.gang_context_array_index = q->gang_ctx_array_index; > + } else { > + queue_input.remove_all_process_queues = true; > + queue_input.pasid = qpd_to_pdd(qpd)->pasid; > + } > queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1; > - queue_input.gang_context_array_index = q->gang_ctx_array_index; > > amdgpu_mes_lock(&adev->mes); > r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input); > @@ -335,10 +361,26 @@ static int remove_queue_mes_on_reset_option(struct device_queue_manager *dqm, st > return r; > > /* remove_hw_queue failure indicates a queue hang. reset the queue */ > - r = reset_queues_mes(dqm, q); > + queue_input.remove_queue_after_reset = false; > + r = reset_queues_mes(dqm, qpd_to_pdd(qpd), &queue_input, &num_hung); > + > + /* hung queues were reset and removed; remove the rest of the process */ > + if (!r && !q && num_hung && qpd_has_mes_queue(qpd)) { > + if (!down_read_trylock(&adev->reset_domain->sem)) > + return -EIO; > + amdgpu_mes_lock(&adev->mes); > + r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input); > + amdgpu_mes_unlock(&adev->mes); > + up_read(&adev->reset_domain->sem); > + } > + > if (r && amdgpu_gpu_recovery) { > - dev_err(adev->dev, "failed to remove queue from MES, doorbell=0x%x\n", > - q->properties.doorbell_off); > + if (q) > + dev_err(adev->dev, "failed to remove queue from MES, doorbell=0x%x\n", > + q->properties.doorbell_off); > + else > + dev_err(adev->dev, "failed to remove queues of pasid 0x%x from MES\n", > + queue_input.pasid); > dev_err(adev->dev, "MES might be in unrecoverable state, issue a GPU reset\n"); > kfd_hws_hang(dqm); > } > @@ -363,6 +405,8 @@ static int remove_queue_mes(struct device_queue_manager *dqm, struct queue *q, > > static int remove_all_kfd_queues_mes(struct device_queue_manager *dqm) > { > + struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev; > + bool remove_all = amdgpu_mes_remove_all_process_queues_supported(adev); > struct device_process_node *cur; > struct device *dev = dqm->dev->adev->dev; > struct qcm_process_device *qpd; > @@ -371,6 +415,16 @@ static int remove_all_kfd_queues_mes(struct device_queue_manager *dqm) > > list_for_each_entry(cur, &dqm->queues, list) { > qpd = cur->qpd; > + if (remove_all) { > + retval = remove_queue_mes(dqm, NULL, qpd); > + if (retval) { > + dev_err(dev, "%s: Failed to remove queues of pasid 0x%x for dev %d", > + __func__, qpd_to_pdd(qpd)->pasid, dqm->dev->id); > + return retval; > + } > + continue; > + } > + > list_for_each_entry(q, &qpd->queues_list, list) { > if (q->properties.is_active) { > retval = remove_queue_mes(dqm, q, qpd); > @@ -452,15 +506,21 @@ int kfd_reset_queue_mes(struct device_queue_manager *dqm, int queue_type, > return reset_queue_mes(dqm, q, queue_type, pipe, queue, db); > } > > -static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q) > +/* > + * queue_input is the remove request for the bad queue(s). If MES doesn't > + * detect a hung queue, it is sent again before the queues are resumed. > + * hung_queue_count (optional) returns the number of hung queues. > + */ > +static int reset_queues_mes(struct device_queue_manager *dqm, > + struct kfd_process_device *pdd, > + struct mes_remove_queue_input *queue_input, > + unsigned int *hung_queue_count) > { > struct amdgpu_device *adev = (struct amdgpu_device *)dqm->dev->adev; > struct drm_wedge_task_info *info = NULL; > struct amdgpu_task_info *ti = NULL; > - struct kfd_process_device *pdd; > unsigned int num_hung = 0; > int r = 0; > - struct mes_remove_queue_input queue_input; > > if (!amdgpu_mes_queue_reset_by_mes_supported(adev)) { > r = -ENOTRECOVERABLE; > @@ -471,18 +531,13 @@ static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q) > if (WARN_ON(dqm->detect_hang_count > 0)) > return 0; > > - memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input)); > - queue_input.doorbell_offset = q->properties.doorbell_off; > - queue_input.gang_context_addr = q->gang_ctx_gpu_addr; > - queue_input.gang_context_array_index = q->gang_ctx_array_index; > - queue_input.queue_type = convert_to_amdgpu_ring_type(q->properties.type); > - queue_input.remove_queue_after_reset = false; > - queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1; > /* pass the known bad queue info to the reset function */ > - r = amdgpu_gfx_reset_mes_compute(adev, dqm->dev->xcp, NULL, NULL, NULL, &num_hung, &queue_input); > + r = amdgpu_gfx_reset_mes_compute(adev, dqm->dev->xcp, NULL, NULL, NULL, &num_hung, > + queue_input); > if (r) > goto fail; > - pdd = kfd_get_process_device_data(q->device, q->process); > + if (hung_queue_count) > + *hung_queue_count = num_hung; > if (pdd) { > ti = amdgpu_vm_get_task_info_pasid(adev, pdd->pasid); > if (ti) { > @@ -1493,6 +1548,7 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, > struct queue *q; > struct device *dev = dqm->dev->adev->dev; > struct kfd_process_device *pdd; > + bool remove_all; > int retval = 0; > > dqm_lock(dqm); > @@ -1514,6 +1570,17 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, > if (dqm->dev->kfd->shared_resources.enable_mes) > pdd->last_evict_timestamp = get_jiffies_64(); > > + remove_all = dqm->dev->kfd->shared_resources.enable_mes && > + amdgpu_mes_remove_all_process_queues_supported(dqm->dev->adev); > + if (remove_all) { > + retval = remove_queue_mes(dqm, NULL, qpd); > + if (retval) { > + dev_err(dev, "Failed to evict queues of pasid 0x%x\n", > + pdd->pasid); > + goto out; > + } > + } > + > /* Mark all queues as evicted. Deactivate all active queues on > * the qpd. > */ > @@ -1525,7 +1592,7 @@ static int evict_process_queues_cpsch(struct device_queue_manager *dqm, > q->properties.is_active = false; > decrement_queue_count(dqm, qpd, q); > > - if (dqm->dev->kfd->shared_resources.enable_mes) { > + if (dqm->dev->kfd->shared_resources.enable_mes && !remove_all) { > retval = remove_queue_mes(dqm, q, qpd); > if (retval) { > dev_err(dev, "Failed to evict queue %d\n", > @@ -3286,6 +3353,7 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, > enum kfd_unmap_queues_filter filter = > KFD_UNMAP_QUEUES_FILTER_DYNAMIC_QUEUES; > bool found = false; > + bool remove_all; > > dqm_lock(dqm); > > @@ -3298,6 +3366,15 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, > filter = KFD_UNMAP_QUEUES_FILTER_ALL_QUEUES; > } > > + remove_all = dqm->dev->kfd->shared_resources.enable_mes && > + amdgpu_mes_remove_all_process_queues_supported(dqm->dev->adev); > + if (remove_all) { > + retval = remove_queue_mes(dqm, NULL, qpd); > + if (retval) > + dev_err(dev, "Failed to remove queues of pasid 0x%x\n", > + qpd_to_pdd(qpd)->pasid); > + } > + > /* Clear all user mode queues */ > list_for_each_entry(q, &qpd->queues_list, list) { > if (q->properties.type == KFD_QUEUE_TYPE_SDMA) > @@ -3308,7 +3385,7 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, > if (q->properties.is_active) { > decrement_queue_count(dqm, qpd, q); > > - if (dqm->dev->kfd->shared_resources.enable_mes) { > + if (dqm->dev->kfd->shared_resources.enable_mes && !remove_all) { > retval = remove_queue_mes(dqm, q, qpd); > if (retval) > dev_err(dev, "Failed to remove queue %d\n", > @@ -3610,7 +3687,17 @@ int kfd_dqm_suspend_bad_queue_mes(struct kfd_node *knode, u32 pasid, u32 doorbel > > list_for_each_entry(q, &qpd->queues_list, list) { > if (q->doorbell_id == doorbell_id && q->properties.is_active) { > - if (reset_queues_mes(dqm, q)) > + struct mes_remove_queue_input queue_input; > + > + memset(&queue_input, 0x0, sizeof(struct mes_remove_queue_input)); > + queue_input.doorbell_offset = q->properties.doorbell_off; > + queue_input.gang_context_addr = q->gang_ctx_gpu_addr; > + queue_input.gang_context_array_index = q->gang_ctx_array_index; > + queue_input.queue_type = > + convert_to_amdgpu_ring_type(q->properties.type); > + queue_input.xcc_id = ffs(dqm->dev->xcc_mask) - 1; > + > + if (reset_queues_mes(dqm, pdd, &queue_input, NULL)) > dev_dbg(knode->adev->dev, > "Fail to remove bad queue. doorbell_id 0x%x\n", q->doorbell_id); > q->properties.is_evicted = true;