Skip to contentSkip to conversation

Workaround the Out-of-order Issue of Loongson-2

PATCH Superseded Wu Zhangjin 2 participants 7 messages Apr 7, 2010 – Apr 8, 2010 MIPS

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Workaround the Out-of-order Issue of Loongson-2

From: Wu Zhangjin <[email protected]>

v3->v4:

+ Incorporated with the feedbacks from Ralf.
o add a new kernel config option to allow the users to disable the workarounds for the new loongson2f batches(2F03 and newer).
o enable the workarounds unconditionally for the related loongson2f(2F01/02).
o use a safer method to fixup the reset issue introduced by the workaround.

v2->v3:

o Herein, RAS is short for Return Address Stack not Row Address Strobe, at the same time, the "model" in the translation of Chapter 15 should be "mode". (feedback from Shinya Kuribayashi)

v1->v2:

o Cleanup some comments and align some instructions.

----

As the Chapter 15: "Errata: Issue of Out-of-order in loongson"[1] shows, to workaround the Issue of Loongson-2F,We need to do:

o When switching from user mode to kernel mode, you should flush the branch target history such as BTB and RAS.

o Doing some tricks to the indirect branch target to make sure that the indirect branch target can not be in the I/O region.

This patchset applied the above methods and for the binutils patch[3] have been merged into binutils 2.20.1, so, it's time to upstream this patchset now. without this patch, the machines will hang when the instruction sequence hit the Out-of-order Issue of Loongson-2F, therefore, this patchset is very urgent for both 2.6.33 and 2.6.34.

[1] Chinese Version: http://www.loongson.cn/uploadfile/file/20080821113149.pdf
[2] English Version of Chapter 15:
http://groups.google.com.hk/group/loongson-dev/msg/e0d2e220958f10a6?dmode=source
[3] http://sourceware.org/ml/binutils/2009-11/msg00387.html

Wu Zhangjin (4):
Loongson: Add CPU_LOONGSON2F_WORKAROUNDS
Loongson-2F: Enable fixups of the latest binutils
Loongson-2F: Flush the branch target history in BTB and RAS (cont.)
Loongson-2F: Fixup of problems introduced by -mfix-loongson2f-jump

 arch/mips/Kconfig                  |   26 ++++++++++++++++++++++++++
 arch/mips/Makefile                 |   13 +++++++++++++
 arch/mips/include/asm/stackframe.h |    2 +-
 arch/mips/loongson/common/reset.c  |   20 +++++++++++++++++++-
 4 files changed, 59 insertions(+), 2 deletions(-)
#1 lore raw

PATCH v4 1/4 Loongson: Add CPU_LOONGSON2F_WORKAROUNDS

From: Wu Zhangjin <[email protected]>

As the Loongson2F User Manual[2,3] shows, the old Loongson2F series(2F01/02) have the NOP & JUMP issues, need the related workarounds in the kernel and binutils, but the new Loongson2F series(2F03 and laters) have no such issues, so, none of the workarounds is needed.

Currently, the workaround[1] with the -mfix-loongson2f-nop, -mfix-loongson2f-jump options have been added into the latest binutils(in the cvs repository), it's time to add the workarounds in the kernel.

The workarounds have no big side effect on the system, but may decrease the performance, therefore, this patch adds a new CPU_LOONGSON2F_WORKAROUNDS config option to allow the users to only enable it for the necessary processor series.

[1] "Fixups of Loongson2F" patch for binutils(actually for gas)
http://sourceware.org/ml/binutils/2009-11/msg00387.html
[2] Chapter 15 of "Loongson2F User Manual"(Chinese Version)
http://www.loongson.cn/uploadfile/file/200808211
[3] English Version of the above chapter 15
http://groups.google.com.hk/group/loongson-dev/msg/e0d2e220958f10a6?dmode=source

---
 arch/mips/Kconfig |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
arch/mips/Kconfig +26 -0
index 29e8692..f2ead53 100644
@@ -1305,6 +1305,32 @@ config CPU_CAVIUM_OCTEON
 
 endchoice
 
+if CPU_LOONGSON2F
+config CPU_NOP_WORKAROUNDS
+	bool
+
+config CPU_JUMP_WORKAROUNDS
+	bool
+
+config CPU_LOONGSON2F_WORKAROUNDS
+	bool "Loongson 2F Workarounds"
+	default y
+	select CPU_NOP_WORKAROUNDS
+	select CPU_JUMP_WORKAROUNDS
+	help
+	  The Loongson 2F01/02 processor has the NOP & JUMP issues, needs the
+	  related workarounds, without workarounds, the system will hang
+	  unexpectedly. to get more information about them, please refer to the
+	  -mfix-loongson2f-nop and -mfix-loongson2f-jump options of gas.
+
+	  For Loongson 2F03 and the later batches have fixed the issues, none
+	  of these workarounds needed for them. These workarounds have no big
+	  side effect on them but may decrease the performance of the system,
+	  therefore, it's better to disable this config for them.
+
+	  If unsure, please say Y.
+endif # CPU_LOONGSON2F
+
 config SYS_SUPPORTS_ZBOOT
 	bool
 	select HAVE_KERNEL_GZIP
