Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp639799pxv; Thu, 15 Jul 2021 12:11:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyY8ruQ+64o1l/LWwcimPkv/Zz0lbEisZ2501H2jQl/sdbslAM5VRf04IDdfQ5wKrmWMl+t X-Received: by 2002:a17:906:d977:: with SMTP id rp23mr7159256ejb.512.1626376301245; Thu, 15 Jul 2021 12:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626376301; cv=none; d=google.com; s=arc-20160816; b=NXeGPVEe2kT0aVnwl3E+Y8/4FFJPUC6hAE5m2gSvqjRtYgSS2hY+0GakoF9HtUGD7I DFm56tNI4AstxyPMad0ffYPh7lzLoKggjg2EV440eoMr3pt39tWGVionYlRFIHOCdUN3 QT1v3l12kC5flUKuZTWIh07ljwTvMPpkNuXCerNo94YSQiyIzowDnn5Q5H8K5TzjYnZ4 3sD3H5dZyCz+frWNnLhrlN08wCI9j4IqCc5Cb96WxbQrGlFPblzrS2JxgQrpI2GDmIBD tRzA6uxpjDqUquLOcf7+dD7/oX7QprJG3nYsjl52+PpQ+hRg8rrcWx5rJ9A4+1UwAV3c 5IoQ== 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=53EvIMy3XL0fAhrrgpANQTgWQbgize1+S97mA3+RxgY=; b=ZoGEjwbH4yUYxOjy7aYog7XiUtuLvSSq09RVuNZEV6u86x4LkdGQxjpmDMO0UhSZRb +87mXpLxTfabG82C9d0XsjaBtEuwOQoDWj7YYx4t9V2ZA+HbrL3pXYB4t5lfbOrgifc4 KjA/BwkY7eKxE38ArxgtlGaEqDE9T497h/cGp4D1tKU2NbaygmgyGqlJKgDTyyWkbaSE Waps0XJq2EDDCZmzezn/2FlCnT0u27K8U2lPSqZo3pAnEsFq+X4lPBEekQrLzTP5wY1B ylhUmnKKV9/O1OY3AKguaUxC0MiRQhTTF1QxxDPC+ESXJOoe5lRdAusp1nIWRj7vY4A5 bU/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=nOOyMbcQ; 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 eb13si10060386edb.245.2021.07.15.12.11.18; Thu, 15 Jul 2021 12:11:41 -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=nOOyMbcQ; 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 S242379AbhGOTK7 (ORCPT + 99 others); Thu, 15 Jul 2021 15:10:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:34066 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242332AbhGOS7h (ORCPT ); Thu, 15 Jul 2021 14:59:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 809D8613E7; Thu, 15 Jul 2021 18:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375380; bh=XvGNq4npWBQakz2OUliDSnF0sJ9yN0gUsA5zRBHOPIk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nOOyMbcQoYCMLRtHmfRK4iTBmw/fx+C/3wWeCx3npsNqNHSOCPis7HHtGZ2z7acCH kuStzB90ORk5LVnIDy8RnVHAH7KAtCHjHbZdFfRqBgCr/m7VpmJGT4RQlsZCgXKQBF V6dSPDiPng5JzHwj81Oz5RdOac6whNogPTBlrAhQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Grodzovsky , =?UTF-8?q?Christian=20K=C3=B6nig?= , Sasha Levin Subject: [PATCH 5.12 025/242] drm/scheduler: Fix hang when sched_entity released Date: Thu, 15 Jul 2021 20:36:27 +0200 Message-Id: <20210715182556.235583290@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: Andrey Grodzovsky [ Upstream commit c61cdbdbffc169dc7f1e6fe94dfffaf574fe672a ] Problem: If scheduler is already stopped by the time sched_entity is released and entity's job_queue not empty I encountred a hang in drm_sched_entity_flush. This is because drm_sched_entity_is_idle never becomes false. Fix: In drm_sched_fini detach all sched_entities from the scheduler's run queues. This will satisfy drm_sched_entity_is_idle. Also wakeup all those processes stuck in sched_entity flushing as the scheduler main thread which wakes them up is stopped by now. v2: Reverse order of drm_sched_rq_remove_entity and marking s_entity as stopped to prevent reinserion back to rq due to race. v3: Drop drm_sched_rq_remove_entity, only modify entity->stopped and check for it in drm_sched_entity_is_idle Signed-off-by: Andrey Grodzovsky Reviewed-by: Christian König Link: https://patchwork.freedesktop.org/patch/msgid/20210512142648.666476-14-andrey.grodzovsky@amd.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/scheduler/sched_entity.c | 3 ++- drivers/gpu/drm/scheduler/sched_main.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index c1ac3e4003c6..72c39608236b 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -116,7 +116,8 @@ static bool drm_sched_entity_is_idle(struct drm_sched_entity *entity) rmb(); /* for list_empty to work without lock */ if (list_empty(&entity->list) || - spsc_queue_count(&entity->job_queue) == 0) + spsc_queue_count(&entity->job_queue) == 0 || + entity->stopped) return true; return false; diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c index 92637b70c9bf..16244e9669b9 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -896,9 +896,33 @@ EXPORT_SYMBOL(drm_sched_init); */ void drm_sched_fini(struct drm_gpu_scheduler *sched) { + struct drm_sched_entity *s_entity; + int i; + if (sched->thread) kthread_stop(sched->thread); + for (i = DRM_SCHED_PRIORITY_COUNT - 1; i >= DRM_SCHED_PRIORITY_MIN; i--) { + struct drm_sched_rq *rq = &sched->sched_rq[i]; + + if (!rq) + continue; + + spin_lock(&rq->lock); + list_for_each_entry(s_entity, &rq->entities, list) + /* + * Prevents reinsertion and marks job_queue as idle, + * it will removed from rq in drm_sched_entity_fini + * eventually + */ + s_entity->stopped = true; + spin_unlock(&rq->lock); + + } + + /* Wakeup everyone stuck in drm_sched_entity_flush for this scheduler */ + wake_up_all(&sched->job_scheduled); + /* Confirm no work left behind accessing device structures */ cancel_delayed_work_sync(&sched->work_tdr); -- 2.30.2