From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D444E347508 for ; Mon, 13 Apr 2026 17:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=78.133.224.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776100834; cv=none; b=R1bVnae1kuvevFUV1m1lIyH4yGq2DrQJrDnkj/vapvMIOcgCp0WIZLPHBTFOY52rI4Dmi3YiEOutmt2g04JCk5o5gUGBrRfFXJbn61wz6PZxN6pG8wXP9hXtoA+NybgFS7xfzhPHZ+3i+GRI/1dbkgyPwF9kH8Bn8W8JHPHJPQk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776100834; c=relaxed/simple; bh=EC6MzfkL9NCVAv4Rji7kgc09UrnTZlFoS505kP0pE+M=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=je673sooe4iihMte1SJjVDcLKFUSUTTMJq1VJ3VRo1t0M0+7uMPe0jY0PXxuN4g4mFdKADEH3HLPT4FwLv6+l3+0EklTFzwy+RK9AI7pvtH4k8VqTyBjNiF8yVYDejzXYwWM8gm/oWjd7baVodOGQm4NnSdcF1Ickyf6M74KqQw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk; spf=none smtp.mailfrom=orcam.me.uk; arc=none smtp.client-ip=78.133.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=orcam.me.uk Received: by angie.orcam.me.uk (Postfix, from userid 500) id 81FE992009E; Mon, 13 Apr 2026 19:20:29 +0200 (CEST) From: "Maciej W. Rozycki" To: stable@vger.kernel.org Cc: Thomas Bogendoerfer , "Maciej W . Rozycki" , Gregory CLEMENT , Klara Modin Subject: [PATCH 5.15.y v2 1/5] MIPS: mm: kmalloc tlb_vpn array to avoid stack overflow Date: Mon, 13 Apr 2026 18:20:00 +0100 Message-Id: <20260413172004.31485-1-macro@orcam.me.uk> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Thomas Bogendoerfer commit 841ecc979b18d3227fad5e2d6a1e6f92688776b5 upstream. Owing to Config4.MMUSizeExt and VTLB/FTLB MMU features later MIPSr2+ cores can have more than 64 TLB entries. Therefore allocate an array for uniquification instead of placing too an small array on the stack. Fixes: 35ad7e181541 ("MIPS: mm: tlb-r4k: Uniquify TLB entries on init") Co-developed-by: Maciej W. Rozycki Signed-off-by: Maciej W. Rozycki Cc: stable@vger.kernel.org # v6.17+: 9f048fa48740: MIPS: mm: Prevent a TLB shutdown on initial uniquification Cc: stable@vger.kernel.org # v6.17+ Tested-by: Gregory CLEMENT Tested-by: Klara Modin Signed-off-by: Thomas Bogendoerfer [ Use memblock_free_ptr() for 5.15.y. ] Signed-off-by: Maciej W. Rozycki --- arch/mips/mm/tlb-r4k.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c index d9a5ede8869b..78e1420471b4 100644 --- a/arch/mips/mm/tlb-r4k.c +++ b/arch/mips/mm/tlb-r4k.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -512,17 +513,26 @@ static int r4k_vpn_cmp(const void *a, const void *b) * Initialise all TLB entries with unique values that do not clash with * what we have been handed over and what we'll be using ourselves. */ -static void r4k_tlb_uniquify(void) +static void __ref r4k_tlb_uniquify(void) { - unsigned long tlb_vpns[1 << MIPS_CONF1_TLBS_SIZE]; int tlbsize = current_cpu_data.tlbsize; + bool use_slab = slab_is_available(); int start = num_wired_entries(); + phys_addr_t tlb_vpn_size; + unsigned long *tlb_vpns; unsigned long vpn_mask; int cnt, ent, idx, i; vpn_mask = GENMASK(cpu_vmbits - 1, 13); vpn_mask |= IS_ENABLED(CONFIG_64BIT) ? 3ULL << 62 : 1 << 31; + tlb_vpn_size = tlbsize * sizeof(*tlb_vpns); + tlb_vpns = (use_slab ? + kmalloc(tlb_vpn_size, GFP_KERNEL) : + memblock_alloc_raw(tlb_vpn_size, sizeof(*tlb_vpns))); + if (WARN_ON(!tlb_vpns)) + return; /* Pray local_flush_tlb_all() is good enough. */ + htw_stop(); for (i = start, cnt = 0; i < tlbsize; i++, cnt++) { @@ -575,6 +585,10 @@ static void r4k_tlb_uniquify(void) tlbw_use_hazard(); htw_start(); flush_micro_tlb(); + if (use_slab) + kfree(tlb_vpns); + else + memblock_free_ptr(tlb_vpns, tlb_vpn_size); } /* -- 2.20.1