powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
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.
--- arch/powerpc/kernel/vdso32/getcpu.S | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/kernel/vdso32/getcpu.S +2 -2
@@ -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
Michael Ellerman
reviewerQuoted 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
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
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
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
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
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
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
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.
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."