Skip to content

[25.12] ramips: work around EPC erratum in MIPS 24K cores - #26784

Merged
openwrt-bot merged 6 commits into
openwrt:openwrt-25.12from
MarcoMartins86:ramips-epc-erratum-25.12
Nov 19, 2026
Merged

openwrt-bot merged 6 commits into
openwrt:openwrt-25.12from
MarcoMartins86:ramips-epc-erratum-25.12

Conversation

@MarcoMartins86

Copy link
Copy Markdown
Contributor

Backport of #26650 to openwrt-25.12 (kernel 6.12), as @namiltd asked there.

The six commits are cherry-picked from main, with their files moved to the 6.12 names (hack-6.12, patches-6.12, config-6.12). Only 334 changed, for the line numbers of its head.S hunk (@@ -66,8 +66,17 @@ becomes @@ -64,8 +64,17 @@). The two workaround patches that the second commit removes are identical on 6.12, and the rest is as on main.

Built on this branch (08379a3 + the six commits): a full mt7620 image (tplink_archer-c20i) and the rt305x and mt76x8 kernels, with no warnings in the touched files. As on main, the option comes out on for mt7620 and rt305x, with the kernel code at 0x80008000 and the padding freed, and off for mt76x8, at 0x80000400 without the free. make target/linux/refresh changes nothing. I haven't booted these on 25.12: my MT7620A device runs main. The module guard (301-03) is the same file that the TL-WR941ND v3 from #26650 runs on 6.12.

🤖 Generated with Claude Code

@openwrt openwrt Bot added kernel pull request/issue with Linux kernel related changes release/25.12 pull request/issue targeted (also) for OpenWrt 24.10 release target/ramips pull request/issue for ramips target labels Nov 17, 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 6 new commits; no new issues found.


Generated by Claude Code

MarcoMartins86 and others added 6 commits November 19, 2026 10:34
The MIPS 24K core of the MT7620 can save a wrong EPC for an interrupt
taken at the first instruction of a J or JAL target, when the jump is
in the first 32 KiB of a 256 MiB segment. The return from the
interrupt then goes to 0x7... instead of 0x8..., and the kernel dies
with "Unable to handle kernel paging request". ramips links the kernel
at 0x80000000, so its first 32 KiB hold such jumps.

The fault was measured without Linux, from a program started by the
boot loader, and the 24Kc of an AR9132 shows it too. MediaTek's SDK
kernels leave the same 32 KiB empty for the MT7620 and the MT7628, but
an MT7628 doesn't show the fault, so the padding comes with
RALINK_PAD_FIRST_32K. It has no prompt, so it cannot be switched off,
and is on for SOC_MT7620 kernels without the MT76x8 pin controller: the
mt7620 subtarget, not mt76x8.

On the TL-WPA7510 v2, 6 of 17 boots crashed in
try_to_generate_entropy(). With the kernel code moved behind
0x80008000, no J or JAL is left in the first 32 KiB; with the whole
series, 15 boots and 10 minutes of load gave no oops.

Suggested-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt#26650
(cherry picked from commit 3c2a81d)
Link: openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
Patches 330 and 331 avoided direct JALs at the call sites that had been
seen to crash: the random helpers of get_random_u32_below() and
blkcg_maybe_throttle_current() in resume_user_mode_work(). They only
applied to the mt7620 subtarget, and they did not cover the jumps in
random.c that crash the boot in try_to_generate_entropy().

With the kernel code out of the first 32 KiB, no jump is left where the
erratum gives a wrong EPC, so drop them. 332, which skips
arch_align_stack() on exec, stays: it is an optimization of its own,
not one of the jump workarounds.

Tested on a TL-WPA7510 v2 with the whole series: no oops in 15 boots,
nor in 10 minutes of exec-heavy load (24.5k rounds) together with the
reproducer from openwrt#16396.

Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt#26650
(cherry picked from commit 959a7f9)
Link: openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
MIPS 24K cores can save a wrong EPC for an interrupt taken at the
target of a J or JAL in the first 32 KiB of a 256 MiB segment, and the
return from the interrupt then goes to the segment below. This was
measured on the 24KEc of an MT7620A and an RT5350 and on the 24Kc of an
AR9132 and a QCA9531, though not on the 24KEc of an MT7628.

