linux/arch/mips
Maciej W. Rozycki 79ad8f6571 MIPS: mm: Rewrite TLB uniquification for the hidden bit feature
commit 540760b77b upstream.

Before the introduction of the EHINV feature, which lets software mark
TLB entries invalid, certain older implementations of the MIPS ISA were
equipped with an analogous bit, as a vendor extension, which however is
hidden from software and only ever set at reset, and then any software
write clears it, making the intended TLB entry valid.

This feature makes it unsafe to read a TLB entry with TLBR, modify the
page mask, and write the entry back with TLBWI, because this operation
will implicitly clear the hidden bit and this may create a duplicate
entry, as with the presence of the hidden bit there is no guarantee all
the entries across the TLB are unique each.

Usually the firmware has already uniquified TLB entries before handing
control over, in which case we only need to guarantee at bootstrap no
clash will happen with the VPN2 values chosen in local_flush_tlb_all().

However with systems such as Mikrotik RB532 we get handed the TLB as at
reset, with the hidden bit set across the entries and possibly duplicate
entries present.  This then causes a machine check exception when page
sizes are reset in r4k_tlb_uniquify() and prevents the system from
booting.

Rewrite the algorithm used in r4k_tlb_uniquify() then such as to avoid
the reuse of ASID/VPN values across the TLB.  Get rid of global entries
first as they may be blocking the entire address space, e.g. 16 256MiB
pages will exhaust the whole address space of a 32-bit CPU and a single
big page can exhaust the 32-bit compatibility space on a 64-bit CPU.

Details of the algorithm chosen are given across the code itself.

