Skip to content

ramips: mt7620: fix direct call failures - #24723

Closed
dormancygrace wants to merge 1 commit into
openwrt:mainfrom
dormancygrace:mt7620-stability
Closed

dormancygrace wants to merge 1 commit into
openwrt:mainfrom
dormancygrace:mt7620-stability

Conversation

@dormancygrace

@dormancygrace dormancygrace commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix three MT7620 direct-call failures observed after moving the target to Linux 6.18:

  • the entropy bootstrap can issue a direct jal to mix_pool_bytes() with the wrong high address nibble and crash during early boot;
  • calls involving spi_finalize_current_message() and udp6_ehashfn() can fail for the same reason later in boot or under network activity.

Compile only random.o, the SPI core spi.o, and the IPv6 udp.o with -mlong-calls on MT7620. This covers every direct call in the affected objects without carrying target-specific function-pointer indirection in generic random code.

Applying -mlong-calls globally is deliberately avoided: on tested MT7620N hardware it changes frame-engine code generation enough to leave PDMA stuck on the first TX descriptor.

Build and static verification

  • After rebasing on current OpenWrt main: fresh native prepare, two idempotent refreshes and a complete ramips/mt7620 kernel/module build with Linux 6.18.54.
  • Earlier object and relocation verification used Linux 6.18.44 and GCC 14.4:
  • the final random.o, spi.o, and IPv6 udp.o were inspected with readelf -rW and objdump -dr;
  • calls targeting mix_pool_bytes, spi_finalize_current_message, and external calls to udp6_ehashfn use full-address HI16/LO16 relocations followed by jalr; none uses a direct R_MIPS_26 relocation to the target function.

Hardware testing

The same object-level fix was built for Linux 6.12.94 with GCC 16.2 and tested on a D-Link DWR-921 C3 (MT7620N rev 2 eco 6, 64 MiB RAM).

It reached userspace and passed concurrent stress consisting of:

  • 64 MiB read from /dev/urandom;
  • eight complete, hash-verified reads of every SPI MTD partition;
  • four parallel IPv6 UDP streams for 20 seconds: 156,081 datagrams and 38.1 MiB with zero loss.

The kernel log contained no panic, Oops, reserved instruction, call trace, page fault, or unaligned-access report. The normal flash boot also completed with Ethernet, DSA, PPE, SPI, IPv6 and CRNG initialization intact. These runtime tests predate the rebase.

Related: #20553
Extracted from: #24493

@openwrt openwrt Bot added the target/ramips pull request/issue for ramips target label Aug 14, 2026

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed 2 commits (fresh review). Both commit messages match their diffs, including the documented 821-SPI-ralink-add-Ralink-SoC-spi-driver.patch offset refresh.

Verified locally against gregkh/linux v6.18.44: both new patches and the refreshed 821 apply with zero fuzz and zero offset (patch -p1 -F0), the 128 → 132 offset bump is exactly the 4 lines 334 adds to drivers/spi/Makefile, mix_pool_bytes()'s signature matches the mix_pool_t typedef so the uncast assignment is well-typed, and all direct callers of spi_finalize_current_message() and udp6_ehashfn() reachable in a ramips build live inside spi.o / net/ipv6/udp.o respectively — so the per-object -mlong-calls scope does cover the reported call sites. CONFIG_NET_RALINK_MT7620 is set only in target/linux/ramips/mt7620/config-6.18, matching the existing 330–332 guard convention.

Remaining comments are inline and mostly patch hygiene, plus one question about whether 333's #ifdef blocks could be replaced by the same per-object -mlong-calls mechanism 334 introduces.


Generated by Claude Code

@dormancygrace

Copy link
Copy Markdown
Contributor Author

Addressed the new Formality suggestions. Both embedded kernel patches now carry complete git format-patch mail headers with real commit IDs generated from Linux v6.18.44 (not zero placeholders), and their subjects identify the two-patch series. Both patches apply together with git am; checkpatch.pl reports zero errors and zero warnings. The patch payload is unchanged from the DWR-921 hardware-tested revision.

@dormancygrace
dormancygrace force-pushed the mt7620-stability branch 2 times, most recently from 215b496 to 6d8dc16 Compare August 14, 2026 19:53

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed after the rework from #ifdef-based function-pointer indirection to per-object -mlong-calls. The new form is much cleaner; the remaining points are one commit-message inaccuracy and two nits.

