From nobody Mon Dec 1 23:35:11 2025 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CB652E2DEF for ; Tue, 25 Nov 2025 21:39:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764106803; cv=none; b=VfQJJNjubdGmFgW9Ht1Js38sMX48zWiZM0ZR0QB+8DqxXD0FOnnU2sl4ZT+HKlN1EsYlpkoYPdzh0Vat+iVzgN1UyebrP3tQZepl1sFZfsU66I14YPKjWE8H7/lUuTiUBj2NaqNlZ7iupf6/MqB7+nDO6vUe+BO+72uvm8hVxKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764106803; c=relaxed/simple; bh=8z2cZU846sahQ+KcKbeJsiqHMdU/DEC/qyZLMKHufmc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Pvk44KiPu22ZB/jQovSDZ71G/8e1PzFeL8d/rFGEpYSy6YlF5ZVfjebDFP9zf1np3rTyKFMnHtSSJkJqy5BHlExwxw8el9pfJKigfg+/mBTWD5X3zIkovNotmlv2rK5QHtKYz9yT9YXUMkTLQEhYdR87HmHe3Ao/fQPtKO3WJlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=alpha.franken.de; spf=fail smtp.mailfrom=alpha.franken.de; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=alpha.franken.de Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=alpha.franken.de Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 1A1EE5BD11; Tue, 25 Nov 2025 21:39:58 +0000 (UTC) Authentication-Results: smtp-out2.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 03EB43EA63; Tue, 25 Nov 2025 21:39:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 8xaRAC4iJmnqBAAAD6G6ig (envelope-from ); Tue, 25 Nov 2025 21:39:58 +0000 From: Thomas Bogendoerfer To: "Maciej W. Rozycki" , Jiaxun Yang , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Gregory CLEMENT Subject: [PATCH v2] MIPS: mm: kmalloc tlb_vpn array to avoid stack overflow Date: Tue, 25 Nov 2025 22:39:42 +0100 Message-ID: <20251125213942.125599-1-tsbogend@alpha.franken.de> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_FIVE(0.00)[5]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Flag: NO X-Spam-Score: -2.80 Content-Type: text/plain; charset="utf-8" Latest MIPS cores could have much more than 64 TLB entries, therefore allocate array for unification instead of placing a too small array on stack. Fixes: 9f048fa48740 ("MIPS: mm: Prevent a TLB shutdown on initial uniquific= ation") Tested-by: Gregory CLEMENT Signed-off-by: Thomas Bogendoerfer --- arch/mips/mm/tlb-r4k.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/mips/mm/tlb-r4k.c b/arch/mips/mm/tlb-r4k.c index 3facf7cc6c7d..5f96a19ecb67 100644 --- a/arch/mips/mm/tlb-r4k.c +++ b/arch/mips/mm/tlb-r4k.c @@ -524,15 +524,19 @@ static int r4k_vpn_cmp(const void *a, const void *b) */ static void r4k_tlb_uniquify(void) { - unsigned long tlb_vpns[1 << MIPS_CONF1_TLBS_SIZE]; int tlbsize =3D current_cpu_data.tlbsize; int start =3D num_wired_entries(); + unsigned long *tlb_vpns; unsigned long vpn_mask; int cnt, ent, idx, i; =20 vpn_mask =3D GENMASK(cpu_vmbits - 1, 13); vpn_mask |=3D IS_ENABLED(CONFIG_64BIT) ? 3ULL << 62 : 1 << 31; =20 + tlb_vpns =3D kmalloc_array(tlbsize, sizeof(unsigned long), GFP_KERNEL); + if (WARN_ON(!tlb_vpns)) + return; /* Pray local_flush_tlb_all() is good enough. */ + htw_stop(); =20 for (i =3D start, cnt =3D 0; i < tlbsize; i++, cnt++) { @@ -585,6 +589,7 @@ static void r4k_tlb_uniquify(void) tlbw_use_hazard(); htw_start(); flush_micro_tlb(); + kfree(tlb_vpns); } =20 /* --=20 2.43.0