Commit f27f75ca authored by Marek Marczykowski-Górecki's avatar Marek Marczykowski-Górecki Committed by Luis Henriques

xen/gntdevt: Fix race condition in gntdev_release()

commit 30b03d05 upstream.

While gntdev_release() is called the MMU notifier is still registered
and can traverse priv->maps list even if no pages are mapped (which is
the case -- gntdev_release() is called after all). But
gntdev_release() will clear that list, so make sure that only one of
those things happens at the same time.
Signed-off-by: default avatarMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: default avatarDavid Vrabel <david.vrabel@citrix.com>
Cc: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 00c115f1
...@@ -529,12 +529,14 @@ static int gntdev_release(struct inode *inode, struct file *flip) ...@@ -529,12 +529,14 @@ static int gntdev_release(struct inode *inode, struct file *flip)
pr_debug("priv %p\n", priv); pr_debug("priv %p\n", priv);
mutex_lock(&priv->lock);
while (!list_empty(&priv->maps)) { while (!list_empty(&priv->maps)) {
map = list_entry(priv->maps.next, struct grant_map, next); map = list_entry(priv->maps.next, struct grant_map, next);
list_del(&map->next); list_del(&map->next);
gntdev_put_map(NULL /* already removed */, map); gntdev_put_map(NULL /* already removed */, map);
} }
WARN_ON(!list_empty(&priv->freeable_maps)); WARN_ON(!list_empty(&priv->freeable_maps));
mutex_unlock(&priv->lock);
if (use_ptemod) if (use_ptemod)
mmu_notifier_unregister(&priv->mn, priv->mm); mmu_notifier_unregister(&priv->mn, priv->mm);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment