Skip to contentSkip to conversation

powerpc: 32 bit getcpu VDSO function uses 64 bit instructions

PATCH In review Anton Blanchard 6 participants 10 messages Nov 26, 2014 – Nov 28, 2014 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: 32 bit getcpu VDSO function uses 64 bit instructions

I used some 64 bit instructions when adding the 32 bit getcpu VDSO function. Fix it.

Fixes 18ad51dd342a ("powerpc: Add VDSO version of getcpu")
---
 arch/powerpc/kernel/vdso32/getcpu.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/vdso32/getcpu.S +2 -2
index 23eb9a9..c62be60 100644
@@ -30,8 +30,8 @@
 V_FUNCTION_BEGIN(__kernel_getcpu)
   .cfi_startproc
 	mfspr	r5,SPRN_SPRG_VDSO_READ
-	cmpdi	cr0,r3,0
-	cmpdi	cr1,r4,0
+	cmpwi	cr0,r3,0
+	cmpwi	cr1,r4,0
 	clrlwi  r6,r5,16
 	rlwinm  r7,r5,16,31-15,31-0
 	beq	cr0,1f
Signature · 1 line
2.1.0
#1 lore raw
Quoted 2 lines · Anton Blanchard

I used some 64 bit instructions when adding the 32 bit getcpu VDSO function. Fix it.

Ouch. The symptom is a SIGILL I presume?

Could we catch this by forcing -m32 in the CFLAGS for vdso32 ?

cheers

#2 lore raw
Quoted 7 lines · Michael Ellerman
Quoted 2 lines · Anton Blanchard

I used some 64 bit instructions when adding the 32 bit getcpu VDSO function. Fix it.

Ouch. The symptom is a SIGILL I presume?

Could we catch this by forcing -m32 in the CFLAGS for vdso32 ?

GCC has added -many to the assembler flags for over ten years now, so no that will not work. You can use -mppc or similar with the assembler if you invoke it correctly (use $(CC) -print-prog-name=as to figure out how to call the assembler, if you want to stay sane and use the same one as the rest of the toolchain you use).

Segher

#3 lore raw
Quoted 3 lines · Segher Boessenkool

GCC has added -many to the assembler flags for over ten years now, so no that will not work. You can use -mppc or similar with the assembler if you invoke it correctly (use $(CC) -print-prog-name=as to figure

s/correctly/directly/

Quoted 5 lines

out how to call the assembler, if you want to stay sane and use the same one as the rest of the toolchain you use).

Segher

#4 lore raw
In reply to Michael Ellerman
Quoted 5 lines · Michael Ellerman
Quoted 2 lines · Anton Blanchard

I used some 64 bit instructions when adding the 32 bit getcpu VDSO function. Fix it.

Ouch. The symptom is a SIGILL I presume?

Nope, you don't get a SIGILL when executing 64-bit instructions in 32-bit mode, so it'll happily just execute the instruction, doing a full 64-bit compare. I'm guessing that the upper 32-bits of both r3 and r4 contain zeros, so we're probably just getting lucky.

Quoted 1 line

Could we catch this by forcing -m32 in the CFLAGS for vdso32 ?

As Segher mentioned, GCC passing -many down to the assembler means -m32 won't help. It was due to Anton disabling that gcc "feature", that this was caught.

Peter

#5 lore raw
Quoted 11 lines · Peter Bergner
Quoted 5 lines · Michael Ellerman
Quoted 2 lines · Anton Blanchard

I used some 64 bit instructions when adding the 32 bit getcpu VDSO function. Fix it.

Ouch. The symptom is a SIGILL I presume?

Nope, you don't get a SIGILL when executing 64-bit instructions in 32-bit mode, so it'll happily just execute the instruction, doing a full 64-bit compare. I'm guessing that the upper 32-bits of both r3 and r4 contain zeros, so we're probably just getting lucky.

You will get a SIGILL if you run on 32-bit hardware.

Quoted 5 lines
Quoted 1 line

Could we catch this by forcing -m32 in the CFLAGS for vdso32 ?

