Message ID | 20240529140739.1387692-1-edgar.iglesias@gmail.com (mailing list archive) |
---|---|
Headers | show |
Series | xen: Support grant mappings | expand |
+Anthony who wasn't Cc'ed. On 29/5/24 16:07, Edgar E. Iglesias wrote: > From: "Edgar E. Iglesias" <edgar.iglesias@amd.com> > > Hi, > > Grant mappings are a mechanism in Xen for guests to grant each other > permissions to map and share pages. These grants can be temporary > so both map and unmaps must be respected. See here for more info: > https://github.com/xen-project/xen/blob/master/docs/misc/grant-tables.txt > > Currently, the primary use-case for grants in QEMU, is with VirtIO backends. > Grant mappings will only work with models that use the address_space_map/unmap > interfaces, any other access will fail with appropriate error messages. > > In response to feedback we got on v3, later version switch approach > from adding new MemoryRegion types and map/unmap hooks to instead reusing > the existing xen_map_cache() hooks (with extensions). Almost all of the > changes are now contained to the Xen modules. > > This approach also refactors the mapcache to support multiple instances > (one for existing foreign mappings and another for grant mappings). > > I've only enabled grants for the ARM PVH machine since that is what > I can currently test on. Anthony, I don't have an easy way to test patches 7 and 8. I can merge patches 1-6 to reduce burden on Edgar (Stefano reviewed this series), but if you are busy I can send a PR for it. Regards, Phil.
From: "Edgar E. Iglesias" <edgar.iglesias@amd.com> Hi, Grant mappings are a mechanism in Xen for guests to grant each other permissions to map and share pages. These grants can be temporary so both map and unmaps must be respected. See here for more info: https://github.com/xen-project/xen/blob/master/docs/misc/grant-tables.txt Currently, the primary use-case for grants in QEMU, is with VirtIO backends. Grant mappings will only work with models that use the address_space_map/unmap interfaces, any other access will fail with appropriate error messages. In response to feedback we got on v3, later version switch approach from adding new MemoryRegion types and map/unmap hooks to instead reusing the existing xen_map_cache() hooks (with extensions). Almost all of the changes are now contained to the Xen modules. This approach also refactors the mapcache to support multiple instances (one for existing foreign mappings and another for grant mappings). I've only enabled grants for the ARM PVH machine since that is what I can currently test on. Cheers, Edgar ChangeLog: v7 -> v8: * Remove xen_mr_is_* stubs. v6 -> v7: * Use g_autofree in xen_remap_bucket(). * Flatten nested if-statements in xen_map_cache(). * Fix typo in error message in xen_map_cache(). v5 -> v6: * Correct passing of ram_addr_offset in xen_replace_cache_entry_unlocked. v4 -> v5: * Compute grant_ref from address_index to xen_remap_bucket(). * Rename grant_is_write to is_write. * Remove unnecessary + mc->bucket_size - 1 in xen_invalidate_map_cache_entry_unlocked(). * Remove use of global mapcache in refactor of xen_replace_cache_entry_unlocked(). * Add error checking for xengnttab_unmap(). * Add assert in xen_replace_cache_entry_unlocked() against grant mappings. * Fix memory leak when freeing first entry in mapcache buckets. * Assert that bucket_shift is >= XC_PAGE_SHIFT when creating mapcache. * Add missing use of xen_mr_is_memory() in hw/xen/xen-hvm-common.c. * Rebase with master. v3 -> v4: * Reuse existing xen_map_cache hooks. * Reuse existing map-cache for both foreign and grant mappings. * Only enable grants for the ARM PVH machine (removed i386). v2 -> v3: * Drop patch 1/7. This was done because device unplug is an x86-only case. * Add missing qemu_mutex_unlock() before return. v1 -> v2: * Split patch 2/7 to keep phymem.c changes in a separate. * In patch "xen: add map and unmap callbacks for grant" add check for total allowed grant < XEN_MAX_VIRTIO_GRANTS. * Fix formatting issues and re-based with master latest. Edgar E. Iglesias (8): xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable xen: mapcache: Unmap first entries in buckets xen: Add xen_mr_is_memory() softmmu: xen: Always pass offset + addr to xen_map_cache softmmu: Replace check for RAMBlock offset 0 with xen_mr_is_memory xen: mapcache: Pass the ram_addr offset to xen_map_cache() xen: mapcache: Add support for grant mappings hw/arm: xen: Enable use of grant mappings hw/arm/xen_arm.c | 5 + hw/xen/xen-hvm-common.c | 18 ++- hw/xen/xen-mapcache.c | 234 ++++++++++++++++++++++++-------- include/hw/xen/xen-hvm-common.h | 3 + include/sysemu/xen-mapcache.h | 2 + include/sysemu/xen.h | 2 + system/physmem.c | 12 +- 7 files changed, 211 insertions(+), 65 deletions(-) base-commit: 79d7475f39f1b0f05fcb159f5cdcbf162340dc7e