From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 6354C39098C for ; Thu, 11 Jun 2026 07:26:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781162802; cv=none; b=LejCpOV0N6DcP9pgevQT2l8bPNWzGIau1WjRUzlILHmNcQ6otBnyJyTcMT4gm8upV4Y0IsNtjwtRYSGA71dDt6nmbN0MS5Er2MQ/2fr6Hqqv/sh5K/45f6zq0JCKTOQ/XRSCHc++WHYxbGUfOamDFCCeoTX8QuD/UvEY0L2edR4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781162802; c=relaxed/simple; bh=ZIs0qLdvTqPBswYwzVk2sFKDDOeSl/qSRzWf38aKPPg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uOstQgO3iaJ0Wuj9n2YLkdF3zYQD+BVd6z46vh0KehRdu7zI9rwft8QmvdOiATeW6AGyRD+jSri230MB2gZqDFLeWZpXlrnm3Bwld46unUTdfQy5mYkicWjdYK6q7hGmhYI54ejnnG6i/RtrYPtyygYj0a7cDTbKhvxULE+tC5c= 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=cRiZSjYZ; arc=none smtp.client-ip=209.85.221.53 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="cRiZSjYZ" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-45ee449671fso510315f8f.2 for ; Thu, 11 Jun 2026 00:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781162800; x=1781767600; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jlBSAof3dxTHn+vmJPVfCbz7wQyEQetNaXJtCkbufXA=; b=cRiZSjYZcJ3nNn42VL8mZxmJV5K96U+B24mHd/9Yu2Lx/6F84WthTggWkyTI6pds89 YHUYNpLFtoNejh0OlDmQs/f/hm9+wB4XG0lOkXoDZAWfVNJPQFEKgKcpg4K5byAfTaJn MLDY2Scead5B3cQhJ+HPY25+2DPANiLfanpXEk7wiFbnglxYzyxYFo7HYghAR4/y4FzD Enuh5XFb0AkSfgLNVo70bmcJiZw2AOhUTDpis7Oz+fid3OFZ2wZmMgThlp8CW/MGOdLe TWZBDzKL5FfNE7VDho7+C5d4nGu94cZ/EoNuaybBiQJ+pgF7L9a6hegUbRpgJrSaCX1F CJsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781162800; x=1781767600; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=jlBSAof3dxTHn+vmJPVfCbz7wQyEQetNaXJtCkbufXA=; b=gm2xnfNDzxTiicjtMWCPeWiKgw2RoVZyfmW/bBkwnNk3OklUL4e95J9F0Z9OliCUuA mp2bPGk7dXScjhpBmXLbvbtNSgyZd4+wk/M0k2/GLxhYUQ3ps5Jz0sf1J9C6dSRRYaG+ 45j0XfhuN2+2AsIeFj0GaUyFVut1oOln1swvnfuo6v8AtdNShVFArJVWPzXCxGT+vXGI CRszvR5tyqH7wc9K/fP5s0T2GBsMLJS3VrIq4Js0Gh6zbtYLVMrvD0AhS/BEHretPeDv ggSKymYIy/CR2y5goDcgWRnjxve82BCTWP7912KVebYZeiPMxVvtemanVA7RSLPcC7Go LRAA== X-Forwarded-Encrypted: i=1; AFNElJ/q2OMiGnEGjuXKpChP1jcNK5F4iOMWaauOuxMejQnJKGvOVWTVRs6xw+MgdneftOeGoESH1+G7gH0CXgs=@vger.kernel.org X-Gm-Message-State: AOJu0YzDIcT2gDC2t+pmPlpVtGYJiY7wsgy0CoasG/bHeF3goaisPO3O dxj+bmSy+C3XVkLvm/GBY30YGCdTeaqJOdb+UeQWtT3v2G9xq7SlTWtc X-Gm-Gg: Acq92OHIIY+fYlFdaQ3pRt+84uWpW5ttYVkG76poAOLpLiFxCLONlKx6mbdopAGyyPL S9oWJhDjKwExAJZY5D4f2qqIle3pfpz3rcRr6HNOCm6uaNdUIf4MVwFH16oCTp6djJoqRBb7Usk I1C43f0JjKw+clPQSYouBRShksXLiRDdkrA6zz8y1Emd3z+fi/tzn0HCh5uAET6nNc5St0Zh72e o81RsFTLJdlalDYTk7ADIbXMtCc0NOnbTOuMP5s8YIddNZ72aWMMo++Bav9u9EVYxjYm0o4Datd YKtmgEymV63j98swHQhK5TrS1LCuRs7f7jH6OnltBfPv16SCRPfIWNeF3ngMF2xgYr3bC3he/EI oLaFgO0b0t4KRIwasFKWo7YAS5RlFfYnYyUEHlRHDT0V0odl+4Fhr6IPBCyhJt7zxHA1dzWAcyi cqwrAENsCCg52ide6+gf3EC2/TO2uGO6KXQ1CcFnMCAgVKfVwNOSFGP0qdDfDw22EuihpE6YUUh Oo9swZBVe21ch3KR0TrOvmM4Q== X-Received: by 2002:a05:600c:1f83:b0:490:3fdd:d344 with SMTP id 5b1f17b1804b1-490e558813fmr7830845e9.1.1781162799452; Thu, 11 Jun 2026 00:26:39 -0700 (PDT) Received: from localhost.localdomain (ip-109-193-028-127.um39.pools.vodafone-ip.de. [109.193.28.127]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490e2c7ea21sm42585795e9.1.2026.06.11.00.26.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2026 00:26:38 -0700 (PDT) From: Marek Czernohous X-Google-Original-From: Marek Czernohous To: Lyude Paul , Danilo Krummrich Cc: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org, Fab Stz Subject: [PATCH v2 2/2] drm/nouveau/kms: guard NULL crtc in nv50_sor_atomic_disable() Date: Thu, 11 Jun 2026 09:26:34 +0200 Message-ID: <66ea307dd4fa080db27b2b9a0caa31b562d72c2b.1781162589.git.marek@czernohous.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Marek Czernohous From: Marek Czernohous nv50_sor_atomic_disable() unconditionally computes nv50_head(nv_encoder->crtc) and dereferences the result a few lines later. 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. 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 small bogus pointer, so the subsequent head dereferences fault and the kernel oopses. 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. 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. 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 Signed-off-by: Marek Czernohous --- v1 -> v2: dropped the nvif_outp_release() call from the early return (the release is owned by the commit_tail release loop; calling it here released twice and detached the OR before the disable flush); turned the silent return into drm_WARN_ON_ONCE(); reworded the commit message (the v1 "race between atomic_check and atomic_commit" wording did not match the mechanism). v1: https://lore.kernel.org/nouveau/20260409172126.115441-3-marek@czernohous.de/ drivers/gpu/drm/nouveau/dispnv50/disp.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/nouveau/dispnv50/disp.c b/drivers/gpu/drm/nouveau/dispnv50/disp.c index 6c3a871..597bc64 100644 --- a/drivers/gpu/drm/nouveau/dispnv50/disp.c +++ b/drivers/gpu/drm/nouveau/dispnv50/disp.c @@ -1565,14 +1565,28 @@ static void nv50_sor_atomic_disable(struct drm_encoder *encoder, struct drm_atomic_state *state) { struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); - struct nv50_head *head = nv50_head(nv_encoder->crtc); + struct nv50_head *head; #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT struct nouveau_connector *nv_connector = nv50_outp_get_old_connector(state, nv_encoder); struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); struct nouveau_backlight *backlight = nv_connector->backlight; struct drm_dp_aux *aux = &nv_connector->aux; int ret; +#endif + + /* nv_encoder->crtc is the driver's shadow pointer, set in + * .atomic_enable and cleared at the end of this function. 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). The + * encoder release is handled by the commit_tail release loop, so + * there is nothing to clean up here. + */ + if (drm_WARN_ON_ONCE(encoder->dev, !nv_encoder->crtc)) + return; + head = nv50_head(nv_encoder->crtc); +#ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT if (backlight && backlight->uses_dpcd) { ret = drm_edp_backlight_disable(aux, &backlight->edp_info); if (ret < 0) -- 2.53.0