diff options
author | Daniel De Graaf <dgdegra@tycho.nsa.gov> | 2011-01-07 06:51:47 -0500 |
---|---|---|
committer | Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> | 2011-01-11 14:31:47 -0500 |
commit | f0a70c882ea546bbd802643990ceded32c39facc (patch) | |
tree | 3544db8b681c4bd513758579afc4847e2e87ecbf /drivers | |
parent | ba5d1012292403c8037adf4a54c4ec50dfe846c4 (diff) |
xen/gntdev: Fix circular locking dependency
apply_to_page_range will acquire PTE lock while priv->lock is held,
and mn_invl_range_start tries to acquire priv->lock with PTE already
held. Fix by not holding priv->lock during the entire map operation.
This is safe because map->vma is set nonzero while the lock is held,
which will cause subsequent maps to fail and will cause the unmap
ioctl (and other users of gntdev_del_map) to return -EBUSY until the
area is unmapped. It is similarly impossible for gntdev_vma_close to
be called while the vma is still being created.
Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/xen/gntdev.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index a2ea5335e152..aba76d437ea8 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c | |||
@@ -575,21 +575,26 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) | |||
575 | if (!(vma->vm_flags & VM_WRITE)) | 575 | if (!(vma->vm_flags & VM_WRITE)) |
576 | map->flags |= GNTMAP_readonly; | 576 | map->flags |= GNTMAP_readonly; |
577 | 577 | ||
578 | spin_unlock(&priv->lock); | ||
579 | |||
578 | err = apply_to_page_range(vma->vm_mm, vma->vm_start, | 580 | err = apply_to_page_range(vma->vm_mm, vma->vm_start, |
579 | vma->vm_end - vma->vm_start, | 581 | vma->vm_end - vma->vm_start, |
580 | find_grant_ptes, map); | 582 | find_grant_ptes, map); |
581 | if (err) { | 583 | if (err) { |
582 | printk(KERN_WARNING "find_grant_ptes() failure.\n"); | 584 | printk(KERN_WARNING "find_grant_ptes() failure.\n"); |
583 | goto unlock_out; | 585 | return err; |
584 | } | 586 | } |
585 | 587 | ||
586 | err = map_grant_pages(map); | 588 | err = map_grant_pages(map); |
587 | if (err) { | 589 | if (err) { |
588 | printk(KERN_WARNING "map_grant_pages() failure.\n"); | 590 | printk(KERN_WARNING "map_grant_pages() failure.\n"); |
589 | goto unlock_out; | 591 | return err; |
590 | } | 592 | } |
593 | |||
591 | map->is_mapped = 1; | 594 | map->is_mapped = 1; |
592 | 595 | ||
596 | return 0; | ||
597 | |||
593 | unlock_out: | 598 | unlock_out: |
594 | spin_unlock(&priv->lock); | 599 | spin_unlock(&priv->lock); |
595 | return err; | 600 | return err; |