Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 EA02B36998C for ; Mon, 22 Jun 2026 09:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782119466; cv=none; b=ddDNj9JOXVDfR8xNHuobB61AUyMv7yxtP/4eEf6ZXYM6lJT1IO4m7ZuBiHN2P7vTsIywUMh8dAajlbwy05fpHLZWK8XMupiPhuPvqrfGr3kT/LEX6UKCVqk5JTDcyBJbEt7z8ug/d9yig2z46MscHh61s2ECj2sXP9Y7xWGQdzc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782119466; c=relaxed/simple; bh=7Sec4ZkzWxJvlyi5skY3VxsKThiVWFBdWwaVv3bHgeg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EG0X5pKt75xnloVCdclbT6MVwfk+0GdWsSH6+Gda6FqBkBPnr2XjDLiDVtHrvgNY7sgyXkl9a28xKPT6uXQGI6aBBfXg4MmPeQLs0vE6ct0c4b9UvVEfwRb4U1ECgJ4bwHmOnJswFKipD7MkB0M//wrn/+WoJ6c5INxRt5Bq2lc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=J+QaSH2z; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h2L+B98h; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=J+QaSH2z; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=h2L+B98h; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="J+QaSH2z"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h2L+B98h"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="J+QaSH2z"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="h2L+B98h" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 11EF675B91; Mon, 22 Jun 2026 09:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1782119463; h=from:from:reply-to: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:autocrypt:autocrypt; bh=M3oBiE9Md4+R04eweGOQRriPVKjOYkq8A1G9mu1OXUo=; b=J+QaSH2zR4eqpR6UEZD4WaL81gDrn+GizVKBki+g4irrMjjTxkpeIVXLoeG7W3Ww9A3eVA 54ArG/l5/kuZy6nsIBAcw09M//o8O10nHt93C7c6jwICMn3yKcY2EmvQOeGlgS/BfcOjX0 Z3lPJiRHkTwNC8/NTIs2CjiOEf3RitA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1782119463; h=from:from:reply-to: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:autocrypt:autocrypt; bh=M3oBiE9Md4+R04eweGOQRriPVKjOYkq8A1G9mu1OXUo=; b=h2L+B98hbh4/j3ad51Llfl83chE8lXyETAsPYJzJm6vdDNgJ6ks6VnLM19vOOky8o2+w0q 0VCrz+vluYT5TZDg== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=J+QaSH2z; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=h2L+B98h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1782119463; h=from:from:reply-to: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:autocrypt:autocrypt; bh=M3oBiE9Md4+R04eweGOQRriPVKjOYkq8A1G9mu1OXUo=; b=J+QaSH2zR4eqpR6UEZD4WaL81gDrn+GizVKBki+g4irrMjjTxkpeIVXLoeG7W3Ww9A3eVA 54ArG/l5/kuZy6nsIBAcw09M//o8O10nHt93C7c6jwICMn3yKcY2EmvQOeGlgS/BfcOjX0 Z3lPJiRHkTwNC8/NTIs2CjiOEf3RitA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1782119463; h=from:from:reply-to: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:autocrypt:autocrypt; bh=M3oBiE9Md4+R04eweGOQRriPVKjOYkq8A1G9mu1OXUo=; b=h2L+B98hbh4/j3ad51Llfl83chE8lXyETAsPYJzJm6vdDNgJ6ks6VnLM19vOOky8o2+w0q 0VCrz+vluYT5TZDg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E2606779A8; Mon, 22 Jun 2026 09:11:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 72y0NSb8OGq0JQAAD6G6ig (envelope-from ); Mon, 22 Jun 2026 09:11:02 +0000 Message-ID: <10f7b889-9e4c-40cd-9aca-b545b9675a37@suse.de> Date: Mon, 22 Jun 2026 11:11:02 +0200 Precedence: bulk X-Mailing-List: sashiko-reviews@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] drm/fb_helper: Determine proper crtc_index within drm_fb_helper_fb_dirty To: Icenowy Zheng , "H. Nikolaus Schaller" , sashiko-reviews@lists.linux.dev Cc: dri-devel@lists.freedesktop.org, Andreas Kemnade References: <5118b37e579cec220f2d2b6ab0bb1ecfb67f0d5c.1781803617.git.hns@goldelico.com> <20260618174310.70DB11F000E9@smtp.kernel.org> <50FDBC3B-BFC2-4BC6-B216-78C2C24D9E30@goldelico.com> <1c9e0e24-9c4a-4259-8700-cf9e5fd60ca3@suse.de> <8773121ff24730f0b4c2d0037132e4507380a77f.camel@iscas.ac.cn> Content-Language: en-US From: Thomas Zimmermann Autocrypt: addr=tzimmermann@suse.de; keydata= xsBNBFs50uABCADEHPidWt974CaxBVbrIBwqcq/WURinJ3+2WlIrKWspiP83vfZKaXhFYsdg XH47fDVbPPj+d6tQrw5lPQCyqjwrCPYnq3WlIBnGPJ4/jreTL6V+qfKRDlGLWFjZcsrPJGE0 BeB5BbqP5erN1qylK9i3gPoQjXGhpBpQYwRrEyQyjuvk+Ev0K1Jc5tVDeJAuau3TGNgah4Yc hdHm3bkPjz9EErV85RwvImQ1dptvx6s7xzwXTgGAsaYZsL8WCwDaTuqFa1d1jjlaxg6+tZsB 9GluwvIhSezPgnEmimZDkGnZRRSFiGP8yjqTjjWuf0bSj5rUnTGiyLyRZRNGcXmu6hj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n3T0TtrijKP4A SAQO9xD1Zk9/61JWk8OysuIh7MXkl0fxbRKWE93XeQBhIJHQfnc+YBLprdnxR446Sh8Wn/2D Ya8cavuWf2zrB6cZurs048xe0UbSW5AOSo4V9M0jzYI4nZqTmPxYyXbm30Kvmz0rYVRaitYJ 4kyYYMhuULvrJDMjZRvaNe52tkKAvMevcGdt38H4KSVXAylqyQOW5zvPc4/sq9c= In-Reply-To: <8773121ff24730f0b4c2d0037132e4507380a77f.camel@iscas.ac.cn> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Flag: NO X-Rspamd-Action: no action X-Spam-Level: X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; TO_DN_SOME(0.00)[]; FUZZY_RATELIMITED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[sashiko.dev:url,suse.de:mid,suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:url]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:106:10:150:64:167:received]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Queue-Id: 11EF675B91 X-Spam-Score: -4.51 Hi Am 19.06.26 um 18:59 schrieb Icenowy Zheng: > 在 2026-06-19五的 10:50 +0200,Thomas Zimmermann写道: >> (cc Icenowy) >> >> Hi, >> >> there are a number of similar reports. Does the attached patch fix >> the >> problem. It picks up what you do, but in a more correct way. > Yes, this patch looks okay, but I wonder whether the crtc index query > should be done in drm_client_modeset_wait_for_vblank() instead. There's another call to this helper from the ioctl helper. It has a lengthy comment about using CRTC 0 only and how these indices don't make much sense with fbdev. I'll look into generalizing the code a bit, but I'd rather not fully integrate the logic into drm_client_modeset_wait_for_vblank(). Best regards Thomas > > I will test this patch this weekend. > > Thanks, > Icenow > >> Best regards >> Thomas >> >> Am 18.06.26 um 19:56 schrieb H. Nikolaus Schaller: >>>> Am 18.06.2026 um 19:43 schrieb sashiko-bot@kernel.org: >>>> >>>> Thank you for your contribution! Sashiko AI review found 3 >>>> potential issue(s) to consider: >>>> - [High] Lockless access to `crtc->state` and `crtc->primary- >>>>> state` can lead to a Use-After-Free due to concurrent atomic >>>> commits. >>>> - [High] The patch breaks vblank synchronization for legacy (non- >>>> atomic) DRM drivers. >>>> - [Medium] The logic selects the first matching CRTC instead of >>>> the last active one, contradicting the commit message. >>>> -- >>>> >>>> commit 0337b26b606b4d905d72ea2be31bcb984fe62c6e >>>> Author: H. Nikolaus Schaller >>>> >>>> drm/fb_helper: Determine proper crtc_index within >>>> drm_fb_helper_fb_dirty >>>> >>>> This commit updates the dirty framebuffer worker to search for a >>>> matching >>>> active CRTC instead of hardcoding the wait for vblank to CRTC >>>> index 0. It >>>> aims to avoid vblank timeouts when CRTC 0 is inactive. >>>> >>>>> diff --git a/drivers/gpu/drm/drm_fb_helper.c >>>>> b/drivers/gpu/drm/drm_fb_helper.c >>>>> --- a/drivers/gpu/drm/drm_fb_helper.c >>>>> +++ b/drivers/gpu/drm/drm_fb_helper.c >>>> [ ... ] >>>>> @@ -232,9 +232,23 @@ static void drm_fb_helper_fb_dirty(struct >>>>> drm_fb_helper *helper) >>>>> struct drm_clip_rect clip_copy; >>>>> unsigned long flags; >>>>> int ret; >>>>> + unsigned int crtc_index = 0; >>>>> + struct drm_crtc *crtc; >>>>> >>>>> mutex_lock(&helper->lock); >>>>> - drm_client_modeset_wait_for_vblank(&helper->client, 0); >>>>> + >>>>> + drm_for_each_crtc(crtc, dev) { >>>>> + if (crtc->primary && crtc->primary->state && >>>>> +    crtc->primary->state->fb == helper->fb && >>>>> +    crtc->state && crtc->state->active) { >>>> [Severity: High] >>>> Can this lockless access to crtc->state and crtc->primary->state >>>> result in a >>>> use-after-free? >>> No idea... >>> >>>> The drm_fb_helper_fb_dirty() function holds helper->lock, but >>>> does not hold >>>> the DRM modeset locks required to protect these state pointers. >>>> During a >>> Which locks are exactly recommended to add? What is their >>> name/pointer? >>> >>>> concurrent atomic modeset commit, the DRM core allocates new >>>> state objects, >>>> swaps them into place, and frees the old objects via kfree(). >>>> >>>> If this code reads an old state pointer and gets preempted, could >>>> it then >>>> dereference the pointer after it has been freed by the concurrent >>>> commit? >>>> >>>> [Severity: High] >>>> Does this break vblank synchronization for legacy non-atomic DRM >>>> drivers? >>>> Legacy drivers do not use the atomic modesetting infrastructure, >>>> so their >>>> crtc->state and crtc->primary->state pointers remain NULL. Since >>>> the condition >>>> above requires these pointers to be non-NULL, the loop will skip >>>> the vblank >>>> wait entirely for legacy drivers. This skips the intended rate- >>>> limiting >>>> behavior and could lead to unbounded damage worker execution. >>> What is the solution? And is this important. >>> >>> Before d8c4bddcd8bcb ("drm/fb-helper: Synchronize dirty worker with >>> vblank") >>> >>> there was also no rate-limiting behavior. >>> >>>>> + crtc_index = drm_crtc_index(crtc) + 1; >>>>> + break; >>>> [Severity: Medium] >>>> The commit message states "If multiple CRTCs match, the last >>>> active one is >>>> selected." Does the break statement here cause the first active >>>> CRTC to be >>>> selected instead, bypassing the remaining matches in the list? >>> Yes, that is correct. The description is indeed wrong. >>> >>>>> + } >>>>> + } >>>>> + >>>>> + if (crtc_index > 0) >>>>> + drm_client_modeset_wait_for_vblank(&helper->client, >>>>> crtc_index - 1); >>>>> + >>>>> mutex_unlock(&helper->lock); >>>> -- >>>> Sashiko AI review · >>>> https://sashiko.dev/#/patchset/5118b37e579cec220f2d2b6ab0bb1ecfb67f0d5c.1781803617.git.hns@goldelico.com?part=1 -- -- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)