Skip to content

pvr/g5p, util/tc: long Firefox renders: real control stream block sizes, rolled-over rp info use-after-free - #49

Merged
henrikklee merged 2 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-csb-tc
Dec 4, 2026
Merged

henrikklee merged 2 commits into
OrchardLinux:mainfrom
brkosebay:submit/g5p-csb-tc

Conversation

@brkosebay

Copy link
Copy Markdown
Contributor

Two fixes for long Firefox (WebRender through Zink) renders on the A9:

  • pvr/g5p: count control stream blocks at their real size. g5p_cmd_draw() continues a render before its VDM control stream passes PVR_G5P_MAX_VDM_BYTES (1 MiB), but it counted 4 KiB per block. The kernel rounds each block BO up to its page, 16 KiB on the iPad. So the continuation came only after about 4 MiB, and long renders were refused at 1 MiB instead and skipped. Speedometer 3.1 hit "a control stream of 1373708 bytes in 85 blocks (at most 1048576)". The fix sums the real BO sizes and keeps the largest block in reserve.
  • util/tc: let the previous batch finish before moving rolled-over rp infos. When a render pass continues across a batch flush, the flushed batch's last tc_batch_rp_info links to infos[0] of the new batch. If the new batch then records more than ten render passes, tc_batch_renderpass_infos_resize() reallocates the array while the driver thread may still read or write through that link. Firefox crashed in threaded_context_get_renderpass_info() from zink_batch_rp() (SIGSEGV on a wild pointer made of float data) during a render of several thousand draws, at Speedometer step 48. Before moving an array whose infos[0] the previous batch links to, the fix waits for that batch's fence. This is a common Gallium change for any threaded-context driver.

Tested on the iPad 5 (j71t): both are in the Mesa the device has run since 2026-12-03 (Firefox daily sites and scroll benchmarks, no crash). Built on this head (Vulkan imagination with asserts on, and the Zink GL build); the G5P meson host tests pass, 9/9.

How to test

On a stock Orchard install with Mesa built from this branch:

PVR_DEBUG=errors firefox https://browserbench.org/Speedometer3.1/ 2>&1 | grep -E 'control stream of|G5P refuses'   # no 1 MiB refusals
coredumpctl list firefox     # no new crash in threaded_context_get_renderpass_info

Expected on the iPad 5: no control stream refusals and no threaded-context crash during Speedometer. A10: the util/tc fix applies to every Gallium threaded-context driver (Zink on the A10 too). The block count is G5P-only.

…uing a render

g5p_cmd_draw() continues a render in a new one (a mid-render barrier: the
first stores, the second loads) before its VDM control stream passes
PVR_G5P_MAX_VDM_BYTES, which pvr_arch_g5p_vdm_stream() lays out as one
range. It counted PVR_CMD_BUFFER_CSB_BO_SIZE (4 KiB) per pvr_csb block,
but pvr_csb_buffer_extend() fills a block up to its BO's size, which the
kernel rounds up to its page: 16 KiB on the iPad. The continuation came
only after 255 blocks (about 4 MiB), so long renders were refused at
1 MiB instead ("a control stream of 1373708 bytes in 85 blocks (at most
1048576)", Speedometer 3.1 in Firefox) and skipped.

Sum the blocks' BO sizes and keep the largest block in reserve.

The 1 MiB limit is the driver's, not the hardware's: the A9 VDM follows
STREAM_LINK (Apple's streams use it), but only flattened streams have
run on the device so far.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
…nfos

When a renderpass continues across a batch flush, the flushed batch's
last tc_batch_rp_info links to infos[0] of the new batch (full_copy in
tc_batch_increment_renderpass_info()). While the flushed batch executes,
the driver thread follows that link in
threaded_context_get_renderpass_info(), and after executing it writes
through it (tc_batch_execute() clears next->prev).

If the new batch then records ten more renderpasses,
tc_batch_renderpass_infos_resize() reallocates its array: the old
infos[0] is freed while the driver thread may still read its ready
fence and next pointer, or write its prev pointer. Firefox (WebRender
through Zink) crashed in threaded_context_get_renderpass_info() from
zink_batch_rp() with a wild pointer made of float data (SIGSEGV at
0x44c2600044800028) during a render of several thousand draws.

Before moving an array whose infos[0] was linked from the previous
batch, wait for that batch's fence. infos[0] has ended and been
signalled by then, so the driver thread is never waiting on the
recording thread. This happens only for a batch that started inside a
renderpass and holds more than ten renderpasses.

Assisted-by: LLM
Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants