Skip to contentSkip to conversation

drm/rockchip: vop2: Give each RK3588 video port its own cluster

PATCH Superseded Arun Iyengar 2 participants 2 messages Nov 21

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/rockchip: vop2: Give each RK3588 video port its own cluster

Damon Ding asked for POST_BUF_EMPTY to be fixed in the layer setup, and Chaoyi Chen pointed out that a video port's layers must stay on one AXI port. On RK3588 Cluster0/1 fetch through AXI0 and Cluster2/3 through AXI1. Each video port takes the first free primary window, so VP0 and VP2 get Cluster0 and Cluster1, both on AXI0. A 4K120 and a 4K60 XR24 primary need about 6 GB/s there, one port delivers about 4.5 GB/s, and VP0 underflows in every frame. aclk_vop at 750 or 850 MHz is the same.

On RK3588 give VP N Cluster N as primary plane. Boards without VP1 now get Cluster2 instead of Cluster1 as VP2's primary. RK3568 and RK3576 are unchanged.

Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")

---
Tested on Orange Pi 5, HDMI 4K120 + DP 4K60, v7.3 plus local HDMI FRL and 750 MHz aclk_vop (not in mainline): 7207 bad frames in 60 s before, 0 after. Applies with Chaoyi Chen's 8K series [1]: VP0 keeps Cluster0 and Cluster1.

[1] https://lore.kernel.org/all/[email protected]/

Developed with Claude (Anthropic), which wrote the code and the commit message. I reviewed every change.

---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +10 -0
index 76d151b8bc52..303d9b987a7c 100644
@@ -2583,6 +2583,12 @@ static bool vop2_is_mirror_win(struct vop2_win *win)
 	}
 }
 
+/* RK3588 primary per video port; Cluster0/1 on AXI0, Cluster2/3 on AXI1. */
+static const u8 rk3588_vp_primary[] = {
+	ROCKCHIP_VOP2_CLUSTER0, ROCKCHIP_VOP2_CLUSTER1,
+	ROCKCHIP_VOP2_CLUSTER2, ROCKCHIP_VOP2_CLUSTER3,
+};
+
 static int vop2_create_crtcs(struct vop2 *vop2)
 {
 	const struct vop2_data *vop2_data = vop2->data;
@@ -2655,6 +2661,10 @@ static int vop2_create_crtcs(struct vop2 *vop2)
 			if (!(win->data->possible_vp_mask & BIT(vp->id)))
 				continue;
 
+			if (vop2->version == VOP_VERSION_RK3588 &&
+			    win->data->phys_id != rk3588_vp_primary[vp->id])
+				continue;
+
 			if (vop2_is_mirror_win(win))
 				continue;
 

---
base-commit: c408466a4dfaee4b12587e926c5b85e68c8b3c40
change-id: 20261121-vop2-axi-primary-971fcba0d98e

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/rockchip: vop2: default zpos inversion for overlays in vop2_create_crtcs() - [Medium]…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/rockchip: vop2: default zpos inversion for overlays in vop2_create_crtcs()
- [Medium] drm/rockchip: vop2: overlay planes and VP0+VP1 still violate AXI separation
It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] drm/rockchip: vop2: port node leak and UAF on error in vop2_create_crtcs() [1]
--

commit 7cc91c6d385e03fd7bff780807113fe9561a15db
Author: Arun Iyengar <[email protected]>

drm/rockchip: vop2: Give each RK3588 video port its own cluster

This commit assigns Cluster N as the primary plane for video port N on RK3588 so that VP0 and VP2 do not share AXI0 for their primary planes.

Quoted 18 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +6 -0
index 76d151b8bc52b..303d9b987a7c5 100644
@@ -2583,6 +2583,12 @@ static bool vop2_is_mirror_win(struct vop2_win *win)
 	}
 }
 
