Skip to content

Commit b8d232d

Browse files
committed
kernel: Fix boot of realtek rtl838x
Revert two patches from upstream Linux: gregkh/linux@135713c gregkh/linux@231ac95 This fixes a boot hang on realtek rtl838x switches. This is the last printed message: Inode-cache hash table entries: 8192 (order: 3, 32768 bytes, linear) Thread on mips mailing list: https://lore.kernel.org/linux-mips/[email protected]/T/#u Link: openwrt/openwrt#21166 Signed-off-by: Hauke Mehrtens <[email protected]>
1 parent 3c97c4a commit b8d232d

File tree

2 files changed

+206
-0
lines changed

2 files changed

+206
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Hauke Mehrtens <[email protected]>
3+
Date: Mon, 15 Dec 2025 01:45:07 +0100
4+
Subject: Revert "MIPS: mm: kmalloc tlb_vpn array to avoid stack overflow"
5+
6+
This reverts commit 231ac951fabae2aaed8b2c00b4a097107be49c8c.
7+
---
8+
arch/mips/mm/tlb-r4k.c | 18 ++----------------
9+
1 file changed, 2 insertions(+), 16 deletions(-)
10+
11+
--- a/arch/mips/mm/tlb-r4k.c
12+
+++ b/arch/mips/mm/tlb-r4k.c
13+
@@ -12,7 +12,6 @@
14+
#include <linux/init.h>
15+
#include <linux/sched.h>
16+
#include <linux/smp.h>
17+
-#include <linux/memblock.h>
18+
#include <linux/mm.h>
19+
#include <linux/hugetlb.h>
20+
#include <linux/export.h>
21+
@@ -521,26 +520,17 @@ static int r4k_vpn_cmp(const void *a, co
22+
* Initialise all TLB entries with unique values that do not clash with
23+
* what we have been handed over and what we'll be using ourselves.
24+
*/
25+
-static void __ref r4k_tlb_uniquify(void)
26+
+static void r4k_tlb_uniquify(void)
27+
{
28+
+ unsigned long tlb_vpns[1 << MIPS_CONF1_TLBS_SIZE];
29+
int tlbsize = current_cpu_data.tlbsize;
30+
- bool use_slab = slab_is_available();
31+
int start = num_wired_entries();
32+
- phys_addr_t tlb_vpn_size;
33+
- unsigned long *tlb_vpns;
34+
unsigned long vpn_mask;
35+
int cnt, ent, idx, i;
36+
37+
vpn_mask = GENMASK(cpu_vmbits - 1, 13);
38+
vpn_mask |= IS_ENABLED(CONFIG_64BIT) ? 3ULL << 62 : 1 << 31;
39+
40+
- tlb_vpn_size = tlbsize * sizeof(*tlb_vpns);
41+
- tlb_vpns = (use_slab ?
42+
- kmalloc(tlb_vpn_size, GFP_KERNEL) :
43+
- memblock_alloc_raw(tlb_vpn_size, sizeof(*tlb_vpns)));
44+
- if (WARN_ON(!tlb_vpns))
45+
- return; /* Pray local_flush_tlb_all() is good enough. */
46+
-
47+
htw_stop();
48+
49+
for (i = start, cnt = 0; i < tlbsize; i++, cnt++) {
50+
@@ -593,10 +583,6 @@ static void __ref r4k_tlb_uniquify(void)
51+
tlbw_use_hazard();
52+
htw_start();
53+
flush_micro_tlb();
54+
- if (use_slab)
55+
- kfree(tlb_vpns);
56+
- else
57+
- memblock_free(tlb_vpns, tlb_vpn_size);
58+
}
59+
60+
/*
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Hauke Mehrtens <[email protected]>
3+
Date: Mon, 15 Dec 2025 01:45:20 +0100
4+
Subject: Revert "MIPS: mm: Prevent a TLB shutdown on initial uniquification"
5+
6+
This reverts commit 135713cd0751bf296e515f5fdec234320f73bbd8.
7+
---
8+
arch/mips/mm/tlb-r4k.c | 100 +++++++++++++++--------------------------
9+
1 file changed, 37 insertions(+), 63 deletions(-)
10+
11+
--- a/arch/mips/mm/tlb-r4k.c
12+
+++ b/arch/mips/mm/tlb-r4k.c
13+
@@ -15,7 +15,6 @@
14+
#include <linux/mm.h>
15+
#include <linux/hugetlb.h>
16+
#include <linux/export.h>
17+
-#include <linux/sort.h>
18+
19+
#include <asm/cpu.h>
20+
#include <asm/cpu-type.h>
21+
@@ -507,79 +506,55 @@ static int __init set_ntlb(char *str)
22+
23+
__setup("ntlb=", set_ntlb);
24+
25+
-
26+
-/* Comparison function for EntryHi VPN fields. */
27+
-static int r4k_vpn_cmp(const void *a, const void *b)
28+
-{
29+
- long v = *(unsigned long *)a - *(unsigned long *)b;
30+
- int s = sizeof(long) > sizeof(int) ? sizeof(long) * 8 - 1: 0;
31+
- return s ? (v != 0) | v >> s : v;
32+
-}
33+
-
34+
-/*
35+
- * Initialise all TLB entries with unique values that do not clash with
36+
- * what we have been handed over and what we'll be using ourselves.
37+
- */
38+
+/* Initialise all TLB entries with unique values */
39+
static void r4k_tlb_uniquify(void)
40+
{
41+
- unsigned long tlb_vpns[1 << MIPS_CONF1_TLBS_SIZE];
42+
- int tlbsize = current_cpu_data.tlbsize;
43+
- int start = num_wired_entries();
44+
- unsigned long vpn_mask;
45+
- int cnt, ent, idx, i;
46+
-
47+
- vpn_mask = GENMASK(cpu_vmbits - 1, 13);
48+
- vpn_mask |= IS_ENABLED(CONFIG_64BIT) ? 3ULL << 62 : 1 << 31;
49+
+ int entry = num_wired_entries();
50+
51+
htw_stop();
52+
+ write_c0_entrylo0(0);
53+
+ write_c0_entrylo1(0);
54+
55+
- for (i = start, cnt = 0; i < tlbsize; i++, cnt++) {
56+
- unsigned long vpn;
57+
+ while (entry < current_cpu_data.tlbsize) {
58+
+ unsigned long asid_mask = cpu_asid_mask(&current_cpu_data);
59+
+ unsigned long asid = 0;
60+
+ int idx;
61+
62+
- write_c0_index(i);
63+
- mtc0_tlbr_hazard();
64+
- tlb_read();
65+
- tlb_read_hazard();
66+
- vpn = read_c0_entryhi();
67+
- vpn &= vpn_mask & PAGE_MASK;
68+
- tlb_vpns[cnt] = vpn;
69+
+ /* Skip wired MMID to make ginvt_mmid work */
70+
+ if (cpu_has_mmid)
71+
+ asid = MMID_KERNEL_WIRED + 1;
72+
73+
- /* Prevent any large pages from overlapping regular ones. */
74+
- write_c0_pagemask(read_c0_pagemask() & PM_DEFAULT_MASK);
75+
+ /* Check for match before using UNIQUE_ENTRYHI */
76+
+ do {
77+
+ if (cpu_has_mmid) {
78+
+ write_c0_memorymapid(asid);
79+
+ write_c0_entryhi(UNIQUE_ENTRYHI(entry));
80+
+ } else {
81+
+ write_c0_entryhi(UNIQUE_ENTRYHI(entry) | asid);
82+
+ }
83+
+ mtc0_tlbw_hazard();
84+
+ tlb_probe();
85+
+ tlb_probe_hazard();
86+
+ idx = read_c0_index();
87+
+ /* No match or match is on current entry */
88+
+ if (idx < 0 || idx == entry)
89+
+ break;
90+
+ /*
91+
+ * If we hit a match, we need to try again with
92+
+ * a different ASID.
93+
+ */
94+
+ asid++;
95+
+ } while (asid < asid_mask);
96+
+
97+
+ if (idx >= 0 && idx != entry)
98+
+ panic("Unable to uniquify TLB entry %d", idx);
99+
+
100+
+ write_c0_index(entry);
101+
mtc0_tlbw_hazard();
102+
tlb_write_indexed();
103+
- tlbw_use_hazard();
104+
+ entry++;
105+
}
106+
107+
- sort(tlb_vpns, cnt, sizeof(tlb_vpns[0]), r4k_vpn_cmp, NULL);
108+
-
109+
- write_c0_pagemask(PM_DEFAULT_MASK);
110+
- write_c0_entrylo0(0);
111+
- write_c0_entrylo1(0);
112+
-
113+
- idx = 0;
114+
- ent = tlbsize;
115+
- for (i = start; i < tlbsize; i++)
116+
- while (1) {
117+
- unsigned long entryhi, vpn;
118+
-
119+
- entryhi = UNIQUE_ENTRYHI(ent);
120+
- vpn = entryhi & vpn_mask & PAGE_MASK;
121+
-
122+
- if (idx >= cnt || vpn < tlb_vpns[idx]) {
123+
- write_c0_entryhi(entryhi);
124+
- write_c0_index(i);
125+
- mtc0_tlbw_hazard();
126+
- tlb_write_indexed();
127+
- ent++;
128+
- break;
129+
- } else if (vpn == tlb_vpns[idx]) {
130+
- ent++;
131+
- } else {
132+
- idx++;
133+
- }
134+
- }
135+
-
136+
tlbw_use_hazard();
137+
htw_start();
138+
flush_micro_tlb();
139+
@@ -625,7 +600,6 @@ static void r4k_tlb_configure(void)
140+
141+
/* From this point on the ARC firmware is dead. */
142+
r4k_tlb_uniquify();
143+
- local_flush_tlb_all();
144+
145+
/* Did I tell you that ARC SUCKS? */
146+
}

0 commit comments

Comments
 (0)