Skip to content

ambarella s3l: enable CONFIG_QUOTA so vendor iav.ko loads - #2778

Closed
openipc-ai wants to merge 1 commit into
masterfrom
s3l-config-quota
Closed

openipc-ai wants to merge 1 commit into
masterfrom
s3l-config-quota

Conversation

@openipc-ai

Copy link
Copy Markdown
Collaborator

The S3L SDK's prebuilt iav.ko is built with MODVERSIONS off and hardcodes
the kernel's struct offsets. It reads inode->i_cdev at offset 272, but
without CONFIG_QUOTA the stock kernel's struct inode places i_cdev at
264 -- enabling QUOTA inserts i_dquot[MAXQUOTAS] (2 pointers, 8 bytes)
ahead of it and lines the two up.

With QUOTA off, iav_open() follows i_cdev to the wrong place and the
driver comes up with a bogus context (the /dev/iav ioctls then fail);
CONFIG_QUOTA=y fixes that and the driver initialises normally.

The added lines mirror the kernel's oldconfig expansion for QUOTA (same set
the other OpenIPC boards that enable it carry). No functional quota use --
this is purely to match the ABI the shipped iav.ko was compiled against.

The S3L SDK's iav.ko is prebuilt with MODVERSIONS off and hardcodes the
kernel's struct offsets. It reads inode->i_cdev at offset 272, but without
CONFIG_QUOTA the stock kernel's struct inode has it at 264: QUOTA adds
i_dquot[2] (8 bytes) ahead of it. Enabling CONFIG_QUOTA aligns the struct so
iav_open() follows i_cdev to the right cdev and the driver initialises
instead of dereferencing a bogus context.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Align S3L inode layout with vendor iav.ko using CONFIG_QUOTA

🐞 Bug fix ⚙️ Configuration changes 🕐 10-20 Minutes

Grey Divider

AI Description

• Enable QUOTA in the S3L kernel to match the inode layout expected by prebuilt iav.ko.
• Restore the correct driver context so /dev/iav ioctls work.
Diagram

graph TD
  A["S3L kernel config"] --> B["QUOTA-enabled kernel"] --> C["i_cdev at 272"] --> D["vendor iav.ko"] --> E["working iav ioctls"]
Loading
High-Level Assessment

Enabling QUOTA in the S3L kernel is the focused way to match the shipped module's inode ABI. Rebuilding the prebuilt vendor module would be a substantially broader approach to this configuration mismatch.

Files changed (1) +7 / -2

Bug fix (1) +7 / -2
s3l.generic.configEnable QUOTA for the S3L vendor driver ABI +7/-2

Enable QUOTA for the S3L vendor driver ABI

• Enables CONFIG_QUOTA and CONFIG_QUOTACTL, with the associated quota options set to match the kernel configuration expansion. This aligns the inode layout with the offset expected by the prebuilt iav.ko; it does not introduce quota usage.

br-ext-chip-ambarella/board/s3l/s3l.generic.config

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Kernel ABI fix rests on an unverified struct offset 🐞 Bug ≡ Correctness
Description
The change turns on CONFIG_QUOTA in the S3L kernel fragment based on the premise that the prebuilt
iav.ko hardcodes inode->i_cdev at offset 272, which only lines up when i_dquot[MAXQUOTAS] is present
in struct inode. Enabling QUOTA shifts every later struct inode field, not just i_cdev, so any other
hardcoded offset in the blob also changes silently. Nothing in the diff or the repo checks the
claimed offsets, so a wrong assumption would ship to every S3L camera on flash.
Code

br-ext-chip-ambarella/board/s3l/s3l.generic.config[R2091-2092]

+CONFIG_QUOTA=y
+# CONFIG_QUOTA_NETLINK_INTERFACE is not set
Evidence
The only justification is the PR description's offset arithmetic (264 vs 272) for one field. The
vendor iav.ko and the struct layout it targets are not in this repository (a search for 'iav' under
br-ext-chip-ambarella returns no matches), so the claim cannot be reproduced here. The kernel is not
stock: s3l_lite_defconfig pulls the OpenIPC linux fork via OPENIPC_KERNEL, so the actual struct
inode layout comes from that fork's headers, which the PR neither pins nor cites.

br-ext-chip-ambarella/board/s3l/s3l.generic.config[2091-2092]
br-ext-chip-ambarella/configs/s3l_lite_defconfig[20-24]


Grey Divider

Context sources
Review mode: Auto: 🚀 Fast: Single-hunk kernel config for one Ambarella board; localized, not shared overlay.

Grey Divider

Tip of the day
💡 Did you know, you can switch off images and animations for a plain-text comment

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@DeathCamel58

Copy link
Copy Markdown
Contributor

Measured on current master (with #2763's CONFIG_LBDAF=y), using a throwaway module built against the S3L kernel:

  • master as is (QUOTA off): inode.i_cdev = 0x110 (272), what iav.ko expects. /dev/iav works: my
    IP4M-1026E streams on this kernel, cold boots included.
  • master + this PR (QUOTA=y): inode.i_cdev = 0x118 (280), 8 bytes past it.

LBDAF makes sector_t/blkcnt_t 64-bit, which already moves i_cdev from 264 to 272. QUOTA's i_dquot[MAXQUOTAS] sits
before i_cdev and adds another 8, so on top of #2763 this PR would break iav.ko instead of fixing it. Ambarella's own
ambarella_s3l_defconfig, which the prebuilt modules were built with, has CONFIG_QUOTA off too.

The 264 in the description matches a kernel without LBDAF, i.e. before #2763. I'd close this one.

@openipc-ai

Copy link
Copy Markdown
Collaborator Author

@DeathCamel58 you're right, and I can confirm it. Closing this, since #2763 already fixed the same offset and this PR would now break it.

Offsets from a probe compiled against ambarella-s3l at 7022a237:

Config inode.i_cdev sizeof(struct inode)
LBDAF off, QUOTA off (before #2763) 0x108 0x120
LBDAF off, QUOTA on 0x110 0x128
LBDAF on, QUOTA off (master) 0x110 0x128
LBDAF on, QUOTA on (master + this PR) 0x118 0x130

The shipped iav.ko reads 0x110:

00000000 <iav_open>:
       0:	e5903110 	ldr	r3, [r0, #272]	@ 0x110

QUOTA was one way to reach 0x110 from 0x108, and LBDAF, from #2763, is the other. Both together overshoot it. With this PR on master, iav_open would read the wrong field. Ambarella's ambarella_s3l_defconfig has CONFIG_LBDAF=y and QUOTA off, so LBDAF is the one that matches how the modules were built.

The green checks here don't catch this, because the kernel builds and the modules load either way. The failure only appears at the first /dev/iav ioctl.

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