Skip to content

media: apple: fix the ISP IPC fortify warning and AVD test sparse casts - #2829

Merged
RyanTheTide merged 2 commits into
integration/aurorafrom
code-health/media-apple-sparse-20261123
Nov 22, 2026
Merged

RyanTheTide merged 2 commits into
integration/aurorafrom
code-health/media-apple-sparse-20261123

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem

With W=1 on the integration/aurora tip:

  • isp-ipc.c: FORTIFY_SOURCE reports __read_overflow2_field, because chan_write_msg_index() does one memcpy() of arg1..arg7 starting at &msg->arg1.
  • sparse reports three "different address spaces" comparisons in avd-pm-test.c. The test backs MMIO apertures with kunit_kzalloc() memory cast to __iomem, then checks those pointers with KUNIT_ASSERT_NOT_NULL().

Change

  • struct isp_message: wrap arg1..arg7 in struct_group(payload, ...) and copy sizeof(msg->payload). The layout, the size (static_assert unchanged) and the bytes written stay the same.
  • avd-pm-test.c: cast back with __force void * for the NULL checks. Test-only.

Testing

  • W=1 C=2 build of drivers/media/platform/apple/ with the fleet79 config: the fortify and avd-pm-test warnings are gone.
  • isp-ipc.o calls the same functions as before, and avd-pm-test.o generates identical code. In isp-ipc.o only register allocation and scheduling around the inlined 56-byte copy changed.
  • KUnit (arm64 qemu, 16K pages, ISP + ISP IPC layout + AVD suites): 99/100 pass. The one failure, apple-isp-hw.isp_test_sensor_sysfs, fails the same way on the unmodified tip (it calls sysfs_emit() with a 32-byte stack buffer, and sysfs_emit() requires a page-aligned one). It is listed in Code health: W=1, sparse, checkpatch and DT schema findings in the Apple drivers (integration/aurora 37106688) #2827.
  • checkpatch --strict: one CHECK on the struct_group() member indentation, which is the usual layout for that macro.

Still to run

A camera stream on any ISP Mac (the IPC write path is byte-identical, so this is a sanity check).

Details

Remaining W=1/sparse output for the directory after this change:

drivers/media/platform/apple/avd/avd-inst.h:179:33: warning: cast truncates bits from constant value (a0a0a0a0a0 becomes a0a0a0a0)   # intended split of a test DMA address into two words
drivers/media/platform/apple/isp/isp-drv.c:1331:34: warning: unused variable 'apple_isp_hw_t6040' [-Wunused-const-variable]   # left over from the T6041 split, tracked separately

KUnit config and logs (lab store): traces/ci/20261123-code-health/kunit-media.config, logs/kunit-media.log, logs/kunit-media-tip.log.

Assisted-by: LLM (Claude:Opus 5.5)

chan_write_msg_index() copies arg1..arg7 with one memcpy() starting at
&msg->arg1. With W=1, FORTIFY_SOURCE flags this as a read beyond the
arg1 field (__read_overflow2_field).

Wrap arg1..arg7 in struct_group(payload, ...) and copy
sizeof(msg->payload). The message layout, its size and the bytes
written are unchanged.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The PM test backs the code, mailbox and PIODMA apertures with
kunit_kzalloc() memory cast to __iomem. Asserting those pointers against
NULL makes sparse warn about comparing different address spaces. Cast
them back with __force for the check, as for the allocation.

Test-only change.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at 28bf9f1.

  1. isp-drv.h:102-114: struct_group(payload, ...) keeps arg1..arg7 contiguous and the outer struct __packed, so sizeof stays at 64 (the static_assert still holds). sizeof(msg->payload) is 56, the same as the old sizeof(*msg) - 8. The destination is still p0 + 1, and arg0 is still written last after dma_wmb() (isp-ipc.c:100-105). The copy length and order are unchanged.
  2. All other users still name the fields directly or through designated initializers (isp-cmd.c:43/56, isp-ipc.c:310/321, isp-cam-test.c:492, isp-ipc-test.c:262), and those work through the anonymous member. chan_read_msg_index() copies the whole struct, so it isn't affected.
  3. avd-pm-test.c:294-296: the __force void * casts only feed the NULL checks, matching the __force casts on the allocations just above. Test-only.

