[PATCH] uml: S390 preparation, abstract host page fault data

This patch removes the arch-specific fault/trap-infos from thread and
skas-regs.

It adds a new struct faultinfo, that is arch-specific defined in
sysdep/faultinfo.h.

The structure is inserted in thread.arch and thread.regs.skas and
thread.regs.tt

Now, segv and other trap-handlers can copy the contents from regs.X.faultinfo
to thread.arch.faultinfo with one simple assignment.

Also, the number of macros necessary is reduced to

FAULT_ADDRESS(struct faultinfo)
    extracts the faulting address from faultinfo

FAULT_WRITE(struct faultinfo)
    extracts the "is_write" flag

SEGV_IS_FIXABLE(struct faultinfo)
    is true for the fixable segvs, i.e. (TRAP == 14)
    on i386

UPT_FAULTINFO(regs)
    result is (struct faultinfo *) to the faultinfo
    in regs->skas.faultinfo

GET_FAULTINFO_FROM_SC(struct faultinfo, struct sigcontext *)
    copies the relevant parts of the sigcontext to
    struct faultinfo.

On SIGSEGV, call user_signal() instead of handle_segv(), if the architecture
provides the information needed in PTRACE_FAULTINFO, or if PTRACE_FAULTINFO is
missing, because segv-stub will provide the info.

The benefit of the change is, that in case of a non-fixable SIGSEGV, we can
give user processes a SIGSEGV, instead of possibly looping on pagefault
handling.

Since handle_segv() sikked arch_fixup() implicitly by passing ip==0 to segv(),
I changed segv() to call arch_fixup() only, if !is_user.

Signed-off-by: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
Bodo Stroesser
2005-05-05 16:15:31 -07:00
committed by Linus Torvalds
parent ea66e8a3b6
commit c578455a3e
24 changed files with 279 additions and 115 deletions

View File