OpenWrt's module allocator (301-02) runs module and BPF JIT code from
the KSEG0 address of the pages it gets, and falls back to vmalloc,
whose area starts at 0xc0000000. On ath79 the kernel starts at
0x80060000, and what the early boot allocations leave free of the RAM
below it goes to the page allocator; on mt7620 the next commit frees
most of the padding that head.S puts there.

Add 301-03: on the 24K cores known to have the fault, those with a PRId
below 0x00019655 (every 24Kc, and the 24KEc before V5.5, which leaves
out the MT7628), hold the blocks the page allocator offers in the first
32 KiB of a segment and ask again, and take the vmalloc fallback from
the rest of the first segment of its area. module_finalize() warns if
module code starts there all the same. Other cores keep the allocator
as it is.

Tested on a TL-WPA7510 v2 with the whole series, in a test build that
took code blocks from the freed movable pages: the seven freed pages
were offered to each 4 KiB block and held, 28 times in all, and none of
9 blocks landed in the first 32 KiB. With the test of the address
switched off, 4 of 9 blocks landed at 0x80004000-0x80007000.

Without the test code: 24 modules, none in a first 32 KiB, in 15 boots
and after 50 rounds of reloading five modules, and 10 minutes of
exec-heavy load without an oops or a warning.

Co-developed-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Link: openwrt#26650
(cherry picked from commit c06ccca)
Link: openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
The first 32 KiB of the kernel image are kept free of code because of
the MIPS 24K EPC erratum, and the module allocator keeps module code
out of them, so hand them back to the page allocator as ordinary data
pages. The first page stays reserved, as the kernel reserves it on
every CPU, which leaves 28 KiB. Nothing is freed if the exception
vectors are in the padding.

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
[Marco: drop the second message, free_reserved_area() logs one; say
 what keeps code out of the pages; keep the first page; move it from
 mt7620.c to of.c, for every SoC with RALINK_PAD_FIRST_32K; add it as a
 patch file]
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Link: openwrt#26650
(cherry picked from commit d1f05be)
Link: openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
The 24KEc of the RT5350 shows the same EPC fault as the MT7620's,
measured from user space: about 38 wrong EPCs a second with J and with
JAL from 0x20003f90 to 0x22e70040, none with JALR. rt305x also links
the kernel at 0x80000000, so turn RALINK_PAD_FIRST_32K on for
SOC_RT305X too. The
padding is freed again as on mt7620, and the module allocator already
keeps module code out of it on every 24K core.

Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt#26650
(cherry picked from commit 6569251)
Link: openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
Commit 7423841 ("ramips: disable CONFIG_LIST_HARDENED on MT7620")
disabled it after the crashes in openwrt#16396, whose cause was unknown. Their
traces show the MIPS 24K EPC erratum: ra in the first 32 KiB of KSEG0
and the EPC in the segment below (0x7...). The checks only made the
crashes more likely, with more cold code and calls in those 32 KiB.
The mt76x8 subtarget kept them, and the MT7628 does not show the fault.

With kernel and module code kept out of the first 32 KiB of a segment,
it can be enabled again, as on the other ramips subtargets. On a
TL-WPA7510 v2 it adds 50 KiB of kernel text, 13 KiB to the compressed
kernel and 2 KiB to the root file system, the modules' checks.

Tested on a TL-WPA7510 v2 booted from RAM: 10 minutes of the reproducer
from openwrt#16396, a loop of `iw <ap> station dump` on both access points
(2200 rounds), together with exec-heavy load (24.5k rounds), without an
oops or a warning. Tested on a TP-Link Archer C5 v4 by Mieczyslaw
Nalewaj.

