x86/xen: open code alloc_vm_area in arch_gnttab_valloc

Replace the last call to alloc_vm_area with an open coded version using an
iterator in struct gnttab_vm_area instead of the triple indirection magic
in alloc_vm_area.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reviewed-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Link: https://lkml.kernel.org/r/20201002122204.1534411-11-hch@lst.de
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Christoph Hellwig 2020-10-17 16:15:36 -07:00 committed by Linus Torvalds
parent b723caece3
commit 5dd63bf1d0

View File

@ -25,6 +25,7 @@
static struct gnttab_vm_area { static struct gnttab_vm_area {
struct vm_struct *area; struct vm_struct *area;
pte_t **ptes; pte_t **ptes;
int idx;
} gnttab_shared_vm_area, gnttab_status_vm_area; } gnttab_shared_vm_area, gnttab_status_vm_area;
int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes, int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
@ -90,21 +91,33 @@ void arch_gnttab_unmap(void *shared, unsigned long nr_gframes)
} }
} }
static int gnttab_apply(pte_t *pte, unsigned long addr, void *data)
{
struct gnttab_vm_area *area = data;
area->ptes[area->idx++] = pte;
return 0;
}
static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames) static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames)
{ {
area->ptes = kmalloc_array(nr_frames, sizeof(*area->ptes), GFP_KERNEL); area->ptes = kmalloc_array(nr_frames, sizeof(*area->ptes), GFP_KERNEL);
if (area->ptes == NULL) if (area->ptes == NULL)
return -ENOMEM; return -ENOMEM;
area->area = get_vm_area(PAGE_SIZE * nr_frames, VM_IOREMAP);
area->area = alloc_vm_area(PAGE_SIZE * nr_frames, area->ptes); if (!area->area)
if (area->area == NULL) { goto out_free_ptes;
if (apply_to_page_range(&init_mm, (unsigned long)area->area->addr,
PAGE_SIZE * nr_frames, gnttab_apply, area))
goto out_free_vm_area;
return 0;
out_free_vm_area:
free_vm_area(area->area);
out_free_ptes:
kfree(area->ptes); kfree(area->ptes);
return -ENOMEM; return -ENOMEM;
} }
return 0;
}
static void arch_gnttab_vfree(struct gnttab_vm_area *area) static void arch_gnttab_vfree(struct gnttab_vm_area *area)
{ {
free_vm_area(area->area); free_vm_area(area->area);