VIRTIO-IOMMU device
v5 cover VIRTIO-IOMMU device
This series implements the virtio-iommu device.
This v5 is an upgrade to v0.5 spec [1].
Compared to v4:
- event queue and fault reporting
- we now return the IOAPIC MSI region if the virtio-iommu is instantiated in a PC machine.
- we bypass transactions on MSI HW region and fault on reserved ones.
- We support ACPI boot with mach-virt (based on IORT proposal)
- We moved to the new driver naming conventions
- simplified mach-virt instantiation
- worked around the disappearing of pci_find_primary_bus
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v2.11.0-virtio-iommu-v5
References:
[1] [RFC] virtio-iommu version 0.5git://linux-arm.org/virtio-iommu.git viommu/v0.5
[2] guest branch featuring the virtio-iommu driver v0.5git://linux-arm.org/linux-jpb.git virtio-iommu/v0.5.1
Testing:
- tested with guest using virtio-pci-net and virtio-blk-pci (,vhost=off,iommu_platform,disable-modern=off,disable-legacy=on)
- virtio-blk-pci uses irqfd: with GICv3, use
"target/arm/kvm: Translate the MSI doorbell in kvm_arch_fixup_msi_route" available on my branch
- VFIO support will be brought by a separate series
- on x86 is hacked guest kernel (available on demand)
History:
v4 -> v5:
- new functionalities reported above + below fixes:
- in virtio_iommu_translate, check the dev->as is not NULL
- initialize as->device_list in virtio_iommu_get_as
- initialize bufstate.error to false in virtio_iommu_probe
v3-> v4:
- see above
v2 -> v3:
- rebase on top of 2.10-rc0 and especially
[PATCH qemu v9 0/2] memory/iommu: QOM'fy IOMMU MemoryRegion
- add mutex init
- fix as->mappings deletion using g_tree_ref/unref
- when a dev is attached whereas it is already attached to another address space, first detach it
- fix some error values
- page_sizes = TARGET_PAGE_MASK;
- I haven't changed the unmap() semantics yet, waiting for the next virtio-iommu spec revision.
v1 -> v2:
- fix redifinition of viommu_as typedef
Eric Auger (22):
machine: Add a get_primary_pci_bus callback
hw/arm/virt: Implement get_primary_pci_bus
pc: Implement get_primary_pci_bus
update-linux-headers: Import virtio_iommu.h
linux-headers: Partial update for virtio-iommu
virtio-iommu: Add skeleton
virtio-iommu: Decode the command payload
virtio-iommu: Add the iommu regions
virtio-iommu: Register attached endpoints
virtio-iommu: Implement attach/detach command
virtio-iommu: Implement map/unmap
virtio-iommu: Implement translate
virtio-iommu: Implement probe request
virtio-iommu: Add an msi_bypass property
virtio-iommu: Implement fault reporting
virtio_iommu: Handle reserved regions in translation process hw/arm/virt: Add virtio-iommu to the virt board hw/arm/virt-acpi-build: Add virtio-iommu node in IORT table memory.h: Add set_page_size_mask IOMMUMemoryRegion callback hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes
virtio-iommu: Implement set_page_size_mask
hw/vfio/common: Do not print error when viommu translates into an mmio
region
hw/arm/virt-acpi-build.c | 55 +- hw/arm/virt.c | 99 ++- hw/i386/pc.c | 8 + hw/vfio/common.c | 7 +- hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 25 + hw/virtio/virtio-iommu.c | 1063 +++++++++++++++++++++++++ include/exec/memory.h | 4 + include/hw/acpi/acpi-defs.h | 21 +- include/hw/arm/virt.h | 19 + include/hw/boards.h | 3 + include/hw/vfio/vfio-common.h | 1 + include/hw/virtio/virtio-iommu.h | 63 ++ include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_iommu.h | 195 +++++ linux-headers/linux/virtio_iommu.h | 1 + scripts/update-linux-headers.sh | 3 + 17 files changed, 1552 insertions(+), 17 deletions(-) create mode 100644 hw/virtio/virtio-iommu.c create mode 100644 include/hw/virtio/virtio-iommu.h create mode 100644 include/standard-headers/linux/virtio_iommu.h create mode 100644 linux-headers/linux/virtio_iommu.h
Signature · 1 line
1.9.1
RFC v5 1/22 machine: Add a get_primary_pci_bus callback
After e492dc5a267e "pci: Eliminate pci_find_primary_bus()" we don't have an easy mean to retrieve the primary bus of a machine. This will be needed by virtio-iommu-device which is bound to be dynamically instantiated in at least ARM virt and Q35 machines.
Adding a get_primary_pci_bus() callback allows to retrieve the PCIBus the iommu is connected to.
---
This is a temporary solution until we decide whether the virtio-iommu-device should be instantiable through a -device command line or through a machine command line, as already suggested by Peter (for vsmmuv3 though).
--- include/hw/boards.h | 3 +++ 1 file changed, 3 insertions(+)
include/hw/boards.h +3 -0
@@ -151,6 +151,8 @@ typedef struct {* should instead use "unimplemented-device" for all memory ranges where * the guest will attempt to probe for a device that QEMU doesn't * implement and a stub device is required. +* @get_primary_pci_bus: return the primary PCI bus or NULL if there are +* several root buses */ struct MachineClass {/*< private >*/
@@ -207,6 +209,7 @@ struct MachineClass { unsigned cpu_index);const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);int64_t (*get_default_cpu_node_id)(const MachineState *ms,int idx); +PCIBus *(*get_primary_pci_bus)(const MachineState *ms); };/**
Signature · 1 line
1.9.1
RFC v5 2/22 hw/arm/virt: Implement get_primary_pci_bus
In reply to Eric Augerget_primary_pci_bus() returns the root bus. We also add the PCIBus handle to VirtMachineState.
--- hw/arm/virt.c | 11 ++++++++++- include/hw/arm/virt.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-)
hw/arm/virt.c +10 -1
@@ -999,7 +999,7 @@ static void create_pcie_irq_map(const VirtMachineState *vms, 0x7 /* PCI irq */); } -static void create_pcie (const VirtMachineState *vms,qemu_irq *pic) +static void create_pcie (VirtMachineState *vms,qemu_irq *pic) {hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO ].base;hwaddr size_mmio = vms->memmap[VIRT_PCIE_MMIO ].size;
@@ -1062,6 +1062,7 @@ static void create_pcie(const VirtMachineState *vms, qemu_irq *pic) pci =PCI_HOST_BRIDGE (dev);if (pci->bus) { + vms->pci_bus = pci->bus;for (i =0 ; i < nb_nics; i++) {NICInfo *nd = &nd_table[i];
@@ -1581,6 +1582,13 @@ static const CPUArchIdList *virt_possible_cpu_arch_ids(MachineState *ms)return ms->possible_cpus; } +static PCIBus *virt_get_primary_pci_bus (const MachineState *ms) +{ +VirtMachineState *vms =VIRT_MACHINE (ms); + +return vms->pci_bus; +} +static void virt_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -1601,6 +1609,7 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->cpu_index_to_instance_props = virt_cpu_index_to_props; mc->default_cpu_type =ARM_CPU_TYPE_NAME ("cortex-a15" ); mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; + mc->get_primary_pci_bus = virt_get_primary_pci_bus; }static const TypeInfo virt_machine_info = {
include/hw/arm/virt.h +1 -0
@@ -106,6 +106,7 @@ typedef struct {uint32_t gic_phandle;uint32_t msi_phandle;int psci_conduit; +PCIBus *pci_bus; } VirtMachineState;#define TYPE_VIRT_MACHINE MACHINE_TYPE_NAME("virt")
Signature · 1 line
1.9.1
RFC v5 3/22 pc: Implement get_primary_pci_bus
In reply to Eric AugerImplement this get_primary_pci_bus() which returns the root bus.
--- hw/i386/pc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/i386/pc.c +8 -0
@@ -2337,6 +2337,13 @@ static void x86_nmi(NMIState *n, int cpu_index, Error **errp) } } +static PCIBus *pc_machine_get_primary_pci_bus (const MachineState *ms) +{ +PCMachineState *pcms =PC_MACHINE (ms); + +return pcms->bus; +} +static void pc_machine_class_init (ObjectClass *oc,void *data) {MachineClass *mc =MACHINE_CLASS (oc);
@@ -2376,6 +2383,7 @@ static void pc_machine_class_init(ObjectClass *oc, void *data) hc->unplug = pc_machine_device_unplug_cb; nc->nmi_monitor_handler = x86_nmi; mc->default_cpu_type =TARGET_DEFAULT_CPU_TYPE ; + mc->get_primary_pci_bus = pc_machine_get_primary_pci_bus; object_class_property_add(oc, PC_MACHINE_MEMHP_REGION_SIZE, "int", pc_machine_get_hotplug_memory_region_size, NULL,
Signature · 1 line
1.9.1
RFC v5 4/22 update-linux-headers: Import virtio_iommu.h
In reply to Eric AugerUpdate the script to update the virtio_iommu.h header.
--- scripts/update-linux-headers.sh | 3 +++ 1 file changed, 3 insertions(+)
scripts/update-linux-headers.sh +3 -0
@@ -135,6 +135,9 @@ EOF cat <<EOF >$output/linux-headers/linux/virtio_config.h #include "standard-headers/linux/virtio_config.h" EOF +cat <<EOF >$output/linux-headers/linux/virtio_iommu.h +#include "standard-headers/linux/virtio_iommu.h" +EOF cat <<EOF >$output/linux-headers/linux/virtio_ring.h #include "standard-headers/linux/virtio_ring.h" EOF
Signature · 1 line
1.9.1
RFC v5 5/22 linux-headers: Partial update for virtio-iommu
In reply to Eric AugerPartial sync against Jean-Philippe's branch:git://linux-arm.org/linux-jpb.git virtio-iommu/v0.5-dev
--- include/standard-headers/linux/virtio_ids.h | 1 + include/standard-headers/linux/virtio_iommu.h | 195 ++++++++++++++++++++++++++ linux-headers/linux/virtio_iommu.h | 1 + 3 files changed, 197 insertions(+) create mode 100644 include/standard-headers/linux/virtio_iommu.h create mode 100644 linux-headers/linux/virtio_iommu.h
include/standard-headers/linux/virtio_ids.h +1 -0
@@ -43,5 +43,6 @@#define VIRTIO_ID_INPUT 18/* virtio input */ #define VIRTIO_ID_VSOCK 19/* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20/* virtio crypto */ +#define VIRTIO_ID_IOMMU 61216/* virtio IOMMU (temporary) */ #endif /* _LINUX_VIRTIO_IDS_H */
include/standard-headers/linux/virtio_iommu.h new file +195 -0
195 lines not on this page · raw message
linux-headers/linux/virtio_iommu.h new file +1 -0
@@ -0,0 +1 @@ +#include "standard-headers/linux/virtio_iommu.h"
Signature · 1 line
1.9.1
RFC v5 6/22 virtio-iommu: Add skeleton
In reply to Eric AugerThis patchs adds the skeleton for the virtio-iommu device.
---
v4 -> v5:
- use the new v0.5 terminology (domain, endpoint)
- add the event virtqueue
v3 -> v4:
- use page_size_mask instead of page_sizes
- added set_features()
- added some traces (reset, set_status, set_features)
- empty virtio_iommu_set_config() as the driver MUST NOT write to device configuration fields
- add get_config trace
v2 -> v3:
- rebase on 2.10-rc0, ie. use IOMMUMemoryRegion and remove iommu_ops.
- advertise VIRTIO_IOMMU_F_MAP_UNMAP feature
- page_sizes set to TARGET_PAGE_SIZE
--- hw/virtio/Makefile.objs | 1 + hw/virtio/trace-events | 7 ++ hw/virtio/virtio-iommu.c | 256 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-iommu.h | 60 +++++++++ 4 files changed, 324 insertions(+) create mode 100644 hw/virtio/virtio-iommu.c create mode 100644 include/hw/virtio/virtio-iommu.h
hw/virtio/Makefile.objs +1 -0
@@ -6,6 +6,7 @@ common-obj-y += virtio-mmio.o obj-y += virtio.o virtio-balloon.o obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o +obj-$(CONFIG_LINUX) += virtio-iommu.o obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o obj-y += virtio-crypto.o obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o
hw/virtio/trace-events +7 -0
@@ -25,3 +25,10 @@ virtio_balloon_handle_output(const char *name, uint64_t gpa) "section name: %s g virtio_balloon_get_config(uint32_t num_pages, uint32_t actual) "num_pages: %d actual: %d" virtio_balloon_set_config(uint32_t actual, uint32_t oldactual) "actual: %d oldactual: %d" virtio_balloon_to_target(uint64_t target, uint32_t num_pages) "balloon target: 0x%"PRIx64" num_pages: %d" + +# hw/virtio/virtio-iommu.c +# +virtio_iommu_set_features(uint64_t features) "features accepted by the driver =0x%"PRIx64 +virtio_iommu_device_reset(void) "reset!" +virtio_iommu_device_status(uint8_t status) "driver status = %d" +virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint8_t ioasid_bits, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" ioasid_bits=%d probe_size=0x%x"
hw/virtio/virtio-iommu.c new file +256 -0
256 lines not on this page · raw message
include/hw/virtio/virtio-iommu.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 7/22 virtio-iommu: Decode the command payload
In reply to Eric AugerThis patch adds the command payload decoding and introduces the functions that will do the actual command handling. Those functions are not yet implemented.
---
v4 -> v5:
- adopt new v0.5 terminology
v3 -> v4:
- no flags field anymore in struct virtio_iommu_req_unmap
- test reserved on attach/detach, change trace proto
- rebase on v2.10.0.
--- hw/virtio/trace-events | 6 ++- hw/virtio/virtio-iommu.c | 104 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 5 deletions(-)
hw/virtio/trace-events +5 -1
@@ -31,4 +31,8 @@ virtio_balloon_to_target(uint64_t target, uint32_t num_pages) "balloon target: 0 virtio_iommu_set_features(uint64_t features) "features accepted by the driver =0x%"PRIx64 virtio_iommu_device_reset(void) "reset!" virtio_iommu_device_status(uint8_t status) "driver status = %d" -virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint8_t ioasid_bits, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" ioasid_bits=%d probe_size=0x%x" +virtio_iommu_get_config(uint64_t page_size_mask, uint64_t start, uint64_t end, uint8_t domain_bits, uint32_t probe_size) "page_size_mask=0x%"PRIx64" start=0x%"PRIx64" end=0x%"PRIx64" domain_bits=%d probe_size=0x%x" +virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" +virtio_iommu_detach(uint32_t ep_id) "endpoint=%d" +virtio_iommu_map(uint32_t domain_id, uint64_t phys_addr, uint64_t virt_addr, uint64_t size, uint32_t flags) "domain=%d phys_addr=0x%"PRIx64" virt_addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d" +virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_addr, uint64_t size) "domain=%d virt_addr=0x%"PRIx64" size=0x%"PRIx64
hw/virtio/virtio-iommu.c +100 -4
129 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 8/22 virtio-iommu: Add the iommu regions
In reply to Eric AugerThis patch initializes the iommu memory regions so that PCIe end point transactions get translated. The translation function is not yet implemented though.
---
v4 -> v5:
- use PCI bus handle as a key
- use get_primary_pci_bus() callback
v3 -> v4:
- add trace_virtio_iommu_init_iommu_mr
v2 -> v3:
- use IOMMUMemoryRegion
- iommu mr name built with BDF
- rename smmu_get_sid into virtio_iommu_get_sid and use PCI_BUILD_BDF
--- hw/virtio/trace-events | 2 + hw/virtio/virtio-iommu.c | 102 +++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-iommu.h | 2 + 3 files changed, 106 insertions(+)
hw/virtio/trace-events +2 -0
@@ -36,3 +36,5 @@ virtio_iommu_attach(uint32_t domain_id, uint32_t ep_id) "domain=%d endpoint=%d" virtio_iommu_detach(uint32_t ep_id) "endpoint=%d" virtio_iommu_map(uint32_t domain_id, uint64_t phys_addr, uint64_t virt_addr, uint64_t size, uint32_t flags) "domain=%d phys_addr=0x%"PRIx64" virt_addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d" virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_addr, uint64_t size) "domain=%d virt_addr=0x%"PRIx64" size=0x%"PRIx64 +virtio_iommu_translate(const char *name, uint32_t rid, uint64_t iova, int flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d" +virtio_iommu_init_iommu_mr(char *iommu_mr) "init %s"
hw/virtio/virtio-iommu.c +102 -0
147 lines not on this page · raw message
include/hw/virtio/virtio-iommu.h +2 -0
@@ -28,6 +28,8 @@#define VIRTIO_IOMMU (obj) \ OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU) +#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region" +#define IOMMU_PCI_BUS_MAX 256#define IOMMU_PCI_DEVFN_MAX 256
Signature · 1 line
1.9.1
RFC v5 9/22 virtio-iommu: Register attached endpoints
In reply to Eric AugerThis patch introduce domain and endpoint internal datatypes. Both are stored in RB trees. The domain owns a list of endpoints attached to it.
It is assumed the endpoint ID corresponds to the PCI BDF.
---
v4 -> v5:
- initialize as->endpoint_list
v3 -> v4:
- new separate patch
--- hw/virtio/trace-events | 4 ++ hw/virtio/virtio-iommu.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)
hw/virtio/trace-events +4 -0
@@ -38,3 +38,7 @@ virtio_iommu_map(uint32_t domain_id, uint64_t phys_addr, uint64_t virt_addr, uin virtio_iommu_unmap(uint32_t domain_id, uint64_t virt_addr, uint64_t size) "domain=%d virt_addr=0x%"PRIx64" size=0x%"PRIx64 virtio_iommu_translate(const char *name, uint32_t rid, uint64_t iova, int flag) "mr=%s rid=%d addr=0x%"PRIx64" flag=%d" virtio_iommu_init_iommu_mr(char *iommu_mr) "init %s" +virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d" +virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d" +virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d" +virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d"
hw/virtio/virtio-iommu.c +123 -0
166 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 10/22 virtio-iommu: Implement attach/detach command
In reply to Eric AugerThis patch implements the endpoint attach/detach to/from a domain.
--- hw/virtio/virtio-iommu.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-)
hw/virtio/virtio-iommu.c +33 -6
@@ -113,8 +113,8 @@ static void virtio_iommu_put_endpoint(gpointer data)g_free (ep); } -viommu_domain *virtio_iommu_get_domain (VirtIOIOMMU *s,uint32_t domain_id); -viommu_domain *virtio_iommu_get_domain (VirtIOIOMMU *s,uint32_t domain_id) +static viommu_domain *virtio_iommu_get_domain (VirtIOIOMMU *s, +uint32_t domain_id) {viommu_domain *domain;
@@ -193,6 +193,8 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,uint32_t domain_id =le32_to_cpu (req->domain);uint32_t ep_id =le32_to_cpu (req->endpoint);uint32_t reserved =le32_to_cpu (req->reserved); +viommu_domain *domain; +viommu_endpoint *ep;trace_virtio_iommu_attach (domain_id, ep_id);
@@ -200,7 +202,22 @@ static int virtio_iommu_attach(VirtIOIOMMU *s,return VIRTIO_IOMMU_S_INVAL ; } -return VIRTIO_IOMMU_S_UNSUPP ; + ep =virtio_iommu_get_endpoint (s, ep_id); +if (ep->domain) { +/* +* the device is already attached to a domain, +* detach it first +*/ +virtio_iommu_detach_endpoint_from_domain (ep); + } + + domain =virtio_iommu_get_domain (s, domain_id); +QLIST_INSERT_HEAD (&domain->endpoint_list, ep, next); + + ep->domain = domain; +g_tree_ref (domain->mappings); + +return VIRTIO_IOMMU_S_OK ; } static int virtio_iommu_detach(VirtIOIOMMU *s,
@@ -208,14 +225,24 @@ static int virtio_iommu_detach(VirtIOIOMMU *s, {uint32_t ep_id =le32_to_cpu (req->endpoint);uint32_t reserved =le32_to_cpu (req->reserved); - -trace_virtio_iommu_detach (ep_id); +viommu_endpoint *ep;if (reserved) {return VIRTIO_IOMMU_S_INVAL ; } -return VIRTIO_IOMMU_S_UNSUPP ; + ep =g_tree_lookup (s->endpoints,GUINT_TO_POINTER (ep_id)); +if (!ep) { +return VIRTIO_IOMMU_S_NOENT ; + } + +if (!ep->domain) { +return VIRTIO_IOMMU_S_INVAL ; + } + +virtio_iommu_detach_endpoint_from_domain (ep); +trace_virtio_iommu_detach (ep_id); +return VIRTIO_IOMMU_S_OK ; } static int virtio_iommu_map(VirtIOIOMMU *s,
Signature · 1 line
1.9.1
RFC v5 11/22 virtio-iommu: Implement map/unmap
In reply to Eric AugerThis patch implements virtio_iommu_map/unmap.
---
v3 -> v4:
- implement unmap semantics as specified in v0.4
--- hw/virtio/trace-events | 3 ++ hw/virtio/virtio-iommu.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 2 deletions(-)
hw/virtio/trace-events +3 -0
@@ -42,3 +42,6 @@ virtio_iommu_get_endpoint(uint32_t ep_id) "Alloc endpoint=%d" virtio_iommu_put_endpoint(uint32_t ep_id) "Free endpoint=%d" virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d" virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" +virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap left [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" +virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" +virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRIx64",0x%"PRIx64"]"
hw/virtio/virtio-iommu.c +89 -2
115 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 12/22 virtio-iommu: Implement translate
In reply to Eric AugerThis patch implements the translate callback
---
v4 -> v5:
- check the device domain is not NULL
- s/printf/error_report
- set flags to IOMMU_NONE in case of all translation faults
--- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-)
hw/virtio/trace-events +1 -0
@@ -45,3 +45,4 @@ virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap left [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRIx64",0x%"PRIx64"]" +virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d"
hw/virtio/virtio-iommu.c +41 -1
60 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 13/22 virtio-iommu: Implement probe request
In reply to Eric AugerThis patch implements the PROBE request. At the moment, no reserved regions are returned as none are registered per device. Only a NONE property is returned.
---
v4 -> v5:
- initialize bufstate.error to false
- add cpu_to_le64(size)
--- hw/virtio/trace-events | 2 + hw/virtio/virtio-iommu.c | 190 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 190 insertions(+), 2 deletions(-)
hw/virtio/trace-events +2 -0
@@ -46,3 +46,5 @@ virtio_iommu_unmap_left_interval(uint64_t low, uint64_t high, uint64_t next_low, virtio_iommu_unmap_right_interval(uint64_t low, uint64_t high, uint64_t next_low, uint64_t next_high) "Unmap right [0x%"PRIx64",0x%"PRIx64"], new interval=[0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRIx64",0x%"PRIx64"]" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" +virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t addr, uint64_t size, uint32_t flags, size_t filled) "dev= %d, subtype=%d addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d filled=0x%lx" +virtio_iommu_fill_none_property(uint32_t devid) "devid=%d"
hw/virtio/virtio-iommu.c +188 -2
258 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 14/22 virtio-iommu: Add an msi_bypass property
In reply to Eric AugerIn case the msi_bypass property is set, it means we need to register the IOAPIC MSI window as a reserved region:0xFEE00000 - 0xFEEFFFFF.
---
--- hw/virtio/virtio-iommu.c | 52 ++++++++++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-iommu.h | 1 + 2 files changed, 53 insertions(+)
hw/virtio/virtio-iommu.c +52 -0
@@ -41,6 +41,9 @@#define VIOMMU_DEFAULT_QUEUE_SIZE 256#define VIOMMU_PROBE_SIZE 512 +#define IOAPIC_RANGE_START (0xfee00000) +#define IOAPIC_RANGE_SIZE (0x100000) +#define SUPPORTED_PROBE_PROPERTIES (\ VIRTIO_IOMMU_PROBE_T_NONE | \ VIRTIO_IOMMU_PROBE_T_RESV_MEM)
@@ -103,6 +106,25 @@ static void virtio_iommu_detach_endpoint_from_domain(viommu_endpoint *ep) ep->domain =NULL ; } +static void virtio_iommu_register_resv_region (viommu_endpoint *ep, +uint8_t subtype, +uint64_t addr,uint64_t size) +{ +viommu_interval *interval; +struct virtio_iommu_probe_resv_mem *reg; + + interval =g_malloc0 (sizeof (*interval)); + interval->low = addr; + interval->high = addr + size -1 ; + + reg =g_malloc0 (sizeof (*reg)); + reg->subtype = subtype; + reg->addr =cpu_to_le64 (addr); + reg->size =cpu_to_le64 (size); + +g_tree_insert (ep->reserved_regions, interval, reg); +} +static viommu_endpoint *virtio_iommu_get_endpoint (VirtIOIOMMU *s,uint32_t ep_id) {
@@ -120,6 +142,12 @@ static viommu_endpoint *virtio_iommu_get_endpoint(VirtIOIOMMU *s, ep->reserved_regions =g_tree_new_full ((GCompareDataFunc )interval_cmp,NULL , (GDestroyNotify )g_free, (GDestroyNotify )g_free); +if (s->msi_bypass) { +virtio_iommu_register_resv_region (ep,VIRTIO_IOMMU_RESV_MEM_T_MSI , +IOAPIC_RANGE_START , +IOAPIC_RANGE_SIZE ); + } +return ep; }
@@ -847,8 +875,32 @@ static void virtio_iommu_set_status(VirtIODevice *vdev, uint8_t status)trace_virtio_iommu_device_status (status); } +static bool virtio_iommu_get_msi_bypass (Object *obj,Error **errp) +{ +VirtIOIOMMU *s =VIRTIO_IOMMU (obj); + +return s->msi_bypass; +} + +static void virtio_iommu_set_msi_bypass (Object *obj,bool value,Error **errp) +{ +VirtIOIOMMU *s =VIRTIO_IOMMU (obj); + + s->msi_bypass = value; +} +static void virtio_iommu_instance_init (Object *obj) { +VirtIOIOMMU *s =VIRTIO_IOMMU (obj); + +object_property_add_bool (obj,"msi_bypass" , virtio_iommu_get_msi_bypass, + virtio_iommu_set_msi_bypass,NULL ); +object_property_set_description (obj,"msi_bypass" , +"Indicates whether msis are bypassed by " +"the IOMMU. Default is YES" , +NULL ); + + s->msi_bypass = true; }static const VMStateDescription vmstate_virtio_iommu = {
include/hw/virtio/virtio-iommu.h +1 -0
@@ -57,6 +57,7 @@ typedef struct VirtIOIOMMU {GTree *domains;QemuMutex mutex;GTree *endpoints; + bool msi_bypass; } VirtIOIOMMU;#endif
Signature · 1 line
1.9.1
RFC v5 15/22 virtio-iommu: Implement fault reporting
In reply to Eric AugerThe event queue allows to report asynchronous errors. The translate function now injects faults when relevant.
--- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 3 deletions(-)
hw/virtio/trace-events +1 -0
@@ -48,3 +48,4 @@ virtio_iommu_unmap_inc_interval(uint64_t low, uint64_t high) "Unmap inc [0x%"PRI virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%d" virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t addr, uint64_t size, uint32_t flags, size_t filled) "dev= %d, subtype=%d addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d filled=0x%lx" virtio_iommu_fill_none_property(uint32_t devid) "devid=%d" +virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64
hw/virtio/virtio-iommu.c +64 -3
104 lines not on this page · raw message
Signature · 1 line
1.9.1
RFC v5 16/22 virtio_iommu: Handle reserved regions in translation process
In reply to Eric AugerWhen translating an address we need to check if it belongs to a reserved virtual address range. If it does, there are 2 cases:
- it belongs to a RESERVED region: the guest should neither use this address in a MAP not instruct the end-point to DMA on them. We report an error
- It belongs to an MSI region: we bypass the translation.
--- hw/virtio/virtio-iommu.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
hw/virtio/virtio-iommu.c +17 -0
@@ -748,6 +748,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,viommu_mapping *mapping;viommu_interval interval;bool read_fault, write_fault; +struct virtio_iommu_probe_resv_mem *reg; interval.low = addr; interval.high = addr +1 ;
@@ -773,6 +774,22 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, goto unlock; } + reg =g_tree_lookup (ep->reserved_regions, (gpointer)(&interval)); +if (reg) { +switch (reg->subtype) { +case VIRTIO_IOMMU_RESV_MEM_T_MSI : + entry.perm = flag; +break ; +case VIRTIO_IOMMU_RESV_MEM_T_RESERVED : +default : +virtio_iommu_report_fault (s,VIRTIO_IOMMU_FAULT_R_MAPPING , +0 , sid, addr); + entry.perm =IOMMU_NONE ; +break ; + } + goto unlock; + } +if (!ep->domain) {error_report ("%s %02x:%02x.%01x not attached to any domain" , __func__,PCI_BUS_NUM (sid),PCI_SLOT (sid),PCI_FUNC (sid));
Signature · 1 line
1.9.1
RFC v5 17/22 hw/arm/virt: Add virtio-iommu to the virt board
In reply to Eric AugerThe specific virtio-mmio node is inconditionally added on machine init while the binding between this latter and the PCIe host bridge is done on machine init done notifier, only if -device virtio-iommu-device was added to the qemu command line.
---
v4 -> v5:
- VirtMachineClass no_iommu added in this patch
- Use object_resolve_path_type
--- hw/arm/virt.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++---- include/hw/arm/virt.h | 5 ++++ 2 files changed, 82 insertions(+), 6 deletions(-)
hw/arm/virt.c +77 -6
@@ -52,6 +52,7 @@#include "hw/arm/fdt.h" #include "hw/intc/arm_gic.h" #include "hw/intc/arm_gicv3_common.h" +#include "hw/virtio/virtio-iommu.h" #include "kvm_arm.h" #include "hw/smbios/smbios.h" #include "qapi/visitor.h"
@@ -139,6 +140,7 @@ static const MemMapEntry a15memmap[] = { [VIRT_FW_CFG] = { 0x09020000, 0x00000018 }, [VIRT_GPIO] = { 0x09030000, 0x00001000 }, [VIRT_SECURE_UART] = { 0x09040000, 0x00001000 }, + [VIRT_IOMMU] = { 0x09050000, 0x00000200 }, [VIRT_MMIO] = { 0x0a000000, 0x00000200 }, /* ...repeating for a total of NUM_VIRTIO_TRANSPORTS, each of that size */ [VIRT_PLATFORM_BUS] = { 0x0c000000, 0x02000000 },
@@ -159,6 +161,7 @@ static const int a15irqmap[] = { [VIRT_SECURE_UART] = 8, [VIRT_MMIO] = 16, /* ...to 16 + NUM_VIRTIO_TRANSPORTS - 1 */ [VIRT_GIC_V2M] = 48, /* ...to 48 + NUM_GICV2M_SPIS - 1 */ + [VIRT_IOMMU] = 74, [VIRT_PLATFORM_BUS] = 112, /* ...to 112 + PLATFORM_BUS_NUM_IRQS -1 */ };
@@ -999,6 +1002,69 @@ static void create_pcie_irq_map(const VirtMachineState *vms, 0x7 /* PCI irq */); } +static void virtio_iommu_notifier (Notifier *notifier,void *data) +{ +VirtMachineState *vms =container_of (notifier, VirtMachineState, + virtio_iommu_done); +VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms); +struct arm_boot_info *info = &vms->bootinfo; +bool ambiguous; +Object *obj =object_resolve_path_type ("" ,TYPE_VIRTIO_IOMMU , &ambiguous); +int dtb_size; +void *fdt = info->get_dtb (info, &dtb_size); + +if (!obj) { +return ; + } + +if (vmc->no_iommu) { +error_setg (&error_fatal,"this machine version does not support iommu" ); + } + +if (ambiguous) { +error_setg (&error_fatal,"a single virtio-iommu device is supported!" ); + } + +object_property_set_bool (obj, false,"msi_bypass" , &error_fatal); + +qemu_fdt_setprop_cells (fdt, vms->pcie_host_nodename,"iommu-map" , +0x0 , vms->iommu_phandle,0x0 ,0x10000 ); +} + +static void create_virtio_iommu (VirtMachineState *vms,qemu_irq *pic) +{ +char *node; +const char compat[] ="virtio,mmio" ; +int irq = vms->irqmap[VIRT_IOMMU ]; +hwaddr base = vms->memmap[VIRT_IOMMU ].base; +hwaddr size = vms->memmap[VIRT_IOMMU ].size; +VirtMachineClass *vmc =VIRT_MACHINE_GET_CLASS (vms); + +if (vmc->no_iommu) { +return ; + } + + vms->iommu_phandle =qemu_fdt_alloc_phandle (vms->fdt); + +sysbus_create_simple ("virtio-mmio" , base, pic[irq]); + + node =g_strdup_printf ("/virtio_mmio@%" PRIx64, base); +qemu_fdt_add_subnode (vms->fdt, node); +qemu_fdt_setprop (vms->fdt, node,"compatible" , compat,sizeof (compat)); +qemu_fdt_setprop_sized_cells (vms->fdt, node,"reg" ,2 , base,2 , size); + +qemu_fdt_setprop_cells (vms->fdt, node,"interrupts" , +GIC_FDT_IRQ_TYPE_SPI , irq,GIC_FDT_IRQ_FLAGS_EDGE_LO_HI ); + +qemu_fdt_setprop (vms->fdt, node,"dma-coherent" ,NULL ,0 ); +qemu_fdt_setprop_cell (vms->fdt, node,"#iommu-cells" ,1 ); +qemu_fdt_setprop_cell (vms->fdt, node,"phandle" , vms->iommu_phandle); +g_free (node); + + vms->virtio_iommu_done.notify = virtio_iommu_notifier; +qemu_add_machine_init_done_notifier (&vms->virtio_iommu_done); +} +static void create_pcie (VirtMachineState *vms,qemu_irq *pic) {hwaddr base_mmio = vms->memmap[VIRT_PCIE_MMIO ].base;
@@ -1074,7 +1140,8 @@ static void create_pcie(VirtMachineState *vms, qemu_irq *pic) } } - nodename =g_strdup_printf ("/pcie@%" PRIx64, base); + vms->pcie_host_nodename =g_strdup_printf ("/pcie@%" PRIx64, base); + nodename = vms->pcie_host_nodename;qemu_fdt_add_subnode (vms->fdt, nodename);qemu_fdt_setprop_string (vms->fdt, nodename,"compatible" ,"pci-host-ecam-generic" );
@@ -1113,7 +1180,6 @@ static void create_pcie(VirtMachineState *vms, qemu_irq *pic)qemu_fdt_setprop_cell (vms->fdt, nodename,"#interrupt-cells" ,1 );create_pcie_irq_map (vms, vms->gic_phandle, irq, nodename); -g_free (nodename); }static void create_platform_bus (VirtMachineState *vms,qemu_irq *pic)
@@ -1429,16 +1495,16 @@ static void machvirt_init(MachineState *machine)create_rtc (vms, pic); -create_pcie (vms, pic); - -create_gpio (vms, pic); -/* Create mmio transports, so the user can create virtio backends * (which will be automatically plugged in to the transports). If * no backend is created the transport will just sit harmlessly idle. */ create_virtio_devices (vms, pic); +create_pcie (vms, pic); + +create_gpio (vms, pic); + vms->fw_cfg =create_fw_cfg (vms, &address_space_memory);rom_set_fw (vms->fw_cfg);
@@ -1463,6 +1529,7 @@ static void machvirt_init(MachineState *machine)* Notifiers are executed in registration reverse order. */ create_platform_bus (vms, pic); +create_virtio_iommu (vms, pic); }static bool virt_get_secure (Object *obj,Error **errp)
@@ -1702,8 +1769,12 @@ static void virt_2_11_instance_init(Object *obj)static void virt_machine_2_11_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_2_12_options (mc);SET_MACHINE_COMPAT (mc,VIRT_COMPAT_2_11 ); + + vmc->no_iommu = true; }DEFINE_VIRT_MACHINE (2 ,11 )
include/hw/arm/virt.h +5 -0
@@ -59,6 +59,7 @@ enum {VIRT_GIC_V2M ,VIRT_GIC_ITS ,VIRT_GIC_REDIST , +VIRT_IOMMU ,VIRT_UART ,VIRT_MMIO , VIRT_RTC,
@@ -84,12 +85,14 @@ typedef struct {bool disallow_affinity_adjustment;bool no_its;bool no_pmu; +bool no_iommu;bool claim_edge_triggered_timers; } VirtMachineClass; typedef struct { MachineState parent; Notifier machine_done; + Notifier virtio_iommu_done; FWCfgState *fw_cfg; bool secure; bool highmem;
@@ -105,6 +108,8 @@ typedef struct {uint32_t clock_phandle;uint32_t gic_phandle;uint32_t msi_phandle; +uint32_t iommu_phandle; +char *pcie_host_nodename;int psci_conduit;PCIBus *pci_bus; } VirtMachineState;
Signature · 1 line
1.9.1
RFC v5 18/22 hw/arm/virt-acpi-build: Add virtio-iommu node in IORT table
In reply to Eric AugerThis patch builds the virtio-iommu node in the ACPI IORT table. The dt node creation function fills the information used by the IORT table generation function (base address, base irq, type of the smmu).
The RID space of the root complex, which spans 0x0-0x10000 maps to streamid space 0x0-0x10000 in smmuv3, which in turn maps to deviceid space 0x0-0x10000 in the ITS group.
--- hw/arm/virt-acpi-build.c | 55 +++++++++++++++++++++++++++++++++++++++------ hw/arm/virt.c | 5 +++++ include/hw/acpi/acpi-defs.h | 21 ++++++++++++++++- include/hw/arm/virt.h | 13 +++++++++++ 4 files changed, 86 insertions(+), 8 deletions(-)
hw/arm/virt-acpi-build.c +48 -7
@@ -42,6 +42,7 @@#include "hw/acpi/aml-build.h" #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" +#include "hw/virtio/virtio-iommu.h" #include "hw/arm/virt.h" #include "sysemu/numa.h" #include "kvm_arm.h"
@@ -393,18 +394,26 @@ build_rsdp(GArray *rsdp_table, BIOSLinker *linker, unsigned xsdt_tbl_offset) }static void -build_iort (GArray *table_data,BIOSLinker *linker) +build_iort (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms) { -int iort_start = table_data->len; +int nb_nodes, iort_start = table_data->len;AcpiIortIdMapping *idmap;AcpiIortItsGroup *its;AcpiIortTable *iort; -size_t node_size, iort_length; +AcpiIortPVIommu *iommu; +size_t node_size, iort_length, iommu_offset =0 ;AcpiIortRC *rc; iort =acpi_data_push (table_data,sizeof (*iort)); +if (vms->iommu_info.type) { + nb_nodes =3 ;/* RC, ITS, IOMMU */ + }else { + nb_nodes =2 ;/* RC, ITS */ + } + iort_length =sizeof (*iort); + iort->node_count =cpu_to_le32 (nb_nodes); iort->node_count =cpu_to_le32 (2 );/* RC and ITS nodes */ iort->node_offset =cpu_to_le32 (sizeof (*iort));
@@ -418,6 +427,32 @@ build_iort(GArray *table_data, BIOSLinker *linker) its->its_count =cpu_to_le32 (1 ); its->identifiers[0 ] =0 ;/* MADT translation_id */ +if (vms->iommu_info.type ==VIRT_IOMMU_VIRTIO ) { + +/* Para-virtualized IOMMU node */ + iommu_offset =cpu_to_le32 (iort->node_offset + node_size); + node_size =sizeof (*iommu) +sizeof (*idmap); + iort_length += node_size; + iommu =acpi_data_push (table_data, node_size); + + iommu->type =ACPI_IORT_NODE_PARAVIRT ; + iommu->length =cpu_to_le16 (node_size); + iommu->base_address =cpu_to_le64 (vms->iommu_info.reg.base); + iommu->span =cpu_to_le64 (vms->iommu_info.reg.size); + iommu->model =ACPI_IORT_NODE_PV_VIRTIO_IOMMU ; + iommu->flags =ACPI_IORT_NODE_PV_CACHE_COHERENT ; + iommu->interrupt_count =1 ; + iommu->interrupts[0 ] =cpu_to_le64 (vms->iommu_info.irq_base); + +/* Identity RID mapping covering the whole input RID range */ + idmap = &iommu->id_mapping_array[0 ]; + idmap->input_base =0 ; + idmap->id_count =cpu_to_le32 (0xFFFF ); + idmap->output_base =0 ; +/* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =cpu_to_le32 (iort->node_offset); + } +/* Root Complex Node */ node_size =sizeof (*rc) +sizeof (*idmap); iort_length += node_size;
@@ -438,10 +473,16 @@ build_iort(GArray *table_data, BIOSLinker *linker) idmap->input_base =0 ; idmap->id_count =cpu_to_le32 (0xFFFF ); idmap->output_base =0 ; -/* output IORT node is the ITS group node (the first node) */ - idmap->output_reference =cpu_to_le32 (iort->node_offset); - iort->length =cpu_to_le32 (iort_length); +if (vms->iommu_info.type) { +/* output IORT node is the smmuv3 node */ + idmap->output_reference =cpu_to_le32 (iommu_offset); + }else { +/* output IORT node is the ITS group node (the first node) */ + idmap->output_reference =cpu_to_le32 (iort->node_offset); + } + + iort->length =cpu_to_le32 (iort_length);build_header (linker, table_data, (void *)(table_data->data + iort_start),"IORT" , table_data->len - iort_start,0 ,NULL ,NULL );
@@ -786,7 +827,7 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)if (its_class_name () && !vmc->no_its) {acpi_add_table (table_offsets, tables_blob); -build_iort (tables_blob, tables->linker); +build_iort (tables_blob, tables->linker, vms); }/* XSDT is pointed to by RSDP */
hw/arm/virt.c +5 -0
@@ -1027,6 +1027,11 @@ static void virtio_iommu_notifier(Notifier *notifier, void *data)object_property_set_bool (obj, false,"msi_bypass" , &error_fatal); + vms->iommu_info.type =VIRT_IOMMU_VIRTIO ; + vms->iommu_info.reg.base = vms->memmap[VIRT_IOMMU ].base; + vms->iommu_info.reg.size = vms->memmap[VIRT_IOMMU ].size; + vms->iommu_info.irq_base = vms->irqmap[VIRT_IOMMU ]; +qemu_fdt_setprop_cells (fdt, vms->pcie_host_nodename,"iommu-map" ,0x0 , vms->iommu_phandle,0x0 ,0x10000 ); }
include/hw/acpi/acpi-defs.h +20 -1
@@ -673,7 +673,8 @@ enum {ACPI_IORT_NODE_NAMED_COMPONENT =0x01 ,ACPI_IORT_NODE_PCI_ROOT_COMPLEX =0x02 ,ACPI_IORT_NODE_SMMU =0x03 , -ACPI_IORT_NODE_SMMU_V3 =0x04 +ACPI_IORT_NODE_SMMU_V3 =0x04 , +ACPI_IORT_NODE_PARAVIRT =0x05 }; struct AcpiIortIdMapping {
@@ -700,6 +701,24 @@ struct AcpiIortItsGroup { }QEMU_PACKED ;typedef struct AcpiIortItsGroup AcpiIortItsGroup ; +struct AcpiIortPVIommu { +ACPI_IORT_NODE_HEADER_DEF + uint64_t base_address; +uint64_t span; +uint32_t model; +uint32_t flags; +uint32_t interrupt_count; +uint64_t interrupts[1 ]; +AcpiIortIdMapping id_mapping_array[0 ]; +}QEMU_PACKED ; +typedef struct AcpiIortPVIommu AcpiIortPVIommu ; + +enum { +ACPI_IORT_NODE_PV_VIRTIO_IOMMU =0x00 , +}; + +#define ACPI_IORT_NODE_PV_CACHE_COHERENT (1 << 0) +struct AcpiIortRC {ACPI_IORT_NODE_HEADER_DEF AcpiIortMemoryAccess memory_properties;
include/hw/arm/virt.h +13 -0
@@ -89,6 +89,18 @@ typedef struct {bool claim_edge_triggered_timers; } VirtMachineClass; +typedef enum VirtIOMMUType { +VIRT_IOMMU_NONE , +VIRT_IOMMU_SMMUV3 , +VIRT_IOMMU_VIRTIO , +}VirtIOMMUType ; + +typedef struct VirtIOMMUInfo { +VirtIOMMUType type; +MemMapEntry reg; +int irq_base; +}VirtIOMMUInfo ; + typedef struct { MachineState parent; Notifier machine_done;
@@ -98,6 +110,7 @@ typedef struct {bool highmem;bool its;bool virt; +VirtIOMMUInfo iommu_info;int32_t gic_version;struct arm_boot_info bootinfo;const MemMapEntry *memmap;
Signature · 1 line
1.9.1
RFC v5 19/22 memory.h: Add set_page_size_mask IOMMUMemoryRegion callback
In reply to Eric AugerThis callback allows to inform the IOMMU memory region about restrictions on the supported page sizes.
--- include/exec/memory.h | 4 ++++ 1 file changed, 4 insertions(+)
include/exec/memory.h +4 -0
@@ -204,6 +204,10 @@ typedef struct IOMMUMemoryRegionClass { IOMMUAccessFlags flag);/* Returns minimum supported page size */ uint64_t (*get_min_page_size)(IOMMUMemoryRegion *iommu); + +/* Limits the supported page sizes to @pgsizes */ +void (*set_page_size_mask)(IOMMUMemoryRegion *iommu,uint64_t pgsizes); +/* Called when IOMMU Notifier flag changed */ void (*notify_flag_changed)(IOMMUMemoryRegion *iommu, IOMMUNotifierFlag old_flags,
Signature · 1 line
1.9.1
RFC v5 20/22 hw/vfio/common: Set the IOMMUMemoryRegion supported page sizes
In reply to Eric AugerWe store the page_size_mask in the container and on vfio_listener_region_add(), the information is conveyed to the IOMMUMemoryRegion.
--- hw/vfio/common.c | 5 +++++ include/hw/vfio/vfio-common.h | 1 + 2 files changed, 6 insertions(+)
hw/vfio/common.c +5 -0
@@ -480,6 +480,7 @@ static void vfio_listener_region_add(MemoryListener *listener,if (memory_region_is_iommu (section->mr)) {VFIOGuestIOMMU *giommu;IOMMUMemoryRegion *iommu_mr =IOMMU_MEMORY_REGION (section->mr); +IOMMUMemoryRegionClass *imrc =IOMMU_MEMORY_REGION_GET_CLASS (iommu_mr);trace_vfio_listener_region_add_iommu (iova, end);/*
@@ -500,6 +501,9 @@ static void vfio_listener_region_add(MemoryListener *listener,IOMMU_NOTIFIER_ALL , section->offset_within_region, int128_get64(llend)); +if (imrc->set_page_size_mask) { + imrc->set_page_size_mask (iommu_mr, container->page_size_mask); + }QLIST_INSERT_HEAD (&container->giommu_list, giommu, giommu_next);memory_region_register_iommu_notifier (section->mr, &giommu->n);
@@ -1027,6 +1031,7 @@ static int vfio_connect_container(VFIOGroup *group, AddressSpace *as,/* Assume 4k IOVA page size */ info.iova_pgsizes =4096 ; } + container->page_size_mask = info.iova_pgsizes;vfio_host_win_add (container,0 , (hwaddr)-1 , info.iova_pgsizes); }else if (ioctl (fd,VFIO_CHECK_EXTENSION ,VFIO_SPAPR_TCE_IOMMU ) ||ioctl (fd,VFIO_CHECK_EXTENSION , VFIO_SPAPR_TCE_v2_IOMMU)) {
include/hw/vfio/vfio-common.h +1 -0
@@ -79,6 +79,7 @@ typedef struct VFIOContainer {int fd;/* /dev/vfio/vfio, empowered by the attached groups */ MemoryListener listener;MemoryListener prereg_listener; +uint64_t page_size_mask;/* page sizes supported for this container */ unsigned iommu_type;int error;bool initialized;
Signature · 1 line
1.9.1
RFC v5 21/22 virtio-iommu: Implement set_page_size_mask
In reply to Eric AugerWe implement the set_page_size_mask callback to allow the virtio-iommu to be aware of any restrictions on the page size mask due to an underlying HW IOMMU.
--- hw/virtio/trace-events | 1 + hw/virtio/virtio-iommu.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
hw/virtio/trace-events +1 -0
@@ -49,3 +49,4 @@ virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) virtio_iommu_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t addr, uint64_t size, uint32_t flags, size_t filled) "dev= %d, subtype=%d addr=0x%"PRIx64" size=0x%"PRIx64" flags=%d filled=0x%lx" virtio_iommu_fill_none_property(uint32_t devid) "devid=%d" virtio_iommu_report_fault(uint8_t reason, uint32_t flags, uint32_t endpoint, uint64_t addr) "FAULT reason=%d flags=%d endpoint=%d address =0x%"PRIx64 +virtio_iommu_set_page_size_mask(const char *iommu_mr, uint64_t mask) "mr=%s page_size_mask=0x%"PRIx64
hw/virtio/virtio-iommu.c +16 -0
@@ -831,6 +831,21 @@ unlock:return entry; } +static void virtio_iommu_set_page_size_mask (IOMMUMemoryRegion *mr, +uint64_t page_size_mask) +{ +IOMMUDevice *sdev =container_of (mr, IOMMUDevice, iommu_mr); +VirtIOIOMMU *s = sdev->viommu; + + s->config.page_size_mask &= page_size_mask; +if (!s->config.page_size_mask) { +error_setg (&error_fatal, +"No compatible page size between guest and host iommus" ); + } + +trace_virtio_iommu_set_page_size_mask (mr->parent_obj.name, page_size_mask); +} +static void virtio_iommu_get_config (VirtIODevice *vdev,uint8_t *config_data) {VirtIOIOMMU *dev =VIRTIO_IOMMU (vdev);
@@ -1021,6 +1036,7 @@ static void virtio_iommu_memory_region_class_init(ObjectClass *klass,IOMMUMemoryRegionClass *imrc =IOMMU_MEMORY_REGION_CLASS (klass); imrc->translate = virtio_iommu_translate; + imrc->set_page_size_mask = virtio_iommu_set_page_size_mask; }static const TypeInfo virtio_iommu_info = {
Signature · 1 line
1.9.1
RFC v5 22/22 hw/vfio/common: Do not print error when viommu translates into an mmio region
In reply to Eric AugerOn ARM, the MSI doorbell is translated by the virtual IOMMU. As such address_space_translate() returns the MSI controller MMIO region and we get an "iommu map to non memory area" message. Let's remove this latter.
--- hw/vfio/common.c | 2 -- 1 file changed, 2 deletions(-)
hw/vfio/common.c +0 -2
@@ -326,8 +326,6 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr, iotlb->translated_addr, &xlat, &len, writable);if (!memory_region_is_ram (mr)) { -error_report ("iommu map to non memory area %" HWADDR_PRIx"" , - xlat);return false; }
Signature · 1 line
1.9.1