Skip to contentSkip to conversation

DEC/SNI: O32 wrapper stack switching fixes

PATCH In review Maciej W. Rozycki 2 participants 5 messages Mar 31, 2014 – Apr 8, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 DEC/SNI: O32 wrapper stack switching fixes

Commit 231a35d37293ab88d325a9cb94e5474c156282c0 [[MIPS] RM: Collected changes] broke DECstation support by introducing an incompatible copy of arch/mips/dec/prom/call_o32.S in arch/mips/fw/lib/, built unconditionally. The copy happens to land earlier of the two among the modules used in the link and is therefore chosen for the DECstation rather than the intended original. As a result random kernel data is corrupted because a pointer to the "%s" formatted output template is used as a temporary stack pointer rather than being passed down to prom_printf. This also explains why prom_printf still works, up to a point -- the next argument is the actual string to output so it works just fine as the output template until enough kernel data has been corrupted to cause a crash.

This change adjusts the modified wrapper in arch/mips/fw/lib/call_o32.S to let callers request no stack switching by passing a null temporary stack pointer in $a1, reworks the DECstation callers to work with the updated interface and removes the old copy from arch/mips/dec/prom/call_o32.S. A few minor readability adjustments are included as well, most importantly O32_SZREG is now used throughout where applicable rather than hardcoded multiplies of 4 and $fp is used to access the argument save area as a more usual register to operate the stack with rather than $s0.

Finally an update is made to the temporary stack space used by the SNI platform to guarantee 8-byte alignment as per o32 requirements.

---
Thomas,

Please verify this works for your system.

Maciej

linux-dec-call-o32.patch

arch/mips/dec/prom/Makefile +0 -1
Index: linux-20140329-4maxp64/arch/mips/dec/prom/Makefile
===================================================================
@@ -6,4 +6,3 @@
 lib-y			+= init.o memory.o cmdline.o identify.o console.o
 
 lib-$(CONFIG_32BIT)	+= locore.o
-lib-$(CONFIG_64BIT)	+= call_o32.o
arch/mips/dec/prom/call_o32.S deleted +0 -89

89 lines not on this page · raw message

arch/mips/fw/lib/call_o32.S +35 -22

102 lines not on this page · raw message

arch/mips/fw/sni/sniprom.c +2 -1
Index: linux-20140329-4maxp64/arch/mips/fw/sni/sniprom.c
===================================================================
@@ -40,7 +40,8 @@
 
 #ifdef CONFIG_64BIT
 
-static u8 o32_stk[16384];
+/* O32 stack has to be 8-byte aligned. */
+static u64 o32_stk[4096];
 #define O32_STK	  &o32_stk[sizeof(o32_stk)]
 
 #define __PROM_O32(fun, arg) fun arg __asm__(#fun); \
arch/mips/include/asm/dec/prom.h +20 -20
Index: linux-20140329-4maxp64/arch/mips/include/asm/dec/prom.h
===================================================================
@@ -113,31 +113,31 @@ extern int (*__pmax_close)(int);
 #define __DEC_PROM_O32(fun, arg) fun arg __asm__(#fun); \
 				 __asm__(#fun " = call_o32")
 
-int __DEC_PROM_O32(_rex_bootinit, (int (*)(void)));
-int __DEC_PROM_O32(_rex_bootread, (int (*)(void)));
-int __DEC_PROM_O32(_rex_getbitmap, (int (*)(memmap *), memmap *));
+int __DEC_PROM_O32(_rex_bootinit, (int (*)(void), void *));
+int __DEC_PROM_O32(_rex_bootread, (int (*)(void), void *));
+int __DEC_PROM_O32(_rex_getbitmap, (int (*)(memmap *), void *, memmap *));
 unsigned long *__DEC_PROM_O32(_rex_slot_address,
-			     (unsigned long *(*)(int), int));
-void *__DEC_PROM_O32(_rex_gettcinfo, (void *(*)(void)));
-int __DEC_PROM_O32(_rex_getsysid, (int (*)(void)));
-void __DEC_PROM_O32(_rex_clear_cache, (void (*)(void)));
+			     (unsigned long *(*)(int), void *, int));
+void *__DEC_PROM_O32(_rex_gettcinfo, (void *(*)(void), void *));
+int __DEC_PROM_O32(_rex_getsysid, (int (*)(void), void *));
+void __DEC_PROM_O32(_rex_clear_cache, (void (*)(void), void *));
 