Fixes: 9f048fa487 ("MIPS: mm: Prevent a TLB shutdown on initial uniquification")
Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: stable@vger.kernel.org # v6.18+
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2026-06-01 17:35:04 +02:00
..
alchemy MIPS: Alchemy: Fix an out-of-bound access in db1550_dev_setup() 2024-01-25 14:52:50 -08:00
ar7 mips: ar7: convert to CONFIG_COMMON_CLK 2021-06-08 17:00:09 +02:00
ath25 mips: Bulk conversion to generic_handle_domain_irq() 2021-08-12 11:39:40 +01:00
ath79 MIPS: of: Introduce helper function to get DTB 2021-02-04 13:34:51 +01:00
bcm47xx MIPS: BCM47XX: Cast memcmp() of function to (void *) 2022-10-26 12:35:30 +02:00
bcm63xx MIPS: BCM63xx: Add check for NULL for clk in clk_enable 2022-12-31 13:14:05 +01:00
bmips mips: bmips: BCM6358: make sure CBR is correctly set 2024-07-05 09:14:29 +02:00
boot mips: lantiq: danube: add missing device_type in pci node 2025-12-07 06:09:20 +09:00
cavium-octeon MIPS: OCTEON: warn only once if deprecated link status is being used 2022-12-31 13:14:05 +01:00
cobalt MIPS: Remove empty prom_free_prom_memory functions 2021-01-07 17:11:33 +01:00
configs Remove DECnet support from kernel 2023-06-21 15:59:15 +02:00
crypto lib/crypto: mips/chacha: Fix clang build and remove unneeded byteswap 2025-08-28 16:24:27 +02:00
dec MIPS: dec: Declare which_prom() as static 2025-05-02 07:44:23 +02:00
fw MIPS: fw: Allow firmware to pass a empty env 2023-05-11 23:00:17 +09:00
generic MIPS: generic/yamon-dt: fix uninitialized variable error 2021-11-25 09:48:36 +01:00
include MIPS: Always record SEGBITS in cpu_data.vmbits 2026-06-01 17:35:03 +02:00
ingenic MIPS: Kconfig: ingenic: Ensure MACH_INGENIC_GENERIC selects all SoCs 2021-06-01 11:44:47 +02:00
jazz MIPS/jazzdma: return error code from jazz_dma_map_sg() 2021-08-09 17:13:05 +02:00
kernel MIPS: Always record SEGBITS in cpu_data.vmbits 2026-06-01 17:35:03 +02:00
kvm MIPS: KVM: Fix a build warning about variable set but not used 2023-12-03 07:31:23 +01:00
lantiq mips: lantiq: xway: sysctrl: rename stp clock 2025-12-07 06:09:20 +09:00
lib MIPS: Fix the GCC version check for `__multi3' workaround 2026-04-18 10:33:32 +02:00
loongson2ef MIPS: Prefer cc-option for additions to cflags 2025-06-27 11:05:21 +01:00
loongson32 MIPS: Loongson32: Fix PHY-mode being left unspecified 2022-09-28 11:11:48 +02:00
loongson64 Makefile.compiler: replace cc-ifversion with compiler-specific macros 2025-12-07 06:09:32 +09:00
math-emu mips/math-emu: fix emulation of the prefx instruction 2025-03-13 12:50:28 +01:00
mm MIPS: mm: Rewrite TLB uniquification for the hidden bit feature 2026-06-01 17:35:04 +02:00
mti-malta MIPS: Malta: Fix !EVA SOC-it PCI MMIO 2025-12-07 06:09:31 +09:00
n64 mips: Add N64 machine type 2021-01-22 11:40:00 +01:00
net bpf, mips: Validate conditional branch offsets 2021-09-15 21:38:16 +02:00
netlogic mips: netlogic: fix kernel-doc complaints in fmn-config.c 2021-07-22 11:48:06 +02:00
pci MIPS: Octeron: remove source file executable bit 2024-08-19 05:45:06 +02:00
pic32 MIPS: pic32: treat port as signed integer 2022-12-02 17:41:02 +01:00
power mips: check for dsp presence only once before save/restore 2019-10-07 10:58:53 -07:00
ralink mips: ralink: mt7621: do not use kzalloc too early 2022-12-31 13:14:04 +01:00
rb532 MIPS: rb532: Fix MMIO UART resource registration 2026-03-04 07:20:35 -05:00
sgi-ip22 bus: Make remove callback return void 2021-07-21 11:53:42 +02:00
sgi-ip27 memblock: allow to specify flags with memblock_add_node() 2023-12-20 15:17:33 +01:00
sgi-ip30 MIPS: ip30: ip30-console: Add missing include 2024-08-19 05:45:21 +02:00
sgi-ip32 kernel.h: split out panic and oops helpers 2021-07-01 11:06:04 -07:00
sibyte MIPS: Remove empty prom_free_prom_memory functions 2021-01-07 17:11:33 +01:00
sni MIPS: sni: Fix the build 2021-11-25 09:48:28 +01:00
tools MIPS: tools: Fix resource leak in elf-entry.c 2020-05-24 09:29:48 +02:00
txx9 MIPS: Remove empty prom_free_prom_memory functions 2021-01-07 17:11:33 +01:00
vdso mips: Add -std= flag specified in KBUILD_CFLAGS to vdso CFLAGS 2025-06-27 11:05:27 +01:00
vr41xx MIPS: Remove repetitive increase irq_err_count 2022-06-29 09:03:24 +02:00
Kbuild MIPS: Fix "make clean" error due to recent changes 2020-05-13 13:20:22 +02:00
Kbuild.platforms MIPS: fix duplicated slashes for Platform file path 2021-11-18 19:17:14 +01:00
Kconfig MIPS: Loongson64: Enable DMA noncoherent support 2023-12-13 18:36:50 +01:00
Kconfig.debug tracing: Refactor TRACE_IRQFLAGS_SUPPORT in Kconfig 2021-08-16 11:37:21 -04:00
Makefile mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation 2025-06-27 11:05:21 +01:00
Makefile.postlink MIPS: fix indentation of the 'RELOCS' message 2020-01-20 15:37:30 -08:00