Suggested-by: Mieczyslaw Nalewaj <[email protected]>
Tested-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt#26650
(cherry picked from commit 6df6804)
Link: openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
@robimarko
robimarko force-pushed the ramips-epc-erratum-25.12 branch from f4a1ca7 to 61a1523 Compare November 19, 2026 09:35
@openwrt-bot
openwrt-bot merged commit 61a1523 into openwrt:openwrt-25.12 Nov 19, 2026
4 of 6 checks passed
@robimarko

Copy link
Copy Markdown
Contributor

Thanks! Rebased on top of openwrt-25.12 and merged!

@MarcoMartins86
MarcoMartins86 deleted the ramips-epc-erratum-25.12 branch November 19, 2026 23:16
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Nov 23, 2026
The MIPS 24K core of the MT7620 can save a wrong EPC for an interrupt
taken at the first instruction of a J or JAL target, when the jump is
in the first 32 KiB of a 256 MiB segment. The return from the
interrupt then goes to 0x7... instead of 0x8..., and the kernel dies
with "Unable to handle kernel paging request". ramips links the kernel
at 0x80000000, so its first 32 KiB hold such jumps.

The fault was measured without Linux, from a program started by the
boot loader, and the 24Kc of an AR9132 shows it too. MediaTek's SDK
kernels leave the same 32 KiB empty for the MT7620 and the MT7628, but
an MT7628 doesn't show the fault, so the padding comes with
RALINK_PAD_FIRST_32K. It has no prompt, so it cannot be switched off,
and is on for SOC_MT7620 kernels without the MT76x8 pin controller: the
mt7620 subtarget, not mt76x8.

On the TL-WPA7510 v2, 6 of 17 boots crashed in
try_to_generate_entropy(). With the kernel code moved behind
0x80008000, no J or JAL is left in the first 32 KiB; with the whole
series, 15 boots and 10 minutes of load gave no oops.

Suggested-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt/openwrt#26650
(cherry picked from commit 3c2a81d482d845cb01190c7311dd8f4b5629ff5b)
Link: openwrt/openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Nov 23, 2026
Patches 330 and 331 avoided direct JALs at the call sites that had been
seen to crash: the random helpers of get_random_u32_below() and
blkcg_maybe_throttle_current() in resume_user_mode_work(). They only
applied to the mt7620 subtarget, and they did not cover the jumps in
random.c that crash the boot in try_to_generate_entropy().

With the kernel code out of the first 32 KiB, no jump is left where the
erratum gives a wrong EPC, so drop them. 332, which skips
arch_align_stack() on exec, stays: it is an optimization of its own,
not one of the jump workarounds.

Tested on a TL-WPA7510 v2 with the whole series: no oops in 15 boots,
nor in 10 minutes of exec-heavy load (24.5k rounds) together with the
reproducer from #16396.

Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt/openwrt#26650
(cherry picked from commit 959a7f9ea96cff203b274c151561efa086c31213)
Link: openwrt/openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Nov 23, 2026
MIPS 24K cores can save a wrong EPC for an interrupt taken at the
target of a J or JAL in the first 32 KiB of a 256 MiB segment, and the
return from the interrupt then goes to the segment below. This was
measured on the 24KEc of an MT7620A and an RT5350 and on the 24Kc of an
AR9132 and a QCA9531, though not on the 24KEc of an MT7628.

OpenWrt's module allocator (301-02) runs module and BPF JIT code from
the KSEG0 address of the pages it gets, and falls back to vmalloc,
whose area starts at 0xc0000000. On ath79 the kernel starts at
0x80060000, and what the early boot allocations leave free of the RAM
below it goes to the page allocator; on mt7620 the next commit frees
most of the padding that head.S puts there.

Add 301-03: on the 24K cores known to have the fault, those with a PRId
below 0x00019655 (every 24Kc, and the 24KEc before V5.5, which leaves
out the MT7628), hold the blocks the page allocator offers in the first
32 KiB of a segment and ask again, and take the vmalloc fallback from
the rest of the first segment of its area. module_finalize() warns if
module code starts there all the same. Other cores keep the allocator
as it is.

