ia64/xen-unstable

changeset 14107:1e5a83fb928b

xen memory allocator: Allow per-domain bitwidth restrictions.
Original patch by Jan Beulich <jbeulich@novell.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author Keir Fraser <keir@xensource.com>
date Sat Feb 24 13:57:34 2007 +0000 (2007-02-24)
parents 8afe591c272b
children 6c938630de54
files xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/x86_64/mm.c xen/common/page_alloc.c xen/include/asm-ia64/mm.h xen/include/asm-powerpc/mm.h xen/include/asm-x86/domain.h xen/include/asm-x86/mm.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Sat Feb 24 12:19:22 2007 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Sat Feb 24 13:57:34 2007 +0000
     1.3 @@ -255,7 +255,7 @@ static void release_compat_l4(struct vcp
     1.4  
     1.5  static inline int may_switch_mode(struct domain *d)
     1.6  {
     1.7 -    return 1; /* XXX */
     1.8 +    return (d->tot_pages == 0);
     1.9  }
    1.10  
    1.11  int switch_native(struct domain *d)
    1.12 @@ -263,7 +263,7 @@ int switch_native(struct domain *d)
    1.13      l1_pgentry_t gdt_l1e;
    1.14      unsigned int vcpuid;
    1.15  
    1.16 -    if ( !d )
    1.17 +    if ( d == NULL )
    1.18          return -EINVAL;
    1.19      if ( !may_switch_mode(d) )
    1.20          return -EACCES;
    1.21 @@ -283,6 +283,8 @@ int switch_native(struct domain *d)
    1.22              release_compat_l4(d->vcpu[vcpuid]);
    1.23      }
    1.24  
    1.25 +    d->arch.physaddr_bitsize = 64;
    1.26 +
    1.27      return 0;
    1.28  }
    1.29  
    1.30 @@ -291,7 +293,7 @@ int switch_compat(struct domain *d)
    1.31      l1_pgentry_t gdt_l1e;
    1.32      unsigned int vcpuid;
    1.33  
    1.34 -    if ( !d )
    1.35 +    if ( d == NULL )
    1.36          return -EINVAL;
    1.37      if ( compat_disabled )
    1.38          return -ENOSYS;
    1.39 @@ -313,6 +315,10 @@ int switch_compat(struct domain *d)
    1.40              return -ENOMEM;
    1.41      }
    1.42  
    1.43 +    d->arch.physaddr_bitsize =
    1.44 +        fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 1
    1.45 +        + (PAGE_SIZE - 2);
    1.46 +
    1.47      return 0;
    1.48  }
    1.49  
     2.1 --- a/xen/arch/x86/domain_build.c	Sat Feb 24 12:19:22 2007 +0000
     2.2 +++ b/xen/arch/x86/domain_build.c	Sat Feb 24 13:57:34 2007 +0000
     2.3 @@ -357,7 +357,11 @@ int construct_dom0(struct domain *d,
     2.4  
     2.5          value = (parms.virt_hv_start_low + mask) & ~mask;
     2.6  #ifdef CONFIG_COMPAT
     2.7 -        HYPERVISOR_COMPAT_VIRT_START(d) = max_t(unsigned int, m2p_compat_vstart, value);
     2.8 +        HYPERVISOR_COMPAT_VIRT_START(d) =
     2.9 +            max_t(unsigned int, m2p_compat_vstart, value);
    2.10 +        d->arch.physaddr_bitsize = !IS_COMPAT(d) ? 64 :
    2.11 +            fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 1
    2.12 +            + (PAGE_SIZE - 2);
    2.13          if ( value > (!IS_COMPAT(d) ?
    2.14                        HYPERVISOR_VIRT_START :
    2.15                        __HYPERVISOR_COMPAT_VIRT_START) )
     3.1 --- a/xen/arch/x86/x86_64/mm.c	Sat Feb 24 12:19:22 2007 +0000
     3.2 +++ b/xen/arch/x86/x86_64/mm.c	Sat Feb 24 13:57:34 2007 +0000
     3.3 @@ -409,6 +409,13 @@ int check_descriptor(const struct domain
     3.4      return 0;
     3.5  }
     3.6  
     3.7 +unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits)
     3.8 +{
     3.9 +    if ( d == NULL )
    3.10 +        return bits;
    3.11 +    return min(d->arch.physaddr_bitsize, bits);
    3.12 +}
    3.13 +
    3.14  #include "compat/mm.c"
    3.15  
    3.16  /*
     4.1 --- a/xen/common/page_alloc.c	Sat Feb 24 12:19:22 2007 +0000
     4.2 +++ b/xen/common/page_alloc.c	Sat Feb 24 13:57:34 2007 +0000
     4.3 @@ -764,19 +764,21 @@ struct page_info *__alloc_domheap_pages(
     4.4      struct page_info *pg = NULL;
     4.5      cpumask_t mask;
     4.6      unsigned long i;
     4.7 -    unsigned int bits = memflags >> _MEMF_bits, zone_hi;
     4.8 +    unsigned int bits = memflags >> _MEMF_bits, zone_hi = NR_ZONES - 1;
     4.9  
    4.10      ASSERT(!in_irq());
    4.11  
    4.12 -    if ( bits && bits <= PAGE_SHIFT + 1 )
    4.13 -        return NULL;
    4.14 +    if ( bits )
    4.15 +    {
    4.16 +        bits = domain_clamp_alloc_bitsize(d, bits);
    4.17 +        if ( bits <= (PAGE_SHIFT + 1) )
    4.18 +            return NULL;
    4.19 +        bits -= PAGE_SHIFT + 1;
    4.20 +        if ( bits < zone_hi )
    4.21 +            zone_hi = bits;
    4.22 +    }
    4.23  
    4.24 -    zone_hi = bits - PAGE_SHIFT - 1;
    4.25 -    if ( zone_hi >= NR_ZONES )
    4.26 -        zone_hi = NR_ZONES - 1;
    4.27 -
    4.28 -    if ( NR_ZONES + PAGE_SHIFT > dma_bitsize &&
    4.29 -         (!bits || bits > dma_bitsize) )
    4.30 +    if ( (zone_hi + PAGE_SHIFT) >= dma_bitsize )
    4.31      {
    4.32          pg = alloc_heap_pages(dma_bitsize - PAGE_SHIFT, zone_hi, cpu, order);
    4.33  
     5.1 --- a/xen/include/asm-ia64/mm.h	Sat Feb 24 12:19:22 2007 +0000
     5.2 +++ b/xen/include/asm-ia64/mm.h	Sat Feb 24 13:57:34 2007 +0000
     5.3 @@ -509,4 +509,6 @@ long arch_memory_op(int op, XEN_GUEST_HA
     5.4  int steal_page(
     5.5      struct domain *d, struct page_info *page, unsigned int memflags);
     5.6  
     5.7 +#define domain_clamp_alloc_bitsize(d, b) (b)
     5.8 +
     5.9  #endif /* __ASM_IA64_MM_H__ */
     6.1 --- a/xen/include/asm-powerpc/mm.h	Sat Feb 24 12:19:22 2007 +0000
     6.2 +++ b/xen/include/asm-powerpc/mm.h	Sat Feb 24 13:57:34 2007 +0000
     6.3 @@ -289,4 +289,7 @@ extern int steal_page(struct domain *d, 
     6.4  /* XXX these just exist until we can stop #including x86 code */
     6.5  #define access_ok(addr,size) 1
     6.6  #define array_access_ok(addr,count,size) 1
     6.7 +
     6.8 +#define domain_clamp_alloc_bitsize(d, b) (b)
     6.9 +
    6.10  #endif
     7.1 --- a/xen/include/asm-x86/domain.h	Sat Feb 24 12:19:22 2007 +0000
     7.2 +++ b/xen/include/asm-x86/domain.h	Sat Feb 24 13:57:34 2007 +0000
     7.3 @@ -179,6 +179,9 @@ struct arch_domain
     7.4      /* Pseudophysical e820 map (XENMEM_memory_map).  */
     7.5      struct e820entry e820[3];
     7.6      unsigned int nr_e820;
     7.7 +
     7.8 +    /* Maximum physical-address bitwidth supported by this guest. */
     7.9 +    unsigned int physaddr_bitsize;
    7.10  } __cacheline_aligned;
    7.11  
    7.12  #ifdef CONFIG_X86_PAE
     8.1 --- a/xen/include/asm-x86/mm.h	Sat Feb 24 12:19:22 2007 +0000
     8.2 +++ b/xen/include/asm-x86/mm.h	Sat Feb 24 13:57:34 2007 +0000
     8.3 @@ -398,8 +398,11 @@ int map_ldt_shadow_page(unsigned int);
     8.4  
     8.5  #ifdef CONFIG_COMPAT
     8.6  int setup_arg_xlat_area(struct vcpu *, l4_pgentry_t *);
     8.7 +unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
     8.8  #else
     8.9  # define setup_arg_xlat_area(vcpu, l4tab) 0
    8.10 +# define domain_clamp_alloc_bitsize(d, b) (b)
    8.11  #endif
    8.12  
    8.13 +
    8.14  #endif /* __ASM_X86_MM_H__ */