ia64/xen-unstable

changeset 5551:30082c72ed69

bitkeeper revision 1.1733 (42ba827d4k5gz1Dasgd0gorMu-SSmQ)

The 32-bit x86 LTP exposed bugs with LDT handling with x86_64 Xen and
XenLinux:
- fill the code for arbitrary_virt_to_machine(XenLinux)
- set 64-bit value for the base address for LDT (Xen)
- fix a bug (64-bit cleanup) in map_ldt_shadow_page (Xen)

Signed-off-by: Jun Nakajima <jun.nakajima@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu Jun 23 09:35:57 2005 +0000 (2005-06-23)
parents 25ceeee71ab6
children 0f6d2253b0fc
files linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/ldt.c linux-2.6.11-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h xen/arch/x86/mm.c xen/include/asm-x86/ldt.h
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/ldt.c	Thu Jun 23 09:24:21 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/arch/xen/x86_64/kernel/ldt.c	Thu Jun 23 09:35:57 2005 +0000
     1.3 @@ -62,7 +62,6 @@ static int alloc_ldt(mm_context_t *pc, u
     1.4  	if (reload) {
     1.5  #ifdef CONFIG_SMP
     1.6  		cpumask_t mask;
     1.7 -
     1.8  		preempt_disable();
     1.9  #endif
    1.10  		make_pages_readonly(pc->ldt, (pc->size * LDT_ENTRY_SIZE) /
    1.11 @@ -73,8 +72,6 @@ static int alloc_ldt(mm_context_t *pc, u
    1.12  		if (!cpus_equal(current->mm->cpu_vm_mask, mask))
    1.13  			smp_call_function(flush_ldt, NULL, 1, 1);
    1.14  		preempt_enable();
    1.15 -#else
    1.16 -		load_LDT(pc);
    1.17  #endif
    1.18  	}
    1.19  	if (oldsize) {
    1.20 @@ -188,13 +185,12 @@ static int write_ldt(void __user * ptr, 
    1.21  {
    1.22  	struct task_struct *me = current;
    1.23  	struct mm_struct * mm = me->mm;
    1.24 -	unsigned long entry = 0, *lp;
    1.25 +	__u32 entry_1, entry_2, *lp;
    1.26  	unsigned long mach_lp;
    1.27  	int error;
    1.28  	struct user_desc ldt_info;
    1.29  
    1.30  	error = -EINVAL;
    1.31 -
    1.32  	if (bytecount != sizeof(ldt_info))
    1.33  		goto out;
    1.34  	error = -EFAULT; 	
    1.35 @@ -218,26 +214,26 @@ static int write_ldt(void __user * ptr, 
    1.36  			goto out_unlock;
    1.37  	}
    1.38  
    1.39 -	lp = (unsigned long *)((ldt_info.entry_number << 3) + (char *) mm->context.ldt);
    1.40 -	mach_lp = arbitrary_virt_to_machine(lp);
    1.41 +	lp = (__u32 *) ((ldt_info.entry_number << 3) + (char *) mm->context.ldt);
    1.42 + 	mach_lp = arbitrary_virt_to_machine(lp);
    1.43  
    1.44     	/* Allow LDTs to be cleared by the user. */
    1.45     	if (ldt_info.base_addr == 0 && ldt_info.limit == 0) {
    1.46  		if (oldmode || LDT_empty(&ldt_info)) {
    1.47 -                        entry = 0;
    1.48 +			entry_1 = 0;
    1.49 +			entry_2 = 0;
    1.50  			goto install;
    1.51  		}
    1.52  	}
    1.53  
    1.54 -#if 0
    1.55 -	entry = LDT_entry(&ldt_info);
    1.56 -#endif
    1.57 +	entry_1 = LDT_entry_a(&ldt_info);
    1.58 +	entry_2 = LDT_entry_b(&ldt_info);
    1.59  	if (oldmode)
    1.60 -		entry &= ~(1 << 20);
    1.61 +		entry_2 &= ~(1 << 20);
    1.62  
    1.63  	/* Install the new entry ...  */
    1.64  install:
    1.65 -	error = HYPERVISOR_update_descriptor(mach_lp, entry);
    1.66 +	error = HYPERVISOR_update_descriptor(mach_lp, (unsigned long)((entry_1 | (unsigned long) entry_2 << 32)));
    1.67  
    1.68  out_unlock:
    1.69  	up(&mm->context.sem);
     2.1 --- a/linux-2.6.11-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h	Thu Jun 23 09:24:21 2005 +0000
     2.2 +++ b/linux-2.6.11-xen-sparse/include/asm-xen/asm-x86_64/pgtable.h	Thu Jun 23 09:35:57 2005 +0000
     2.3 @@ -30,7 +30,20 @@ extern void clear_kernel_mapping(unsigne
     2.4  
     2.5  extern unsigned long pgkern_mask;
     2.6  
     2.7 -#define arbitrary_virt_to_machine(__va) ({0;})
     2.8 +#define virt_to_ptep(__va)						\
     2.9 +({									\
    2.10 +	pgd_t *__pgd = pgd_offset_k((unsigned long)(__va));		\
    2.11 +	pud_t *__pud = pud_offset(__pgd, (unsigned long)(__va));	\
    2.12 +	pmd_t *__pmd = pmd_offset(__pud, (unsigned long)(__va));	\
    2.13 +	pte_offset_kernel(__pmd, (unsigned long)(__va));		\
    2.14 +})
    2.15 +
    2.16 +#define arbitrary_virt_to_machine(__va)					\
    2.17 +({									\
    2.18 +	pte_t *__pte = virt_to_ptep(__va);				\
    2.19 +	unsigned long __pa = (*(unsigned long *)__pte) & PAGE_MASK;	\
    2.20 +	__pa | ((unsigned long)(__va) & (PAGE_SIZE-1));			\
    2.21 +})
    2.22  
    2.23  /*
    2.24   * ZERO_PAGE is a global shared page that is always zero: used
    2.25 @@ -210,6 +223,7 @@ static inline pte_t ptep_get_and_clear(p
    2.26  #define PAGE_KERNEL_EXEC MAKE_GLOBAL(__PAGE_KERNEL_EXEC)
    2.27  #define PAGE_KERNEL_RO MAKE_GLOBAL(__PAGE_KERNEL_RO)
    2.28  #define PAGE_KERNEL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_NOCACHE)
    2.29 +#define PAGE_KERNEL_VSYSCALL32 __pgprot(__PAGE_KERNEL_VSYSCALL)
    2.30  #define PAGE_KERNEL_VSYSCALL MAKE_GLOBAL(__PAGE_KERNEL_VSYSCALL)
    2.31  #define PAGE_KERNEL_LARGE MAKE_GLOBAL(__PAGE_KERNEL_LARGE)
    2.32  #define PAGE_KERNEL_VSYSCALL_NOCACHE MAKE_GLOBAL(__PAGE_KERNEL_VSYSCALL_NOCACHE)
     3.1 --- a/xen/arch/x86/mm.c	Thu Jun 23 09:24:21 2005 +0000
     3.2 +++ b/xen/arch/x86/mm.c	Thu Jun 23 09:35:57 2005 +0000
     3.3 @@ -288,7 +288,7 @@ int map_ldt_shadow_page(unsigned int off
     3.4      struct domain *d = v->domain;
     3.5      unsigned long gpfn, gmfn;
     3.6      l1_pgentry_t l1e, nl1e;
     3.7 -    unsigned gva = v->arch.guest_context.ldt_base + (off << PAGE_SHIFT);
     3.8 +    unsigned long gva = v->arch.guest_context.ldt_base + (off << PAGE_SHIFT);
     3.9      int res;
    3.10  
    3.11  #if defined(__x86_64__)
     4.1 --- a/xen/include/asm-x86/ldt.h	Thu Jun 23 09:24:21 2005 +0000
     4.2 +++ b/xen/include/asm-x86/ldt.h	Thu Jun 23 09:35:57 2005 +0000
     4.3 @@ -18,9 +18,7 @@ static inline void load_LDT(struct vcpu 
     4.4      {
     4.5          cpu = smp_processor_id();
     4.6          desc = gdt_table + __LDT(cpu) - FIRST_RESERVED_GDT_ENTRY;
     4.7 -        desc->a = ((LDT_VIRT_START(v)&0xffff)<<16) | (ents*8-1);
     4.8 -        desc->b = (LDT_VIRT_START(v)&(0xff<<24)) | 0x8200 |
     4.9 -            ((LDT_VIRT_START(v)&0xff0000)>>16);
    4.10 +        _set_tssldt_desc(desc, LDT_VIRT_START(v), ents*8-1, 2);
    4.11          __asm__ __volatile__ ( "lldt %%ax" : : "a" (__LDT(cpu)<<3) );
    4.12      }
    4.13  }