Skip to content

Commit 6bda50f

Browse files
committed
Merge tag 'mips-fixes_6.18_2' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux
Pull MIPS fix from Thomas Bogendoerfer: "Fix TLB unification for cores with more than 64 TLB entries" * tag 'mips-fixes_6.18_2' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux: MIPS: mm: kmalloc tlb_vpn array to avoid stack overflow
2 parents 19eef1d + 841ecc9 commit 6bda50f

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

arch/mips/mm/tlb-r4k.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/init.h>
1313
#include <linux/sched.h>
1414
#include <linux/smp.h>
15+
#include <linux/memblock.h>
1516
#include <linux/mm.h>
1617
#include <linux/hugetlb.h>
1718
#include <linux/export.h>
@@ -522,17 +523,26 @@ static int r4k_vpn_cmp(const void *a, const void *b)
522523
* Initialise all TLB entries with unique values that do not clash with
523524
* what we have been handed over and what we'll be using ourselves.
524525
*/
525-
static void r4k_tlb_uniquify(void)
526+
static void __ref r4k_tlb_uniquify(void)
526527
{
527-
unsigned long tlb_vpns[1 << MIPS_CONF1_TLBS_SIZE];
528528
int tlbsize = current_cpu_data.tlbsize;
529+
bool use_slab = slab_is_available();
529530
int start = num_wired_entries();
531+
phys_addr_t tlb_vpn_size;
532+
unsigned long *tlb_vpns;
530533
unsigned long vpn_mask;
531534
int cnt, ent, idx, i;
532535

533536
vpn_mask = GENMASK(cpu_vmbits - 1, 13);
534537
vpn_mask |= IS_ENABLED(CONFIG_64BIT) ? 3ULL << 62 : 1 << 31;
535538

539+
tlb_vpn_size = tlbsize * sizeof(*tlb_vpns);
540+
tlb_vpns = (use_slab ?
541+
kmalloc(tlb_vpn_size, GFP_KERNEL) :
542+
memblock_alloc_raw(tlb_vpn_size, sizeof(*tlb_vpns)));
543+
if (WARN_ON(!tlb_vpns))
544+
return; /* Pray local_flush_tlb_all() is good enough. */
545+
536546
htw_stop();
537547

538548
for (i = start, cnt = 0; i < tlbsize; i++, cnt++) {
@@ -585,6 +595,10 @@ static void r4k_tlb_uniquify(void)
585595
tlbw_use_hazard();
586596
htw_start();
587597
flush_micro_tlb();
598+
if (use_slab)
599+
kfree(tlb_vpns);
600+
else
601+
memblock_free(tlb_vpns, tlb_vpn_size);
588602
}
589603

590604
/*

0 commit comments

Comments
 (0)