<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/arch/mips/include/asm/ptrace.h, branch linux-rolling-stable</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-rolling-stable</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-rolling-stable'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2025-05-18T06:26:07Z</updated>
<entry>
<title>MIPS: Fix MAX_REG_OFFSET</title>
<updated>2025-05-18T06:26:07Z</updated>
<author>
<name>Thorsten Blum</name>
<email>thorsten.blum@linux.dev</email>
</author>
<published>2025-04-27T11:34:24Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=5a9c892814b17bf3b4c95edcc24f0d01c8b278a6'/>
<id>urn:sha1:5a9c892814b17bf3b4c95edcc24f0d01c8b278a6</id>
<content type='text'>
[ Upstream commit c44572e0cc13c9afff83fd333135a0aa9b27ba26 ]

Fix MAX_REG_OFFSET to point to the last register in 'pt_regs' and not to
the marker itself, which could allow regs_get_register() to return an
invalid offset.

Fixes: 40e084a506eb ("MIPS: Add uprobes support.")
Suggested-by: Maciej W. Rozycki &lt;macro@orcam.me.uk&gt;
Signed-off-by: Thorsten Blum &lt;thorsten.blum@linux.dev&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>MIPS: Export syscall stack arguments properly for remote use</title>
<updated>2025-02-13T11:41:18Z</updated>
<author>
<name>Maciej W. Rozycki</name>
<email>macro@orcam.me.uk</email>
</author>
<published>2025-02-11T18:22:30Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=ed975485a13d1f6080218aa71c29425ba2dfb332'/>
<id>urn:sha1:ed975485a13d1f6080218aa71c29425ba2dfb332</id>
<content type='text'>
We have several places across the kernel where we want to access another
task's syscall arguments, such as ptrace(2), seccomp(2), etc., by making
a call to syscall_get_arguments().

This works for register arguments right away by accessing the task's
`regs' member of `struct pt_regs', however for stack arguments seen with
32-bit/o32 kernels things are more complicated.  Technically they ought
to be obtained from the user stack with calls to an access_remote_vm(),
but we have an easier way available already.

So as to be able to access syscall stack arguments as regular function
arguments following the MIPS calling convention we copy them over from
the user stack to the kernel stack in arch/mips/kernel/scall32-o32.S, in
handle_sys(), to the current stack frame's outgoing argument space at
the top of the stack, which is where the handler called expects to see
its incoming arguments.  This area is also pointed at by the `pt_regs'
pointer obtained by task_pt_regs().

Make the o32 stack argument space a proper member of `struct pt_regs'
then, by renaming the existing member from `pad0' to `args' and using
generated offsets to access the space.  No functional change though.

With the change in place the o32 kernel stack frame layout at the entry
to a syscall handler invoked by handle_sys() is therefore as follows:

$sp + 68 -&gt; |         ...         | &lt;- pt_regs.regs[9]
            +---------------------+
$sp + 64 -&gt; |         $t0         | &lt;- pt_regs.regs[8]
            +---------------------+
$sp + 60 -&gt; |   $a3/argument #4   | &lt;- pt_regs.regs[7]
            +---------------------+
$sp + 56 -&gt; |   $a2/argument #3   | &lt;- pt_regs.regs[6]
            +---------------------+
$sp + 52 -&gt; |   $a1/argument #2   | &lt;- pt_regs.regs[5]
            +---------------------+
$sp + 48 -&gt; |   $a0/argument #1   | &lt;- pt_regs.regs[4]
            +---------------------+
$sp + 44 -&gt; |         $v1         | &lt;- pt_regs.regs[3]
            +---------------------+
$sp + 40 -&gt; |         $v0         | &lt;- pt_regs.regs[2]
            +---------------------+
$sp + 36 -&gt; |         $at         | &lt;- pt_regs.regs[1]
            +---------------------+
$sp + 32 -&gt; |        $zero        | &lt;- pt_regs.regs[0]
            +---------------------+
$sp + 28 -&gt; |  stack argument #8  | &lt;- pt_regs.args[7]
            +---------------------+
$sp + 24 -&gt; |  stack argument #7  | &lt;- pt_regs.args[6]
            +---------------------+
