public inbox for linux-mips@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
To: Tiezhu Yang <kernelpatch@126.com>
Cc: Oleg Nesterov <oleg@redhat.com>,
	linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
	Xuefeng Li <lixuefeng@loongson.cn>,
	kernel test robot <lkp@intel.com>,
	Xingxing Su <suxingxing@loongson.cn>
Subject: Re: [PATCH v2 RESEND] MIPS: Add basic support for ptrace single step
Date: Sat, 13 Feb 2021 10:05:22 +0100	[thread overview]
Message-ID: <20210213090522.GA4330@alpha.franken.de> (raw)
In-Reply-To: <fb37951.4.177977952f5.Coremail.kernelpatch@126.com>

On Sat, Feb 13, 2021 at 02:20:46AM +0800, Tiezhu Yang wrote:
> From: Tiezhu Yang <yangtiezhu@loongson.cn>
> 
> In the current code, arch_has_single_step() is not defined on MIPS,
> that means MIPS does not support instruction single-step for user mode.
> 
> Delve is a debugger for the Go programming language, the ptrace syscall
> PtraceSingleStep() failed [1] on MIPS and then the single step function
> can not work well, we can see that PtraceSingleStep() definition returns
> ptrace(PTRACE_SINGLESTEP) [2].
> 
> So it is necessary to support ptrace single step on MIPS.
> 
> At the beginning, we try to use the Debug Single Step exception on the
> Loongson 3A4000 platform, but it has no effect when set CP0_DEBUG SSt
> bit, this is because CP0_DEBUG NoSSt bit is 1 which indicates no
> single-step feature available [3], so this way which is dependent on the
> hardware is almost impossible.
> 
> With further research, we find out there exists a common way used with
> break instruction in arch/alpha/kernel/ptrace.c, it is workable.
> 
> For the above analysis, define arch_has_single_step(), add the common
> function user_enable_single_step() and user_disable_single_step(), set
> flag TIF_SINGLESTEP for child process, use break instruction to set
> breakpoint.
> 
> We can use the following testcase to test it:
> tools/testing/selftests/breakpoints/step_after_suspend_test.c
> 
>  $ make -C tools/testing/selftests TARGETS=breakpoints
>  $ cd tools/testing/selftests/breakpoints
> 
> Without this patch:
> 
>  $ ./step_after_suspend_test -n
>  TAP version 13
>  1..4
>  # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
>  ok 1 # SKIP CPU 0
>  # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
>  ok 2 # SKIP CPU 1
>  # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
>  ok 3 # SKIP CPU 2
>  # ptrace(PTRACE_SINGLESTEP) not supported on this architecture: Input/output error
>  ok 4 # SKIP CPU 3
>  # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:4 error:0
> 
> With this patch:
> 
>  $ ./step_after_suspend_test -n
>  TAP version 13
>  1..4
>  ok 1 CPU 0
>  ok 2 CPU 1
>  ok 3 CPU 2
>  ok 4 CPU 3
>  # Totals: pass:4 fail:0 xfail:0 xpass:0 skip:0 error:0
> 
> [1] https://github.com/go-delve/delve/blob/master/pkg/proc/native/threads_linux.go#L50
> [2] https://github.com/go-delve/delve/blob/master/vendor/golang.org/x/sys/unix/syscall_linux.go#L1573
> [3] http://www.t-es-t.hu/download/mips/md00047f.pdf
> 
> Reported-by: Guoqi Chen <chenguoqi@loongson.cn>
> Signed-off-by: Xingxing Su <suxingxing@loongson.cn>
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> Reported-by: kernel test robot <lkp@intel.com>
> ---
> 
> RESEND due to send to mail list failed, sorry for that.
> 
> v2: make union mips_instruction mips_insn = { 0 };
>     to fix uninitialized build warning used with clang
>     reported by kernel test robot.
> 
>  arch/mips/include/asm/ptrace.h      |   2 +
>  arch/mips/include/asm/thread_info.h |   5 ++
>  arch/mips/kernel/ptrace.c           | 108 ++++++++++++++++++++++++++++++++++++
>  arch/mips/kernel/signal.c           |   2 +-
>  4 files changed, 116 insertions(+), 1 deletion(-)

applied to mips-next.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

      reply	other threads:[~2021-02-13  9:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-12 18:20 [PATCH v2 RESEND] MIPS: Add basic support for ptrace single step Tiezhu Yang
2021-02-13  9:05 ` Thomas Bogendoerfer [this message]

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=20210213090522.GA4330@alpha.franken.de \
    --to=tsbogend@alpha.franken.de \
    --cc=kernelpatch@126.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=lkp@intel.com \
    --cc=oleg@redhat.com \
    --cc=suxingxing@loongson.cn \
    /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