diff mbox series

[v3,04/10] hw/arm/virt: Reject instantiation of multiple IOMMUs

Message ID 20210914142004.2433568-5-jean-philippe@linaro.org
State New
Headers show
Series virtio-iommu: Add ACPI support | expand

Commit Message

Jean-Philippe Brucker Sept. 14, 2021, 2:19 p.m. UTC
We do not support instantiating multiple IOMMUs. Before adding a
virtio-iommu, check that no other IOMMU is present. This will detect
both "iommu=smmuv3" machine parameter and another virtio-iommu instance.

Fixes: 70e89132c9 ("hw/arm/virt: Add the virtio-iommu device tree mappings")
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>

---
 hw/arm/virt.c | 5 +++++
 1 file changed, 5 insertions(+)

-- 
2.33.0

Comments

Eric Auger Sept. 16, 2021, 12:45 p.m. UTC | #1
Hi Jean,

On 9/14/21 4:19 PM, Jean-Philippe Brucker wrote:
> We do not support instantiating multiple IOMMUs. Before adding a

> virtio-iommu, check that no other IOMMU is present. This will detect

> both "iommu=smmuv3" machine parameter and another virtio-iommu instance.

>

> Fixes: 70e89132c9 ("hw/arm/virt: Add the virtio-iommu device tree mappings")

> Reviewed-by: Eric Auger <eric.auger@redhat.com>

> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>

Tested-by: Eric Auger <eric.auger@redhat.com>


Eric
> ---

>  hw/arm/virt.c | 5 +++++

>  1 file changed, 5 insertions(+)

>

> diff --git a/hw/arm/virt.c b/hw/arm/virt.c

> index f238766aa1..26069f943a 100644

> --- a/hw/arm/virt.c

> +++ b/hw/arm/virt.c

> @@ -2471,6 +2471,11 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,

>      if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {

>          PCIDevice *pdev = PCI_DEVICE(dev);

>  

> +        if (vms->iommu != VIRT_IOMMU_NONE) {

> +            error_setg(errp, "virt machine does not support multiple IOMMUs");

> +            return;

> +        }

> +

>          vms->iommu = VIRT_IOMMU_VIRTIO;

>          vms->virtio_iommu_bdf = pci_get_bdf(pdev);

>          create_virtio_iommu_dt_bindings(vms);
Igor Mammedov Sept. 20, 2021, 8:11 a.m. UTC | #2
On Tue, 14 Sep 2021 15:19:59 +0100
Jean-Philippe Brucker <jean-philippe@linaro.org> wrote:

> We do not support instantiating multiple IOMMUs. Before adding a

> virtio-iommu, check that no other IOMMU is present. This will detect

> both "iommu=smmuv3" machine parameter and another virtio-iommu instance.

> 

> Fixes: 70e89132c9 ("hw/arm/virt: Add the virtio-iommu device tree mappings")

> Reviewed-by: Eric Auger <eric.auger@redhat.com>

> Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>

> ---

>  hw/arm/virt.c | 5 +++++

>  1 file changed, 5 insertions(+)

> 

> diff --git a/hw/arm/virt.c b/hw/arm/virt.c

> index f238766aa1..26069f943a 100644

> --- a/hw/arm/virt.c

> +++ b/hw/arm/virt.c

> @@ -2471,6 +2471,11 @@ static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,

>      if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {

>          PCIDevice *pdev = PCI_DEVICE(dev);

>  

> +        if (vms->iommu != VIRT_IOMMU_NONE) {

> +            error_setg(errp, "virt machine does not support multiple IOMMUs");

> +            return;

> +        }


can you move check into 'pre_plug' callback?

(plug should not fail and just finish up whatever was
verified/set by pre_plug, there are plans to remove errp
argument from 'plug' callback)
> +

>          vms->iommu = VIRT_IOMMU_VIRTIO;

>          vms->virtio_iommu_bdf = pci_get_bdf(pdev);

>          create_virtio_iommu_dt_bindings(vms);
diff mbox series

Patch

diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index f238766aa1..26069f943a 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -2471,6 +2471,11 @@  static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev,
     if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_IOMMU_PCI)) {
         PCIDevice *pdev = PCI_DEVICE(dev);
 
+        if (vms->iommu != VIRT_IOMMU_NONE) {
+            error_setg(errp, "virt machine does not support multiple IOMMUs");
+            return;
+        }
+
         vms->iommu = VIRT_IOMMU_VIRTIO;
         vms->virtio_iommu_bdf = pci_get_bdf(pdev);
         create_virtio_iommu_dt_bindings(vms);