Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp651673pxv; Thu, 15 Jul 2021 12:30:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjtmcQqutQq0BxlqiNKkuydKsilS+Hqci/2Tn+601eDCp2GRmLLuH1+hRAc03nSqy8kkRk X-Received: by 2002:a17:906:fb88:: with SMTP id lr8mr7163900ejb.423.1626377440027; Thu, 15 Jul 2021 12:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377440; cv=none; d=google.com; s=arc-20160816; b=qQpjmDcPpiPSFMXlJPjb4PqryKiUlhSC5/YRSgT+CTQh5niOBiTs5JvfrUiQLuNPaC C0617vJLSRoJmkbdiqQsXAzVnaYtaYH/Wra9YORJvNbR6OD3DMgjuVGfiuCjABLaPSrA p72lXEL70fS2LIWRB97vsrT+MpCYCz1N5e/iXOn9FC6Rdtq9nWKIagIBryobbKgX1CBg WSbX1PwNTjWO+R6sVcnX/1Lmst53bKeVzmiEsT+ydhXvbhp0r+hGRGyNz1gVVaSvFIyo LFEAndCndqNkTbzTV2mGN5lUl65psFIj+v1ARvHAyxp5m5y1SeL3VvBI6nuw3r4he9Cy dtpg== 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=1c9NbbqoJQSR1VfMF8vCc9F/tHDVjvlHQaPXD/L806o=; b=rTOMz8TbeZj6xtyNfgtv/mqKFbd6amjb8/IGxmsWbj6PlmBYNjPQUrzG1SQ+NgRqfy 6fOjZBP0ZZz2RWoWXyDhCPzfg8jWIwbp6J/5TZLRuzCI7pgLsfHVihhYOou0uyhTpTK2 KtwkeRsuDNskwmoM/630Cw/itBNWmPw3F/1X4qs9mcvjas0MYxSpd6FoYgaSgYx3hZad uoxRRH+zl1gSXU+iHIrSpnd7SWLqzn0zkhmD5ePtdOSria7y86zVw5Jbu7PdKT9QeioF OPL0ZSB1rAwK7oqMayOSlVoJPUk64erfZc57vNXx0cYA6QSXoISRCULKm7//ow2sZoiS c0LA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=1AvuKo2y; 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 t13si7984288edc.254.2021.07.15.12.30.17; Thu, 15 Jul 2021 12:30:40 -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=1AvuKo2y; 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 S243175AbhGOT1s (ORCPT + 99 others); Thu, 15 Jul 2021 15:27:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:46404 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243647AbhGOTJ7 (ORCPT ); Thu, 15 Jul 2021 15:09:59 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id BD94061408; Thu, 15 Jul 2021 19:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375975; bh=v2U3oFrCcd0K1eyC+/MWzXjy/77AblsNqWuQmzV9OOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1AvuKo2yIK+IFDgxG3kO6F0ZyMFgUl6BgSZAAeh0EeUJ4S7SQ7zwz85Mk3qxPKoVW nyRnyX5HKoJtoGvwP+5GdCF9Zso77AsSLovHxH9I+3gwu2EpIDve+3HGtkuQro9lOH jA7jQ0dXlpCF34K3ms+M7hdcIuuMzRA6QPwSBWuo= 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.13 032/266] drm/scheduler: Fix hang when sched_entity released Date: Thu, 15 Jul 2021 20:36:27 +0200 Message-Id: <20210715182619.818541303@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 f0790e9471d1..cb58f692dad9 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 92d8de24d0a1..c105c807d7e5 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -888,9 +888,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