2020-05-25 14:41:43

by Tycho Andersen

[permalink] [raw]
Subject: Re: [PATCH] riscv: Remove unnecessary path for syscall_trace

On Mon, May 25, 2020 at 02:18:26PM +0000, [email protected] wrote:
> From: Guo Ren <[email protected]>
>
> Obviously, there is no need to recover a0-a7 in reject path.
>
> Previous modification is from commit af33d243 by Tycho, to
> fixup seccomp reject syscall code path.

Doesn't this suffer from the same problem, though? a7 is clobbered, so
the -ERESTARTSYS behavior won't work?

I haven't run the test case that was failing before.

Tycho


2020-05-26 00:34:03

by Guo Ren

[permalink] [raw]
Subject: Re: [PATCH] riscv: Remove unnecessary path for syscall_trace

Hi Tycho,

On Mon, May 25, 2020 at 10:36 PM Tycho Andersen <[email protected]> wrote:
>
> On Mon, May 25, 2020 at 02:18:26PM +0000, [email protected] wrote:
> > From: Guo Ren <[email protected]>
> >
> > Obviously, there is no need to recover a0-a7 in reject path.
> >
> > Previous modification is from commit af33d243 by Tycho, to
> > fixup seccomp reject syscall code path.
>
> Doesn't this suffer from the same problem, though? a7 is clobbered, so
> the -ERESTARTSYS behavior won't work?

Look, the patch only affects the path of ret_from_syscall_rejected,
and there are two possible paths:
1. ret_from_syscall_rejected->handle_syscall_trace_exit->ret_from_exception
2. ret_from_syscall_rejected->ret_from_exception

All the above skip the check_syscall_nr and ignore the current a7, in
the C function they use the pt_regs in the stack to get proper reg's
value.

For the -ERESTARTSYS, we only process it in:
ret_from_exception->resume_userspace->work_notifysig->do_notify_resume:
do_signal & handle_signal:

switch (regs->a0) {
case -ERESTARTNOHAND:
case -ERESTARTSYS:
case -ERESTARTNOINTR:
regs->a0 = regs->orig_a0;
regs->epc -= 0x4;
break;

All above are done in pt_regs and when returning to userspace, a7 will
be recovered by restore_all in entry.S.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
--
Best Regards
Guo Ren

ML: https://lore.kernel.org/linux-csky/

2020-05-26 14:19:23

by Tycho Andersen

[permalink] [raw]
Subject: Re: [PATCH] riscv: Remove unnecessary path for syscall_trace

On Tue, May 26, 2020 at 08:29:45AM +0800, Guo Ren wrote:
> Hi Tycho,
>
> On Mon, May 25, 2020 at 10:36 PM Tycho Andersen <[email protected]> wrote:
> >
> > On Mon, May 25, 2020 at 02:18:26PM +0000, [email protected] wrote:
> > > From: Guo Ren <[email protected]>
> > >
> > > Obviously, there is no need to recover a0-a7 in reject path.
> > >
> > > Previous modification is from commit af33d243 by Tycho, to
> > > fixup seccomp reject syscall code path.
> >
> > Doesn't this suffer from the same problem, though? a7 is clobbered, so
> > the -ERESTARTSYS behavior won't work?
>
> Look, the patch only affects the path of ret_from_syscall_rejected,
> and there are two possible paths:
> 1. ret_from_syscall_rejected->handle_syscall_trace_exit->ret_from_exception
> 2. ret_from_syscall_rejected->ret_from_exception
>
> All the above skip the check_syscall_nr and ignore the current a7, in
> the C function they use the pt_regs in the stack to get proper reg's
> value.
>
> For the -ERESTARTSYS, we only process it in:
> ret_from_exception->resume_userspace->work_notifysig->do_notify_resume:
> do_signal & handle_signal:
>
> switch (regs->a0) {
> case -ERESTARTNOHAND:
> case -ERESTARTSYS:
> case -ERESTARTNOINTR:
> regs->a0 = regs->orig_a0;
> regs->epc -= 0x4;
> break;
>
> All above are done in pt_regs and when returning to userspace, a7 will
> be recovered by restore_all in entry.S.

Yes, thanks for that explanation.

Reviewed-by: Tycho Andersen <[email protected]>