From 923ddb84d8f127bf97d450c79a1e7b0cfa789838 Mon Sep 17 00:00:00 2001 From: Hongchen Zhang Date: Tue, 31 Jan 2023 09:28:41 +0800 Subject: [PATCH] LoongArch: Change definition of cpu_relax() for Loongson-3 LoongArch inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I6BWFP -------------------------------- This patch changes the definition of cpu_relax() to smp_mb() for Loongson-3, forcing a flush of the SFB on SMP systems which will cause any pending writes to make it as far as the L1 caches where they will become visible to other CPUs. If the kernel is not compiled for SMP support, this will expand to a barrier() as before. Reference commit a30718868915 ("MIPS: Change definition of cpu_relax() for Loongson-3") for detail. Signed-off-by: Huacai Chen Signed-off-by: Hongchen Zhang Change-Id: I1ad7efc19b77ead5932ff8429819db0856fb8e33 --- arch/loongarch/include/asm/vdso/processor.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/include/asm/vdso/processor.h b/arch/loongarch/include/asm/vdso/processor.h index ef5770b343a0..fa3d08bbde94 100644 --- a/arch/loongarch/include/asm/vdso/processor.h +++ b/arch/loongarch/include/asm/vdso/processor.h @@ -7,7 +7,16 @@ #ifndef __ASSEMBLY__ -#define cpu_relax() barrier() +/* + * Loongson-3's SFB (Store-Fill-Buffer) may buffer writes indefinitely when a + * tight read loop is executed, because reads take priority over writes & the + * hardware (incorrectly) doesn't ensure that writes will eventually occur. + * + * Since spin loops of any kind should have a cpu_relax() in them, force an SFB + * flush from cpu_relax() such that any pending writes will become visible as + * expected. + */ +#define cpu_relax() smp_mb() #endif /* __ASSEMBLY__ */ -- GitLab