From: Stafford Horne <shorne@gmail.com>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Linux OpenRISC <linux-openrisc@vger.kernel.org>,
Stafford Horne <shorne@gmail.com>,
stable@vger.kernel.org, Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Zi Yan <ziy@nvidia.com>,
Andrew Morton <akpm@linux-foundation.org>,
Thomas Gleixner <tglx@kernel.org>
Subject: [PATCH 2/3] openrisc: Add full instruction cache invalidate functions
Date: Sat, 23 May 2026 06:36:17 +0100 [thread overview]
Message-ID: <20260523053624.630443-3-shorne@gmail.com> (raw)
In-Reply-To: <20260523053624.630443-1-shorne@gmail.com>
Add functions to invalidate all cache lines which we will use for
static_key patching.
On OpenRISC there is no instruction to invalidate an entire cache so we
loop and invalidate cache lines one by one. This is not extremely
expensive on OpenRISC as we usually have only a few hundred cache lines.
I considered using the invalidate cache page or range functions.
However, tracking which ranges need invalidation would have been more
expensive than flushing all pages.
Cc: stable@vger.kernel.org
Signed-off-by: Stafford Horne <shorne@gmail.com>
---
arch/openrisc/include/asm/cacheflush.h | 4 ++++
arch/openrisc/kernel/smp.c | 21 +++++++++++++++++++++
arch/openrisc/mm/cache.c | 16 ++++++++++++++++
3 files changed, 41 insertions(+)
diff --git a/arch/openrisc/include/asm/cacheflush.h b/arch/openrisc/include/asm/cacheflush.h
index cd8f971c0fec..7b8c043a831d 100644
--- a/arch/openrisc/include/asm/cacheflush.h
+++ b/arch/openrisc/include/asm/cacheflush.h
@@ -26,6 +26,7 @@ extern void local_icache_page_inv(struct page *page);
extern void local_dcache_range_flush(unsigned long start, unsigned long end);
extern void local_dcache_range_inv(unsigned long start, unsigned long end);
extern void local_icache_range_inv(unsigned long start, unsigned long end);
+extern void local_icache_all_inv(void);
/*
* Data cache flushing always happen on the local cpu. Instruction cache
@@ -35,10 +36,13 @@ extern void local_icache_range_inv(unsigned long start, unsigned long end);
#ifndef CONFIG_SMP
#define dcache_page_flush(page) local_dcache_page_flush(page)
#define icache_page_inv(page) local_icache_page_inv(page)
+#define icache_all_inv() local_icache_all_inv()
#else /* CONFIG_SMP */
#define dcache_page_flush(page) local_dcache_page_flush(page)
#define icache_page_inv(page) smp_icache_page_inv(page)
+#define icache_all_inv() smp_icache_all_inv()
extern void smp_icache_page_inv(struct page *page);
+extern void smp_icache_all_inv(void);
#endif /* CONFIG_SMP */
/*
diff --git a/arch/openrisc/kernel/smp.c b/arch/openrisc/kernel/smp.c
index 040ca201b692..65599252f3d4 100644
--- a/arch/openrisc/kernel/smp.c
+++ b/arch/openrisc/kernel/smp.c
@@ -346,3 +346,24 @@ void smp_icache_page_inv(struct page *page)
on_each_cpu(ipi_icache_page_inv, page, 1);
}
EXPORT_SYMBOL(smp_icache_page_inv);
+
+static void ipi_icache_all_inv(void *arg)
+{
+ local_icache_all_inv();
+}
+
+void smp_icache_all_inv(void)
+{
+ if (num_online_cpus() < 2) {
+ local_icache_all_inv();
+ return;
+ }
+
+ /*
+ * Ensure stores complete before we request remote icaches
+ * to invalidate.
+ */
+ mb();
+
+ on_each_cpu(ipi_icache_all_inv, NULL, 1);
+}
diff --git a/arch/openrisc/mm/cache.c b/arch/openrisc/mm/cache.c
index f33df46dae4e..2667d90691b5 100644
--- a/arch/openrisc/mm/cache.c
+++ b/arch/openrisc/mm/cache.c
@@ -63,6 +63,22 @@ void local_icache_page_inv(struct page *page)
}
EXPORT_SYMBOL(local_icache_page_inv);
+void local_icache_all_inv(void)
+{
+ if (cpu_cache_is_present(SPR_UPR_ICP)) {
+ unsigned long iccfgr = mfspr(SPR_ICCFGR);
+ unsigned long sets = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3);
+ unsigned long block_size = 16 << ((iccfgr & SPR_ICCFGR_CBS) >> 7);
+ unsigned long paddr = 0;
+ unsigned long end = sets * block_size;
+
+ while (paddr < end) {
+ mtspr(SPR_ICBIR, paddr);
+ paddr += block_size;
+ }
+ }
+}
+
void local_dcache_range_flush(unsigned long start, unsigned long end)
{
cache_loop(start, end, SPR_DCBFR, SPR_UPR_DCP);
--
2.53.0
next prev parent reply other threads:[~2026-05-23 5:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-23 5:36 [PATCH 0/3] OpenRISC Fixes for jump_label SMP Syncing Stafford Horne
2026-05-23 5:36 ` [PATCH 1/3] openrisc: Cache invalidation cleanup Stafford Horne
2026-05-23 5:36 ` Stafford Horne [this message]
2026-05-23 5:36 ` [PATCH 3/3] openrisc: Fix jump_label smp syncing Stafford Horne
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=20260523053624.630443-3-shorne@gmail.com \
--to=shorne@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=jonas@southpole.se \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=tglx@kernel.org \
--cc=willy@infradead.org \
--cc=ziy@nvidia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome