From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=220.197.32.86 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796368476; b=ZxC89hsTlWIXo0YgdnKhqajNTvp8SgNYk++1hn3xb1kcJQoRhjsYR5Z1w8P4FsdeQ2oj vesokYLID8ZOiuqI6pedyW52RmX/kWSRdDMkarlzrB9goU4lwBKUK3JHwaL6CtK1UkeUD yZFQlsjQEHJwgW5kISkFBXxEM2LmqVPaluMe5WeonChleDtcckLq857Df+Vx6BePa4tnU nt99hFGuQr88N3QanEIL7IDhFK95wEHCZy/wSxDTJP7xDFp2nH3bip6JeFdcoOlgIT7yd p/tb4EyusXN+0MiUtkZN9237ebKwcH8SFqZsXLk0l0/RZoTW2RAMDjBwrrG15b2e0bQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796368476; h=DMARC-Filter:Received:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:Content-Language:From:In-Reply-To: Content-Type:Content-Transfer-Encoding:X-HM-Tid:X-HM-MType: X-HM-Spam-Status:DKIM-Signature; bh=2W8CBKpuqV8mqRvdkEb26mzIoWSfvumWSHFhdKsBRAA=; b=Qizgaz3vTKErCSsmVtEvxOZe1J9sF/FxP7NKNs23oloEEacojsxWWJUS06qMrZYMiIgv 1YwX15YAL7BwLB/8TF7pjsQ4aeXqApbe9llstGA9NfJvK+e6WnhsTlg4yWPejVqamD/Z5 /hNJnIsQo1TlzanRyHeszuuLaHrwGpbrYJJhH8xbBYFXoUP0WkTazyxF6UZODS9gs7yZy ekCCJK7bDa/ePqtWq4tb65oRInlLHhcYQcHzIlvlA92ZQ0MvcdW25ZYytkaE2QLONeEuN NNSQEEJou22knR1FoKLP2b10hhW1KreVHDmfsa2WZMYmP5GbRZ5ZxTWYYdLq05VyRvA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=rock-chips.com; spf=pass smtp.mailfrom=rock-chips.com; dkim=pass header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=UR+3gfVy; arc=none smtp.remote-ip=220.197.32.86 Received: from mail-m3286.qiye.163.com (mail-m3286.qiye.163.com [220.197.32.86]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 541C0606A322 for ; Fri, 4 Dec 2026 07:14:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 541C0606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rock-chips.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=UR+3gfVy Received: from [172.16.12.90] (unknown [61.154.14.86]) by smtp.qiye.163.com (Hmail) with ESMTP id 57178cbf4; Fri, 4 Dec 2026 15:14:24 +0800 (GMT+08:00) Message-ID: <2e35a072-45ff-4438-a5d9-cd67cf8d1424@rock-chips.com> Date: Fri, 4 Dec 2026 15:14:23 +0800 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain To: Francesco Saverio Pavone Cc: Joerg Roedel , Will Deacon , Robin Murphy , Sandy Huang , Heiko Stuebner , Andy Yan , Damon Ding , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jiaxing Hu , iommu@lists.linux.dev, dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-arm-kernel@lists.infradead.org References: <43f9ba0b26794fc58762d4e3188796fbf92becd2.1796334467.git.pavone.lawyer@gmail.com> Content-Language: en-US From: Chaoyi Chen In-Reply-To: <43f9ba0b26794fc58762d4e3188796fbf92becd2.1796334467.git.pavone.lawyer@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-HM-Tid: 0aa23fe7788003a7kunm3c70811e109fc6 X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVkZHUNMVkxISkNCHx8eSBhPHVYVFA kWGhdVEwETFhoSFyQUDg9ZV1kYEgtZQVlNSlVKTk9VSk9VQ01ZV1kWGg8SFR0UWUFZT0tIVUpLSE pKQk1VSktLVUpCWQY+ DKIM-Signature: a=rsa-sha256; b=UR+3gfVySNx35psjeUDrVGYruDrE8ZM65OjJbHoi+i2ybJMDpPexOZtbWlYpWqLV2uvLP08d6IzQ0MaqDvefqUg2aqF2ub0oumV6ZDAKo/b8PieukEM0ZOWEicXpr3uhj85nDbZpGHQ2y4J2JVnsT/iF7EAUHf1B7T/8PC4rIN8=; s=default; c=relaxed/relaxed; d=rock-chips.com; v=1; bh=2W8CBKpuqV8mqRvdkEb26mzIoWSfvumWSHFhdKsBRAA=; h=date:mime-version:subject:message-id:from; Hi, On 12/4/2026 2:24 PM, Francesco Saverio Pavone wrote: > The driver allocates its own IOMMU domain and attaches a VOP to it on > the first CRTC enable. If the bootloader left a window scanning out of > its own framebuffer, that buffer has no mapping in the new domain, and > the VOP reads it until the first new frame is latched. On a ROCK 5B+ > started from EDK2, with the buffer mapped in the default domain only, > this shows at the first modeset as > > rk_iommu fdd97e00.iommu: Page fault at 0x00000000e6810400 of type read > > and the two "Enable stall request timed out" lines come back later, > when the compositor takes over. > > When the devicetree describes the buffer as a reserved region of the > VOP ("memory-region" with "iommu-addresses"), the iommu core maps it > 1:1 in the default domain. Collect the direct-mapped regions of every > VOP when it is bound, then give them the same mapping in the DRM domain > before any device is attached, and reserve the range in the drm_mm so > that no GEM object is given those addresses. > > A region that does not fit in the aperture of the domain is skipped > with a warning. The mappings are kept until the domain is freed: the > driver does not know when the last read of the old buffer happens. > Signed-off-by: Francesco Saverio Pavone Again, please consider condensing your commit message. > --- > drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 121 ++++++++++++++++++++ > drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 2 + > 2 files changed, 123 insertions(+) > > diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c > index ba417f7e9e474..aed22787c05e2 100644 > --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c > +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c > @@ -88,6 +88,121 @@ void rockchip_drm_dma_detach_device(struct drm_device *drm_dev, > iommu_detach_device(private->domain, dev); > } > > +struct rockchip_drm_resv { > + struct list_head list; > + struct drm_mm_node node; > + int prot; > +}; > + > +/* > + * Remember the direct-mapped reserved regions of a VOP. The iommu core maps > + * them 1:1 in the default domain of the device; rockchip_drm_init_iommu() > + * gives them the same mapping in the DRM domain. > + */ Drop this comment. > +static void rockchip_drm_collect_resv_regions(struct drm_device *drm_dev, > + struct device *dev) > +{ > + struct rockchip_drm_private *private = drm_dev->dev_private; > + struct iommu_resv_region *region; > + struct rockchip_drm_resv *resv; > + LIST_HEAD(regions); > + > + iommu_get_resv_regions(dev, ®ions); > + > + list_for_each_entry(region, ®ions, list) { > + if (region->type != IOMMU_RESV_DIRECT && > + region->type != IOMMU_RESV_DIRECT_RELAXABLE) > + continue; > + > + resv = devm_kzalloc_obj(drm_dev->dev, *resv); > + if (!resv) > + break; > + > + resv->node.start = region->start; > + resv->node.size = region->length; This looks somewhat similar to iommu_create_device_direct_mapping(). Consider aligning the address range to page_size? > + resv->prot = region->prot; > + list_add_tail(&resv->list, &private->resv_list); > + } > + > + iommu_put_resv_regions(dev, ®ions); > +} > + > +static void rockchip_drm_unmap_resv_regions(struct rockchip_drm_private *private) > +{ > + struct rockchip_drm_resv *resv; > + > + list_for_each_entry(resv, &private->resv_list, list) { > + if (!drm_mm_node_allocated(&resv->node)) > + continue; > + > + iommu_unmap(private->domain, resv->node.start, resv->node.size); > + drm_mm_remove_node(&resv->node); > + } > +} > + > +/* > + * Map the reserved regions of the VOPs 1:1 in the DRM domain and keep their > + * addresses away from the GEM objects, so that a scanout left running by the > + * bootloader keeps working when a VOP is moved over to this domain. The VOP > + * reads the old buffer until the first new frame is latched, so the mappings > + * stay for as long as the domain does. > + */ Drop this comment. > +static void rockchip_drm_map_resv_regions(struct drm_device *drm_dev) > +{ > + struct rockchip_drm_private *private = drm_dev->dev_private; > + struct iommu_domain_geometry *geometry = &private->domain->geometry; > + unsigned long pgsz = 1UL << __ffs(private->domain->pgsize_bitmap); > + struct rockchip_drm_resv *resv, *other; > + u64 start, end; > + int ret; > + > + list_for_each_entry(resv, &private->resv_list, list) { > + /* Same rounding as the direct mappings of the iommu core. */ > + start = ALIGN(resv->node.start, pgsz); > + end = ALIGN(resv->node.start + resv->node.size, pgsz); Oops, it looks like you perform the alignment here, but isn't that too late for your subsequent comparison? > + if (start >= end) > + continue; > + > + /* Two VOPs may point at the same region. */ > + ret = 0; > + list_for_each_entry(other, &private->resv_list, list) { > + if (other == resv) > + break; > + if (drm_mm_node_allocated(&other->node) && > + other->node.start == start && > + other->node.size == end - start) > + ret = -EEXIST; > + } > + if (ret) > + continue; > + Hmm, this doesn't seem to handle overlapping cases, but it's sufficient for now. > + if (start < geometry->aperture_start || > + end - 1 > geometry->aperture_end) { > + drm_warn(drm_dev, > + "reserved region [%#llx-%#llx] is outside the IOMMU aperture\n", > + start, end - 1); > + continue; > + } > + > + resv->node.start = start; > + resv->node.size = end - start; > + ret = drm_mm_reserve_node(&private->mm, &resv->node); > + if (ret) { > + drm_warn(drm_dev, "cannot reserve [%#llx-%#llx]: %d\n", > + start, end - 1, ret); > + continue; > + } > + > + ret = iommu_map(private->domain, start, start, end - start, > + resv->prot, GFP_KERNEL); > + if (ret) { > + drm_warn(drm_dev, "cannot map [%#llx-%#llx]: %d\n", > + start, end - 1, ret); > + drm_mm_remove_node(&resv->node); > + } > + } > +} > + > void rockchip_drm_dma_init_device(struct drm_device *drm_dev, > struct device *dev) > { > @@ -100,6 +215,9 @@ void rockchip_drm_dma_init_device(struct drm_device *drm_dev, > > if (!IS_ERR(private->iommu_dev)) > drm_dev_set_dma_dev(drm_dev, private->iommu_dev); > + > + if (device_iommu_mapped(dev)) > + rockchip_drm_collect_resv_regions(drm_dev, dev); > } > > static int rockchip_drm_init_iommu(struct drm_device *drm_dev) > @@ -127,6 +245,7 @@ static int rockchip_drm_init_iommu(struct drm_device *drm_dev) > start, end); > drm_mm_init(&private->mm, start, end - start + 1); > mutex_init(&private->mm_lock); > + rockchip_drm_map_resv_regions(drm_dev); > > return 0; > } > @@ -138,6 +257,7 @@ static void rockchip_iommu_cleanup(struct drm_device *drm_dev) > if (!private->domain) > return; > > + rockchip_drm_unmap_resv_regions(private); > drm_mm_takedown(&private->mm); > iommu_domain_free(private->domain); > } > @@ -170,6 +290,7 @@ static int rockchip_drm_bind(struct device *dev) > } > > drm_dev->dev_private = private; > + INIT_LIST_HEAD(&private->resv_list); > > ret = drmm_mode_config_init(drm_dev); > if (ret) > diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h > index 4705dc6b8bd7d..f107342527c6d 100644 > --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h > +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h > @@ -67,12 +67,14 @@ struct rockchip_crtc_state { > * @crtc: array of enabled CRTCs, used to map from "pipe" to drm_crtc. > * @num_pipe: number of pipes for this device. > * @mm_lock: protect drm_mm on multi-threads. > + * @resv_list: reserved regions of the VOPs, mapped 1:1 in @domain. > */ > struct rockchip_drm_private { > struct iommu_domain *domain; > struct device *iommu_dev; > struct mutex mm_lock; > struct drm_mm mm; > + struct list_head resv_list; > }; > > struct rockchip_encoder { -- Best, Chaoyi