As Segher mentioned, GCC passing -many down to the assembler means -m32 won't help. It was due to Anton disabling that gcc "feature", that this was caught.

There are extremely many complex failure cases without the -many. Feel free to work on removing it, I won't :-)

Segher

#6 lore raw
Quoted 7 lines · Segher Boessenkool
Quoted 4 lines · Peter Bergner

Nope, you don't get a SIGILL when executing 64-bit instructions in 32-bit mode, so it'll happily just execute the instruction, doing a full 64-bit compare. I'm guessing that the upper 32-bits of both r3 and r4 contain zeros, so we're probably just getting lucky.

You will get a SIGILL if you run on 32-bit hardware.

Ha, I completely forgot about 32-bit hardware. Anyway, I looked at the ISA, and cmpdi and cmpwi are just extended mnemonics for cmpi, with cmpdi setting the L field to 1. Probably on 32-bit hardware, the hardware is just ignoring the L bit being set and doing a cmpwi for us???

Peter

#9 lore raw
In reply to Segher Boessenkool
Quoted 6 lines · Segher Boessenkool
Quoted 5 lines · Peter Bergner
Quoted 4 lines · Michael Ellerman
Quoted 2 lines · Anton Blanchard

I used some 64 bit instructions when adding the 32 bit getcpu VDSO function. Fix it.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Ouch. The symptom is a SIGILL I presume?

Nope, you don't get a SIGILL when executing 64-bit instructions in 32-bit mode, so it'll happily just execute the instruction, doing a full 64-bit compare. I'm guessing that the upper 32-bits of both r3 and r4 contain zeros, so we're probably just getting lucky.

You will get a SIGILL if you run on 32-bit hardware.

Not on the 7447A, fwiw.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
#7 lore raw
In reply to Peter Bergner
Quoted 7 lines · Peter Bergner
Quoted 6 lines · Segher Boessenkool
Quoted 4 lines · Peter Bergner

Nope, you don't get a SIGILL when executing 64-bit instructions in 32-bit mode, so it'll happily just execute the instruction, doing a full 64-bit compare. I'm guessing that the upper 32-bits of both r3 and r4 contain zeros, so we're probably just getting lucky.

Quoted 7 lines
Quoted 1 line

You will get a SIGILL if you run on 32-bit hardware.

Ha, I completely forgot about 32-bit hardware. Anyway, I looked at the ISA, and cmpdi and cmpwi are just extended mnemonics for cmpi, with cmpdi setting the L field to 1. Probably on 32-bit hardware, the hardware is just ignoring the L bit being set and doing a cmpwi for us???

Huh. Yes, maybe some implementations do that.

The good news is that those then compute the correct thing ;-)

Can QEMU help catch such bugs more reliably?

Segher

#8 lore raw
Quoted 16 lines · Segher Boessenkool
Quoted 7 lines · Peter Bergner
Quoted 6 lines · Segher Boessenkool
Quoted 4 lines · Peter Bergner

Nope, you don't get a SIGILL when executing 64-bit instructions in 32-bit mode, so it'll happily just execute the instruction, doing a full 64-bit compare. I'm guessing that the upper 32-bits of both r3 and r4 contain zeros, so we're probably just getting lucky.

Quoted 7 lines
Quoted 1 line

You will get a SIGILL if you run on 32-bit hardware.

Ha, I completely forgot about 32-bit hardware. Anyway, I looked at the ISA, and cmpdi and cmpwi are just extended mnemonics for cmpi, with cmpdi setting the L field to 1. Probably on 32-bit hardware, the hardware is just ignoring the L bit being set and doing a cmpwi for us???

Quoted 5 lines

Huh. Yes, maybe some implementations do that.

The good news is that those then compute the correct thing ;-)

Can QEMU help catch such bugs more reliably?

That's all moot, that piece of code only exist on 64-bit kernels :-)

So the only risk here is the very remote and unlikely case where the register might contain 0 in the low 32-bits and some garbage in the top.

Cheers,
Ben.