From: "Siddha, Suresh B" Subject: [Patch] by default don't give all memory to dom0 Date: Thu, 18 Aug 2005 12:24:13 -0700 Message-ID: <20050818122413.C17270@unix-os.sc.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Keir.Fraser@cl.cam.ac.uk Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org On a system where swiotlb is used, by default xen fails to allocate memory for dom0's swiotlb contiguous memory request. By default, xen needs to reserve some portion of memory to satisfy SWIOTLB and other contguous memory region requests. Following the current swiotlb enabling mechanism, Appended patch reserves 128MB of memory on systems with more than 2GB of RAM. Ideally shouldn't we enable SWIOTLB in dom0 and this DMA memory reservation in hypervisor by default? Otherwise we will have a problem(even on systems with less than 2GB of RAM) in servicing a driver DMA request to a kmalloc'd buffer which spans more than a page or the various xen_create_contiguous_region() requests. Signed-off-by: Suresh Siddha diff -r 84ee014ebd41 xen/arch/x86/domain_build.c --- a/xen/arch/x86/domain_build.c Wed Aug 17 20:34:38 2005 +++ b/xen/arch/x86/domain_build.c Thu Aug 18 11:52:57 2005 @@ -34,6 +34,18 @@ opt_dom0_mem = (unsigned int)(bytes >> 10); } custom_param("dom0_mem", parse_dom0_mem); + +static unsigned int reserve_dmapages = 0; +static void parse_reserve_dmamem(char *s) +{ + unsigned long long bytes = parse_size_and_unit(s); + /* If no unit is specified we default to kB units, not bytes. */ + if ( isdigit(s[strlen(s)-1]) ) + reserve_dmapages = (unsigned int)bytes >> (PAGE_SHIFT - 10); + else + reserve_dmapages = (unsigned int)(bytes >> PAGE_SHIFT); +} +custom_param("dma_mem", parse_reserve_dmamem); static unsigned int opt_dom0_shadow = 0; boolean_param("dom0_shadow", opt_dom0_shadow); @@ -137,10 +149,13 @@ printk("*** LOADING DOMAIN 0 ***\n"); - /* By default DOM0 is allocated all available memory. */ d->max_pages = ~0U; + /* By default DOM0 is allocated (all available memory - reserved dma + low memory) */ + if (!reserve_dmapages && max_page > 0x7ffff) + reserve_dmapages = 32 * 1024; /* 128MB */ if ( (nr_pages = opt_dom0_mem >> (PAGE_SHIFT - 10)) == 0 ) - nr_pages = avail_domheap_pages() + + nr_pages = avail_domheap_pages() - reserve_dmapages + ((initrd_len + PAGE_SIZE - 1) >> PAGE_SHIFT) + ((image_len + PAGE_SIZE - 1) >> PAGE_SHIFT);