From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7532D4C9557 for ; Fri, 21 Aug 2026 15:23:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787325791; cv=none; b=HHws9ASJN6YUR1qy5anhUy6PUhHTLmYC+QxbY1fVV9KQy1uDx9+Z+RDf0SDbipeCCYnPi6/6Mrgo0AmmbjJwHuUXbrxVoq7/+7QXdDIzYXjW5Di32wJSMiihvnfsSxf0eHA5hFsII4GtXdS13NTQjKQwH4WxBbOBsDwUzSeQyj8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787325791; c=relaxed/simple; bh=ZErlHBib0LaSTq6e7b9h8OwF5+h7jSxTg3+J3DsZHqs=; h=From:Date:Subject:To:Cc:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gthOhQJJ033sFxmmFvH0D5vnJoX/zdK1tWJpFzcU3lXmK4AX5nRyGau9+0FHlABJpO9BnHD5Fv4aojr+S5emZm6DkvftbgJ69Ixuo4emKRur4Etzcenk/0DXt6lhiDl4pV7bPdUCuJyhSeqTzhJ9dPFVXnCQkNs2nQDS6jWi0hg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=XarpU2sY; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XarpU2sY" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-c15fc4707f5so10877466b.3 for ; Fri, 21 Aug 2026 08:23:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787325788; x=1787930588; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:cc:to:subject:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=YGnVjNNQSxXEhjGwV8/5Y2JvucgSZxjVxoUzS+hSzcQ=; b=XarpU2sYyAgRFSCsGdeL8vvJxaWiV08PDSvFpT52Cflf7dibEr+hbUw4/s0eCZliXv rKjDJHbGWB4sWy2xoOw8rkG282n/sQQicS+Yh7uMHa24KY0Jdn+NsYR/w+L0h8Gc7haQ iyJ8LUvYYXrdaeDvj4XqxOMd7sUyrOt2HQSpqOhGlBliFdhDfzZx+EcPtOKGdO0SPEDc YSfsPmZltJY+OzJ5BDFxy+kjSUEtXs4TApaAuxXd0wZHMHn+e6BGOFug5yz7uyRi4xWY 4juoqJv0VZ/fX1rqQAz7GlgvOEjJuE/e7QW5PC99cF2fZ3I/bY1QTX5VospCBW4V7aAh PEnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787325788; x=1787930588; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:cc:to:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=YGnVjNNQSxXEhjGwV8/5Y2JvucgSZxjVxoUzS+hSzcQ=; b=YV5bt7p+aAd+VCRtsU20RTvSBN/V5XBOXjABf/3w6Dv2sfV0oDI7F9rhmGF9rn98MM Ol9l+/A9QGgItsr+4g02kJ5XcHuYmxWW1JtGKa7LEn/HxLcBkIbcZJoes1vQo+FvRBVr gWILu6Yy/zH3yFCN5+ZZCSUpds86oFAHY0hVYSy2ONx4AOquYHz4Wg0GgQc+avwlxPkq tNJc254pIVuaVA7JOjhL3QMxlGZU28y3YlaKryQs5zLYGdqFVm+c62Q7DRHmE+voXTtK buzV6fmPwuqwX1Xi3/HMbSuKsrwunMhsrfV5bnkwC+LDzX2e1up6pBNtA8K62VMjdOQ2 tLzw== X-Gm-Message-State: AFuF++kOpSv3dH+u/ZmpPFJXhOXf0OjG/8BvQZznCqbSgC/JueDe2MT0 tPiDcTKi01BYukHiyAgqieQ5oSvXXEMuLtIWASiHmHDhILV00bARadGI X-Gm-Gg: AR+sD13wsLnZ+k7OaiP3XTIE+JarkznqY5VHlnTBZptLtdWsgFFuDZ15OqSeoppiVY0 rEHBgYs/RjzlU4NfofW4dEv3OVL/K7WDUhMFHtLL9SdTCIpjMYGlahkM+6zbY2LuW+JtLucCoZe E9iYg4qJdVV8gpyGyOAEDh2oE/vCf7g1KVrm3tkkVrUoqyFXP7kLrkcjGC4zlGayyqd5i0OTXJ/ F2puiiTeANgCHhwDJvM0jxee4xv8iHYMXK4hvv+zYIH7DYoFd4/FLxfqjZv6ARXKRcp0J68lAaV Y4/MLKzQ3Bjwpq4bsUH92+M6nJwliQh60RYWg+daHbNVeEbBKRbcsOM0M5F8ZDJXmOrovvOv9E5 aTrGLDqawZDR56ipHHEYaH3j53ZP4bl2LVAcU3O+F5PnlIUxdJ/4NN3N1JS0nJX/vNFT1PQjPBU 1Xt/W/vcjBbgPKvoTjsiuJ0avzINOIVQ0+oNwTTMW5OLfCG9EjVTEojFT7tvKGXxaCqz2rSh2CQ fnDIzlvSJx3j5G3WpRJ5DGdomJX1q4qhT0n9Yd/9Q== X-Received: by 2002:a17:907:6d20:b0:c15:9f0c:8d31 with SMTP id a640c23a62f3a-c246a5f67f3mr391862066b.2.1787325787404; Fri, 21 Aug 2026 08:23:07 -0700 (PDT) Received: from [127.0.0.1] (ip-109-193-028-127.um39.pools.vodafone-ip.de. [109.193.28.127]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c24591dc662sm506198566b.42.2026.08.21.08.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Aug 2026 08:23:06 -0700 (PDT) From: Marek Czernohous X-Google-Original-From: Marek Czernohous Date: Fri, 21 Aug 2026 17:23:01 +0200 Subject: [PATCH v4 1/3] drm/nouveau: unsubscribe the channel-kill event before the fence context To: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Lyude Paul , Danilo Krummrich , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Ben Skeggs Message-ID: <178732578167.167481.14789825868710929167@gmail.com> In-Reply-To: <178732578167.167481.5619512544301226563@gmail.com> References: <178732578167.167481.5619512544301226563@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nouveau_channel_del() tears the fence context down first and only drops the channel-kill subscription later, in the middle of the nvif object teardown: if (chan->fence) nouveau_fence(chan->cli->drm)->context_del(chan); ... nvif_object_dtor(&chan->vram); nvif_event_dtor(&chan->kill); The subscribed handler is nouveau_channel_killed(), which calls nouveau_channel_kill() and from there nouveau_fence_context_kill() on chan->fence. A kill event delivered in that window takes fctx->lock and walks fctx->pending on a fence context that context_del() has already freed. Nothing reaches this below Fermi today, because the subscription is gated on FERMI_CHANNEL_GPFIFO and nothing kills a channel there. On Fermi and newer the window is real but narrow, since a kill has to land exactly while the channel is being destroyed. That is reason enough on its own, which is why this carries a Fixes: tag. The last patch in this series subscribes Tesla channels as well; nothing kills those today, so it does not widen the exposure now, but it is the groundwork for a recovery path that would, and the ordering is better fixed before that lands than alongside it. Drop the subscription before anything it depends on is torn down. Fixes: ea13e5abf807 ("drm/nouveau: signal pending fences when channel has been killed") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5 Signed-off-by: Marek Czernohous Reviewed-by: Lyude Paul --- drivers/gpu/drm/nouveau/nouveau_chan.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_chan.c b/drivers/gpu/drm/nouveau/nouveau_chan.c index 598513f60449..f142f6310596 100644 --- a/drivers/gpu/drm/nouveau/nouveau_chan.c +++ b/drivers/gpu/drm/nouveau/nouveau_chan.c @@ -90,6 +90,14 @@ nouveau_channel_del(struct nouveau_channel **pchan) { struct nouveau_channel *chan = *pchan; if (chan) { + /* + * Drop the kill-event subscription first. Its handler + * dereferences chan->fence, which the fence context teardown + * below frees, so leaving it armed across the teardown leaves + * a window for a use-after-free. + */ + nvif_event_dtor(&chan->kill); + if (chan->fence) nouveau_fence(chan->cli->drm)->context_del(chan); @@ -100,7 +108,6 @@ nouveau_channel_del(struct nouveau_channel **pchan) nvif_object_dtor(&chan->nvsw); nvif_object_dtor(&chan->gart); nvif_object_dtor(&chan->vram); - nvif_event_dtor(&chan->kill); nvif_object_dtor(&chan->user); nvif_mem_dtor(&chan->mem_userd); nouveau_vma_del(&chan->sema.vma); -- 2.54.0