ia64/xen-unstable
changeset 400:9a33c17a47a6
bitkeeper revision 1.184.1.7 (3ead2bb0z-Au3xm19OXW9JIFLwKvPw)
Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
Merge scramble.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into scramble.cl.cam.ac.uk:/local/scratch/kaf24/xeno
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Mon Apr 28 13:25:04 2003 +0000 (2003-04-28) |
parents | a8cf7c3a5af3 47d2a4460ed1 |
children | b695c18bad2d |
files | xen/arch/i386/entry.S xen/arch/i386/process.c xen/common/domain.c xen/include/hypervisor-ifs/hypervisor-if.h xen/include/xeno/sched.h xenolinux-2.4.21-pre4-sparse/arch/xeno/kernel/ioport.c xenolinux-2.4.21-pre4-sparse/arch/xeno/kernel/process.c xenolinux-2.4.21-pre4-sparse/include/asm-xeno/hypervisor.h |
line diff
1.1 --- a/xen/arch/i386/entry.S Mon Apr 28 13:12:52 2003 +0000 1.2 +++ b/xen/arch/i386/entry.S Mon Apr 28 13:25:04 2003 +0000 1.3 @@ -647,6 +647,7 @@ ENTRY(hypervisor_call_table) 1.4 .long SYMBOL_NAME(do_dom_mem_op) 1.5 .long SYMBOL_NAME(do_multicall) 1.6 .long SYMBOL_NAME(do_kbd_op) 1.7 + .long SYMBOL_NAME(do_iopl) 1.8 .rept NR_syscalls-((.-hypervisor_call_table)/4) 1.9 .long SYMBOL_NAME(sys_ni_syscall) 1.10 .endr
2.1 --- a/xen/arch/i386/process.c Mon Apr 28 13:12:52 2003 +0000 2.2 +++ b/xen/arch/i386/process.c Mon Apr 28 13:25:04 2003 +0000 2.3 @@ -31,6 +31,9 @@ 2.4 #include <xeno/irq.h> 2.5 #include <xeno/event.h> 2.6 2.7 +#define GET_SYSCALL_REGS(_p) \ 2.8 + (((struct pt_regs *)(THREAD_SIZE + (unsigned long)(_p))) - 1) 2.9 + 2.10 asmlinkage void ret_from_newdomain(void) __asm__("ret_from_newdomain"); 2.11 2.12 int hlt_counter; 2.13 @@ -247,9 +250,7 @@ void new_thread(struct task_struct *p, 2.14 unsigned long start_stack, 2.15 unsigned long start_info) 2.16 { 2.17 - struct pt_regs * regs; 2.18 - 2.19 - regs = ((struct pt_regs *) (THREAD_SIZE + (unsigned long) p)) - 1; 2.20 + struct pt_regs *regs = GET_SYSCALL_REGS(p); 2.21 memset(regs, 0, sizeof(*regs)); 2.22 2.23 /* 2.24 @@ -345,3 +346,12 @@ void __switch_to(struct task_struct *pre 2.25 } 2.26 2.27 } 2.28 + 2.29 + 2.30 +long do_iopl(unsigned int new_iopl) 2.31 +{ 2.32 + struct pt_regs *regs = GET_SYSCALL_REGS(current); 2.33 + if ( !IS_PRIV(current) ) return -EPERM; 2.34 + regs->eflags = (regs->eflags & 0xffffcfff) | ((new_iopl&3) << 12); 2.35 + return 0; 2.36 +}
3.1 --- a/xen/common/domain.c Mon Apr 28 13:12:52 2003 +0000 3.2 +++ b/xen/common/domain.c Mon Apr 28 13:25:04 2003 +0000 3.3 @@ -357,6 +357,9 @@ int final_setup_guestos(struct task_stru 3.4 virt_startinfo_addr->mod_start = meminfo->virt_mod_addr; 3.5 virt_startinfo_addr->mod_len = meminfo->virt_mod_len; 3.6 3.7 + virt_startinfo_addr->dom_id = p->domain; 3.8 + virt_startinfo_addr->flags = IS_PRIV(p) ? SIF_PRIVILEGED : 0; 3.9 + 3.10 if( virt_startinfo_addr->mod_len ) 3.11 printk("Initrd module present %08lx (%08lx)\n", 3.12 virt_startinfo_addr->mod_start, 3.13 @@ -618,6 +621,9 @@ int setup_guestos(struct task_struct *p, 3.14 virt_startinfo_address->pt_base = virt_load_address + 3.15 ((p->tot_pages - 1) << PAGE_SHIFT); 3.16 3.17 + virt_startinfo_address->dom_id = p->domain; 3.18 + virt_startinfo_address->flags = IS_PRIV(p) ? SIF_PRIVILEGED : 0; 3.19 + 3.20 if ( initrd_len ) 3.21 { 3.22 virt_startinfo_address->mod_start = (unsigned long)dst-initrd_len;
4.1 --- a/xen/include/hypervisor-ifs/hypervisor-if.h Mon Apr 28 13:12:52 2003 +0000 4.2 +++ b/xen/include/hypervisor-ifs/hypervisor-if.h Mon Apr 28 13:25:04 2003 +0000 4.3 @@ -48,6 +48,7 @@ 4.4 #define __HYPERVISOR_dom_mem_op 17 4.5 #define __HYPERVISOR_multicall 18 4.6 #define __HYPERVISOR_kbd_op 19 4.7 +#define __HYPERVISOR_iopl 20 4.8 4.9 /* And the trap vector is... */ 4.10 #define TRAP_INSTR "int $0x82" 4.11 @@ -242,9 +243,14 @@ typedef struct start_info_st { 4.12 unsigned long net_rings[MAX_DOMAIN_VIFS]; 4.13 /* Machine address of block-device ring. Will be page aligned. */ 4.14 unsigned long blk_ring; 4.15 + unsigned int dom_id; 4.16 + unsigned long flags; 4.17 unsigned char cmd_line[1]; /* variable-length */ 4.18 } start_info_t; 4.19 4.20 +/* These flags are passed in the 'flags' field of start_info_t. */ 4.21 +#define SIF_PRIVILEGED 1 /* Is thie domain privileged? */ 4.22 + 4.23 /* For use in guest OSes. */ 4.24 extern shared_info_t *HYPERVISOR_shared_info; 4.25
5.1 --- a/xen/include/xeno/sched.h Mon Apr 28 13:12:52 2003 +0000 5.2 +++ b/xen/include/xeno/sched.h Mon Apr 28 13:25:04 2003 +0000 5.3 @@ -60,8 +60,11 @@ extern struct mm_struct init_mm; 5.4 #include <xeno/block.h> 5.5 #include <xeno/segment.h> 5.6 5.7 -struct task_struct { 5.8 +/* SMH: replace below when have explicit 'priv' flag or bitmask */ 5.9 +#define IS_PRIV(_p) ((_p)->domain == 0) 5.10 5.11 +struct task_struct 5.12 +{ 5.13 /* 5.14 * DO NOT CHANGE THE ORDER OF THE FOLLOWING. 5.15 * Their offsets are hardcoded in entry.S 5.16 @@ -72,10 +75,6 @@ struct task_struct { 5.17 int hyp_events; /* 08: pending intra-Xen events */ 5.18 unsigned int domain; /* 12: domain id */ 5.19 5.20 - // SMH: replace below when have explicit 'priv' flag or bitmask 5.21 -#define IS_PRIV(_p) ((_p)->domain == 0) 5.22 - 5.23 - 5.24 /* An unsafe pointer into a shared data area. */ 5.25 shared_info_t *shared_info; /* 16: shared data area */ 5.26
6.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/kernel/ioport.c Mon Apr 28 13:12:52 2003 +0000 6.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/kernel/ioport.c Mon Apr 28 13:25:04 2003 +0000 6.3 @@ -7,13 +7,30 @@ 6.4 6.5 asmlinkage int sys_ioperm(unsigned long from, unsigned long num, int turn_on) 6.6 { 6.7 - /* No IO permission! */ 6.8 - return -EPERM; 6.9 + /* No IO permission! Selective IO perms aren't virtualised yet. */ 6.10 + return -EPERM; 6.11 } 6.12 6.13 6.14 asmlinkage int sys_iopl(unsigned long unused) 6.15 { 6.16 - /* The hypervisor won't allow it! */ 6.17 - return -EPERM; 6.18 + struct pt_regs *regs = (struct pt_regs *)&unused; 6.19 + unsigned int level = regs->ebx; 6.20 + unsigned int old = (regs->eflags >> 12) & 3; 6.21 + 6.22 + if ( !(start_info.flags & SIF_PRIVILEGED) ) 6.23 + return -EPERM; 6.24 + 6.25 + if ( level > 3 ) 6.26 + return -EINVAL; 6.27 + if ( (level > old) && !capable(CAP_SYS_RAWIO) ) 6.28 + return -EPERM; 6.29 + 6.30 + /* Change the one on our stack for sanity's sake. */ 6.31 + regs->eflags = (regs->eflags & 0xffffcfff) | (level << 12); 6.32 + 6.33 + /* Force the change at ring 0. */ 6.34 + HYPERVISOR_iopl(level); 6.35 + 6.36 + return 0; 6.37 }
7.1 --- a/xenolinux-2.4.21-pre4-sparse/arch/xeno/kernel/process.c Mon Apr 28 13:12:52 2003 +0000 7.2 +++ b/xenolinux-2.4.21-pre4-sparse/arch/xeno/kernel/process.c Mon Apr 28 13:25:04 2003 +0000 7.3 @@ -363,7 +363,12 @@ void __switch_to(struct task_struct *pre 7.4 } 7.5 7.6 if ( next->esp0 != 0 ) 7.7 + { 7.8 queue_multicall2(__HYPERVISOR_stack_switch, __KERNEL_DS, next->esp0); 7.9 + /* Next call will silently fail if we are a non-privileged guest OS. */ 7.10 + queue_multicall1(__HYPERVISOR_iopl, 7.11 + ((((struct pt_regs *)next->esp0)-1)->eflags>>12)&3); 7.12 + } 7.13 7.14 /* EXECUTE ALL TASK SWITCH XEN SYSCALLS AT THIS POINT. */ 7.15 execute_multicall_list();
8.1 --- a/xenolinux-2.4.21-pre4-sparse/include/asm-xeno/hypervisor.h Mon Apr 28 13:12:52 2003 +0000 8.2 +++ b/xenolinux-2.4.21-pre4-sparse/include/asm-xeno/hypervisor.h Mon Apr 28 13:25:04 2003 +0000 8.3 @@ -353,7 +353,6 @@ static inline int HYPERVISOR_multicall(v 8.4 return ret; 8.5 } 8.6 8.7 - 8.8 static inline long HYPERVISOR_kbd_op(unsigned char op, unsigned char val) 8.9 { 8.10 int ret; 8.11 @@ -365,4 +364,15 @@ static inline long HYPERVISOR_kbd_op(uns 8.12 return ret; 8.13 } 8.14 8.15 +static inline long HYPERVISOR_iopl(unsigned int new_iopl) 8.16 +{ 8.17 + int ret; 8.18 + __asm__ __volatile__ ( 8.19 + TRAP_INSTR 8.20 + : "=a" (ret) : "0" (__HYPERVISOR_iopl), 8.21 + "b" (new_iopl) ); 8.22 + 8.23 + return ret; 8.24 +} 8.25 + 8.26 #endif /* __HYPERVISOR_H__ */