From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B0812E54D1 for ; Thu, 20 Aug 2026 19:10:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787253018; cv=none; b=QchWx3HoRQih3B0l6Qv+9jTK/KZ95W/pIgco6aOihoNUpuokDbzr41stJqp10eRUVKDgLlWS/OPKuPg6cceQ2a8seXxyYIw/WRyfCTJn77VOjP9rZ4t/+f/rbNrTONVxq96Pl6Dng/IlK3lf02tBm0tqsD9qIZYJXyjWJq1X9mM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787253018; c=relaxed/simple; bh=HVUQr72f7PRh/OYsTR9Bq12FWtesk1IWDV7lBhFkRdA=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=RsF4Vw/2i4LbWZ9w/Z6D0sZ3SmKuy2FWDn0ZjHdfocGfoPm5tHStNrV96PeCx03o8UGGAEtcXfnWvFg2PcShRd+Bq2Ay3bYkD+3mRRZB6PW7bLp7YzIaL3p0BKKyaoXbFruaRgemobP4bdCpO6Heo0Ffz+xr12dyyoB2mENRUNw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=h1pfy54r; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=MpOQLIO8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="h1pfy54r"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="MpOQLIO8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787253015; h=from:from: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=cnb/0LkhoX6JhBArFplr3WwxDbTfPxUble2GOXa/Bjk=; b=h1pfy54rFyfgN0PCdTiIZ/5ZQJgspyqFmAlqQ1qJ4Eq3+EejuFTrIQcTgVSPlAJYgo907t gTvk0JwMM5RN7bwAnLQ1jSWd3MLfkSEOoiJcfZIZnmXEJOMA0/tGWDp7mcJWDKbRoUiUJB uBg8HL3hGS62s6hJxL/56onR/mcqUgY= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-686-fBEcHh93NcWhfY9aJdMHmQ-1; Thu, 20 Aug 2026 15:10:12 -0400 X-MC-Unique: fBEcHh93NcWhfY9aJdMHmQ-1 X-Mimecast-MFC-AGG-ID: fBEcHh93NcWhfY9aJdMHmQ_1787253012 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-51c1c7f135bso2816981cf.0 for ; Thu, 20 Aug 2026 12:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1787253012; x=1787857812; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=cnb/0LkhoX6JhBArFplr3WwxDbTfPxUble2GOXa/Bjk=; b=MpOQLIO8LbuFBAE3rfPCup8CdcahKjkaB8zTe3MBXQocguwNzQJLHjK/m7c0Y+pXmA Nc5zlvMk+DjXyYzOJyse20BNUQR8I5rW0hmkqhi1p3EfOS1gIzx/CfgjyxyuEkGQSg+d +Hh7++L9uf5UF9u+YhLy2hXCi1O15lL9450TosrONm9EiWWi5K138dEuYNSnxV9tYNCi JO5NFiHa9RRV/E1D2clvGCDfRwMfuqEHAycwVd1poAItKmQIyhARbUxVKSayq3yWbOS4 MeqAE43y5xBewExiucK7MRwfjxwEXiJFXpPZPVJ33XpRcuAgb+UyDcTOoxj42a5RTgQ6 8OTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787253012; x=1787857812; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cnb/0LkhoX6JhBArFplr3WwxDbTfPxUble2GOXa/Bjk=; b=Cz+4vfPMJ8jmkQqQ3uqEmKIA6ng+WAGbS7btMzACAmsziLFCujR+v4fZSvovZIdSal W5pdIsCBDpcc2GQtkspLthxa4Qk1LsW3KeCFBMe84FYJZJH9y7FEcWojiyBW4w6Wz3Z3 /vdUhF/j6X7zMt3l7mTrol/m6QTPs75/QafxJX8PBvbUpGL0DZMh5fndM3pxKJtSW0tU AeumCN1G7Jds+aFDqhp23E4AmfPo8BCxPvmCPg2Bxc+hJpjVH2QP7vzf8Vz6J+lv5Vl9 uUNUZhh4opwryHpVscZQGJDhDQZRaWB5M6MZl0WrJNcB7HK7YumKcdIObdAgvjfE8GVS 1jnw== X-Gm-Message-State: AOJu0YwvMnT1r+7A8gv2X9i2A1P0KMrUbkyOB1tSpDq/3ZD8JrRxhx6O uQeqJDzoaXUtJmzIviWtf5yhI8BzLrdR6BbZfOKARKBOHGzCMzx52auMbOkIph6Qy9xxZk+ASAl +xmKnb0joHshP8FuRkMRI/UBPYY0XDjJCltrMSe2XKy+/OZsWICBKMV6I10U6fr/yVQ== X-Gm-Gg: AR+sD12I0WxI8YTZvzhbG5Z0uwxlJ3bBuXQlmsGKN53JqO/01XAn32xi1E+CWLf4LPO 2k8hHnE/UvDakrYfBZoBldNF5MyeKmmFvd9bOAJaLjhNby9fYKXwHVTyjqr+wWJQVMhXFEp6I2u BPqeNW3ur8WbCUTAGXAMU9dMOlRw0xvT3E3n0KG+yaeeq8BIeskWeMYnc3AuSwo3xK/fTCETg9o KhZInNjc20+ZLxVdXLV+CxrnKxyc97pMA1fuZ4CkVR3FQTGS0gsd5oaL8tKRrUuXNUaf3lELLdO Bh/jnYZVT+3qXDIiVESt29g7pvs63HMV0pH5wIbVyDagjguVliYUbXlfn62Lcbnb9Q3lnZu3 X-Received: by 2002:a05:622a:1112:b0:51c:22c5:daf5 with SMTP id d75a77b69052e-52df59fb918mr5347451cf.38.1787253011696; Thu, 20 Aug 2026 12:10:11 -0700 (PDT) X-Received: by 2002:a05:622a:1112:b0:51c:22c5:daf5 with SMTP id d75a77b69052e-52df59fb918mr5346851cf.38.1787253011087; Thu, 20 Aug 2026 12:10:11 -0700 (PDT) Received: from [192.168.8.4] ([100.0.180.93]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-90c5edb5097sm45137076d6.9.2026.08.20.12.10.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 12:10:10 -0700 (PDT) Message-ID: <4db24c901f8cf3315131e4b23cfe7a86dd26874a.camel@redhat.com> Subject: Re: [PATCH v3 1/4] drm/nouveau: unsubscribe the channel-kill event before the fence context From: lyude@redhat.com To: Marek Czernohous , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: linux-kernel@vger.kernel.org, Danilo Krummrich , David Airlie , Simona Vetter , Ben Skeggs Date: Thu, 20 Aug 2026 15:10:09 -0400 In-Reply-To: <20260812231330.705425-2-mczernohous@gmail.com> References: <20260812231330.705425-1-mczernohous@gmail.com> <20260812231330.705425-2-mczernohous@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 (3.58.3-1.fc43) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reviewed-by: Lyude Paul On Thu, 2026-08-13 at 01:13 +0200, Marek Czernohous wrote: > From: Marek Czernohous >=20 > 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: >=20 > if (chan->fence) > nouveau_fence(chan->cli->drm)->context_del(chan); > ... > nvif_object_dtor(&chan->vram); > nvif_event_dtor(&chan->kill); >=20 > 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. >=20 > 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. >=20 > Drop the subscription before anything it depends on is torn down. >=20 > 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 > --- > =C2=A0drivers/gpu/drm/nouveau/nouveau_chan.c | 9 ++++++++- > =C2=A01 file changed, 8 insertions(+), 1 deletion(-) >=20 > 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) > =C2=A0{ > =C2=A0 struct nouveau_channel *chan =3D *pchan; > =C2=A0 if (chan) { > + /* > + * Drop the kill-event subscription first.=C2=A0 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); > + > =C2=A0 if (chan->fence) > =C2=A0 nouveau_fence(chan->cli->drm)- > >context_del(chan); > =C2=A0 > @@ -100,7 +108,6 @@ nouveau_channel_del(struct nouveau_channel > **pchan) > =C2=A0 nvif_object_dtor(&chan->nvsw); > =C2=A0 nvif_object_dtor(&chan->gart); > =C2=A0 nvif_object_dtor(&chan->vram); > - nvif_event_dtor(&chan->kill); > =C2=A0 nvif_object_dtor(&chan->user); > =C2=A0 nvif_mem_dtor(&chan->mem_userd); > =C2=A0 nouveau_vma_del(&chan->sema.vma);