linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Munroe <munroesj@linux.vnet.ibm.com>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	"Ryan S. Arnold" <rsa@us.ibm.com>
Cc: linux-arch@vger.kernel.org,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Mark Lord <kernel@teksavvy.com>,
	Ulrich Drepper <drepper@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: 64-syscall args on 32-bit vs syscall()
Date: Mon, 15 Mar 2010 10:03:32 -0500	[thread overview]
Message-ID: <1268665412.19726.75.camel@spokane1.rchland.ibm.com> (raw)
In-Reply-To: <1268628493.2355.2.camel@pasglop>

On Mon, 2010-03-15 at 15:48 +1100, Benjamin Herrenschmidt wrote:
> Hoy there !
> 
> This may have been discussed earlier (I have some vague memories...) but
> I just hit a problem with that again (Mark: hint, it's in hdparm's
> fallocate) so I'd like a bit of a refresh here on what is the "right
> thing" to do...
> 
> So some syscalls want a 64-bit argument. Let's take fallocate() as our
> example. So we already know that we have to be extra careful since some
> 32-bit arch will pass this into 2 registers (or stack slots) which need
> to be aligned, and so we tend to already take care of making sure that
> the said 64-bit argument is either defined as 2x32-bit arguments, or
> defined as 1x64 bit argument aligned to 2x32-bit in the argument list.
> 
> So far so good...
> 
> The problem is when user space tries to use the same trick for calling
> those functions using glibc-provided syscall() function. In this
> example, hdparm does:
> 
> err = syscall(SYS_fallocate, fd, mode, offset, len);
> 
> With "offset" being a 64-bit argument.
> 

The powerpc implementation of syscall is:


ENTRY (syscall)
	mr   r0,r3
	mr   r3,r4
	mr   r4,r5
	mr   r5,r6
	mr   r6,r7
	mr   r7,r8
	mr   r8,r9
	sc
	PSEUDO_RET
PSEUDO_END (syscall)

The ABI says:

"Long long arguments are considered to have 8-byte size and alignment.
The same 8-byte arguments that must go in aligned pairs or registers are
8-byte aligned on the stack."

This implies that the SYS_fallocate call will skip a register to get the
required alignment in the parameter save area.

for ppc32 on entry

r3 == SYS_fallocate
r4 == fd
r5 == mode
r6 == not used
r7, r8 == offset
r9 == len

This gets shifted to:

r0 == SYS_fallocate
r3 == fd
r4 == mode
r5 == not used
r6, r7 == offset
r8 == len

For syscall the vararg parms will be mirrored to the parameter save area
but will not be used. The ABI does not talk to LE for this case.

Ryan does the new ABI doc cover this?

> This will break because the first argument to syscall now shifts
> everything by one register, which breaks the register pair alignment
> (and I suppose archs with stack based calling convention can have
> similar alignment issues even if x86 doesn't).
> 
> Ulrich, Steven, shouldn't we have glibc's syscall() take a long long as
> it's first argument to correct that ? Either that or making it some kind
> of macro wrapper around a __syscall(int dummy, int sysno, ...) ?
> 
> As it is, any 32-bit app using syscall() on any of the syscalls that
> takes 64-bit arguments will be broken, unless the app itself breaks up
> the argument, but the the order of the hi and lo part is different
> between BE and LE architectures ;-)
> 
> So is there a more "correct" solution than another here ? Should powerpc
> glibc be fixed at least so that syscall() keeps the alignment ?
> 
> Cheers,
> Ben.
> 
> 

  parent reply	other threads:[~2010-03-15 14:54 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
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 [this message]
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=1268665412.19726.75.camel@spokane1.rchland.ibm.com \
    --to=munroesj@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=drepper@redhat.com \
    --cc=kernel@teksavvy.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=munroesj@us.ibm.com \
    --cc=rsa@us.ibm.com \
    --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).