Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp707881pxv; Thu, 15 Jul 2021 14:04:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSbiz0UdFkb4AQY2masx67hGhac99kkRFy8wKdWk4OmU7tyAgPM/bvaHd8AMccQnaYrwWE X-Received: by 2002:aa7:d991:: with SMTP id u17mr9627105eds.240.1626383040679; Thu, 15 Jul 2021 14:04:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626383040; cv=none; d=google.com; s=arc-20160816; b=R4vgUJSgKmJ8gKNOWGVCgiVWp/PAUzEexdTW6V4VrII1SaY8SDAFh1zn/TgKtCOSmh KocNH+PJzBnRL6vrHNj6yv8uP5wK5iAPNBw7PxgglokmVWXjYSPO13gWlLZlAXH6WVO0 UuweDFKxFDqTwzBTO2+e8eOyVjjZqAAb4K1yDxP7AUheIddpa9r6TCiE4SI4yGIbZMAJ mPpZttN6iun5ZuCWCc1D2HC4xWYQINlRsD4aOq8xxdXuLw8mTRS8791UyNhv6DzJ8Uzo UL/qbI8OTyOcjDnxE8T7HGIfZDfF2FXd992Y2gtVIZ2r4yGtLn4xg9PwfHtZeJhcBIdZ uWEA== 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=gH6LhysWR7AqC/Mj+IMSkuGZyIy1p1bahSDvWZZN44A=; b=eqeQavocTSfU/MKffKDixrOouwBgCJLxxERlP+xSwLpZc4nzEzHZCu9tDw8slt0FCA Tngz910HlP6Khnc9PWfmmHGRgyf71hFBfSmbcjN/1SRZ1e/em2QbTWny7we3onBwT65+ bs0j7tfrJfXJOrZB650yGJ73DStDQgnE7THaeeuFJbnLwE4AColQ7PPk+VROPBFYOmjL Z9PqDHbBRWkrhVN+q0qM5DLgLW70YOv8QsEy3oODeOBQYdOK3wAuDRn4Jb6LW6BbfxPC 4EPBSDg5IkJcfrP6tMdb9HBrRj1w4PAOP5ByUW216Z6BDPcCy0W7mSmBDF1bME5+uXhY DFLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=RfkmTqyZ; 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 ws17si2082816ejb.374.2021.07.15.14.03.37; Thu, 15 Jul 2021 14:04:00 -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=RfkmTqyZ; 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 S243357AbhGOTNd (ORCPT + 99 others); Thu, 15 Jul 2021 15:13:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:38160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242255AbhGOTBO (ORCPT ); Thu, 15 Jul 2021 15:01:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5E01D613CF; Thu, 15 Jul 2021 18:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375477; bh=pOJ1w1dBinbT0HX1LaUNE1gDjLBmaqvMRUrFCRootGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RfkmTqyZVbYmpnovdgu/s8ELfIxSTvptOJJGoCXYWRR4UaTpTEi8RAOBhG3PXuYww nOME00DKSDnW0/jsf+joowoyOjwpTSiU5FfJWC0xEKj/CA4HMqwNViqAI1eQ3ixeGl L0d+pLZmuYEbiGbB9ipPrinpbfCySksclLwfLMTI= 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.12 103/242] drm/amdkfd: Walk through list with dqm lock hold Date: Thu, 15 Jul 2021 20:37:45 +0200 Message-Id: <20210715182611.175415633@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 3d66565a618f..b2e55917c308 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