ia64/xen-unstable

changeset 7747:8a5dca8c1e8f

Merged.
author emellor@leeni.uk.xensource.com
date Thu Nov 10 11:43:26 2005 +0100 (2005-11-10)
parents ad6a208992cc 8f83f7ccf185
children 08f0066158c3 3920df5da25e
files
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S	Wed Nov 09 16:40:07 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/entry.S	Thu Nov 10 11:43:26 2005 +0100
     1.3 @@ -81,7 +81,7 @@ VM_MASK		= 0x00020000
     1.4  #define evtchn_upcall_pending		/* 0 */
     1.5  #define evtchn_upcall_mask		1
     1.6  
     1.7 -#define sizeof_vcpu_shift		3
     1.8 +#define sizeof_vcpu_shift		4
     1.9  
    1.10  #ifdef CONFIG_SMP
    1.11  #define preempt_disable(reg)	incl TI_preempt_count(reg)
    1.12 @@ -813,35 +813,9 @@ ENTRY(alignment_check)
    1.13  	pushl $do_alignment_check
    1.14  	jmp error_code
    1.15  
    1.16 -# This handler is special, because it gets an extra value on its stack,
    1.17 -# which is the linear faulting address.
    1.18 -# fastcall register usage:  %eax = pt_regs, %edx = error code,
    1.19 -#			    %ecx = fault address
    1.20  ENTRY(page_fault)
    1.21 -	pushl %ds
    1.22 -	pushl %eax
    1.23 -	xorl %eax, %eax
    1.24 -	pushl %ebp
    1.25 -	pushl %edi
    1.26 -	pushl %esi
    1.27 -	pushl %edx
    1.28 -	decl %eax			/* eax = -1 */
    1.29 -	pushl %ecx
    1.30 -	pushl %ebx
    1.31 -	cld
    1.32 -	pushl %es
    1.33 -#	UNWIND_ESPFIX_STACK
    1.34 -	popl %edi
    1.35 -	movl ES(%esp), %ecx		/* get the faulting address */
    1.36 -	movl ORIG_EAX(%esp), %edx	/* get the error code */
    1.37 -	movl %eax, ORIG_EAX(%esp)
    1.38 -	movl %edi, ES(%esp)
    1.39 -	movl $(__KERNEL_DS),%eax
    1.40 -	movl %eax, %ds
    1.41 -	movl %eax, %es
    1.42 -	movl %esp,%eax			/* pt_regs pointer */
    1.43 -	call do_page_fault
    1.44 -	jmp ret_from_exception
    1.45 +	pushl $do_page_fault
    1.46 +	jmp error_code
    1.47  
    1.48  #ifdef CONFIG_X86_MCE
    1.49  ENTRY(machine_check)
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Wed Nov 09 16:40:07 2005 +0100
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/traps.c	Thu Nov 10 11:43:26 2005 +0100
     2.3 @@ -972,7 +972,7 @@ void __init trap_init_f00f_bug(void)
     2.4  
     2.5  
     2.6  /*
     2.7 - * NB. All these are "trap gates" (i.e. events_mask isn't cleared) except
     2.8 + * NB. All these are "trap gates" (i.e. events_mask isn't set) except
     2.9   * for those that specify <dpl>|4 in the second field.
    2.10   */
    2.11  static trap_info_t trap_table[] = {
    2.12 @@ -988,7 +988,7 @@ static trap_info_t trap_table[] = {
    2.13  	{ 11, 0, __KERNEL_CS, (unsigned long)segment_not_present	},
    2.14  	{ 12, 0, __KERNEL_CS, (unsigned long)stack_segment		},
    2.15  	{ 13, 0, __KERNEL_CS, (unsigned long)general_protection		},
    2.16 -	{ 14, 0, __KERNEL_CS, (unsigned long)page_fault			},
    2.17 +	{ 14, 0|4, __KERNEL_CS, (unsigned long)page_fault		},
    2.18  	{ 15, 0, __KERNEL_CS, (unsigned long)fixup_4gb_segment		},
    2.19  	{ 16, 0, __KERNEL_CS, (unsigned long)coprocessor_error		},
    2.20  	{ 17, 0, __KERNEL_CS, (unsigned long)alignment_check		},
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Wed Nov 09 16:40:07 2005 +0100
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/fault.c	Thu Nov 10 11:43:26 2005 +0100
     3.3 @@ -279,15 +279,18 @@ static void dump_fault_path(unsigned lon
     3.4   *	bit 1 == 0 means read, 1 means write
     3.5   *	bit 2 == 0 means kernel, 1 means user-mode
     3.6   */
     3.7 -fastcall void do_page_fault(struct pt_regs *regs, unsigned long error_code,
     3.8 -			      unsigned long address)
     3.9 +fastcall void do_page_fault(struct pt_regs *regs, unsigned long error_code)
    3.10  {
    3.11  	struct task_struct *tsk;
    3.12  	struct mm_struct *mm;
    3.13  	struct vm_area_struct * vma;
    3.14 +	unsigned long address;
    3.15  	int write;
    3.16  	siginfo_t info;
    3.17  
    3.18 +	address = HYPERVISOR_shared_info->vcpu_data[
    3.19 +		smp_processor_id()].arch.cr2;
    3.20 +
    3.21  	/* Set the "privileged fault" bit to something sane. */
    3.22  	error_code &= ~4;
    3.23  	error_code |= (regs->xcs & 2) << 1;
    3.24 @@ -297,11 +300,10 @@ fastcall void do_page_fault(struct pt_re
    3.25  	if (notify_die(DIE_PAGE_FAULT, "page fault", regs, error_code, 14,
    3.26  					SIGSEGV) == NOTIFY_STOP)
    3.27  		return;
    3.28 -#if 0
    3.29 +
    3.30  	/* It's safe to allow irq's after cr2 has been saved */
    3.31 -	if (regs->eflags & (X86_EFLAGS_IF|VM_MASK))
    3.32 +	if ((uint8_t)(regs->xcs >> 16) == 0)
    3.33  		local_irq_enable();
    3.34 -#endif
    3.35  
    3.36  	tsk = current;
    3.37  
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/entry.S	Wed Nov 09 16:40:07 2005 +0100
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/entry.S	Thu Nov 10 11:43:26 2005 +0100
     4.3 @@ -874,42 +874,8 @@ 1:      RESTORE_ARGS
     4.4  	ret
     4.5  	CFI_ENDPROC
     4.6  
     4.7 -
     4.8 - /*
     4.9 - * Copy error_entry because of the different stack frame
    4.10 - */                        
    4.11  ENTRY(page_fault)
    4.12 -        movq (%rsp),%rcx
    4.13 -        movq 8(%rsp),%r11
    4.14 -        addq $0x10,%rsp         # now %rsp points to %cr2
    4.15 -        pushq %rax
    4.16 -        leaq do_page_fault(%rip),%rax
    4.17 -	cld	
    4.18 -	subq  $13*8,%rsp
    4.19 -	movq %rdx,12*8(%rsp)    # save %rdx
    4.20 -	movq 13*8(%rsp),%rdx	# load rax
    4.21 -	movq %rcx,11*8(%rsp)
    4.22 -	movq %rdx,10*8(%rsp)	# store rax
    4.23 -        movq %rsi,13*8(%rsp)    # now save %rsi
    4.24 -        movq 14*8(%rsp),%rdx    # load %cr2, 3rd argument
    4.25 -	movq %r8, 9*8(%rsp)
    4.26 -	movq %r9, 8*8(%rsp)
    4.27 -	movq %r10,7*8(%rsp)
    4.28 -	movq %r11,6*8(%rsp)
    4.29 -	movq %rbx,5*8(%rsp) 
    4.30 -	movq %rbp,4*8(%rsp) 
    4.31 -	movq %r12,3*8(%rsp) 
    4.32 -	movq %r13,2*8(%rsp) 
    4.33 -	movq %r14,1*8(%rsp) 
    4.34 -	movq %r15,(%rsp)
    4.35 -#if 0        
    4.36 -	cmpl $__KERNEL_CS,CS(%rsp)
    4.37 -	je  error_kernelspace
    4.38 -#endif
    4.39 -        /*
    4.40 -         * 1st and 2nd arguments are set by error_call_handler
    4.41 -         */
    4.42 -        jmp error_call_handler
    4.43 +	errorentry do_page_fault
    4.44  
    4.45  ENTRY(coprocessor_error)
    4.46  	zeroentry do_coprocessor_error
    4.47 @@ -948,24 +914,15 @@ ENTRY(nmi)
    4.48  paranoid_exit:
    4.49  	testl %ebx,%ebx				/* swapgs needed? */
    4.50  	jnz paranoid_restore
    4.51 +	testl $3,CS(%rsp)
    4.52 +	jnz   paranoid_userspace
    4.53  paranoid_swapgs:	
    4.54 -/*	swapgs */
    4.55 +	swapgs
    4.56  paranoid_restore:	
    4.57  	RESTORE_ALL 8
    4.58 -/*	iretq */
    4.59 +	iretq
    4.60  paranoid_userspace:	
    4.61  	GET_THREAD_INFO(%rcx)
    4.62 -#	movl threadinfo_flags(%rcx),%edx
    4.63 -#	testl $_TIF_NEED_RESCHED,%edx
    4.64 -#	jnz paranoid_resched
    4.65 -#	testl $(_TIF_SIGPENDING|_TIF_NOTIFY_RESUME|_TIF_SINGLESTEP),%edx
    4.66 -#	jnz paranoid_signal
    4.67 -#	jmp paranoid_swapgs
    4.68 -#paranoid_resched:		
    4.69 -#/*	sti */
    4.70 -#	call schedule
    4.71 -#	jmp paranoid_exit
    4.72 -#paranoid_signal:		
    4.73  	movl threadinfo_flags(%rcx),%ebx
    4.74  	andl $_TIF_WORK_MASK,%ebx
    4.75  	jz paranoid_swapgs
    4.76 @@ -975,13 +932,10 @@ paranoid_userspace:
    4.77  	testl $_TIF_NEED_RESCHED,%ebx
    4.78  	jnz paranoid_schedule
    4.79  	movl %ebx,%edx			/* arg3: thread flags */
    4.80 -/*	sti */
    4.81 -#	xorl %esi,%esi /* oldset */
    4.82 -#	movq %rsp,%rdi /* &pt_regs */
    4.83 +	sti
    4.84  	xorl %esi,%esi 			/* arg2: oldset */
    4.85  	movq %rsp,%rdi 			/* arg1: &pt_regs */
    4.86  	call do_notify_resume
    4.87 -#	jmp paranoid_exit
    4.88  	cli
    4.89  	jmp paranoid_userspace
    4.90  paranoid_schedule:
    4.91 @@ -1057,4 +1011,3 @@ ENTRY(machine_check)
    4.92  ENTRY(call_debug)
    4.93         zeroentry do_call_debug
    4.94  
    4.95 -
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/traps.c	Wed Nov 09 16:40:07 2005 +0100
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/traps.c	Thu Nov 10 11:43:26 2005 +0100
     5.3 @@ -89,7 +89,7 @@ int register_die_notifier(struct notifie
     5.4  
     5.5  static inline void conditional_sti(struct pt_regs *regs)
     5.6  {
     5.7 -	if (regs->eflags & X86_EFLAGS_IF)
     5.8 +	if ((uint8_t)(regs->cs >> 32) == 0)
     5.9  		local_irq_enable();
    5.10  }
    5.11  
    5.12 @@ -905,30 +905,33 @@ void do_call_debug(struct pt_regs *regs)
    5.13  }
    5.14  
    5.15  
    5.16 +/*
    5.17 + * NB. All these are "interrupt gates" (i.e. events_mask is set) because we
    5.18 + * specify <dpl>|4 in the second field.
    5.19 + */
    5.20  static trap_info_t trap_table[] = {
    5.21 -        {  0, 0, (__KERNEL_CS|0x3), (unsigned long)divide_error               },
    5.22 -        {  1, 0, (__KERNEL_CS|0x3), (unsigned long)debug                      },
    5.23 -        {  3, 3, (__KERNEL_CS|0x3), (unsigned long)int3                       },
    5.24 -        {  4, 3, (__KERNEL_CS|0x3), (unsigned long)overflow                   },
    5.25 -        {  5, 3, (__KERNEL_CS|0x3), (unsigned long)bounds                     },
    5.26 -        {  6, 0, (__KERNEL_CS|0x3), (unsigned long)invalid_op                 },
    5.27 -        {  7, 0, (__KERNEL_CS|0x3), (unsigned long)device_not_available       },
    5.28 -        {  9, 0, (__KERNEL_CS|0x3), (unsigned long)coprocessor_segment_overrun},
    5.29 -        { 10, 0, (__KERNEL_CS|0x3), (unsigned long)invalid_TSS                },
    5.30 -        { 11, 0, (__KERNEL_CS|0x3), (unsigned long)segment_not_present        },
    5.31 -        { 12, 0, (__KERNEL_CS|0x3), (unsigned long)stack_segment              },
    5.32 -        { 13, 0, (__KERNEL_CS|0x3), (unsigned long)general_protection         },
    5.33 -        { 14, 0, (__KERNEL_CS|0x3), (unsigned long)page_fault                 },
    5.34 -        { 15, 0, (__KERNEL_CS|0x3), (unsigned long)spurious_interrupt_bug     },
    5.35 -        { 16, 0, (__KERNEL_CS|0x3), (unsigned long)coprocessor_error          },
    5.36 -        { 17, 0, (__KERNEL_CS|0x3), (unsigned long)alignment_check            },
    5.37 +        {  0, 0|4, (__KERNEL_CS|0x3), (unsigned long)divide_error               },
    5.38 +        {  1, 0|4, (__KERNEL_CS|0x3), (unsigned long)debug                      },
    5.39 +        {  3, 3|4, (__KERNEL_CS|0x3), (unsigned long)int3                       },
    5.40 +        {  4, 3|4, (__KERNEL_CS|0x3), (unsigned long)overflow                   },
    5.41 +        {  5, 3|4, (__KERNEL_CS|0x3), (unsigned long)bounds                     },
    5.42 +        {  6, 0|4, (__KERNEL_CS|0x3), (unsigned long)invalid_op                 },
    5.43 +        {  7, 0|4, (__KERNEL_CS|0x3), (unsigned long)device_not_available       },
    5.44 +        {  9, 0|4, (__KERNEL_CS|0x3), (unsigned long)coprocessor_segment_overrun},
    5.45 +        { 10, 0|4, (__KERNEL_CS|0x3), (unsigned long)invalid_TSS                },
    5.46 +        { 11, 0|4, (__KERNEL_CS|0x3), (unsigned long)segment_not_present        },
    5.47 +        { 12, 0|4, (__KERNEL_CS|0x3), (unsigned long)stack_segment              },
    5.48 +        { 13, 0|4, (__KERNEL_CS|0x3), (unsigned long)general_protection         },
    5.49 +        { 14, 0|4, (__KERNEL_CS|0x3), (unsigned long)page_fault                 },
    5.50 +        { 15, 0|4, (__KERNEL_CS|0x3), (unsigned long)spurious_interrupt_bug     },
    5.51 +        { 16, 0|4, (__KERNEL_CS|0x3), (unsigned long)coprocessor_error          },
    5.52 +        { 17, 0|4, (__KERNEL_CS|0x3), (unsigned long)alignment_check            },
    5.53  #ifdef CONFIG_X86_MCE
    5.54 -        { 18, 0, (__KERNEL_CS|0x3), (unsigned long)machine_check              },
    5.55 +        { 18, 0|4, (__KERNEL_CS|0x3), (unsigned long)machine_check              },
    5.56  #endif
    5.57 -        { 19, 0, (__KERNEL_CS|0x3), (unsigned long)simd_coprocessor_error     },
    5.58 -        { SYSCALL_VECTOR, 3, (__KERNEL_CS|0x3), (unsigned long)system_call   },
    5.59 +        { 19, 0|4, (__KERNEL_CS|0x3), (unsigned long)simd_coprocessor_error     },
    5.60  #ifdef CONFIG_IA32_EMULATION
    5.61 -	{ IA32_SYSCALL_VECTOR, 3, (__KERNEL_CS|0x3), (unsigned long)ia32_syscall},
    5.62 +	{ IA32_SYSCALL_VECTOR, 3|4, (__KERNEL_CS|0x3), (unsigned long)ia32_syscall},
    5.63  #endif
    5.64          {  0, 0,           0, 0                                              }
    5.65  };
     6.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Wed Nov 09 16:40:07 2005 +0100
     6.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/xen_entry.S	Thu Nov 10 11:43:26 2005 +0100
     6.3 @@ -5,7 +5,7 @@
     6.4  #define evtchn_upcall_pending		0
     6.5  #define evtchn_upcall_mask		1
     6.6  
     6.7 -#define sizeof_vcpu_shift		4
     6.8 +#define sizeof_vcpu_shift		5
     6.9  
    6.10  #ifdef CONFIG_SMP
    6.11  //#define preempt_disable(reg)	incl threadinfo_preempt_count(reg)
     7.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c	Wed Nov 09 16:40:07 2005 +0100
     7.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c	Thu Nov 10 11:43:26 2005 +0100
     7.3 @@ -318,12 +318,12 @@ int exception_trace = 1;
     7.4   *	bit 2 == 0 means kernel, 1 means user-mode
     7.5   *      bit 3 == 1 means fault was an instruction fetch
     7.6   */
     7.7 -asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code,
     7.8 -       unsigned long address)
     7.9 +asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code)
    7.10  {
    7.11  	struct task_struct *tsk;
    7.12  	struct mm_struct *mm;
    7.13  	struct vm_area_struct * vma;
    7.14 +	unsigned long address;
    7.15  	const struct exception_table_entry *fixup;
    7.16  	int write;
    7.17  	siginfo_t info;
    7.18 @@ -342,11 +342,16 @@ asmlinkage void do_page_fault(struct pt_
    7.19  		}
    7.20  	}
    7.21  #endif
    7.22 +
    7.23 +	/* get the address */
    7.24 +	address = HYPERVISOR_shared_info->vcpu_data[
    7.25 +		smp_processor_id()].arch.cr2;
    7.26 +
    7.27  	if (notify_die(DIE_PAGE_FAULT, "page fault", regs, error_code, 14,
    7.28  					SIGSEGV) == NOTIFY_STOP)
    7.29  		return;
    7.30  
    7.31 -	if (likely(regs->eflags & X86_EFLAGS_IF))
    7.32 +	if (likely((uint8_t)(regs->cs >> 32) == 0))
    7.33  		local_irq_enable();
    7.34  
    7.35  	if (unlikely(page_fault_trace))
     8.1 --- a/xen/arch/x86/setup.c	Wed Nov 09 16:40:07 2005 +0100
     8.2 +++ b/xen/arch/x86/setup.c	Thu Nov 10 11:43:26 2005 +0100
     8.3 @@ -430,6 +430,10 @@ void __init __start_xen(multiboot_info_t
     8.4      /* Sanity check for unwanted bloat of dom0_op_t structure. */
     8.5      BUG_ON(sizeof(((dom0_op_t *)0)->u) != sizeof(((dom0_op_t *)0)->u.pad));
     8.6  
     8.7 +    BUG_ON(sizeof(start_info_t) > PAGE_SIZE);
     8.8 +    BUG_ON(sizeof(shared_info_t) > PAGE_SIZE);
     8.9 +    BUG_ON(sizeof(vcpu_info_t) != (sizeof(unsigned long) * 4));
    8.10 +
    8.11      init_frametable();
    8.12  
    8.13      end_boot_allocator();
     9.1 --- a/xen/arch/x86/shadow32.c	Wed Nov 09 16:40:07 2005 +0100
     9.2 +++ b/xen/arch/x86/shadow32.c	Thu Nov 10 11:43:26 2005 +0100
     9.3 @@ -997,7 +997,8 @@ int __shadow_mode_enable(struct domain *
     9.4      if ( new_modes & SHM_log_dirty )
     9.5      {
     9.6          ASSERT( !d->arch.shadow_dirty_bitmap );
     9.7 -        d->arch.shadow_dirty_bitmap_size = (d->max_pages + 63) & ~63;
     9.8 +        d->arch.shadow_dirty_bitmap_size = 
     9.9 +            (d->shared_info->arch.max_pfn +  63) & ~63;
    9.10          d->arch.shadow_dirty_bitmap = 
    9.11              xmalloc_array(unsigned long, d->arch.shadow_dirty_bitmap_size /
    9.12                                           (8 * sizeof(unsigned long)));
    9.13 @@ -1287,34 +1288,28 @@ static int shadow_mode_table_op(
    9.14          d->arch.shadow_dirty_net_count   = 0;
    9.15          d->arch.shadow_dirty_block_count = 0;
    9.16   
    9.17 -        if ( (d->max_pages > sc->pages) || 
    9.18 -             (sc->dirty_bitmap == NULL) || 
    9.19 +        if ( (sc->dirty_bitmap == NULL) || 
    9.20               (d->arch.shadow_dirty_bitmap == NULL) )
    9.21          {
    9.22              rc = -EINVAL;
    9.23              break;
    9.24          }
    9.25 - 
    9.26 -        sc->pages = d->max_pages;
    9.27 +
    9.28 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
    9.29 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
    9.30  
    9.31  #define chunk (8*1024) /* Transfer and clear in 1kB chunks for L1 cache. */
    9.32 -        for ( i = 0; i < d->max_pages; i += chunk )
    9.33 +        for ( i = 0; i < sc->pages; i += chunk )
    9.34          {
    9.35 -            int bytes = ((((d->max_pages - i) > chunk) ?
    9.36 -                          chunk : (d->max_pages - i)) + 7) / 8;
    9.37 +            int bytes = ((((sc->pages - i) > chunk) ?
    9.38 +                          chunk : (sc->pages - i)) + 7) / 8;
    9.39       
    9.40              if (copy_to_user(
    9.41                      sc->dirty_bitmap + (i/(8*sizeof(unsigned long))),
    9.42                      d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
    9.43                      bytes))
    9.44              {
    9.45 -                // copy_to_user can fail when copying to guest app memory.
    9.46 -                // app should zero buffer after mallocing, and pin it
    9.47                  rc = -EINVAL;
    9.48 -                memset(
    9.49 -                    d->arch.shadow_dirty_bitmap + 
    9.50 -                    (i/(8*sizeof(unsigned long))),
    9.51 -                    0, (d->max_pages/8) - (i/(8*sizeof(unsigned long))));
    9.52                  break;
    9.53              }
    9.54  
    9.55 @@ -1331,17 +1326,19 @@ static int shadow_mode_table_op(
    9.56          sc->stats.dirty_net_count   = d->arch.shadow_dirty_net_count;
    9.57          sc->stats.dirty_block_count = d->arch.shadow_dirty_block_count;
    9.58   
    9.59 -        if ( (d->max_pages > sc->pages) || 
    9.60 -             (sc->dirty_bitmap == NULL) || 
    9.61 +
    9.62 +        if ( (sc->dirty_bitmap == NULL) || 
    9.63               (d->arch.shadow_dirty_bitmap == NULL) )
    9.64          {
    9.65              rc = -EINVAL;
    9.66              break;
    9.67          }
    9.68   
    9.69 -        sc->pages = d->max_pages;
    9.70 -        if (copy_to_user(
    9.71 -            sc->dirty_bitmap, d->arch.shadow_dirty_bitmap, (d->max_pages+7)/8))
    9.72 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
    9.73 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
    9.74 +
    9.75 +        if (copy_to_user(sc->dirty_bitmap, 
    9.76 +                         d->arch.shadow_dirty_bitmap, (sc->pages+7)/8))
    9.77          {
    9.78              rc = -EINVAL;
    9.79              break;
    10.1 --- a/xen/arch/x86/shadow_public.c	Wed Nov 09 16:40:07 2005 +0100
    10.2 +++ b/xen/arch/x86/shadow_public.c	Thu Nov 10 11:43:26 2005 +0100
    10.3 @@ -1009,7 +1009,8 @@ int __shadow_mode_enable(struct domain *
    10.4      if ( new_modes & SHM_log_dirty )
    10.5      {
    10.6          ASSERT( !d->arch.shadow_dirty_bitmap );
    10.7 -        d->arch.shadow_dirty_bitmap_size = (d->max_pages + 63) & ~63;
    10.8 +        d->arch.shadow_dirty_bitmap_size = 
    10.9 +            (d->shared_info->arch.max_pfn +  63) & ~63;
   10.10          d->arch.shadow_dirty_bitmap = 
   10.11              xmalloc_array(unsigned long, d->arch.shadow_dirty_bitmap_size /
   10.12                            (8 * sizeof(unsigned long)));
   10.13 @@ -1163,34 +1164,29 @@ static int shadow_mode_table_op(
   10.14          d->arch.shadow_dirty_net_count   = 0;
   10.15          d->arch.shadow_dirty_block_count = 0;
   10.16   
   10.17 -        if ( (d->max_pages > sc->pages) || 
   10.18 -             (sc->dirty_bitmap == NULL) || 
   10.19 +
   10.20 +        if ( (sc->dirty_bitmap == NULL) || 
   10.21               (d->arch.shadow_dirty_bitmap == NULL) )
   10.22          {
   10.23              rc = -EINVAL;
   10.24              break;
   10.25          }
   10.26 - 
   10.27 -        sc->pages = d->max_pages;
   10.28 +
   10.29 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
   10.30 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
   10.31  
   10.32  #define chunk (8*1024) /* Transfer and clear in 1kB chunks for L1 cache. */
   10.33 -        for ( i = 0; i < d->max_pages; i += chunk )
   10.34 +        for ( i = 0; i < sc->pages; i += chunk )
   10.35          {
   10.36 -            int bytes = ((((d->max_pages - i) > chunk) ?
   10.37 -                          chunk : (d->max_pages - i)) + 7) / 8;
   10.38 +            int bytes = ((((sc->pages - i) > chunk) ?
   10.39 +                          chunk : (sc->pages - i)) + 7) / 8;
   10.40  
   10.41              if (copy_to_user(
   10.42                  sc->dirty_bitmap + (i/(8*sizeof(unsigned long))),
   10.43                  d->arch.shadow_dirty_bitmap +(i/(8*sizeof(unsigned long))),
   10.44                  bytes))
   10.45              {
   10.46 -                // copy_to_user can fail when copying to guest app memory.
   10.47 -                // app should zero buffer after mallocing, and pin it
   10.48                  rc = -EINVAL;
   10.49 -                memset(
   10.50 -                    d->arch.shadow_dirty_bitmap + 
   10.51 -                    (i/(8*sizeof(unsigned long))),
   10.52 -                    0, (d->max_pages/8) - (i/(8*sizeof(unsigned long))));
   10.53                  break;
   10.54              }
   10.55              memset(
   10.56 @@ -1206,17 +1202,18 @@ static int shadow_mode_table_op(
   10.57          sc->stats.dirty_net_count   = d->arch.shadow_dirty_net_count;
   10.58          sc->stats.dirty_block_count = d->arch.shadow_dirty_block_count;
   10.59   
   10.60 -        if ( (d->max_pages > sc->pages) || 
   10.61 -             (sc->dirty_bitmap == NULL) || 
   10.62 +        if ( (sc->dirty_bitmap == NULL) || 
   10.63               (d->arch.shadow_dirty_bitmap == NULL) )
   10.64          {
   10.65              rc = -EINVAL;
   10.66              break;
   10.67          }
   10.68   
   10.69 -        sc->pages = d->max_pages;
   10.70 -        if (copy_to_user(
   10.71 -            sc->dirty_bitmap, d->arch.shadow_dirty_bitmap, (d->max_pages+7)/8))
   10.72 +        if(sc->pages > d->arch.shadow_dirty_bitmap_size)
   10.73 +            sc->pages = d->arch.shadow_dirty_bitmap_size; 
   10.74 +
   10.75 +        if (copy_to_user(sc->dirty_bitmap, 
   10.76 +                         d->arch.shadow_dirty_bitmap, (sc->pages+7)/8))
   10.77          {
   10.78              rc = -EINVAL;
   10.79              break;
    11.1 --- a/xen/arch/x86/traps.c	Wed Nov 09 16:40:07 2005 +0100
    11.2 +++ b/xen/arch/x86/traps.c	Thu Nov 10 11:43:26 2005 +0100
    11.3 @@ -412,16 +412,16 @@ void propagate_page_fault(unsigned long 
    11.4      struct vcpu *v = current;
    11.5      struct trap_bounce *tb = &v->arch.trap_bounce;
    11.6  
    11.7 +    v->arch.guest_context.ctrlreg[2] = addr;
    11.8 +    v->vcpu_info->arch.cr2           = addr;
    11.9 +
   11.10      ti = &v->arch.guest_context.trap_ctxt[TRAP_page_fault];
   11.11 -    tb->flags = TBF_EXCEPTION | TBF_EXCEPTION_ERRCODE | TBF_EXCEPTION_CR2;
   11.12 -    tb->cr2        = addr;
   11.13 +    tb->flags = TBF_EXCEPTION | TBF_EXCEPTION_ERRCODE;
   11.14      tb->error_code = error_code;
   11.15      tb->cs         = ti->cs;
   11.16      tb->eip        = ti->address;
   11.17      if ( TI_GET_IF(ti) )
   11.18          tb->flags |= TBF_INTERRUPT;
   11.19 -
   11.20 -    v->arch.guest_context.ctrlreg[2] = addr;
   11.21  }
   11.22  
   11.23  static int handle_perdomain_mapping_fault(
   11.24 @@ -931,6 +931,7 @@ static int emulate_privileged_op(struct 
   11.25  
   11.26          case 2: /* Write CR2 */
   11.27              v->arch.guest_context.ctrlreg[2] = *reg;
   11.28 +            v->vcpu_info->arch.cr2           = *reg;
   11.29              break;
   11.30              
   11.31          case 3: /* Write CR3 */
    12.1 --- a/xen/arch/x86/x86_32/asm-offsets.c	Wed Nov 09 16:40:07 2005 +0100
    12.2 +++ b/xen/arch/x86/x86_32/asm-offsets.c	Thu Nov 10 11:43:26 2005 +0100
    12.3 @@ -75,7 +75,6 @@ void __dummy__(void)
    12.4      BLANK();
    12.5  
    12.6      OFFSET(TRAPBOUNCE_error_code, struct trap_bounce, error_code);
    12.7 -    OFFSET(TRAPBOUNCE_cr2, struct trap_bounce, cr2);
    12.8      OFFSET(TRAPBOUNCE_flags, struct trap_bounce, flags);
    12.9      OFFSET(TRAPBOUNCE_cs, struct trap_bounce, cs);
   12.10      OFFSET(TRAPBOUNCE_eip, struct trap_bounce, eip);
    13.1 --- a/xen/arch/x86/x86_32/entry.S	Wed Nov 09 16:40:07 2005 +0100
    13.2 +++ b/xen/arch/x86/x86_32/entry.S	Thu Nov 10 11:43:26 2005 +0100
    13.3 @@ -401,30 +401,25 @@ FLT16:  movl %eax,%gs:8(%esi)
    13.4          subl $4,%esi                    # push error_code onto guest frame
    13.5          movl TRAPBOUNCE_error_code(%edx),%eax
    13.6  FLT17:  movl %eax,%gs:(%esi)
    13.7 -        testb $TBF_EXCEPTION_CR2,%cl
    13.8 -        jz   2f
    13.9 -        subl $4,%esi                    # push %cr2 onto guest frame
   13.10 -        movl TRAPBOUNCE_cr2(%edx),%eax
   13.11 -FLT18:  movl %eax,%gs:(%esi)
   13.12  1:      testb $TBF_FAILSAFE,%cl
   13.13          jz   2f
   13.14          subl $16,%esi                # add DS/ES/FS/GS to failsafe stack frame
   13.15          testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
   13.16          jz   nvm86_2
   13.17          xorl %eax,%eax               # VM86: we write zero selector values
   13.18 -FLT19:  movl %eax,%gs:(%esi) 
   13.19 -FLT20:  movl %eax,%gs:4(%esi)
   13.20 -FLT21:  movl %eax,%gs:8(%esi) 
   13.21 -FLT22:  movl %eax,%gs:12(%esi)
   13.22 +FLT18:  movl %eax,%gs:(%esi) 
   13.23 +FLT19:  movl %eax,%gs:4(%esi)
   13.24 +FLT20:  movl %eax,%gs:8(%esi) 
   13.25 +FLT21:  movl %eax,%gs:12(%esi)
   13.26          jmp  2f
   13.27  nvm86_2:movl UREGS_ds+4(%esp),%eax   # non-VM86: write real selector values
   13.28 -FLT23:  movl %eax,%gs:(%esi) 
   13.29 +FLT22:  movl %eax,%gs:(%esi) 
   13.30          movl UREGS_es+4(%esp),%eax
   13.31 -FLT24:  movl %eax,%gs:4(%esi)
   13.32 +FLT23:  movl %eax,%gs:4(%esi)
   13.33          movl UREGS_fs+4(%esp),%eax
   13.34 -FLT25:  movl %eax,%gs:8(%esi) 
   13.35 +FLT24:  movl %eax,%gs:8(%esi) 
   13.36          movl UREGS_gs+4(%esp),%eax
   13.37 -FLT26:  movl %eax,%gs:12(%esi)
   13.38 +FLT25:  movl %eax,%gs:12(%esi)
   13.39  2:      testl $X86_EFLAGS_VM,UREGS_eflags+4(%esp)
   13.40          jz   nvm86_3
   13.41          xorl %eax,%eax      /* zero DS-GS, just as a real CPU would */
   13.42 @@ -456,7 +451,6 @@ nvm86_3:/* Rewrite our stack frame and r
   13.43          .long FLT20,domain_crash_synchronous , FLT21,domain_crash_synchronous
   13.44          .long FLT22,domain_crash_synchronous , FLT23,domain_crash_synchronous
   13.45          .long FLT24,domain_crash_synchronous , FLT25,domain_crash_synchronous
   13.46 -        .long FLT26,domain_crash_synchronous
   13.47  .previous
   13.48  
   13.49          ALIGN
    14.1 --- a/xen/arch/x86/x86_64/asm-offsets.c	Wed Nov 09 16:40:07 2005 +0100
    14.2 +++ b/xen/arch/x86/x86_64/asm-offsets.c	Thu Nov 10 11:43:26 2005 +0100
    14.3 @@ -75,7 +75,6 @@ void __dummy__(void)
    14.4      BLANK();
    14.5  
    14.6      OFFSET(TRAPBOUNCE_error_code, struct trap_bounce, error_code);
    14.7 -    OFFSET(TRAPBOUNCE_cr2, struct trap_bounce, cr2);
    14.8      OFFSET(TRAPBOUNCE_flags, struct trap_bounce, flags);
    14.9      OFFSET(TRAPBOUNCE_cs, struct trap_bounce, cs);
   14.10      OFFSET(TRAPBOUNCE_eip, struct trap_bounce, eip);
    15.1 --- a/xen/arch/x86/x86_64/entry.S	Wed Nov 09 16:40:07 2005 +0100
    15.2 +++ b/xen/arch/x86/x86_64/entry.S	Thu Nov 10 11:43:26 2005 +0100
    15.3 @@ -370,27 +370,22 @@ FLT6:   movq  %rax,(%rsi)               
    15.4          subq  $8,%rsi
    15.5          movl  TRAPBOUNCE_error_code(%rdx),%eax
    15.6  FLT7:   movq  %rax,(%rsi)               # ERROR CODE
    15.7 -        testb $TBF_EXCEPTION_CR2,%cl
    15.8 -        jz    2f
    15.9 -        subq  $8,%rsi
   15.10 -        movq  TRAPBOUNCE_cr2(%rdx),%rax
   15.11 -FLT8:   movq  %rax,(%rsi)               # CR2
   15.12  1:      testb $TBF_FAILSAFE,%cl
   15.13          jz    2f
   15.14          subq  $32,%rsi
   15.15          movl  %gs,%eax
   15.16 -FLT9:   movq  %rax,24(%rsi)             # GS
   15.17 +FLT8:   movq  %rax,24(%rsi)             # GS
   15.18          movl  %fs,%eax
   15.19 -FLT10:  movq  %rax,16(%rsi)             # FS
   15.20 +FLT9:   movq  %rax,16(%rsi)             # FS
   15.21          movl  %es,%eax
   15.22 -FLT11:  movq  %rax,8(%rsi)              # ES
   15.23 +FLT10:  movq  %rax,8(%rsi)              # ES
   15.24          movl  %ds,%eax
   15.25 -FLT12:  movq  %rax,(%rsi)               # DS
   15.26 +FLT11:  movq  %rax,(%rsi)               # DS
   15.27  2:      subq  $16,%rsi
   15.28          movq  UREGS_r11+8(%rsp),%rax
   15.29 -FLT13:  movq  %rax,8(%rsi)              # R11
   15.30 +FLT12:  movq  %rax,8(%rsi)              # R11
   15.31          movq  UREGS_rcx+8(%rsp),%rax
   15.32 -FLT14:  movq  %rax,(%rsi)               # RCX
   15.33 +FLT13:  movq  %rax,(%rsi)               # RCX
   15.34          /* Rewrite our stack frame and return to guest-OS mode. */
   15.35          /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
   15.36          movl  $TRAP_syscall,UREGS_entry_vector+8(%rsp)
   15.37 @@ -411,7 +406,6 @@ FLT14:  movq  %rax,(%rsi)               
   15.38          .quad  FLT8,domain_crash_synchronous ,  FLT9,domain_crash_synchronous
   15.39          .quad FLT10,domain_crash_synchronous , FLT11,domain_crash_synchronous
   15.40          .quad FLT12,domain_crash_synchronous , FLT13,domain_crash_synchronous
   15.41 -        .quad FLT14,domain_crash_synchronous
   15.42  .previous
   15.43  
   15.44          ALIGN
    16.1 --- a/xen/include/asm-x86/domain.h	Wed Nov 09 16:40:07 2005 +0100
    16.2 +++ b/xen/include/asm-x86/domain.h	Thu Nov 10 11:43:26 2005 +0100
    16.3 @@ -8,7 +8,6 @@
    16.4  
    16.5  struct trap_bounce {
    16.6      unsigned long  error_code;
    16.7 -    unsigned long  cr2;
    16.8      unsigned short flags; /* TBF_ */
    16.9      unsigned short cs;
   16.10      unsigned long  eip;
    17.1 --- a/xen/include/asm-x86/processor.h	Wed Nov 09 16:40:07 2005 +0100
    17.2 +++ b/xen/include/asm-x86/processor.h	Thu Nov 10 11:43:26 2005 +0100
    17.3 @@ -121,7 +121,6 @@
    17.4  /* 'trap_bounce' flags values */
    17.5  #define TBF_EXCEPTION          1
    17.6  #define TBF_EXCEPTION_ERRCODE  2
    17.7 -#define TBF_EXCEPTION_CR2      4
    17.8  #define TBF_INTERRUPT          8
    17.9  #define TBF_FAILSAFE          16
   17.10  
    18.1 --- a/xen/include/public/arch-ia64.h	Wed Nov 09 16:40:07 2005 +0100
    18.2 +++ b/xen/include/public/arch-ia64.h	Thu Nov 10 11:43:26 2005 +0100
    18.3 @@ -271,12 +271,10 @@ typedef struct {
    18.4  
    18.5  typedef mapped_regs_t vpd_t;
    18.6  
    18.7 -#define __ARCH_HAS_VCPU_INFO
    18.8 -
    18.9  typedef struct {
   18.10      unsigned int flags;
   18.11      unsigned long start_info_pfn;
   18.12 -} arch_shared_info_t;  // DON'T PACK 
   18.13 +} arch_shared_info_t;
   18.14  
   18.15  typedef struct vcpu_guest_context {
   18.16  #define VGCF_FPU_VALID (1<<0)
    19.1 --- a/xen/include/public/arch-x86_32.h	Wed Nov 09 16:40:07 2005 +0100
    19.2 +++ b/xen/include/public/arch-x86_32.h	Thu Nov 10 11:43:26 2005 +0100
    19.3 @@ -132,6 +132,11 @@ typedef struct arch_shared_info {
    19.4      unsigned long pfn_to_mfn_frame_list_list; 
    19.5  } arch_shared_info_t;
    19.6  
    19.7 +typedef struct {
    19.8 +    unsigned long cr2;
    19.9 +    unsigned long pad; /* sizeof(vcpu_info_t) == 16 */
   19.10 +} arch_vcpu_info_t;
   19.11 +
   19.12  #endif
   19.13  
   19.14  #endif
    20.1 --- a/xen/include/public/arch-x86_64.h	Wed Nov 09 16:40:07 2005 +0100
    20.2 +++ b/xen/include/public/arch-x86_64.h	Thu Nov 10 11:43:26 2005 +0100
    20.3 @@ -201,6 +201,11 @@ typedef struct arch_shared_info {
    20.4      unsigned long pfn_to_mfn_frame_list_list; 
    20.5  } arch_shared_info_t;
    20.6  
    20.7 +typedef struct {
    20.8 +    unsigned long cr2;
    20.9 +    unsigned long pad; /* sizeof(vcpu_info_t) == 32 */
   20.10 +} arch_vcpu_info_t;
   20.11 +
   20.12  #endif /* !__ASSEMBLY__ */
   20.13  
   20.14  #endif
    21.1 --- a/xen/include/public/dom0_ops.h	Wed Nov 09 16:40:07 2005 +0100
    21.2 +++ b/xen/include/public/dom0_ops.h	Thu Nov 10 11:43:26 2005 +0100
    21.3 @@ -19,7 +19,7 @@
    21.4   * This makes sure that old versions of dom0 tools will stop working in a
    21.5   * well-defined way (rather than crashing the machine, for instance).
    21.6   */
    21.7 -#define DOM0_INTERFACE_VERSION   0xAAAA1011
    21.8 +#define DOM0_INTERFACE_VERSION   0xAAAA1012
    21.9  
   21.10  /************************************************************************/
   21.11  
    22.1 --- a/xen/include/public/xen.h	Wed Nov 09 16:40:07 2005 +0100
    22.2 +++ b/xen/include/public/xen.h	Thu Nov 10 11:43:26 2005 +0100
    22.3 @@ -299,9 +299,7 @@ typedef struct vcpu_info {
    22.4      uint8_t evtchn_upcall_pending;
    22.5      uint8_t evtchn_upcall_mask;
    22.6      unsigned long evtchn_pending_sel;
    22.7 -#ifdef __ARCH_HAS_VCPU_INFO
    22.8      arch_vcpu_info_t arch;
    22.9 -#endif
   22.10  } vcpu_info_t;
   22.11  
   22.12  typedef struct vcpu_time_info {