$sp + 20 -&gt; |  stack argument #6  | &lt;- pt_regs.args[5]
            +---------------------+
$sp + 16 -&gt; |  stack argument #5  | &lt;- pt_regs.args[4]
            +---------------------+
$sp + 12 -&gt; | psABI space for $a3 | &lt;- pt_regs.args[3]
            +---------------------+
$sp +  8 -&gt; | psABI space for $a2 | &lt;- pt_regs.args[2]
            +---------------------+
$sp +  4 -&gt; | psABI space for $a1 | &lt;- pt_regs.args[1]
            +---------------------+
$sp +  0 -&gt; | psABI space for $a0 | &lt;- pt_regs.args[0]
            +---------------------+

holding user data received and with the first 4 frame slots reserved by
the psABI for the compiler to spill the incoming arguments from $a0-$a3
registers (which it sometimes does according to its needs) and the next
4 frame slots designated by the psABI for any stack function arguments
that follow.  This data is also available for other tasks to peek/poke
at as reqired and where permitted.

Signed-off-by: Maciej W. Rozycki &lt;macro@orcam.me.uk&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>MIPS: scall: Save thread_info.syscall unconditionally on entry</title>
<updated>2024-04-09T14:52:21Z</updated>
<author>
<name>Jiaxun Yang</name>
<email>jiaxun.yang@flygoat.com</email>
</author>
<published>2024-03-28T14:27:56Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=4370b673ccf240bf7587b0cb8e6726a5ccaf1f17'/>
<id>urn:sha1:4370b673ccf240bf7587b0cb8e6726a5ccaf1f17</id>
<content type='text'>
thread_info.syscall is used by syscall_get_nr to supply syscall nr
over a thread stack frame.

Previously, thread_info.syscall is only saved at syscall_trace_enter
when syscall tracing is enabled. However rest of the kernel code do
expect syscall_get_nr to be available without syscall tracing. The
previous design breaks collect_syscall.

Move saving process to syscall entry to fix it.

Reported-by: Xi Ruoyao &lt;xry111@xry111.site&gt;
Link: https://github.com/util-linux/util-linux/issues/2867
Signed-off-by: Jiaxun Yang &lt;jiaxun.yang@flygoat.com&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>MIPS: Clear Cause.BD in instruction_pointer_set</title>
<updated>2024-02-12T22:04:40Z</updated>
<author>
<name>Jiaxun Yang</name>
<email>jiaxun.yang@flygoat.com</email>
</author>
<published>2024-02-02T12:30:27Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=9d6e21ddf20293b3880ae55b9d14de91c5891c59'/>
<id>urn:sha1:9d6e21ddf20293b3880ae55b9d14de91c5891c59</id>
<content type='text'>
Clear Cause.BD after we use instruction_pointer_set to override
EPC.

This can prevent exception_epc check against instruction code at
new return address.
It won't be considered as "in delay slot" after epc being overridden
anyway.

Signed-off-by: Jiaxun Yang &lt;jiaxun.yang@flygoat.com&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>ptrace: Introduce exception_ip arch hook</title>
<updated>2024-02-12T22:04:34Z</updated>
<author>
<name>Jiaxun Yang</name>
<email>jiaxun.yang@flygoat.com</email>
</author>
<published>2024-02-02T12:30:26Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=11ba1728be3edb6928791f4c622f154ebe228ae6'/>
<id>urn:sha1:11ba1728be3edb6928791f4c622f154ebe228ae6</id>
<content type='text'>
On architectures with delay slot, architecture level instruction
pointer (or program counter) in pt_regs may differ from where
exception was triggered.

Introduce exception_ip hook to invoke architecture code and determine
actual instruction pointer to the exception.

Link: https://lore.kernel.org/lkml/00d1b813-c55f-4365-8d81-d70258e10b16@app.fastmail.com/
Signed-off-by: Jiaxun Yang &lt;jiaxun.yang@flygoat.com&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>Revert "MIPS: Add basic support for ptrace single step"</title>
<updated>2021-02-18T10:57:44Z</updated>
<author>
<name>Thomas Bogendoerfer</name>
<email>tsbogend@alpha.franken.de</email>
</author>
<published>2021-02-18T10:57:44Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=b0c2793bad0b5f10be2fc5f56df827e0c1bbf4af'/>
<id>urn:sha1:b0c2793bad0b5f10be2fc5f56df827e0c1bbf4af</id>
<content type='text'>
This reverts commit 7c86ff9925cbc83e8a21f164a8fdc2767e03531e.

