From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796208812; b=h20HUjc9P2S3BfFwcppqzJbjqm4lhTGtLMKFh4JS1vIPo04VUg8qBtfMy2D5o4gV4o+l GSMmbd+uaBL/oQjkO46Llcm87J79k/I8ZQXfog+dFBN78VTyjb1xvzYhRqZINUDGNl5OV jWcPeAIKyaLlJsfU+dIsv2LFjOkYs5MmHZ1By4FIQ/Az7x8kjND188HO53+dleTE2yOM8 Ag71wRTl3NeZB/S7soUG7QG9r7R+Tol+dofWTPF1SPCJvwsDXejtpHWh0dFr+9qexy3RY C++sne+iY+fpXPt5SYT3ehY26SKmxVbMsjbaOSL81oWCo4wnZd+/6Rn5LdQotV7oEHg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796208812; h=Received:DKIM-Signature:Subject:To:Cc:From:Date:Message-ID: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=prOL6crLkh2v/5aiSeHpyF903BCzGS+V2CEm7FweOcM=; b=SBDZgLnRzMYBfJR+vwKeXQ038yWF5f4GmyNeukufH4oQZ9/53MzWQzigiuSrF2z4swQL 2nDtPjPh88kQK9+wt/sl5hJ7WNSFaIOyQKKnkYqCX+1E2siLnM4NoMKlJnOuwxopSZlS5 zhzfnUlsWvj2+6bVcLPGxYM8Qz0nFVByS6NCcOn5qkhGmEGkcCC1uSZBSJtrmHJlvWMUS LzxR9Ov9RW/dNrZomj/tzvOFM+WnqsCDmcKWpDwSwzNtU9E2Td9TJW8E1OTatwOE6O3WX n3qAWFeTMKumn7TLqaCoojTeGRqg7LY4hAm0qx3JdeyaYqnl3MF3qhLG3dxWswtorUg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WuBiiQRw; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3C50606A327 for ; Wed, 2 Dec 2026 10:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=WuBiiQRw Received: by smtp.kernel.org (Postfix) with ESMTPSA id D58001F00924; Wed, 2 Dec 2026 10:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796208812; bh=prOL6crLkh2v/5aiSeHpyF903BCzGS+V2CEm7FweOcM=; h=Subject:To:Cc:From:Date; b=WuBiiQRwbEq4FFAxa8ezA55Q4cQfYl2qmEgGHYZLNkM9cQT0HQN4nWgT9ZsUFF8we 1xw/b2+Nm+YN2fLR6W+HGmvWzfubKjnrG5eVk46nXuPm8gD1n3XE4Q3+Fjv/TNGhNd 3WEP0leqGzQr/NW5RiZ9hcAo7xWgkFf5zSi1MX5I= Subject: FAILED: patch "[PATCH] drm/sched: Ensure stopped entity cannot be re-added to the" failed to apply to 6.12-stable tree To: tvrtko.ursulin@igalia.com,airlied@gmail.com,andrey.grodzovsky@amd.com,christian.koenig@amd.com,dakr@kernel.org,luben.tuikov@amd.com,matthew.brost@intel.com,phasta@kernel.org,simona@ffwll.ch Cc: From: Date: Wed, 02 Dec 2026 11:53:19 +0100 Message-ID: <2026120219-mulled-sheep-f77e@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The patch below does not apply to the 6.12-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y git checkout FETCH_HEAD git cherry-pick -x 7e2645d5c05ac03f240685fe76a2c04733d36a1a # git commit -s git send-email --to '' --in-reply-to '2026120219-mulled-sheep-f77e@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..' Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 7e2645d5c05ac03f240685fe76a2c04733d36a1a Mon Sep 17 00:00:00 2001 From: Tvrtko Ursulin Date: Mon, 9 Nov 2026 16:07:43 +0000 Subject: [PATCH] drm/sched: Ensure stopped entity cannot be re-added to the run-queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When entities are torn down in drm_sched_entity_kill() a multi-step process is undertaken to synchronize with a drm_sched_run_job_work() consuming jobs from the same entity. First the entity is marked as stopped and removed from the run-queue, with both the entity and run-queue lock correctly taken. The process then waits for the entity idle via the completion after which point it assumes it is the only accessor to the entity in question. What can happen however in drm_sched_run_job_work() if there are at least two outstanding runnable jobs on an entity, is that drm_sched_entity_pop_job() can re-add it to the run-queue due the unconditial add to the rbtree via drm_sched_rq_update_fifo_locked(). What is required is that the teardown starts after the run job has selected the entity and that it gets to it's completion waiting stage before the run job goes to dequeue a job, and for the run job to be able to de-queue a job before teardown has consumed too many. Run job will then see there is another job pending (after the one about to be de-queued) and it will re-add the entity to the run-queue. Run job will then signal the completion and entity teardown will proceed incorrectly thinking it's removal of the entity was final. End result is a pointer to an entity about to be freed dangling forever in the rbtree. drm_sched_run_job_work() drm_sched_entity_kill() drm_sched_select_entity stops and removes entity wait_for_completion drm_sched_entity_pop_job -> re-adds to run-queue due more jobs complete_all drm_sched_entity_queue_pop ... fini entity ... drm_sched_run_job_queue drm_sched_select_entity - UAF This race existed ever since the FIFO policy was first added. Lets mirror the guard from drm_sched_rq_add_entity() in drm_sched_rq_pop_entity() and close this gap. Signed-off-by: Tvrtko Ursulin References: https://sashiko.dev/#/patchset/20261020154123.33631-1-tvrtko.ursulin@igalia.com?part=7 Fixes: 08fb97de03aa ("drm/sched: Add FIFO sched policy to run queue") Cc: Luben Tuikov Cc: Christian König Cc: Andrey Grodzovsky Cc: Matthew Brost Cc: Danilo Krummrich Cc: Philipp Stanner Cc: David Airlie Cc: Simona Vetter Cc: stable@vger.kernel.org # v6.2+ Signed-off-by: Philipp Stanner Link: https://patch.msgid.link/20261109160743.17020-1-tvrtko.ursulin@igalia.com diff --git a/drivers/gpu/drm/scheduler/sched_rq.c b/drivers/gpu/drm/scheduler/sched_rq.c index 23f46ec610e7..6f67a146d99c 100644 --- a/drivers/gpu/drm/scheduler/sched_rq.c +++ b/drivers/gpu/drm/scheduler/sched_rq.c @@ -345,6 +345,13 @@ void drm_sched_rq_pop_entity(struct drm_sched_entity *entity) lockdep_assert_held(&entity->lock); + /* + * If entity is getting torn down via drm_sched_entity_kill() we need + * to ensure it does not get re-added to the tree behind it's back. + */ + if (entity->stopped) + return; + spin_lock(&rq->lock); /*