From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 438E9219303; Sat, 30 May 2026 18:23:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780165396; cv=none; b=FQohIiJMK7YcRbvt6NsZBjrB1BWMn33IXXzEzmT/I230wlOI6b6pVLpT5zPkjCBgx1ZoXC2npKZXqs0EewS/PJXgQK+6K3fqZAT9P4gnkBOs/AksIPfdM8dWc0D1DhHiuu+Z9U9s8QNGZrXdlfe83otCLUalpVcTgnnPBm9qezU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780165396; c=relaxed/simple; bh=d/mppMHivmdJ9ZbJhLhTvpbnQ/7c2z+uh2tXKYx/jRY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=umhpiYK5Z/txUOziJyb8+6BvTAJvJumoVH0+C826sRrCyerK93sztBKvlFt4evp/fMr04HmBspnVCo/sWVgKFLAe5blPGyuff7tXiMNaR4mCXXPbeo8uP28d8BRqi04qgbxvWbwZA8CGAu5ofkqKZCmjWM6Wue4SIYw5I8kc2Yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=YjQ+583J; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="YjQ+583J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 887011F00893; Sat, 30 May 2026 18:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1780165395; bh=JC0XqhC97qH070ulm3oA5Pcxnhq0ERifZSqbDpxioKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=YjQ+583Jnt55+iAO0xkpWpNCQ//DP3A1fBS+JX6tYHu/BMUTbP3JEpkA2rnJfPp/M AZ5lnWGwLc+35h4OiOCMUVsApvdhU/GdrIGg5WGUY7ex08mH7P2w/qP/nLNeor+lhW H4axr8aEe22PeqirgptZp/ansCkigTEk2V5Udo/Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Maciej W. Rozycki" , Gregory CLEMENT , Klara Modin , Thomas Bogendoerfer , Sasha Levin Subject: [PATCH 5.10 036/589] MIPS: mm: kmalloc tlb_vpn array to avoid stack overflow Date: Sat, 30 May 2026 17:58:37 +0200 Message-ID: <20260530160225.537167195@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260530160224.570625122@linuxfoundation.org> References: <20260530160224.570625122@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ 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(__pa(...), ...) for 5.10.y. ] Signed-off-by: Maciej W. Rozycki Signed-off-by: Sasha Levin --- 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 d9a5ede8869bd..8bc98c311ca62 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(__pa(tlb_vpns), tlb_vpn_size); } /* -- 2.53.0