xen/gntdev: safely unmap grants in case they are still in use
Use gnttab_unmap_refs_async() to wait until the mapped pages are no longer in use before unmapping them. This allows userspace programs to safely use Direct I/O and AIO to a network filesystem which may retain refs to pages in queued skbs after the filesystem I/O has completed. Signed-off-by: Jennifer Herbert <jennifer.herbert@citrix.com> Reviewed-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com> Signed-off-by: David Vrabel <david.vrabel@citrix.com>
This commit is contained in:
parent
1401c00e59
commit
745282256c
|
@ -309,9 +309,30 @@ static int map_grant_pages(struct grant_map *map)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct unmap_grant_pages_callback_data
|
||||||
|
{
|
||||||
|
struct completion completion;
|
||||||
|
int result;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void unmap_grant_callback(int result,
|
||||||
|
struct gntab_unmap_queue_data *data)
|
||||||
|
{
|
||||||
|
struct unmap_grant_pages_callback_data* d = data->data;
|
||||||
|
|
||||||
|
d->result = result;
|
||||||
|
complete(&d->completion);
|
||||||
|
}
|
||||||
|
|
||||||
static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
|
static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
|
||||||
{
|
{
|
||||||
int i, err = 0;
|
int i, err = 0;
|
||||||
|
struct gntab_unmap_queue_data unmap_data;
|
||||||
|
struct unmap_grant_pages_callback_data data;
|
||||||
|
|
||||||
|
init_completion(&data.completion);
|
||||||
|
unmap_data.data = &data;
|
||||||
|
unmap_data.done= &unmap_grant_callback;
|
||||||
|
|
||||||
if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {
|
if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {
|
||||||
int pgno = (map->notify.addr >> PAGE_SHIFT);
|
int pgno = (map->notify.addr >> PAGE_SHIFT);
|
||||||
|
@ -323,11 +344,16 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
err = gnttab_unmap_refs(map->unmap_ops + offset,
|
unmap_data.unmap_ops = map->unmap_ops + offset;
|
||||||
use_ptemod ? map->kunmap_ops + offset : NULL, map->pages + offset,
|
unmap_data.kunmap_ops = use_ptemod ? map->kunmap_ops + offset : NULL;
|
||||||
pages);
|
unmap_data.pages = map->pages + offset;
|
||||||
if (err)
|
unmap_data.count = pages;
|
||||||
return err;
|
|
||||||
|
gnttab_unmap_refs_async(&unmap_data);
|
||||||
|
|
||||||
|
wait_for_completion(&data.completion);
|
||||||
|
if (data.result)
|
||||||
|
return data.result;
|
||||||
|
|
||||||
for (i = 0; i < pages; i++) {
|
for (i = 0; i < pages; i++) {
|
||||||
if (map->unmap_ops[offset+i].status)
|
if (map->unmap_ops[offset+i].status)
|
||||||
|
|
Loading…
Reference in New Issue