SKAS4
Subsystems (10)
cover SKAS4
Major changes since version 5 -
Rebased on 2.6.25 Added sys_vcpu support
Major changes since version 4 -
Fiddled the switch_mm interface, simplifying the
implementation, its users, and the architecture hooks
userspace registers are now encapsulated in struct user_regs,
which will include FP registers as well
Fixed a skas4 detection bug
Major changes since version 3 -
Rebased on 2.6.24 Removed some unused options to new_mm and switch_mm
Major changes since version 2 -
Rebased on rc8
Code cleanup
mmfs.c moved to mm arch-specific code is moved to arch mm refcounting fixed
Major changes since version 1 -
32-bit compatibility - 32-bit skas4 guests run on skas4 hosts testing of host PTRACE_GETSIGINFO support
A full rolled-up patch is appended to this message.
These patches implement host and guest SKAS4 support for both 32- and 64-bit x86, plus 32-bit compatibility.
I think the new interfaces here are much more acceptable than those in SKAS3, so I'm going to push this to mainline.
What's new:
three new system calls -
new_mm - creates a new address space and returns a file
descriptor referencing it
switch_mm - moves the calling process to the address space
referenced by the file descriptor passed to it
vcpu - allows both UML's kernel and processes to run in a
single host process by creating a new context in which system calls and signals cause an exit back to the original context by returning from the vcpu call.
/proc/<pid>/mm - opening this gives you a file descriptor
referencing the address space occupied by the given pid - this descriptor can be given to switch_mm just as a new_mm descriptor can
PTRACE_SWITCH_MM - same as with SKAS3, causes the child process to
switch from its current address space to a different one
siginfo_t extensions - siginfo_t always contained the faulting
address in the SIGSEGV case. However, for it to be useful to UML, it needs the CPU trap number and error code. There already was conditional support for the trap number, which x86 didn't implement. This is enabled, and support for passing out the error code is added.
How this compares to skas3:
Creating a new address space:
skas3 - open /proc/mm
skas4 - new_mm()
Remapping pages within another address space
skas3 - write a structure desribing the change to a /proc/mm
descriptor
skas4 - switch_mm to the address space, run the necessary system
calls directly, switch_mm back to the UML kernel address space
Getting page fault information from a process
skas3 - PTRACE_FAULTINFO
skas4 - PTRACE_GETSIGINFO
This patchset contains 12 patches. Six of them contain the siginfo extension, guest siginfo support, host new_mm/switch_mm support, guest new_mm/switch_mm support, and host and guest vcpu support. The rest are preparation patches which shouldn't change anything functionally, but which make the four functional patches smaller and easier to read.
These are against 2.6.25. Build both host and guest from the same tree. I will be tweaking the interfaces in incompatible ways, so if you play with future versions of this patchset, throw this one out. Definitely don't try to boot a guest built from one version on a host built from another. It will work, but likely you'll get skas0, as there will likely be some interface change which causes the host skas4 checks to fail.
This is very experimental at this point. Don't let it near anything resembling a production system.
Jeff
Signature · 1 line
Work email - jdike at linux dot intel dot com
arch/um/include/as-layout.h +6 -7
@@ -23,16 +23,15 @@*/ #ifdef __ASSEMBLY__ -#define _AC (X ,Y ) (Y) +#define _C (Y ) (Y)#else -#define __AC (X ,Y ) (X (Y)) -#define _AC (X ,Y ) __AC(X, Y) +#define _C (Y ) ((unsigned long) (Y))#endif -#define STUB_START _AC(, 0x100000) -#define STUB_CODE _AC((unsigned long), STUB_START) -#define STUB_DATA _AC((unsigned long), STUB_CODE + UM_KERN_PAGE_SIZE) -#define STUB_END _AC((unsigned long), STUB_DATA + UM_KERN_PAGE_SIZE) +#define STUB_START _C(0x100000) +#define STUB_CODE STUB_START +#define STUB_DATA (STUB_CODE + UM_KERN_PAGE_SIZE) +#define STUB_END (STUB_DATA + UM_KERN_PAGE_SIZE)#ifndef __ASSEMBLY__
arch/um/include/kern_util.h +2 -2
@@ -20,9 +20,9 @@ extern int kmalloc_ok;extern unsigned long alloc_stack (int order,int atomic);extern void free_stack (unsigned long stack,int order); -extern int do_signal (void ); +extern void do_signal (void );extern void copy_sc (struct uml_pt_regs *regs,void *from); -extern void interrupt_end (void ); +extern int interrupt_end (void );extern void relay_signal (int sig,struct uml_pt_regs *regs); extern unsigned long segv(struct faultinfo fi, unsigned long ip,
arch/um/include/os.h +1 -0
@@ -265,6 +265,7 @@ extern int is_skas_winch(int pid, int fd, void *data);extern int start_userspace (unsigned long stub_stack);extern int copy_context_skas0 (unsigned long stack,int pid);extern void userspace (struct uml_pt_regs *regs); +extern void vcpu_userspace (struct uml_pt_regs *regs,int mm_fd);extern int map_stub_pages (int fd,unsigned long code,unsigned long data,unsigned long stack);extern void new_thread (void *stack,jmp_buf *buf,void (*handler)(void ));
arch/um/include/siginfo_segv.h new file +133 -0
133 lines not on this page · raw message
arch/um/include/skas/mm_id.h +1 -1
@@ -7,7 +7,7 @@#define __MM_ID_Hstruct mm_id { -union { +struct {int mm_fd;int pid; } u;
arch/um/include/skas/skas.h +111 -1
129 lines not on this page · raw message
arch/um/include/skas_ptrace.h +4 -13
@@ -1,5 +1,5 @@/* -* Copyright (C) 2000, 2001, 2002 Jeff Dike ([email protected]) +* Copyright (C) 2000 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */
@@ -7,19 +7,10 @@#define __SKAS_PTRACE_H#define PTRACE_FAULTINFO 52 -#define PTRACE_SWITCH_MM 55 +#ifndef OLD_PTRACE_SWITCH_MM +#define OLD_PTRACE_SWITCH_MM 55 +#endif #include "sysdep/skas_ptrace.h" #endif - -/* -* Overrides for Emacs so that we follow Linus's tabbing style. -* Emacs will notice this stuff at the end of the file and automatically -* adjust the settings for this buffer only. This must remain at the end -* of the file. -* --------------------------------------------------------------------------- -* Local variables: -* c-file-style: "linux" -* End: -*/
arch/um/include/sysdep-i386/ptrace.h +1 -1
@@ -156,7 +156,7 @@ struct syscall_args { } while (0)#define UPT_SET_SYSCALL_RETURN (r, res) \ - REGS_SET_SYSCALL_RETURN((r)->regs, (res)) + REGS_SET_SYSCALL_RETURN((r)->gp, (res))#define UPT_RESTART_SYSCALL (r) REGS_RESTART_SYSCALL((r)->gp)
arch/um/include/sysdep-i386/ptrace_user.h +2 -0
@@ -43,6 +43,8 @@#define FP_SIZE ((HOST_XFP_SIZE > HOST_FP_SIZE) ? HOST_XFP_SIZE : HOST_FP_SIZE) +#define FP_SIZE ((HOST_XFP_SIZE > HOST_FP_SIZE) ? HOST_XFP_SIZE : HOST_FP_SIZE) +#ifndef FRAME_SIZE #define FRAME_SIZE (17)#endif
arch/um/include/sysdep-i386/tls.h +9 -3
@@ -1,7 +1,7 @@#ifndef _SYSDEP_TLS_H#define _SYSDEP_TLS_H -# ifndef __KERNEL__ +#ifndef __KERNEL__/* Change name to avoid conflicts with the original one from <asm/ldt.h>, which * may be named user_desc (but in 2.4 and in header matching its API was named
@@ -19,13 +19,19 @@ typedef struct um_dup_user_desc { unsigned int useable:1; } user_desc_t; -# else /* __KERNEL__ */ +#else /* __KERNEL__ */ -# include <asm/ldt.h> +#include <asm/host_ldt.h> typedef struct user_desc user_desc_t ;# endif /* __KERNEL__ */ +struct uml_tls_struct { +user_desc_t tls; +unsigned flushed:1 ; +unsigned present:1 ; +}; +#define GDT_ENTRY_TLS_MIN_I386 6#define GDT_ENTRY_TLS_MIN_X86_64 12
arch/um/include/sysdep-x86_64/ptrace.h +3 -5
@@ -225,16 +225,14 @@ struct syscall_args { })#define UPT_SET_SYSCALL_RETURN (r, res) \ - REGS_SET_SYSCALL_RETURN((r)->regs, (res)) + REGS_SET_SYSCALL_RETURN((r)->gp, (res))#define UPT_RESTART_SYSCALL (r) REGS_RESTART_SYSCALL((r)->gp) -#define UPT_SEGV_IS_FIXABLE (r) REGS_SEGV_IS_FIXABLE(&r->skas) +#define UPT_SEGV_IS_FIXABLE (r) REGS_SEGV_IS_FIXABLE(&(r)->skas)#define UPT_FAULTINFO (r) (&(r)->faultinfo) -static inline void arch_init_registers (int pid) -{ -} +extern void arch_init_registers (int pid);#endif
arch/um/include/sysdep-x86_64/ptrace_user.h +2 -0
@@ -72,6 +72,8 @@#define FP_SIZE (HOST_FP_SIZE) +#define FP_SIZE (HOST_FP_SIZE) +#endif /*
arch/um/kernel/process.c +13 -4
@@ -111,12 +111,13 @@ void *_switch_to(void *prev, void *next, void *last) } -void interrupt_end (void ) +int interrupt_end (void ) {if (need_resched ())schedule (); -if (test_tsk_thread_flag (current,TIF_SIGPENDING )) +if (test_thread_flag (TIF_SIGPENDING ))do_signal (); +return current->mm->context.id.u.mm_fd; }void exit_thread (void )
@@ -152,7 +153,11 @@ void new_thread_handler(void)if (n ==1 ) {/* Handle any immediate reschedules or signals */ interrupt_end (); -userspace (¤t->thread.regs.regs); +if (have_vcpu) +vcpu_userspace (¤t->thread.regs.regs, + current->mm->context.id.u.mm_fd); +else +userspace (¤t->thread.regs.regs); }else do_exit (0 ); }
@@ -176,7 +181,11 @@ void fork_handler(void)/* Handle any immediate reschedules or signals */ interrupt_end (); -userspace (¤t->thread.regs.regs); +if (have_vcpu) +vcpu_userspace (¤t->thread.regs.regs, + current->mm->context.id.u.mm_fd); +else +userspace (¤t->thread.regs.regs); } int copy_thread(int nr, unsigned long clone_flags, unsigned long sp,
arch/um/kernel/ptrace.c +34 -1
@@ -192,7 +192,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data) }#endif #ifdef CONFIG_PROC_MM -case PTRACE_SWITCH_MM : { +case OLD_PTRACE_SWITCH_MM : {struct mm_struct *old = child->mm;struct mm_struct *new =proc_mm_get_mm (data);
@@ -292,3 +292,36 @@ void syscall_trace(struct uml_pt_regs *regs, int entryexit) current->exit_code =0 ; } } + +int ptrace_to_pt_regs (struct pt_regs *to,struct user_regs __user *from) +{ +struct user_regs regs; +int rem; + + rem =copy_from_user (®s, from,sizeof (regs)); +if (rem) +return -EFAULT ; + +memcpy (&to->regs.gp, ®s.regs,sizeof (to->regs.gp)); + +return put_fp_registers (userspace_pid[0 ], + (unsigned long *) ®s.fpregs); +} + +int pt_regs_to_ptrace (struct user_regs __user *to,struct pt_regs *from) +{ +struct user_regs regs; +int err; + + err =get_fp_registers (userspace_pid[0 ], + (unsigned long *) ®s.fpregs); +if (err) +return err; + +memcpy (®s.regs, &from->regs.gp,sizeof (regs.regs)); + +if (copy_to_user (to, ®s,sizeof (regs))) +return -EFAULT ; + +return 0 ; +}
arch/um/kernel/reboot.c +1 -1
@@ -12,7 +12,7 @@ void (*pm_power_off)(void);static void kill_off_processes (void ) { -if (proc_mm) +if (proc_mm || have_switch_mm)/* * FIXME: need to loop over userspace_pids */
arch/um/kernel/signal.c +9 -7
@@ -85,8 +85,11 @@ static int handle_signal(struct pt_regs *regs, unsigned long signr,return err; } -static int kern_do_signal (struct pt_regs *regs) +extern int unvcpu (struct pt_regs *regs,siginfo_t *siginfo); + +void do_signal (void ) { +struct pt_regs *regs = ¤t->thread.regs;struct k_sigaction ka_copy;siginfo_t info;sigset_t *oldset;
@@ -98,6 +101,11 @@ static int kern_do_signal(struct pt_regs *regs) oldset = ¤t->blocked;while ((sig =get_signal_to_deliver (&info, &ka_copy, regs,NULL )) >0 ) { +if (test_thread_flag (TIF_VCPU )) { +PT_REGS_SET_SYSCALL_RETURN (regs,unvcpu (regs, &info)); +return ; + } + handled_sig =1 ;/* Whee! Actually deliver the signal. */ if (!handle_signal (regs, sig, &ka_copy, &info, oldset)) {
@@ -150,12 +158,6 @@ static int kern_do_signal(struct pt_regs *regs)clear_thread_flag (TIF_RESTORE_SIGMASK );sigprocmask (SIG_SETMASK , ¤t->saved_sigmask,NULL ); } -return handled_sig; -} - -int do_signal (void ) -{ -return kern_do_signal (¤t->thread.regs); }/*
arch/um/kernel/skas/clone.c +1 -1
@@ -3,8 +3,8 @@* Licensed under the GPL */ -#include <signal.h> #include <sched.h> +#include <signal.h> #include <asm/unistd.h> #include <sys/time.h> #include "as-layout.h"
arch/um/kernel/skas/mmu.c +19 -3
@@ -46,6 +46,9 @@ static int init_stub_pte(struct mm_struct *mm, unsigned long proc,return -ENOMEM ; } +extern int copy_context_skas4 (struct mm_id *id); +extern int get_new_mm (void ); +int init_new_context (struct task_struct *task,struct mm_struct *mm) {struct mm_context *from_mm =NULL ;
@@ -64,13 +67,26 @@ int init_new_context(struct task_struct *task, struct mm_struct *mm) from_mm = ¤t->mm->context;if (proc_mm) { - ret =new_mm (stack); + ret =make_new_mm (stack);if (ret <0 ) {printk (KERN_ERR "init_new_context_skas - " -"new_mm failed, errno = %d\n" , ret); +"make_new_mm failed, errno = %d\n" , ret); goto out_free; } to_mm->id.u.mm_fd = ret; + }else if (have_switch_mm) { + to_mm->id.u.mm_fd =get_new_mm (); +if (to_mm->id.u.mm_fd <0 ) { + ret = to_mm->id.u.mm_fd; + goto out_free; + } + + ret =copy_context_skas4 (&to_mm->id); +if (ret <0 ) { +os_close_file (to_mm->id.u.mm_fd); + to_mm->id.u.mm_fd =-1 ; + goto out_free; + } }else {if (from_mm)
@@ -167,7 +183,7 @@ void destroy_context(struct mm_struct *mm) {struct mm_context *mmu = &mm->context; -if (proc_mm) +if (proc_mm || have_switch_mm)os_close_file (mmu->id.u.mm_fd);else {/*
arch/um/kernel/skas/process.c +3 -2
@@ -10,7 +10,7 @@#include "os.h" #include "skas.h" -int new_mm (unsigned long stack) +int make_new_mm (unsigned long stack) {int fd, err;
@@ -55,7 +55,8 @@ int __init start_uml(void) {stack_protections ((unsigned long ) &cpu0_irqstack);set_sigstack (cpu0_irqstack,THREAD_SIZE ); -if (proc_mm) { + +if (!have_vcpu && (proc_mm || have_switch_mm)) { userspace_pid[0 ] =start_userspace (0 );if (userspace_pid[0 ] <0 ) { printf("start_uml - start_userspace returned %d\n",
arch/um/kernel/skas/syscall.c +7 -0
@@ -12,12 +12,19 @@extern int syscall_table_size;#define NR_syscalls (syscall_table_size / sizeof(void *)) +extern int unvcpu (struct pt_regs *regs,siginfo_t *siginfo); +void handle_syscall (struct uml_pt_regs *r) { struct pt_regs *regs = container_of(r, struct pt_regs, regs);long result;int syscall; +if (test_thread_flag (TIF_VCPU )) { +REGS_SET_SYSCALL_RETURN (r->gp,unvcpu (regs,NULL )); +return ; + } +syscall_trace (r,0 );/*
arch/um/kernel/syscall.c +28 -10
@@ -1,17 +1,17 @@/* -* Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) +* Copyright (C) 2000 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ -#include "linux/file.h" -#include "linux/fs.h" -#include "linux/mm.h" -#include "linux/sched.h" -#include "linux/utsname.h" -#include "asm/current.h" -#include "asm/mman.h" -#include "asm/uaccess.h" -#include "asm/unistd.h" +#include <linux/file.h> +#include <linux/fs.h> +#include <linux/mm.h> +#include <linux/sched.h> +#include <linux/utsname.h> +#include <asm/current.h> +#include <asm/mman.h> +#include <asm/uaccess.h> +#include <asm/unistd.h> long sys_fork (void ) {
@@ -148,3 +148,21 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[])return ret; } + +extern long do_switch_mm (int fd,long __user *save,long __user *new, +unsigned long ip,unsigned long sp, +struct pt_regs *regs); + +long sys_switch_mm (int fd,long __user *save,long __user *new, +unsigned long ip,unsigned long sp) +{ +return do_switch_mm (fd, save, new, ip, sp, ¤t->thread.regs); +} + +extern long do_vcpu (int mm_fd,struct vcpu_user __user *new, +struct pt_regs *regs); + +long sys_vcpu (int mm_fd,struct vcpu_user __user *new) +{ +return do_vcpu (mm_fd, new, ¤t->thread.regs); +}
arch/um/kernel/um_arch.c +3 -1
@@ -284,7 +284,9 @@ int __init linux_main(int argc, char **argv)can_do_skas (); -if (proc_mm && ptrace_faultinfo) +if (have_switch_mm) + mode ="SKAS4" ; +else if (proc_mm && ptrace_faultinfo) mode ="SKAS3" ;else mode ="SKAS0" ;
arch/um/os-Linux/skas/mem.c +122 -77
260 lines not on this page · raw message
arch/um/os-Linux/skas/process.c +169 -17
258 lines not on this page · raw message
arch/um/os-Linux/start_up.c +472 -43
611 lines not on this page · raw message
arch/um/os-Linux/sys-i386/registers.c +30 -3
@@ -4,10 +4,16 @@* Licensed under the GPL */ +#include <stdio.h> +#include <stdlib.h> #include <errno.h> +#include <asm/ldt.h> +#include <sys/syscall.h> +#include <unistd.h> #include "kern_constants.h" #include "longjmp.h" #include "user.h" +#include "skas.h" #include "sysdep/ptrace_user.h" int save_fp_registers (int pid,unsigned long *fp_regs)
@@ -72,12 +78,32 @@ int put_fp_registers(int pid, unsigned long *regs)return restore_fp_registers (pid, regs); } +extern int host_gdt_entry_tls_min; + +#define GDT_ENTRY_TLS_ENTRIES 3 +#define GDT_ENTRY_TLS_MIN 6 +#define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1) + +struct user_desc tls[GDT_ENTRY_TLS_ENTRIES ]; + +unsigned long fp_regs[FP_SIZE ]; +void arch_init_registers (int pid) { -unsigned long fpx_regs[HOST_XFP_SIZE ]; -int err; +struct user_desc *entry; +int err, i; - err =ptrace (PTRACE_GETFPXREGS , pid,0 , fpx_regs); +for (i =0 ; i <GDT_ENTRY_TLS_ENTRIES ; i++) { + entry = &tls[i]; + entry->entry_number = i +GDT_ENTRY_TLS_MIN ; + err =get_thread_area (entry); +if (err) { +perror ("get_thread_area" ); +exit (1 ); + } + } + + err =ptrace (PTRACE_GETFPXREGS , pid,0 , fp_regs);if (!err)return ;
@@ -87,3 +113,4 @@ void arch_init_registers(int pid) have_fpx_regs =0 ; } +
arch/um/os-Linux/sys-x86_64/registers.c +14 -1
@@ -1,5 +1,5 @@/* -* Copyright (C) 2006 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) +* Copyright (C) 2006 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */
@@ -10,6 +10,7 @@#include "kern_constants.h" #include "longjmp.h" #include "user.h" +#include "sysdep/ptrace_user.h" int save_fp_registers (int pid,unsigned long *fp_regs) {
@@ -50,3 +51,15 @@ int put_fp_registers(int pid, unsigned long *regs) {return restore_fp_registers (pid, regs); } + +unsigned long fp_regs[FP_SIZE ]; + +void arch_init_registers (int pid) +{ +int err; + + err =ptrace (PTRACE_GETFPREGS , pid,0 , fp_regs); +if (err) +panic ("arch_init_registers : PTRACE_GETFPREGS failed, " +"errno = %d" , errno); +}
arch/um/sys-i386/ldt.c +1 -1
@@ -437,7 +437,7 @@ long init_new_ldt(struct mm_context *new_mm, struct mm_context *from_mm)/* * We have a valid from_mm, so we now have to copy the LDT of * from_mm to new_mm, because using proc_mm an new mm with -* an empty/default LDT was created in new_mm() +* an empty/default LDT was created in make_new_mm() */ copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS, .u =
arch/um/sys-i386/signal.c +10 -26
@@ -164,6 +164,8 @@ static int convert_fxsr_from_user(struct user_fxsr_struct *fxsave,extern int have_fpx_regs; +extern unsigned long fp_regs[FP_SIZE ]; +static int copy_sc_from_user (struct pt_regs *regs,struct sigcontext __user *from) {
@@ -177,24 +179,12 @@ static int copy_sc_from_user(struct pt_regs *regs, pid = userspace_pid[current_thread_info ()->cpu];copy_sc (®s->regs, &sc);if (have_fpx_regs) { -struct user_fxsr_struct fpx; - - err =copy_from_user (&fpx, &sc.fpstate->_fxsr_env[0 ], -sizeof (struct user_fxsr_struct )); -if (err) -return 1 ; +struct user_fxsr_struct *fpx = + (struct user_fxsr_struct *) &fp_regs; - err =convert_fxsr_from_user (&fpx, sc.fpstate); + err =convert_fxsr_from_user (fpx, sc.fpstate);if (err)return 1 ; - - err =restore_fpx_registers (pid, (unsigned long *) &fpx); -if (err <0 ) { -printk (KERN_ERR "copy_sc_from_user - " -"restore_fpx_registers failed, errno = %d\n" , - -err); -return 1 ; - } }else {struct user_i387_struct fp;
@@ -250,25 +240,19 @@ static int copy_sc_to_user(struct sigcontext __user *to, pid = userspace_pid[current_thread_info ()->cpu];if (have_fpx_regs) { -struct user_fxsr_struct fpx; - - err =save_fpx_registers (pid, (unsigned long *) &fpx); -if (err <0 ){ -printk (KERN_ERR "copy_sc_to_user - save_fpx_registers " -"failed, errno = %d\n" , err); -return 1 ; - } +struct user_fxsr_struct *fpx = + (struct user_fxsr_struct *) &fp_regs; - err =convert_fxsr_to_user (to_fp, &fpx); + err =convert_fxsr_to_user (to_fp, fpx);if (err)return 1 ; - err |=__put_user (fpx.swd, &to_fp->status); + err |=__put_user (fpx->swd, &to_fp->status); err |=__put_user (X86_FXSR_MAGIC , &to_fp->magic);if (err)return 1 ; -if (copy_to_user (&to_fp->_fxsr_env[0 ], &fpx, +if (copy_to_user (&to_fp->_fxsr_env[0 ], fpx,sizeof (struct user_fxsr_struct )))return 1 ; }
arch/um/sys-i386/stub.S +47 -39
99 lines not on this page · raw message
arch/um/sys-i386/tls.c +32 -12
90 lines not on this page · raw message
arch/um/sys-x86_64/signal.c +24 -14
@@ -42,6 +42,8 @@ void copy_sc(struct uml_pt_regs *regs, void *from)#undef GETREG } +static unsigned long fp_regs[HOST_FP_SIZE ]; +static int copy_sc_from_user (struct pt_regs *regs,struct sigcontext __user *from,struct _fpstate __user *fpp)
@@ -81,13 +83,17 @@ static int copy_sc_from_user(struct pt_regs *regs,if (err)return 1 ; - err =restore_fp_registers (userspace_pid[current_thread_info ()->cpu], - (unsigned long *) &fp); -if (err <0 ) { -printk (KERN_ERR "copy_sc_from_user - " -"restore_fp_registers failed, errno = %d\n" , - -err); -return 1 ; +if (have_vcpu) +memcpy (fp_regs, &fp,sizeof (fp_regs)); +else { + err =restore_fp_registers (userspace_pid[current_thread_info ()->cpu], + (unsigned long *) &fp); +if (err <0 ) { +printk (KERN_ERR "copy_sc_from_user - " +"restore_fp_registers failed, errno = %d\n" , + -err); +return 1 ; + } }return 0 ;
@@ -143,14 +149,18 @@ static int copy_sc_to_user(struct sigcontext __user *to,if (err)return 1 ; - err =save_fp_registers (userspace_pid[current_thread_info ()->cpu], - (unsigned long *) &fp); -if (err <0 ) { -printk (KERN_ERR "copy_sc_from_user - restore_fp_registers " -"failed, errno = %d\n" , -err); -return 1 ; +if (have_vcpu) +memcpy (&fp, fp_regs,sizeof (fp)); +else { + err =save_fp_registers (userspace_pid[current_thread_info ()->cpu], + (unsigned long *) &fp); +if (err <0 ) { +printk (KERN_ERR "copy_sc_from_user - " +"restore_fp_registers failed, errno = %d\n" , + -err); +return 1 ; + } } -if (copy_to_user (to_fp, &fp,sizeof (struct user_i387_struct )))return 1 ;
arch/um/sys-x86_64/stub.S +57 -56
124 lines not on this page · raw message
arch/um/sys-x86_64/syscall_table.c +2 -0
@@ -39,6 +39,8 @@#define stub_rt_sigsuspend sys_rt_sigsuspend#define stub_sigaltstack sys_sigaltstack#define stub_rt_sigreturn sys_rt_sigreturn +#define stub_switch_mm sys_switch_mm +#define stub_vcpu sys_vcpu#define __SYSCALL (nr, sym) extern asmlinkage void sym(void) ;#undef _ASM_X86_64_UNISTD_H_
arch/um/sys-x86_64/syscalls.c +68 -51
129 lines not on this page · raw message
arch/x86/ia32/ia32_signal.c +2 -0
@@ -68,6 +68,8 @@ int copy_siginfo_to_user32(compat_siginfo_t __user *to, siginfo_t *from) &to->_sifields._pad[0]);switch (from->si_code >>16 ) {case __SI_FAULT >>16 : + err |=__put_user (from->si_trapno, &to->si_trapno); + err |=__put_user (from->si_error, &to->si_error);break ;case __SI_CHLD >>16 : err |=__put_user (from->si_utime, &to->si_utime);
arch/x86/ia32/ia32entry.S +3 -0
@@ -373,6 +373,7 @@ quiet_ni_syscall: PTREGSCALL stub32_vfork, sys_vfork, %rdi PTREGSCALL stub32_iopl, sys_iopl, %rsi PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdx + PTREGSCALL stub32_switch_mm, sys_switch_mm, %r9 ENTRY(ia32_ptregs_common) popq %r11
@@ -727,4 +728,6 @@ ia32_sys_call_table: .quad sys32_fallocate .quad compat_sys_timerfd_settime /* 325 */ .quad compat_sys_timerfd_gettime + .quad sys_new_mm + .quad stub32_switch_mm ia32_syscall_end:
arch/x86/kernel/entry_32.S +1 -1
@@ -371,7 +371,7 @@ ENTRY(system_call) GET_THREAD_INFO(%ebp) # system call tracing in operation / emulation /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */ - testw $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT),TI_flags(%ebp) + testl $(_TIF_SYSCALL_EMU|_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_VCPU),TI_flags(%ebp) jnz syscall_trace_entry cmpl $(nr_syscalls), %eax jae syscall_badsys
arch/x86/kernel/entry_64.S +25 -1
@@ -244,7 +244,7 @@ ENTRY(system_call_after_swapgs) movq %rcx,RIP-ARGOFFSET(%rsp) CFI_REL_OFFSET rip,RIP-ARGOFFSET GET_THREAD_INFO(%rcx) - testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),threadinfo_flags(%rcx) + testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP|_TIF_VCPU),threadinfo_flags(%rcx) jnz tracesys cmpq $__NR_syscall_max,%rax ja badsys
@@ -323,6 +323,12 @@ tracesys: FIXUP_TOP_OF_STACK %rdi movq %rsp,%rdi call syscall_trace_enter + testl %eax, %eax + jz 2f + LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */ + RESTORE_REST + jmp int_ret_from_sys_call +2: LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */ RESTORE_REST cmpq $__NR_syscall_max,%rax
@@ -425,6 +431,7 @@ END(\label) PTREGSCALL stub_rt_sigsuspend, sys_rt_sigsuspend, %rdx PTREGSCALL stub_sigaltstack, sys_sigaltstack, %rdx PTREGSCALL stub_iopl, sys_iopl, %rsi + PTREGSCALL stub_switch_mm, sys_switch_mm, %r9 ENTRY(ptregscall_common) popq %r11
@@ -481,6 +488,23 @@ ENTRY(stub_rt_sigreturn) END(stub_rt_sigreturn) /* + * vcpu is special too + */ +ENTRY(stub_vcpu) + CFI_STARTPROC + addq $8, %rsp + CFI_ADJUST_CFA_OFFSET -8 + SAVE_REST + movq %rsp,%rdx + FIXUP_TOP_OF_STACK %r11 + call sys_vcpu + movq %rax,RAX(%rsp) # fixme, this could be done at the higher layer + RESTORE_REST + jmp int_ret_from_sys_call + CFI_ENDPROC +END(stub_vcpu) + +/* * initial frame state for interrupts and exceptions */ .macro _frame ref
arch/x86/kernel/ptrace.c +194 -6
268 lines not on this page · raw message
arch/x86/kernel/signal_32.c +7 -0
@@ -573,6 +573,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,return ret; } +extern int unvcpu (struct pt_regs *regs,siginfo_t *siginfo); +/* * Note that 'init' is a special process: it doesn't get signals it doesn't * want to handle. Thus you cannot kill init even with a SIGKILL even by
@@ -603,6 +605,11 @@ static void do_signal(struct pt_regs *regs) signr =get_signal_to_deliver (&info, &ka, regs,NULL );if (signr >0 ) { +if (test_thread_flag (TIF_VCPU )) { + regs->ax =unvcpu (regs, &info); +return ; + } +/* Re-enable any watchpoints before delivering the * signal to user space. The processor register will * have been cleared if the watchpoint triggered
arch/x86/kernel/signal_64.c +7 -0
@@ -407,6 +407,8 @@ handle_signal(unsigned long sig, siginfo_t *info, struct k_sigaction *ka,return ret; } +extern int unvcpu (struct pt_regs *regs,siginfo_t *siginfo); +/* * Note that 'init' is a special process: it doesn't get signals it doesn't * want to handle. Thus you cannot kill init even with a SIGKILL even by
@@ -435,6 +437,11 @@ static void do_signal(struct pt_regs *regs) signr =get_signal_to_deliver (&info, &ka, regs,NULL );if (signr >0 ) { +if (test_thread_flag (TIF_VCPU )) { + regs->ax =unvcpu (regs, &info); +return ; + } +/* Re-enable any watchpoints before delivering the * signal to user space. The processor register will * have been cleared if the watchpoint triggered
arch/x86/kernel/sys_i386_32.c +26 -0
@@ -21,6 +21,7 @@#include <asm/uaccess.h> #include <asm/unistd.h> +#include <asm/user.h> /* * sys_pipe() is the normal C calling standard for creating
@@ -261,3 +262,28 @@ int kernel_execve(const char *filename, char *const argv[], char *const envp[]) : "0" (__NR_execve),"ri" (filename),"c" (argv), "d" (envp) : "memory");return __res; } + +extern long do_switch_mm (int fd,struct __user user_regs *save, +struct __user user_regs *new,unsigned long ip, +unsigned long sp,struct pt_regs *regs); + +asmlinkage long sys_switch_mm (struct pt_regs regs) +{ +return do_switch_mm (regs.bx, (struct __user user_regs *) regs.cx, + (struct __user user_regs *) regs.dx, regs.si, + regs.di, ®s); +} + +extern long do_vcpu (int mm_fd,struct vcpu_user __user *new, +struct pt_regs *regs); + +asmlinkage long sys_vcpu (struct pt_regs regs) +{ +int err; + + err =do_vcpu (regs.bx, (struct vcpu_user __user *) regs.cx, ®s); +if (err) +return err; + +return regs.ax; +}
arch/x86/kernel/sys_x86_64.c +26 -0
@@ -251,3 +251,29 @@ asmlinkage long sys_uname(struct new_utsname __user * name) err |=copy_to_user (&name->machine,"i686" ,5 );return err ? -EFAULT :0 ; } + +extern long do_switch_mm (int fd,struct __user user_regs *save, +struct __user user_regs *new,unsigned long ip, +unsigned long sp,struct pt_regs *regs); + +asmlinkage long sys_switch_mm (int fd,struct __user user_regs *save, +struct __user user_regs *new,unsigned long ip, +unsigned long sp,struct pt_regs *regs) +{ +return do_switch_mm (fd, save, new, ip, sp, regs); +} + +extern long do_vcpu (int mm_fd,struct vcpu_user __user *new, +struct pt_regs *regs); + +asmlinkage long sys_vcpu (int mm_fd,struct vcpu_user __user *new, +struct pt_regs *regs) +{ +int err; + + err =do_vcpu (mm_fd, new, regs); +if (err) +return err; + +return regs->ax; +}
arch/x86/kernel/syscall_table_32.S +3 -0
@@ -326,3 +326,6 @@ ENTRY(sys_call_table) .long sys_fallocate .long sys_timerfd_settime /* 325 */ .long sys_timerfd_gettime + .long sys_new_mm + .long sys_switch_mm + .long sys_vcpu
arch/x86/mm/fault.c +2 -0
@@ -173,6 +173,8 @@ static void force_sig_info_fault(int si_signo, int si_code, info.si_errno =0 ; info.si_code = si_code; info.si_addr = (void __user *)address; + info.si_trapno = tsk->thread.trap_no; + info.si_error = tsk->thread.error_code;force_sig_info (si_signo, &info, tsk); }
fs/proc/base.c +32 -0
@@ -2279,6 +2279,37 @@ static int proc_pid_io_accounting(struct task_struct *task, char *buffer) }#endif +static int proc_pid_mm_open (struct inode *inode,struct file *file) +{ +struct task_struct *task =pid_task (proc_pid (inode),PIDTYPE_PID ); +struct mm_struct *mm; + +if (task ==NULL ) +return -ENOENT ; + + mm =get_task_mm (task); +if (mm ==NULL ) +return -EINVAL ; + + file->private_data = mm; +return 0 ; +} + +static int proc_pid_mm_release (struct inode *inode,struct file *file) +{ +struct mm_struct *mm = file->private_data; + +if (mm !=NULL ) +mmput (mm); + +return 0 ; +} + +const struct file_operations proc_pid_mm_operations = { + .open = proc_pid_mm_open, + .release = proc_pid_mm_release, +}; +/* * Thread groups */
@@ -2350,6 +2381,7 @@ static const struct pid_entry tgid_base_stuff[] = {#ifdef CONFIG_TASK_IO_ACCOUNTING INF ("io" ,S_IRUGO , pid_io_accounting), #endif + REG("mm", S_IRUSR | S_IWUSR, pid_mm), }; static int proc_tgid_base_readdir(struct file * filp,
include/asm-generic/siginfo.h +6 -0
@@ -82,6 +82,9 @@ typedef struct siginfo {#ifdef __ARCH_SI_TRAPNOint _trapno;/* TRAP # which caused the signal */ #endif +#ifdef __ARCH_SI_ERROR +int _error;/* CPU error code */ +#endif } _sigfault;/* SIGPOLL */
@@ -112,6 +115,9 @@ typedef struct siginfo {#ifdef __ARCH_SI_TRAPNO#define si_trapno _sifields._sigfault._trapno#endif +#ifdef __ARCH_SI_ERROR +#define si_error _sifields._sigfault._error +#endif #define si_band _sifields._sigpoll._band#define si_fd _sifields._sigpoll._fd
Lines of this file are not shown. View the raw message.
include/asm-x86/ptrace.h +59 -1
60 lines not on this page · raw message
kernel/vcpu.c new file +129 -0
129 lines not on this page · raw message
mm/mmfs.c new file +215 -0
215 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Part of the diff is not shown here. View the raw message.