All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Andi Kleen <ak@suse.de>
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 16:57:59 -0700	[thread overview]
Message-ID: <200407152357.i6FNvxiu020873@magilla.sf.frob.com> (raw)
In-Reply-To: Andi Kleen's message of  Friday, 16 July 2004 00:06:18 +0200 <20040716000618.0441d268.ak@suse.de>

> Anyways, even if I applied your patch there would be still inconsistency
> because there are several other system calls that use IRET. So I don't
> see much advantage in adding a special case just for sigreturn.

Now that I see that the difference is due to iret being used, I have a
different solution that handles all cases.  The following patch replaces
both my previous patch for x86-64 native behavior and my patch for x86-64's
ia32 support.  This patch just directly clones Davide Libenzi's i386 code
for x86-64 in both 64-bit and 32-bit cases.  With this, the behavior of
single-stepping all system calls is consistent.  

The syscall exit tracing caused by TIF_SINGLESTEP is superfluous in the
case of sysret returns, but harmlessly so (since continuing afterward with
PTRACE_CONT will have cleared TF as well as TIF_SINGLESTEP).  I figured
that little bit of extra processing in the single-step case was better than
adding code to ignore the flag in the sysret case.



Thanks,
Roland


Signed-off-by: Roland McGrath <roland@redhat.com>


Index: linux-2.6/arch/x86_64/kernel/entry.S
===================================================================
RCS file: /home/roland/redhat/bkcvs/linux-2.5/arch/x86_64/kernel/entry.S,v
retrieving revision 1.22
diff -b -p -u -r1.22 entry.S
--- linux-2.6/arch/x86_64/kernel/entry.S 12 Apr 2004 20:29:12 -0000 1.22
+++ linux-2.6/arch/x86_64/kernel/entry.S 15 Jul 2004 23:45:59 -0000
@@ -297,7 +297,7 @@ int_very_careful:
 	sti
 	SAVE_REST
 	/* Check for syscall exit trace */	
-	testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),%edx
+	testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SINGLESTEP),%edx
 	jz int_signal
 	pushq %rdi
 	leaq 8(%rsp),%rdi	# &ptregs -> arg1	
Index: linux-2.6/arch/x86_64/kernel/ptrace.c
===================================================================
RCS file: /home/roland/redhat/bkcvs/linux-2.5/arch/x86_64/kernel/ptrace.c,v
retrieving revision 1.16
diff -b -p -u -r1.16 ptrace.c
--- linux-2.6/arch/x86_64/kernel/ptrace.c 31 May 2004 03:07:42 -0000 1.16
+++ linux-2.6/arch/x86_64/kernel/ptrace.c 15 Jul 2004 23:56:44 -0000
@@ -88,6 +88,7 @@ void ptrace_disable(struct task_struct *
 { 
 	long tmp;
 
+	clear_tsk_thread_flag(child, TIF_SINGLESTEP);
 	tmp = get_stack_long(child, EFL_OFFSET) & ~TRAP_FLAG;
 	put_stack_long(child, EFL_OFFSET, tmp);
 }
@@ -344,6 +345,7 @@ asmlinkage long sys_ptrace(long request,
 			set_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
 		else
 			clear_tsk_thread_flag(child,TIF_SYSCALL_TRACE);
+		clear_tsk_thread_flag(child, TIF_SINGLESTEP);
 		child->exit_code = data;
 	/* make sure the single step bit is not set. */
 		tmp = get_stack_long(child, EFL_OFFSET);
@@ -395,6 +397,7 @@ asmlinkage long sys_ptrace(long request,
 		ret = 0;
 		if (child->state == TASK_ZOMBIE)	/* already dead */
 			break;
+		clear_tsk_thread_flag(child, TIF_SINGLESTEP);
 		child->exit_code = SIGKILL;
 		/* make sure the single step bit is not set. */
 		tmp = get_stack_long(child, EFL_OFFSET) & ~TRAP_FLAG;
@@ -416,6 +419,7 @@ asmlinkage long sys_ptrace(long request,
 		}
 		tmp = get_stack_long(child, EFL_OFFSET) | TRAP_FLAG;
 		put_stack_long(child, EFL_OFFSET, tmp);
+		set_tsk_thread_flag(child, TIF_SINGLESTEP);
 		child->exit_code = data;
 		/* give it a chance to run. */
 		wake_up_process(child);
@@ -528,7 +532,8 @@ asmlinkage void syscall_trace_leave(stru
 	if (unlikely(current->audit_context))
 		audit_syscall_exit(current, regs->rax);
 
-	if (test_thread_flag(TIF_SYSCALL_TRACE)
+	if ((test_thread_flag(TIF_SYSCALL_TRACE)
+	     || test_thread_flag(TIF_SINGLESTEP))
 	    && (current->ptrace & PT_PTRACED))
 		syscall_trace(regs);
 }

  reply	other threads:[~2004-07-15 23:58 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
2004-07-15 21:13       ` Roland McGrath
2004-07-15 22:06         ` Andi Kleen
2004-07-15 23:57           ` Roland McGrath [this message]
     [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=200407152357.i6FNvxiu020873@magilla.sf.frob.com \
    --to=roland@redhat.com \
    --cc=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=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 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.