All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Andi Kleen <ak@suse.de>, Petr Vandrovec <VANDROVE@vc.cvut.cz>,
	Linux Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: 32-bit syscalls from 64-bit process on x86-64?
Date: Thu, 16 Dec 2004 05:35:21 +0100	[thread overview]
Message-ID: <20041216043520.GD32718@wotan.suse.de> (raw)
In-Reply-To: <1103144285.13338.30.camel@minilith.goop.org>

On Wed, Dec 15, 2004 at 12:58:05PM -0800, Jeremy Fitzhardinge wrote:
> On Wed, 2004-12-15 at 11:55 +0100, Andi Kleen wrote:
> > Hmm, in theory you could handle a 64bit signal frame from 32bit code
> > (just may need an assembly stub if you want the arguments). But it 
> > would be quite ugly agreed.
> 
> Yes.  I've tried this out, and it works OK, but it isn't pleasing.  One
> of the main problems is that the stack is likely to be above 4G, so %esp
> has no useful value, and when you switch to 64-bit mode, the top 32-bits
> of %rsp become undefined.

They seem to stay at the previous value in the current CPUs, but it's 
undefined behaviour yes.

> 
> > Perhaps it should force __USER_CS yes in this case, agreed.
> > 
> > There is a small risk of breaking someone, but it's very small.
> 
> Well, if they've got code which is already switching between 32 and 64
> bit segments, then they need to cope with either cs being current at
> delivery time.

Can you cope with that in valgrind? If I change it there will
be kernels with both behaviour around for a long time.

> 
> > I can do that change if you want.
> > 
> > BTW the long term plan is to get rid of the special cases to make
> > it easierto use the 32bit kernel ABI from a 64bit program.
> > This means signal handling will likely just check the code segment
> > at some  point to decide if it should set up 32bit or 64bit frames
> > and we'll probably do similar things with the other cases 
> > (except exec which needs to stay this way) 
> 
> At syscall time, rather than delivery time, I assume.  Hm, I'd prefer it
> if it didn't look at the current segment, but at the syscall path.  Ie,
> installing a handler with __NR_rt_sigaction via int 0x80 (or 32-bit
> syscall/sysenter) should set up a 32-bit frame on delivery, but if the
> handler was installed with the 64-bit syscall, it should be called with
> a 64-bit frame.

That would probably add some complications to the syscall exit path:
there is some code sharing between 32bit and 64bit, in particular 64bit
execve uses the IRET path to restore all registers and there can be a 
signal after that.

The only case that wouldn't be handled by checking the segment would
be that if someone defines a 64bit LDT code segment and uses it, it
will not work. But that won't work anyways from 64bit because SYSRET
always forces __USER_CS. If you want to do any 64bit system calls
you cannot use such custom segment anyways. 

So i don't see any drawbacks in just checking the segment for this.

-Andi


  reply	other threads:[~2004-12-16  4:35 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-14 22:01 32-bit syscalls from 64-bit process on x86-64? Petr Vandrovec
2004-12-15  4:27 ` Andi Kleen
2004-12-15 10:50   ` Jeremy Fitzhardinge
2004-12-15 10:55     ` Andi Kleen
2004-12-15 20:58       ` Jeremy Fitzhardinge
2004-12-16  4:35         ` Andi Kleen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-12-02 16:22 Jeremy Fitzhardinge
2004-12-02 18:52 ` Jeremy Fitzhardinge
2004-12-03  6:15 ` Andi Kleen
2004-12-03 23:16   ` Jeremy Fitzhardinge
2004-12-04 14:40     ` Petr Vandrovec
2004-12-04 21:33       ` Jeremy Fitzhardinge
2004-12-08  2:30       ` Jeremy Fitzhardinge
2004-12-14  7:45       ` Andi Kleen

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=20041216043520.GD32718@wotan.suse.de \
    --to=ak@suse.de \
    --cc=VANDROVE@vc.cvut.cz \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.