+/* RK3588 primary per video port; Cluster0/1 on AXI0, Cluster2/3 on AXI1. */
+static const u8 rk3588_vp_primary[] = {
+	ROCKCHIP_VOP2_CLUSTER0, ROCKCHIP_VOP2_CLUSTER1,
+	ROCKCHIP_VOP2_CLUSTER2, ROCKCHIP_VOP2_CLUSTER3,
+};
+
 static int vop2_create_crtcs(struct vop2 *vop2)
 {
 	const struct vop2_data *vop2_data = vop2->data;

drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static int vop2_create_crtcs(struct vop2 *vop2) · line 2669

Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +4 -0
@@ -2655,6 +2661,10 @@ static int vop2_create_crtcs(struct vop2 *vop2)
 			if (!(win->data->possible_vp_mask & BIT(vp->id)))
 				continue;
 
+			if (vop2->version == VOP_VERSION_RK3588 &&
+			    win->data->phys_id != rk3588_vp_primary[vp->id])
+				continue;
+
 			if (vop2_is_mirror_win(win))
 				continue;

[Severity: Medium]
When an earlier video port is unused (such as VP0 + VP2 without VP1), does skipping Cluster1-win0 here give the first overlay plane a lower default zpos than VP2's primary plane?

vop2_win_init() assigns win->win_id sequentially (Cluster0..3 get 0..3), and vop2_plane_init() sets each plane's initial zpos to win->win_id:

drivers/gpu/drm/rockchip/rockchip_drm_vop2.c:vop2_plane_init() {
	...
	drm_plane_create_zpos_property(&win->base, win->win_id, 0,
				       vop2->registered_num_wins - 1);
	...
}

When VP1 is disabled, VP2 claims Cluster2-win0 (default zpos 2) as its primary plane, while the unclaimed Cluster1-win0 (default zpos 1) is registered as the first DRM_PLANE_TYPE_OVERLAY plane in the loop below. If userspace enables that overlay plane on VP2 or VP3 without explicitly setting zpos, drm_atomic_normalize_zpos() places the overlay underneath the primary plane.

[Severity: Medium]
Does filtering only the primary plane loop actually keep a video port's layers on one AXI bus, or avoid AXI0 sharing on VP0 + VP1 boards?

In the overlay loop right below, possible_crtcs is still computed solely from win->data->possible_vp_mask (BIT(0) | BIT(1) | BIT(2) | BIT(3) for all eight windows in rk3588_vop_win_data[]), and neither possible_crtcs nor atomic_check restricts a video port's planes to one axi_bus_id. On a board with VP0 and VP2 active and VP1 disabled, the skipped Cluster1-win0 (axi_bus_id 0) becomes the first overlay plane and can be attached directly to VP2 alongside its Cluster2-win0 (axi_bus_id 1) primary plane, as can Esmart0/1.

In addition, because rk3588_vp_primary[] maps VP0 to Cluster0 and VP1 to Cluster1, dual-display RK3588 boards wired to VP0 and VP1 (such as Rock 5B, Orange Pi 5 Plus/Max, and NanoPC-T6) still put both 4K primary planes on AXI0.

[Severity: High]
This problem wasn't introduced by this patch, but if vop2_create_crtcs() fails after acquiring port nodes or initializing planes or CRTCs [1], does the early return leak vp->crtc.port references and leave freed planes and CRTCs linked in drm->mode_config?

In the first loop, of_graph_get_port_by_id() stores a device_node reference in vp->crtc.port, and the following loops link embedded win->base and vp->crtc objects into drm->mode_config.plane_list and crtc_list. Returning an error without calling vop2_destroy_crtcs() leaks the port nodes and lets component_bind() free the devm-allocated struct vop2 while its planes and CRTCs remain on drm_device, causing a use-after-free when rockchip_drm_bind() unwinds through drm_mode_config_cleanup().

[1] https://sashiko.dev/#/bug/linux-81b4737a-b947-4652-ad38-8f28fe971257

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1