Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
air_run: one sampler pointer where the driver reads num_tex of them
vcvkk72ca48455206
diff --git a/docs/air.md b/docs/air.mdindex aa20d71..a9fcd6c 100644--- a/docs/air.md+++ b/docs/air.md@@ -380,8 +380,35 @@ functions and not entry points at all.established**, and 22 kernels binding images successfully is the reason it cannot be read as"images do not work".- **What distinguishes the four is two things, not one**, which is as far as looking at them goes- today. Three of them — `FilmGrainLumaKernel_Uint`, `FilmGrainLumaKernel_Unorm`,+ **The cause is found and it is this harness's, not freedreno's. Whether it accounts for all four+ is a prediction, not yet a result.**++ void *csampler = NULL;+ pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE, 0, num_tex, &csampler);++ `bind_sampler_states` reads `num_tex` pointers from the address it is given, and `&csampler` is+ the address of *one*. At `num_tex == 1` that is right by accident, which is why 22 kernels bound+ images without trouble; at two or more the driver takes whatever followed that variable on the+ stack and stores it as `samplers[1..]`, and `fd6_texture_state`'s loop over `num_samplers` then+ dereferences those for `->seqno`. A wild pointer plus a small field offset is exactly+ `0x100000000034`. The draw path beside it has always built a proper `void *samplers[]` array, so+ the new code failed to learn what the old code already knew.++ A peer session's reading of the same function proposed a different mechanism — `view_seqno[16]`+ overflowing because `num_textures` is unclamped against `textures[32]`, which is a real+ fragility in freedreno — and it is not reachable from here: this harness refuses a slot index of+ 16 or more by name. Checking whether someone else's bug was reachable, instead of fixing it, is+ what left the adjacent line to be read.++ **And the feature that looked discriminating was probably a confound.** Exactly 4 of the 47+ kernels carry an inlined module-local function; three crashed and the fourth was refused earlier+ on the shuffle mask, so none dispatched and every one that reached dispatch died. That is 3 of 3+ and not a correlation — but those same kernels are the only ones reading *two* textures, and two+ is precisely the threshold of the bug above. One mechanism may account for all four, including+ `spillCorrectionPreProcess`, which carries no call at all. `air_run` now prints the texture+ count beside the image count so the next run decides it rather than an argument.++ What distinguishing them achieved, before the cause was known: Three of them — `FilmGrainLumaKernel_Uint`, `FilmGrainLumaKernel_Unorm`,`FilmGrainChromaKernel_Unorm` — are exactly the kernels that contain an inlined module-localfunction, and nothing that dispatched contains one. The fourth,`spillCorrectionPreProcess`, contains no call at all and is instead the only kernel in thediff --git a/tools/mesa/air/air_run.c b/tools/mesa/air/air_run.cindex cee670b..cc02281 100644--- a/tools/mesa/air/air_run.c+++ b/tools/mesa/air/air_run.c@@ -623,7 +623,18 @@ dispatch_kernel(struct pipe_screen *screen, const struct air_shader_info *info,.mag_img_filter = PIPE_TEX_FILTER_NEAREST,.min_mip_filter = PIPE_TEX_MIPFILTER_NONE,.unnormalized_coords = 1 });- pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE, 0, num_tex, &csampler);+ /* one entry per texture, not the address of one pointer. bind_sampler_states+ * reads num_tex pointers from what it is given, so passing &csampler made+ * the driver take whatever followed that single variable on the stack and+ * store it as samplers[1..]; fd6_texture_state then dereferenced those for+ * ->seqno and died at a wild address. It only showed with two or more+ * textures, which is why 22 kernels bound images here without trouble and+ * four did not. The draw path below always did this correctly.+ */+ void *csamplers[MAX_IMG] = { 0 };+ for (unsigned i = 0; i < num_tex && i < MAX_IMG; i++)+ csamplers[i] = csampler;+ pipe->bind_sampler_states(pipe, PIPE_SHADER_COMPUTE, 0, num_tex, csamplers);pipe->set_sampler_views(pipe, PIPE_SHADER_COMPUTE, 0, num_tex, 0, false, views);}@@ -645,10 +656,11 @@ dispatch_kernel(struct pipe_screen *screen, const struct air_shader_info *info,printf("air_run: dispatching %ux%ux1 threads in one workgroup; %u device buffer%s bound, ""%u of them written, filled with (i * 7 + 13) & 0xff\n",GRID, GRID, num_ssbo, num_ssbo == 1 ? "" : "s", num_written);- if (num_img)- printf("air_run: %u image%s bound (%u written), %ux%u, texel (x,y,z) of slot n = "- "(100+x+1000n, 200+y, 300+x+y+z, 400)\n", num_img, num_img == 1 ? "" : "s",- num_img_written, TEX_SIZE, TEX_SIZE);+ if (num_img || num_tex)+ printf("air_run: %u image%s bound (%u written) and %u texture%s, %ux%u, texel (x,y,z) of "+ "slot n = (100+x+1000n, 200+y, 300+x+y+z, 400)\n", num_img,+ num_img == 1 ? "" : "s", num_img_written, num_tex, num_tex == 1 ? "" : "s",+ TEX_SIZE, TEX_SIZE);pipe->launch_grid(pipe, &grid);pipe->flush(pipe, NULL, 0);