Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp621251pxv; Thu, 15 Jul 2021 11:45:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf30ePoOrl2bFhE8exSAwAM2LJ9YXoUo/3JEcuStY28qE0p42wW99g8VhAtRVy6rCH4ltL X-Received: by 2002:a05:6602:26d2:: with SMTP id g18mr4197383ioo.194.1626374720748; Thu, 15 Jul 2021 11:45:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626374720; cv=none; d=google.com; s=arc-20160816; b=wWz4pqeBg16rpy+tIPRiborcLnr0VSCAUcA7BBswZ8aaHH9amzvxaQzkTa3HxGN6xY AJfCnfGQP8LyMbC+CvvHix8rrzvnUu13UapuhvCr8Ps47472UwZBYaooVDrYfNV+K4en Oq5hKMOgQno9L47l8V3GUjTPRjO/OesgMVsLyLFqjcEIgFNEkRU+mJXY4odc5Ptwulz1 njvi6Zbss36JsSR+xUvNix/+LfQ7wjFOazZowR0HGuxz82E9qJynVdJTDR/pW7i+wssI BxQDd6BgO7kVpNcLdSCic8D3SqBZpfHhIJwD/wY8oj5FTIFjRom+blDUtxJPEM2ZIkFR JUhA== 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=6LzjoaA08i4hNjQ5wVJbffpEfZ5eNe63nF485krvOFc=; b=ANGEq1aCWqq1SnG+ZF+kcda6j3yUklIbPqtYlja4bd4Nj689uTJC9/yaL6Adj7RCUR Sq3V3oVz3/ooNUsEP+VBZcXGRU9rxWkfRnpaZD7+N0LOSpi+Z/DK0SQqHqWohKXP9veA 8hT4gLfX+lB+rzDCQWCldr4G4YoFIOCKvppZeVaZqb9qmLCuFKFaORkyGQ5wgo1329JZ 6sq4pIfPW04+JfE+KYWmr06Z3LpvW/xHTCJ3edrWyMR0yK7+lDEJxUDq5qY8xzRHP/5v l+vQ/+C/45qOKyeDAJWoGeFTB3bmsGTT3umrjbV6rfrDZISS5KSaUpAYOqkyJ8tSPdOZ ck7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JxSBbuWw; 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 x3si7939864ion.71.2021.07.15.11.45.08; Thu, 15 Jul 2021 11:45:20 -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=JxSBbuWw; 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 S237504AbhGOSp7 (ORCPT + 99 others); Thu, 15 Jul 2021 14:45:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:46110 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbhGOSp2 (ORCPT ); Thu, 15 Jul 2021 14:45:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2791C61396; Thu, 15 Jul 2021 18:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374554; bh=1W/bstbucNPe+USJhNe3o8RBL+LRH+w9EP++FNRD0ww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JxSBbuWwrIWFX5xVRyxJ/BcGZTAioWN7VAOVCPMxJPgvUKC159eVSE6TrQrOaMe86 VTEu/3dH60hcg0rAkNnLtP3Y29G+E1JHa3nTG1j9niRicAcxLiSbqty/k4FWBP+AHF FbPFutgZdtegOJQyojhium0nnEBGho5YHgeH2ApI= 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.4 048/122] drm/amdkfd: Walk through list with dqm lock hold Date: Thu, 15 Jul 2021 20:38:15 +0200 Message-Id: <20210715182501.161276920@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182448.393443551@linuxfoundation.org> References: <20210715182448.393443551@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 ab69898c9cb7..723ec6c2830d 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c @@ -1584,7 +1584,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; @@ -1639,24 +1639,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