-int __DEC_PROM_O32(_prom_getchar, (int (*)(void)));
-char *__DEC_PROM_O32(_prom_getenv, (char *(*)(char *), char *));
-int __DEC_PROM_O32(_prom_printf, (int (*)(char *, ...), char *, ...));
+int __DEC_PROM_O32(_prom_getchar, (int (*)(void), void *));
+char *__DEC_PROM_O32(_prom_getenv, (char *(*)(char *), void *, char *));
+int __DEC_PROM_O32(_prom_printf, (int (*)(char *, ...), void *, char *, ...));
 
 
-#define rex_bootinit()		_rex_bootinit(__rex_bootinit)
-#define rex_bootread()		_rex_bootread(__rex_bootread)
-#define rex_getbitmap(x)	_rex_getbitmap(__rex_getbitmap, x)
-#define rex_slot_address(x)	_rex_slot_address(__rex_slot_address, x)
-#define rex_gettcinfo()		_rex_gettcinfo(__rex_gettcinfo)
-#define rex_getsysid()		_rex_getsysid(__rex_getsysid)
-#define rex_clear_cache()	_rex_clear_cache(__rex_clear_cache)
+#define rex_bootinit()		_rex_bootinit(__rex_bootinit, NULL)
+#define rex_bootread()		_rex_bootread(__rex_bootread, NULL)
+#define rex_getbitmap(x)	_rex_getbitmap(__rex_getbitmap, NULL, x)
+#define rex_slot_address(x)	_rex_slot_address(__rex_slot_address, NULL, x)
+#define rex_gettcinfo()		_rex_gettcinfo(__rex_gettcinfo, NULL)
+#define rex_getsysid()		_rex_getsysid(__rex_getsysid, NULL)
+#define rex_clear_cache()	_rex_clear_cache(__rex_clear_cache, NULL)
 
-#define prom_getchar()		_prom_getchar(__prom_getchar)
-#define prom_getenv(x)		_prom_getenv(__prom_getenv, x)
-#define prom_printf(x...)	_prom_printf(__prom_printf, x)
+#define prom_getchar()		_prom_getchar(__prom_getchar, NULL)
+#define prom_getenv(x)		_prom_getenv(__prom_getenv, NULL, x)
+#define prom_printf(x...)	_prom_printf(__prom_printf, NULL, x)
 
 #else /* !CONFIG_64BIT */
 
#1 lore raw
Quoted 1 line · Maciej W. Rozycki

Please verify this works for your system.

works on a RM200 system (after removing stupid EARLY_CRAP_8250 select).

Only strange thing I see is

WARNING: CPU: 0 PID: 0 at /home/tsbogend/mips/work/linux/arch/mips/mm/uasm.c:97 build_insn+0x4c4/0x570()

Micro-assembler field overflow

Happens twice one for build_clear_cache() and build_copy_cache(). CPU is is R4600PC 2.0.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#2 lore raw
Quoted 1 line · Thomas Bogendoerfer

works on a RM200 system (after removing stupid EARLY_CRAP_8250 select).

Great! Thanks for verifying.

Quoted 7 lines

Only strange thing I see is

WARNING: CPU: 0 PID: 0 at /home/tsbogend/mips/work/linux/arch/mips/mm/uasm.c:97 build_insn+0x4c4/0x570()

Micro-assembler field overflow

Happens twice one for build_clear_cache() and build_copy_cache(). CPU is is R4600PC 2.0.

That is rather dangerous, if you do not dare debugging this yourself, can
you build arch/mips/mm/page.c with -DDEBUG somehow so that it dumps the machine code generated by these two helpers and we can see what's going on here and maybe where the overflow is?

Maciej

#3 lore raw
Quoted 2 lines · Maciej W. Rozycki

That is rather dangerous, if you do not dare debugging this yourself, can
you build arch/mips/mm/page.c with -DDEBUG somehow so that it dumps the

I didn't get that to work :-(

Quoted 2 lines

machine code generated by these two helpers and we can see what's going on here and maybe where the overflow is?

but adding more info to the debug message showed it's a simm field overflow.

It didn't like

	uasm_i_lui(&buf, AT, 0xa000);

which is only created for R4600 rev 2.0 CPUs.

Will send a fix for that.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#4 lore raw
Quoted 4 lines · Thomas Bogendoerfer
Quoted 2 lines

That is rather dangerous, if you do not dare debugging this yourself, can
you build arch/mips/mm/page.c with -DDEBUG somehow so that it dumps the

I didn't get that to work :-(

I'm fairly sure you can pass that down with CPPFLAGS_page.o (or maybe
CFLAGS_page.o), e.g.:

$ make CPPFLAGS_page.o=-DDEBUG arch/mips/mm/page.o
$ make vmlinux

but if that fails for some reason you could always just paste:

#define DEBUG

at the top of page.c, before headers are included. ;) You might have to tweak the default console log level, I reckon there's a config option these days, or otherwise just put "debug" somewhere on the kernel command line.

Quoted 11 lines
Quoted 2 lines

machine code generated by these two helpers and we can see what's going on here and maybe where the overflow is?

but adding more info to the debug message showed it's a simm field overflow.

It didn't like

	uasm_i_lui(&buf, AT, 0xa000);

which is only created for R4600 rev 2.0 CPUs.

Aha, in GAS LUI accepts an unsigned 16-bit immediate, so I think our
kernel should do the same.

Quoted 1 line

Will send a fix for that.

Great, thanks!

Maciej