diff mbox series

[v3,08/15] vfio/common: Relax vIOMMU detection when DMA translation is off

Message ID 20230530175937.24202-9-joao.m.martins@oracle.com (mailing list archive)
State New, archived
Headers show
Series vfio: VFIO migration support with vIOMMU | expand

Commit Message

Joao Martins May 30, 2023, 5:59 p.m. UTC
Relax the vIOMMU migration blocker when the underlying IOMMU reports that
DMA translation disabled. When it is disabled there will be no DMA mappings
via the vIOMMU and the guest only uses it for Interrupt Remapping.

The latter is done via the vfio_viommu_preset() return value whereby in
addition to validating that the address space is memory, we also check
whether the IOMMU MR has DMA translation on. Assume it is enabled if
there's no IOMMU MR or if no dma-translation property is supported.

Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 hw/vfio/common.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé May 30, 2023, 9:39 p.m. UTC | #1
On 30/5/23 19:59, Joao Martins wrote:
> Relax the vIOMMU migration blocker when the underlying IOMMU reports that
> DMA translation disabled. When it is disabled there will be no DMA mappings
> via the vIOMMU and the guest only uses it for Interrupt Remapping.
> 
> The latter is done via the vfio_viommu_preset() return value whereby in
> addition to validating that the address space is memory, we also check
> whether the IOMMU MR has DMA translation on.

> Assume it is enabled if
> there's no IOMMU MR or if no dma-translation property is supported.

This comment ^ ...

> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
>   hw/vfio/common.c | 22 +++++++++++++++++++++-
>   1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index fa8fd949b1cf..060acccb3443 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -414,12 +414,32 @@ void vfio_unblock_multiple_devices_migration(void)
>       multiple_devices_migration_blocker = NULL;
>   }
>   
> +static bool vfio_viommu_dma_translation_enabled(VFIOAddressSpace *space)
> +{
> +    bool enabled = false;
> +    int ret;
> +
> +    if (!space->iommu_mr) {
> +        return true;
> +    }
> +
> +    ret = memory_region_iommu_get_attr(space->iommu_mr,
> +                                       IOMMU_ATTR_DMA_TRANSLATION,
> +                                       &enabled);
> +    if (ret || enabled) {

... could be helpful if duplicated here.

> +        return true;
> +    }
> +
> +    return false;
> +}
Joao Martins May 31, 2023, 9:39 a.m. UTC | #2
On 30/05/2023 22:39, Philippe Mathieu-Daudé wrote:
> On 30/5/23 19:59, Joao Martins wrote:
>> Relax the vIOMMU migration blocker when the underlying IOMMU reports that
>> DMA translation disabled. When it is disabled there will be no DMA mappings
>> via the vIOMMU and the guest only uses it for Interrupt Remapping.
>>
>> The latter is done via the vfio_viommu_preset() return value whereby in
>> addition to validating that the address space is memory, we also check
>> whether the IOMMU MR has DMA translation on.
> 
>> Assume it is enabled if
>> there's no IOMMU MR or if no dma-translation property is supported.
> 
> This comment ^ ...
> 
>> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
>> ---
>>   hw/vfio/common.c | 22 +++++++++++++++++++++-
>>   1 file changed, 21 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
>> index fa8fd949b1cf..060acccb3443 100644
>> --- a/hw/vfio/common.c
>> +++ b/hw/vfio/common.c
>> @@ -414,12 +414,32 @@ void vfio_unblock_multiple_devices_migration(void)
>>       multiple_devices_migration_blocker = NULL;
>>   }
>>   +static bool vfio_viommu_dma_translation_enabled(VFIOAddressSpace *space)
>> +{
>> +    bool enabled = false;
>> +    int ret;
>> +
>> +    if (!space->iommu_mr) {
>> +        return true;
>> +    }
>> +
>> +    ret = memory_region_iommu_get_attr(space->iommu_mr,
>> +                                       IOMMU_ATTR_DMA_TRANSLATION,
>> +                                       &enabled);
>> +    if (ret || enabled) {
> 
> ... could be helpful if duplicated here.
> 

I'll add it.

>> +        return true;
>> +    }
>> +
>> +    return false;
>> +}
>
diff mbox series

Patch

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index fa8fd949b1cf..060acccb3443 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -414,12 +414,32 @@  void vfio_unblock_multiple_devices_migration(void)
     multiple_devices_migration_blocker = NULL;
 }
 
+static bool vfio_viommu_dma_translation_enabled(VFIOAddressSpace *space)
+{
+    bool enabled = false;
+    int ret;
+
+    if (!space->iommu_mr) {
+        return true;
+    }
+
+    ret = memory_region_iommu_get_attr(space->iommu_mr,
+                                       IOMMU_ATTR_DMA_TRANSLATION,
+                                       &enabled);
+    if (ret || enabled) {
+        return true;
+    }
+
+    return false;
+}
+
 static bool vfio_viommu_preset(void)
 {
     VFIOAddressSpace *space;
 
     QLIST_FOREACH(space, &vfio_address_spaces, list) {
-        if (space->as != &address_space_memory) {
+        if ((space->as != &address_space_memory) &&
+            vfio_viommu_dma_translation_enabled(space)) {
             return true;
         }
     }