public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: Roland McGrath <roland@redhat.com>
Cc: akpm@osdl.org, torvalds@osdl.org, linux-kernel@vger.kernel.org,
	jparadis@redhat.com, cagney@redhat.com, discuss@x86-64.org
Subject: Re: [PATCH] x86-64 singlestep through sigreturn system call
Date: Thu, 15 Jul 2004 07:46:18 +0200	[thread overview]
Message-ID: <20040715074618.4c33bd31.ak@suse.de> (raw)
In-Reply-To: <200407150056.i6F0uQMa010372@magilla.sf.frob.com>

On Wed, 14 Jul 2004 17:56:26 -0700
Roland McGrath <roland@redhat.com> wrote:

[adding discuss@x86-64.org, maybe someone there knows more about the SYSRET
behaviour]

> > > This patch fixes the problem by forcing a fake single-step trap at the end
> > > of rt_sigreturn when PTRACE_SINGLESTEP was used to enter the system call.
> > 
> > I don't like this very much, see previous mail.
> 
> The previous mail addressed the subject of changing the behavior of i386
> processes, where single-stepping any system call misses a trap.  The native
> x86-64 behavior is different, and so this issue is really separate from
> that one.  By the way, I would love it if you could explain to me with
> references to the x86-64 chip documentation why restoring TF with sysret
> seems to trap before executing the next user instruction in 64-bit mode,
> while restoring TF with sysexit to 32-bit user mode behaves like native
> 32-bit mode (as documented) and executes one instruction before taking the
> single-step trap.

I don't think it's documented anywhere. Even the old SYSCALL/SYSRET Athlon
application note doesn't say anything about how single step is supposed
to work with this. It's probably an artifact of the first implementation
that has been faithfully reproduced since then.

> Anyway, on native x86-64 single-stepping into `syscall' already works like
> a user would expect, and takes a single-step trap immediately on return
> from the system call before executing the first user instruction.  Only
> stepping into an `rt_sigreturn' call behaves otherwise.

and a few other calls who use iret, like iopl() or sigaltstack().

Anyways, I don't have any plans to change the 64bit behaviour. gdb will
have to live with a few minor inconsistencies as price for faster system
calls. 


> > If you really wanted to do it:
> > 
> > Wouldn't it be simpler to just copy the TF bit from the previous Eflags? 
> > This special case looks quite ugly.
> 
> I would expect that to work from the behavior I think I see with other
> system calls.  But I've tried it and it doesn't work.  Setting TF this way
> behaves like the i386 does: it executes one user instruction at the
> restored PC and then traps.  I certainly find this confusing, but as I said
> above I still haven't explained to myself why it doesn't behave that way
> for normal system calls (that don't change the PC being returned to).

The normal syscalls use SYSRET, the special syscalls use IRET. That's required
because SYSRET cannot restore all registers, so sometimes a slow path out
must be taken.

-Andi


  reply	other threads:[~2004-07-15  5:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-13  0:22 [PATCH] x86-64 singlestep through sigreturn system call Roland McGrath
2004-07-13  7:23 ` Andi Kleen
2004-07-15  0:56   ` Roland McGrath
2004-07-15  5:46     ` Andi Kleen [this message]
2004-07-15 21:13       ` Roland McGrath
2004-07-15 22:06         ` Andi Kleen
2004-07-15 23:57           ` Roland McGrath
     [not found] <2imAA-4n7-49@gated-at.bofh.it>
     [not found] ` <2iosE-5Kb-17@gated-at.bofh.it>
2004-07-17 11:12   ` Andi Kleen
2004-07-22  2:16     ` Roland McGrath
2004-07-22  6:11       ` Andrew Morton
2004-07-22 22:58         ` Roland McGrath

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=20040715074618.4c33bd31.ak@suse.de \
    --to=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=cagney@redhat.com \
    --cc=discuss@x86-64.org \
    --cc=jparadis@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=roland@redhat.com \
    --cc=torvalds@osdl.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