linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Jamie Lokier <jamie@shareable.org>
Cc: Ulrich Drepper <drepper@redhat.com>,
	munroesj@us.ibm.com, "H. Peter Anvin" <hpa@zytor.com>,
	David Miller <davem@davemloft.net>,
	ralf@linux-mips.org, linux-arch@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel@teksavvy.com,
	torvalds@linux-foundation.org
Subject: Re: 64-syscall args on 32-bit vs syscall()
Date: Wed, 17 Mar 2010 21:18:58 +1100	[thread overview]
Message-ID: <1268821138.2335.196.camel@pasglop> (raw)
In-Reply-To: <20100317091820.GA8149@shareable.org>

On Wed, 2010-03-17 at 09:18 +0000, Jamie Lokier wrote:
> Benjamin Herrenschmidt wrote:
> > Hence, apps that use the first form today because it works on x86 would
> > end up working at least on powerpc where they would have been otherwise
> > broken unless they used some arch specific #ifdef to do the second form.
> 
> I think what Ulrich is getting at is your change will break existing
> code which already does:
> 
> #ifdef __powerpc__
> 	syscall(SYS_foo, 0, my_64bit_arg);
> #else
> 	syscall(SYS_foo, my_64bit_arg);
> #endif
> 
> I don't know of any such code, but it might be out there.

No, the above "workaround" doesn't work. With the existing syscall()
definition, there is no difference between your two examples. In the
first case, you force a proper 64-bit aligment, but you are already off
by one register pair from the kernel expectation. In the second case,
gcc will imply one, which means that both your examples above will
result in my_64bit_arg in the -same- place, which is off by a register
pair from what the kernel expect.

IE. In the first case gcc will put SYS_foo in r3, 0 in r4, and
my_64bit_arg in r5 and r6. In the second case, gcc will put SYS_foo in
r3, won't care about r4, and will put the 64-bit arg in r5 and r6. Then,
glibc syscall() will shift r3 to r0, r3 to r4 etc... causing
my_64bit_arg to land in r4 and r5. But the kernel expects it in r3 and
r4.

The workaround that apps should use today is:

#if defined(__powerpc__) && WORDSIZE == 32
	syscall(SYS_foo, (u32)(my_64bit_arg >> 32), (u32)my_64bit_arg);
#else
	syscall(SYS_foo, my_64bit_arg);
#endif

And with my proposed change, both of the above will work. IE. gcc will
put the argument always in r5,r6 and the syscall() implementation will
always shift r5 to r3 and t6 to r4. 

Cheers,
Ben.

  reply	other threads:[~2010-03-17 10:20 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-15  4:48 64-syscall args on 32-bit vs syscall() Benjamin Herrenschmidt
2010-03-15  4:48 ` Benjamin Herrenschmidt
2010-03-15  5:06 ` David Miller
2010-03-15  5:18   ` Benjamin Herrenschmidt
2010-03-15  5:54     ` David Miller
2010-03-15 20:22       ` Benjamin Herrenschmidt
2010-03-15 13:44     ` Ralf Baechle
2010-03-15 15:13       ` H. Peter Anvin
2010-03-15 16:00         ` Ulrich Drepper
2010-03-15 19:00           ` David Miller
2010-03-15 19:41             ` H. Peter Anvin
2010-03-15 20:35               ` Benjamin Herrenschmidt
2010-03-15 20:41                 ` H. Peter Anvin
2010-03-16 21:56                 ` Steven Munroe
2010-03-17  0:31                   ` Benjamin Herrenschmidt
2010-03-17  0:31                     ` Benjamin Herrenschmidt
2010-03-17  5:52                     ` Ulrich Drepper
2010-03-17  8:56                       ` Benjamin Herrenschmidt
2010-03-17  9:14                         ` Ulrich Drepper
2010-03-17 10:13                           ` Benjamin Herrenschmidt
2010-03-17  9:18                         ` Jamie Lokier
2010-03-17 10:18                           ` Benjamin Herrenschmidt [this message]
2010-03-17 18:30                         ` H. Peter Anvin
2010-03-17 20:35                           ` Benjamin Herrenschmidt
2010-03-17 20:53                             ` H. Peter Anvin
2010-03-17 22:58                               ` Benjamin Herrenschmidt
2010-03-17 22:58                                 ` Benjamin Herrenschmidt
2010-03-18 16:08                                 ` Steven Munroe
2010-03-18 16:21                                   ` Andreas Schwab
2010-03-18 16:21                                     ` Andreas Schwab
2010-03-18 17:03                                     ` Steven Munroe
2010-03-18 21:18                                       ` Benjamin Herrenschmidt
2010-03-19  1:22                                         ` Jamie Lokier
2010-03-15 20:27       ` Benjamin Herrenschmidt
2010-03-15 15:03 ` Steven Munroe
2010-03-15 20:32   ` Benjamin Herrenschmidt
2010-03-15 15:04 ` Jamie Lokier
2010-03-15 20:33   ` Benjamin Herrenschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1268821138.2335.196.camel@pasglop \
    --to=benh@kernel.crashing.org \
    --cc=davem@davemloft.net \
    --cc=drepper@redhat.com \
    --cc=hpa@zytor.com \
    --cc=jamie@shareable.org \
    --cc=kernel@teksavvy.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=munroesj@us.ibm.com \
    --cc=ralf@linux-mips.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).