VIRTIO-IOMMU probe request support and MSI bypass on ARM
v5 cover VIRTIO-IOMMU probe request support and MSI bypass on ARM
By default the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. However the virt machine code knows where the MSI doorbells are, so we can easily declare those regions as VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest iommu subsystem will not need to map MSIs. This setup will simplify the VFIO integration.
In this series, the ITS or GICV2M doorbells are declared as HW MSI regions to be bypassed by the VIRTIO-IOMMU.
This also paves the way to the x86 integration where the MSI region, [0xFEE00000,0xFEEFFFFF], will be exposed by the q35 machine. However this will be handled in a separate series when not-DT support gets resolved.
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v5.0.0-virtio-iommu-msi-bypass-v5
History:
v4 -> v5:
- Take into account some additional comments from Markus:
- reserved region type becomes an unsigned + some comment/desc rewording
- assert if the type is not RESERVED or MSI
v3 -> v4:
- collected Jean and markus's R-bs
- tool into account all Markus' comments in [1/5] (except removal of goto)
- use ':' as delimitor instead of commas
- add example in 4/5 commit message as suggested by Markus
v2 -> v3:
- Introduce VIRT_MSI_CTRL_NONE in VirtMSIControllerType
- do not fill the remainder of the probe buffer
v1 -> v2:
- check which MSI controller is in use and advertise the corresponding MSI doorbell
- managed for both ITS and GICv2M
- various fixes spotted by Peter and Jean-Philippe, see individual logs
v1: Most of those patches were respinned from
[PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device
except the last one which is new
Eric Auger (5):
qdev: Introduce DEFINE_PROP_RESERVED_REGION
virtio-iommu: Implement RESV_MEM probe request
virtio-iommu: Handle reserved regions in the translation process
virtio-iommu-pci: Add array of Interval properties hw/arm/virt: Let the virtio-iommu bypass MSIs
include/exec/memory.h | 6 ++ include/hw/arm/virt.h | 7 ++ include/hw/qdev-properties.h | 3 + include/hw/virtio/virtio-iommu.h | 2 + include/qemu/typedefs.h | 1 + hw/arm/virt.c | 18 +++++ hw/core/qdev-properties.c | 89 ++++++++++++++++++++++++ hw/virtio/virtio-iommu-pci.c | 3 + hw/virtio/virtio-iommu.c | 112 +++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 10 files changed, 238 insertions(+), 4 deletions(-)
Signature · 1 line
2.20.1
PATCH v5 1/5 qdev: Introduce DEFINE_PROP_RESERVED_REGION
Introduce a new property defining a reserved region:
<low address>:<high address>:<type>.
This will be used to encode reserved IOVA regions.
For instance, in virtio-iommu use case, reserved IOVA regions will be passed by the machine code to the virtio-iommu-pci device (an array of those). The type of the reserved region will match the virtio_iommu_probe_resv_mem subtype value:
- VIRTIO_IOMMU_RESV_MEM_T_RESERVED (0)
- VIRTIO_IOMMU_RESV_MEM_T_MSI (1)
on PC/Q35 machine, this will be used to inform the virtio-iommu-pci device it should bypass the MSI region. The reserved region will be: 0xfee00000:0xfeefffff:1.
On ARM, we can declare the ITS MSI doorbell as an MSI region to prevent MSIs from being mapped on guest side.
---
v4 -> v5:
- type becomes an unsigned + comment/error rewording
v3 -> v4:
- use ':' instead of commas as separators.
- rearrange error messages
- check snprintf returned value
- dared to keep Markus' R-b despite those changes
--- include/exec/memory.h | 6 +++ include/hw/qdev-properties.h | 3 ++ include/qemu/typedefs.h | 1 + hw/core/qdev-properties.c | 89 ++++++++++++++++++++++++++++++++++++ 4 files changed, 99 insertions(+)
include/exec/memory.h +6 -0
@@ -51,6 +51,12 @@ extern bool global_dirty_log;typedef struct MemoryRegionOps MemoryRegionOps ; +struct ReservedRegion { +hwaddr low; +hwaddr high; +unsigned type; +}; +typedef struct IOMMUTLBEntry IOMMUTLBEntry ;/* See address_space_translate: bit 0 is read, bit 1 is write. */
include/hw/qdev-properties.h +3 -0
@@ -19,6 +19,7 @@ extern const PropertyInfo qdev_prop_string;extern const PropertyInfo qdev_prop_chr;extern const PropertyInfo qdev_prop_tpm;extern const PropertyInfo qdev_prop_macaddr; +extern const PropertyInfo qdev_prop_reserved_region;extern const PropertyInfo qdev_prop_on_off_auto;extern const PropertyInfo qdev_prop_multifd_compression;extern const PropertyInfo qdev_prop_losttickpolicy;
@@ -184,6 +185,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width; DEFINE_PROP(_n, _s, _f, qdev_prop_drive_iothread, BlockBackend *) #define DEFINE_PROP_MACADDR(_n, _s, _f) \DEFINE_PROP (_n, _s, _f, qdev_prop_macaddr, MACAddr) +#define DEFINE_PROP_RESERVED_REGION(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_reserved_region, ReservedRegion)#define DEFINE_PROP_ON_OFF_AUTO (_n, _s, _f, _d) \ DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)#define DEFINE_PROP_MULTIFD_COMPRESSION (_n, _s, _f, _d) \
include/qemu/typedefs.h +1 -0
@@ -58,6 +58,7 @@ typedef struct ISABus ISABus;typedef struct ISADevice ISADevice ;typedef struct IsaDma IsaDma ;typedef struct MACAddr MACAddr ; +typedef struct ReservedRegion ReservedRegion ;typedef struct MachineClass MachineClass ;typedef struct MachineState MachineState ;typedef struct MemoryListener MemoryListener ;
hw/core/qdev-properties.c +89 -0
101 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v5 2/5 virtio-iommu: Implement RESV_MEM probe request
In reply to Eric AugerThis patch implements the PROBE request. At the moment, only THE RESV_MEM property is handled. The first goal is to report iommu wide reserved regions such as the MSI regions set by the machine code. On x86 this will be the IOAPIC MSI region, [0xFEE00000 - 0xFEEFFFFF], on ARM this may be the ITS doorbell.
In the future we may introduce per device reserved regions. This will be useful when protecting host assigned devices which may expose their own reserved regions
---
v4 -> v5:
- assert if reserved region type is different from RESERVED or MSI
v3 -> v4:
- removed any reference to the NONE property that does not exist anymore.
v2 -> v3:
- on probe, do not fill the reminder of the buffer with zeroes as the buffer was already zero initialized (Bharat)
v1 -> v2:
- move the unlock back to the same place
- remove the push label and factorize the code after the out label
- fix a bunch of cpu_to_leX according to the latest spec revision
- do not remove sizeof(last) from free space
- check the ep exists
--- include/hw/virtio/virtio-iommu.h | 2 + hw/virtio/virtio-iommu.c | 92 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 91 insertions(+), 4 deletions(-)
include/hw/virtio/virtio-iommu.h +2 -0
@@ -53,6 +53,8 @@ typedef struct VirtIOIOMMU {GHashTable *as_by_busptr;IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX ];PCIBus *primary_bus; +ReservedRegion *reserved_regions; +uint32_t nb_reserved_regions;GTree *domains;QemuMutex mutex;GTree *endpoints;
hw/virtio/virtio-iommu.c +88 -4
145 lines not on this page · raw message
hw/virtio/trace-events +1 -0
@@ -74,3 +74,4 @@ virtio_iommu_get_domain(uint32_t domain_id) "Alloc domain=%d" virtio_iommu_put_domain(uint32_t domain_id) "Free domain=%d" virtio_iommu_translate_out(uint64_t virt_addr, uint64_t phys_addr, uint32_t sid) "0x%"PRIx64" -> 0x%"PRIx64 " for sid=%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_fill_resv_property(uint32_t devid, uint8_t subtype, uint64_t start, uint64_t end) "dev= %d, type=%d start=0x%"PRIx64" end=0x%"PRIx64
Signature · 1 line
2.20.1
Re: [PATCH v5 2/5] virtio-iommu: Implement RESV_MEM probe request
Quoted 78 lines · Eric Auger
This patch implements the PROBE request. At the moment, only THE
RESV_MEMproperty is handled. The first goal is to report iommu wide reserved regions such as the MSI regions set by the machine code. On x86 this will be the IOAPIC MSI region, [0xFEE00000-0xFEEFFFFF], on ARM this may be the ITS doorbell.In the future we may introduce per device reserved regions. This will be useful when protecting host assigned devices which may expose their own reserved regions
Signed-off-by Eric Auger <[email protected]>Reviewed-by Jean-Philippe Brucker <[email protected]>---
v4 -> v5:
- assert if reserved region type is different from RESERVED or MSIv3 -> v4:
- removed any reference to the NONE property that does not exist anymore.v2 -> v3:
- on probe, do not fill the reminder of the buffer with zeroes as the buffer was already zero initialized (Bharat)v1 -> v2:
- move the unlock back to the same place
- remove the push label and factorize the code after the out label
- fix a bunch ofcpu_to_leXaccording to the latest spec revision
- do not remove sizeof(last) from free space
- check the ep exists--- include/hw/virtio/virtio-iommu.h | 2 + hw/virtio/virtio-iommu.c | 92 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 91 insertions(+), 4 deletions(-)include/hw/virtio/virtio-iommu.h +2
-0@@ -53,6 +53,8 @@ typedef struct VirtIOIOMMU {GHashTable *as_by_busptr;IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX ];PCIBus *primary_bus; +ReservedRegion *reserved_regions; +uint32_t nb_reserved_regions;GTree *domains;QemuMutex mutex;GTree *endpoints;hw/virtio/virtio-iommu.c +10
-0@@ -38,6 +38,7 @@/* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +#define VIOMMU_PROBE_SIZE 512 typedef struct VirtIOIOMMUDomain { uint32_t id;@@ -378,6 +379,63 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,return ret; } +static ssize_t virtio_iommu_fill_resv_mem_prop (VirtIOIOMMU *s,uint32_t ep, +uint8_t *buf,size_t free) +{ +struct virtio_iommu_probe_resv_mem prop = {}; +size_t size =sizeof (prop), length = size -sizeof (prop.head), total; +int i; + + total = size * s->nb_reserved_regions; +
hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 400
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+if (total > free) { +return -ENOSPC ; + } + +for (i =0 ; i < s->nb_reserved_regions; i++) { + prop.head.type =cpu_to_le16 (VIRTIO_IOMMU_PROBE_T_RESV_MEM ); + prop.head.length =cpu_to_le16 (length); + prop.subtype = s->reserved_regions[i].type; +assert (prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_RESERVED || + prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_MSI );
The assertion makes sense here: we're mapping from the generic ReservedRegion type (which is unsigned) to the specific virtio_iommu_probe_resv_mem subtype (which is uint8_t, but only these two values are valid).
Howver, the assertion should test s->reserved_regions[i].type and go before the assignment, to ensure it doesn't truncate!
Can I trigger the assertion with -device? My try to find the answer myself failed:
$ qemu-system-x86_64 -nodefaults -S -display none -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99
qemu-system-x86_64: -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99: pc-i440fx-5.1 machine fails to create iommu-map device tree bindings
Check you machine implements a hotplug handler for the virtio-iommu-pci device
Check the guest is booted without FW or with -no-acpiBy the way: s/Check you machine/Check your machine/.
[...]
Re: [PATCH v5 2/5] virtio-iommu: Implement RESV_MEM probe request
Quoted 6 lines · Markus Armbruster
$ qemu-system-x86_64 -nodefaults -S -display none -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99 qemu-system-x86_64: -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99: pc-i440fx-5.1 machine fails to create iommu-map device tree bindings Check you machine implements a hotplug handler for the virtio-iommu-pci device Check the guest is booted without FW or with -no-acpiBy the way: s/Check you machine/Check your machine/.
Patch sent:
https://patchew.org/QEMU/[email protected]/
thanks
-- PMM
Re: [PATCH v5 2/5] virtio-iommu: Implement RESV_MEM probe request
Hi Peter,
Quoted 10 lines · Peter Maydell
Quoted 6 lines · Markus Armbruster
$ qemu-system-x86_64 -nodefaults -S -display none -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99 qemu-system-x86_64: -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99: pc-i440fx-5.1 machine fails to create iommu-map device tree bindings Check you machine implements a hotplug handler for the virtio-iommu-pci device Check the guest is booted without FW or with -no-acpiBy the way: s/Check you machine/Check your machine/.
Patch sent:
https://patchew.org/QEMU/[email protected]/
Thank you for the typo fix.
Eric
Quoted 4 lines
thanks
-- PMM
Re: [PATCH v5 2/5] virtio-iommu: Implement RESV_MEM probe request
In reply to Markus ArmbrusterHi Markus,
Quoted 96 lines · Markus Armbruster
Quoted 78 lines · Eric Auger
This patch implements the PROBE request. At the moment, only THE
RESV_MEMproperty is handled. The first goal is to report iommu wide reserved regions such as the MSI regions set by the machine code. On x86 this will be the IOAPIC MSI region, [0xFEE00000-0xFEEFFFFF], on ARM this may be the ITS doorbell.In the future we may introduce per device reserved regions. This will be useful when protecting host assigned devices which may expose their own reserved regions
Signed-off-by Eric Auger <[email protected]>Reviewed-by Jean-Philippe Brucker <[email protected]>---
v4 -> v5:
- assert if reserved region type is different from RESERVED or MSIv3 -> v4:
- removed any reference to the NONE property that does not exist anymore.v2 -> v3:
- on probe, do not fill the reminder of the buffer with zeroes as the buffer was already zero initialized (Bharat)v1 -> v2:
- move the unlock back to the same place
- remove the push label and factorize the code after the out label
- fix a bunch ofcpu_to_leXaccording to the latest spec revision
- do not remove sizeof(last) from free space
- check the ep exists--- include/hw/virtio/virtio-iommu.h | 2 + hw/virtio/virtio-iommu.c | 92 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 91 insertions(+), 4 deletions(-)include/hw/virtio/virtio-iommu.h +2
-0@@ -53,6 +53,8 @@ typedef struct VirtIOIOMMU {GHashTable *as_by_busptr;IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX ];PCIBus *primary_bus; +ReservedRegion *reserved_regions; +uint32_t nb_reserved_regions;GTree *domains;QemuMutex mutex;GTree *endpoints;hw/virtio/virtio-iommu.c +10
-0@@ -38,6 +38,7 @@/* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +#define VIOMMU_PROBE_SIZE 512 typedef struct VirtIOIOMMUDomain { uint32_t id;@@ -378,6 +379,63 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,return ret; } +static ssize_t virtio_iommu_fill_resv_mem_prop (VirtIOIOMMU *s,uint32_t ep, +uint8_t *buf,size_t free) +{ +struct virtio_iommu_probe_resv_mem prop = {}; +size_t size =sizeof (prop), length = size -sizeof (prop.head), total; +int i; + + total = size * s->nb_reserved_regions; +hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 400
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+if (total > free) { +return -ENOSPC ; + } + +for (i =0 ; i < s->nb_reserved_regions; i++) { + prop.head.type =cpu_to_le16 (VIRTIO_IOMMU_PROBE_T_RESV_MEM ); + prop.head.length =cpu_to_le16 (length); + prop.subtype = s->reserved_regions[i].type; +assert (prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_RESERVED || + prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_MSI );The assertion makes sense here: we're mapping from the generic ReservedRegion type (which is unsigned) to the specific
virtio_iommu_probe_resv_memsubtype (which isuint8_t, but only these two values are valid).
Quoted 2 lines
Howver, the assertion should test s->reserved_regions[i].type and go before the assignment, to ensure it doesn't truncate!
OK I will do.
Quoted 3 lines
Can I trigger the assertion with -device? My try to find the answer myself failed:
At the moment the virtio-iommu-pci device only can be instantiated with machvirt, booting in dt mode.
Quoted 7 lines
$ qemu-system-x86_64 -nodefaults -S -display none -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99 qemu-system-x86_64: -device virtio-iommu-pci,len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:99: pc-i440fx-5.1 machine fails to create iommu-map device tree bindings Check you machine implements a hotplug handler for the virtio-iommu-pci device Check the guest is booted without FW or with -no-acpiBy the way: s/Check you machine/Check your machine/.
Thanks
Eric
Quoted 3 lines
[...]
Re: [PATCH v5 2/5] virtio-iommu: Implement RESV_MEM probe request
Quoted 98 lines · Auger Eric
Hi Markus,
Quoted 96 lines · Markus Armbruster
Quoted 78 lines · Eric Auger
This patch implements the PROBE request. At the moment, only THE
RESV_MEMproperty is handled. The first goal is to report iommu wide reserved regions such as the MSI regions set by the machine code. On x86 this will be the IOAPIC MSI region, [0xFEE00000-0xFEEFFFFF], on ARM this may be the ITS doorbell.In the future we may introduce per device reserved regions. This will be useful when protecting host assigned devices which may expose their own reserved regions
Signed-off-by Eric Auger <[email protected]>Reviewed-by Jean-Philippe Brucker <[email protected]>---
v4 -> v5:
- assert if reserved region type is different from RESERVED or MSIv3 -> v4:
- removed any reference to the NONE property that does not exist anymore.v2 -> v3:
- on probe, do not fill the reminder of the buffer with zeroes as the buffer was already zero initialized (Bharat)v1 -> v2:
- move the unlock back to the same place
- remove the push label and factorize the code after the out label
- fix a bunch ofcpu_to_leXaccording to the latest spec revision
- do not remove sizeof(last) from free space
- check the ep exists--- include/hw/virtio/virtio-iommu.h | 2 + hw/virtio/virtio-iommu.c | 92 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 91 insertions(+), 4 deletions(-)include/hw/virtio/virtio-iommu.h +2
-0@@ -53,6 +53,8 @@ typedef struct VirtIOIOMMU {GHashTable *as_by_busptr;IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX ];PCIBus *primary_bus; +ReservedRegion *reserved_regions; +uint32_t nb_reserved_regions;GTree *domains;QemuMutex mutex;GTree *endpoints;hw/virtio/virtio-iommu.c +10
-0@@ -38,6 +38,7 @@/* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +#define VIOMMU_PROBE_SIZE 512 typedef struct VirtIOIOMMUDomain { uint32_t id;@@ -378,6 +379,63 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,return ret; } +static ssize_t virtio_iommu_fill_resv_mem_prop (VirtIOIOMMU *s,uint32_t ep, +uint8_t *buf,size_t free) +{ +struct virtio_iommu_probe_resv_mem prop = {}; +size_t size =sizeof (prop), length = size -sizeof (prop.head), total; +int i; + + total = size * s->nb_reserved_regions; +hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 400
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+if (total > free) { +return -ENOSPC ; + } + +for (i =0 ; i < s->nb_reserved_regions; i++) { + prop.head.type =cpu_to_le16 (VIRTIO_IOMMU_PROBE_T_RESV_MEM ); + prop.head.length =cpu_to_le16 (length); + prop.subtype = s->reserved_regions[i].type; +assert (prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_RESERVED || + prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_MSI );The assertion makes sense here: we're mapping from the generic ReservedRegion type (which is unsigned) to the specific
virtio_iommu_probe_resv_memsubtype (which isuint8_t, but only these two values are valid).
Quoted 8 lines
Quoted 2 lines
Howver, the assertion should test s->reserved_regions[i].type and go before the assignment, to ensure it doesn't truncate!
OK I will do.
Quoted 3 lines
Can I trigger the assertion with -device? My try to find the answer myself failed:
At the moment the virtio-iommu-pci device only can be instantiated with machvirt, booting in dt mode.
I asked because if I can, then invalid types need to be rejected cleanly.
Invalid property values can be rejected by the setter, or by the realize method. Since this setter by design accepts anything that fits into unsigned, it's realize.
[...]
Re: [PATCH v5 2/5] virtio-iommu: Implement RESV_MEM probe request
Hi Markus
Quoted 109 lines · Markus Armbruster
Quoted 98 lines · Auger Eric
Hi Markus,
Quoted 96 lines · Markus Armbruster
Quoted 78 lines · Eric Auger
This patch implements the PROBE request. At the moment, only THE
RESV_MEMproperty is handled. The first goal is to report iommu wide reserved regions such as the MSI regions set by the machine code. On x86 this will be the IOAPIC MSI region, [0xFEE00000-0xFEEFFFFF], on ARM this may be the ITS doorbell.In the future we may introduce per device reserved regions. This will be useful when protecting host assigned devices which may expose their own reserved regions
Signed-off-by Eric Auger <[email protected]>Reviewed-by Jean-Philippe Brucker <[email protected]>---
v4 -> v5:
- assert if reserved region type is different from RESERVED or MSIv3 -> v4:
- removed any reference to the NONE property that does not exist anymore.v2 -> v3:
- on probe, do not fill the reminder of the buffer with zeroes as the buffer was already zero initialized (Bharat)v1 -> v2:
- move the unlock back to the same place
- remove the push label and factorize the code after the out label
- fix a bunch ofcpu_to_leXaccording to the latest spec revision
- do not remove sizeof(last) from free space
- check the ep exists--- include/hw/virtio/virtio-iommu.h | 2 + hw/virtio/virtio-iommu.c | 92 ++++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 3 files changed, 91 insertions(+), 4 deletions(-)include/hw/virtio/virtio-iommu.h +2
-0@@ -53,6 +53,8 @@ typedef struct VirtIOIOMMU {GHashTable *as_by_busptr;IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX ];PCIBus *primary_bus; +ReservedRegion *reserved_regions; +uint32_t nb_reserved_regions;GTree *domains;QemuMutex mutex;GTree *endpoints;hw/virtio/virtio-iommu.c +10
-0@@ -38,6 +38,7 @@/* Max size */ #define VIOMMU_DEFAULT_QUEUE_SIZE 256 +#define VIOMMU_PROBE_SIZE 512 typedef struct VirtIOIOMMUDomain { uint32_t id;@@ -378,6 +379,63 @@ static int virtio_iommu_unmap(VirtIOIOMMU *s,return ret; } +static ssize_t virtio_iommu_fill_resv_mem_prop (VirtIOIOMMU *s,uint32_t ep, +uint8_t *buf,size_t free) +{ +struct virtio_iommu_probe_resv_mem prop = {}; +size_t size =sizeof (prop), length = size -sizeof (prop.head), total; +int i; + + total = size * s->nb_reserved_regions; +hw/virtio/virtio-iommu.c static int virtio_iommu_unmap(VirtIOIOMMU *s, · line 400
Quoted 10 lines
hw/virtio/virtio-iommu.c +10
-0+if (total > free) { +return -ENOSPC ; + } + +for (i =0 ; i < s->nb_reserved_regions; i++) { + prop.head.type =cpu_to_le16 (VIRTIO_IOMMU_PROBE_T_RESV_MEM ); + prop.head.length =cpu_to_le16 (length); + prop.subtype = s->reserved_regions[i].type; +assert (prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_RESERVED || + prop.subtype ==VIRTIO_IOMMU_RESV_MEM_T_MSI );The assertion makes sense here: we're mapping from the generic ReservedRegion type (which is unsigned) to the specific
virtio_iommu_probe_resv_memsubtype (which isuint8_t, but only these two values are valid).Quoted 8 lines
Quoted 2 lines
Howver, the assertion should test s->reserved_regions[i].type and go before the assignment, to ensure it doesn't truncate!
OK I will do.
Quoted 3 lines
Can I trigger the assertion with -device? My try to find the answer myself failed:
At the moment the virtio-iommu-pci device only can be instantiated with machvirt, booting in dt mode.
Quoted 6 lines
I asked because if I can, then invalid types need to be rejected cleanly.
Invalid property values can be rejected by the setter, or by the realize method. Since this setter by design accepts anything that fits into unsigned, it's realize.
OK. Then the place where I do the assert is not the right one as this will happen later. Probe request is triggered by the guest virtio-iommu driver.
Thanks
Eric
Quoted 3 lines
[...]
PATCH v5 3/5 virtio-iommu: Handle reserved regions in the 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.
---
v1 -> v2:
- use addr when testing addr belongs to the reserved region and use a block local variable
--- hw/virtio/virtio-iommu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
hw/virtio/virtio-iommu.c +20 -0
@@ -605,6 +605,7 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,uint32_t sid, flags;bool bypass_allowed;bool found; +int i; interval.low = addr; interval.high = addr +1 ;
@@ -638,6 +639,25 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr, goto unlock; } +for (i =0 ; i < s->nb_reserved_regions; i++) { +ReservedRegion *reg = &s->reserved_regions[i]; + +if (addr >= reg->low && addr <= reg->high) { +switch (reg->type) { +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 , +VIRTIO_IOMMU_FAULT_F_ADDRESS , + sid, addr); +break ; + } + goto unlock; + } + } +if (!ep->domain) {if (!bypass_allowed) { error_report_once("%s %02x:%02x.%01x not attached to any domain",
Signature · 1 line
2.20.1
PATCH v5 4/5 virtio-iommu-pci: Add array of Interval properties
In reply to Eric AugerThe machine may need to pass reserved regions to the virtio-iommu-pci device (such as the MSI window on x86 or the MSI doorbells on ARM).
So let's add an array of Interval properties.
Note: if some reserved regions are already set by the machine code - which should be the case in general -, the length of the property array is already set and prevents the end-user from modifying them. For example, attempting to use:
-device virtio-iommu-pci,\
len-reserved-regions=1,reserved-regions[0]=0xfee00000:0xfeefffff:1
would result in the following error message:
-device virtio-iommu-pci,len-reserved-regions=1,len-reserved-regions=1,
reserved-regions[0]=0xfee00000:0xfeefffff:1: array size property len-reserved-regions may not be set more than once
Otherwise, for example, adding two reserved regions is achieved using the following options:
-device virtio-iommu-pci,addr=0xa,len-reserved-regions=2,\
reserved-regions[0]=0xfee00000:0xfeefffff:1,\
reserved-regions[1]=0x1000000:100ffff:1
---
v3 -> v4:
- added examples in the commit message as suggested by Markus
- added Jean's R-b
--- hw/virtio/virtio-iommu-pci.c | 3 +++ 1 file changed, 3 insertions(+)
hw/virtio/virtio-iommu-pci.c +3 -0
@@ -33,6 +33,9 @@ struct VirtIOIOMMUPCI {static Property virtio_iommu_pci_properties[] = {DEFINE_PROP_UINT32 ("class" , VirtIOPCIProxy, class_code,0 ), +DEFINE_PROP_ARRAY ("reserved-regions" , VirtIOIOMMUPCI, + vdev.nb_reserved_regions, vdev.reserved_regions, + qdev_prop_reserved_region, ReservedRegion),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
2.20.1
PATCH v5 5/5 hw/arm/virt: Let the virtio-iommu bypass MSIs
In reply to Eric AugerAt the moment the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. The virt machine code knows where the guest MSI doorbells are so we can easily declare those regions as VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest will not map MSIs through the IOMMU and those transactions will be simply bypassed.
Depending on which MSI controller is in use (ITS or GICV2M), we declare either:
- the ITS interrupt translation space (ITS_base + 0x10000), containing the GITS_TRANSLATOR or
- The GICV2M single frame, containing the MSI_SETSP_NS register.
---
v3 -> v4:
- use ':' as separators
v2 -> v3:
- Add a new value to VirtMSIControllerType
v1 -> v2:
- Test which MSI controller is instantiated
- If GICV2M is in use, declare its doorbell as an MSI doorbell too
--- include/hw/arm/virt.h | 7 +++++++ hw/arm/virt.c | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+)
include/hw/arm/virt.h +7 -0
@@ -96,6 +96,12 @@ typedef enum VirtIOMMUType {VIRT_IOMMU_VIRTIO , } VirtIOMMUType; +typedef enum VirtMSIControllerType { +VIRT_MSI_CTRL_NONE , +VIRT_MSI_CTRL_GICV2M , +VIRT_MSI_CTRL_ITS , +}VirtMSIControllerType ; + typedef enum VirtGICType { VIRT_GIC_VERSION_MAX, VIRT_GIC_VERSION_HOST,
@@ -136,6 +142,7 @@ typedef struct {OnOffAuto acpi;VirtGICType gic_version;VirtIOMMUType iommu; +VirtMSIControllerType msi_controller;uint16_t virtio_iommu_bdf;struct arm_boot_info bootinfo;MemMapEntry *memmap;
hw/arm/virt.c +18 -0
@@ -602,6 +602,7 @@ static void create_its(VirtMachineState *vms)sysbus_mmio_map (SYS_BUS_DEVICE (dev),0 , vms->memmap[VIRT_GIC_ITS ].base);fdt_add_its_gic_node (vms); + vms->msi_controller =VIRT_MSI_CTRL_ITS ; }static void create_v2m (VirtMachineState *vms)
@@ -622,6 +623,7 @@ static void create_v2m(VirtMachineState *vms) }fdt_add_v2m_gic_node (vms); + vms->msi_controller =VIRT_MSI_CTRL_GICV2M ; }static void create_gic (VirtMachineState *vms)
@@ -2149,8 +2151,24 @@ out:static void virt_machine_device_pre_plug_cb (HotplugHandler *hotplug_dev,DeviceState *dev,Error **errp) { +VirtMachineState *vms =VIRT_MACHINE (hotplug_dev); +if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {virt_memory_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +/* we declare a VIRTIO_IOMMU_RESV_MEM_T_MSI region */ + +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) { +/* GITS_TRANSLATER page */ +qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 ); +qdev_prop_set_string (dev,"reserved-regions[0]" , +"0x8090000:0x809FFFF:1" ); + }else if (vms->msi_controller ==VIRT_MSI_CTRL_GICV2M ) { +/* MSI_SETSPI_NS page */ +qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 ); +qdev_prop_set_string (dev,"reserved-regions[0]" , +"0x8020000:0x8020FFF:1" ); + } } }
Signature · 1 line
2.20.1
Re: [PATCH v5 5/5] hw/arm/virt: Let the virtio-iommu bypass MSIs
Quoted 28 lines · Eric Auger
At the moment the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. The virt machine code knows where the guest MSI doorbells are so we can easily declare those regions as
VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest will not map MSIs through the IOMMU and those transactions will be simply bypassed.Depending on which MSI controller is in use (ITS or GICV2M), we declare either:
- the ITS interrupt translation space (ITS_base+0x10000), containing theGITS_TRANSLATORor
- The GICV2M single frame, containing theMSI_SETSP_NSregister.Signed-off-by Eric Auger <[email protected]>Reviewed-by Jean-Philippe Brucker <[email protected]>static void virt_machine_device_pre_plug_cb(HotplugHandler
*hotplug_dev,
DeviceState *dev, Error **errp)
{hw/arm/virt.c +5
-0+VirtMachineState *vms =VIRT_MACHINE (hotplug_dev); +if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {virt_memory_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +/* we declare a VIRTIO_IOMMU_RESV_MEM_T_MSI region */ +
hw/arm/virt.c out: · line 2170
Quoted 10 lines
hw/arm/virt.c +10
-0+if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) { +/* GITS_TRANSLATER page */ +qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 ); +qdev_prop_set_string (dev,"reserved-regions[0]" , +"0x8090000:0x809FFFF:1" ); + }else if (vms->msi_controller ==VIRT_MSI_CTRL_GICV2M ) { +/* MSI_SETSPI_NS page */ +qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 ); +qdev_prop_set_string (dev,"reserved-regions[0]" , +"0x8020000:0x8020FFF:1" );
This hardcodes addresses and lengths that are in the base_memmap[] array for VIRT_GIC_ITS and VIRT_GIC_V2M, so it's setting up a bear trap if we ever decide to move those. Could we construct the string from the base_memmap[] array entry values instead, please ?
thanks
-- PMM
Re: [PATCH v5 5/5] hw/arm/virt: Let the virtio-iommu bypass MSIs
Hi Peter,
Quoted 37 lines · Peter Maydell
Quoted 36 lines · Eric Auger
At the moment the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. The virt machine code knows where the guest MSI doorbells are so we can easily declare those regions as
VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest will not map MSIs through the IOMMU and those transactions will be simply bypassed.Depending on which MSI controller is in use (ITS or GICV2M), we declare either:
- the ITS interrupt translation space (ITS_base+0x10000), containing theGITS_TRANSLATORor
- The GICV2M single frame, containing theMSI_SETSP_NSregister.Signed-off-by Eric Auger <[email protected]>Reviewed-by Jean-Philippe Brucker <[email protected]>static void virt_machine_device_pre_plug_cb(HotplugHandler
*hotplug_dev,
DeviceState *dev, Error **errp)
{hw/arm/virt.c +13
-0+VirtMachineState *vms =VIRT_MACHINE (hotplug_dev); +if (object_dynamic_cast (OBJECT (dev),TYPE_PC_DIMM )) {virt_memory_pre_plug (hotplug_dev, dev, errp); + }else if (object_dynamic_cast (OBJECT (dev),TYPE_VIRTIO_IOMMU_PCI )) { +/* we declare a VIRTIO_IOMMU_RESV_MEM_T_MSI region */ + +if (vms->msi_controller ==VIRT_MSI_CTRL_ITS ) { +/* GITS_TRANSLATER page */ +qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 ); +qdev_prop_set_string (dev,"reserved-regions[0]" , +"0x8090000:0x809FFFF:1" ); + }else if (vms->msi_controller ==VIRT_MSI_CTRL_GICV2M ) { +/* MSI_SETSPI_NS page */ +qdev_prop_set_uint32 (dev,"len-reserved-regions" ,1 );
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ qdev_prop_set_string(dev, "reserved-regions[0]", + "0x8020000:0x8020FFF:1");This hardcodes addresses and lengths that are in the base_memmap[] array for
VIRT_GIC_ITSandVIRT_GIC_V2M, so it's setting up a bear trap if we ever decide to move those. Could we construct the string from the base_memmap[] array entry values instead, please ?
Sure
Eric
Quoted 4 lines
thanks
-- PMM
Quoted 7 lines · Eric Auger
By default the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. However the virt machine code knows where the MSI doorbells are, so we can easily declare those regions as
VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest iommu subsystem will not need to map MSIs. This setup will simplify the VFIO integration.
Quoted 8 lines
In this series, the ITS or GICV2M doorbells are declared as HW MSI regions to be bypassed by the VIRTIO-IOMMU.
This also paves the way to the x86 integration where the MSI region, [0xFEE00000,0xFEEFFFFF], will be exposed by the q35 machine. However this will be handled in a separate series when not-DT support gets resolved.
What's going on with that btw?
I think the next step is to put the spec up for virtio tc vote, then we can merge that, right? acpi parts will need to be ratified by the acpi sig.
Quoted 59 lines
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v5.0.0-virtio-iommu-msi-bypass-v5History:
v4 -> v5:
- Take into account some additional comments from Markus:
- reserved region type becomes an unsigned + some comment/desc rewording
- assert if the type is not RESERVED or MSIv3 -> v4:
- collected Jean and markus's R-bs
- tool into account all Markus' comments in [1/5] (except removal of goto)
- use ':' as delimitor instead of commas
- add example in 4/5 commit message as suggested by Markusv2 -> v3:
- IntroduceVIRT_MSI_CTRL_NONEin VirtMSIControllerType
- do not fill the remainder of the probe bufferv1 -> v2:
- check which MSI controller is in use and advertise the corresponding MSI doorbell
- managed for both ITS and GICv2M
- various fixes spotted by Peter and Jean-Philippe, see individual logsv1: Most of those patches were respinned from
[PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device
except the last one which is newEric Auger (5):
qdev: IntroduceDEFINE_PROP_RESERVED_REGION
virtio-iommu: ImplementRESV_MEMprobe request
virtio-iommu: Handle reserved regions in the translation process
virtio-iommu-pci: Add array of Interval properties hw/arm/virt: Let the virtio-iommu bypass MSIsinclude/exec/memory.h | 6 ++ include/hw/arm/virt.h | 7 ++ include/hw/qdev-properties.h | 3 + include/hw/virtio/virtio-iommu.h | 2 + include/qemu/typedefs.h | 1 + hw/arm/virt.c | 18 +++++ hw/core/qdev-properties.c | 89 ++++++++++++++++++++++++ hw/virtio/virtio-iommu-pci.c | 3 + hw/virtio/virtio-iommu.c | 112 +++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 10 files changed, 238 insertions(+), 4 deletions(-)Signature · 1 line
2.20.1
Quoted 17 lines · Michael S. Tsirkin
Quoted 7 lines · Eric Auger
By default the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. However the virt machine code knows where the MSI doorbells are, so we can easily declare those regions as
VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest iommu subsystem will not need to map MSIs. This setup will simplify the VFIO integration.Quoted 8 lines
In this series, the ITS or GICV2M doorbells are declared as HW MSI regions to be bypassed by the VIRTIO-IOMMU.
This also paves the way to the x86 integration where the MSI region, [0xFEE00000,0xFEEFFFFF], will be exposed by the q35 machine. However this will be handled in a separate series when not-DT support gets resolved.
Quoted 4 lines
What's going on with that btw?
I think the next step is to put the spec up for virtio tc vote, then we can merge that, right? acpi parts will need to be ratified by the acpi sig.
Yes I'm being unreasonably slow on this. I'll look at both the virtio spec and ACPI after coming back from Holiday in July. I'm afraid the situation for the built-in description will be the same on the Linux side (asked to use ACPI instead), but it's worth retrying as we have some progress on ACPI support.
Thanks,
Jean
Quoted 61 lines
Quoted 60 lines
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v5.0.0-virtio-iommu-msi-bypass-v5History:
v4 -> v5:
- Take into account some additional comments from Markus:
- reserved region type becomes an unsigned + some comment/desc rewording
- assert if the type is not RESERVED or MSIv3 -> v4:
- collected Jean and markus's R-bs
- tool into account all Markus' comments in [1/5] (except removal of goto)
- use ':' as delimitor instead of commas
- add example in 4/5 commit message as suggested by Markusv2 -> v3:
- IntroduceVIRT_MSI_CTRL_NONEin VirtMSIControllerType
- do not fill the remainder of the probe bufferv1 -> v2:
- check which MSI controller is in use and advertise the corresponding MSI doorbell
- managed for both ITS and GICv2M
- various fixes spotted by Peter and Jean-Philippe, see individual logsv1: Most of those patches were respinned from
[PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device
except the last one which is newEric Auger (5):
qdev: IntroduceDEFINE_PROP_RESERVED_REGION
virtio-iommu: ImplementRESV_MEMprobe request
virtio-iommu: Handle reserved regions in the translation process
virtio-iommu-pci: Add array of Interval properties hw/arm/virt: Let the virtio-iommu bypass MSIsinclude/exec/memory.h | 6 ++ include/hw/arm/virt.h | 7 ++ include/hw/qdev-properties.h | 3 + include/hw/virtio/virtio-iommu.h | 2 + include/qemu/typedefs.h | 1 + hw/arm/virt.c | 18 +++++ hw/core/qdev-properties.c | 89 ++++++++++++++++++++++++ hw/virtio/virtio-iommu-pci.c | 3 + hw/virtio/virtio-iommu.c | 112 +++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 10 files changed, 238 insertions(+), 4 deletions(-)Signature · 1 line
2.20.1
Quoted 10 lines · Eric Auger
By default the virtio-iommu translates MSI transactions. This behavior is inherited from ARM SMMU. However the virt machine code knows where the MSI doorbells are, so we can easily declare those regions as
VIRTIO_IOMMU_RESV_MEM_T_MSI. With that setting the guest iommu subsystem will not need to map MSIs. This setup will simplify the VFIO integration.In this series, the ITS or GICV2M doorbells are declared as HW MSI regions to be bypassed by the VIRTIO-IOMMU.
Quoted 8 lines
This also paves the way to the x86 integration where the MSI region, [0xFEE00000,0xFEEFFFFF], will be exposed by the q35 machine. However this will be handled in a separate series when not-DT support gets resolved.
Best Regards
Eric
Virtio bits look OK:
Who's merging this? ARM tree?
Quoted 55 lines
This series can be found at:
https://github.com/eauger/qemu/tree/v5.0.0-virtio-iommu-msi-bypass-v5History:
v4 -> v5:
- Take into account some additional comments from Markus:
- reserved region type becomes an unsigned + some comment/desc rewording
- assert if the type is not RESERVED or MSIv3 -> v4:
- collected Jean and markus's R-bs
- tool into account all Markus' comments in [1/5] (except removal of goto)
- use ':' as delimitor instead of commas
- add example in 4/5 commit message as suggested by Markusv2 -> v3:
- IntroduceVIRT_MSI_CTRL_NONEin VirtMSIControllerType
- do not fill the remainder of the probe bufferv1 -> v2:
- check which MSI controller is in use and advertise the corresponding MSI doorbell
- managed for both ITS and GICv2M
- various fixes spotted by Peter and Jean-Philippe, see individual logsv1: Most of those patches were respinned from
[PATCH for-5.0 v11 00/20] VIRTIO-IOMMU device
except the last one which is newEric Auger (5):
qdev: IntroduceDEFINE_PROP_RESERVED_REGION
virtio-iommu: ImplementRESV_MEMprobe request
virtio-iommu: Handle reserved regions in the translation process
virtio-iommu-pci: Add array of Interval properties hw/arm/virt: Let the virtio-iommu bypass MSIsinclude/exec/memory.h | 6 ++ include/hw/arm/virt.h | 7 ++ include/hw/qdev-properties.h | 3 + include/hw/virtio/virtio-iommu.h | 2 + include/qemu/typedefs.h | 1 + hw/arm/virt.c | 18 +++++ hw/core/qdev-properties.c | 89 ++++++++++++++++++++++++ hw/virtio/virtio-iommu-pci.c | 3 + hw/virtio/virtio-iommu.c | 112 +++++++++++++++++++++++++++++-- hw/virtio/trace-events | 1 + 10 files changed, 238 insertions(+), 4 deletions(-)Signature · 1 line
2.20.1
Quoted 3 lines · Michael S. Tsirkin
Virtio bits look OK:
Reviewed-by Michael S. Tsirkin <[email protected]>
I can take it via the arm tree once it's ready. I had a comment on patch 5 and it looks like Markus had a question about patch 2, though.
thanks
-- PMM