Skip to content

Commit

Permalink
[PATCH] uml: S390 preparation, abstract host page fault data
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bodo Stroesser authored and Linus Torvalds committed May 5, 2005
1 parent ea66e8a commit c578455
Show file tree
Hide file tree
Showing 24 changed files with 279 additions and 115 deletions.
7 changes: 4 additions & 3 deletions arch/um/include/kern_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "linux/threads.h"
#include "sysdep/ptrace.h"
#include "sysdep/faultinfo.h"

extern int ncpus;
extern char *linux_prog;
Expand All @@ -31,8 +32,8 @@ extern int current_pid(void);
extern unsigned long alloc_stack(int order, int atomic);
extern int do_signal(void);
extern int is_stack_fault(unsigned long sp);
extern unsigned long segv(unsigned long address, unsigned long ip,
int is_write, int is_user, void *sc);
extern unsigned long segv(struct faultinfo fi, unsigned long ip,
int is_user, void *sc);
extern int handle_page_fault(unsigned long address, unsigned long ip,
int is_write, int is_user, int *code_out);
extern void syscall_ready(void);
Expand Down Expand Up @@ -82,7 +83,7 @@ extern void timer_irq(union uml_pt_regs *regs);
extern void unprotect_stack(unsigned long stack);
extern void do_uml_exitcalls(void);
extern int attach_debugger(int idle_pid, int pid, int stop);
extern void bad_segv(unsigned long address, unsigned long ip, int is_write);
extern void bad_segv(struct faultinfo fi, unsigned long ip);
extern int config_gdb(char *str);
extern int remove_gdb(void);
extern char *uml_strdup(char *string);
Expand Down
29 changes: 29 additions & 0 deletions arch/um/include/sysdep-i386/faultinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2004 Fujitsu Siemens Computers GmbH
* Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
* Licensed under the GPL
*/

#ifndef __FAULTINFO_I386_H
#define __FAULTINFO_I386_H

/* this structure contains the full arch-specific faultinfo
* from the traps.
* On i386, ptrace_faultinfo unfortunately doesn't provide
* all the info, since trap_no is missing.
* All common elements are defined at the same position in
* both structures, thus making it easy to copy the
* contents without knowledge about the structure elements.
*/
struct faultinfo {
int error_code; /* in ptrace_faultinfo misleadingly called is_write */
unsigned long cr2; /* in ptrace_faultinfo called addr */
int trap_no; /* missing in ptrace_faultinfo */
};

#define FAULT_WRITE(fi) ((fi).error_code & 2)
#define FAULT_ADDRESS(fi) ((fi).cr2)

#define PTRACE_FULL_FAULTINFO 0

#endif
23 changes: 5 additions & 18 deletions arch/um/include/sysdep-i386/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ extern int sysemu_supported;
#ifdef UML_CONFIG_MODE_SKAS

#include "skas_ptregs.h"
#include "sysdep/faultinfo.h"

#define REGS_IP(r) ((r)[HOST_IP])
#define REGS_SP(r) ((r)[HOST_SP])
Expand All @@ -53,12 +54,6 @@ extern int sysemu_supported;

#define REGS_RESTART_SYSCALL(r) IP_RESTART_SYSCALL(REGS_IP(r))

#define REGS_SEGV_IS_FIXABLE(r) SEGV_IS_FIXABLE((r)->trap_type)

#define REGS_FAULT_ADDR(r) ((r)->fault_addr)

#define REGS_FAULT_WRITE(r) FAULT_WRITE((r)->fault_type)

