From mboxrd@z Thu Jan 1 00:00:00 1970 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 53EFB606A325 for ; Tue, 1 Dec 2026 13:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=zohomail header.b=OfQ8stHZ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BAA5C10E194; Tue, 1 Dec 2026 13:19:26 +0000 (UTC) Received: from sender6-pp-f112.zoho.com (sender6-pp-f112.zoho.com [165.173.180.112]) by gabe.freedesktop.org (Postfix) with ESMTPS id C036110E194 for ; Tue, 1 Dec 2026 13:19:20 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; t=1796131146; cv=none; d=zohomail.com; s=zohoarc; b=WXRdZwqtr0tIDaeD1ZRLcnIDmB5rM0rfkGO6TYFeUjIFLokMhf9xq4cBKAlAAZSK75pncoaG3/zukHBavB0gJNRAQXSGQNA87RJUTuFoOYgjzRTL7xms5zZ3cK/z6MbD5hUNfPphszZDJH7fabgKkiFEt28bmGGMDN1g+FRGJog= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1796131146; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=VSXp7z46IDBUSev5PoprdU2/46Btk43Zlzr+nCXN/s0=; b=mZeAKScYGDH0hgFV2bEPnzkKjACy/nsklpJj3UVrcFSxwaQ9928UT1UJG7UmdHR6gcgtO8oNXrqQo0dUgV52lhWdwEjeY/lErTvL3NwSKXsfbMsBojJZHpCySoSrOk8CkO3tX1DkNALe6m5hHBSvbdomFp8ErAow7B6zHqUKRU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=nicolas.frattaroli@collabora.com; dmarc=pass header.from= DKIM-Signature: a=rsa-sha256; b=OfQ8stHZw7k4tgTDIOmDqu0eNDpls98UrQk21Enbl9Gq4bZkyKlK6ogifJsE1p/vs5FW4EPFSpDKaTK3XREQCCJcMzm+5R1MNAvADR7OnmXxnfedOvxj29jRa8MS89bk0svIsv1I5TdwK8sZGfUSOCXFkelxQY2YLczO4qT+Aic=; c=relaxed/relaxed; s=zohomail; d=collabora.com; v=1; bh=VSXp7z46IDBUSev5PoprdU2/46Btk43Zlzr+nCXN/s0=; h=Content-Description:Content-ID:Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Resent-Sender:Resent-Cc:Resent-Date:Resent-To:Reply-To:Resent-Message-ID:Resent-From:Sender:Subject:To:Date:From:Message-Id:Reply-To:Subject:To:Cc; Received: by smtp.zohomail.com with SMTPS id 1796131145030614.9325100699994; Tue, 1 Dec 2026 05:19:05 -0800 (PST) From: Nicolas Frattaroli To: Boris Brezillon , Matthew Brost , Danilo Krummrich , Philipp Stanner , Christian =?UTF-8?B?S8O2bmln?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Luben Tuikov , phasta@kernel.org Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, stable@vger.kernel.org Subject: Re: [PATCH] drm/sched: Sanitise wqueue_start/wqueue_stop/is_stopped interleavings Date: Tue, 01 Dec 2026 14:18:59 +0100 Message-ID: In-Reply-To: <132b66f04e0ed601e45f721f777834b15bf05ed3.camel@mailbox.org> References: <20261128-drm-sched-fini-race-v1-1-9803ee8aa8b4@collabora.com> <132b66f04e0ed601e45f721f777834b15bf05ed3.camel@mailbox.org> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" 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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Tuesday, 1 December 2026 08:56:35 Central European Standard Time Philipp Stanner wrote: > On Sat, 2026-11-28 at 09:27 +0100, Nicolas Frattaroli wrote: > > drm_sched_wqueue_stop() will WRITE_ONCE 1 to the sched's pause_submit > > member. This member is checked (with READ_ONCE) in every > > drm_sched_run_job_queue() and drm_sched_run_free_queue() invocation, > > which is how the two work items drm_sched_wqueue_stop() cancels would > > usually get re-armed. > > > > However, this is of little consequence on SMP systems, where the effect > > of WRITE_ONCE is not guaranteed to be ordered with READ_ONCE calls on > > other CPUs. As a consequence, during drm_sched_fini(), a work item may > > become re-armed after its call to drm_sched_wqueue_stop(), and run into > > a sched->sched_rq that is now NULL, dereferencing a NULL pointer. > > > I just realize that we have recently solved basically the same issue > for drm::JobQueue. > > https://lore.kernel.org/rust-for-linux/20261124122951.878199-11-phasta@kernel.org/ > > > We need to park and unpark the queue. We do that for scheduling- > reasons, but the addressed issue is basically the same since we also > use it to halt the run_worker in our JobQueue deconstructor. > > The mechanism is based on an atomic bool + srcu to wait for everyone to > have seen the flag. Only then do we tear down. The flag is checked in > the worker, so no matter who might kick the worker when for what > reason, it will never access freed resources. > > Maybe you can draw inspiration from that and see whether a mechanism > like that could address the observed problem in drm_sched? Will do. My current solution also has a deadlock according to both sashiko and casual reading of the code, but funnily enough I could not yet trigger a lockdep splat by running both code paths. Basically work_tdr can and will start/stop the drm_sched as well, so synchronously disabling it while holding the pause_lock in drm_sched_fini is a bad idea. In practice, lockdep has somehow not complained, despite me confirming with ftrace that both the timedout function ran and the drm_sched_fini function ran. I guess because in none of those executions, the timedout thread synchronised with drm_sched_fini? Who knows. Kind regards, Nicolas Frattaroli > > > Thx > P. >