From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=80.241.56.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796111803; b=PkakpgXLehtYFpBn6YBephI9LWhKfyce25nMiHgkS7MRgfRpa9V7vchHL6gRFLpg1Q7h 4pvhdtn19TUp1eI3tSYOJfsPNKs/wygAmNp7rRZ0UzwlzBpfavm0/VC50ENRloGRAmHea dIbqtSWAn1jNmGVbHgj2bxW7+3vEYAGlBkD6pAcLFcOfALDPuXIqe3o5spJ2VQokwA6D3 ouV7zRvGhWirLYfsx+f9c62uy/8r9QEdazJRE3qby9XIvsqw6+jGUmr8GAkhPYiXyiH7+ HyTlMeN+ZGxdYpSIn4p5q3ntRyH3AS/OFYTVDY1u9nvgVyWOy/WtIwgUJwq8ekN3OHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796111803; h=DMARC-Filter:Received:DKIM-Signature:Message-ID:Subject:From: Reply-To:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:MIME-Version:X-MBO-RS-ID: X-MBO-RS-META; bh=i02u8zGss2RMjnLcfSQ9YPfgzgiU5uoosearv6/+LHo=; b=5ROoWfFgKRo4DAMwSwUsRnJ2fWSNOclCxNxQQ589JnP+hewhe9H1nmIemArmXDVLZMxA O1DrUYGsfkJtSdaQu1GqTYlz6glG94V6JzUm801wqm4+WU61Qto3DgmE3QM3u7I0gjS20 qS7bt3VYngvC4uq7FPFnArcTMzj56G5UGta8pJ3wRN7g9aKs07njWRorjSdjO+EzUIZ5R bl2YWU8qUGUwUopYCU5hHGkw+QWCX+GBCOe/LftyNLAzbae3PwIkFB+6sq8qn7zZxoKzS BAG/EGjRlqUrq1H8n8V+ls8p6lOLtpmPj2Upfn38M0d2+CMh3N2sFMCDLaihWdMTUSQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mailbox.org; spf=pass smtp.mailfrom=mailbox.org; dkim=pass header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=LpH9KQ6M; arc=none smtp.remote-ip=80.241.56.171 Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (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 C31AD606A31A; Tue, 1 Dec 2026 07:56:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C31AD606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=mailbox.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mailbox.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=mailbox.org header.i=@mailbox.org header.a=rsa-sha256 header.s=mail20150812 header.b=LpH9KQ6M Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:b231:465::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519MLKEM768 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4jdtWV47nhzMll8; Tue, 01 Dec 2026 08:56:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1796111798; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i02u8zGss2RMjnLcfSQ9YPfgzgiU5uoosearv6/+LHo=; b=LpH9KQ6M/VIbF4MEDjHfvbjzv7ctnFPbJs72lkU/2B0i3Oldg0Uhj/bcepHlkglNZ9mcMz rmMpXEqiZIj/HVAEJsuts9WhHhg49j+47eBJNO+sgmSdlJ0HnuVtLn7INTqUYeez4wuqBA mWYZYqSEctgzAzYYrrKyrgTotVRejDHVaLl60gC2826MSa2hG/YtpJ0bWzmZQXxnmhJ55/ eOeMt3hn81giVVQ6T89qxp+nBOAfmmq/FqLwY/l2f7uJB2FoAGQQO3x7UUjHOkMv+Y4nrT nnndx+HBOkaLfO6/+17vBYacDWVljE69qwoTOqWMIWlGsKlXcbqiihiiXVCjkQ== Message-ID: <132b66f04e0ed601e45f721f777834b15bf05ed3.camel@mailbox.org> Subject: Re: [PATCH] drm/sched: Sanitise wqueue_start/wqueue_stop/is_stopped interleavings From: Philipp Stanner Reply-To: phasta@kernel.org To: Nicolas Frattaroli , Boris Brezillon , Matthew Brost , Danilo Krummrich , Philipp Stanner , Christian =?ISO-8859-1?Q?K=F6nig?= , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Luben Tuikov Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, stable@vger.kernel.org Date: Tue, 01 Dec 2026 08:56:35 +0100 In-Reply-To: <20261128-drm-sched-fini-race-v1-1-9803ee8aa8b4@collabora.com> References: <20261128-drm-sched-fini-race-v1-1-9803ee8aa8b4@collabora.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.2 (3.60.2-3.fc44) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MBO-RS-ID: 2dbf9e6f2a76512b4b7 X-MBO-RS-META: 44eytk98q386un18d91m57ug8fuxsenx 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. >=20 > 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@kern= el.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? Thx P.