|
| 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(¤t_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