Skip to content

Commit dbe5283

Browse files
jbeulichjgross1
authored andcommitted
Xen/gntdev: correct dev_bus_addr handling in gntdev_map_grant_pages()
We may not skip setting the field in the unmap structure when GNTMAP_device_map is in use - such an unmap would fail to release the respective resources (a page ref in the hypervisor). Otoh the field doesn't need setting at all when GNTMAP_device_map is not in use. To record the value for unmapping, we also better don't use our local p2m: In particular after a subsequent change it may not have got updated for all the batch elements. Instead it can simply be taken from the respective map's results. We can additionally avoid playing this game altogether for the kernel part of the mappings in (x86) PV mode. This is part of XSA-361. Signed-off-by: Jan Beulich <jbeulich@suse.com> Cc: stable@vger.kernel.org Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent b512e1b commit dbe5283

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

‎drivers/xen/gntdev.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -309,18 +309,25 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
309309
* to the kernel linear addresses of the struct pages.
310310
* These ptes are completely different from the user ptes dealt
311311
* with find_grant_ptes.
312+
* Note that GNTMAP_device_map isn't needed here: The
313+
* dev_bus_addr output field gets consumed only from ->map_ops,
314+
* and by not requesting it when mapping we also avoid needing
315+
* to mirror dev_bus_addr into ->unmap_ops (and holding an extra
316+
* reference to the page in the hypervisor).
312317
*/
318+
unsigned int flags = (map->flags & ~GNTMAP_device_map) |
319+
GNTMAP_host_map;
320+
313321
for (i = 0; i < map->count; i++) {
314322
unsigned long address = (unsigned long)
315323
pfn_to_kaddr(page_to_pfn(map->pages[i]));
316324
BUG_ON(PageHighMem(map->pages[i]));
317325

318-
gnttab_set_map_op(&map->kmap_ops[i], address,
319-
map->flags | GNTMAP_host_map,
326+
gnttab_set_map_op(&map->kmap_ops[i], address, flags,
320327
map->grants[i].ref,
321328
map->grants[i].domid);
322329
gnttab_set_unmap_op(&map->kunmap_ops[i], address,
323-
map->flags | GNTMAP_host_map, -1);
330+
flags, -1);
324331
}
325332
}
326333

@@ -336,17 +343,12 @@ int gntdev_map_grant_pages(struct gntdev_grant_map *map)
336343
continue;
337344
}
338345

346+
if (map->flags & GNTMAP_device_map)
347+
map->unmap_ops[i].dev_bus_addr = map->map_ops[i].dev_bus_addr;
348+
339349
map->unmap_ops[i].handle = map->map_ops[i].handle;
340350
if (use_ptemod)
341351
map->kunmap_ops[i].handle = map->kmap_ops[i].handle;
342-
#ifdef CONFIG_XEN_GRANT_DMA_ALLOC
343-
else if (map->dma_vaddr) {
344-
unsigned long bfn;
345-
346-
bfn = pfn_to_bfn(page_to_pfn(map->pages[i]));
347-
map->unmap_ops[i].dev_bus_addr = __pfn_to_phys(bfn);
348-
}
349-
#endif
350352
}
351353
return err;
352354
}

0 commit comments

Comments
 (0)