Tiezhu Yang (2):
LoongArch: Only clone and clone3 need to call SAVE_STATIC
LoongArch: No need to call RESTORE_ALL_AND_RET for all syscalls
arch/loongarch/include/asm/stackframe.h | 10 ++++++++++
arch/loongarch/kernel/entry.S | 25 ++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletion(-)
--
2.1.0
In handle_syscall, it is unnecessary to call SAVE_STATIC for all syscalls,
only clone and clone3 need to do this operation, so it is better to check
the syscall number before call SAVE_STATIC.
Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/loongarch/kernel/entry.S | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S
index d5b3dbc..551b6ec 100644
--- a/arch/loongarch/kernel/entry.S
+++ b/arch/loongarch/kernel/entry.S
@@ -14,6 +14,7 @@
#include <asm/regdef.h>
#include <asm/stackframe.h>
#include <asm/thread_info.h>
+#include <asm/unistd.h>
.text
.cfi_sections .debug_frame
@@ -56,8 +57,20 @@ SYM_FUNC_START(handle_syscall)
cfi_st u0, PT_R21
cfi_st fp, PT_R22
+ /*
+ * Syscall number held in a7.
+ * If syscall number is __NR_clone and __NR_clone3, call SAVE_STATIC.
+ */
+ li.w t3, __NR_clone
+ beq a7, t3, 1f
+ li.w t3, __NR_clone3
+ beq a7, t3, 1f
+ b 2f
+
+1:
SAVE_STATIC
+2:
move u0, t0
li.d tp, ~_THREAD_MASK
and tp, tp, sp
--
2.1.0
In handle_syscall, it is unnecessary to call RESTORE_ALL_AND_RET for all
syscalls, clone and clone3 should call RESTORE_STATIC_SOME_AND_RET, and
the other syscalls should call RESTORE_SOME_AND_RET.
Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/loongarch/include/asm/stackframe.h | 10 ++++++++++
arch/loongarch/kernel/entry.S | 12 +++++++++++-
2 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/stackframe.h b/arch/loongarch/include/asm/stackframe.h
index 4ca9530..9869b39 100644
--- a/arch/loongarch/include/asm/stackframe.h
+++ b/arch/loongarch/include/asm/stackframe.h
@@ -216,4 +216,14 @@
RESTORE_SP_AND_RET \docfi
.endm
+ .macro RESTORE_STATIC_SOME_AND_RET docfi=0
+ RESTORE_STATIC \docfi
+ RESTORE_SOME \docfi
+ RESTORE_SP_AND_RET \docfi
+ .endm
+
+ .macro RESTORE_SOME_AND_RET docfi=0
+ RESTORE_SOME \docfi
+ RESTORE_SP_AND_RET \docfi
+ .endm
#endif /* _ASM_STACKFRAME_H */
diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S
index 551b6ec..8176094 100644
--- a/arch/loongarch/kernel/entry.S
+++ b/arch/loongarch/kernel/entry.S
@@ -78,7 +78,17 @@ SYM_FUNC_START(handle_syscall)
move a0, sp
bl do_syscall
- RESTORE_ALL_AND_RET
+ /*
+ * Syscall number held in a7.
+ * If syscall number is __NR_clone and __NR_clone3, call RESTORE_STATIC_SOME_AND_RET.
+ */
+ li.w t3, __NR_clone
+ beq a7, t3, 3f
+ li.w t3, __NR_clone3
+ beq a7, t3, 3f
+ RESTORE_SOME_AND_RET
+3:
+ RESTORE_STATIC_SOME_AND_RET
SYM_FUNC_END(handle_syscall)
SYM_CODE_START(ret_from_fork)
--
2.1.0