@@ -24,6 +24,7 @@
#include "hw/virtio/virtio.h"
#include "hw/pci/pci.h"
#include "qom/object.h"
+#include "qapi/qapi-types-virtio.h"
#define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci"
@@ -67,6 +68,7 @@ struct VirtIOIOMMU {
Notifier machine_done;
bool granule_frozen;
uint8_t aw_bits;
+ GranuleMode granule_mode;
};
#endif
@@ -29,6 +29,7 @@
#include "sysemu/reset.h"
#include "sysemu/sysemu.h"
#include "qemu/reserved-region.h"
+#include "qemu/units.h"
#include "qapi/error.h"
#include "qemu/error-report.h"
#include "trace.h"
@@ -1115,8 +1116,8 @@ static int virtio_iommu_notify_flag_changed(IOMMUMemoryRegion *iommu_mr,
}
/*
- * The default mask (TARGET_PAGE_MASK) is the smallest supported guest granule,
- * for example 0xfffffffffffff000. When an assigned device has page size
+ * The default mask depends on the "granule" property. For example, with
+ * 4K granule, it is -(4 * KiB). When an assigned device has page size
* restrictions due to the hardware IOMMU configuration, apply this restriction
* to the mask.
*/
@@ -1313,7 +1314,26 @@ static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
* in vfio realize
*/
s->config.bypass = s->boot_bypass;
- s->config.page_size_mask = qemu_target_page_mask();
+
+ switch (s->granule_mode) {
+ case GRANULE_MODE_4K:
+ s->config.page_size_mask = -(4 * KiB);
+ break;
+ case GRANULE_MODE_8K:
+ s->config.page_size_mask = -(8 * KiB);
+ break;
+ case GRANULE_MODE_16K:
+ s->config.page_size_mask = -(16 * KiB);
+ break;
+ case GRANULE_MODE_64K:
+ s->config.page_size_mask = -(64 * KiB);
+ break;
+ case GRANULE_MODE_HOST:
+ s->config.page_size_mask = qemu_real_host_page_mask();
+ break;
+ default:
+ error_setg(errp, "Unsupported granule mode");
+ }
if (s->aw_bits < 32 || s->aw_bits > 64) {
error_setg(errp, "aw-bits must be within [32,64]");
}
@@ -1527,6 +1547,8 @@ static Property virtio_iommu_properties[] = {
TYPE_PCI_BUS, PCIBus *),
DEFINE_PROP_BOOL("boot-bypass", VirtIOIOMMU, boot_bypass, true),
DEFINE_PROP_UINT8("aw-bits", VirtIOIOMMU, aw_bits, 0),
+ DEFINE_PROP_GRANULE_MODE("granule", VirtIOIOMMU, granule_mode,
+ GRANULE_MODE_4K),
DEFINE_PROP_END_OF_LIST(),
};
@@ -1179,6 +1179,9 @@ SRST
``aw-bits=val`` (val between 32 and 64, default depends on machine)
This decides the address width of IOVA address space. It defaults
to 39 bits on q35 machines and 48 bits on ARM virt machines.
+ ``granule=val`` (possible values are 4K, 8K, 16K, 64K and host)
+ This decides the default granule to be be exposed by the
+ virtio-iommu. If host, the granule matches the host page size.
ERST