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 81E43C55822 for ; Tue, 4 Aug 2026 22:41:26 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 12AA710EBF8; Tue, 4 Aug 2026 22:41:26 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="i+tRNBcE"; dkim-atps=neutral Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11010026.outbound.protection.outlook.com [52.101.46.26]) by gabe.freedesktop.org (Postfix) with ESMTPS id 240EF10EBF4 for ; Tue, 4 Aug 2026 22:41:24 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=W6rhfhC1KRd+Gsr37LLljGtafH8/CUCPMOu231AUvghZTQNbCtt2psy2wRH3ffXz6bkSjQDk2ra08MYSMk6xEPGER9Z/Y5hDHCvgIHPX7lHC9wgMHA+s4Ixn9eBDX4L3edH4IkNMBDkkT2e8IL1jB5BxJyn5PdCjSjIS/1TXCMTVpsv71NPcT9/DzXipBjBKFQQ8FZSFShQ+7kK3YN2DxGhF4N7dFYibAnQjDnF8DSAqha0S7YFXf/7si8NDCjEujZdkg7oZzvfhvR0JHkV0UCy4P+blemeg72aC55IiYmENGODo/f322qN+y9TIx5WWrEDBcp0Z7N9eZJ/3g+57XQ== 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=ARj5anRMZ7GS9B1uCaFwjhwOpzmmq4m9WvD79wmq5aw=; b=TQRilJpo+eDi0LFTq7WVpr+ZdK0zdM+JEpyFnDqAt/to2m/taiLOJ200SBT+Rvz2ngoLGKZ5ytm5IrNDweXBFDV4cWjJiXF9OTbhPtMrKacUh6R5tKlpqZ+2a1gT2xuWkmirn++amSKNU82X863CMl6dtu71PRFPNxEHvN9Njs3BSgRpnMEQ7JSSrIUUsy2JzXftvU3wtWGewnP2yw9wQBeFe8Yh/6rqVmH+piVykFL6soMqDLMT+svU/+zGm16OL9leNOrDuQmEraDzDabl/XqgW3EnGAi0RjNKAWPOmB4V3BUco5F9tD3gDW3benO6fMm7r3tDk8Pwv8jW78FZvg== 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=ARj5anRMZ7GS9B1uCaFwjhwOpzmmq4m9WvD79wmq5aw=; b=i+tRNBcEZwdJqBGvlW/1/RvYseUKhMnZiAPb4lON9Srk4pgBinqciWrmp1YFfL1fkTapGcS1N4Xmk0kXlLPIVkokJ/bFawdJT9Fh74sayN7RCuQd1Jn4tIKgdm1yBORNsgu0lTA8QkidOkezfzUpEjvW853Dcf9/BH5wL2MIsk0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from DS5PPF78FC67EBA.namprd12.prod.outlook.com (2603:10b6:f:fc00::655) by DS7PR12MB8229.namprd12.prod.outlook.com (2603:10b6:8:ea::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.292.15; Tue, 4 Aug 2026 22:41:20 +0000 Received: from DS5PPF78FC67EBA.namprd12.prod.outlook.com ([fe80::7111:7e5c:8508:7852]) by DS5PPF78FC67EBA.namprd12.prod.outlook.com ([fe80::7111:7e5c:8508:7852%8]) with mapi id 15.21.0270.016; Tue, 4 Aug 2026 22:41:20 +0000 Content-Type: multipart/alternative; boundary="------------IRrdPtyfwattjL0UmC8yENgv" Message-ID: Date: Tue, 4 Aug 2026 18:41:18 -0400 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] amdkfd: fix deadlock in set_perfcount To: Zhu Lingshan , Alexander.Deucher@amd.com, Christian.Koenig@amd.com, "Welton, Benjamin" Cc: Ray.Huang@amd.com, amd-gfx@lists.freedesktop.org References: <20260731095105.3529371-1-lingshan.zhu@amd.com> Content-Language: en-US From: Felix Kuehling Organization: AMD Inc. In-Reply-To: <20260731095105.3529371-1-lingshan.zhu@amd.com> X-ClientProxiedBy: YT2PR01CA0003.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:38::8) To DS5PPF78FC67EBA.namprd12.prod.outlook.com (2603:10b6:f:fc00::655) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS5PPF78FC67EBA:EE_|DS7PR12MB8229:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ee4423f-5962-44e6-8d4c-08def27980a0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|1800799024|23010399003|18002099003|22082099003|5023799004|11063799006|8096899003|10067099003|56012099006; X-Microsoft-Antispam-Message-Info: skQGwvnQPZT/lAXR0kk129qHYXNtVSPiNT05JJm26sBsmmSxuqNQoEFyBGhPxuGPQlIxL6BG9lxm6TX4NkCHs4hksp4QVd6kieyEKYtDpNx6SByY+XnO/qnQkrk/XCN2nGzdXAQUdJuIb9f/oA8ap0NXgPgFq2Faref9geJt8N1lNBLZnt3MuyGqzM1MNxDN48dzsyYrKRCv4/n+MykpuICFjdbCYmGpZBc1pe9XKNQLswW+Evn5aJHMGDXmNvswb8XazOqZBlhl+jI+vK6pcIyo5W4uj5bjWMAvzXXatphtZMVZlPDN69Q516hQ9ILKBOqhzN+Zv/KGCs/mQxLN8aZZr5nmDpeCYhdwD5BxJAW429vpK3HID+Box7PuKz2lE7DajRcowtTVEpIGYATO5YmJr5lAFPcaejtuvDUQYTa+Au5QOMPXP3VlmgxX1st4SPn9aaoQhql9BiSDPUEp1TG6w5lbH9AfF8Byl9MGvVR1YWzFrZqLdSCBja/2IB2mAOwOtUSw7pUuJz1DPQtQgLGAToSQ9xkm5OPD3MX5an0QqR5cGQvvjVof8dnvL8/IdR1bVFYJ5IF2fPJu7/0jZfi0noBYTuUp7LlIPymz+Q40M5hpTGy5uUCHXbDSXsJKLWpt2QQH0EhOZZaeqLGvv+ANYLrf9RAucQsTHyXJqHY= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS5PPF78FC67EBA.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(23010399003)(18002099003)(22082099003)(5023799004)(11063799006)(8096899003)(10067099003)(56012099006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RW8yL3NjZnlra2ZPS3AyQTZ4VGIvdEx2dVV5YmVSRDRPQXJRdU1lWG5IWHJG?= =?utf-8?B?SkdDOUNMdEdaZHZxK1RtbGVhZDNUbWErV3JsQk5rVzJVNDNONTdVV09SRVVj?= =?utf-8?B?T1NPSjJXK243SE9KeXBIZE1qSmVRNnp3WVkvVW9Bc1VUbitrVkhNUGY5cFRC?= =?utf-8?B?cmV4VC9qWWVYN3hwYWJuaWpla1ViT0tMRGJZckpiNW5xT3pTMFE4MXVIUCta?= =?utf-8?B?ZmxLQWVyak45VmlMbXozcTkydmxZRGdDOWd5RT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JxeU1lLzR3cng3YStIVmlCTXFHdlNkVitKZnFjMTA1clBr?= =?utf-8?B?cFpna1Nna2ZabC9CN2lWWEh1RG51ZFo2OSt1NnpVVzErTXBSNWFxTDZtNkRZ?= =?utf-8?B?SjRWaU0rNU1ycG4xcDVxQkd5a0tBSGh6OWtTdFArbG5PbEVhcW1zOE45L3JX?= =?utf-8?B?V21rRWpjaHR0OUcvZ294UnJPWHVCSEtJaFYyVW9ZTUZoa0hVa0hmNGl2TVpY?= =?utf-8?B?K1AvZm93UE9ySElpSUhPby9pSUpTR1lSSWdDc3hxYW91WXVaQTNTUT09?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ee4423f-5962-44e6-8d4c-08def27980a0 X-MS-Exchange-CrossTenant-AuthSource: DS5PPF78FC67EBA.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2026 22:41:19.8032 (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: FvBLockhBvnPQKfNRmso1O9cIWijzctZqmFN3Dk3Lqf4t5gczOAQ94in+SuDNobVSZsxEbqxpzxKlY+ldGswhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB8229 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" --------------IRrdPtyfwattjL0UmC8yENgv Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit [+Benjamin] On 2026-07-31 05:51, Zhu Lingshan wrote: > set_perfcount holds the DQM lock (dqm_lock(dqm) > while walking queues, but pqm_update_mqd > calls update_queue, which acquires the > same lock by dqm_lock(dqm), causing deadlocks. > > This commit introduces update_queue_locked which assumes > the dqm lock is already held, and update_queue calls it > with proper lockings. > > set_perfcount calls update_queue_locked instead of pqm_update_mqd, > therefore the deadlock is fixed. I think the patch looks fine to me. I'm just wondering how this bug was not noticed in developer testing of this feature. I see a very similar patch already exists on the DKMS branch but somehow it's missing in amd-staging-drm-next: commit 5cd0710732a45527b6398f8b522289f9adca708b Author: Benjamin Welton AuthorDate: Mon Jan 6 10:30:01 2025 -0800 Commit: Chengjun Yao CommitDate: Mon Jun 22 12:51:06 2026 +0800 amd/amdkfd: fix double lock aquisition in set_perfcount Seperates out locking from update_queue to allow updating of queues by code already holding the mqd lock. Fixes a hang in set_perfcount. This change was in the original mailing list commit for set_perfcount but was not included in gerrit. Fixes: b58289f0abf7 ("Add kfd_ioctl_profiler to contain profiler kernel driver changes") Signed-off-by: Benjamin Welton Acked-by: Kent Russell Benjamin, do you know what's going on here? I think the above patch just needs to be ported to amd-staging-drm-next. But then I'm wondering what else is missing. Or maybe the whole feature was submitted to amd-staging-drm-next by mistake. Regards,   Felix > > Signed-off-by: Zhu Lingshan > --- > .../drm/amd/amdkfd/kfd_device_queue_manager.c | 44 ++++++++++++------- > 1 file changed, 27 insertions(+), 17 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 51ee9c39104b..c34c5f6a5541 100644 > --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c > @@ -77,6 +77,9 @@ static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager * > static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q, > struct qcm_process_device *qpd); > static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q); > +static int update_queue_locked(struct device_queue_manager *dqm, > + struct queue *q, > + struct mqd_update_info *minfo); > > static inline > enum KFD_MQD_TYPE get_mqd_type_from_queue_type(enum kfd_queue_type type) > @@ -341,8 +344,7 @@ static void set_perfcount(struct device_queue_manager *dqm, int enable) > list_for_each_entry(cur, &dqm->queues, list) { > qpd = cur->qpd; > list_for_each_entry(q, &qpd->queues_list, list) { > - pqm_update_mqd(qpd->pqm, q->properties.queue_id, > - &minfo); > + update_queue_locked(dqm, q, &minfo); > } > } > dqm_unlock(dqm); > @@ -1059,8 +1061,9 @@ static int destroy_queue_nocpsch(struct device_queue_manager *dqm, > return retval; > } > > -static int update_queue(struct device_queue_manager *dqm, struct queue *q, > - struct mqd_update_info *minfo) > +static int update_queue_locked(struct device_queue_manager *dqm, > + struct queue *q, > + struct mqd_update_info *minfo) > { > int retval = 0; > struct device *dev = dqm->dev->adev->dev; > @@ -1068,12 +1071,11 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q, > struct kfd_process_device *pdd; > bool prev_active = false; > > - dqm_lock(dqm); > + lockdep_assert_held(&dqm->lock_hidden); > + > pdd = kfd_get_process_device_data(q->device, q->process); > - if (!pdd) { > - retval = -ENODEV; > - goto out_unlock; > - } > + if (!pdd) > + return -ENODEV; > mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type( > q->properties.type)]; > > @@ -1089,14 +1091,12 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q, > retval = remove_queue_mes(dqm, q, &pdd->qpd); > > /* queue is reset so inaccessable */ > - if (pdd->has_reset_queue) { > - retval = -EACCES; > - goto out_unlock; > - } > + if (pdd->has_reset_queue) > + return -EACCES; > > if (retval) { > dev_err(dev, "unmap queue failed\n"); > - goto out_unlock; > + return retval; > } > } else if (prev_active && > (q->properties.type == KFD_QUEUE_TYPE_COMPUTE || > @@ -1105,7 +1105,7 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q, > > if (!dqm->sched_running) { > WARN_ONCE(1, "Update non-HWS queue while stopped\n"); > - goto out_unlock; > + return -EIO; > } > > retval = mqd_mgr->destroy_mqd(mqd_mgr, q->mqd, > @@ -1115,7 +1115,7 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q, > KFD_UNMAP_LATENCY_MS, q->pipe, q->queue); > if (retval) { > dev_err(dev, "destroy mqd failed\n"); > - goto out_unlock; > + return retval; > } > } > > @@ -1163,8 +1163,18 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q, > &q->properties, current->mm); > } > > -out_unlock: > + return retval; > +} > + > +static int update_queue(struct device_queue_manager *dqm, struct queue *q, > + struct mqd_update_info *minfo) > +{ > + int retval; > + > + dqm_lock(dqm); > + retval = update_queue_locked(dqm, q, minfo); > dqm_unlock(dqm); > + > return retval; > } > --------------IRrdPtyfwattjL0UmC8yENgv Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

[+Benjamin]

On 2026-07-31 05:51, Zhu Lingshan wrote:
set_perfcount holds the DQM lock (dqm_lock(dqm)
while walking queues, but pqm_update_mqd
calls update_queue, which acquires the
same lock by dqm_lock(dqm), causing deadlocks.

This commit introduces update_queue_locked which assumes
the dqm lock is already held, and update_queue calls it
with proper lockings.

set_perfcount calls update_queue_locked instead of pqm_update_mqd,
therefore the deadlock is fixed.

I think the patch looks fine to me. I'm just wondering how this bug was not noticed in developer testing of this feature. I see a very similar patch already exists on the DKMS branch but somehow it's missing in amd-staging-drm-next:

commit 5cd0710732a45527b6398f8b522289f9adca708b
Author:     Benjamin Welton <bewelton@amd.com>
AuthorDate: Mon Jan 6 10:30:01 2025 -0800
Commit:     Chengjun Yao <Chengjun.Yao@amd.com>
CommitDate: Mon Jun 22 12:51:06 2026 +0800

    amd/amdkfd: fix double lock aquisition in set_perfcount
    
    Seperates out locking from update_queue to allow updating
    of queues by code already holding the mqd lock. Fixes a
    hang in set_perfcount. This change was in the original
    mailing list commit for set_perfcount but was not included
    in gerrit.
    
    Fixes: b58289f0abf7 ("Add kfd_ioctl_profiler to contain profiler kernel driver changes")
    
    Signed-off-by: Benjamin Welton <benjamin.welton@amd.com>
    Acked-by: Kent Russell <kent.russell@amd.com>


Benjamin, do you know what's going on here? I think the above patch just needs to be ported to amd-staging-drm-next. But then I'm wondering what else is missing. Or maybe the whole feature was submitted to amd-staging-drm-next by mistake.

Regards,
  Felix



Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
---
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 44 ++++++++++++-------
 1 file changed, 27 insertions(+), 17 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 51ee9c39104b..c34c5f6a5541 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -77,6 +77,9 @@ static struct queue *find_queue_by_doorbell_offset(struct device_queue_manager *
 static void set_queue_as_reset(struct device_queue_manager *dqm, struct queue *q,
 			       struct qcm_process_device *qpd);
 static int reset_queues_mes(struct device_queue_manager *dqm, struct queue *q);
+static int update_queue_locked(struct device_queue_manager *dqm,
+			       struct queue *q,
+			       struct mqd_update_info *minfo);
 
 static inline
 enum KFD_MQD_TYPE get_mqd_type_from_queue_type(enum kfd_queue_type type)
@@ -341,8 +344,7 @@ static void set_perfcount(struct device_queue_manager *dqm, int enable)
 	list_for_each_entry(cur, &dqm->queues, list) {
 		qpd = cur->qpd;
 		list_for_each_entry(q, &qpd->queues_list, list) {
-			pqm_update_mqd(qpd->pqm, q->properties.queue_id,
-						&minfo);
+			update_queue_locked(dqm, q, &minfo);
 		}
 	}
 	dqm_unlock(dqm);
@@ -1059,8 +1061,9 @@ static int destroy_queue_nocpsch(struct device_queue_manager *dqm,
 	return retval;
 }
 
-static int update_queue(struct device_queue_manager *dqm, struct queue *q,
-			struct mqd_update_info *minfo)
+static int update_queue_locked(struct device_queue_manager *dqm,
+			       struct queue *q,
+			       struct mqd_update_info *minfo)
 {
 	int retval = 0;
 	struct device *dev = dqm->dev->adev->dev;
@@ -1068,12 +1071,11 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q,
 	struct kfd_process_device *pdd;
 	bool prev_active = false;
 
-	dqm_lock(dqm);
+	lockdep_assert_held(&dqm->lock_hidden);
+
 	pdd = kfd_get_process_device_data(q->device, q->process);
-	if (!pdd) {
-		retval = -ENODEV;
-		goto out_unlock;
-	}
+	if (!pdd)
+		return -ENODEV;
 	mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type(
 			q->properties.type)];
 
@@ -1089,14 +1091,12 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q,
 			retval = remove_queue_mes(dqm, q, &pdd->qpd);
 
 		/* queue is reset so inaccessable  */
-		if (pdd->has_reset_queue) {
-			retval = -EACCES;
-			goto out_unlock;
-		}
+		if (pdd->has_reset_queue)
+			return -EACCES;
 
 		if (retval) {
 			dev_err(dev, "unmap queue failed\n");
-			goto out_unlock;
+			return retval;
 		}
 	} else if (prev_active &&
 		   (q->properties.type == KFD_QUEUE_TYPE_COMPUTE ||
@@ -1105,7 +1105,7 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q,
 
 		if (!dqm->sched_running) {
 			WARN_ONCE(1, "Update non-HWS queue while stopped\n");
-			goto out_unlock;
+			return -EIO;
 		}
 
 		retval = mqd_mgr->destroy_mqd(mqd_mgr, q->mqd,
@@ -1115,7 +1115,7 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q,
 				KFD_UNMAP_LATENCY_MS, q->pipe, q->queue);
 		if (retval) {
 			dev_err(dev, "destroy mqd failed\n");
-			goto out_unlock;
+			return retval;
 		}
 	}
 
@@ -1163,8 +1163,18 @@ static int update_queue(struct device_queue_manager *dqm, struct queue *q,
 						   &q->properties, current->mm);
 	}
 
-out_unlock:
+	return retval;
+}
+
+static int update_queue(struct device_queue_manager *dqm, struct queue *q,
+			struct mqd_update_info *minfo)
+{
+	int retval;
+
+	dqm_lock(dqm);
+	retval = update_queue_locked(dqm, q, minfo);
 	dqm_unlock(dqm);
+
 	return retval;
 }
 
--------------IRrdPtyfwattjL0UmC8yENgv--