Commit checks

  • 269c3f1 "ramips: mt7620: avoid direct jal in entropy bootstrap" — the message opens with "Linux 6.18 introduced direct calls to mix_pool_bytes() in the timer entropy bootstrap", but those call sites are not new in 6.18. try_to_generate_entropy() has the same two direct calls in 6.12: random.c:1339 and :1343 (v6.12.103), matching random.c:1344 and :1348 (v6.18.44) — in fact the full set of mix_pool_bytes()/_mix_pool_bytes() call sites in random.c is identical between the two trees. What 6.18 changed is the resulting layout/codegen, not the source. Worth rewording (e.g. "Linux 6.18 codegen places these calls out of jal range" / "exposed") so nobody goes hunting for a 6.18 commit that doesn't exist. The embedded patch's own wording — "Linux 6.18 calls mix_pool_bytes() directly from the timer-based entropy bootstrap" — is accurate and needs no change. 6d8dc16's message matches its diff, including the documented 821 offset refresh.

Verified against gregkh/linux v6.18.44: 333, 334 and the refreshed 821 apply in that order with zero fuzz and zero offset (patch -p1 -F0); the @@ -128 → @@ -132 bump is exactly the four lines 334 adds to drivers/spi/Makefile. -mlong-calls is effective here because MIPS kernels build with -mno-abicalls -fno-pic (arch/mips/Makefile:97) — GCC documents the option as a no-op for abicalls code. The per-object scope still covers the reported sites in a mt7620 build: the only in-build direct callers of spi_finalize_current_message() live in spi.c itself (CONFIG_SPI_RT2880's spi-rt2880.c never calls it, nor does spi-mem.c), and udp6_ehashfn()'s only non-udp.c reference is the INDIRECT_CALL_INET() in inet6_hashtables.c:141, which without CONFIG_MITIGATION_RETPOLINE (unavailable on MIPS) expands to a real indirect call. CONFIG_IPV6 resolves to y via KERNEL_IPV6 in config/Config-kernel.in, so net/ipv6/udp.o is built-in and not already covered by KBUILD_CFLAGS_MODULE += -mlong-calls. Patch numbers 333/334 are free and sit correctly next to the existing 330–332 MT7620 workarounds. CI on the head commit reports nothing failed.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed the fold of 333+334 into a single 333-mt7620-use-long-calls.patch. The change since my last review is structural only — same twelve added lines, same three Makefiles — and the two substantive points from last round are resolved: the "Linux 6.18 introduced direct calls to mix_pool_bytes()" claim is gone (the new message correctly says 6.18 codegen/layout exposed the failures), and the SPI hunk now sits above the upstream comment block it was splitting. Only two nits left, both inline.

Verified against gregkh/linux v6.18.44: 333 and the refreshed 821 apply in that order with zero fuzz and zero offset (patch -p1 -F0), and the @@ -128 → @@ -132 bump in 821 is exactly the four lines 333 now adds to drivers/spi/Makefile — the refresh stays correct after the fold, since the insertion count is unchanged and 333 still sorts before 821. All three hunk headers are internally consistent (@@ -3,6 +3,10 @@ / @@ -5,6 +5,10 @@ ×2) and the diffstat "3 files changed, 12 insertions(+)" matches. No other patch in target/linux/ramips/patches-6.18/ or target/linux/generic/{backport,pending,hack}-6.18/ touches drivers/char/Makefile, drivers/spi/Makefile or net/ipv6/Makefile, so nothing else needs a refresh. Patch number 334 is now free and unreferenced. CONFIG_NET_RALINK_MT7620=y only in target/linux/ramips/mt7620/config-6.18 (explicitly is not set in mt76x8), matching the 330–332 guard convention, and KERNEL_PATCHVER:=6.18 is the only patch series in this target, so there is no 6.12 parity gap. CI on the head commit is green, including Check Kernel patches (ramips, mt7620) and the mt7620 kernel build.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed the single new revision (049557d → c872b92). The only change is whitespace: CFLAGS_random.o went from two tabs to three, and CFLAGS_udp.o from three tabs to a single space — both exactly as requested last round, and both now correct. The patch payload is otherwise byte-identical, so the hardware and build results carry over unchanged.

The From <sha> Mon Sep 17 00:00:00 2001 envelope point is settled: your reasoning (siblings 330–332 use the same bare From: form, FormalityCheck / Code Patches is green, and a fabricated object id would be misleading) is sound, and I won't raise it again.

Re-verified against gregkh/linux v6.18.44 at this head: 333 and the refreshed 821 apply in that order with zero fuzz and zero offset (patch -p1 -F0); the diffstat "3 files changed, 12 insertions(+)" still matches the three 4-line hunks; and the @@ -128 → @@ -132 bump in 821 remains exactly the four lines 333 adds to drivers/spi/Makefile. CI on c872b92 is fully green — Check Kernel patches (ramips, mt7620), all five ramips subtarget kernel builds, and all three FormalityCheck runs. The commit message matches its diff, including the documented 821 offset refresh.

One cosmetic nit remains, inline — and it is a correction of something I got wrong last round rather than a new request.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed c872b921 → 6cf6354b. The two commits are content-identical: same tree 59ee5947835a18826b0452dd65df4543bf31b69d, same parent f6bc2a3b294b3d6b298cf5a625e9923459d64edd, same message — only the committer date moved (2026-08-15 16:29:02 → 2026-08-16 07:55:52). git diff c872b921..6cf6354b is empty.

That means the one open nit from last round is still open: CFLAGS_spi.o in the embedded patch remains at three tabs, not four. Details inline. Nothing else changed, so the previous verification carries over unaltered — 333 and the refreshed 821 still apply against gregkh/linux v6.18.44 in order with zero fuzz and zero offset, the @@ -128 → @@ -132 bump still matches the four lines 333 adds to drivers/spi/Makefile, and the diffstat still matches the three 4-line hunks.

CI on 6cf6354b is green: Check Kernel patches (ramips, mt7620), all five ramips subtarget kernel builds, and all three FormalityCheck runs. The commit message matches its diff, including the documented 821 offset refresh. The From <sha> envelope question stays settled as agreed — not raising it again.


Generated by Claude Code

@openwrt-ai openwrt-ai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 6cf6354b → 15ac158a. The only change is the whitespace fix left open last round: CFLAGS_spi.o in the embedded patch went from three tabs to four, which aligns its += to column 40 to match obj-$(CONFIG_SPI_MASTER) in drivers/spi/Makefile. That was the last open nit, and it is now correct. The other two objects were already right and are unchanged — CFLAGS_random.o aligns to column 32 (matching obj-y / obj-$(CONFIG_TTY_PRINTK)), and CFLAGS_udp.o uses a single space to match its neighbour obj-$(CONFIG_IPV6) in net/ipv6/Makefile. The commit message and the rest of the patch payload are byte-identical to the previous revision, so the earlier build/hardware verification carries over.

CI on 15ac158a is green: all five ramips subtarget kernel builds, Check Kernel patches (ramips, mt7620), and all three FormalityCheck runs (Git & Commits, Code Patches, OpenWrt Makefiles). The commit message matches its diff, including the documented 821 offset refresh.

Reviewed 1 new commit; no new issues found.


Generated by Claude Code

MT7620 can sporadically execute direct J-type calls with an incorrect high
address nibble.  Linux 6.18 code generation and layout exposed failures in
the entropy bootstrap, SPI core and IPv6 UDP code.

Compile only random.o, spi.o and IPv6 udp.o with -mlong-calls.  Applying
the option globally was tested on MT7620N hardware and prevents PDMA from
processing its first transmit descriptor.  The targeted workaround boots
and passes sustained bidirectional traffic while retaining the known-good
frame-engine code generation.

Keep the workaround in one kernel patch because all three objects address
the same MT7620 direct-call failure mechanism.  Refresh the SPI driver
patch offset after adding four lines to drivers/spi/Makefile.

Link: openwrt#20553
Signed-off-by: Gleb Pesin <[email protected]>
Assisted-by: Codex:gpt-6.1-sol
@dormancygrace

Copy link
Copy Markdown
Contributor Author

Closing in favor of #26650, which works around the MIPS 24K EPC erratum by keeping executable kernel and module code out of the affected address ranges.

I tested the kernel padding change on a Zbtlink WE826-T2 (MT7620A) with the entropy, SPI, and IPv6 UDP workarounds from this PR removed. Both GCC 14.4 and 16.2 builds booted and passed the SPI read and bidirectional IPv6 UDP tests without an oops or panic. The test results are in #26650.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

target/ramips pull request/issue for ramips target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants