Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3581039 authored by Vineet Gupta's avatar Vineet Gupta
Browse files

ARC: Signal handling



Includes following fixes courtesy review by Al-Viro

* Tracer poke to Callee-regs were lost

  Before going off into do_signal( ) we save the user-mode callee regs
  (as they are not saved by default as part of pt_regs). This is to make
  sure that that a Tracer (if tracing related signal) is able to do likes
  of PEEKUSR(callee-reg).

  However in return path we were simply discarding the user-mode callee
  regs, which would break a POKEUSR(callee-reg) from a tracer.

* Issue related to multiple syscall restarts are addressed in next patch

Signed-off-by: default avatarVineet Gupta <vgupta@synopsys.com>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Acked-by: default avatarJonas Bonn <jonas@southpole.se>
parent d8005e6b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ config ARC
	select GENERIC_KERNEL_EXECVE
	select GENERIC_KERNEL_THREAD
	select GENERIC_PENDING_IRQ if SMP
	select GENERIC_SIGALTSTACK
	select GENERIC_SMP_IDLE_THREAD
	select HAVE_GENERIC_HARDIRQS
	select MODULES_USE_ELF_RELA
+35 −0
Original line number Diff line number Diff line
@@ -165,6 +165,41 @@

.endm

/*--------------------------------------------------------------
 * RESTORE_CALLEE_SAVED_USER:
 * This is called after do_signal where tracer might have changed callee regs
 * thus we need to restore the reg file.
 * Special case handling is required for r25 in case it is used by kernel
 *  for caching task ptr. Ptrace would have modified on-kernel-stack value of
 *  r25, which needs to be shoved back into task->thread.user_r25 where from
 *  Low level exception/ISR return code will retrieve to populate with rest of
 *  callee reg-file.
 *-------------------------------------------------------------*/
.macro RESTORE_CALLEE_SAVED_USER

	add     sp, sp, 4   /* skip "callee_regs->stack_place_holder" */

#ifdef CONFIG_ARC_CURR_IN_REG
	ld.ab   r12, [sp, 4]
	st      r12, [r25, TASK_THREAD + THREAD_USER_R25]
#else
	ld.ab   r25, [sp, 4]
#endif

	ld.ab   r24, [sp, 4]
	ld.ab   r23, [sp, 4]
	ld.ab   r22, [sp, 4]
	ld.ab   r21, [sp, 4]
	ld.ab   r20, [sp, 4]
	ld.ab   r19, [sp, 4]
	ld.ab   r18, [sp, 4]
	ld.ab   r17, [sp, 4]
	ld.ab   r16, [sp, 4]
	ld.ab   r15, [sp, 4]
	ld.ab   r14, [sp, 4]
	ld.ab   r13, [sp, 4]
.endm

/*--------------------------------------------------------------
 * Super FAST Restore callee saved regs by simply re-adjusting SP
 *-------------------------------------------------------------*/
+22 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

#ifndef _ASM_ARC_SIGCONTEXT_H
#define _ASM_ARC_SIGCONTEXT_H

#include <asm/ptrace.h>

/*
 * Signal context structure - contains all info to do with the state
 * before the signal handler was invoked.
 */
struct sigcontext {
	struct user_regs_struct regs;
};

#endif /* _ASM_ARC_SIGCONTEXT_H */
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
 */

#ifndef _ASM_ARC_SIGNAL_H
#define _ASM_ARC_SIGNAL_H

/*
 * This is much needed for ARC sigreturn optimization.
 * This allows uClibc to piggback the addr of a sigreturn stub in sigaction,
 * which allows sigreturn based re-entry into kernel after handling signal.
 * W/o this kernel needs to "synthesize" the sigreturn trampoline on user
 * mode stack which in turn forces the following:
 * -TLB Flush (after making the stack page executable)
 * -Cache line Flush (to make I/D Cache lines coherent)
 */
#define SA_RESTORER	0x04000000

#include <asm-generic/signal.h>

#endif /* _ASM_ARC_SIGNAL_H */
+8 −3
Original line number Diff line number Diff line
@@ -470,7 +470,11 @@ resume_user_mode_begin:

	bbit0  r9, TIF_SIGPENDING, .Lchk_notify_resume

	; save CALLEE Regs.
	; Normal Trap/IRQ entry only saves Scratch (caller-saved) regs
	; in pt_reg since the "C" ABI (kernel code) will automatically
	; save/restore callee-saved regs.
	;
	; However, here we need to explicitly save callee regs because
	; (i)  If this signal causes coredump - full regfile needed
	; (ii) If signal is SIGTRAP/SIGSTOP, task is being traced thus
	;      tracer might call PEEKUSR(CALLEE reg)
@@ -484,8 +488,9 @@ resume_user_mode_begin:

	bl  @do_signal

	; unwind SP for cheap discard of Callee saved Regs
	DISCARD_CALLEE_SAVED_USER
	; Ideally we want to discard the Callee reg above, however if this was
	; a tracing signal, tracer could have done a POKEUSR(CALLEE reg)
	RESTORE_CALLEE_SAVED_USER

	b      resume_user_mode_begin	; loop back to start of U mode ret

Loading