trace: decode /dev/ive IVE ops (motion pipeline + XNN model geometry) - #227
Conversation
PR Summary by QodoDecode IVE XNN loadmodel geometry in ARM traces
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Large models lose their layer list
|
| unsigned char oms[0x400] = {0}; | ||
| size_t n = model_size < sizeof oms ? model_size : sizeof oms; | ||
| if (!copy_from_process(child, model_virt, oms, n)) |
There was a problem hiding this comment.
1. Large models lose their layer list 🐞 Bug ≡ Correctness
ive_xnn_loadmodel_decode copies at most 0x400 bytes of the OMS, then stops walking descriptors when it reaches the end of that copy. A model whose descriptors extend past that point gets an incomplete list or no input geometry; even the accepted case of 16 inputs and 16 outputs puts the first descriptor at byte 1168.
Agent Prompt
## Issue description
The fixed 0x400-byte OMS copy truncates descriptor parsing and can prevent the decoder from printing input geometry or the full layer list.
## Fix Focus Areas
- src/ptrace.c[564-566]
- src/ptrace.c[580-602]
## Recommended Fix
Read descriptor data as needed up to the validated model size, or allocate a bounded buffer for the model, and distinguish a truncated or invalid descriptor stream from a complete decode.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (cmd == IVE_XNN_LOADMODEL) | ||
| ive_xnn_loadmodel_decode(proc->pid, arg); |
There was a problem hiding this comment.
2. Failed model loads appear in the trace 🐞 Bug ≡ Correctness
ive_xnn_ioctl_exit_cb calls the decoder for the loadmodel command without checking sysret. If the ioctl fails but its argument and model buffer remain readable, the callback still prints the normal loadmodel banner and any descriptors it can parse.
Agent Prompt
## Issue description
The loadmodel callback reports readable model data even when the ioctl returned an error.
## Fix Focus Areas
- src/ptrace.c[605-608]
## Recommended Fix
Check `sysret` before decoding a successful load, or explicitly label failed attempts rather than printing them as completed loads.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
fdb9dff to
1ea5743
Compare
On-camera proof (Hi3516EV300 + IMX335, OpenIPC/majestic)Ran the ptrace decoder against majestic with It intercepts majestic's live (DMA = frame load, ADD = background-model blend, CCL = connected-components blob labeling — matching Scope + a correction
Camera restored to normal (majestic restarted) after the test. |
V4 parts (Hi3516EV200/EV300, Goke) have no NNIE; the IVE block at /dev/ive serves both the classic pixel ops that back motion detection (DMA/SUB/THRESH/ ADD/CCL) and, via the private mpi_ive_xnn_* API, CNN inference on the built-in XNN unit. `ipctool trace` already ptrace-decodes i2c/spi/mipi/gpio/mtd; add /dev/ive so its ioctls are decoded too. - Every IVE ioctl (magic 'F') is named by its nr (DMA/CCL/ADD/... and the XNN_* range), so a ptraced streamer's motion pipeline is visible line by line. - For XNN loadmodel (0xc8a04636) the model buffer is read out of the tracee and the OMS parsed to print the network input WxHxC (Preproc layer) and a conv/fc/... layer summary — the geometry a source-less vendor detector (e.g. XiongMai Sofia's SSH face model /usr/res/fd.bin) never stores on disk. Buffer offsets (model_virt @ +8, size @ +16) and the OMS segment-header / layer-descriptor layout are from OpenIPC/openhisilicon kernel/ive_neo (ive_xnn_loadmodel) and the XNN ioctl RE; reads are bounds-gated. ptrace.c is __arm__-only, so no change on mips/arm64. Verified on a Hi3516EV300 + IMX335 OpenIPC camera: `ipctool trace` on majestic with motionDetect enabled intercepts the live IVE pipeline (thousands of ive_op(DMA)/ive_op(CCL)/ive_op(ADD) at 656x480, main/4). majestic's personDetect is a NEON CPU path and does not touch /dev/ive, so the XNN geometry decode is verified by construction against ive_neo and awaits a live XNN consumer (XM Sofia) to confirm end to end.
|
Addressed both findings in acb42be:
|
1ea5743 to
acb42be
Compare
|
The latest Qodo pass re-lists the same two items but against the pre-fix revision — it cites |
What
ipctool traceis a ptrace syscall decoder that already turns a source-less streamer's i2c/spi/mipi/gpio/mtd traffic into readable pseudocode (seedocs/sensor-driver-extraction.md). This teaches it/dev/ive.V4 parts (Hi3516EV200/EV300, Goke) have no NNIE — CNN inference runs on the IVE's built-in XNN unit through
/dev/iveand the privatempi_ive_xnn_*API. Vendor detectors like XiongMai Sofia's SSH face model (/usr/res/fd.bin) ship only int8 weights on disk (no header, not OMS), so the network's input geometry and layer list exist only on the wire, in the OMS the streamer hands to theloadmodelioctl.This decodes that ioctl (
0xc8a04636): read the model buffer's virtual address from the ioctl arg, copy the OMS out of the tracee, and print the inputWxHxC(from the OMS Preproc layer) plus aconv/fc/...layer summary.Expected output line, interleaved with the existing trace:
Provenance
Buffer offsets (
model_virt@ +8,model_size@ +16) and the OMS segment-header + layer-descriptor layout come from two authoritative sources that agree:OpenIPC/openhisiliconkernel/ive_neo/ive_neo.c(ive_xnn_loadmodel,ive_build_task_nodes) — the clean-room driver;test-xnn.cinOpenIPC/qemu-hisilicon).All reads are bounds-gated (sane
src/dst/layercounts; every descriptor within the copied range), so a partial or non-OMS buffer is skipped, never misread.Scope / safety
src/ptrace.cis wholly#ifdef __arm__, so this is arm32-only; no change on mips/arm64./dev/ivebranch in the open dispatch + a self-contained decoder. No effect on existing i2c/spi/mipi/mtd paths.Testing
cYAML_test/reginfo_testandtools/test_pipeline.shpass.000529B22021-03-03): confirmedipctool trace /usr/bin/Sofiaruns and captures the streamer's bus traffic (1.5 MB, 150+sensor_writelines). Caveat: under ptrace Sofia starts ~100× slower and its AI init is deep in startup, so the XNNloadmodelline itself was not reached within the traced window — the decoder is verified by construction against the two sources above, and live capture of the decode is still to be confirmed. Flagging that honestly for review.Closes nothing; complements the sensor-driver-extraction workflow.