SKAS4 - Guest vcpu support
RFC PATCH 12/12 SKAS4 - Guest vcpu support
This patch implements sys_vcpu support in UML.
arch/um/include/kern_util.h +1 -1
@@ -22,7 +22,7 @@ extern void free_stack(unsigned long stack, int order);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/skas/skas.h +44 -1
84 lines not on this page · raw message
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 +1 -3
@@ -233,8 +233,6 @@ struct syscall_args {#define UPT_FAULTINFO (r) (&(r)->faultinfo) -static inline void arch_init_registers (int pid) -{ -} +extern void arch_init_registers (int pid);#endif
arch/um/kernel/process.c +12 -3
@@ -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_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/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/process.c +2 -1
@@ -55,7 +55,8 @@ int __init start_uml(void) {stack_protections ((unsigned long ) &cpu0_irqstack);set_sigstack (cpu0_irqstack,THREAD_SIZE ); -if (proc_mm || have_switch_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/os-Linux/skas/mem.c +5 -4
@@ -6,7 +6,6 @@#include <stddef.h> #include <unistd.h> #include <errno.h> -#include <signal.h> #include <string.h> #include <sys/mman.h> #include "init.h"
@@ -122,11 +121,12 @@ static long do_syscall_stub(struct mm_id *mm_idp, void **addr)return ret; } +static struct user_regs return_regs; +long do_syscall_stub_skas4 (struct mm_id *mm_idp,void **addr,unsigned long ip,unsigned long sp) {long ret; -struct user_regs return_regs;unsigned long *ptr;int err;sigset_t sigs, old;
@@ -221,9 +221,10 @@ long syscall_stub_data(struct mm_id *mm_idp, unsigned long *data,return ret; stack =check_init_stack (mm_idp, *addr); - *stack++ = data_count *sizeof (long ); + *stack = data_count; + *addr = stack++; -memcpy (stack, data, data_count *sizeof (long )); +memcpy (stack, data, data_count); *stub_addr = (void *)(((unsigned long ) stack & ~UM_KERN_PAGE_MASK ) +STUB_DATA );
arch/um/os-Linux/skas/process.c +83 -1
97 lines not on this page · raw message
arch/um/os-Linux/start_up.c +83 -3
128 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/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/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/syscalls.c +68 -51
129 lines not on this page · raw message
include/asm-um/processor-i386.h +11 -13
@@ -1,25 +1,19 @@/* -* Copyright (C) 2002 Jeff Dike ([email protected]) +* Copyright (C) 2002 - 2008 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ #ifndef __UM_PROCESSOR_I386_H #define __UM_PROCESSOR_I386_H -#include "linux/string.h" -#include "asm/host_ldt.h" -#include "asm/segment.h" - -extern int host_has_cmov; - -/* include faultinfo structure */ +#include <linux/kernel.h> +#include <linux/string.h> +#include <asm/host_ldt.h> +#include <asm/segment.h> #include "sysdep/faultinfo.h" +#include "sysdep/tls.h" -struct uml_tls_struct { - struct user_desc tls; - unsigned flushed:1; - unsigned present:1; -}; +extern int host_has_cmov; struct arch_thread { struct uml_tls_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
@@ -38,8 +32,12 @@ struct arch_thread {static inline void arch_flush_thread (struct arch_thread *thread) { +int i; +/* Clear any TLS still hanging */ memset (&thread->tls_array,0 ,sizeof (thread->tls_array)); +for (i =0 ; i <ARRAY_SIZE (thread->tls_array); i++) + thread->tls_array[i].tls.entry_number =GDT_ENTRY_TLS_MIN + i; } static inline void arch_copy_thread(struct arch_thread *from,
-------------------------------------------------------------------------
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