Skip to content

Commit

Permalink
xen/gntdev,gntalloc: Remove unneeded VM flags
Browse files Browse the repository at this point in the history
The only time when granted pages need to be treated specially is when
using Xen's PTE modification for grant mappings owned by another domain
(that is, only gntdev on PV guests).  Otherwise, the area does not
require VM_DONTCOPY and VM_PFNMAP, since it can be accessed just like
any other page of RAM.

Since the vm_operations_struct close operations decrement reference
counts, a corresponding open function that increments them is required
now that it is possible to have multiple references to a single area.

We are careful in the gntdev to check if we can remove those flags. The
reason that we need to be careful in gntdev on PV guests is because we are
not changing the PFN/MFN mapping on PV; instead, we change the application's
page tables to point to the other domain's memory. This means that the vma
cannot be copied without using another grant mapping hypercall; it also
requires special handling on unmap, which is the reason for gntdev's
dependency on the MMU notifier.

For gntalloc, this is not a concern - the pages are owned by the domain
using the gntalloc device, and can be mapped and unmapped in the same manner
as any other page of memory.

Acked-by: Ian Campbell <[email protected]>
Signed-off-by: Daniel De Graaf <[email protected]>
Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
[v2: Added in git commit "We are.." from email correspondence]
  • Loading branch information
dgdegraaf authored and konradwilk committed Mar 10, 2011
1 parent 38eaeb0 commit d79647a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
14 changes: 12 additions & 2 deletions drivers/xen/gntalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,17 @@ static long gntalloc_ioctl(struct file *filp, unsigned int cmd,
return 0;
}

static void gntalloc_vma_open(struct vm_area_struct *vma)
{
struct gntalloc_gref *gref = vma->vm_private_data;
if (!gref)
return;

spin_lock(&gref_lock);
gref->users++;
spin_unlock(&gref_lock);
}

static void gntalloc_vma_close(struct vm_area_struct *vma)
{
struct gntalloc_gref *gref = vma->vm_private_data;
Expand All @@ -441,6 +452,7 @@ static void gntalloc_vma_close(struct vm_area_struct *vma)
}

static struct vm_operations_struct gntalloc_vmops = {
.open = gntalloc_vma_open,
.close = gntalloc_vma_close,
};

Expand Down Expand Up @@ -471,8 +483,6 @@ static int gntalloc_mmap(struct file *filp, struct vm_area_struct *vma)
vma->vm_private_data = gref;

vma->vm_flags |= VM_RESERVED;
vma->vm_flags |= VM_DONTCOPY;
vma->vm_flags |= VM_PFNMAP | VM_PFN_AT_MMAP;

vma->vm_ops = &gntalloc_vmops;

Expand Down
16 changes: 14 additions & 2 deletions drivers/xen/gntdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,17 +358,26 @@ static int unmap_grant_pages(struct grant_map *map, int offset, int pages)

/* ------------------------------------------------------------------ */

static void gntdev_vma_open(struct vm_area_struct *vma)
{
struct grant_map *map = vma->vm_private_data;

pr_debug("gntdev_vma_open %p\n", vma);
atomic_inc(&map->users);
}

static void gntdev_vma_close(struct vm_area_struct *vma)
{
struct grant_map *map = vma->vm_private_data;

pr_debug("close %p\n", vma);
pr_debug("gntdev_vma_close %p\n", vma);
map->vma = NULL;
vma->vm_private_data = NULL;
gntdev_put_map(map);
}

static struct vm_operations_struct gntdev_vmops = {
.open = gntdev_vma_open,
.close = gntdev_vma_close,
};

Expand Down Expand Up @@ -680,7 +689,10 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma)

vma->vm_ops = &gntdev_vmops;

vma->vm_flags |= VM_RESERVED|VM_DONTCOPY|VM_DONTEXPAND|VM_PFNMAP;
vma->vm_flags |= VM_RESERVED|VM_DONTEXPAND;

if (use_ptemod)
vma->vm_flags |= VM_DONTCOPY|VM_PFNMAP;

vma->vm_private_data = map;

Expand Down

0 comments on commit d79647a

Please sign in to comment.