From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423110AbXEEFYN (ORCPT ); Sat, 5 May 2007 01:24:13 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1423102AbXEEFYN (ORCPT ); Sat, 5 May 2007 01:24:13 -0400 Received: from 50.sub-75-208-68.myvzw.com ([75.208.68.50]:33047 "EHLO mail.goop.org" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754641AbXEEFYN (ORCPT ); Sat, 5 May 2007 01:24:13 -0400 X-Greylist: delayed 4997 seconds by postgrey-1.27 at vger.kernel.org; Sat, 05 May 2007 01:24:12 EDT Message-Id: <20070504232119.196309373@goop.org> References: <20070504232051.411946839@goop.org> User-Agent: quilt/0.46-1 Date: Fri, 04 May 2007 16:20:53 -0700 From: Jeremy Fitzhardinge To: Andi Kleen Cc: Andrew Morton , virtualization@lists.osdl.org, lkml , Chris Wright , Ian Pratt , Christian Limpach , "Jan Beulich" , "Andi Kleen" Subject: [patch 02/29] xen: Allocate and free vmalloc areas Content-Disposition: inline; filename=alloc-vm-area.patch Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Allocate/destroy a 'vmalloc' VM area: alloc_vm_area and free_vm_area The alloc function ensures that page tables are constructed for the region of kernel virtual address space and mapped into init_mm. Signed-off-by: Jeremy Fitzhardinge Signed-off-by: Ian Pratt Signed-off-by: Christian Limpach Signed-off-by: Chris Wright Cc: "Jan Beulich" Cc: "Andi Kleen" --- include/linux/vmalloc.h | 4 +++ mm/vmalloc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) =================================================================== --- a/include/linux/vmalloc.h +++ b/include/linux/vmalloc.h @@ -68,6 +68,10 @@ extern int map_vm_area(struct vm_struct struct page ***pages); extern void unmap_vm_area(struct vm_struct *area); +/* Allocate/destroy a 'vmalloc' VM area. */ +extern struct vm_struct *alloc_vm_area(unsigned long size); +extern void free_vm_area(struct vm_struct *area); + /* * Internals. Dont't use.. */ =================================================================== --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -757,3 +757,54 @@ out_einval_locked: } EXPORT_SYMBOL(remap_vmalloc_range); +static int f(pte_t *pte, struct page *pmd_page, unsigned long addr, void *data) +{ + /* apply_to_page_range() does all the hard work. */ + return 0; +} + +/** + * alloc_vm_area - allocate a range of kernel address space + * @size: size of the area + * @returns: NULL on failure, vm_struct on success + * + * This function reserves a range of kernel address space, and + * allocates pagetables to map that range. No actual mappings + * are created. If the kernel address space is not shared + * between processes, it syncs the pagetable across all + * processes. + */ +struct vm_struct *alloc_vm_area(unsigned long size) +{ + struct vm_struct *area; + + area = get_vm_area(size, VM_IOREMAP); + if (area == NULL) + return NULL; + + /* + * This ensures that page tables are constructed for this region + * of kernel virtual address space and mapped into init_mm. + */ + if (apply_to_page_range(&init_mm, (unsigned long)area->addr, + area->size, f, NULL)) { + free_vm_area(area); + return NULL; + } + + /* Make sure the pagetables are constructed in process kernel + mappings */ + vmalloc_sync_all(); + + return area; +} +EXPORT_SYMBOL_GPL(alloc_vm_area); + +void free_vm_area(struct vm_struct *area) +{ + struct vm_struct *ret; + ret = remove_vm_area(area->addr); + BUG_ON(ret != area); + kfree(area); +} +EXPORT_SYMBOL_GPL(free_vm_area); --