Commit d79647aea22732f39c81bbdc80931f96b46023f0

Authored by Daniel De Graaf
Committed by Konrad Rzeszutek Wilk
1 parent 38eaeb0fd8

xen/gntdev,gntalloc: Remove unneeded VM flags

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 <ian.campbell@citrix.com>
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
[v2: Added in git commit "We are.." from email correspondence]

Showing 2 changed files with 26 additions and 4 deletions Side-by-side Diff

drivers/xen/gntalloc.c
... ... @@ -427,6 +427,17 @@
427 427 return 0;
428 428 }
429 429  
  430 +static void gntalloc_vma_open(struct vm_area_struct *vma)
  431 +{
  432 + struct gntalloc_gref *gref = vma->vm_private_data;
  433 + if (!gref)
  434 + return;
  435 +
  436 + spin_lock(&gref_lock);
  437 + gref->users++;
  438 + spin_unlock(&gref_lock);
  439 +}
  440 +
430 441 static void gntalloc_vma_close(struct vm_area_struct *vma)
431 442 {
432 443 struct gntalloc_gref *gref = vma->vm_private_data;
... ... @@ -441,6 +452,7 @@
441 452 }
442 453  
443 454 static struct vm_operations_struct gntalloc_vmops = {
  455 + .open = gntalloc_vma_open,
444 456 .close = gntalloc_vma_close,
445 457 };
446 458  
... ... @@ -471,8 +483,6 @@
471 483 vma->vm_private_data = gref;
472 484  
473 485 vma->vm_flags |= VM_RESERVED;
474   - vma->vm_flags |= VM_DONTCOPY;
475   - vma->vm_flags |= VM_PFNMAP | VM_PFN_AT_MMAP;
476 486  
477 487 vma->vm_ops = &gntalloc_vmops;
478 488  
drivers/xen/gntdev.c
... ... @@ -358,17 +358,26 @@
358 358  
359 359 /* ------------------------------------------------------------------ */
360 360  
  361 +static void gntdev_vma_open(struct vm_area_struct *vma)
  362 +{
  363 + struct grant_map *map = vma->vm_private_data;
  364 +
  365 + pr_debug("gntdev_vma_open %p\n", vma);
  366 + atomic_inc(&map->users);
  367 +}
  368 +
361 369 static void gntdev_vma_close(struct vm_area_struct *vma)
362 370 {
363 371 struct grant_map *map = vma->vm_private_data;
364 372  
365   - pr_debug("close %p\n", vma);
  373 + pr_debug("gntdev_vma_close %p\n", vma);
366 374 map->vma = NULL;
367 375 vma->vm_private_data = NULL;
368 376 gntdev_put_map(map);
369 377 }
370 378  
371 379 static struct vm_operations_struct gntdev_vmops = {
  380 + .open = gntdev_vma_open,
372 381 .close = gntdev_vma_close,
373 382 };
374 383  
... ... @@ -680,7 +689,10 @@
680 689  
681 690 vma->vm_ops = &gntdev_vmops;
682 691  
683   - vma->vm_flags |= VM_RESERVED|VM_DONTCOPY|VM_DONTEXPAND|VM_PFNMAP;
  692 + vma->vm_flags |= VM_RESERVED|VM_DONTEXPAND;
  693 +
  694 + if (use_ptemod)
  695 + vma->vm_flags |= VM_DONTCOPY|VM_PFNMAP;
684 696  
685 697 vma->vm_private_data = map;
686 698