There are too many special cases for MIPS not covered by this patch.
In the end it might be better to implement single stepping in userland
than emulating it in the kernel.

Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>MIPS: Add basic support for ptrace single step</title>
<updated>2021-02-13T08:49:19Z</updated>
<author>
<name>Tiezhu Yang</name>
<email>yangtiezhu@loongson.cn</email>
</author>
<published>2021-02-12T18:20:46Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=7c86ff9925cbc83e8a21f164a8fdc2767e03531e'/>
<id>urn:sha1:7c86ff9925cbc83e8a21f164a8fdc2767e03531e</id>
<content type='text'>
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 &lt;chenguoqi@loongson.cn&gt;
Signed-off-by: Xingxing Su &lt;suxingxing@loongson.cn&gt;
Signed-off-by: Tiezhu Yang &lt;yangtiezhu@loongson.cn&gt;
Reported-by: kernel test robot &lt;lkp@intel.com&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>MIPS: fix kernel_stack_pointer()</title>
<updated>2021-02-03T10:32:52Z</updated>
<author>
<name>Huang Pei</name>
<email>huangpei@loongson.cn</email>
</author>
<published>2021-01-29T04:35:07Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=a78ddac1bc22bd7a47fbec06c9c4ef4312ba71cf'/>
<id>urn:sha1:a78ddac1bc22bd7a47fbec06c9c4ef4312ba71cf</id>
<content type='text'>
MIPS always save kernel stack pointer in regs[29]

Signed-off-by: Huang Pei &lt;huangpei@loongson.cn&gt;
Signed-off-by: Thomas Bogendoerfer &lt;tsbogend@alpha.franken.de&gt;
</content>
</entry>
<entry>
<title>asm-generic: remove ptrace.h</title>
<updated>2019-07-01T15:51:40Z</updated>
<author>
<name>Christoph Hellwig</name>
<email>hch@lst.de</email>
</author>
<published>2019-06-24T05:47:28Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=7f3a8dff1219fba3076fe207972d1d7893c099bb'/>
<id>urn:sha1:7f3a8dff1219fba3076fe207972d1d7893c099bb</id>
<content type='text'>
No one is using this header anymore.

Signed-off-by: Christoph Hellwig &lt;hch@lst.de&gt;
Acked-by: Arnd Bergmann &lt;arnd@arndb.de&gt;
Acked-by: Oleg Nesterov &lt;oleg@redhat.com&gt;
Acked-by: Paul Burton &lt;paul.burton@mips.com&gt;
Signed-off-by: Arnd Bergmann &lt;arnd@arndb.de&gt;
</content>
</entry>
<entry>
<title>MIPS: ptrace: Fix regs_return_value for kernel context</title>
<updated>2016-10-12T12:34:45Z</updated>
<author>
<name>Marcin Nowakowski</name>
<email>marcin.nowakowski@imgtec.com</email>
</author>
<published>2016-10-12T07:32:56Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=74f1077b5b783e7bf4fa3007cefdc8dbd6c07518'/>
<id>urn:sha1:74f1077b5b783e7bf4fa3007cefdc8dbd6c07518</id>
<content type='text'>
Currently regs_return_value always negates reg[2] if it determines
the syscall has failed, but when called in kernel context this check is
invalid and may result in returning a wrong value.

This fixes errors reported by CONFIG_KPROBES_SANITY_TEST

Fixes: d7e7528bcd45 ("Audit: push audit success and retcode into arch ptrace.h")
Signed-off-by: Marcin Nowakowski &lt;marcin.nowakowski@imgtec.com&gt;
Cc: linux-mips@linux-mips.org
Cc: stable@vger.kernel.org # 3.3+
Patchwork: https://patchwork.linux-mips.org/patch/14381/
Signed-off-by: Ralf Baechle &lt;ralf@linux-mips.org&gt;
</content>
</entry>
</feed>
