Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0443E606A322 for ; Thu, 3 Dec 2026 14:02:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.a=rsa-sha256 header.s=20170329 header.b=PAHsQ1FB Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 766351128F7; Thu, 3 Dec 2026 14:01:52 +0000 (UTC) Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id C45FB10E75C for ; Thu, 3 Dec 2026 14:01:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:From:Reply-To; bh=/42BAgYTH2Ln2OoeObIP978FcQGb+U16vs5siJmuNP8=; t=1796306497; x=2111666497; b=PAHsQ1FBD7+1oLHalCfyOEuCrf5YjYuTv+Q+inc2ihNq7fWCTE0jR33fgugSQE72dkC3tCtFlSo G5u8NHFeq8dYcj+15TN8+7112g52pqhIn9ERONFEpJyRBGgesJG4bJoPCJt1Y9f7tV+3PeIeo5tlW X5a56DZxLrGyc5AUWcbWsdsujjZw1dRltfKYHMNMH7exViGrRx2M3W8KlVO1K/cY0kq6jN7OLoudS jfU8XENqy5cpWdptaqA+FpG6apx81Lldt2IuKDWKJm0Dq0KGWDjwrXntqU7WGi2oGDS///hLPUldY wbEqo1I5+emIs0DctfmuDTtcTfcF09FMZJJw==; Received: from [81.79.79.1] (helo=localhost) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) (envelope-from ) id 1xZ7NQ-00000001fXQ-0vBc; Thu, 03 Dec 2026 15:01:36 +0100 From: Tvrtko Ursulin To: dri-devel@lists.freedesktop.org Cc: kernel-dev@igalia.com, Tvrtko Ursulin , =?UTF-8?q?Christian=20K=C3=B6nig?= , Danilo Krummrich , Matthew Brost , Philipp Stanner Subject: [PATCH v2 06/10] drm/sched: Disallow initializing entities with un-initialized schedulers Date: Thu, 3 Dec 2026 14:01:24 +0000 Message-ID: <20261203140128.6813-7-tvrtko.ursulin@igalia.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261203140128.6813-1-tvrtko.ursulin@igalia.com> References: <20261203140128.6813-1-tvrtko.ursulin@igalia.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "dri-devel" X-Spam-Status: No, score=-17.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Simplify the code and theoretical runtime combinations by disallowing initializing entities with un-initialized schedulers. Signed-off-by: Tvrtko Ursulin Cc: Christian König Cc: Danilo Krummrich Cc: Matthew Brost Cc: Philipp Stanner --- I do not *think* any of the drivers relies on this inverted initialization order but it needs more eyes for sure. --- drivers/gpu/drm/scheduler/sched_entity.c | 36 ++++++++++++++++-------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c index 03e68b4102d5..69bcefdf2c55 100644 --- a/drivers/gpu/drm/scheduler/sched_entity.c +++ b/drivers/gpu/drm/scheduler/sched_entity.c @@ -90,6 +90,19 @@ ktime_t drm_sched_entity_stats_job_add_gpu_time(struct drm_sched_job *job) return duration; } +static bool drm_sched_list_is_initialized(struct drm_gpu_scheduler **sched_list, + unsigned int num_sched_list) +{ + unsigned int i; + + for (i = 0; i < num_sched_list; i++) { + if (!sched_list[i] || !sched_list[i]->sched_rq) + return false; + } + + return true; +} + /** * drm_sched_entity_init - Init a context entity used by scheduler when * submit to HW ring. @@ -119,7 +132,10 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, unsigned int num_sched_list, atomic_t *guilty) { - if (!entity || !sched_list || !num_sched_list || !sched_list[0]) + if (!entity || !sched_list || !num_sched_list) + return -EINVAL; + + if (!drm_sched_list_is_initialized(sched_list, num_sched_list)) return -EINVAL; memset(entity, 0, sizeof(struct drm_sched_entity)); @@ -135,13 +151,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->sched_list = num_sched_list > 1 ? sched_list : NULL; RB_CLEAR_NODE(&entity->rb_tree_node); - if (!sched_list[0]->sched_rq) { - /* Since every entry covered by num_sched_list - * should be non-NULL and therefore we warn drivers - * not to do this and to fix their DRM calling order. - */ - pr_warn("%s: called with uninitialized scheduler\n", __func__); - } else if (priority >= sched_list[0]->num_user_rqs) { + if (priority >= sched_list[0]->num_user_rqs) { /* * The "priority" of an entity cannot exceed the number of * run-queues of a scheduler. Protect against num_rqs being 0, @@ -158,8 +168,7 @@ int drm_sched_entity_init(struct drm_sched_entity *entity, entity->priority = priority; entity->rq_priority = drm_sched_policy == DRM_SCHED_POLICY_FAIR ? DRM_SCHED_PRIORITY_KERNEL : priority; - if (sched_list[0]->sched_rq) - entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; + entity->rq = sched_list[0]->sched_rq[entity->rq_priority]; init_completion(&entity->entity_idle); @@ -192,7 +201,12 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity, struct drm_gpu_scheduler **sched_list, unsigned int num_sched_list) { - WARN_ON(!num_sched_list || !sched_list); + if (WARN_ON(!num_sched_list || !sched_list)) + return; + + if (WARN_ON_ONCE(!drm_sched_list_is_initialized(sched_list, + num_sched_list))) + return; spin_lock(&entity->lock); entity->sched_list = sched_list; -- 2.56.0