linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: "Dmitry V. Levin" <ldv@altlinux.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Oleg Nesterov <oleg@redhat.com>,
	Andy Lutomirski <luto@kernel.org>
Cc: Elvira Khabirova <lineprinter@altlinux.org>,
	Eugene Syromyatnikov <esyr@redhat.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: powerpc syscall_set_return_value() is confused (was Re: [PATCH v6 18/27] powerpc: define syscall_get_error())
Date: Tue, 18 Dec 2018 23:36:09 +1100	[thread overview]
Message-ID: <874lbbt3k6.fsf@concordia.ellerman.id.au> (raw)
In-Reply-To: <20181213172313.GR6024@altlinux.org>

Hi Dmitry,

"Dmitry V. Levin" <ldv@altlinux.org> writes:
> syscall_get_error() is required to be implemented on this
> architecture in addition to already implemented syscall_get_nr(),
> syscall_get_arguments(), syscall_get_return_value(), and
> syscall_get_arch() functions in order to extend the generic
> ptrace API with PTRACE_GET_SYSCALL_INFO request.
>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Elvira Khabirova <lineprinter@altlinux.org>
> Cc: Eugene Syromyatnikov <esyr@redhat.com>
> Cc: linuxppc-dev@lists.ozlabs.org
> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> ---
>
> Notes:
>     v6: unchanged
>     
>     v5:
>     This change has been tested with
>     tools/testing/selftests/ptrace/get_syscall_info.c and strace,
>     so it's correct from PTRACE_GET_SYSCALL_INFO point of view.
>     
>     This cast doubts on commit v4.3-rc1~86^2~81 that changed
>     syscall_set_return_value() in a way that doesn't quite match
>     syscall_get_error(), but syscall_set_return_value() is out
>     of scope of this series, so I'll just let you know my concerns.

Sorry I only just saw this comment.

It's going to take me a while to page this stuff back into my brain, but
I think you may have a point.

I think the way it's written now *works* but only because it's only used
by seccomp, and we rely on the fact that the syscall exit path will
negate the value before returning to userspace or calling ptrace etc.

eg. we do:

syscall_set_return_value()
	if (error) {
		regs->ccr |= 0x10000000L;
		regs->gpr[3] = error;

then the asm does:

	/* Return code is already in r3 thanks to do_syscall_trace_enter() */
	b	.Lsyscall_exit
	...

.Lsyscall_exit:
	std	r3,RESULT(r1)
	...

3:	cmpld	r3,r11
	ld	r5,_CCR(r1)
	bge-	.Lsyscall_error
	...

.Lsyscall_error:
	oris	r5,r5,0x1000	/* Set SO bit in CR */
	neg	r3,r3
	std	r5,_CCR(r1)

And we do the same before calling do_syscall_trace_leave().


Still it's a bit confused, because in the C code we're setting r3 and
CCR in the C code, but we're not negating the value in r3, and we're not
setting result at all.

I'll test a patch to fix it up.

cheers

  reply	other threads:[~2018-12-18 12:36 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20181213171833.GA5240@altlinux.org>
2018-12-13 17:21 ` [PATCH v6 01/27] asm-generic/syscall.h: prepare for inclusion by other files Dmitry V. Levin
2018-12-13 17:21 ` [PATCH v6 02/27] asm-generic/syscall.h: turn syscall_[gs]et_arguments into wrappers Dmitry V. Levin
2018-12-13 17:21 ` [PATCH v6 03/27] alpha: define remaining syscall_get_* functions Dmitry V. Levin
2018-12-13 17:21 ` [PATCH v6 04/27] Move EM_ARCOMPACT and EM_ARCV2 to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-21  1:19   ` Dmitry V. Levin
2018-12-13 17:21 ` [PATCH v6 05/27] arc: define syscall_get_arch() Dmitry V. Levin
2018-12-21  1:21   ` Dmitry V. Levin
2018-12-13 17:21 ` [PATCH v6 06/27] c6x: " Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 07/27] elf-em.h: add EM_CSKY Dmitry V. Levin
2018-12-14  4:43   ` Guo Ren
2018-12-21  2:35     ` Dmitry V. Levin
2018-12-21 14:49       ` Guo Ren
2018-12-13 17:22 ` [PATCH v6 08/27] csky: define syscall_get_arch() Dmitry V. Levin
2018-12-14  4:44   ` Guo Ren
2018-12-21  2:36     ` Dmitry V. Levin
2018-12-21 14:48       ` Guo Ren
2018-12-13 17:22 ` [PATCH v6 09/27] h8300: define remaining syscall_get_* functions Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 10/27] Move EM_HEXAGON to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 11/27] hexagon: define remaining syscall_get_* functions Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 12/27] Move EM_NDS32 to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 13/27] nds32: define syscall_get_arch() Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 14/27] nios2: " Dmitry V. Levin
2018-12-13 17:22 ` [PATCH v6 15/27] m68k: add asm/syscall.h Dmitry V. Levin
2018-12-13 17:23 ` [PATCH v6 16/27] mips: define syscall_get_error() Dmitry V. Levin
2018-12-13 19:00   ` Paul Burton
2018-12-21  1:31     ` Dmitry V. Levin
2018-12-13 17:23 ` [PATCH v6 17/27] parisc: " Dmitry V. Levin
2018-12-13 17:23 ` [PATCH v6 18/27] powerpc: " Dmitry V. Levin
2018-12-18 12:36   ` Michael Ellerman [this message]
2018-12-13 17:23 ` [PATCH v6 19/27] riscv: define syscall_get_arch() Dmitry V. Levin
2018-12-13 17:23 ` [PATCH v6 20/27] Move EM_XTENSA to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-13 17:23 ` [PATCH v6 21/27] xtensa: define syscall_get_* functions Dmitry V. Levin
2018-12-13 17:24 ` [PATCH v6 22/27] Move EM_UNICORE to uapi/linux/elf-em.h Dmitry V. Levin
2018-12-13 17:24 ` [PATCH v6 23/27] unicore32: add asm/syscall.h Dmitry V. Levin
2018-12-13 17:24 ` [PATCH v6 24/27] syscall_get_arch: add "struct task_struct *" argument Dmitry V. Levin
2018-12-13 17:24 ` [PATCH v6 25/27] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Dmitry V. Levin
2018-12-13 17:24 ` [PATCH v6 26/27] ptrace: add PTRACE_GET_SYSCALL_INFO request Dmitry V. Levin
2018-12-13 17:24 ` [PATCH v6 27/27] selftests/ptrace: add a test case for PTRACE_GET_SYSCALL_INFO Dmitry V. Levin

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=874lbbt3k6.fsf@concordia.ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=benh@kernel.crashing.org \
    --cc=esyr@redhat.com \
    --cc=ldv@altlinux.org \
    --cc=lineprinter@altlinux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=oleg@redhat.com \
    --cc=paulus@samba.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).