[PATCH RFC 8/8] tile: implement syscall restart generically

From: Jonas Bonn
Date: Sun Oct 23 2011 - 06:20:46 EST



Manipulating task state to effect re-execution of an interrupted syscall
used to be purely architecture specific code. However, as most arch's
were essentially just making minor adjustments to almost identical logic,
this code could be moved to a common implementation.

The generic variant introduces the function handle_syscall_restart() to be
called after get_signal_to_deliver(). The architecture specific register
manipulations required to effect the actual restart are now implemented
in the generic syscall interface found in asm/syscall.h

This patch transitions this architecture's signal handling code over to
using the generic syscall restart code by:

i) Implementing the register manipulations in asm/syscall.h
ii) Replacing the restart logic with a call to handle_syscall_restart

Cc: Chris Metcalf <cmetcalf@xxxxxxxxxx>
Signed-off-by: Jonas Bonn <jonas@xxxxxxxxxxxx>
---
arch/tile/include/asm/syscall.h | 28 ++++++++++++++++++++-
arch/tile/kernel/signal.c | 52 +++------------------------------------
2 files changed, 31 insertions(+), 49 deletions(-)

diff --git a/arch/tile/include/asm/syscall.h b/arch/tile/include/asm/syscall.h
index d35e0dc..428e28c 100644
--- a/arch/tile/include/asm/syscall.h
+++ b/arch/tile/include/asm/syscall.h
@@ -21,6 +21,7 @@
#include <linux/sched.h>
#include <linux/err.h>
#include <arch/abi.h>
+#include <asm/unistd.h>

/*
* Only the low 32 bits of orig_r0 are meaningful, so we return int.
@@ -29,15 +30,40 @@
*/
static inline int syscall_get_nr(struct task_struct *t, struct pt_regs *regs)
{
- return regs->regs[TREG_SYSCALL_NR];
+ if (regs->faultnum == INT_SWINT_1)
+ return regs->regs[TREG_SYSCALL_NR];
+ else
+ return -1;
}

static inline void syscall_rollback(struct task_struct *task,
struct pt_regs *regs)
{
+ regs->flags |= PT_FLAGS_CALLER_SAVES;
regs->regs[0] = regs->orig_r0;
}

+static inline void
+syscall_clear(struct task_struct *task, struct pt_regs *regs)
+{
+ regs->faultnum = INT_SWINT_1_SIGRETURN;
+}
+
+static inline void
+syscall_restart(struct task_struct *task, struct pt_regs *regs)
+{
+ syscall_rollback(task, regs);
+ regs->pc -= 8;
+}
+
+static inline void
+syscall_do_restartblock(struct task_struct *task, struct pt_regs *regs)
+{
+ regs->flags |= PT_FLAGS_CALLER_SAVES;
+ regs->gpr[TREG_SYSCALL_NR] = __NR_restart_syscall;
+ regs->pc -= 8;
+}
+
static inline long syscall_get_error(struct task_struct *task,
struct pt_regs *regs)
{
diff --git a/arch/tile/kernel/signal.c b/arch/tile/kernel/signal.c
index bedaf4e..ab1f4e7 100644
--- a/arch/tile/kernel/signal.c
+++ b/arch/tile/kernel/signal.c
@@ -251,29 +251,6 @@ static int handle_signal(unsigned long sig, siginfo_t *info,
{
int ret;

- /* Are we from a system call? */
- if (regs->faultnum == INT_SWINT_1) {
- /* If so, check system call restarting.. */
- switch (regs->regs[0]) {
- case -ERESTART_RESTARTBLOCK:
- case -ERESTARTNOHAND:
- regs->regs[0] = -EINTR;
- break;
-
- case -ERESTARTSYS:
- if (!(ka->sa.sa_flags & SA_RESTART)) {
- regs->regs[0] = -EINTR;
- break;
- }
- /* fallthrough */
- case -ERESTARTNOINTR:
- /* Reload caller-saves to restore r0..r5 and r10. */
- regs->flags |= PT_FLAGS_CALLER_SAVES;
- regs->regs[0] = regs->orig_r0;
- regs->pc -= 8;
- }
- }
-
/* Set up the stack frame */
#ifdef CONFIG_COMPAT
if (is_compat_task())
@@ -323,6 +300,9 @@ void do_signal(struct pt_regs *regs)
oldset = &current->blocked;

signr = get_signal_to_deliver(&info, &ka, regs, NULL);
+
+ handle_syscall_restart(regs, &ka, (signr > 0));
+
if (signr > 0) {
/* Whee! Actually deliver the signal. */
if (handle_signal(signr, &info, &ka, oldset, regs) == 0) {
@@ -335,27 +315,7 @@ void do_signal(struct pt_regs *regs)
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
}

- goto done;
- }
-
- /* Did we come from a system call? */
- if (regs->faultnum == INT_SWINT_1) {
- /* Restart the system call - no handlers present */
- switch (regs->regs[0]) {
- case -ERESTARTNOHAND:
- case -ERESTARTSYS:
- case -ERESTARTNOINTR:
- regs->flags |= PT_FLAGS_CALLER_SAVES;
- regs->regs[0] = regs->orig_r0;
- regs->pc -= 8;
- break;
-
- case -ERESTART_RESTARTBLOCK:
- regs->flags |= PT_FLAGS_CALLER_SAVES;
- regs->regs[TREG_SYSCALL_NR] = __NR_restart_syscall;
- regs->pc -= 8;
- break;
- }
+ return;
}

/* If there's no signal to deliver, just put the saved sigmask back. */
@@ -363,10 +323,6 @@ void do_signal(struct pt_regs *regs)
current_thread_info()->status &= ~TS_RESTORE_SIGMASK;
sigprocmask(SIG_SETMASK, &current->saved_sigmask, NULL);
}
-
-done:
- /* Avoid double syscall restart if there are nested signals. */
- regs->faultnum = INT_SWINT_1_SIGRETURN;
}

int show_unhandled_signals = 1;
--
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/