LoongArch: jump_label: Batch icache maintenance
Subsystems (2)
PATCH 1/1 LoongArch: jump_label: Batch icache maintenance
From: Youling Tang <[email protected]>
Switch to the batched version of the jump label update functions so instruction cache maintenance is deferred until the end of the update.
--- arch/loongarch/include/asm/cacheflush.h | 16 +++++++++++++++- arch/loongarch/include/asm/jump_label.h | 1 + arch/loongarch/kernel/inst.c | 6 +++--- arch/loongarch/kernel/jump_label.c | 13 +++++++++++-- arch/loongarch/mm/cache.c | 10 ---------- 5 files changed, 30 insertions(+), 16 deletions(-)
arch/loongarch/include/asm/cacheflush.h +15 -1
@@ -31,9 +31,23 @@ static inline unsigned int cpu_last_level_cache_line_size(void)return boot_cpu_data.cache_leaves[cache_present -1 ].linesz; } +/* +* LoongArch maintains ICache/DCache coherency by hardware, +* we just need "ibar" to avoid instruction hazard here. +*/ +static inline void local_flush_icache_all (void ) +{ + asmvolatile ("\tibar 0\n" ::); +} + +static inline void local_flush_icache_range (unsigned long start,unsigned long end) +{ +local_flush_icache_all (); +} + asmlinkage void __flush_cache_all(void); -void local_flush_icache_range (unsigned long start,unsigned long end); +#define flush_icache_all local_flush_icache_all#define flush_icache_range local_flush_icache_range#define flush_icache_user_range local_flush_icache_range
arch/loongarch/include/asm/jump_label.h +1 -0
@@ -11,6 +11,7 @@#include <linux/types.h> +#define HAVE_JUMP_LABEL_BATCH #define JUMP_LABEL_NOP_SIZE 4/* This macro is also expanded on the Rust side. */
arch/loongarch/kernel/inst.c +3 -3
@@ -209,6 +209,9 @@ int larch_insn_write(void *addr, u32 insn)int ret;unsigned long flags =0 ; +if ((unsigned long )addr &3 ) +return -EINVAL ; +raw_spin_lock_irqsave (&patch_lock, flags); ret =copy_to_kernel_nofault (addr, &insn,LOONGARCH_INSN_SIZE );raw_spin_unlock_irqrestore (&patch_lock, flags);
@@ -221,9 +224,6 @@ int larch_insn_patch_text(void *addr, u32 insn)int ret;u32 *tp = addr; -if ((unsigned long )tp &3 ) -return -EINVAL ; - ret =larch_insn_write (tp, insn);if (!ret) flush_icache_range((unsigned long)tp,
arch/loongarch/kernel/jump_label.c +11 -2
@@ -6,9 +6,11 @@*/ #include <linux/kernel.h> #include <linux/jump_label.h> +#include <asm/cacheflush.h> #include <asm/inst.h> -void arch_jump_label_transform (struct jump_entry *entry,enum jump_label_type type) +bool arch_jump_label_transform_queue (struct jump_entry *entry, +enum jump_label_type type) {u32 insn;void *addr = (void *)jump_entry_code (entry);
@@ -18,5 +20,12 @@ void arch_jump_label_transform(struct jump_entry *entry, enum jump_label_type tyelse insn =larch_insn_gen_nop (); -larch_insn_patch_text (addr, insn); +larch_insn_write (addr, insn); + +return true; +} + +void arch_jump_label_transform_apply (void ) +{ +flush_icache_all (); }
arch/loongarch/mm/cache.c +0 -10
@@ -31,16 +31,6 @@ void cache_error_setup(void)set_merr_handler (0x0 , &except_vec_cex,0x80 ); } -/* -* LoongArch maintains ICache/DCache coherency by hardware, -* we just need "ibar" to avoid instruction hazard here. -*/ -void local_flush_icache_range (unsigned long start,unsigned long end) -{ - asmvolatile ("\tibar 0\n" ::); -} -EXPORT_SYMBOL (local_flush_icache_range); -static void flush_cache_leaf (unsigned int leaf) {int i, j, nr_nodes;
Signature · 1 line
2.43.0
Huacai Chen
maintainerHi, Youling,
First of all, it is better to split to two patches:
LoongArch: Add flush_icache_all()/local_flush_icache_all()
LoongArch: Batch icache maintenance for jump_label
Quoted 25 lines · Youling Tang
From: Youling Tang <[email protected]>
Switch to the batched version of the jump label update functions so instruction cache maintenance is deferred until the end of the update.
Signed-off-by Youling Tang <[email protected]>--- arch/loongarch/include/asm/cacheflush.h | 16 +++++++++++++++- arch/loongarch/include/asm/jump_label.h | 1 + arch/loongarch/kernel/inst.c | 6 +++--- arch/loongarch/kernel/jump_label.c | 13 +++++++++++-- arch/loongarch/mm/cache.c | 10 ---------- 5 files changed, 30 insertions(+), 16 deletions(-)arch/loongarch/include/asm/cacheflush.h +2
-0@@ -31,9 +31,23 @@ static inline unsigned int cpu_last_level_cache_line_size(void)return boot_cpu_data.cache_leaves[cache_present -1 ].linesz; } +/* +* LoongArch maintains ICache/DCache coherency by hardware,
arch/loongarch/include/asm/cacheflush.h static inline unsigned int cpu_last_level_cache_line_size(void) · line 45
Quoted 10 lines
arch/loongarch/include/asm/cacheflush.h +10
-0+* we just need "ibar" to avoid instruction hazard here. +*/ +static inline void local_flush_icache_all (void ) +{ + asmvolatile ("\tibar 0\n" ::); +} + +static inline void local_flush_icache_range (unsigned long start,unsigned long end) +{ +local_flush_icache_all ();
Just use a plain "asm volatile ("\tibar 0\n"::);", and put them after __flush_cache_all().
Huacai
Quoted 100 lines
arch/loongarch/include/asm/cacheflush.h +3
-1+} + asmlinkage void __flush_cache_all(void); -void local_flush_icache_range (unsigned long start,unsigned long end); +#define flush_icache_all local_flush_icache_all#define flush_icache_range local_flush_icache_range#define flush_icache_user_range local_flush_icache_rangearch/loongarch/include/asm/jump_label.h +1
-0@@ -11,6 +11,7 @@#include <linux/types.h> +#define HAVE_JUMP_LABEL_BATCH #define JUMP_LABEL_NOP_SIZE 4/* This macro is also expanded on the Rust side. */ arch/loongarch/kernel/inst.c +3
-3@@ -209,6 +209,9 @@ int larch_insn_write(void *addr, u32 insn)int ret;unsigned long flags =0 ; +if ((unsigned long )addr &3 ) +return -EINVAL ; +raw_spin_lock_irqsave (&patch_lock, flags); ret =copy_to_kernel_nofault (addr, &insn,LOONGARCH_INSN_SIZE );raw_spin_unlock_irqrestore (&patch_lock, flags);@@ -221,9 +224,6 @@ int larch_insn_patch_text(void *addr, u32 insn)int ret;u32 *tp = addr; -if ((unsigned long )tp &3 ) -return -EINVAL ; - ret =larch_insn_write (tp, insn);if (!ret) flush_icache_range((unsigned long)tp,arch/loongarch/kernel/jump_label.c +11
-2@@ -6,9 +6,11 @@*/ #include <linux/kernel.h> #include <linux/jump_label.h> +#include <asm/cacheflush.h> #include <asm/inst.h> -void arch_jump_label_transform (struct jump_entry *entry,enum jump_label_type type) +bool arch_jump_label_transform_queue (struct jump_entry *entry, +enum jump_label_type type) {u32 insn;void *addr = (void *)jump_entry_code (entry);@@ -18,5 +20,12 @@ void arch_jump_label_transform(struct jump_entry *entry, enum jump_label_type tyelse insn =larch_insn_gen_nop (); -larch_insn_patch_text (addr, insn); +larch_insn_write (addr, insn); + +return true; +} + +void arch_jump_label_transform_apply (void ) +{ +flush_icache_all (); }arch/loongarch/mm/cache.c +0
-11@@ -31,16 +31,6 @@ void cache_error_setup(void)set_merr_handler (0x0 , &except_vec_cex,0x80 ); } -/* -* LoongArch maintains ICache/DCache coherency by hardware, -* we just need "ibar" to avoid instruction hazard here. -*/ -void local_flush_icache_range (unsigned long start,unsigned long end) -{ - asmvolatile ("\tibar 0\n" ::); -} -EXPORT_SYMBOL (local_flush_icache_range); -static void flush_cache_leaf (unsigned int leaf) {int i, j, nr_nodes; --2.43.0
Quoted 6 lines · Huacai Chen
Quoted 4 lines
+static inline void
local_flush_icache_range(unsigned long start, unsigned long end)
+{
+local_flush_icache_all();Just use a plain "asm volatile ("\tibar 0\n"::);", and put them after
__flush_cache_all().
IMO for consistency it should be "ibar\t0" (without the leading \t and trailing \n: we don't have those in any of other inline assemblies).
Signature · 1 line
Xi Ruoyao <[email protected]>
Huacai Chen
maintainerQuoted 11 lines · Xi Ruoyao
Quoted 6 lines · Huacai Chen
Review
Quoted 4 lines
+static inline void
local_flush_icache_range(unsigned long start, unsigned long end)(quoted diff) +2
-0+{ + local_flush_icache_all();Just use a plain "asm volatile ("\tibar 0\n"::);", and put them after
__flush_cache_all().IMO for consistency it should be "ibar\t0" (without the leading \t and trailing \n: we don't have those in any of other inline assemblies).
Leading \t should be removed, but trailing \n can be kept (\t is also OK).
Huacai
Quoted 3 lines
--
Xi Ruoyao <[email protected]>