ia64/xen-unstable

changeset 2031:b7e842452bff

bitkeeper revision 1.1108.33.30 (410e5661Rzjfq990tCgPcsBrf4HUgg)

Change dom_mem_op interface to allow non-order-0 allocations.
(i.e., can alloc contiguous memory extents larger than one page).
author kaf24@scramble.cl.cam.ac.uk
date Mon Aug 02 14:57:37 2004 +0000 (2004-08-02)
parents e231cd8ec652
children 67defb498ac1 7eabdea08bd0
files linux-2.4.26-xen-sparse/arch/xen/drivers/balloon/balloon.c linux-2.6.7-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6.7-xen-sparse/drivers/xen/netback/netback.c linux-2.6.7-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6.7-xen-sparse/include/asm-xen/hypervisor.h xen/common/dom_mem_ops.c
line diff
     1.1 --- a/linux-2.4.26-xen-sparse/arch/xen/drivers/balloon/balloon.c	Mon Aug 02 14:50:46 2004 +0000
     1.2 +++ b/linux-2.4.26-xen-sparse/arch/xen/drivers/balloon/balloon.c	Mon Aug 02 14:57:37 2004 +0000
     1.3 @@ -109,7 +109,7 @@ static unsigned long inflate_balloon(uns
     1.4      XEN_flush_page_update_queue();
     1.5  
     1.6      ret = HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, 
     1.7 -                                parray, num_pages);
     1.8 +                                parray, num_pages, 0);
     1.9      if ( unlikely(ret != num_pages) )
    1.10      {
    1.11          printk("Unable to inflate balloon, error %lx\n", ret);
    1.12 @@ -199,7 +199,7 @@ unsigned long deflate_balloon(unsigned l
    1.13      XEN_flush_page_update_queue();
    1.14  
    1.15      ret = HYPERVISOR_dom_mem_op(MEMOP_increase_reservation, 
    1.16 -                                parray, num_pages);
    1.17 +                                parray, num_pages, 0);
    1.18      if ( unlikely(ret != num_pages) )
    1.19      {
    1.20          printk("Unable to deflate balloon, error %lx\n", ret);
     2.1 --- a/linux-2.6.7-xen-sparse/arch/xen/i386/mm/hypervisor.c	Mon Aug 02 14:50:46 2004 +0000
     2.2 +++ b/linux-2.6.7-xen-sparse/arch/xen/i386/mm/hypervisor.c	Mon Aug 02 14:57:37 2004 +0000
     2.3 @@ -305,7 +305,7 @@ unsigned long allocate_empty_lowmem_regi
     2.4      flush_page_update_queue();
     2.5  
     2.6      ret = HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, 
     2.7 -                                pfn_array, 1<<order);
     2.8 +                                pfn_array, 1<<order, 0);
     2.9      if ( unlikely(ret != (1<<order)) )
    2.10      {
    2.11          printk(KERN_WARNING "Unable to reduce memory reservation (%d)\n", ret);
    2.12 @@ -332,7 +332,7 @@ void deallocate_lowmem_region(unsigned l
    2.13          BUG();
    2.14  
    2.15      ret = HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
    2.16 -                                pfn_array, 1<<order);
    2.17 +                                pfn_array, 1<<order, 0);
    2.18      if ( unlikely(ret != (1<<order)) )
    2.19      {
    2.20          printk(KERN_WARNING "Unable to increase memory reservation (%d)\n",
     3.1 --- a/linux-2.6.7-xen-sparse/drivers/xen/netback/netback.c	Mon Aug 02 14:50:46 2004 +0000
     3.2 +++ b/linux-2.6.7-xen-sparse/drivers/xen/netback/netback.c	Mon Aug 02 14:57:37 2004 +0000
     3.3 @@ -71,7 +71,7 @@ static spinlock_t mfn_lock = SPIN_LOCK_U
     3.4  static void __refresh_mfn_list(void)
     3.5  {
     3.6      int ret = HYPERVISOR_dom_mem_op(MEMOP_increase_reservation,
     3.7 -                                    mfn_list, MAX_MFN_ALLOC);
     3.8 +                                    mfn_list, MAX_MFN_ALLOC, 0);
     3.9      if ( unlikely(ret != MAX_MFN_ALLOC) )
    3.10          BUG();
    3.11      alloc_index = MAX_MFN_ALLOC;
    3.12 @@ -94,7 +94,8 @@ static void dealloc_mfn(unsigned long mf
    3.13      spin_lock_irqsave(&mfn_lock, flags);
    3.14      if ( alloc_index != MAX_MFN_ALLOC )
    3.15          mfn_list[alloc_index++] = mfn;
    3.16 -    else if ( HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation, &mfn, 1) != 1 )
    3.17 +    else if ( HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation,
    3.18 +                                    &mfn, 1, 0) != 1 )
    3.19          BUG();
    3.20      spin_unlock_irqrestore(&mfn_lock, flags);
    3.21  }
     4.1 --- a/linux-2.6.7-xen-sparse/drivers/xen/netfront/netfront.c	Mon Aug 02 14:50:46 2004 +0000
     4.2 +++ b/linux-2.6.7-xen-sparse/drivers/xen/netfront/netfront.c	Mon Aug 02 14:57:37 2004 +0000
     4.3 @@ -282,6 +282,7 @@ static void network_alloc_rx_buffers(str
     4.4      rx_mcl[nr_pfns].args[0] = MEMOP_decrease_reservation;
     4.5      rx_mcl[nr_pfns].args[1] = (unsigned long)rx_pfn_array;
     4.6      rx_mcl[nr_pfns].args[2] = (unsigned long)nr_pfns;
     4.7 +    rx_mcl[nr_pfns].args[3] = 0;
     4.8  
     4.9      /* Zap PTEs and give away pages in one big multicall. */
    4.10      (void)HYPERVISOR_multicall(rx_mcl, nr_pfns+1);
     5.1 --- a/linux-2.6.7-xen-sparse/include/asm-xen/hypervisor.h	Mon Aug 02 14:50:46 2004 +0000
     5.2 +++ b/linux-2.6.7-xen-sparse/include/asm-xen/hypervisor.h	Mon Aug 02 14:57:37 2004 +0000
     5.3 @@ -3,7 +3,7 @@
     5.4   * 
     5.5   * Linux-specific hypervisor handling.
     5.6   * 
     5.7 - * Copyright (c) 2002, K A Fraser
     5.8 + * Copyright (c) 2002-2004, K A Fraser
     5.9   */
    5.10  
    5.11  #ifndef __HYPERVISOR_H__
    5.12 @@ -366,14 +366,16 @@ static inline int HYPERVISOR_set_fast_tr
    5.13  }
    5.14  
    5.15  static inline int HYPERVISOR_dom_mem_op(unsigned int   op,
    5.16 -                                        unsigned long *pages,
    5.17 -                                        unsigned long  nr_pages)
    5.18 +                                        unsigned long *extent_list,
    5.19 +                                        unsigned long  nr_extents,
    5.20 +                                        unsigned int   extent_order)
    5.21  {
    5.22      int ret;
    5.23      __asm__ __volatile__ (
    5.24          TRAP_INSTR
    5.25          : "=a" (ret) : "0" (__HYPERVISOR_dom_mem_op),
    5.26 -        "b" (op), "c" (pages), "d" (nr_pages) : "memory" );
    5.27 +        "b" (op), "c" (extent_list), "d" (nr_extents), "S" (extent_order)
    5.28 +        : "memory" );
    5.29  
    5.30      return ret;
    5.31  }
     6.1 --- a/xen/common/dom_mem_ops.c	Mon Aug 02 14:50:46 2004 +0000
     6.2 +++ b/xen/common/dom_mem_ops.c	Mon Aug 02 14:57:37 2004 +0000
     6.3 @@ -16,76 +16,89 @@
     6.4  #include <asm/domain_page.h>
     6.5  
     6.6  static long alloc_dom_mem(struct domain *d, 
     6.7 -                          unsigned long *pages, 
     6.8 -                          unsigned long  nr_pages)
     6.9 +                          unsigned long *extent_list, 
    6.10 +                          unsigned long  nr_extents,
    6.11 +                          unsigned int   extent_order)
    6.12  {
    6.13      struct pfn_info *page;
    6.14      unsigned long    i;
    6.15  
    6.16 -    for ( i = 0; i < nr_pages; i++ )
    6.17 +    if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current) )
    6.18      {
    6.19 -        if ( unlikely((page = alloc_domheap_page(d)) == NULL) )
    6.20 +        DPRINTK("Only I/O-capable domains may allocate > order-0 memory.\n");
    6.21 +        return 0;
    6.22 +    }
    6.23 +
    6.24 +    for ( i = 0; i < nr_extents; i++ )
    6.25 +    {
    6.26 +        if ( unlikely((page = alloc_domheap_pages(d, extent_order)) == NULL) )
    6.27          {
    6.28              DPRINTK("Could not allocate a frame\n");
    6.29 -            break;
    6.30 +            return i;
    6.31          }
    6.32  
    6.33          /* Inform the domain of the new page's machine address. */ 
    6.34 -        if ( unlikely(put_user(page_to_pfn(page), &pages[i]) != 0) )
    6.35 -            break;
    6.36 +        if ( unlikely(put_user(page_to_pfn(page), &extent_list[i]) != 0) )
    6.37 +            return i;
    6.38      }
    6.39  
    6.40      return i;
    6.41  }
    6.42      
    6.43 -static long free_dom_mem(struct domain *d, 
    6.44 -                         unsigned long *pages, 
    6.45 -                         unsigned long  nr_pages)
    6.46 +static long free_dom_mem(struct domain *d,
    6.47 +                         unsigned long *extent_list, 
    6.48 +                         unsigned long  nr_extents,
    6.49 +                         unsigned int   extent_order)
    6.50  {
    6.51      struct pfn_info *page;
    6.52 -    unsigned long    i, mpfn;
    6.53 -    long             rc = 0;
    6.54 -
    6.55 -    for ( i = 0; i < nr_pages; i++ )
    6.56 -    {
    6.57 -        if ( unlikely(get_user(mpfn, &pages[i]) != 0) )
    6.58 -            break;
    6.59 +    unsigned long    i, j, mpfn;
    6.60  
    6.61 -        if ( unlikely(mpfn >= max_page) )
    6.62 -        {
    6.63 -            DPRINTK("Domain %u page number out of range (%08lx>=%08lx)\n", 
    6.64 -                    d->domain, mpfn, max_page);
    6.65 -            rc = -EINVAL;
    6.66 -            break;
    6.67 -        }
    6.68 +    for ( i = 0; i < nr_extents; i++ )
    6.69 +    {
    6.70 +        if ( unlikely(get_user(mpfn, &extent_list[i]) != 0) )
    6.71 +            return i;
    6.72  
    6.73 -        page = &frame_table[mpfn];
    6.74 -        if ( unlikely(!get_page(page, d)) )
    6.75 +        for ( j = 0; j < (1 << extent_order); j++ )
    6.76          {
    6.77 -            DPRINTK("Bad page free for domain %u\n", d->domain);
    6.78 -            rc = -EINVAL;
    6.79 -            break;
    6.80 -        }
    6.81 +            if ( unlikely((mpfn + j) >= max_page) )
    6.82 +            {
    6.83 +                DPRINTK("Domain %u page number out of range (%08lx>=%08lx)\n", 
    6.84 +                        d->domain, mpfn + j, max_page);
    6.85 +                return i;
    6.86 +            }
    6.87 +            
    6.88 +            page = &frame_table[mpfn + j];
    6.89 +            if ( unlikely(!get_page(page, d)) )
    6.90 +            {
    6.91 +                DPRINTK("Bad page free for domain %u\n", d->domain);
    6.92 +                return i;
    6.93 +            }
    6.94  
    6.95 -        if ( test_and_clear_bit(_PGC_guest_pinned, &page->u.inuse.count_info) )
    6.96 -            put_page_and_type(page);
    6.97 +            if ( test_and_clear_bit(_PGC_guest_pinned, 
    6.98 +                                    &page->u.inuse.count_info) )
    6.99 +                put_page_and_type(page);
   6.100 +            
   6.101 +            if ( test_and_clear_bit(_PGC_allocated,
   6.102 +                                    &page->u.inuse.count_info) )
   6.103 +                put_page(page);
   6.104  
   6.105 -        if ( test_and_clear_bit(_PGC_allocated, &page->u.inuse.count_info) )
   6.106              put_page(page);
   6.107 -
   6.108 -        put_page(page);
   6.109 +        }
   6.110      }
   6.111  
   6.112 -    return rc ? rc : nr_pages;
   6.113 +    return i;
   6.114  }
   6.115      
   6.116 -long do_dom_mem_op(unsigned int op, void *pages, unsigned long nr_pages)
   6.117 +long do_dom_mem_op(unsigned int   op, 
   6.118 +                   unsigned long *extent_list, 
   6.119 +                   unsigned long  nr_extents,
   6.120 +                   unsigned int   extent_order)
   6.121  {
   6.122      if ( op == MEMOP_increase_reservation )
   6.123 -        return alloc_dom_mem(current, pages, nr_pages);
   6.124 +        return alloc_dom_mem(current, extent_list, nr_extents, extent_order);
   6.125  
   6.126      if ( op == MEMOP_decrease_reservation )
   6.127 -        return free_dom_mem(current, pages, nr_pages);
   6.128 +        return free_dom_mem(current, extent_list, nr_extents, extent_order);
   6.129  
   6.130      return -ENOSYS;
   6.131  }