Skip to contentSkip to conversation

riscv: compat: signal: Add rt_frame implementation

PATCH Superseded [email protected] 2 participants 3 messages Jan 20, 2022 – Jan 21, 2022

Subsystems (4)

v3 of 12 Superseded Latest is v12 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH v3 13/17 riscv: compat: signal: Add rt_frame implementation

From: Guo Ren <[email protected]>

Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them.

---
 arch/riscv/kernel/Makefile        |   1 +
 arch/riscv/kernel/compat_signal.c | 243 ++++++++++++++++++++++++++++++
 arch/riscv/kernel/signal.c        |  13 +-
 3 files changed, 256 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/kernel/compat_signal.c
arch/riscv/kernel/Makefile +1 -0
index 59cf97faddae..ef47f7d5843f 100644
@@ -66,4 +66,5 @@ obj-$(CONFIG_JUMP_LABEL)	+= jump_label.o
 
 obj-$(CONFIG_EFI)		+= efi.o
 obj-$(CONFIG_COMPAT)		+= compat_syscall_table.o
+obj-$(CONFIG_COMPAT)		+= compat_signal.o
 obj-$(CONFIG_COMPAT)		+= compat_vdso/
arch/riscv/kernel/compat_signal.c new file +243 -0

243 lines not on this page · raw message

arch/riscv/kernel/signal.c +12 -1
index c2d5ecbe5526..27d8f39228c4 100644
@@ -6,6 +6,7 @@
  * Copyright (C) 2012 Regents of the University of California
  */
 
+#include <linux/compat.h>
 #include <linux/signal.h>
 #include <linux/uaccess.h>
 #include <linux/syscalls.h>
@@ -229,6 +230,11 @@ static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
 	return 0;
 }
 
+#ifdef CONFIG_COMPAT
+extern int compat_setup_rt_frame(struct ksignal *ksig, sigset_t *set,
+				 struct pt_regs *regs);
+#endif
+
 static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 {
 	sigset_t *oldset = sigmask_to_save();
@@ -258,8 +264,13 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
 		}
 	}
 
+#ifdef CONFIG_COMPAT
 	/* Set up the stack frame */
-	ret = setup_rt_frame(ksig, oldset, regs);
+	if (is_compat_task())
+		ret = compat_setup_rt_frame(ksig, oldset, regs);
+	else
+#endif
+		ret = setup_rt_frame(ksig, oldset, regs);
 
 	signal_setup_done(ret, ksig, 0);
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 10 lines · On Thu, Jan 20, 2022 at 8:39 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them.

I hope someone else can properly review this part, it's not my area but it looks complex enough that it could bring subtle bugs.

Arnd

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author maintainer
#2 lore raw
Quoted 9 lines · Arnd Bergmann
Quoted 7 lines · On Thu, Jan 20, 2022 at 8:39 AM <[email protected]> wrote:

From: Guo Ren <[email protected]>

Implement compat_setup_rt_frame for sigcontext save & restore. The main process is the same with signal, but the rv32 pt_regs' size is different from rv64's, so we needs convert them.

Quoted 6 lines
Quoted 3 lines

I hope someone else can properly review this part, it's not my area but it looks complex enough that it could bring subtle bugs.

Here are ltp signal test results:

sigaction01                                        PASS       0
sigaction02                                        PASS       0
sigaltstack01                                      PASS       0
sigaltstack02                                      PASS       0
sighold02                                          PASS       0
signal01                                           PASS       0
signal02                                           PASS       0
signal03                                           PASS       0
signal04                                           PASS       0
signal05                                           PASS       0
signal06                                           CONF       32
signalfd01                                         PASS       0
signalfd4_01                                       PASS       0
signalfd4_02                                       PASS       0
sigpending02                                       PASS       0
sigprocmask01                                      PASS       0
sigrelse01                                         PASS       0
sigsuspend01                                       PASS       0
sigtimedwait01                                     PASS       0
sigwait01                                          PASS       0
sigwaitinfo01                                      CONF       32
Quoted 2 lines

Arnd

Signature · 4 lines
Best Regards
 Guo Ren

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