@ -252,13 +252,13 @@ long sys_ptrace(long request, long pid, long addr, long data)
break;
#endif
case PTRACE_FAULTINFO: {
struct ptrace_faultinfo fault;
fault = ((struct ptrace_faultinfo)
{ .is_write = child->thread.err,
.addr = child->thread.cr2 });
ret = copy_to_user((unsigned long __user *) data, &fault,
sizeof(fault));
/* Take the info from thread->arch->faultinfo,
* but transfer max. sizeof(struct ptrace_faultinfo).
* On i386, ptrace_faultinfo is smaller!
*/
ret = copy_to_user((unsigned long __user *) data,
&child->thread.arch.faultinfo,
sizeof(struct ptrace_faultinfo));
if(ret)
break;
break;
@ -269,6 +269,7 @@ long sys_ptrace(long request, long pid, long addr, long data)
sizeof(child->pending.signal));
break;
#ifdef PTRACE_LDT
case PTRACE_LDT: {
struct ptrace_ldt ldt;
@ -284,6 +285,7 @@ long sys_ptrace(long request, long pid, long addr, long data)
ret = -EIO;
break;
}
#endif
#ifdef CONFIG_PROC_MM
case PTRACE_SWITCH_MM: {
struct mm_struct *old = child->mm;

View File

@ -27,9 +27,10 @@ extern void map(int fd, unsigned long virt, unsigned long len, int r, int w,
extern int unmap(int fd, void *addr, unsigned long len);
extern int protect(int fd, unsigned long addr, unsigned long len,
int r, int w, int x);
extern void user_signal(int sig, union uml_pt_regs *regs);
extern void user_signal(int sig, union uml_pt_regs *regs, int pid);
extern int new_mm(int from);
extern void start_userspace(int cpu);
extern void get_skas_faultinfo(int pid, struct faultinfo * fi);
extern long execute_syscall_skas(void *r);
#endif

View File

@ -4,6 +4,7 @@
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
@ -37,17 +38,26 @@ int is_skas_winch(int pid, int fd, void *data)
return(1);
}
static void handle_segv(int pid)
void get_skas_faultinfo(int pid, struct faultinfo * fi)
{
struct ptrace_faultinfo fault;
int err;
err = ptrace(PTRACE_FAULTINFO, pid, 0, &fault);
err = ptrace(PTRACE_FAULTINFO, pid, 0, fi);
if(err)
panic("handle_segv - PTRACE_FAULTINFO failed, errno = %d\n",
errno);
panic("get_skas_faultinfo - PTRACE_FAULTINFO failed, "
"errno = %d\n", errno);
segv(fault.addr, 0, FAULT_WRITE(fault.is_write), 1, NULL);
/* Special handling for i386, which has different structs */
if (sizeof(struct ptrace_faultinfo) < sizeof(struct faultinfo))
memset((char *)fi + sizeof(struct ptrace_faultinfo), 0,
sizeof(struct faultinfo) -
sizeof(struct ptrace_faultinfo));
}
static void handle_segv(int pid, union uml_pt_regs * regs)
{
get_skas_faultinfo(pid, &regs->skas.faultinfo);
segv(regs->skas.faultinfo, 0, 1, NULL);
}
/*To use the same value of using_sysemu as the caller, ask it that value (in local_using_sysemu)*/
@ -163,7 +173,7 @@ void userspace(union uml_pt_regs *regs)
if(WIFSTOPPED(status)){
switch(WSTOPSIG(status)){
case SIGSEGV:
handle_segv(pid);
handle_segv(pid, regs);
break;
case SIGTRAP + 0x80:
handle_trap(pid, regs, local_using_sysemu);
@ -177,7 +187,7 @@ void userspace(union uml_pt_regs *regs)
case SIGBUS:
case SIGFPE:
case SIGWINCH:
user_signal(WSTOPSIG(status), regs);
user_signal(WSTOPSIG(status), regs, pid);
break;
default:
printk("userspace - child stopped with signal "

View File

@ -5,12 +5,15 @@
#include <signal.h>
#include <errno.h>
#include "sysdep/ptrace.h"
#include "signal_user.h"
#include "user_util.h"
#include "kern_util.h"
#include "task.h"
#include "sigcontext.h"
#include "skas.h"
#include "ptrace_user.h"
#include "sysdep/ptrace.h"
#include "sysdep/ptrace_user.h"
void sig_handler_common_skas(int sig, void *sc_ptr)
{
@ -31,9 +34,11 @@ void sig_handler_common_skas(int sig, void *sc_ptr)
r = &TASK_REGS(get_current())->skas;
save_user = r->is_user;
r->is_user = 0;
r->fault_addr = SC_FAULT_ADDR(sc);
r->fault_type = SC_FAULT_TYPE(sc);
r->trap_type = SC_TRAP_TYPE(sc);
if ( sig == SIGFPE || sig == SIGSEGV ||
sig == SIGBUS || sig == SIGILL ||
sig == SIGTRAP ) {
GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
}
change_sig(SIGUSR1, 1);
info = &sig_info[sig];
@ -45,14 +50,17 @@ void sig_handler_common_skas(int sig, void *sc_ptr)
r->is_user = save_user;
}
void user_signal(int sig, union uml_pt_regs *regs)
extern int ptrace_faultinfo;
void user_signal(int sig, union uml_pt_regs *regs, int pid)
{
struct signal_info *info;
int segv = ((sig == SIGFPE) || (sig == SIGSEGV) || (sig == SIGBUS) ||
(sig == SIGILL) || (sig == SIGTRAP));
regs->skas.is_user = 1;
regs->skas.fault_addr = 0;
regs->skas.fault_type = 0;
regs->skas.trap_type = 0;
if (segv)
get_skas_faultinfo(pid, &regs->skas.faultinfo);
info = &sig_info[sig];
(*info->handler)(sig, regs);

View File

@ -133,12 +133,19 @@ static int check_remapped_addr(unsigned long address, int is_write)
return(0);
}
unsigned long segv(unsigned long address, unsigned long ip, int is_write,
int is_user, void *sc)
/*
* We give a *copy* of the faultinfo in the regs to segv.
* This must be done, since nesting SEGVs could overwrite
* the info in the regs. A pointer to the info then would
* give us bad data!
*/
unsigned long segv(struct faultinfo fi, unsigned long ip, int is_user, void *sc)
{
struct siginfo si;
void *catcher;
int err;
int is_write = FAULT_WRITE(fi);
unsigned long address = FAULT_ADDRESS(fi);
if(!is_user && (address >= start_vm) && (address < end_vm)){
flush_tlb_kernel_vm();
@ -159,7 +166,7 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
}
else if(current->thread.fault_addr != NULL)
panic("fault_addr set but no fault catcher");
else if(arch_fixup(ip, sc))
else if(!is_user && arch_fixup(ip, sc))
return(0);
if(!is_user)
@ -171,6 +178,7 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
si.si_errno = 0;
si.si_code = BUS_ADRERR;
si.si_addr = (void *)address;
current->thread.arch.faultinfo = fi;
force_sig_info(SIGBUS, &si, current);
}
else if(err == -ENOMEM){
@ -180,22 +188,20 @@ unsigned long segv(unsigned long address, unsigned long ip, int is_write,
else {
si.si_signo = SIGSEGV;
si.si_addr = (void *) address;
current->thread.cr2 = address;
current->thread.err = is_write;
current->thread.arch.faultinfo = fi;
force_sig_info(SIGSEGV, &si, current);
}
return(0);
}
void bad_segv(unsigned long address, unsigned long ip, int is_write)
void bad_segv(struct faultinfo fi, unsigned long ip)
{
struct siginfo si;
si.si_signo = SIGSEGV;
si.si_code = SEGV_ACCERR;
si.si_addr = (void *) address;
current->thread.cr2 = address;
current->thread.err = is_write;
si.si_addr = (void *) FAULT_ADDRESS(fi);
current->thread.arch.faultinfo = fi;
force_sig_info(SIGSEGV, &si, current);
}
@ -204,6 +210,7 @@ void relay_signal(int sig, union uml_pt_regs *regs)
if(arch_handle_signal(sig, regs)) return;
if(!UPT_IS_USER(regs))
panic("Kernel mode signal %d", sig);
current->thread.arch.faultinfo = *UPT_FAULTINFO(regs);
force_sig(sig, current);
}

View File

@ -54,23 +54,22 @@ struct {
void segv_handler(int sig, union uml_pt_regs *regs)
{
int index, max;
struct faultinfo * fi = UPT_FAULTINFO(regs);
if(UPT_IS_USER(regs) && !UPT_SEGV_IS_FIXABLE(regs)){
bad_segv(UPT_FAULT_ADDR(regs), UPT_IP(regs),
UPT_FAULT_WRITE(regs));
if(UPT_IS_USER(regs) && !SEGV_IS_FIXABLE(fi)){
bad_segv(*fi, UPT_IP(regs));
return;
}
max = sizeof(segfault_record)/sizeof(segfault_record[0]);
index = next_trap_index(max);
nsegfaults++;
segfault_record[index].address = UPT_FAULT_ADDR(regs);
segfault_record[index].address = FAULT_ADDRESS(*fi);
segfault_record[index].pid = os_getpid();
segfault_record[index].is_write = UPT_FAULT_WRITE(regs);
segfault_record[index].is_write = FAULT_WRITE(*fi);
segfault_record[index].sp = UPT_SP(regs);
segfault_record[index].is_user = UPT_IS_USER(regs);
segv(UPT_FAULT_ADDR(regs), UPT_IP(regs), UPT_FAULT_WRITE(regs),
UPT_IS_USER(regs), regs);
segv(*fi, UPT_IP(regs), UPT_IS_USER(regs), regs);
}
void usr2_handler(int sig, union uml_pt_regs *regs)

View File

@ -89,8 +89,10 @@ void tracer_panic(char *format, ...)
static void tracer_segv(int sig, struct sigcontext sc)
{
struct faultinfo fi;
GET_FAULTINFO_FROM_SC(fi, &sc);
printf("Tracing thread segfault at address 0x%lx, ip 0x%lx\n",
SC_FAULT_ADDR(&sc), SC_IP(&sc));
FAULT_ADDRESS(fi), SC_IP(&sc));
while(1)
pause();
}

View File

@ -7,6 +7,7 @@
#include <errno.h>
#include <signal.h>
#include "sysdep/ptrace.h"
#include "sysdep/sigcontext.h"
#include "signal_user.h"
#include "user_util.h"
#include "kern_util.h"
@ -28,6 +29,11 @@ void sig_handler_common_tt(int sig, void *sc_ptr)
change_sig(SIGSEGV, 1);
r = &TASK_REGS(get_current())->tt;
if ( sig == SIGFPE || sig == SIGSEGV ||
sig == SIGBUS || sig == SIGILL ||
sig == SIGTRAP ) {
GET_FAULTINFO_FROM_SC(r->faultinfo, sc);
}
save_regs = *r;
is_user = user_context(SC_SP(sc));
r->sc = sc;