mbox series

[v4,00/17] xen: Support grant mappings

Message ID 20240430164939.925307-1-edgar.iglesias@gmail.com (mailing list archive)
Headers show
Series xen: Support grant mappings | expand

Message

Edgar E. Iglesias April 30, 2024, 4:49 p.m. UTC
From: "Edgar E. Iglesias" <edgar.iglesias@amd.com>

Hi,

This is a follow-up on Vikrams v3:
http://next.patchew.org/QEMU/20240227223501.28475-1-vikram.garhwal@amd.com/

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 this is with QEMU's 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, this version switches 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).

Patch 1 - 10 are refactorings with minimal functional changes.
Patch 3 - 10 could possibly get squashed into one but I've left them
separate to make them easier to review.

I've only enabled grants for the ARM PVH machine since that is what
I can currently test on.

Cheers,
Edgar

ChangeLog:

v3 -> v4:
* Major changes.
* 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 (15):
  xen: mapcache: Refactor lock functions for multi-instance
  xen: mapcache: Refactor xen_map_cache for multi-instance
  xen: mapcache: Refactor xen_remap_bucket for multi-instance
  xen: mapcache: Break out xen_ram_addr_from_mapcache_single
  xen: mapcache: Refactor xen_replace_cache_entry_unlocked
  xen: mapcache: Refactor xen_invalidate_map_cache_entry_unlocked
  xen: mapcache: Break out xen_invalidate_map_cache_single()
  xen: mapcache: Break out xen_map_cache_init_single()
  xen: mapcache: Make MCACHE_BUCKET_SHIFT runtime configurable
  xen: mapcache: Unmap first entries in buckets
  softmmu: Pass RAM MemoryRegion and is_write xen_map_cache()
  xen: Add xen_mr_is_memory()
  xen: mapcache: Remove assumption of RAMBlock with 0 offset
  xen: mapcache: Add support for grant mappings
  hw/arm: xen: Enable use of grant mappings

Juergen Gross (2):
  softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length()
  xen: let xen_ram_addr_from_mapcache() return -1 in case of not found
    entry

 hw/arm/xen_arm.c                |   5 +
 hw/xen/xen-hvm-common.c         |  16 +-
 hw/xen/xen-mapcache.c           | 408 +++++++++++++++++++++-----------
 include/hw/xen/xen-hvm-common.h |   3 +
 include/sysemu/xen-mapcache.h   |  13 +-
 include/sysemu/xen.h            |  15 ++
 system/physmem.c                |  83 ++++---
 7 files changed, 365 insertions(+), 178 deletions(-)

Comments

Philippe Mathieu-Daudé May 6, 2024, 10:36 a.m. UTC | #1
Hi,

On 30/4/24 18:49, Edgar E. Iglesias wrote:

 > Juergen Gross (2):
 >    softmmu: let qemu_map_ram_ptr() use qemu_ram_ptr_length()
 >    xen: let xen_ram_addr_from_mapcache() return -1 if not found entry

> Edgar E. Iglesias (15):
>    xen: mapcache: Refactor lock functions for multi-instance
>    xen: mapcache: Refactor xen_map_cache for multi-instance
>    xen: mapcache: Refactor xen_remap_bucket for multi-instance
>    xen: mapcache: Break out xen_ram_addr_from_mapcache_single
>    xen: mapcache: Refactor xen_replace_cache_entry_unlocked
>    xen: mapcache: Refactor xen_invalidate_map_cache_entry_unlocked
>    xen: mapcache: Break out xen_invalidate_map_cache_single()
>    xen: mapcache: Break out xen_map_cache_init_single()

>    softmmu: Pass RAM MemoryRegion and is_write xen_map_cache()

I'm queuing 1-10 & 13 to alleviate the respin, thanks.