Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp626270pxv; Thu, 15 Jul 2021 11:53:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoebsFtKAqWlwDrvLkirN3ift2We3dP5Ym+np3u4xyIOLOu0ROLiy6o8ZWJHAfjNRHjX8M X-Received: by 2002:a92:dc4a:: with SMTP id x10mr3594346ilq.166.1626375194673; Thu, 15 Jul 2021 11:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375194; cv=none; d=google.com; s=arc-20160816; b=YZEsnka0m1dd+3sxTCXjzTc36I9/Rgit7ysAT6Q0ddMbEIXamhgJeneecg9j5MFQQG OmN1p9EVZ1Nkbk6LScZgJ9fB8Maip093gTCeh3HgR92WCYKnITQoG3BnP31q//Fsiu5f tD/rVmUn19nGrFKURQ3IG0t5dg2z2ka7+UzxzD95KagUw/b7Yz/OcDxmdLcADYsSgR9P Ckgs7tCUadlt1k9IX0Gw498/pzFeQF8qO+yqfNn7RrvGr3HMbEqoYOn+8/u+WAR+YkIC nD0NXx0bdUGoZe9XRb5kcemgMrv6q4dmeunLuwTpONBwC8DqhlYVsY5yVAh3mMRHZ9Vn IInA== 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=pzlS+FkopWXLl3YSsGNZeEYxQI6unrStABnlhMW5mdU=; b=wuVRoXoXFxmObJTkGwkCottx7gBlCCVb0unQPcOQyQpvsaD44O6MkJakP2+Z4zHCXB b+xFR5ylT3IDp8l8DUb0iSCh3qwwZWSBH8TIhzt6OXUQUN9MJ8k6wYbgVqBuAc2xD/zr e5A8YlGJbecH74DgImDsKHUI7lhISjiOLxAM0xIQLhQe8xWrNkspqcFKA94VaTXxAXRz Zajxi1E3+KJTpj5QuM2nB59IDr+QNd/83RgZVgT8slbfxs4s5CjUiWttW76WzO4IppRs EIcp0R904QfolqGawAXXN71GMfHFeI5IWWop1NzXWditmSfNFwKwSK5TInrD/KuHB967 SaaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BqOcpFQ0; 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 p10si260623iov.66.2021.07.15.11.53.02; Thu, 15 Jul 2021 11:53:14 -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=BqOcpFQ0; 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 S237695AbhGOSzT (ORCPT + 99 others); Thu, 15 Jul 2021 14:55:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:53048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239252AbhGOSuu (ORCPT ); Thu, 15 Jul 2021 14:50:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 71985613F3; Thu, 15 Jul 2021 18:47:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374865; bh=jH8NKxFTKwNu/qUdPjPesAKZszR0sQ/EmNDNJP5FCcs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BqOcpFQ0H3xPGeVK8S+wFY9+jMNW38C8e2aX0/p64FZ8fINmGKUZbB2yCe2Y9ZzZZ VAmEVM7UgHyeOY9rMd147rqWnNapdqslg7hhzjWqGrC691QAktiiYgKBeaUnIf2zWC HOvA2RfEzzzJrjwez9rvwVbIzLYeKPWYiQqvhZE4= 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.10 024/215] drm/scheduler: Fix hang when sched_entity released Date: Thu, 15 Jul 2021 20:36:36 +0200 Message-Id: <20210715182603.127125120@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: 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 146380118962..2006cc057f99 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -113,7 +113,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 7111e0f527b0..b6c2757c3d83 100644 --- a/drivers/gpu/drm/scheduler/sched_main.c +++ b/drivers/gpu/drm/scheduler/sched_main.c @@ -887,9 +887,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