Looks good.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial pre-PR checklist (§1–§6) review at 28bf9f1a800d4d39efbff25b20bbe6975d5b7226:

  • Technical / ABI & semantics check:
    • media: apple: isp (1442df56): wrapping arg1..arg7 in struct_group(payload, ...) inside struct isp_message { ... } __packed; (isp-drv.h:102-114) preserves ABI, layout, alignment, and size: all 7 fields are u64 (zero internal padding), offsetof(struct isp_message, payload) == offsetof(struct isp_message, arg1) == 8, sizeof(msg->payload) == 56 == sizeof(*msg) - 8, and static_assert(sizeof(struct isp_message) == ISP_IPC_MESSAGE_SIZE) still enforces 64 bytes. chan_write_msg_index() (isp-ipc.c:100-106) preserves the exact destination (p0 + 1), 56-byte copy length, and ordering (payload copy -> dma_wmb() -> *p0 = msg->arg0 -> dma_wmb()). This is the canonical kernel pattern for CONFIG_FORTIFY_SOURCE multi-field copies rather than masking an overflow. Direct member accesses and designated initializers remain valid via the anonymous mirror struct.
    • media: apple: avd (28bf9f1a): avd-pm-test.c:291-296 backs the test apertures with kunit_kzalloc() RAM cast to (__force void __iomem *) on the three lines immediately preceding the KUNIT_ASSERT_NOT_NULL() checks. Casting back to (__force void *) strictly for those test assertions does not mask any real MMIO address-space bug and produces identical object code.
  • §1 No model gating / §2 Production-ready / §3 Safety: Pass — no model gates, no hacks, IPC write barrier ordering untouched.
  • §4 Clean-room & attribution: Pass — both commits carry human author/committer (Ryan Murray <ryan@aurorasilicon.org>), human Signed-off-by, zero AI trailers in commits, and Assisted-by: in the PR body.
  • §5 Evidence: Pass — W=1 C=2 targeted warnings gone, objdump verified, arm64 qemu KUnit ISP/AVD suites 99/100 (single pre-existing isp_test_sensor_sysfs failure verified identical on unmodified tip and tracked in #2827), Host tests/host-tests CI green, mergeable (clean).
  • §6 Naming: Pass.

Verdict: APPROVE — ready for MERGETRAIN-LINUX4.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Merge-train adversarial review (MERGETRAIN-LINUX4) at 28bf9f1: no blockers. Merges clean on integration/aurora, alone and together with #2828-#2832.

Full review

VERDICT: NO BLOCKERS

Blockers: none.

Checked:

  • Firmware-shared IPC layout, isp-drv.h:102-115. I compiled a userspace copy of the kernel's __struct_group
    with GCC. Old and new struct isp_message are both sizeof 64 with alignment 1 (the outer __packed still
    makes it 1). offsetof(payload) = offsetof(arg1) = 8, offsetof(arg7) = 56, and sizeof(payload) = 56. Mixed
    designated initializers (.arg0, .arg1, .arg7) still initialize the right fields. The static_assert at
    :115 still holds.
  • isp-ipc.c:97-106: same destination (p0 + 1), same 56-byte length (= old sizeof(*msg) - 8), and the
    order is unchanged: payload copy, dma_wmb, arg0, dma_wmb. The read side (:81/:84) copies the whole struct
    and is not affected.
  • Every initializer and user is designated or uses a field name (isp-cam-test.c:492/563,
    isp-ipc-test.c:176/262/266). None is positional.
  • avd-pm-test.c:294-296: the __force void * casts are only for KUNIT_ASSERT_NOT_NULL, on the kunit_kzalloc
    memory that :291-293 cast to __iomem. Test only.

Nits: none.
Earlier reviews: both approve and leave nothing open. DjDeveloperr notes that the 99/100 KUnit run has a
failure (isp_test_sensor_sysfs) that already fails on the tip and is tracked in #2827. I did not re-run it.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide
RyanTheTide merged commit 4f3b4b3 into integration/aurora Nov 22, 2026
1 check passed
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Post-merge check at cdce3146 (#2828-#2831 merged onto integration/aurora 120d6aa, fleet79 config, LLVM arm64).

pahole on isp-ipc.o shows struct isp_message is still 64 bytes with arg0..arg7 at offsets 0, 8, ..., 56 on both sides, and the copy is 56 bytes on both. isp-ipc.o, isp-drv.o, isp-cmd.o and avd-pm-test.o disassemble identically before and after. The two W=1 __read_overflow2_field warnings in isp-ipc.c and the three avd-pm-test.c sparse address-space errors are gone.

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