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.129.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 D84512E7BD3 for ; Tue, 18 Aug 2026 20:44:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787085855; cv=none; b=XG1xw74bHQfci6vK8OwQVypxe+ihYqDtMlehCoFjTqbmMrEZYujRLTSXY7F6q+jE1Wo3VFKuCke1wKaFvwniW/zJ05pkOdbPT5O6sHoFM8zAa6ZZr9GL98SKqYD/J43XbU1qryt7jVA+9VDh8WorxtjqGfZh/Sixu8qTw8AFYtI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787085855; c=relaxed/simple; bh=DVOtRCeL9c23dUvIx58yn6v8FS40InWm2+KWJBV+qao=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=f2g2ms+0Mv2z6d7tu3fanEe38ch0Eo0t0yePtBlRQnvX6/Zk5ete/l8RwCZ/uhMUun7yn388fXdGfRzVVFRX8MLKsTQHSLXCZ+5ql+lheHfLZ4yZpogvXQu8iUEAzee/cu3qJvBumXClfTZ5ps+SzO1/sQjGbkQW37bHNMpyTqQ= 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=NhZJK+Zs; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=kuaGfmKv; arc=none smtp.client-ip=170.10.129.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="NhZJK+Zs"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="kuaGfmKv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787085852; 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=IrRWDLtIAaM5eStqn60ea6A/t2RWeOJ1hays+yS0yG0=; b=NhZJK+ZsGmaaQI/IyHEvXBFGK7R6wVo64l+QR0+tDmRrJXp3FpwxX+VasSQ1Z38ie7A35r FiquJd4fx+prxlHwmmlqnF6+xpb9nN9rxZl2OX2BJ7TVVhtI0byLBMhPyaYPHtdtEiWoBl WH1b+epfcsu5F/6/rdVSlAGGQ8XIr0M= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-Ifvm0tPsORKZBX8eC3NVYg-1; Tue, 18 Aug 2026 16:44:11 -0400 X-MC-Unique: Ifvm0tPsORKZBX8eC3NVYg-1 X-Mimecast-MFC-AGG-ID: Ifvm0tPsORKZBX8eC3NVYg_1787085851 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-51c083f1818so3181611cf.0 for ; Tue, 18 Aug 2026 13:44:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1787085851; x=1787690651; 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=IrRWDLtIAaM5eStqn60ea6A/t2RWeOJ1hays+yS0yG0=; b=kuaGfmKvoFQvGpkA/sRGe8pE44apGx4sSyFtT+Kiidq+0uHOwTmPW+WulIPTLcZcWs BS3Kq/Orw/tr3Wqb135M688JnE/O6wHHUq5SAz77JOdd9etnu4ZD7Hoi0lkkYprdjz+Z jsFVcd4qvgs6tzifI7I5gR1DVIxtpfuloGWmPHfDJSCzPWzSbftc4iPuUeWqNPGc5sG4 9b5e/n/BL/ZXiM12fjX2aTclnm4IRmezh/NSb2hZhYDYhMPDfR+gd9cza7to9eo2cWpD GtTZxRpHAHw050K08P3xUH1eoaW/pheULs8pQb1uDya4yu7Dec9ASXfx/weddz3QA10i 0uhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787085851; x=1787690651; 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=IrRWDLtIAaM5eStqn60ea6A/t2RWeOJ1hays+yS0yG0=; b=bx5p1LkdUDRZfsoj8L+yiSB0syGtldeoB0cEM2Unklzxl7PQMcqkEAqXfQh+l1AwYT SjiN7cI1tMk5b+z/CIpOgxNQcAxJraw8PYIpui1AtYOfdVKrniIkKDcnowwwHlR9OzOd 0DmAASeGB2q6hviD9z++xcolG+otG3U5B0KiW22mKDoue016/s2upcd+X7Nh+BeohIMH SdvkypcWaTTZdjSQue56I0HW/urGQunV+2NCcODYYMuaNybuO0xr16Vvau+dkbeSrcAf r0RwJkCwCR+2wunzDfyecgPQ2LEOaZGiDoiHCJf5X0ez4gSmV3P9YGsOyNBl6XyNnHvN WMoA== X-Gm-Message-State: AOJu0Yy7tHko4vOsrlH0CjoKqh2OgnFVkpWTRI86fy+FyWd6JDBG7/2U CFfXXLCmV44M6A28hzmqmrYUZHnOcmLEn4g66VliHD0JbKSkcUuj3sTQPAZuwMij0rvzIrHXkrp o/G/aQ8CUeEdcMJrv/gqq9kpaPL6kU340fQofZgqQb/iD29PENYcDsbRiGelbCS/3Og== X-Gm-Gg: AR+sD13aIQCHwsGg95FZrgiWWr5Z1S6utKk8z9K/P2xgnU+dH6R8ilS89ZO9VDzL0F4 wrUXgCtPjpz+6ktazJXhJIiObwNb8qgB9dW9Qssh/uZXkErWL+utuD5x7RX2yUVpxgjJJC8kvGF 4VaD6QXpNJc7P8Dt9U3esfUmC5LDYUCfultBZQi2jw7yzascPDzSLCtoasH+dbSk7ROr82z9hq5 HVkWr2m1eAZMrScRfCjoPPT+a78j2i0ZbOb+tgWpWa+OSufX8E4EHS3wc28WNyj6GWAXjZm2B8O xyKo8i8XTFNlScTD7z7A/1iRMcYdl4PcuGUpZzTK1WQfUejIifAGCKpQX6Sv3EHAvADjyrGd X-Received: by 2002:a05:622a:410e:b0:51c:7d0:7ed7 with SMTP id d75a77b69052e-52dd3313d61mr8945741cf.39.1787085850592; Tue, 18 Aug 2026 13:44:10 -0700 (PDT) X-Received: by 2002:a05:622a:410e:b0:51c:7d0:7ed7 with SMTP id d75a77b69052e-52dd3313d61mr8945411cf.39.1787085850093; Tue, 18 Aug 2026 13:44:10 -0700 (PDT) Received: from [192.168.8.4] ([100.0.180.93]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-52db610b491sm47319561cf.8.2026.08.18.13.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 13:44:09 -0700 (PDT) Message-ID: Subject: Re: [PATCH v4 2/2] drm/nouveau/kms: guard NULL crtc in nv50_sor_atomic_disable() 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 Date: Tue, 18 Aug 2026 16:44:08 -0400 In-Reply-To: <178688574402.522643.5471719764843371376@gmail.com> References: <178688574400.522643.6695278742335367229@gmail.com> <178688574402.522643.5471719764843371376@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 This isn't correct On Sun, 2026-08-16 at 15:09 +0200, Marek Czernohous wrote: > From: Marek Czernohous >=20 > nv50_sor_atomic_disable() unconditionally computes > nv50_head(nv_encoder->crtc) and dereferences the result a few lines > later.=C2=A0 nv_encoder->crtc is nouveau's own shadow pointer, set in > .atomic_enable and cleared at the end of .atomic_disable. > Commit f575f2bdb6c3 ("drm/nouveau/kms/nv50-: Remove (nv_encoder- > >crtc) > checks in ->disable callbacks") removed the NULL check here, > reasoning that the atomic helpers never call ->disable without a > crtc.=C2=A0 On NVAC (MCP79) under Wayland sessions (observed with Weston'= s > DRM backend and with labwc/wlroots) we have hit the NULL case in > practice during session teardown and VT switches: disable runs > without > (or after) its matching enable, and because nv50_head() is > container_of(), the NULL does not stay NULL but becomes a bogus > non-NULL pointer, so the subsequent head dereferences fault and the > kernel oopses. In the future you should probably put a backtrace if you've seen this in the wild >=20 > Restore the guard, as drm_WARN_ON_ONCE() instead of a silent return: > a NULL crtc here still indicates a state-tracking inconsistency that > should stay visible.=C2=A0 Return without touching the output; in this > path > either enable never ran (nothing to tear down) or an earlier disable > already did the teardown, and the encoder release is handled by the > commit_tail release loop in both cases.=C2=A0 (That loop then rejects the > release of a never-acquired output with -EINVAL in the nvif layer, > which is harmless; the vanilla code oopsed before ever reaching it.) >=20 > The same inconsistent-state path can also leave the encoder without > an > old connector state, in which case nv50_outp_get_old_connector() > returns NULL while the backlight teardown dereferenced it > unconditionally, so the oops would only have moved there.=C2=A0 Hoist the > guard above all of that and look at the old connector only after > checking it. >=20 > Fixes: f575f2bdb6c3 ("drm/nouveau/kms/nv50-: Remove (nv_encoder- > >crtc) checks in ->disable callbacks") > Cc: > Tested-by: Fab Stz > Assisted-by: Claude:claude-opus-4-7 > Assisted-by: Claude:claude-opus-4-8 > Assisted-by: Claude:claude-opus-5 > Signed-off-by: Marek Czernohous > --- > =C2=A0drivers/gpu/drm/nouveau/dispnv50/disp.c | 30 ++++++++++++++++++++--= - > -- > =C2=A01 file changed, 25 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c > b/drivers/gpu/drm/nouveau/dispnv50/disp.c > index 364227f5456f..f532b0ed8880 100644 > --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c > +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c > @@ -1565,16 +1565,36 @@ static void > =C2=A0nv50_sor_atomic_disable(struct drm_encoder *encoder, struct > drm_atomic_commit *state) > =C2=A0{ > =C2=A0 struct nouveau_encoder *nv_encoder =3D > nouveau_encoder(encoder); > - struct nv50_head *head =3D nv50_head(nv_encoder->crtc); > + struct nv50_head *head; > =C2=A0#ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT > - struct nouveau_connector *nv_connector =3D > nv50_outp_get_old_connector(state, nv_encoder); > + struct nouveau_connector *nv_connector; > =C2=A0 struct nouveau_drm *drm =3D nouveau_drm(nv_encoder- > >base.base.dev); > - struct nouveau_backlight *backlight =3D nv_connector- > >backlight; > - struct drm_dp_aux *aux =3D &nv_connector->aux; > + struct nouveau_backlight *backlight; > =C2=A0 int ret; > +#endif > =C2=A0 > + /* nv_encoder->crtc is the driver's shadow pointer, set in It's actually an outdated variable from the pre-atomic days > + * .atomic_enable (and by the boot-time hardware readback) > and We don't set nv_encoder->crtc at the boot-time hardware state readback. > + * cleared at the end of this function.=C2=A0 NULL here > + * means disable-without-enable or a double disable; bail > before > + * container_of() turns it into a bogus head pointer > (checking the > + * result would not work, container_of(NULL) is never > NULL).=C2=A0 The > + * encoder release is handled by the commit_tail release > loop, so > + * there is nothing to clean up here. > + */ this is way too verbose > + if (drm_WARN_ON_ONCE(encoder->dev, !nv_encoder->crtc)) > + return; > + head =3D nv50_head(nv_encoder->crtc); this isn't the bug, the bug is that we're reading nv_encoder->crtc at all here. > + > +#ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT > + /* The same inconsistent-state path can leave us without an > old > + * connector state, so check before touching it. > + */ > + nv_connector =3D nv50_outp_get_old_connector(state, > nv_encoder); > + backlight =3D nv_connector ? nv_connector->backlight : NULL; > =C2=A0 if (backlight && backlight->uses_dpcd) { > - ret =3D drm_edp_backlight_disable(aux, &backlight- > >edp_info); > + ret =3D drm_edp_backlight_disable(&nv_connector->aux, > + &backlight- > >edp_info); This doesn't need changing either if we just fix where the encoder came from. I'll send out proper fixes for this in a moment > =C2=A0 if (ret < 0) > =C2=A0 NV_ERROR(drm, "Failed to disable backlight > on [CONNECTOR:%d:%s]: %d\n", > =C2=A0 nv_connector->base.base.id, > nv_connector->base.name, ret);