linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
@ 2014-11-26 21:11 Anton Blanchard
  2014-11-26 22:38 ` Michael Ellerman
  0 siblings, 1 reply; 10+ messages in thread
From: Anton Blanchard @ 2014-11-26 21:11 UTC (permalink / raw)
  To: benh, paulus, mpe; +Cc: linuxppc-dev

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

Fixes: 18ad51dd342a ("powerpc: Add VDSO version of getcpu")
Cc: stable@vger.kernel.org
Signed-off-by: Anton Blanchard <anton@samba.org>
---
 arch/powerpc/kernel/vdso32/getcpu.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/kernel/vdso32/getcpu.S b/arch/powerpc/kernel/vdso32/getcpu.S
index 23eb9a9..c62be60 100644
--- a/arch/powerpc/kernel/vdso32/getcpu.S
+++ b/arch/powerpc/kernel/vdso32/getcpu.S
@@ -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
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-26 21:11 [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions Anton Blanchard
@ 2014-11-26 22:38 ` Michael Ellerman
  2014-11-26 23:23   ` Segher Boessenkool
  2014-11-26 23:50   ` Peter Bergner
  0 siblings, 2 replies; 10+ messages in thread
From: Michael Ellerman @ 2014-11-26 22:38 UTC (permalink / raw)
  To: Anton Blanchard; +Cc: paulus, linuxppc-dev

On Thu, 2014-11-27 at 08:11 +1100, Anton Blanchard wrote:
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-26 22:38 ` Michael Ellerman
@ 2014-11-26 23:23   ` Segher Boessenkool
  2014-11-26 23:28     ` Segher Boessenkool
  2014-11-26 23:50   ` Peter Bergner
  1 sibling, 1 reply; 10+ messages in thread
From: Segher Boessenkool @ 2014-11-26 23:23 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev, paulus, Anton Blanchard

On Thu, Nov 27, 2014 at 09:38:17AM +1100, Michael Ellerman wrote:
> On Thu, 2014-11-27 at 08:11 +1100, Anton Blanchard wrote:
> > 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-26 23:23   ` Segher Boessenkool
@ 2014-11-26 23:28     ` Segher Boessenkool
  0 siblings, 0 replies; 10+ messages in thread
From: Segher Boessenkool @ 2014-11-26 23:28 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: paulus, linuxppc-dev, Anton Blanchard

On Wed, Nov 26, 2014 at 05:23:18PM -0600, Segher Boessenkool wrote:
> 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/
> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-26 22:38 ` Michael Ellerman
  2014-11-26 23:23   ` Segher Boessenkool
@ 2014-11-26 23:50   ` Peter Bergner
  2014-11-27 16:08     ` Segher Boessenkool
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Bergner @ 2014-11-26 23:50 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev, paulus, Anton Blanchard

On Thu, 2014-11-27 at 09:38 +1100, Michael Ellerman wrote:
> On Thu, 2014-11-27 at 08:11 +1100, Anton Blanchard wrote:
> > 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.


> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-26 23:50   ` Peter Bergner
@ 2014-11-27 16:08     ` Segher Boessenkool
  2014-11-27 17:41       ` Peter Bergner
  2014-11-27 18:20       ` Andreas Schwab
  0 siblings, 2 replies; 10+ messages in thread
From: Segher Boessenkool @ 2014-11-27 16:08 UTC (permalink / raw)
  To: Peter Bergner; +Cc: linuxppc-dev, Anton Blanchard, paulus

On Wed, Nov 26, 2014 at 05:50:27PM -0600, Peter Bergner wrote:
> On Thu, 2014-11-27 at 09:38 +1100, Michael Ellerman wrote:
> > On Thu, 2014-11-27 at 08:11 +1100, Anton Blanchard wrote:
> > > 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.

> > 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-27 16:08     ` Segher Boessenkool
@ 2014-11-27 17:41       ` Peter Bergner
  2014-11-27 20:50         ` Segher Boessenkool
  2014-11-27 18:20       ` Andreas Schwab
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Bergner @ 2014-11-27 17:41 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Anton Blanchard, paulus

On Thu, 2014-11-27 at 10:08 -0600, Segher Boessenkool wrote:
> On Wed, Nov 26, 2014 at 05:50:27PM -0600, Peter Bergner wrote:
> > 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-27 16:08     ` Segher Boessenkool
  2014-11-27 17:41       ` Peter Bergner
@ 2014-11-27 18:20       ` Andreas Schwab
  1 sibling, 0 replies; 10+ messages in thread
From: Andreas Schwab @ 2014-11-27 18:20 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Anton Blanchard, paulus

Segher Boessenkool <segher@kernel.crashing.org> writes:

> On Wed, Nov 26, 2014 at 05:50:27PM -0600, Peter Bergner wrote:
>> On Thu, 2014-11-27 at 09:38 +1100, Michael Ellerman wrote:
>> > On Thu, 2014-11-27 at 08:11 +1100, Anton Blanchard wrote:
>> > > 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.

Not on the 7447A, fwiw.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-27 17:41       ` Peter Bergner
@ 2014-11-27 20:50         ` Segher Boessenkool
  2014-11-28  2:00           ` Benjamin Herrenschmidt
  0 siblings, 1 reply; 10+ messages in thread
From: Segher Boessenkool @ 2014-11-27 20:50 UTC (permalink / raw)
  To: Peter Bergner; +Cc: linuxppc-dev, Anton Blanchard, paulus

On Thu, Nov 27, 2014 at 11:41:40AM -0600, Peter Bergner wrote:
> On Thu, 2014-11-27 at 10:08 -0600, Segher Boessenkool wrote:
> > On Wed, Nov 26, 2014 at 05:50:27PM -0600, Peter Bergner wrote:
> > > 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???

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions
  2014-11-27 20:50         ` Segher Boessenkool
@ 2014-11-28  2:00           ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 10+ messages in thread
From: Benjamin Herrenschmidt @ 2014-11-28  2:00 UTC (permalink / raw)
  To: Segher Boessenkool; +Cc: linuxppc-dev, Anton Blanchard, paulus

On Thu, 2014-11-27 at 14:50 -0600, Segher Boessenkool wrote:
> On Thu, Nov 27, 2014 at 11:41:40AM -0600, Peter Bergner wrote:
> > On Thu, 2014-11-27 at 10:08 -0600, Segher Boessenkool wrote:
> > > On Wed, Nov 26, 2014 at 05:50:27PM -0600, Peter Bergner wrote:
> > > > 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???
> 
> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-11-28  2:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-26 21:11 [PATCH] powerpc: 32 bit getcpu VDSO function uses 64 bit instructions Anton Blanchard
2014-11-26 22:38 ` Michael Ellerman
2014-11-26 23:23   ` Segher Boessenkool
2014-11-26 23:28     ` Segher Boessenkool
2014-11-26 23:50   ` Peter Bergner
2014-11-27 16:08     ` Segher Boessenkool
2014-11-27 17:41       ` Peter Bergner
2014-11-27 20:50         ` Segher Boessenkool
2014-11-28  2:00           ` Benjamin Herrenschmidt
2014-11-27 18:20       ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).