Signature · 1 line
1.7.0.1
#2 lore raw

PATCH v4 2/4 Loongson-2F: Enable fixups of the latest binutils

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

Changes from old revision:

o Incorporated with the feedbacks from Ralf and used the options introduced from "Loongson: Add CPU_LOONGSON2F_WORKAROUNDS".

As the "Fixups of Loongson2F" patch[1] to binutils have been applied into binutils 2.20.1. It's time to enable the options provided by the patch to compile the kernel.

Without these fixups, the system will hang unexpectedly for the bug of processor.

To learn more about these fixups, please refer to the following references.

[1] "Fixups of Loongson2F" patch for binutils(actually for gas)
http://sourceware.org/ml/binutils/2009-11/msg00387.html
[2] Chapter 15 of "Loongson2F User Manual"(Chinese Version)
http://www.loongson.cn/uploadfile/file/200808211
[3] English Version of the above chapter 15
http://groups.google.com.hk/group/loongson-dev/msg/e0d2e220958f10a6?dmode=source

---
 arch/mips/Makefile |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/mips/Makefile +13 -0
index 2f2eac2..14f12bc 100644
@@ -136,6 +136,19 @@ cflags-$(CONFIG_CPU_LOONGSON2E) += \
 	$(call cc-option,-march=loongson2e,-march=r4600)
 cflags-$(CONFIG_CPU_LOONGSON2F) += \
 	$(call cc-option,-march=loongson2f,-march=r4600)
+# enable the workarounds for loongson2f
+ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS
+  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-nop,),)
+    $(error gcc does not support needed option -mfix-loongson2f-nop)
+  else
+    cflags-$(CONFIG_CPU_NOP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-nop
+  endif
+  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-jump,),)
+    $(error gcc does not support needed option -mfix-loongson2f-jump)
+  else
+    cflags-$(CONFIG_CPU_JUMP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-jump
+  endif
+endif
 
 cflags-$(CONFIG_CPU_MIPS32_R1)	+= $(call cc-option,-march=mips32,-mips32 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32) \
 			-Wa,-mips32 -Wa,--trap
Signature · 1 line
1.7.0.1
#3 lore raw

Re: [PATCH v4 2/4] Loongson-2F: Enable fixups of the latest binutils

Quoted 35 lines · Wu Zhangjin

From: Wu Zhangjin <[email protected]>

Changes from old revision:

o Incorporated with the feedbacks from Ralf and used the options introduced from "Loongson: Add CPU_LOONGSON2F_WORKAROUNDS".

As the "Fixups of Loongson2F" patch[1] to binutils have been applied into binutils 2.20.1. It's time to enable the options provided by the patch to compile the kernel.

Without these fixups, the system will hang unexpectedly for the bug of processor.

To learn more about these fixups, please refer to the following references.

[1] "Fixups of Loongson2F" patch for binutils(actually for gas)
http://sourceware.org/ml/binutils/2009-11/msg00387.html
[2] Chapter 15 of "Loongson2F User Manual"(Chinese Version)
http://www.loongson.cn/uploadfile/file/200808211
[3] English Version of the above chapter 15
http://groups.google.com.hk/group/loongson-dev/msg/e0d2e220958f10a6?dmode=source

---
 arch/mips/Makefile |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
arch/mips/Makefile +0 -0
index 2f2eac2..14f12bc 100644

arch/mips/Makefile cflags-$(CONFIG_CPU_LOONGSON2E) += \ · line 142

Quoted 7 lines
arch/mips/Makefile +4 -0
@@ -136,6 +136,19 @@ cflags-$(CONFIG_CPU_LOONGSON2E) += \
 	$(call cc-option,-march=loongson2e,-march=r4600)
 cflags-$(CONFIG_CPU_LOONGSON2F) += \
 	$(call cc-option,-march=loongson2f,-march=r4600)
+# enable the workarounds for loongson2f
+ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS
+  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-nop,),)
+    $(error gcc does not support needed option -mfix-loongson2f-nop)

Again, this is an as option. :)
So this error msg is a little miss leading.
Maybe we should tell user at least which version of binutils is needed.

arch/mips/Makefile cflags-$(CONFIG_CPU_LOONGSON2E) += \ · line 147

Quoted 5 lines
arch/mips/Makefile +5 -0
+  else
+    cflags-$(CONFIG_CPU_NOP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-nop
+  endif
+  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-jump,),)
+    $(error gcc does not support needed option -mfix-loongson2f-jump)

Same here.

Zhang, Le

