| Message ID | 20260814203542.1405135-5-lyude@redhat.com (mailing list archive) |
|---|---|
| State | New |
| Headers |
Return-Path: <linux-sunxi+bounces-25182-sunxi=pue.re@lists.linux.dev> X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id D43D11C0100 for <noreply@patchwork.local>; Fri, 14 Aug 2026 22:39:26 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=redhat.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-25182-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-25182-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 24EED306F4FC for <noreply@patchwork.local>; Fri, 14 Aug 2026 20:36:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 03A953DC4AB; Fri, 14 Aug 2026 20:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aIuSW2Yc" X-Original-To: linux-sunxi@lists.linux.dev 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 524F63CC314 for <linux-sunxi@lists.linux.dev>; Fri, 14 Aug 2026 20:36:22 +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=1786739783; cv=none; b=rV3UIHcPBIWltR/0rDGvlVPMsgnLPG/wY97cusGWgGlKAGJlqhQfTJCOktydXq9Rj8nEt5EB+adRh/Oujlxit/yfAhllJfbtvJ5qU4D+3fKC7/kTCOXgwsCN/TYzDotqNcDBI/8XANG0x6qc4JCxGfh/Lk2z+ceK8Q72oVDU57E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786739783; c=relaxed/simple; bh=eedkQEXrorNp37ksZK/2amUEphp9uBOtzRKZqiLu8RY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:content-type; b=ssFyIff3gooUKSWMPD58GdmkhwAPGZaXOjALjAAr2M6WK+4JKCfNHQDq+hWs4sr6qOi49cwFdFTSN++v/HmT3y2CevwYKxpo/uFUdg6NrXv+tEAjoFYV5bl8eY21c+BMph1Jpt9NtV63X/ZC46geYPFetSJYPBpnPB2XkUiRcGE= 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=aIuSW2Yc; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786739781; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UEzS7cgh0s3kpDJoSKFSaeUbfz26XKFwvX4uV6Y0kQg=; b=aIuSW2YcYbKcOASFqM3CuHW+dPBpE4EH9vohusOZLAswwdY5aY0M5RQZypE6mNIdu5dT7Q R6Sjv69VpVDpuiOfY86yWyvLu800YexTVwvn8jx/TT9pyeYafgLPJhGLQNx1bcEXjkZvXC +s76asttlkjW+vQOoNYWHzylMrh5TsQ= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-oqOvZT7bMEW5oR1aBhdpHw-1; Fri, 14 Aug 2026 16:36:07 -0400 X-MC-Unique: oqOvZT7bMEW5oR1aBhdpHw-1 X-Mimecast-MFC-AGG-ID: oqOvZT7bMEW5oR1aBhdpHw_1786739765 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8FF7D195608A; Fri, 14 Aug 2026 20:36:04 +0000 (UTC) Received: from GoldenWind.lan (unknown [10.22.64.233]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 94B5E197751A; Fri, 14 Aug 2026 20:36:00 +0000 (UTC) From: Lyude Paul <lyude@redhat.com> To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, freedreno@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, nouveau@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-sunxi@lists.linux.dev, asahi@lists.linux.dev, linux-stm32@st-md-mailman.stormreply.com, linux-samsung-soc@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-mediatek@lists.infradead.org, intel-gfx@lists.freedesktop.org, linux-aspeed@lists.ozlabs.org, linux-rockchip@lists.infradead.org, linux-tegra@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-mips@vger.kernel.org, amd-gfx@lists.freedesktop.org, spice-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org, imx@lists.linux.dev Subject: [PATCH 4/5] drm/vblank: Use drm_for_each_crtc() in drm_vblank_init() Date: Fri, 14 Aug 2026 16:35:32 -0400 Message-ID: <20260814203542.1405135-5-lyude@redhat.com> In-Reply-To: <20260814203542.1405135-1-lyude@redhat.com> References: <20260814203542.1405135-1-lyude@redhat.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: <linux-sunxi.lists.linux.dev> List-Subscribe: <mailto:linux-sunxi+subscribe@lists.linux.dev> List-Unsubscribe: <mailto:linux-sunxi+unsubscribe@lists.linux.dev> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-MFC-PROC-ID: OxgY8D9P-JioH8mBFnOhMatzEW5xPZ37gqnchW_WnwI_1786739765 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= |
| Series |
drm/vblank: Enforce all-or-nothing vblank support
|
|
Commit Message
Lyude Paul
Aug. 14, 2026, 8:35 p.m. UTC
No functional changes yet, we just should be using this iterator here
instead of manually counting the number of CRTCs anyhow.
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
drivers/gpu/drm/drm_vblank.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
Comments
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Calling `drm_vblank_init` before creating CRTCs results in a zero-size allocation, leading to a kernel crash when vblank features are later used. -- --- Patch [4]: [PATCH 4/5] drm/vblank: Use drm_for_each_crtc() in drm_vblank_init() --- commit 4aec980231f556c8a36b5294d67b3d582d49d623 Author: Lyude Paul <lyude@redhat.com> drm/vblank: Use drm_for_each_crtc() in drm_vblank_init() This patch updates drm_vblank_init() to use the drm_for_each_crtc() iterator instead of manually counting the number of CRTCs. > diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c > index 17283e8920378..d57405050554f 100644 > --- a/drivers/gpu/drm/drm_vblank.c > +++ b/drivers/gpu/drm/drm_vblank.c > @@ -547,19 +547,20 @@ static void drm_vblank_init_release(struct drm_device *dev, void *ptr) > int drm_vblank_init(struct drm_device *dev) > { > int ret; > - unsigned int num_crtcs = dev->mode_config.num_crtc; > - unsigned int i; > + struct drm_crtc *crtc; > > spin_lock_init(&dev->vbl_lock); > spin_lock_init(&dev->vblank_time_lock); > > - dev->vblank = drmm_kcalloc(dev, num_crtcs, sizeof(*dev->vblank), GFP_KERNEL); > + dev->vblank = drmm_kcalloc(dev, dev->mode_config.num_crtc, > + sizeof(*dev->vblank), GFP_KERNEL); > if (!dev->vblank) > return -ENOMEM; > > dev->has_hw_vblank = true; > > - for (i = 0; i < num_crtcs; i++) { > + drm_for_each_crtc(crtc, dev) { [Severity: Critical] Could this change lead to an uninitialized vblank array and subsequent page fault for drivers that initialize vblank before creating CRTCs? For example, in vkms_drv.c:vkms_create(), drm_vblank_init() is called before vkms_modeset_init() creates the CRTCs: ret = drm_vblank_init(&vkms_device->drm); if (ret) { DRM_ERROR("Failed to vblank\n"); goto out_devres; } ret = vkms_modeset_init(vkms_device); Because the CRTCs are not yet created at this point, dev->mode_config.num_crtc is 0. The allocation for the vblank array becomes a 0-byte allocation, returning ZERO_SIZE_PTR (0x10). The drm_for_each_crtc() loop then executes 0 times, and drm_vblank_init() successfully returns 0. When userspace later calls DRM_IOCTL_WAIT_VBLANK, the kernel looks up the CRTC using drm_vblank_crtc(dev, pipe). This returns a pointer into the array, which evaluates to ZERO_SIZE_PTR + pipe * sizeof(...). Will dereferencing this pointer cause an immediate kernel OOPS? > + unsigned int i = crtc->index; > struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, i); > > vblank->dev = dev;
diff --git a/drivers/gpu/drm/drm_vblank.c b/drivers/gpu/drm/drm_vblank.c index 17283e8920378..d57405050554f 100644 --- a/drivers/gpu/drm/drm_vblank.c +++ b/drivers/gpu/drm/drm_vblank.c @@ -547,19 +547,20 @@ static void drm_vblank_init_release(struct drm_device *dev, void *ptr) int drm_vblank_init(struct drm_device *dev) { int ret; - unsigned int num_crtcs = dev->mode_config.num_crtc; - unsigned int i; + struct drm_crtc *crtc; spin_lock_init(&dev->vbl_lock); spin_lock_init(&dev->vblank_time_lock); - dev->vblank = drmm_kcalloc(dev, num_crtcs, sizeof(*dev->vblank), GFP_KERNEL); + dev->vblank = drmm_kcalloc(dev, dev->mode_config.num_crtc, + sizeof(*dev->vblank), GFP_KERNEL); if (!dev->vblank) return -ENOMEM; dev->has_hw_vblank = true; - for (i = 0; i < num_crtcs; i++) { + drm_for_each_crtc(crtc, dev) { + unsigned int i = crtc->index; struct drm_vblank_crtc *vblank = drm_vblank_crtc(dev, i); vblank->dev = dev;