Skip to content

Commit

Permalink
xen: re-introduce support for grant v2 interface
Browse files Browse the repository at this point in the history
The grant v2 support was removed from the kernel with
commit 438b33c ("xen/grant-table:
remove support for V2 tables") as the higher memory footprint of v2
grants resulted in less grants being possible for a kernel compared
to the v1 grant interface.

As machines with more than 16TB of memory are expected to be more
common in the near future support of grant v2 is mandatory in order
to be able to run a Xen pv domain at any memory location.

So re-add grant v2 support basically by reverting above commit.

Signed-off-by: Juergen Gross <[email protected]>
Reviewed-by: Boris Ostrovsky <[email protected]>
Signed-off-by: Boris Ostrovsky <[email protected]>
  • Loading branch information
jgross1 authored and Boris Ostrovsky committed Nov 6, 2017
1 parent ec4001c commit b988b8f
Show file tree
Hide file tree
Showing 4 changed files with 398 additions and 13 deletions.
9 changes: 8 additions & 1 deletion arch/arm/xen/grant-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,14 @@ void arch_gnttab_unmap(void *shared, unsigned long nr_gframes)
return;
}

int arch_gnttab_init(unsigned long nr_shared)
int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes,
unsigned long max_nr_gframes,
grant_status_t **__shared)
{
return -ENOSYS;
}

int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status)
{
return 0;
}
60 changes: 55 additions & 5 deletions arch/x86/xen/grant-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
static struct gnttab_vm_area {
struct vm_struct *area;
pte_t **ptes;
} gnttab_shared_vm_area;
} gnttab_shared_vm_area, gnttab_status_vm_area;

int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
unsigned long max_nr_gframes,
Expand All @@ -73,16 +73,43 @@ int arch_gnttab_map_shared(unsigned long *frames, unsigned long nr_gframes,
return 0;
}

int arch_gnttab_map_status(uint64_t *frames, unsigned long nr_gframes,
unsigned long max_nr_gframes,
grant_status_t **__shared)
{
grant_status_t *shared = *__shared;
unsigned long addr;
unsigned long i;

if (shared == NULL)
*__shared = shared = gnttab_status_vm_area.area->addr;

addr = (unsigned long)shared;

for (i = 0; i < nr_gframes; i++) {
set_pte_at(&init_mm, addr, gnttab_status_vm_area.ptes[i],
mfn_pte(frames[i], PAGE_KERNEL));
addr += PAGE_SIZE;
}

return 0;
}

void arch_gnttab_unmap(void *shared, unsigned long nr_gframes)
{
pte_t **ptes;
unsigned long addr;
unsigned long i;

if (shared == gnttab_status_vm_area.area->addr)
ptes = gnttab_status_vm_area.ptes;
else
ptes = gnttab_shared_vm_area.ptes;

addr = (unsigned long)shared;

for (i = 0; i < nr_gframes; i++) {
set_pte_at(&init_mm, addr, gnttab_shared_vm_area.ptes[i],
__pte(0));
set_pte_at(&init_mm, addr, ptes[i], __pte(0));
addr += PAGE_SIZE;
}
}
Expand All @@ -102,12 +129,35 @@ static int arch_gnttab_valloc(struct gnttab_vm_area *area, unsigned nr_frames)
return 0;
}

int arch_gnttab_init(unsigned long nr_shared)
static void arch_gnttab_vfree(struct gnttab_vm_area *area)
{
free_vm_area(area->area);
kfree(area->ptes);
}

int arch_gnttab_init(unsigned long nr_shared, unsigned long nr_status)
{
int ret;

if (!xen_pv_domain())
return 0;

return arch_gnttab_valloc(&gnttab_shared_vm_area, nr_shared);
ret = arch_gnttab_valloc(&gnttab_shared_vm_area, nr_shared);
if (ret < 0)
return ret;

/*
* Always allocate the space for the status frames in case
* we're migrated to a host with V2 support.
*/
ret = arch_gnttab_valloc(&gnttab_status_vm_area, nr_status);
if (ret < 0)
goto err;

return 0;
err:
arch_gnttab_vfree(&gnttab_shared_vm_area);
return -ENOMEM;
}

#ifdef CONFIG_XEN_PVH
Expand Down
Loading

0 comments on commit b988b8f

Please sign in to comment.