All of lore.kernel.org
 help / color / mirror / Atom feed
From: Imre Kaloz <kaloz@kernel.org>
To: Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
	linux-mips@vger.kernel.org
Cc: Ethan Nelson-Moore <enelsonmoore@gmail.com>,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: [PATCH] MIPS: c-r4k: Flush the cache error vector before writing it uncached
Date: Wed, 21 Oct 2026 21:00:20 +0200	[thread overview]
Message-ID: <20261021190020.20954-1-kaloz@kernel.org> (raw)

On R10000-class CPUs, a store prefetch while copying the preceding
vector can leave a dirty line whose write-back overwrites the uncached
cache error handler. Flush it first in r4k_cache_error_setup() with
r4k_dma_cache_wback_inv(), as dma_cache_wback_inv() is a no-op on
coherent systems.

Fixes: e01402b115cc ("More AP / SP bits for the 34K, the Malta bits and things.  Still wants a little polishing.")
Cc: stable@vger.kernel.org
Signed-off-by: Imre Kaloz <kaloz@kernel.org>
---
 arch/mips/mm/c-r4k.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index d8aadd3dc057..ae31966ac65b 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -743,8 +743,6 @@ static void r4k_flush_icache_user_range(unsigned long start, unsigned long end)
 	return __r4k_flush_icache_range(start, end, true);
 }
 
-#ifdef CONFIG_DMA_NONCOHERENT
-
 static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
 {
 	/* Catch bad driver code */
@@ -786,6 +784,8 @@ static void r4k_dma_cache_wback_inv(unsigned long addr, unsigned long size)
 	__sync();
 }
 
+#ifdef CONFIG_DMA_NONCOHERENT
+
 static void prefetch_cache_inv(unsigned long addr, unsigned long size)
 {
 	unsigned int linesz = cpu_scache_line_size();
@@ -1684,6 +1684,14 @@ static void r4k_cache_error_setup(void)
 	extern char __weak except_vec2_generic;
 	extern char __weak except_vec2_sb1;
 
+	/*
+	 * The handler is written uncached. Copying the preceding vector
+	 * may have left a dirty cached line of it behind, through a store
+	 * prefetch or a speculative store; write it back and invalidate it
+	 * first, or its later write-back overwrites the handler.
+	 */
+	r4k_dma_cache_wback_inv(ebase + 0x100, 0x80);
+
 	switch (current_cpu_type()) {
 	case CPU_SB1:
 	case CPU_SB1A:

base-commit: 24a19b953e2a3d0ea5a8c4951a0ab8f32720c907

             reply	other threads:[~2026-10-21 19:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 19:00 Imre Kaloz [this message]
2026-10-22 16:19 ` [PATCH] MIPS: c-r4k: Flush the cache error vector before writing it uncached Maciej W. Rozycki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021190020.20954-1-kaloz@kernel.org \
    --to=kaloz@kernel.org \
    --cc=enelsonmoore@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.