ia64/xen-unstable

changeset 6486:1de508b9063b

Replace dom_mem_op hypercall with memory_op hypercall with
better interface. Fix "mem=" parameter on x86/64 boot.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Aug 30 11:53:47 2005 +0000 (2005-08-30)
parents f509c7303954
children 77af70556792
files linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h tools/libxc/xc_domain.c tools/libxc/xc_linux_restore.c tools/libxc/xc_private.c tools/libxc/xenctrl.h xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/entry.S xen/common/Makefile xen/common/memory.c xen/common/page_alloc.c xen/include/public/memory.h xen/include/public/xen.h
line diff
     1.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 30 09:46:33 2005 +0000
     1.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/pci-dma.c	Tue Aug 30 11:53:47 2005 +0000
     1.3 @@ -115,9 +115,9 @@ dma_supported(struct device *dev, u64 ma
     1.4  	if (swiotlb)
     1.5  		return swiotlb_dma_supported(dev, mask);
     1.6  	/*
     1.7 -         * By default we'll BUG when an infeasible DMA is requested, and
     1.8 -         * request swiotlb=force (see IOMMU_BUG_ON).
     1.9 -         */
    1.10 +	 * By default we'll BUG when an infeasible DMA is requested, and
    1.11 +	 * request swiotlb=force (see IOMMU_BUG_ON).
    1.12 +	 */
    1.13  	return 1;
    1.14  }
    1.15  EXPORT_SYMBOL(dma_supported);
     2.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Tue Aug 30 09:46:33 2005 +0000
     2.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c	Tue Aug 30 11:53:47 2005 +0000
     2.3 @@ -55,6 +55,7 @@
     2.4  #include <asm/io.h>
     2.5  #include <asm-xen/hypervisor.h>
     2.6  #include <asm-xen/xen-public/physdev.h>
     2.7 +#include <asm-xen/xen-public/memory.h>
     2.8  #include "setup_arch_pre.h"
     2.9  #include <bios_ebda.h>
    2.10  
    2.11 @@ -1585,15 +1586,21 @@ void __init setup_arch(char **cmdline_p)
    2.12  				(unsigned int *)xen_start_info.mfn_list,
    2.13  				xen_start_info.nr_pages * sizeof(unsigned int));
    2.14  		} else {
    2.15 +			struct xen_memory_reservation reservation = {
    2.16 +				.extent_start = (unsigned long *)xen_start_info.mfn_list + max_pfn,
    2.17 +				.nr_extents   = xen_start_info.nr_pages - max_pfn,
    2.18 +				.extent_order = 0,
    2.19 +				.domid        = DOMID_SELF
    2.20 +			};
    2.21 +
    2.22  			memcpy(phys_to_machine_mapping,
    2.23  				(unsigned int *)xen_start_info.mfn_list,
    2.24  				max_pfn * sizeof(unsigned int));
    2.25  			/* N.B. below relies on sizeof(int) == sizeof(long). */
    2.26 -			if (HYPERVISOR_dom_mem_op(
    2.27 -				MEMOP_decrease_reservation,
    2.28 -				(unsigned long *)xen_start_info.mfn_list + max_pfn,
    2.29 -				xen_start_info.nr_pages - max_pfn, 0) !=
    2.30 -			    (xen_start_info.nr_pages - max_pfn)) BUG();
    2.31 +			BUG_ON(HYPERVISOR_memory_op(
    2.32 +				XENMEM_decrease_reservation,
    2.33 +				&reservation) !=
    2.34 +			    (xen_start_info.nr_pages - max_pfn));
    2.35  		}
    2.36  		free_bootmem(
    2.37  			__pa(xen_start_info.mfn_list), 
     3.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c	Tue Aug 30 09:46:33 2005 +0000
     3.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/hypervisor.c	Tue Aug 30 11:53:47 2005 +0000
     3.3 @@ -35,6 +35,7 @@
     3.4  #include <asm/pgtable.h>
     3.5  #include <asm-xen/hypervisor.h>
     3.6  #include <asm-xen/balloon.h>
     3.7 +#include <asm-xen/xen-public/memory.h>
     3.8  #include <linux/module.h>
     3.9  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)
    3.10  #include <linux/percpu.h>
    3.11 @@ -320,6 +321,12 @@ void xen_create_contiguous_region(unsign
    3.12  	pmd_t         *pmd;
    3.13  	pte_t         *pte;
    3.14  	unsigned long  mfn, i, flags;
    3.15 +	struct xen_memory_reservation reservation = {
    3.16 +		.extent_start = &mfn,
    3.17 +		.nr_extents   = 1,
    3.18 +		.extent_order = 0,
    3.19 +		.domid        = DOMID_SELF
    3.20 +	};
    3.21  
    3.22  	scrub_pages(vstart, 1 << order);
    3.23  
    3.24 @@ -336,13 +343,15 @@ void xen_create_contiguous_region(unsign
    3.25  			vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
    3.26  		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    3.27  			INVALID_P2M_ENTRY;
    3.28 -		BUG_ON(HYPERVISOR_dom_mem_op(
    3.29 -			MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
    3.30 +		BUG_ON(HYPERVISOR_memory_op(
    3.31 +			XENMEM_decrease_reservation, &reservation) != 1);
    3.32  	}
    3.33  
    3.34  	/* 2. Get a new contiguous memory extent. */
    3.35 -	BUG_ON(HYPERVISOR_dom_mem_op(
    3.36 -		MEMOP_increase_reservation, &mfn, 1, order | (32<<8)) != 1);
    3.37 +	reservation.extent_order = order;
    3.38 +	reservation.address_bits = 31; /* aacraid limitation */
    3.39 +	BUG_ON(HYPERVISOR_memory_op(
    3.40 +		XENMEM_increase_reservation, &reservation) != 1);
    3.41  
    3.42  	/* 3. Map the new extent in place of old pages. */
    3.43  	for (i = 0; i < (1<<order); i++) {
    3.44 @@ -367,6 +376,12 @@ void xen_destroy_contiguous_region(unsig
    3.45  	pmd_t         *pmd;
    3.46  	pte_t         *pte;
    3.47  	unsigned long  mfn, i, flags;
    3.48 +	struct xen_memory_reservation reservation = {
    3.49 +		.extent_start = &mfn,
    3.50 +		.nr_extents   = 1,
    3.51 +		.extent_order = 0,
    3.52 +		.domid        = DOMID_SELF
    3.53 +	};
    3.54  
    3.55  	scrub_pages(vstart, 1 << order);
    3.56  
    3.57 @@ -385,14 +400,14 @@ void xen_destroy_contiguous_region(unsig
    3.58  			vstart + (i*PAGE_SIZE), __pte_ma(0), 0));
    3.59  		phys_to_machine_mapping[(__pa(vstart)>>PAGE_SHIFT)+i] =
    3.60  			INVALID_P2M_ENTRY;
    3.61 -		BUG_ON(HYPERVISOR_dom_mem_op(
    3.62 -			MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
    3.63 +		BUG_ON(HYPERVISOR_memory_op(
    3.64 +			XENMEM_decrease_reservation, &reservation) != 1);
    3.65  	}
    3.66  
    3.67  	/* 2. Map new pages in place of old pages. */
    3.68  	for (i = 0; i < (1<<order); i++) {
    3.69 -		BUG_ON(HYPERVISOR_dom_mem_op(
    3.70 -			MEMOP_increase_reservation, &mfn, 1, 0) != 1);
    3.71 +		BUG_ON(HYPERVISOR_memory_op(
    3.72 +			XENMEM_increase_reservation, &reservation) != 1);
    3.73  		BUG_ON(HYPERVISOR_update_va_mapping(
    3.74  			vstart + (i*PAGE_SIZE),
    3.75  			pfn_pte_ma(mfn, PAGE_KERNEL), 0));
     4.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Tue Aug 30 09:46:33 2005 +0000
     4.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c	Tue Aug 30 11:53:47 2005 +0000
     4.3 @@ -734,9 +734,9 @@ void __init setup_arch(char **cmdline_p)
     4.4  		/* Make sure we have a large enough P->M table. */
     4.5  		if (end_pfn > xen_start_info.nr_pages) {
     4.6  			phys_to_machine_mapping = alloc_bootmem(
     4.7 -				max_pfn * sizeof(u32));
     4.8 +				end_pfn * sizeof(u32));
     4.9  			memset(phys_to_machine_mapping, ~0,
    4.10 -			       max_pfn * sizeof(u32));
    4.11 +			       end_pfn * sizeof(u32));
    4.12  			memcpy(phys_to_machine_mapping,
    4.13  			       (u32 *)xen_start_info.mfn_list,
    4.14  			       xen_start_info.nr_pages * sizeof(u32));
    4.15 @@ -749,11 +749,8 @@ void __init setup_arch(char **cmdline_p)
    4.16  		pfn_to_mfn_frame_list = alloc_bootmem(PAGE_SIZE);
    4.17  
    4.18  		for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(u32)), j++ )
    4.19 -		{	
    4.20  			pfn_to_mfn_frame_list[j] = 
    4.21  				virt_to_mfn(&phys_to_machine_mapping[i]);
    4.22 -		}
    4.23 -
    4.24  	}
    4.25  #endif
    4.26  
     5.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Tue Aug 30 09:46:33 2005 +0000
     5.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c	Tue Aug 30 11:53:47 2005 +0000
     5.3 @@ -466,7 +466,7 @@ static inline int make_readonly(unsigned
     5.4      return readonly;
     5.5  }
     5.6  
     5.7 -void __init phys_pud_init(pud_t *pud, unsigned long address, unsigned long end)
     5.8 +static void __init phys_pud_init(pud_t *pud, unsigned long address, unsigned long end)
     5.9  { 
    5.10          long i, j, k; 
    5.11          unsigned long paddr;
    5.12 @@ -502,16 +502,17 @@ void __init phys_pud_init(pud_t *pud, un
    5.13                          pte = alloc_low_page(&pte_phys);
    5.14                          pte_save = pte;
    5.15                          for (k = 0; k < PTRS_PER_PTE; pte++, k++, paddr += PTE_SIZE) {
    5.16 +                                if ((paddr >= end) ||
    5.17 +                                    ((paddr >> PAGE_SHIFT)
    5.18 +                                     >= xen_start_info.nr_pages)) { 
    5.19 +                                        __set_pte(pte, __pte(0)); 
    5.20 +                                        continue;
    5.21 +                                }
    5.22                                  if (make_readonly(paddr)) {
    5.23                                          __set_pte(pte, 
    5.24                                                  __pte(paddr | (_KERNPG_TABLE & ~_PAGE_RW)));
    5.25                                          continue;
    5.26                                  }
    5.27 -                                if (paddr >= end) { 
    5.28 -                                        for (; k < PTRS_PER_PTE; k++, pte++)
    5.29 -                                                __set_pte(pte, __pte(0)); 
    5.30 -                                        break;
    5.31 -                                }
    5.32                                  __set_pte(pte, __pte(paddr | _KERNPG_TABLE));
    5.33                          }
    5.34                          pte = pte_save;
     6.1 --- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 30 09:46:33 2005 +0000
     6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c	Tue Aug 30 11:53:47 2005 +0000
     6.3 @@ -44,6 +44,7 @@
     6.4  #include <asm-xen/xen_proc.h>
     6.5  #include <asm-xen/hypervisor.h>
     6.6  #include <asm-xen/balloon.h>
     6.7 +#include <asm-xen/xen-public/memory.h>
     6.8  #include <asm/pgalloc.h>
     6.9  #include <asm/pgtable.h>
    6.10  #include <asm/uaccess.h>
    6.11 @@ -168,6 +169,11 @@ static void balloon_process(void *unused
    6.12  	struct page   *page;
    6.13  	long           credit, debt, rc;
    6.14  	void          *v;
    6.15 +	struct xen_memory_reservation reservation = {
    6.16 +		.address_bits = 0,
    6.17 +		.extent_order = 0,
    6.18 +		.domid        = DOMID_SELF
    6.19 +	};
    6.20  
    6.21  	down(&balloon_mutex);
    6.22  
    6.23 @@ -180,14 +186,18 @@ static void balloon_process(void *unused
    6.24  			goto out;
    6.25  
    6.26  		balloon_lock(flags);
    6.27 -		rc = HYPERVISOR_dom_mem_op(
    6.28 -			MEMOP_increase_reservation, mfn_list, credit, 0);
    6.29 +		reservation.extent_start = mfn_list;
    6.30 +		reservation.nr_extents   = credit;
    6.31 +		rc = HYPERVISOR_memory_op(
    6.32 +			XENMEM_increase_reservation, &reservation);
    6.33  		balloon_unlock(flags);
    6.34  		if (rc < credit) {
    6.35  			/* We hit the Xen hard limit: reprobe. */
    6.36 -			BUG_ON(HYPERVISOR_dom_mem_op(
    6.37 -				MEMOP_decrease_reservation,
    6.38 -				mfn_list, rc, 0) != rc);
    6.39 +			reservation.extent_start = mfn_list;
    6.40 +			reservation.nr_extents   = rc;
    6.41 +			BUG_ON(HYPERVISOR_memory_op(
    6.42 +				XENMEM_decrease_reservation,
    6.43 +				&reservation) != rc);
    6.44  			hard_limit = current_pages + rc - driver_pages;
    6.45  			vfree(mfn_list);
    6.46  			goto retry;
    6.47 @@ -261,8 +271,10 @@ static void balloon_process(void *unused
    6.48  			balloon_append(pfn_to_page(pfn));
    6.49  		}
    6.50  
    6.51 -		BUG_ON(HYPERVISOR_dom_mem_op(
    6.52 -			MEMOP_decrease_reservation,mfn_list, debt, 0) != debt);
    6.53 +		reservation.extent_start = mfn_list;
    6.54 +		reservation.nr_extents   = debt;
    6.55 +		BUG_ON(HYPERVISOR_memory_op(
    6.56 +			XENMEM_decrease_reservation, &reservation) != debt);
    6.57  
    6.58  		current_pages -= debt;
    6.59  	}
    6.60 @@ -438,11 +450,17 @@ static int dealloc_pte_fn(
    6.61  	pte_t *pte, struct page *pte_page, unsigned long addr, void *data)
    6.62  {
    6.63  	unsigned long mfn = pte_mfn(*pte);
    6.64 +	struct xen_memory_reservation reservation = {
    6.65 +		.extent_start = &mfn,
    6.66 +		.nr_extents   = 1,
    6.67 +		.extent_order = 0,
    6.68 +		.domid        = DOMID_SELF
    6.69 +	};
    6.70  	set_pte(pte, __pte_ma(0));
    6.71  	phys_to_machine_mapping[__pa(addr) >> PAGE_SHIFT] =
    6.72  		INVALID_P2M_ENTRY;
    6.73 -	BUG_ON(HYPERVISOR_dom_mem_op(
    6.74 -		MEMOP_decrease_reservation, &mfn, 1, 0) != 1);
    6.75 +	BUG_ON(HYPERVISOR_memory_op(
    6.76 +		XENMEM_decrease_reservation, &reservation) != 1);
    6.77  	return 0;
    6.78  }
    6.79  
     7.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Tue Aug 30 09:46:33 2005 +0000
     7.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Tue Aug 30 11:53:47 2005 +0000
     7.3 @@ -12,6 +12,7 @@
     7.4  
     7.5  #include "common.h"
     7.6  #include <asm-xen/balloon.h>
     7.7 +#include <asm-xen/xen-public/memory.h>
     7.8  
     7.9  #if defined(CONFIG_XEN_NETDEV_GRANT_TX) || defined(CONFIG_XEN_NETDEV_GRANT_RX)
    7.10  #include <asm-xen/xen-public/grant_table.h>
    7.11 @@ -110,10 +111,16 @@ static spinlock_t mfn_lock = SPIN_LOCK_U
    7.12  static unsigned long alloc_mfn(void)
    7.13  {
    7.14      unsigned long mfn = 0, flags;
    7.15 +    struct xen_memory_reservation reservation = {
    7.16 +        .extent_start = mfn_list,
    7.17 +        .nr_extents   = MAX_MFN_ALLOC,
    7.18 +        .extent_order = 0,
    7.19 +        .domid        = DOMID_SELF
    7.20 +    };
    7.21      spin_lock_irqsave(&mfn_lock, flags);
    7.22      if ( unlikely(alloc_index == 0) )
    7.23 -        alloc_index = HYPERVISOR_dom_mem_op(
    7.24 -            MEMOP_increase_reservation, mfn_list, MAX_MFN_ALLOC, 0);
    7.25 +        alloc_index = HYPERVISOR_memory_op(
    7.26 +            XENMEM_increase_reservation, &reservation);
    7.27      if ( alloc_index != 0 )
    7.28          mfn = mfn_list[--alloc_index];
    7.29      spin_unlock_irqrestore(&mfn_lock, flags);
    7.30 @@ -124,11 +131,17 @@ static unsigned long alloc_mfn(void)
    7.31  static void free_mfn(unsigned long mfn)
    7.32  {
    7.33      unsigned long flags;
    7.34 +    struct xen_memory_reservation reservation = {
    7.35 +        .extent_start = &mfn,
    7.36 +        .nr_extents   = 1,
    7.37 +        .extent_order = 0,
    7.38 +        .domid        = DOMID_SELF
    7.39 +    };
    7.40      spin_lock_irqsave(&mfn_lock, flags);
    7.41      if ( alloc_index != MAX_MFN_ALLOC )
    7.42          mfn_list[alloc_index++] = mfn;
    7.43 -    else if ( HYPERVISOR_dom_mem_op(MEMOP_decrease_reservation,
    7.44 -                                    &mfn, 1, 0) != 1 )
    7.45 +    else if ( HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation)
    7.46 +              != 1 )
    7.47          BUG();
    7.48      spin_unlock_irqrestore(&mfn_lock, flags);
    7.49  }
     8.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Aug 30 09:46:33 2005 +0000
     8.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Tue Aug 30 11:53:47 2005 +0000
     8.3 @@ -50,6 +50,7 @@
     8.4  #include <asm-xen/evtchn.h>
     8.5  #include <asm-xen/xenbus.h>
     8.6  #include <asm-xen/xen-public/io/netif.h>
     8.7 +#include <asm-xen/xen-public/memory.h>
     8.8  #include <asm-xen/balloon.h>
     8.9  #include <asm/page.h>
    8.10  #include <asm/uaccess.h>
    8.11 @@ -328,6 +329,7 @@ static void network_alloc_rx_buffers(str
    8.12      struct sk_buff *skb;
    8.13      int i, batch_target;
    8.14      NETIF_RING_IDX req_prod = np->rx->req_prod;
    8.15 +    struct xen_memory_reservation reservation;
    8.16  #ifdef CONFIG_XEN_NETDEV_GRANT_RX
    8.17      int ref;
    8.18  #endif
    8.19 @@ -388,12 +390,15 @@ static void network_alloc_rx_buffers(str
    8.20      rx_mcl[i-1].args[MULTI_UVMFLAGS_INDEX] = UVMF_TLB_FLUSH|UVMF_ALL;
    8.21  
    8.22      /* Give away a batch of pages. */
    8.23 -    rx_mcl[i].op = __HYPERVISOR_dom_mem_op;
    8.24 -    rx_mcl[i].args[0] = MEMOP_decrease_reservation;
    8.25 -    rx_mcl[i].args[1] = (unsigned long)rx_pfn_array;
    8.26 -    rx_mcl[i].args[2] = (unsigned long)i;
    8.27 -    rx_mcl[i].args[3] = 0;
    8.28 -    rx_mcl[i].args[4] = DOMID_SELF;
    8.29 +    rx_mcl[i].op = __HYPERVISOR_memory_op;
    8.30 +    rx_mcl[i].args[0] = XENMEM_decrease_reservation;
    8.31 +    rx_mcl[i].args[1] = (unsigned long)&reservation;
    8.32 +
    8.33 +    reservation.extent_start = rx_pfn_array;
    8.34 +    reservation.nr_extents   = i;
    8.35 +    reservation.extent_order = 0;
    8.36 +    reservation.address_bits = 0;
    8.37 +    reservation.domid        = DOMID_SELF;
    8.38  
    8.39      /* Tell the ballon driver what is going on. */
    8.40      balloon_update_driver_allowance(i);
    8.41 @@ -401,7 +406,7 @@ static void network_alloc_rx_buffers(str
    8.42      /* Zap PTEs and give away pages in one big multicall. */
    8.43      (void)HYPERVISOR_multicall(rx_mcl, i+1);
    8.44  
    8.45 -    /* Check return status of HYPERVISOR_dom_mem_op(). */
    8.46 +    /* Check return status of HYPERVISOR_memory_op(). */
    8.47      if (unlikely(rx_mcl[i].result != i))
    8.48          panic("Unable to reduce memory reservation\n");
    8.49  
     9.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h	Tue Aug 30 09:46:33 2005 +0000
     9.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h	Tue Aug 30 11:53:47 2005 +0000
     9.3 @@ -236,12 +236,10 @@ HYPERVISOR_update_descriptor(
     9.4  }
     9.5  
     9.6  static inline int
     9.7 -HYPERVISOR_dom_mem_op(
     9.8 -	unsigned int op, unsigned long *extent_list,
     9.9 -	unsigned long nr_extents, unsigned int extent_order)
    9.10 +HYPERVISOR_memory_op(
    9.11 +	unsigned int cmd, void *arg)
    9.12  {
    9.13 -	return _hypercall5(int, dom_mem_op, op, extent_list,
    9.14 -			   nr_extents, extent_order, DOMID_SELF);
    9.15 +	return _hypercall2(int, memory_op, cmd, arg);
    9.16  }
    9.17  
    9.18  static inline int
    10.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h	Tue Aug 30 09:46:33 2005 +0000
    10.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h	Tue Aug 30 11:53:47 2005 +0000
    10.3 @@ -231,12 +231,10 @@ HYPERVISOR_update_descriptor(
    10.4  }
    10.5  
    10.6  static inline int
    10.7 -HYPERVISOR_dom_mem_op(
    10.8 -	unsigned int op, unsigned long *extent_list,
    10.9 -	unsigned long nr_extents, unsigned int extent_order)
   10.10 +HYPERVISOR_memory_op(
   10.11 +	unsigned int cmd, void *arg)
   10.12  {
   10.13 -	return _hypercall5(int, dom_mem_op, op, extent_list,
   10.14 -			   nr_extents, extent_order, DOMID_SELF);
   10.15 +	return _hypercall2(int, memory_op, cmd, arg);
   10.16  }
   10.17  
   10.18  static inline int
    11.1 --- a/tools/libxc/xc_domain.c	Tue Aug 30 09:46:33 2005 +0000
    11.2 +++ b/tools/libxc/xc_domain.c	Tue Aug 30 11:53:47 2005 +0000
    11.3 @@ -7,6 +7,7 @@
    11.4   */
    11.5  
    11.6  #include "xc_private.h"
    11.7 +#include <xen/memory.h>
    11.8  
    11.9  int xc_domain_create(int xc_handle,
   11.10                       u32 ssidref,
   11.11 @@ -265,9 +266,13 @@ int xc_domain_memory_increase_reservatio
   11.12  {
   11.13      int err;
   11.14      unsigned int npages = mem_kb / (PAGE_SIZE/1024);
   11.15 +    struct xen_memory_reservation reservation = {
   11.16 +        .nr_extents   = npages,
   11.17 +        .extent_order = 0,
   11.18 +        .domid        = DOMID_SELF
   11.19 +    };
   11.20  
   11.21 -    err = xc_dom_mem_op(xc_handle, MEMOP_increase_reservation, NULL,
   11.22 -                        npages, 0, domid);
   11.23 +    err = xc_memory_op(xc_handle, XENMEM_increase_reservation, &reservation);
   11.24      if (err == npages)
   11.25          return 0;
   11.26  
    12.1 --- a/tools/libxc/xc_linux_restore.c	Tue Aug 30 09:46:33 2005 +0000
    12.2 +++ b/tools/libxc/xc_linux_restore.c	Tue Aug 30 11:53:47 2005 +0000
    12.3 @@ -8,11 +8,10 @@
    12.4  
    12.5  #include <stdlib.h>
    12.6  #include <unistd.h>
    12.7 -
    12.8  #include "xg_private.h"
    12.9  #include <xenctrl.h>
   12.10 -
   12.11  #include <xen/linux/suspend.h>
   12.12 +#include <xen/memory.h>
   12.13  
   12.14  #define MAX_BATCH_SIZE 1024
   12.15  
   12.16 @@ -411,7 +410,8 @@ int xc_linux_restore(int xc_handle, int 
   12.17  
   12.18      /* Get the list of PFNs that are not in the psuedo-phys map */
   12.19      {
   12.20 -	unsigned int count, *pfntab;
   12.21 +	unsigned int count;
   12.22 +        unsigned long *pfntab;
   12.23  	int rc;
   12.24  
   12.25  	if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
   12.26 @@ -443,9 +443,15 @@ int xc_linux_restore(int xc_handle, int 
   12.27  
   12.28  	if ( count > 0 )
   12.29  	{
   12.30 -	    if ( (rc = xc_dom_mem_op( xc_handle,
   12.31 -				       MEMOP_decrease_reservation,
   12.32 -				       pfntab, count, 0, dom )) <0 )
   12.33 +            struct xen_memory_reservation reservation = {
   12.34 +                .extent_start = pfntab,
   12.35 +                .nr_extents   = count,
   12.36 +                .extent_order = 0,
   12.37 +                .domid        = DOMID_SELF
   12.38 +            };
   12.39 +	    if ( (rc = xc_memory_op(xc_handle,
   12.40 +                                    XENMEM_decrease_reservation,
   12.41 +                                    &reservation)) != count )
   12.42  	    {
   12.43  		ERR("Could not decrease reservation : %d",rc);
   12.44  		goto out;
    13.1 --- a/tools/libxc/xc_private.c	Tue Aug 30 09:46:33 2005 +0000
    13.2 +++ b/tools/libxc/xc_private.c	Tue Aug 30 11:53:47 2005 +0000
    13.3 @@ -6,6 +6,7 @@
    13.4  
    13.5  #include <zlib.h>
    13.6  #include "xc_private.h"
    13.7 +#include <xen/memory.h>
    13.8  
    13.9  void *xc_map_foreign_batch(int xc_handle, u32 dom, int prot,
   13.10                             unsigned long *arr, int num )
   13.11 @@ -187,28 +188,43 @@ int xc_finish_mmu_updates(int xc_handle,
   13.12      return flush_mmu_updates(xc_handle, mmu);
   13.13  }
   13.14  
   13.15 -int xc_dom_mem_op(int xc_handle,
   13.16 -		  unsigned int memop, 
   13.17 -		  unsigned int *extent_list, 
   13.18 -		  unsigned int nr_extents,
   13.19 -		  unsigned int extent_order,
   13.20 -		  domid_t domid)
   13.21 +int xc_memory_op(int xc_handle,
   13.22 +                 int cmd,
   13.23 +                 void *arg)
   13.24  {
   13.25      privcmd_hypercall_t hypercall;
   13.26 +    struct xen_memory_reservation *reservation = arg;
   13.27      long ret = -EINVAL;
   13.28  
   13.29 -    hypercall.op     = __HYPERVISOR_dom_mem_op;
   13.30 -    hypercall.arg[0] = (unsigned long)memop;
   13.31 -    hypercall.arg[1] = (unsigned long)extent_list;
   13.32 -    hypercall.arg[2] = (unsigned long)nr_extents;
   13.33 -    hypercall.arg[3] = (unsigned long)extent_order;
   13.34 -    hypercall.arg[4] = (unsigned long)domid;
   13.35 +    hypercall.op     = __HYPERVISOR_memory_op;
   13.36 +    hypercall.arg[0] = (unsigned long)cmd;
   13.37 +    hypercall.arg[1] = (unsigned long)arg;
   13.38  
   13.39 -    if ( (extent_list != NULL) && 
   13.40 -         (mlock(extent_list, nr_extents*sizeof(unsigned long)) != 0) )
   13.41 +    switch ( cmd )
   13.42      {
   13.43 -        PERROR("Could not lock memory for Xen hypercall");
   13.44 -        goto out1;
   13.45 +    case XENMEM_increase_reservation:
   13.46 +    case XENMEM_decrease_reservation:
   13.47 +        if ( mlock(reservation, sizeof(*reservation)) != 0 )
   13.48 +        {
   13.49 +            PERROR("Could not mlock");
   13.50 +            goto out1;
   13.51 +        }
   13.52 +        if ( (reservation->extent_start != NULL) &&
   13.53 +             (mlock(reservation->extent_start,
   13.54 +                    reservation->nr_extents * sizeof(unsigned long)) != 0) )
   13.55 +        {
   13.56 +            PERROR("Could not mlock");
   13.57 +            safe_munlock(reservation, sizeof(*reservation));
   13.58 +            goto out1;
   13.59 +        }
   13.60 +        break;
   13.61 +    case XENMEM_maximum_ram_page:
   13.62 +        if ( mlock(arg, sizeof(unsigned long)) != 0 )
   13.63 +        {
   13.64 +            PERROR("Could not mlock");
   13.65 +            goto out1;
   13.66 +        }
   13.67 +        break;
   13.68      }
   13.69  
   13.70      if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
   13.71 @@ -217,8 +233,19 @@ int xc_dom_mem_op(int xc_handle,
   13.72                  " rebuild the user-space tool set?\n",ret,errno);
   13.73      }
   13.74  
   13.75 -    if ( extent_list != NULL )
   13.76 -        safe_munlock(extent_list, nr_extents*sizeof(unsigned long));
   13.77 +    switch ( cmd )
   13.78 +    {
   13.79 +    case XENMEM_increase_reservation:
   13.80 +    case XENMEM_decrease_reservation:
   13.81 +        safe_munlock(reservation, sizeof(*reservation));
   13.82 +        if ( reservation->extent_start != NULL )
   13.83 +            safe_munlock(reservation->extent_start,
   13.84 +                         reservation->nr_extents * sizeof(unsigned long));
   13.85 +        break;
   13.86 +    case XENMEM_maximum_ram_page:
   13.87 +        safe_munlock(arg, sizeof(unsigned long));
   13.88 +        break;
   13.89 +    }
   13.90  
   13.91   out1:
   13.92      return ret;
    14.1 --- a/tools/libxc/xenctrl.h	Tue Aug 30 09:46:33 2005 +0000
    14.2 +++ b/tools/libxc/xenctrl.h	Tue Aug 30 11:53:47 2005 +0000
    14.3 @@ -430,9 +430,7 @@ int xc_ia64_get_pfn_list(int xc_handle, 
    14.4  int xc_mmuext_op(int xc_handle, struct mmuext_op *op, unsigned int nr_ops,
    14.5  		 domid_t dom);
    14.6  
    14.7 -int xc_dom_mem_op(int xc_handle, unsigned int memop, unsigned int *extent_list,
    14.8 -		  unsigned int nr_extents, unsigned int extent_order,
    14.9 -		  domid_t domid);
   14.10 +int xc_memory_op(int xc_handle, int cmd, void *arg);
   14.11  
   14.12  int xc_get_pfn_type_batch(int xc_handle, u32 dom, int num, unsigned long *arr);
   14.13  
    15.1 --- a/xen/arch/x86/x86_32/entry.S	Tue Aug 30 09:46:33 2005 +0000
    15.2 +++ b/xen/arch/x86/x86_32/entry.S	Tue Aug 30 11:53:47 2005 +0000
    15.3 @@ -790,7 +790,7 @@ ENTRY(hypercall_table)
    15.4          .long do_get_debugreg
    15.5          .long do_update_descriptor  /* 10 */
    15.6          .long do_ni_hypercall
    15.7 -        .long do_dom_mem_op
    15.8 +        .long do_memory_op
    15.9          .long do_multicall
   15.10          .long do_update_va_mapping
   15.11          .long do_set_timer_op       /* 15 */
   15.12 @@ -823,7 +823,7 @@ ENTRY(hypercall_args_table)
   15.13          .byte 1 /* do_get_debugreg      */
   15.14          .byte 4 /* do_update_descriptor */  /* 10 */
   15.15          .byte 0 /* do_ni_hypercall      */
   15.16 -        .byte 5 /* do_dom_mem_op        */
   15.17 +        .byte 2 /* do_memory_op         */
   15.18          .byte 2 /* do_multicall         */
   15.19          .byte 4 /* do_update_va_mapping */
   15.20          .byte 2 /* do_set_timer_op      */  /* 15 */
    16.1 --- a/xen/arch/x86/x86_64/entry.S	Tue Aug 30 09:46:33 2005 +0000
    16.2 +++ b/xen/arch/x86/x86_64/entry.S	Tue Aug 30 11:53:47 2005 +0000
    16.3 @@ -616,7 +616,7 @@ ENTRY(hypercall_table)
    16.4          .quad do_get_debugreg
    16.5          .quad do_update_descriptor  /* 10 */
    16.6          .quad do_ni_hypercall
    16.7 -        .quad do_dom_mem_op
    16.8 +        .quad do_memory_op
    16.9          .quad do_multicall
   16.10          .quad do_update_va_mapping
   16.11          .quad do_set_timer_op       /* 15 */
   16.12 @@ -649,7 +649,7 @@ ENTRY(hypercall_args_table)
   16.13          .byte 1 /* do_get_debugreg      */
   16.14          .byte 2 /* do_update_descriptor */  /* 10 */
   16.15          .byte 0 /* do_ni_hypercall      */
   16.16 -        .byte 5 /* do_dom_mem_op        */
   16.17 +        .byte 2 /* do_memory_op         */
   16.18          .byte 2 /* do_multicall         */
   16.19          .byte 3 /* do_update_va_mapping */
   16.20          .byte 1 /* do_set_timer_op      */  /* 15 */
    17.1 --- a/xen/common/Makefile	Tue Aug 30 09:46:33 2005 +0000
    17.2 +++ b/xen/common/Makefile	Tue Aug 30 11:53:47 2005 +0000
    17.3 @@ -2,7 +2,6 @@
    17.4  include $(BASEDIR)/Rules.mk
    17.5  
    17.6  ifeq ($(TARGET_ARCH),ia64)
    17.7 -#OBJS := $(subst dom_mem_ops.o,,$(OBJS))
    17.8  OBJS := $(subst grant_table.o,,$(OBJS))
    17.9  endif
   17.10  
    18.1 --- a/xen/common/dom_mem_ops.c	Tue Aug 30 09:46:33 2005 +0000
    18.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.3 @@ -1,186 +0,0 @@
    18.4 -/******************************************************************************
    18.5 - * dom_mem_ops.c
    18.6 - *
    18.7 - * Code to handle memory related requests from domains eg. balloon driver.
    18.8 - *
    18.9 - * Copyright (c) 2003-2004, B Dragovic & K A Fraser.
   18.10 - */
   18.11 -
   18.12 -#include <xen/config.h>
   18.13 -#include <xen/types.h>
   18.14 -#include <xen/lib.h>
   18.15 -#include <xen/mm.h>
   18.16 -#include <xen/perfc.h>
   18.17 -#include <xen/sched.h>
   18.18 -#include <xen/event.h>
   18.19 -#include <xen/shadow.h>
   18.20 -#include <asm/current.h>
   18.21 -#include <asm/hardirq.h>
   18.22 -
   18.23 -/*
   18.24 - * To allow safe resume of do_dom_mem_op() after preemption, we need to know 
   18.25 - * at what point in the page list to resume. For this purpose I steal the 
   18.26 - * high-order bits of the @op parameter, which are otherwise unused and zero.
   18.27 - */
   18.28 -#define START_EXTENT_SHIFT 4 /* op[:4] == start_extent */
   18.29 -
   18.30 -#define PREEMPT_CHECK(_op)                          \
   18.31 -    if ( hypercall_preempt_check() )                \
   18.32 -        return hypercall5_create_continuation(      \
   18.33 -            __HYPERVISOR_dom_mem_op,                \
   18.34 -            (_op) | (i << START_EXTENT_SHIFT),      \
   18.35 -            extent_list, nr_extents, extent_order,  \
   18.36 -            (d == current->domain) ? DOMID_SELF : d->domain_id);
   18.37 -
   18.38 -static long
   18.39 -alloc_dom_mem(struct domain *d, 
   18.40 -              unsigned long *extent_list, 
   18.41 -              unsigned long  start_extent,
   18.42 -              unsigned int   nr_extents,
   18.43 -              unsigned int   extent_order,
   18.44 -    		  unsigned int   flags)
   18.45 -{
   18.46 -    struct pfn_info *page;
   18.47 -    unsigned long    i;
   18.48 -
   18.49 -    if ( (extent_list != NULL) && 
   18.50 -         !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   18.51 -        return start_extent;
   18.52 -
   18.53 -    if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current->domain) )
   18.54 -    {
   18.55 -        DPRINTK("Only I/O-capable domains may allocate > order-0 memory.\n");
   18.56 -        return start_extent;
   18.57 -    }
   18.58 -
   18.59 -    for ( i = start_extent; i < nr_extents; i++ )
   18.60 -    {
   18.61 -        PREEMPT_CHECK(MEMOP_increase_reservation);
   18.62 -
   18.63 -        if ( unlikely((page = alloc_domheap_pages(d, extent_order,
   18.64 -                                                  flags)) == NULL) )
   18.65 -        {
   18.66 -            DPRINTK("Could not allocate a frame\n");
   18.67 -            return i;
   18.68 -        }
   18.69 -
   18.70 -        /* Inform the domain of the new page's machine address. */ 
   18.71 -        if ( (extent_list != NULL) && 
   18.72 -             (__put_user(page_to_pfn(page), &extent_list[i]) != 0) )
   18.73 -            return i;
   18.74 -    }
   18.75 -
   18.76 -    return i;
   18.77 -}
   18.78 -    
   18.79 -static long
   18.80 -free_dom_mem(struct domain *d,
   18.81 -             unsigned long *extent_list, 
   18.82 -             unsigned long  start_extent,
   18.83 -             unsigned int   nr_extents,
   18.84 -             unsigned int   extent_order)
   18.85 -{
   18.86 -    struct pfn_info *page;
   18.87 -    unsigned long    i, j, mpfn;
   18.88 -
   18.89 -    if ( !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   18.90 -        return start_extent;
   18.91 -
   18.92 -    for ( i = start_extent; i < nr_extents; i++ )
   18.93 -    {
   18.94 -        PREEMPT_CHECK(MEMOP_decrease_reservation);
   18.95 -
   18.96 -        if ( unlikely(__get_user(mpfn, &extent_list[i]) != 0) )
   18.97 -            return i;
   18.98 -
   18.99 -        for ( j = 0; j < (1 << extent_order); j++ )
  18.100 -        {
  18.101 -            if ( unlikely((mpfn + j) >= max_page) )
  18.102 -            {
  18.103 -                DPRINTK("Domain %u page number out of range (%lx >= %lx)\n", 
  18.104 -                        d->domain_id, mpfn + j, max_page);
  18.105 -                return i;
  18.106 -            }
  18.107 -            
  18.108 -            page = &frame_table[mpfn + j];
  18.109 -            if ( unlikely(!get_page(page, d)) )
  18.110 -            {
  18.111 -                DPRINTK("Bad page free for domain %u\n", d->domain_id);
  18.112 -                return i;
  18.113 -            }
  18.114 -
  18.115 -            if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) )
  18.116 -                put_page_and_type(page);
  18.117 -            
  18.118 -            if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
  18.119 -                put_page(page);
  18.120 -
  18.121 -            shadow_sync_and_drop_references(d, page);
  18.122 -
  18.123 -            put_page(page);
  18.124 -        }
  18.125 -    }
  18.126 -
  18.127 -    return i;
  18.128 -}
  18.129 -
  18.130 -long
  18.131 -do_dom_mem_op(unsigned long  op, 
  18.132 -              unsigned long *extent_list, 
  18.133 -              unsigned int   nr_extents,
  18.134 -              unsigned int   extent_order,
  18.135 -              domid_t        domid)
  18.136 -{
  18.137 -    struct domain *d;
  18.138 -    unsigned long  rc, start_extent;
  18.139 -    unsigned int   address_bits_order;
  18.140 -
  18.141 -    /* Extract @start_extent from @op. */
  18.142 -    start_extent  = op >> START_EXTENT_SHIFT;
  18.143 -    op           &= (1 << START_EXTENT_SHIFT) - 1;
  18.144 -
  18.145 -    /* seperate extent_order and address_bits_order */
  18.146 -    address_bits_order = (extent_order >> 8) & 0xff;
  18.147 -    extent_order &= 0xff;
  18.148 -
  18.149 -    if ( unlikely(start_extent > nr_extents) )
  18.150 -        return -EINVAL;
  18.151 -
  18.152 -    if ( likely(domid == DOMID_SELF) )
  18.153 -        d = current->domain;
  18.154 -    else if ( unlikely(!IS_PRIV(current->domain)) )
  18.155 -        return -EPERM;
  18.156 -    else if ( unlikely((d = find_domain_by_id(domid)) == NULL) )
  18.157 -        return -ESRCH;
  18.158 -
  18.159 -    switch ( op )
  18.160 -    {
  18.161 -    case MEMOP_increase_reservation:
  18.162 -        rc = alloc_dom_mem(
  18.163 -            d, extent_list, start_extent, nr_extents, extent_order,
  18.164 -            (address_bits_order <= 32) ? ALLOC_DOM_DMA : 0);
  18.165 -        break;
  18.166 -    case MEMOP_decrease_reservation:
  18.167 -        rc = free_dom_mem(
  18.168 -            d, extent_list, start_extent, nr_extents, extent_order);
  18.169 -        break;
  18.170 -    default:
  18.171 -        rc = -ENOSYS;
  18.172 -        break;
  18.173 -    }
  18.174 -
  18.175 -    if ( unlikely(domid != DOMID_SELF) )
  18.176 -        put_domain(d);
  18.177 -
  18.178 -    return rc;
  18.179 -}
  18.180 -
  18.181 -/*
  18.182 - * Local variables:
  18.183 - * mode: C
  18.184 - * c-set-style: "BSD"
  18.185 - * c-basic-offset: 4
  18.186 - * tab-width: 4
  18.187 - * indent-tabs-mode: nil
  18.188 - * End:
  18.189 - */
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/xen/common/memory.c	Tue Aug 30 11:53:47 2005 +0000
    19.3 @@ -0,0 +1,205 @@
    19.4 +/******************************************************************************
    19.5 + * memory.c
    19.6 + *
    19.7 + * Code to handle memory-related requests.
    19.8 + *
    19.9 + * Copyright (c) 2003-2004, B Dragovic
   19.10 + * Copyright (c) 2003-2005, K A Fraser
   19.11 + */
   19.12 +
   19.13 +#include <xen/config.h>
   19.14 +#include <xen/types.h>
   19.15 +#include <xen/lib.h>
   19.16 +#include <xen/mm.h>
   19.17 +#include <xen/perfc.h>
   19.18 +#include <xen/sched.h>
   19.19 +#include <xen/event.h>
   19.20 +#include <xen/shadow.h>
   19.21 +#include <asm/current.h>
   19.22 +#include <asm/hardirq.h>
   19.23 +#include <public/memory.h>
   19.24 +
   19.25 +static long
   19.26 +increase_reservation(
   19.27 +    struct domain *d, 
   19.28 +    unsigned long *extent_list, 
   19.29 +    unsigned int   nr_extents,
   19.30 +    unsigned int   extent_order,
   19.31 +    unsigned int   flags)
   19.32 +{
   19.33 +    struct pfn_info *page;
   19.34 +    unsigned long    i;
   19.35 +
   19.36 +    if ( (extent_list != NULL)
   19.37 +         && !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   19.38 +        return 0;
   19.39 +
   19.40 +    if ( (extent_order != 0) && !IS_CAPABLE_PHYSDEV(current->domain) )
   19.41 +    {
   19.42 +        DPRINTK("Only I/O-capable domains may allocate > order-0 memory.\n");
   19.43 +        return 0;
   19.44 +    }
   19.45 +
   19.46 +    for ( i = 0; i < nr_extents; i++ )
   19.47 +    {
   19.48 +        if ( hypercall_preempt_check() )
   19.49 +            return i;
   19.50 +
   19.51 +        if ( unlikely((page = alloc_domheap_pages(
   19.52 +            d, extent_order, flags)) == NULL) )
   19.53 +        {
   19.54 +            DPRINTK("Could not allocate a frame\n");
   19.55 +            return i;
   19.56 +        }
   19.57 +
   19.58 +        /* Inform the domain of the new page's machine address. */ 
   19.59 +        if ( (extent_list != NULL)
   19.60 +             && (__put_user(page_to_pfn(page), &extent_list[i]) != 0) )
   19.61 +            return i;
   19.62 +    }
   19.63 +
   19.64 +    return nr_extents;
   19.65 +}
   19.66 +    
   19.67 +static long
   19.68 +decrease_reservation(
   19.69 +    struct domain *d, 
   19.70 +    unsigned long *extent_list, 
   19.71 +    unsigned int   nr_extents,
   19.72 +    unsigned int   extent_order,
   19.73 +    unsigned int   flags)
   19.74 +{
   19.75 +    struct pfn_info *page;
   19.76 +    unsigned long    i, j, mpfn;
   19.77 +
   19.78 +    if ( !array_access_ok(extent_list, nr_extents, sizeof(*extent_list)) )
   19.79 +        return 0;
   19.80 +
   19.81 +    for ( i = 0; i < nr_extents; i++ )
   19.82 +    {
   19.83 +        if ( hypercall_preempt_check() )
   19.84 +            return i;
   19.85 +
   19.86 +        if ( unlikely(__get_user(mpfn, &extent_list[i]) != 0) )
   19.87 +            return i;
   19.88 +
   19.89 +        for ( j = 0; j < (1 << extent_order); j++ )
   19.90 +        {
   19.91 +            if ( unlikely((mpfn + j) >= max_page) )
   19.92 +            {
   19.93 +                DPRINTK("Domain %u page number out of range (%lx >= %lx)\n", 
   19.94 +                        d->domain_id, mpfn + j, max_page);
   19.95 +                return i;
   19.96 +            }
   19.97 +            
   19.98 +            page = &frame_table[mpfn + j];
   19.99 +            if ( unlikely(!get_page(page, d)) )
  19.100 +            {
  19.101 +                DPRINTK("Bad page free for domain %u\n", d->domain_id);
  19.102 +                return i;
  19.103 +            }
  19.104 +
  19.105 +            if ( test_and_clear_bit(_PGT_pinned, &page->u.inuse.type_info) )
  19.106 +                put_page_and_type(page);
  19.107 +            
  19.108 +            if ( test_and_clear_bit(_PGC_allocated, &page->count_info) )
  19.109 +                put_page(page);
  19.110 +
  19.111 +            shadow_sync_and_drop_references(d, page);
  19.112 +
  19.113 +            put_page(page);
  19.114 +        }
  19.115 +    }
  19.116 +
  19.117 +    return nr_extents;
  19.118 +}
  19.119 +
  19.120 +/*
  19.121 + * To allow safe resume of do_memory_op() after preemption, we need to know 
  19.122 + * at what point in the page list to resume. For this purpose I steal the 
  19.123 + * high-order bits of the @cmd parameter, which are otherwise unused and zero.
  19.124 + */
  19.125 +#define START_EXTENT_SHIFT 4 /* cmd[:4] == start_extent */
  19.126 +
  19.127 +long do_memory_op(int cmd, void *arg)
  19.128 +{
  19.129 +    struct domain *d;
  19.130 +    int rc, start_extent, op, flags = 0;
  19.131 +    struct xen_memory_reservation reservation;
  19.132 +
  19.133 +    op = cmd & ((1 << START_EXTENT_SHIFT) - 1);
  19.134 +
  19.135 +    switch ( op )
  19.136 +    {
  19.137 +    case XENMEM_increase_reservation:
  19.138 +    case XENMEM_decrease_reservation:
  19.139 +        if ( copy_from_user(&reservation, arg, sizeof(reservation)) )
  19.140 +            return -EFAULT;
  19.141 +
  19.142 +        start_extent = cmd >> START_EXTENT_SHIFT;
  19.143 +        if ( unlikely(start_extent > reservation.nr_extents) )
  19.144 +            return -EINVAL;
  19.145 +        
  19.146 +        if ( reservation.extent_start != NULL )
  19.147 +            reservation.extent_start += start_extent;
  19.148 +        reservation.nr_extents -= start_extent;
  19.149 +
  19.150 +        if ( unlikely(reservation.address_bits != 0)
  19.151 +             && (reservation.address_bits > (get_order(max_page)+PAGE_SHIFT)) )
  19.152 +        {
  19.153 +            if ( reservation.address_bits < 31 )
  19.154 +                return -ENOMEM;
  19.155 +            flags = ALLOC_DOM_DMA;
  19.156 +        }
  19.157 +
  19.158 +        if ( likely(reservation.domid == DOMID_SELF) )
  19.159 +            d = current->domain;
  19.160 +        else if ( !IS_PRIV(current->domain) )
  19.161 +            return -EPERM;
  19.162 +        else if ( (d = find_domain_by_id(reservation.domid)) == NULL )
  19.163 +            return -ESRCH;
  19.164 +
  19.165 +        rc = ((op == XENMEM_increase_reservation) ?
  19.166 +              increase_reservation : decrease_reservation)(
  19.167 +                  d,
  19.168 +                  reservation.extent_start,
  19.169 +                  reservation.nr_extents,
  19.170 +                  reservation.extent_order,
  19.171 +                  flags);
  19.172 +
  19.173 +        if ( unlikely(reservation.domid != DOMID_SELF) )
  19.174 +            put_domain(d);
  19.175 +
  19.176 +        rc += start_extent;
  19.177 +
  19.178 +        if ( (rc != reservation.nr_extents) && hypercall_preempt_check() )
  19.179 +            return hypercall2_create_continuation(
  19.180 +                __HYPERVISOR_memory_op,
  19.181 +                op | (rc << START_EXTENT_SHIFT),
  19.182 +                arg);
  19.183 +        
  19.184 +        break;
  19.185 +
  19.186 +    case XENMEM_maximum_ram_page:
  19.187 +        if ( put_user(max_page, (unsigned long *)arg) )
  19.188 +            return -EFAULT;
  19.189 +        rc = -ENOSYS;
  19.190 +        break;
  19.191 +
  19.192 +    default:
  19.193 +        rc = -ENOSYS;
  19.194 +        break;
  19.195 +    }
  19.196 +
  19.197 +    return rc;
  19.198 +}
  19.199 +
  19.200 +/*
  19.201 + * Local variables:
  19.202 + * mode: C
  19.203 + * c-set-style: "BSD"
  19.204 + * c-basic-offset: 4
  19.205 + * tab-width: 4
  19.206 + * indent-tabs-mode: nil
  19.207 + * End:
  19.208 + */
    20.1 --- a/xen/common/page_alloc.c	Tue Aug 30 09:46:33 2005 +0000
    20.2 +++ b/xen/common/page_alloc.c	Tue Aug 30 11:53:47 2005 +0000
    20.3 @@ -216,7 +216,7 @@ unsigned long alloc_boot_pages(unsigned 
    20.4  #define NR_ZONES    3
    20.5  
    20.6  
    20.7 -#define MAX_DMADOM_PFN 0xFFFFF
    20.8 +#define MAX_DMADOM_PFN 0x7FFFF /* 31 addressable bits */
    20.9  #define pfn_dom_zone_type(_pfn)                                 \
   20.10      (((_pfn) <= MAX_DMADOM_PFN) ? MEMZONE_DMADOM : MEMZONE_DOM)
   20.11  
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/xen/include/public/memory.h	Tue Aug 30 11:53:47 2005 +0000
    21.3 @@ -0,0 +1,50 @@
    21.4 +/******************************************************************************
    21.5 + * memory.h
    21.6 + * 
    21.7 + * Memory reservation and information.
    21.8 + * 
    21.9 + * Copyright (c) 2005, Keir Fraser <keir@xensource.com>
   21.10 + */
   21.11 +
   21.12 +#ifndef __XEN_PUBLIC_MEMORY_H__
   21.13 +#define __XEN_PUBLIC_MEMORY_H__
   21.14 +
   21.15 +/* arg == addr of struct xen_memory_reservation. */
   21.16 +#define XENMEM_increase_reservation 0
   21.17 +
   21.18 +/* arg == addr of struct xen_memory_reservation. */
   21.19 +#define XENMEM_decrease_reservation 1
   21.20 +
   21.21 +/* arg == addr of unsigned long. */
   21.22 +#define XENMEM_maximum_ram_page     2
   21.23 +
   21.24 +typedef struct xen_memory_reservation {
   21.25 +
   21.26 +    /*
   21.27 +     * MFN bases of extents to free (XENMEM_decrease_reservation).
   21.28 +     * MFN bases of extents that were allocated (XENMEM_increase_reservation).
   21.29 +     */
   21.30 +    unsigned long *extent_start;
   21.31 +
   21.32 +    /* Number of extents, and size/alignment of each (2^extent_order pages). */
   21.33 +    unsigned long  nr_extents;
   21.34 +    unsigned int   extent_order;
   21.35 +
   21.36 +    /*
   21.37 +     * XENMEM_increase_reservation: maximum # bits addressable by the user
   21.38 +     * of the allocated region (e.g., I/O devices often have a 32-bit
   21.39 +     * limitation even in 64-bit systems). If zero then the user has no
   21.40 +     * addressing restriction.
   21.41 +     * XENMEM_decrease_reservation: unused.
   21.42 +     */
   21.43 +    unsigned int   address_bits;
   21.44 +
   21.45 +    /*
   21.46 +     * Domain whose reservation is being changed.
   21.47 +     * Unprivileged domains can specify only DOMID_SELF.
   21.48 +     */
   21.49 +    domid_t        domid;
   21.50 +
   21.51 +} xen_memory_reservation_t;
   21.52 +
   21.53 +#endif /* __XEN_PUBLIC_MEMORY_H__ */
    22.1 --- a/xen/include/public/xen.h	Tue Aug 30 09:46:33 2005 +0000
    22.2 +++ b/xen/include/public/xen.h	Tue Aug 30 11:53:47 2005 +0000
    22.3 @@ -42,7 +42,7 @@
    22.4  #define __HYPERVISOR_set_debugreg          8
    22.5  #define __HYPERVISOR_get_debugreg          9
    22.6  #define __HYPERVISOR_update_descriptor    10
    22.7 -#define __HYPERVISOR_dom_mem_op           12
    22.8 +#define __HYPERVISOR_memory_op            12
    22.9  #define __HYPERVISOR_multicall            13
   22.10  #define __HYPERVISOR_update_va_mapping    14
   22.11  #define __HYPERVISOR_set_timer_op         15
   22.12 @@ -225,12 +225,6 @@ struct mmuext_op {
   22.13  #define CONSOLEIO_read          1
   22.14  
   22.15  /*
   22.16 - * Commands to HYPERVISOR_dom_mem_op().
   22.17 - */
   22.18 -#define MEMOP_increase_reservation 0
   22.19 -#define MEMOP_decrease_reservation 1
   22.20 -
   22.21 -/*
   22.22   * Commands to HYPERVISOR_vm_assist().
   22.23   */
   22.24  #define VMASST_CMD_enable                0