ia64/xen-unstable

changeset 17842:52c0117dd374

x86/32on64: fix physical address restriction

The allocation bit size setting wasn't working anymore after the
recent fix to properly use PAGE_SHIFT instead of PAGE_SIZE. This was
because the bit size implies a power-of-two range that's accessible,
but if all memory is accessible anyway (and its upper boundary is not
a power of two), the domain would either be needlessly restricted or
wouldn't be able to allocate as much memory as was intended for it
(specifically the case for Dom0 without dom0_mem= boot
parameter). Consequently, don't restrict the bit width if all memory
can be accessed.

To avoid needing to adjust this code in two places in the future (it
may need further touching when memory hotplug gets supported), fold
the logic into a function.

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jun 12 16:05:35 2008 +0100 (2008-06-12)
parents 5e98eb873e13
children a3319f32496f
files xen/arch/x86/domain.c xen/arch/x86/domain_build.c xen/arch/x86/x86_64/mm.c xen/include/asm-x86/mm.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Thu Jun 12 15:47:45 2008 +0100
     1.2 +++ b/xen/arch/x86/domain.c	Thu Jun 12 16:05:35 2008 +0100
     1.3 @@ -254,11 +254,7 @@ int switch_compat(struct domain *d)
     1.4                                   FIRST_RESERVED_GDT_PAGE)] = gdt_l1e;
     1.5      }
     1.6  
     1.7 -    d->arch.physaddr_bitsize =
     1.8 -        /* 2^n entries can be contained in guest's p2m mapping space */
     1.9 -        fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
    1.10 -        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
    1.11 -        + PAGE_SHIFT;
    1.12 +    domain_set_alloc_bitsize(d);
    1.13  
    1.14      return 0;
    1.15  
     2.1 --- a/xen/arch/x86/domain_build.c	Thu Jun 12 15:47:45 2008 +0100
     2.2 +++ b/xen/arch/x86/domain_build.c	Thu Jun 12 16:05:35 2008 +0100
     2.3 @@ -353,14 +353,7 @@ int __init construct_dom0(
     2.4  #endif
     2.5      }
     2.6  
     2.7 -#if defined(__x86_64__)
     2.8 -    if ( is_pv_32on64_domain(d) )
     2.9 -        d->arch.physaddr_bitsize =
    2.10 -            /* 2^n entries can be contained in guest's p2m mapping space */
    2.11 -            fls((1UL << 32) - HYPERVISOR_COMPAT_VIRT_START(d)) - 3
    2.12 -            /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
    2.13 -            + PAGE_SHIFT;
    2.14 -#endif
    2.15 +    domain_set_alloc_bitsize(d);
    2.16  
    2.17      /*
    2.18       * Why do we need this? The number of page-table frames depends on the 
     3.1 --- a/xen/arch/x86/x86_64/mm.c	Thu Jun 12 15:47:45 2008 +0100
     3.2 +++ b/xen/arch/x86/x86_64/mm.c	Thu Jun 12 16:05:35 2008 +0100
     3.3 @@ -168,7 +168,7 @@ void __init paging_init(void)
     3.4      if ( mpt_size > RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START )
     3.5          mpt_size = RDWR_COMPAT_MPT_VIRT_END - RDWR_COMPAT_MPT_VIRT_START;
     3.6      mpt_size &= ~((1UL << L2_PAGETABLE_SHIFT) - 1UL);
     3.7 -    if ( m2p_compat_vstart + mpt_size < MACH2PHYS_COMPAT_VIRT_END )
     3.8 +    if ( (m2p_compat_vstart + mpt_size) < MACH2PHYS_COMPAT_VIRT_END )
     3.9          m2p_compat_vstart = MACH2PHYS_COMPAT_VIRT_END - mpt_size;
    3.10      for ( i = 0; i < (mpt_size >> L2_PAGETABLE_SHIFT); i++ )
    3.11      {
    3.12 @@ -472,9 +472,21 @@ int check_descriptor(const struct domain
    3.13      return 0;
    3.14  }
    3.15  
    3.16 +void domain_set_alloc_bitsize(struct domain *d)
    3.17 +{
    3.18 +    if ( !is_pv_32on64_domain(d) ||
    3.19 +         (MACH2PHYS_COMPAT_NR_ENTRIES(d) >= max_page) )
    3.20 +        return;
    3.21 +    d->arch.physaddr_bitsize =
    3.22 +        /* 2^n entries can be contained in guest's p2m mapping space */
    3.23 +        fls(MACH2PHYS_COMPAT_NR_ENTRIES(d)) - 1
    3.24 +        /* 2^n pages -> 2^(n+PAGE_SHIFT) bits */
    3.25 +        + PAGE_SHIFT;
    3.26 +}
    3.27 +
    3.28  unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits)
    3.29  {
    3.30 -    if ( (d == NULL) || !is_pv_32on64_domain(d) )
    3.31 +    if ( (d == NULL) || (d->arch.physaddr_bitsize == 0) )
    3.32          return bits;
    3.33      return min(d->arch.physaddr_bitsize, bits);
    3.34  }
     4.1 --- a/xen/include/asm-x86/mm.h	Thu Jun 12 15:47:45 2008 +0100
     4.2 +++ b/xen/include/asm-x86/mm.h	Thu Jun 12 16:05:35 2008 +0100
     4.3 @@ -342,8 +342,10 @@ int steal_page(
     4.4  int map_ldt_shadow_page(unsigned int);
     4.5  
     4.6  #ifdef CONFIG_COMPAT
     4.7 +void domain_set_alloc_bitsize(struct domain *d);
     4.8  unsigned int domain_clamp_alloc_bitsize(struct domain *d, unsigned int bits);
     4.9  #else
    4.10 +# define domain_set_alloc_bitsize(d) ((void)0)
    4.11  # define domain_clamp_alloc_bitsize(d, b) (b)
    4.12  #endif
    4.13