From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Ananth N Mavinakayanahalli <ananth@in.ibm.com>,
Veaceslav Falico <vfalico@redhat.com>,
Paul Mackerras <paulus@samba.org>,
Alexey Dobriyan <adobriyan@gmail.com>,
Christoph Hellwig <hch@infradead.org>,
"Frank Ch. Eigler" <fche@redhat.com>, Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
Roland McGrath <roland@redhat.com>,
linux-kernel@vger.kernel.org, utrace-devel@redhat.com
Subject: Re: powerpc: syscall_dotrace() && retcode (Was: powerpc: fork && stepping)
Date: Mon, 30 Nov 2009 10:15:01 +1100 [thread overview]
Message-ID: <1259536501.2076.39.camel@pasglop> (raw)
In-Reply-To: <20091129210716.GA19205@redhat.com>
On Sun, 2009-11-29 at 22:07 +0100, Oleg Nesterov wrote:
> On 11/28, Ananth N Mavinakayanahalli wrote:
> >
> > syscall-reset is the only failure I see on
> > powerpc:
> >
> > errno 14 (Bad address)
> > syscall-reset: syscall-reset.c:95: main: Assertion `(*__errno_location
> > ()) == 38' failed.
> > unexpected child status 67f
> > FAIL: syscall-reset
>
> (to remind, it also fails without utrace)
>
> Once again, I know nothing about powerc, perhaps I misread the code,
> but I believe this test-case is just wrong on powerpc and should be
> fixed.
>
> On powerpc, syscall_get_nr() returns regs->gpr[0], this means this
> register is used to pass the syscall number.
Correct.
> This matches do_syscall_trace_enter(), it returns regs->gpr[0] as a
> (possibly changed by tracer) syscall nr.
>
> arch/powerpc/kernel/entry_64.S does
>
> syscall_dotrace:
>
> bl .do_syscall_trace_enter
> mr r0,r3 // I guess, r3 = r0 ?
r3 is the return value from a function so this replaces the
syscall number
> ...
> b syscall_dotrace_cont
>
> syscall_dotrace_cont:
>
> syscall_dotrace_cont:
>
> cmpldi 0,r0,NR_syscalls
> bge- syscall_enosys
>
> syscall_enosys:
>
> li r3,-ENOSYS
> b syscall_exit
>
>
> Now return to the test-case, syscall-reset.c. The tracee does
> l = syscall (-23, 1, 2, 3) and stops.
>
> The tracer does
>
> #define RETREG offsetof(struct pt_regs, gpr[0])
> #define NEWVAL ((long) ENOTTY)
>
> l = ptrace(PTRACE_PEEKUSER, child, RETREG, 0l);
>
> l == -23, this is correct, note syscall(-23) above.
>
> l = ptrace(PTRACE_POKEUSER, child, RETREG, NEWVAL);
>
> And expects the tracee will see NEWVAL==ENOTTY after return from
> the systame call.
>
> Of course this can't happen. We changed the syscall number, the
> new value is ENOTTY == 25 == __NR_stime, sys_stime() correctly
> returns -EFAULT.
>
> -----------------------------------------------------------------
>
> If I change the test-case to use NEWVAL == 1000 (or any other value
> greater than NR_syscalls), then the tracee sees ENOSYS and this is
> correct too.
>
> But I do not see how it is possible to change the retcode on powerpc.
> Unlike x86, powepc doesn't set -ENOSYS "in advance", before doing
> do_syscall_trace_enter() logic. This means that if the tracer "cancels"
> syscall, r3 will be overwritten by syscall_enosys.
>
> This probably means the kernel should be fixed too, but I am not
> brave enough to change the asm which I can't understand ;)
Yes, the asm should be changed. I suppose we could check if the result
of do_syscall_trace_enter is negative, and if it is, branch to the exit
path using r3 as the error code. Would that be ok ?
Something like this:
diff --git a/arch/powerpc/kernel/entry_32.S b/arch/powerpc/kernel/entry_32.S
index 1175a85..7a88c88 100644
--- a/arch/powerpc/kernel/entry_32.S
+++ b/arch/powerpc/kernel/entry_32.S
@@ -419,6 +419,9 @@ syscall_dotrace:
stw r0,_TRAP(r1)
addi r3,r1,STACK_FRAME_OVERHEAD
bl do_syscall_trace_enter
+ cmpwi cr0,r3,0
+ blt ret_from_syscall
+
/*
* Restore argument registers possibly just changed.
* We use the return value of do_syscall_trace_enter
diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S
index 9763267..ec709a7 100644
--- a/arch/powerpc/kernel/entry_64.S
+++ b/arch/powerpc/kernel/entry_64.S
@@ -240,6 +240,9 @@ syscall_dotrace:
bl .save_nvgprs
addi r3,r1,STACK_FRAME_OVERHEAD
bl .do_syscall_trace_enter
+ cmpdi cr0,r3,0
+ blt syscall_exit
+
/*
* Restore argument registers possibly just changed.
* We use the return value of do_syscall_trace_enter
Cheers,
Ben.
next prev parent reply other threads:[~2009-11-29 23:18 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-24 20:01 [RFC,PATCH 0/14] utrace/ptrace Oleg Nesterov
2009-11-25 8:03 ` Ananth N Mavinakayanahalli
2009-11-25 15:40 ` Oleg Nesterov
2009-11-26 7:53 ` Ananth N Mavinakayanahalli
2009-11-26 14:50 ` powerpc: fork && stepping (Was: [RFC,PATCH 0/14] utrace/ptrace) Oleg Nesterov
2009-11-26 17:25 ` Oleg Nesterov
2009-11-26 18:22 ` Veaceslav Falico
2009-11-26 20:23 ` Oleg Nesterov
2009-11-26 21:04 ` Oleg Nesterov
2009-11-26 21:53 ` Paul Mackerras
2009-11-26 22:37 ` Oleg Nesterov
2009-11-27 17:46 ` Veaceslav Falico
2009-11-28 7:30 ` Ananth N Mavinakayanahalli
2009-11-29 21:07 ` powerpc: syscall_dotrace() && retcode (Was: powerpc: fork && stepping) Oleg Nesterov
2009-11-29 23:15 ` Benjamin Herrenschmidt [this message]
2009-11-30 0:43 ` Benjamin Herrenschmidt
2009-11-30 20:00 ` Oleg Nesterov
2009-11-30 20:01 ` Oleg Nesterov
2009-12-01 19:27 ` Roland McGrath
2009-12-01 20:17 ` Benjamin Herrenschmidt
2009-11-26 22:40 ` powerpc: fork && stepping (Was: [RFC,PATCH 0/14] utrace/ptrace) Andreas Schwab
2009-11-27 5:39 ` Ananth N Mavinakayanahalli
2009-11-27 15:05 ` Oleg Nesterov
2009-11-28 7:06 ` Ananth N Mavinakayanahalli
2009-11-25 21:48 ` [RFC,PATCH 0/14] utrace/ptrace Christoph Hellwig
2009-11-25 22:28 ` Oleg Nesterov
2009-11-26 7:07 ` Srikar Dronamraju
2009-11-26 12:55 ` Peter Zijlstra
2009-11-26 9:10 ` Ingo Molnar
2009-11-26 10:47 ` Christoph Hellwig
2009-11-26 12:24 ` Ingo Molnar
2009-11-27 14:04 ` Christoph Hellwig
2009-11-27 14:17 ` Oleg Nesterov
2009-11-27 19:16 ` Ingo Molnar
2009-11-26 14:27 ` Oleg Nesterov
2009-12-02 0:46 ` Roland McGrath
2009-11-29 8:59 ` Pavel Machek
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=1259536501.2076.39.camel@pasglop \
--to=benh@kernel.crashing.org \
--cc=adobriyan@gmail.com \
--cc=ananth@in.ibm.com \
--cc=fche@redhat.com \
--cc=hch@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
--cc=roland@redhat.com \
--cc=utrace-devel@redhat.com \
--cc=vfalico@redhat.com \
/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