Tested on a TL-WPA7510 v2 with the whole series, in a test build that
took code blocks from the freed movable pages: the seven freed pages
were offered to each 4 KiB block and held, 28 times in all, and none of
9 blocks landed in the first 32 KiB. With the test of the address
switched off, 4 of 9 blocks landed at 0x80004000-0x80007000.

Without the test code: 24 modules, none in a first 32 KiB, in 15 boots
and after 50 rounds of reloading five modules, and 10 minutes of
exec-heavy load without an oops or a warning.

Co-developed-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Link: openwrt/openwrt#26650
(cherry picked from commit c06ccca080872d054e564a79b652d4343ea3a1fc)
Link: openwrt/openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Nov 23, 2026
The first 32 KiB of the kernel image are kept free of code because of
the MIPS 24K EPC erratum, and the module allocator keeps module code
out of them, so hand them back to the page allocator as ordinary data
pages. The first page stays reserved, as the kernel reserves it on
every CPU, which leaves 28 KiB. Nothing is freed if the exception
vectors are in the padding.

Signed-off-by: Mieczyslaw Nalewaj <[email protected]>
[Marco: drop the second message, free_reserved_area() logs one; say
 what keeps code out of the pages; keep the first page; move it from
 mt7620.c to of.c, for every SoC with RALINK_PAD_FIRST_32K; add it as a
 patch file]
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Link: openwrt/openwrt#26650
(cherry picked from commit d1f05be244cfe173407bc592595b5ce3707d9aed)
Link: openwrt/openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Nov 23, 2026
The 24KEc of the RT5350 shows the same EPC fault as the MT7620's,
measured from user space: about 38 wrong EPCs a second with J and with
JAL from 0x20003f90 to 0x22e70040, none with JALR. rt305x also links
the kernel at 0x80000000, so turn RALINK_PAD_FIRST_32K on for
SOC_RT305X too. The
padding is freed again as on mt7620, and the module allocator already
keeps module code out of it on every 24K core.

Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt/openwrt#26650
(cherry picked from commit 656925183532053e8c1757b382bddc8ef3779494)
Link: openwrt/openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
liudf0716 pushed a commit to liudf0716/chawrt that referenced this pull request Nov 23, 2026
Commit 7423841 ("ramips: disable CONFIG_LIST_HARDENED on MT7620")
disabled it after the crashes in #16396, whose cause was unknown. Their
traces show the MIPS 24K EPC erratum: ra in the first 32 KiB of KSEG0
and the EPC in the segment below (0x7...). The checks only made the
crashes more likely, with more cold code and calls in those 32 KiB.
The mt76x8 subtarget kept them, and the MT7628 does not show the fault.

With kernel and module code kept out of the first 32 KiB of a segment,
it can be enabled again, as on the other ramips subtargets. On a
TL-WPA7510 v2 it adds 50 KiB of kernel text, 13 KiB to the compressed
kernel and 2 KiB to the root file system, the modules' checks.

Tested on a TL-WPA7510 v2 booted from RAM: 10 minutes of the reproducer
from #16396, a loop of `iw <ap> station dump` on both access points
(2200 rounds), together with exec-heavy load (24.5k rounds), without an
oops or a warning. Tested on a TP-Link Archer C5 v4 by Mieczyslaw
Nalewaj.

Suggested-by: Mieczyslaw Nalewaj <[email protected]>
Tested-by: Mieczyslaw Nalewaj <[email protected]>
Signed-off-by: Marco Martins <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Link: openwrt/openwrt#26650
(cherry picked from commit 6df68042d1db716eabca0754880876cc8a408c85)
Link: openwrt/openwrt#26784
Signed-off-by: Robert Marko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kernel pull request/issue with Linux kernel related changes release/25.12 pull request/issue targeted (also) for OpenWrt 24.10 release target/ramips pull request/issue for ramips target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants