We used to set the default granule to 4kB but with VFIO assignment
it makes more sense to use the actual host page size.
Indeed when hotplugging a VFIO device protected by a virtio-iommu
on a 64kB/64kB host/guest config, we currently get a qemu crash:
"vfio: DMA mapping failed, unable to continue"
This is due to the hot-attached VFIO device calling
memory_region_iommu_set_page_size_mask() with 64kB granule
whereas the virtio-iommu granule was already frozen to 4kB on
machine init done.
Introduce a new granule property, set this latter to "host"
and introduce a new compat (that sets it to 4k for machine
types older than 9.0).
Note that the new default will prevent 4kB guest on 64kB host
because the granule will be set to 64kB which would be larger
than the guest page size. In that situation, the virtio-iommu
driver fails on viommu_domain_finalise() with
"granule 0x10000 larger than system page size 0x1000".
In that case 4K granule should be used.
To summarize, before the series, the support matrix (credit
to Jean-Philippe Brucker) was:
Host | Guest | virtio-net | IGB passthrough
4k | 4k | Y | Y
64k | 64k | Y | N
64k | 4k | Y | N
4k | 64k | Y | Y
After the series:
Host | Guest | virtio-net | IGB passthrough
4k | 4k | Y | Y
64k | 64k | Y | Y
64k | 4k | 4K | N
4k | 64k | Y | Y
The current limitation of global granule in the virtio-iommu
should be removed and turned into per domain granule. But
until we get this upgraded, this new default is probably
better because I don't think anyone is currently interested in
running a 4KB page size guest with virtio-iommu on a 64KB host.
However supporting 64kB guest on 64kB host with virtio-iommu and
VFIO looks a more important feature.
This series can be found at:
https://github.com/eauger/qemu/tree/granule-v3
Applied on top of
[PATCH v5 0/4] VIRTIO-IOMMU: Introduce an aw-bits option
https://lore.kernel.org/all/20240215084315.863897-1-eric.auger@redhat.com/
History:
v4 -> v5:
- use -(n * KiB) (Philippe)
- remove code that can be automatically generated
and add the new enum in qapi/virtio.json (Philippe).
- Improve commit msg on last patch and collected Philippe's R-b
v3 -> v4:
- Add 8K granule (Richard)
v2 -> v3
- introduce a dedicated granule option to handle the compat
Eric Auger (3):
qdev: Add a granule_mode property
virtio-iommu: Add a granule property
virtio-iommu: Change the default granule to the host page size
qapi/virtio.json | 18 ++++++++++++++++++
include/hw/qdev-properties-system.h | 3 +++
include/hw/virtio/virtio-iommu.h | 2 ++
hw/core/machine.c | 1 +
hw/core/qdev-properties-system.c | 15 +++++++++++++++
hw/virtio/virtio-iommu.c | 28 +++++++++++++++++++++++++---
qemu-options.hx | 3 +++
7 files changed, 67 insertions(+), 3 deletions(-)
--
2.41.0