Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp629697pxv; Thu, 15 Jul 2021 11:58:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxC2xzoyNyDbnmhMUkQCo38GkG7rNWheUPAjfA6E4HbaUgh7kVctFuc7aZLfLQ8HkYNQb7D X-Received: by 2002:a05:6e02:114e:: with SMTP id o14mr3544944ill.301.1626375489231; Thu, 15 Jul 2021 11:58:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375489; cv=none; d=google.com; s=arc-20160816; b=p1uID1Bzn2I5e9KSljuLdrrwg/adB5eLonDVaHKVMnkBgkNQDhg5gaXOrLG2V0wlgd mWsTmCO42OFdgJqQ0I9oa9rSG5sZ0PRZdpO+ivdzcahyQVNfJPw3a8oRGDsNs8GjZzi3 LyIKEE7pfGb9QqjVvLFUWXdGdLsUCvZ3iBooPVeib0HMOEtPS3JL3RH/upJP7ryVkdn4 2jeCz1mUYP4STOJDdMrqRmiE6p0XezYOB4Oeu/4pjBYm7auKR728JxXcFEPtjQS8N7mt gl463CO9V9KIcEvWEq+IN8TV9DwJEg0GJZ67uAJ8G5VwKiBPgBsvTCN2YnG+cLs0SzoB uQIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ytpsey+k3ceoJ7740uxYSfa+hy4ciD70ypbfeCMa52k=; b=HXPVe4eg9DHTIyiCewmUEfmNYIdsL5ToKlDgvM2ouybSbxXR3FKIY8yWieLTSBhLy8 MeUMAocLBkXb4l3ZU8QzEvMVQO9VftE6E3rsgn+IyKwwd+Ap3I/bpblq+dxfc0Z/zTTG ay16+7kFOxV4G0pj8RfHxnue60JfaPz9ox/6v6Ko6xtZ2fpEUZUd0xniVCdlpInQBpom VoBrXeXnRZvEcBSDXTo7ZPTxSqJSxQ3Ps0dfsemZX832DOsQr0Obc4wWCCj/agoIGUH/ fGBGrbsLoH1GNarnRVbPrXn6G1FD08td8nNYM40RF4d2o4hbNxJd5vh7Yfw4aaXQiYeK PYCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c1oWUB71; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si7023659ilb.149.2021.07.15.11.57.54; Thu, 15 Jul 2021 11:58:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c1oWUB71; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242052AbhGOS6U (ORCPT + 99 others); Thu, 15 Jul 2021 14:58:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:55394 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240344AbhGOSwB (ORCPT ); Thu, 15 Jul 2021 14:52:01 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6D8F4613D8; Thu, 15 Jul 2021 18:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374947; bh=ywqNzcJWC1iCcLtLuxp5/Cii7zk7uyXau/bWP/zwWdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c1oWUB71tlCTwR/iYZZduhU4IbKOXZOgdgwpl2gAj3SBYtH59UQdGGZoCN71VMSfF eUyDZ5HxGPuO5IUrxl2wWCO57o61CfiG2XtL2ABDgjyIqAZU3cTHXF7pgM+itYmtS9 vhe8yqVyyDX3cDQo/P/QcYf5lJRGkEM9zIaZnu54= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, xinhui pan , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 093/215] drm/amdkfd: Walk through list with dqm lock hold Date: Thu, 15 Jul 2021 20:37:45 +0200 Message-Id: <20210715182615.810289566@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: xinhui pan [ Upstream commit 56f221b6389e7ab99c30bbf01c71998ae92fc584 ] To avoid any list corruption. Signed-off-by: xinhui pan Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../drm/amd/amdkfd/kfd_device_queue_manager.c | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 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 ffb3d37881a8..352a32dc609b 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1712,7 +1712,7 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, struct qcm_process_device *qpd) { int retval; - struct queue *q, *next; + struct queue *q; struct kernel_queue *kq, *kq_next; struct mqd_manager *mqd_mgr; struct device_process_node *cur, *next_dpn; @@ -1769,24 +1769,26 @@ static int process_termination_cpsch(struct device_queue_manager *dqm, qpd->reset_wavefronts = false; } - dqm_unlock(dqm); - - /* Outside the DQM lock because under the DQM lock we can't do - * reclaim or take other locks that others hold while reclaiming. - */ - if (found) - kfd_dec_compute_active(dqm->dev); - /* Lastly, free mqd resources. * Do free_mqd() after dqm_unlock to avoid circular locking. */ - list_for_each_entry_safe(q, next, &qpd->queues_list, list) { + while (!list_empty(&qpd->queues_list)) { + q = list_first_entry(&qpd->queues_list, struct queue, list); mqd_mgr = dqm->mqd_mgrs[get_mqd_type_from_queue_type( q->properties.type)]; list_del(&q->list); qpd->queue_count--; + dqm_unlock(dqm); mqd_mgr->free_mqd(mqd_mgr, q->mqd, q->mqd_mem_obj); + dqm_lock(dqm); } + dqm_unlock(dqm); + + /* Outside the DQM lock because under the DQM lock we can't do + * reclaim or take other locks that others hold while reclaiming. + */ + if (found) + kfd_dec_compute_active(dqm->dev); return retval; } -- 2.30.2