#endif
#ifndef PTRACE_SYSEMU_SINGLESTEP
#define PTRACE_SYSEMU_SINGLESTEP 32
Expand All @@ -71,16 +66,15 @@ union uml_pt_regs {
struct tt_regs {
long syscall;
void *sc;
struct faultinfo faultinfo;
} tt;
#endif
#ifdef UML_CONFIG_MODE_SKAS
struct skas_regs {
unsigned long regs[HOST_FRAME_SIZE];
unsigned long fp[HOST_FP_SIZE];
unsigned long xfp[HOST_XFP_SIZE];
unsigned long fault_addr;
unsigned long fault_type;
unsigned long trap_type;
struct faultinfo faultinfo;
long syscall;
int is_user;
} skas;
Expand Down Expand Up @@ -217,15 +211,8 @@ struct syscall_args {
#define UPT_SYSCALL_NR(r) UPT_ORIG_EAX(r)
#define UPT_SYSCALL_RET(r) UPT_EAX(r)

#define UPT_SEGV_IS_FIXABLE(r) \
CHOOSE_MODE(SC_SEGV_IS_FIXABLE(UPT_SC(r)), \
REGS_SEGV_IS_FIXABLE(&r->skas))

#define UPT_FAULT_ADDR(r) \
__CHOOSE_MODE(SC_FAULT_ADDR(UPT_SC(r)), REGS_FAULT_ADDR(&r->skas))

#define UPT_FAULT_WRITE(r) \
CHOOSE_MODE(SC_FAULT_WRITE(UPT_SC(r)), REGS_FAULT_WRITE(&r->skas))
#define UPT_FAULTINFO(r) \
CHOOSE_MODE((&(r)->tt.faultinfo), (&(r)->skas.faultinfo))

#endif

Expand Down
19 changes: 7 additions & 12 deletions arch/um/include/sysdep-i386/sigcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,20 @@
#define SC_RESTART_SYSCALL(sc) IP_RESTART_SYSCALL(SC_IP(sc))
#define SC_SET_SYSCALL_RETURN(sc, result) SC_EAX(sc) = (result)

#define SC_FAULT_ADDR(sc) SC_CR2(sc)
#define SC_FAULT_TYPE(sc) SC_ERR(sc)

#define FAULT_WRITE(err) (err & 2)
#define TO_SC_ERR(is_write) ((is_write) ? 2 : 0)

#define SC_FAULT_WRITE(sc) (FAULT_WRITE(SC_ERR(sc)))

#define SC_TRAP_TYPE(sc) SC_TRAPNO(sc)
#define GET_FAULTINFO_FROM_SC(fi,sc) \
{ \
(fi).cr2 = SC_CR2(sc); \
(fi).error_code = SC_ERR(sc); \
(fi).trap_no = SC_TRAPNO(sc); \
}

/* ptrace expects that, at the start of a system call, %eax contains
* -ENOSYS, so this makes it so.
*/
#define SC_START_SYSCALL(sc) do SC_EAX(sc) = -ENOSYS; while(0)

/* This is Page Fault */
#define SEGV_IS_FIXABLE(trap) (trap == 14)

#define SC_SEGV_IS_FIXABLE(sc) (SEGV_IS_FIXABLE(SC_TRAPNO(sc)))
#define SEGV_IS_FIXABLE(fi) ((fi)->trap_no == 14)

extern unsigned long *sc_sigmask(void *sc_ptr);
extern int sc_get_fpregs(unsigned long buf, void *sc_ptr);
Expand Down
22 changes: 22 additions & 0 deletions arch/um/include/sysdep-i386/skas_ptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/

#ifndef __SYSDEP_I386_SKAS_PTRACE_H
#define __SYSDEP_I386_SKAS_PTRACE_H

struct ptrace_faultinfo {
int is_write;
unsigned long addr;
};

struct ptrace_ldt {
int func;
void *ptr;
unsigned long bytecount;
};

#define PTRACE_LDT 54

#endif
22 changes: 22 additions & 0 deletions arch/um/include/sysdep-ia64/skas_ptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/

#ifndef __SYSDEP_IA64_SKAS_PTRACE_H
#define __SYSDEP_IA64_SKAS_PTRACE_H

struct ptrace_faultinfo {
int is_write;
unsigned long addr;
};

struct ptrace_ldt {
int func;
void *ptr;
unsigned long bytecount;
};

#define PTRACE_LDT 54

#endif
22 changes: 22 additions & 0 deletions arch/um/include/sysdep-ppc/skas_ptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/

#ifndef __SYSDEP_PPC_SKAS_PTRACE_H
#define __SYSDEP_PPC_SKAS_PTRACE_H

struct ptrace_faultinfo {
int is_write;
unsigned long addr;
};

struct ptrace_ldt {
int func;
void *ptr;
unsigned long bytecount;
};

#define PTRACE_LDT 54

#endif
29 changes: 29 additions & 0 deletions arch/um/include/sysdep-x86_64/faultinfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 2004 Fujitsu Siemens Computers GmbH
* Author: Bodo Stroesser <bstroesser@fujitsu-siemens.com>
* Licensed under the GPL
*/

#ifndef __FAULTINFO_X86_64_H
#define __FAULTINFO_X86_64_H

/* this structure contains the full arch-specific faultinfo
* from the traps.
* On i386, ptrace_faultinfo unfortunately doesn't provide
* all the info, since trap_no is missing.
* All common elements are defined at the same position in
* both structures, thus making it easy to copy the
* contents without knowledge about the structure elements.
*/
struct faultinfo {
int error_code; /* in ptrace_faultinfo misleadingly called is_write */
unsigned long cr2; /* in ptrace_faultinfo called addr */
int trap_no; /* missing in ptrace_faultinfo */
};

#define FAULT_WRITE(fi) ((fi).error_code & 2)
#define FAULT_ADDRESS(fi) ((fi).cr2)

#define PTRACE_FULL_FAULTINFO 1

#endif
16 changes: 5 additions & 11 deletions arch/um/include/sysdep-x86_64/ptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "uml-config.h"
#include "user_constants.h"
#include "sysdep/faultinfo.h"

#define MAX_REG_OFFSET (UM_FRAME_SIZE)
#define MAX_REG_NR ((MAX_REG_OFFSET) / sizeof(unsigned long))
Expand Down Expand Up @@ -83,16 +84,15 @@ union uml_pt_regs {
long syscall;
unsigned long orig_rax;
void *sc;
struct faultinfo faultinfo;
} tt;
#endif
#ifdef UML_CONFIG_MODE_SKAS
struct skas_regs {
/* XXX */
unsigned long regs[27];
unsigned long fp[65];
unsigned long fault_addr;
unsigned long fault_type;
unsigned long trap_type;
struct faultinfo faultinfo;
long syscall;
int is_user;
} skas;
Expand Down Expand Up @@ -241,14 +241,8 @@ struct syscall_args {
CHOOSE_MODE(SC_SEGV_IS_FIXABLE(UPT_SC(r)), \
REGS_SEGV_IS_FIXABLE(&r->skas))

#define UPT_FAULT_ADDR(r) \
__CHOOSE_MODE(SC_FAULT_ADDR(UPT_SC(r)), REGS_FAULT_ADDR(&r->skas))

#define UPT_FAULT_WRITE(r) \
CHOOSE_MODE(SC_FAULT_WRITE(UPT_SC(r)), REGS_FAULT_WRITE(&r->skas))

#define UPT_TRAP(r) __CHOOSE_MODE(SC_TRAP_TYPE(UPT_SC(r)), REGS_TRAP(&r->skas))
#define UPT_ERR(r) __CHOOSE_MODE(SC_FAULT_TYPE(UPT_SC(r)), REGS_ERR(&r->skas))
#define UPT_FAULTINFO(r) \
CHOOSE_MODE((&(r)->tt.faultinfo), (&(r)->skas.faultinfo))

#endif

Expand Down
15 changes: 8 additions & 7 deletions arch/um/include/sysdep-x86_64/sigcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
#define SC_FAULT_ADDR(sc) SC_CR2(sc)
#define SC_FAULT_TYPE(sc) SC_ERR(sc)

#define FAULT_WRITE(err) ((err) & 2)

#define SC_FAULT_WRITE(sc) FAULT_WRITE(SC_FAULT_TYPE(sc))

#define SC_TRAP_TYPE(sc) SC_TRAPNO(sc)
#define GET_FAULTINFO_FROM_SC(fi,sc) \
{ \
(fi).cr2 = SC_CR2(sc); \
(fi).error_code = SC_ERR(sc); \
(fi).trap_no = SC_TRAPNO(sc); \
}

/* ptrace expects that, at the start of a system call, %eax contains
* -ENOSYS, so this makes it so.
*/

#define SC_START_SYSCALL(sc) do SC_RAX(sc) = -ENOSYS; while(0)

#define SEGV_IS_FIXABLE(trap) ((trap) == 14)
#define SC_SEGV_IS_FIXABLE(sc) SEGV_IS_FIXABLE(SC_TRAP_TYPE(sc))
/* This is Page Fault */
#define SEGV_IS_FIXABLE(fi) ((fi)->trap_no == 14)

extern unsigned long *sc_sigmask(void *sc_ptr);

Expand Down
22 changes: 22 additions & 0 deletions arch/um/include/sysdep-x86_64/skas_ptrace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/

#ifndef __SYSDEP_X86_64_SKAS_PTRACE_H
#define __SYSDEP_X86_64_SKAS_PTRACE_H

struct ptrace_faultinfo {
int is_write;
unsigned long addr;
};

struct ptrace_ldt {
int func;
void *ptr;
unsigned long bytecount;
};

#define PTRACE_LDT 54

#endif
16 changes: 9 additions & 7 deletions arch/um/kernel/ptrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion arch/um/kernel/skas/include/skas.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit c578455

Please sign in to comment.