ptrace_multi: speedup for virtual machines (and debuggers) running on ptrace
Subsystems (6)
cover ptrace_multi: speedup for virtual machines (and debuggers) running on ptrace
This patch proposes/implements a new tag for ptrace: PTRACE_MULTI.
The patch is against linux-2.6.26-rc6, it applies with some line offset warnings to git2, too.
ptrace's PTRACE_MULTI tag sends multiple ptrace requests with a single system call. In fact, a process that uses ptrace() often needs to send several ptrace requests in a row, for example PTRACE_PEEKDATA for getting/setting some useful, even small pieces of data, or several registers or other ptrace commands.
You can see this fact using the following commands:
strace -o /tmp/trace strace ls
or
strace -o /tmp/trace linux ubd0=linux.img
(where linux is a UML kernel).
Looking into /tmp/trace you'll see runs of ptrace syscalls like:
(strace example) ...ptrace(PTRACE_PEEKUSER, 27177, 4*ORIG_EAX, [0xb]) = 0 ptrace(PTRACE_PEEKUSER, 27177, 4*EAX, [0xffffffda]) = 0 ptrace(PTRACE_PEEKUSER, 27177, 4*EBX, [0xbfe2d4b0]) = 0 ptrace(PTRACE_PEEKUSER, 27177, 4*ECX, [0xbfe2e698]) = 0 ptrace(PTRACE_PEEKUSER, 27177, 4*EDX, [0xbfe2e6a0]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2d4b0, [0x6e69622f]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2d4b4, [0x736c2f]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2e698, [0xbfe2f992]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2f990, [0x736c0065]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2f994, [0x45485300]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2e69c, [0]) = 0 ptrace(PTRACE_PEEKDATA, 27177, 0xbfe2e6a0, [0xbfe2f995]) = 0
...
(uml example)ptrace(PTRACE_SETREGS, 27086, 0, 0x82f16bc) = 0ptrace(PTRACE_CONT, 27086, 0, SIG_0) = 0
...
It is useful for these programs to run several ptrace operations while limiting the number of context switches.
For Virtual Machines limiting the number of context switches is a must, while a speed up for debuggers is not so crucial but it helps. Having a faster debugger should not be a problem, expecially when you've to fix large complex programs...
For User Mode Linux the number of context switches due to ptrace should be reduced 33% (2 ptraces each 3).
(look at the trace above, all the sequences PTRACE_SETREGS followed by PTRACE_CONT or PTRACE_SYSCALL or PTRACE_SYSEMU collapse in a single PTRACE_MULTI call).
Ptrace-multi gets a "struct ptrace_multi" array parameter (together with its number of elements). It is a similar concept/syntax to the management of buffers for readv or writev.
struct ptrace_multi {
long request;
long addr;
void *localaddr;
long length;
};Each "struct ptrace_multi" specifies a single standard ptrace request. So you can join several requests into one request array that will be passed through the "void* addr" parameter (the third) of ptrace(). request, addr and localaddr have the same meaning of ptrace's request, addr and data field for a single request.
Here is an example of PTRACE_MULTI call:
struct ptrace_multi req[] = {
{PTRACE_SETREGS, 0, regs, 0},
{PTRACE_SYSCALL, 0, 0, 0}};
if (ptrace(PTRACE_MULTI,pid,req,2))
/*ERROR*/The last field in the struct (length) specifies the numbers of requests to be accomplished by ptrace on a sequence of words/bytes.
- PTRACE_PEEKTEXT, PTRACE_PEEKDATA, PTRACE_PEEKUSR, PTRACE_POKETEXT, PTRACE_POKEDATA, PTRACE_POKEUSR requests load/store chunks
of registers, data, text code. "length" is the number of memory words to exchange. field==0 has the same meaning as field=1.
While normal ptrace requests can get a word at a time, I have added some other request for simplify the interface between kernel and applications that use ptrace(); these requests can get from user space more than one word at a time:
- PTRACE_PEEKCHARDATA and PTRACE_POKECHARDATA is used for transferring general data, like structure, buffer, and so on... lenth is in bytes.
- PTRACE_PEEKSTRINGDATA get strings from user space (using the new mm function:
access_process_vm_user) stopping the transfer if the '\0' string termination occur. length is in bytes.
Debuggers and virtual machines (like User Mode Linux, or Virtual Square's umview) and many other applications that are based on ptrace can get performance improvements by PTRACE_MULTI: the number of system calls (and context switches) decreases significantly.
This patch is architecture independent.
This patch is logically independent with ptrace_vm: applying this patch after ptrace_vm (and viceversa) generates just some warnings about line offsets.
I am submitting also a "proof of concept" patch that adds PTRACE_MULTI support for UML clients (this must be applied after ptrace_vm, otherwise there are some code patching rejection). I have optimized the code of UML in three ptrace interactions. In the tests I have done UML reduces the overall number of syscalls by about 15% and the perfomance increases around 5%. There are however other further optimizations that could be already applied. This latter patch /proof of concept is not complete, I have not coded the ppc support yet, where PTRACE_MULTI could have a sensible impact on speedup:
ptrace_{get,set}regs in arch/um/sys-ppc/ptrace_user.c function call tens of ptrace in a row.
The same feature has been implemented also for the new ptrace running on McGrath's utrace support. This specific patch can be found here:
http://view-os.svn.sourceforge.net/viewvc/view-os/trunk/kmview-kernel-module/kernel_patches/
renzo
Quoted 1 line · Renzo Davoli
This patch proposes/implements a new tag for ptrace:
PTRACE_MULTI.
I would just forget this. Linux, on purpose, hasn't implemented system call batching, in favor of trying to keep system call overhead low enough that it doesn't matter too much.
There's nothing special about ptrace - if you look around, you'll see other common sequences which could equally well be batched. So, even if batching were a good idea, you'd need a more general design.
One possibility is the syslets idea introduced a while back by Ingo and Zach Brown.
Another possibility is a more structured virtualization system which accomplishes the same thing, which I hadn't got around to posting to LKML yet.
The patch below implements sys_vcpu, which puts the current process into a restricted mode in which a system call or signal causes a return from sys_vcpu with the state at the time of the system call or signal saved in a buffer. This accomplishes the equivalent of PTRACE_GETREGS + PTRACE_SYSEMU + PTRACE_SETREGS in one system call.
Jeff
Signature · 12 lines
Work email - jdike at linux dot intel dot com commit 7b7254ed4c788b8dbfdca3d52f21e29ae935805c Author: Jeff Dike <[email protected]> Date: Thu May 15 14:54:03 2008 -0400 Host VCPU support This patch implements sys_vcpu, which allows a process to enter a new mode in which a signal or system call will cause a return to the original context.
arch/um/include/kern_util.h +1 -1
@@ -20,7 +20,7 @@ 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 void relay_signal (int sig,struct uml_pt_regs *regs);
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-x86_64/ptrace.h +2 -2
@@ -225,11 +225,11 @@ 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)
arch/um/kernel/process.c +1 -1
@@ -115,7 +115,7 @@ void interrupt_end(void) {if (need_resched ())schedule (); -if (test_tsk_thread_flag (current,TIF_SIGPENDING )) +if (test_thread_flag (TIF_SIGPENDING ))do_signal (); }
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/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 +18 -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 ) {
@@ -158,3 +158,11 @@ long sys_switch_mm(int fd, long __user *save, long __user *new, {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/os-Linux/skas/process.c +7 -1
@@ -446,8 +446,14 @@ void userspace(struct uml_pt_regs *regs) "with signal %d\n", sig);fatal_sigsegv (); } - pid = userspace_pid[0 ]; + +/* +* userspace_pid can change in in_interrupt since +* PTRACE_SWITCH_MM can cause a process to change +* address spaces +*/ interrupt_end (); + pid = userspace_pid[0 ];/* Avoid -ERESTARTSYS handling in host */ if (PT_SYSCALL_NR_OFFSET !=PT_SYSCALL_RET_OFFSET )
arch/um/sys-x86_64/syscall_table.c +1 -0
@@ -40,6 +40,7 @@#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/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 +24 -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
@@ -482,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 +20 -1
@@ -1453,6 +1453,8 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs, int error_code)force_sig_info (SIGTRAP , &info, tsk); } +extern int unvcpu (struct pt_regs *regs,siginfo_t *siginfo); +/* notification of system call entry/exit * - triggered by current->work.syscall_trace */
@@ -1489,6 +1491,14 @@ int do_syscall_trace(struct pt_regs *regs, int entryexit) goto out; } +if (test_thread_flag (TIF_VCPU )) { +if (entryexit) +return 0 ; + + regs->ax =unvcpu (regs,NULL ); +return 1 ; + } +if (!(current->ptrace &PT_PTRACED )) goto out;
@@ -1616,11 +1626,18 @@ static void syscall_trace(struct pt_regs *regs) } } -asmlinkage void syscall_trace_enter(struct pt_regs *regs) +extern int unvcpu (struct pt_regs *regs,siginfo_t *siginfo); + +asmlinkage int syscall_trace_enter(struct pt_regs *regs) {/* do the secure computing check first */ secure_computing (regs->orig_ax); +if (test_thread_flag (TIF_VCPU )) { + regs->ax =unvcpu (regs,NULL ); +return 1 ; + } +if (test_thread_flag (TIF_SYSCALL_TRACE ) && (current->ptrace &PT_PTRACED ))syscall_trace (regs);
@@ -1638,6 +1655,8 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs) regs->dx, regs->r10); } } + +return 0 ; } asmlinkage void syscall_trace_leave(struct pt_regs *regs)
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 +14 -0
@@ -273,3 +273,17 @@ asmlinkage long sys_switch_mm(struct pt_regs regs) (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 +15 -0
@@ -262,3 +262,18 @@ asmlinkage long sys_switch_mm(int fd, struct __user user_regs *save, {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 +1 -0
@@ -328,3 +328,4 @@ ENTRY(sys_call_table) .long sys_timerfd_gettime .long sys_new_mm .long sys_switch_mm + .long sys_vcpu
include/asm-um/desc.h +6 -0
@@ -1,6 +1,11 @@#ifndef __UM_DESC_H#define __UM_DESC_H +#ifdef CONFIG_64BIT +#define LM (info) (info)->lm == 0 +#else +#define LM (info) (1) +#endif /* Taken from asm-i386/desc.h, it's the only thing we need. The rest wouldn't * compile, and has never been used. */ #define LDT_empty (info) (\
@@ -11,6 +16,7 @@ (info)->seg_32bit == 0 && \ (info)->limit_in_pages == 0 && \ (info)->seg_not_present == 1 && \ + LM(info) && \ (info)->useable == 0 )#endif
include/asm-um/host_ldt-i386.h +2 -11
@@ -1,7 +1,8 @@#ifndef __ASM_HOST_LDT_I386_H#define __ASM_HOST_LDT_I386_H -#include "asm/arch/ldt.h" +#include <asm/desc.h> +#include <asm/arch/ldt.h> /* * macros stolen from include/asm-i386/desc.h
@@ -21,14 +22,4 @@ ((info)->useable << 20) | \ 0x7000) -#define LDT_empty (info) (\ - (info)->base_addr == 0 && \ - (info)->limit == 0 && \ - (info)->contents == 0 && \ - (info)->read_exec_only == 1 && \ - (info)->seg_32bit == 0 && \ - (info)->limit_in_pages == 0 && \ - (info)->seg_not_present == 1 && \ - (info)->useable == 0 ) -#endif
include/asm-um/host_ldt-x86_64.h +2 -12
@@ -1,7 +1,8 @@#ifndef __ASM_HOST_LDT_X86_64_H#define __ASM_HOST_LDT_X86_64_H -#include "asm/arch/ldt.h" +#include <asm/desc.h> +#include <asm/arch/ldt.h> /* * macros stolen from include/asm-x86_64/desc.h
@@ -24,15 +25,4 @@/* ((info)->lm << 21) | */ \ 0x7000) -#define LDT_empty (info) (\ - (info)->base_addr == 0 && \ - (info)->limit == 0 && \ - (info)->contents == 0 && \ - (info)->read_exec_only == 1 && \ - (info)->seg_32bit == 0 && \ - (info)->limit_in_pages == 0 && \ - (info)->seg_not_present == 1 && \ - (info)->useable == 0 && \ - (info)->lm == 0) -#endif
include/asm-um/thread_info.h +2 -0
@@ -83,6 +83,7 @@ static inline struct thread_info *current_thread_info(void)#define TIF_MEMDIE 5#define TIF_SYSCALL_AUDIT 6#define TIF_RESTORE_SIGMASK 7 +#define TIF_VCPU 8#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
@@ -91,5 +92,6 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_MEMDIE (1 << TIF_MEMDIE)#define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)#define _TIF_RESTORE_SIGMASK (1 << TIF_RESTORE_SIGMASK) +#define _TIF_VCPU (1 << TIF_VCPU)#endif
include/asm-x86/thread_info_32.h +2 -0
@@ -142,6 +142,7 @@ static inline struct thread_info *current_thread_info(void)#define TIF_DEBUGCTLMSR 22/* uses thread_struct.debugctlmsr */ #define TIF_DS_AREA_MSR 23/* uses thread_struct.ds_area_msr */ #define TIF_BTS_TRACE_TS 24/* record scheduling event timestamps */ +#define TIF_VCPU 25#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
@@ -161,6 +162,7 @@ static inline struct thread_info *current_thread_info(void)#define _TIF_DEBUGCTLMSR (1<<TIF_DEBUGCTLMSR)#define _TIF_DS_AREA_MSR (1<<TIF_DS_AREA_MSR)#define _TIF_BTS_TRACE_TS (1<<TIF_BTS_TRACE_TS) +#define _TIF_VCPU (1<<TIF_VCPU)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK \
include/asm-x86/thread_info_64.h +2 -0
@@ -125,6 +125,7 @@ static inline struct thread_info *stack_thread_info(void)#define TIF_DEBUGCTLMSR 25/* uses thread_struct.debugctlmsr */ #define TIF_DS_AREA_MSR 26/* uses thread_struct.ds_area_msr */ #define TIF_BTS_TRACE_TS 27/* record scheduling event timestamps */ +#define TIF_VCPU 28#define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)#define _TIF_SIGPENDING (1<<TIF_SIGPENDING)
@@ -146,6 +147,7 @@ static inline struct thread_info *stack_thread_info(void)#define _TIF_DEBUGCTLMSR (1<<TIF_DEBUGCTLMSR)#define _TIF_DS_AREA_MSR (1<<TIF_DS_AREA_MSR)#define _TIF_BTS_TRACE_TS (1<<TIF_BTS_TRACE_TS) +#define _TIF_VCPU (1<<TIF_VCPU)/* work to do on interrupt/exception return */ #define _TIF_WORK_MASK \
include/asm-x86/unistd_32.h +1 -0
@@ -334,6 +334,7 @@#define __NR_timerfd_gettime 326#define __NR_new_mm 327#define __NR_switch_mm 328 +#define __NR_vcpu 329#ifdef __KERNEL__
include/asm-x86/unistd_64.h +2 -0
@@ -643,6 +643,8 @@ __SYSCALL(__NR_timerfd_gettime, sys_timerfd_gettime) __SYSCALL(__NR_new_mm, sys_new_mm)#define __NR_switch_mm 289 __SYSCALL(__NR_switch_mm, stub_switch_mm) +#define __NR_vcpu 290 +__SYSCALL(__NR_vcpu, stub_vcpu)#ifndef __NO_STUBS
include/linux/init_task.h +1 -0
@@ -193,6 +193,7 @@ extern struct group_info init_groups; [PIDTYPE_SID] = INIT_PID_LINK(PIDTYPE_SID), \ }, \ .dirties =INIT_PROP_LOCAL_SINGLE (dirties), \ + .vcpu = NULL, \ INIT_IDS \ INIT_TRACE_IRQFLAGS \INIT_LOCKDEP \
include/linux/sched.h +20 -0
@@ -65,6 +65,7 @@ struct sched_param {#include <asm/page.h> #include <asm/ptrace.h> #include <asm/cputime.h> +#include <asm/ldt.h> #include <linux/smp.h> #include <linux/sem.h>
@@ -991,6 +992,24 @@ struct sched_rt_entity {#endif }; +struct vcpu_user { +enum {VCPU_SYSCALL ,VCPU_SIGNAL } event; +struct user_regs regs; +siginfo_t siginfo; +#if defined(CONFIG_X86_32 ) && !defined(CONFIG_UML ) +struct user_desc tls_array[GDT_ENTRY_TLS_ENTRIES ]; +#endif +}; + +struct vcpu { +struct vcpu_user user; +struct mm_struct *mm; +struct vcpu_user __user *state; +#if defined(CONFIG_X86_32 ) && !defined(CONFIG_UML ) +struct user_desc tls[GDT_ENTRY_TLS_ENTRIES ]; +#endif +}; +struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */ void *stack;
@@ -1103,6 +1122,7 @@ struct task_struct {cputime_t it_prof_expires, it_virt_expires;unsigned long long it_sched_expires;struct list_head cpu_timers[3 ]; +struct vcpu *vcpu;/* process credentials */ uid_t uid,euid,suid,fsuid;
kernel/Makefile +1 -1
@@ -9,7 +9,7 @@ obj-y = sched.o fork.o exec_domain.o panic.o printk.o profile.o \ rcupdate.o extable.o params.o posix-timers.o \ kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o mutex.o \ hrtimer.o rwsem.o nsproxy.o srcu.o \ - notifier.o ksysfs.o pm_qos_params.o + notifier.o ksysfs.o pm_qos_params.o vcpu.o obj-$(CONFIG_SYSCTL) += sysctl_check.o obj-$(CONFIG_STACKTRACE) += stacktrace.o
kernel/exit.c +5 -0
@@ -175,6 +175,11 @@ repeat:write_unlock_irq (&tasklist_lock);release_thread (p); + +if (p->vcpu && p->vcpu->mm) +mmput (p->vcpu->mm); +kfree (p->vcpu); +call_rcu (&p->rcu, delayed_put_task_struct); p = leader;
kernel/fork.c +2 -0
@@ -1086,6 +1086,8 @@ static struct task_struct *copy_process(unsigned long clone_flags,clear_tsk_thread_flag (p,TIF_SIGPENDING );init_sigpending (&p->pending); + p->vcpu =NULL ; + p->utime = cputime_zero; p->stime = cputime_zero; p->gtime = cputime_zero;
kernel/signal.c +3 -0
@@ -1785,6 +1785,9 @@ relock:if (!signr)break ;/* will return 0 */ +if (test_thread_flag (TIF_VCPU )) +break ; +if ((current->ptrace &PT_PTRACED ) && signr !=SIGKILL ) {ptrace_signal_deliver (regs, cookie);
kernel/vcpu.c new file +129 -0
129 lines not on this page · raw message