Quoted 10 lines
arch/mips/Makefile +4 -0
+  else
+    cflags-$(CONFIG_CPU_JUMP_WORKAROUNDS) += -Wa$(comma)-mfix-loongson2f-jump
+  endif
+endif
 
 cflags-$(CONFIG_CPU_MIPS32_R1)	+= $(call cc-option,-march=mips32,-mips32 -U_MIPS_ISA -D_MIPS_ISA=_MIPS_ISA_MIPS32) \
 			-Wa,-mips32 -Wa,--trap
Signature · 1 line
1.7.0.1
#4 lore raw

Re: [PATCH v4 2/4] Loongson-2F: Enable fixups of the latest binutils

On Wed, 2010-04-07 at 17:16 +0000, Zhang Le wrote:
[...]

Quoted 9 lines

arch/mips/Makefile cflags-$(CONFIG_CPU_LOONGSON2E) += \ · line 142

Quoted 4 lines
arch/mips/Makefile +4 -0
+# enable the workarounds for loongson2f
+ifdef CONFIG_CPU_LOONGSON2F_WORKAROUNDS
+  ifeq ($(call as-option,-Wa$(comma)-mfix-loongson2f-nop,),)
+    $(error gcc does not support needed option -mfix-loongson2f-nop)

Again, this is an as option. :)
So this error msg is a little miss leading.
Maybe we should tell user at least which version of binutils is needed.

hmm, yeah, it's better to tell the users the exact tool here although 'as' is part of the integrated gcc toolchain ;)

Thanks & Regards,
Wu Zhangjin

#5 lore raw

PATCH v4 3/4 Loongson-2F: Flush the branch target history in BTB and RAS (cont.)

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

This patch uses the new option CONFIG_CPU_JUMP_WORKAROUNDS introduced from "Loongson: Add CPU_LOONGSON2F_WORKAROUNDS" to enable the workarounds for the necessary loongson series(2F01/02).

---
 arch/mips/include/asm/stackframe.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/mips/include/asm/stackframe.h +1 -1
index c841912..58730c5 100644
@@ -121,7 +121,7 @@
 		.endm
 #else
 		.macro	get_saved_sp	/* Uniprocessor variation */
-#ifdef CONFIG_CPU_LOONGSON2F
+#ifdef CONFIG_CPU_JUMP_WORKAROUNDS
 		/*
 		 * Clear BTB (branch target buffer), forbid RAS (return address
 		 * stack) to workaround the Out-of-order Issue in Loongson2F
Signature · 1 line
1.7.0.1
#6 lore raw

PATCH v4 4/4 Loongson-2F: Fixup of problems introduced by -mfix-loongson2f-jump

In reply to Wu Zhangjin

From: Wu Zhangjin <[email protected]>

Changes from old revisions:

o Incorporated with the feedbacks from Ralf Baechle and used the option CONFIG_CPU_JUMP_WORKAROUNDS introduced by "Loongson: Add CPU_LOONGSON2F_WORKAROUNDS".

The -mfix-loongson2f-jump option provided by the latest binutils(in the cvs repository) have fixed the Out-of-order Issue of Loongson-2F described in Chapter 15 of "Loongson2F User Manual"[1,2], but introduced some problems.

The option changes all of the jumping target to "addr & 0xcfffffff" through the at($1) register, but for the REBOOT address of loongson-2F: 0xbfc00000, this is totally wrong, so, this patch try to avoid the problem via telling the assembler not to use at($1) register.

[1] Loongson2F User Manual(Chinese Version)
http://www.loongson.cn/uploadfile/file/200808211
[2] English Version of Chapter 15:
http://groups.google.com.hk/group/loongson-dev/msg/e0d2e220958f10a6?dmode=source

---
 arch/mips/loongson/common/reset.c |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
arch/mips/loongson/common/reset.c +19 -1
index 4bd9c18..9e10d62 100644
@@ -16,13 +16,31 @@
 
 #include <loongson.h>
 
+static inline void loongson_reboot(void)
+{
+#ifndef CONFIG_CPU_JUMP_WORKAROUNDS
+	((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) ();
+#else
+	void (*func)(void);
+
+	func = (void *)ioremap_nocache(LOONGSON_BOOT_BASE, 4);
+
+	__asm__ __volatile__(
+	"       .set    noat                                            \n"
+	"       jr      %[func]                                         \n"
+	"       .set    at                                              \n"
+	: /* No outputs */
+	: [func] "r" (func));
+#endif
+}
+
 static void loongson_restart(char *command)
 {
 	/* do preparation for reboot */
 	mach_prepare_reboot();
 
 	/* reboot via jumping to boot base address */
-	((void (*)(void))ioremap_nocache(LOONGSON_BOOT_BASE, 4)) ();
+	loongson_reboot();
 }
 
 static void loongson_poweroff(void)
Signature · 1 line
1.7.0.1