debuggers.hg

changeset 20852:4a54c794bfd4

x86: Fix and clarify 20803:50bd4235f486

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 14 11:46:53 2010 +0000 (2010-01-14)
parents e406e3451835
children 4b8843ecd553
files xen/arch/x86/setup.c xen/arch/x86/xen.lds.S xen/drivers/passthrough/vtd/x86/vtd.c
line diff
     1.1 --- a/xen/arch/x86/setup.c	Thu Jan 14 10:14:17 2010 +0000
     1.2 +++ b/xen/arch/x86/setup.c	Thu Jan 14 11:46:53 2010 +0000
     1.3 @@ -203,6 +203,8 @@ static void __init percpu_init_areas(voi
     1.4  {
     1.5      unsigned int i, data_size = __per_cpu_data_end - __per_cpu_start;
     1.6  
     1.7 +    BUG_ON((unsigned long)__per_cpu_start & ~PAGE_MASK);
     1.8 +    BUG_ON((unsigned long)__per_cpu_data_end & ~PAGE_MASK);
     1.9      BUG_ON(data_size > PERCPU_SIZE);
    1.10  
    1.11      /* Initialise per-cpu data area for all possible secondary CPUs. */
    1.12 @@ -230,7 +232,6 @@ static void __init percpu_free_unused_ar
    1.13      /* Free all unused per-cpu data areas. */
    1.14      free_xen_data(&__per_cpu_start[first_unused << PERCPU_SHIFT], __bss_start);
    1.15  
    1.16 -    data_size = (data_size + PAGE_SIZE - 1) & PAGE_MASK;
    1.17      if ( data_size != PERCPU_SIZE )
    1.18          for ( i = 0; i < first_unused; i++ )
    1.19              free_xen_data(&__per_cpu_start[(i << PERCPU_SHIFT) + data_size],
    1.20 @@ -1195,15 +1196,15 @@ void arch_get_xen_caps(xen_capabilities_
    1.21      }
    1.22  }
    1.23  
    1.24 -int xen_in_range(paddr_t start, paddr_t end)
    1.25 +int xen_in_range(unsigned long mfn)
    1.26  {
    1.27 +    paddr_t start, end;
    1.28      int i;
    1.29  
    1.30      enum { region_s3, region_text, region_percpu, region_bss, nr_regions };
    1.31      static struct {
    1.32          paddr_t s, e;
    1.33      } xen_regions[nr_regions];
    1.34 -    static unsigned int percpu_data_size;
    1.35  
    1.36      /* initialize first time */
    1.37      if ( !xen_regions[0].s )
    1.38 @@ -1218,17 +1219,33 @@ int xen_in_range(paddr_t start, paddr_t 
    1.39          xen_regions[region_percpu].s = __pa(&__per_cpu_start);
    1.40          xen_regions[region_percpu].e = xen_regions[2].s +
    1.41              (((paddr_t)last_cpu(cpu_possible_map) + 1) << PERCPU_SHIFT);
    1.42 -        percpu_data_size = __per_cpu_data_end - __per_cpu_start;
    1.43 -        percpu_data_size = (percpu_data_size + PAGE_SIZE - 1) & PAGE_MASK;
    1.44          /* bss */
    1.45          xen_regions[region_bss].s = __pa(&__bss_start);
    1.46          xen_regions[region_bss].e = __pa(&_end);
    1.47      }
    1.48  
    1.49 +    start = (paddr_t)mfn << PAGE_SHIFT;
    1.50 +    end = start + PAGE_SIZE;
    1.51      for ( i = 0; i < nr_regions; i++ )
    1.52 -        if ( (start < xen_regions[i].e) && (end > xen_regions[i].s) )
    1.53 -            return ((i != region_percpu) ||
    1.54 -                    ((start & (PERCPU_SIZE - 1)) < percpu_data_size));
    1.55 +    {
    1.56 +        if ( (start >= xen_regions[i].e) || (end <= xen_regions[i].s) )
    1.57 +            continue;
    1.58 +
    1.59 +        if ( i == region_percpu )
    1.60 +        {
    1.61 +            /*
    1.62 +             * Check if the given page falls into an unused (and therefore
    1.63 +             * freed) section of the per-cpu data space. Each CPU's data
    1.64 +             * area is page-aligned, so the following arithmetic is safe.
    1.65 +             */
    1.66 +            unsigned int off = ((start - (unsigned long)__per_cpu_start)
    1.67 +                                & (PERCPU_SIZE - 1));
    1.68 +            unsigned int data_sz = __per_cpu_data_end - __per_cpu_start;
    1.69 +            return off < data_sz;
    1.70 +        }
    1.71 +
    1.72 +        return 1;
    1.73 +    }
    1.74  
    1.75      return 0;
    1.76  }
     2.1 --- a/xen/arch/x86/xen.lds.S	Thu Jan 14 10:14:17 2010 +0000
     2.2 +++ b/xen/arch/x86/xen.lds.S	Thu Jan 14 11:46:53 2010 +0000
     2.3 @@ -104,6 +104,7 @@ SECTIONS
     2.4         *(.data.percpu)
     2.5         . = ALIGN(SMP_CACHE_BYTES);
     2.6         *(.data.percpu.read_mostly)
     2.7 +       . = ALIGN(PAGE_SIZE);
     2.8         __per_cpu_data_end = .;
     2.9    } :text
    2.10    . = __per_cpu_start + (NR_CPUS << PERCPU_SHIFT);
     3.1 --- a/xen/drivers/passthrough/vtd/x86/vtd.c	Thu Jan 14 10:14:17 2010 +0000
     3.2 +++ b/xen/drivers/passthrough/vtd/x86/vtd.c	Thu Jan 14 11:46:53 2010 +0000
     3.3 @@ -133,7 +133,7 @@ void hvm_dpci_isairq_eoi(struct domain *
     3.4  void iommu_set_dom0_mapping(struct domain *d)
     3.5  {
     3.6      u64 i, j, tmp, max_pfn;
     3.7 -    extern int xen_in_range(paddr_t start, paddr_t end);
     3.8 +    extern int xen_in_range(unsigned long mfn);
     3.9  
    3.10      BUG_ON(d->domain_id != 0);
    3.11  
    3.12 @@ -153,7 +153,7 @@ void iommu_set_dom0_mapping(struct domai
    3.13              continue;
    3.14  
    3.15          /* Exclude Xen bits */
    3.16 -        if ( xen_in_range(i << PAGE_SHIFT, (i + 1) << PAGE_SHIFT) )
    3.17 +        if ( xen_in_range(i) )
    3.18              continue;
    3.19  
    3.20          tmp = 1 << (PAGE_SHIFT - PAGE_SHIFT_4K);