amd_iommu: Fixes
v3 cover amd_iommu: Fixes
Fix following two issues in the amd viommu
1. The guest fails to setup the passthrough device when for following setup because amd iommu enables the no DMA memory region even when guest is using DMA remapping mode.
-device amd-iommu,intremap=on,xtsup=on,pt=on \
-device vfio-pci,host=<DEVID> \
and guest forcing DMA remap mode e.g. 'iommu.passthrough=0'
which will cause failures from QEMU:
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
2. The guest fails to boot with xtsup=on and <= 255 vCPUs, because amd_iommu does not enable x2apic mode.
base commit 56c6e249b6988c1b6edc2dd34ebb0f1e570a1365 (v10.0.0-rc3)
Sairaj Kodilkar (1):
hw/i386/amd_iommu: Fix device setup failure when PT is on.
Vasant Hegde (1):
hw/i386/amd_iommu: Fix xtsup when vcpus < 255
hw/i386/amd_iommu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/2 hw/i386/amd_iommu: Fix device setup failure when PT is on.
Commit c1f46999ef506 ("amd_iommu: Add support for pass though mode") introduces the support for "pt" flag by enabling nodma memory when "pt=off". This allowed VFIO devices to successfully register notifiers by using nodma region.
But, This also broke things when guest is booted with the iommu=nopt because, devices bypass the IOMMU and use untranslated addresses (IOVA) to perform DMA reads/writes to the nodma memory region, ultimately resulting in a failure to setup the devices in the guest.
Fix the above issue by always enabling the amdvi_dev_as->iommu memory region. But this will once again cause VFIO devices to fail while registering the notifiers with AMD IOMMU memory region.
--- hw/i386/amd_iommu.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
hw/i386/amd_iommu.c +2 -10
@@ -1426,7 +1426,6 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)AMDVIState *s = opaque;AMDVIAddressSpace **iommu_as, *amdvi_dev_as;int bus_num =pci_bus_num (bus); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s); iommu_as = s->address_spaces[bus_num];
@@ -1486,15 +1485,8 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)AMDVI_INT_ADDR_FIRST , &amdvi_dev_as->iommu_ir, 1); -if (!x86_iommu->pt_supported) { -memory_region_set_enabled (&amdvi_dev_as->iommu_nodma, false); -memory_region_set_enabled (MEMORY_REGION (&amdvi_dev_as->iommu), - true); - }else { -memory_region_set_enabled (MEMORY_REGION (&amdvi_dev_as->iommu), - false); -memory_region_set_enabled (&amdvi_dev_as->iommu_nodma, true); - } +memory_region_set_enabled (&amdvi_dev_as->iommu_nodma, false); +memory_region_set_enabled (MEMORY_REGION (&amdvi_dev_as->iommu), true); }return &iommu_as[devfn]->as; }
Signature · 1 line
2.34.1
Re: [PATCH v3 1/2] hw/i386/amd_iommu: Fix device setup failure when PT is on.
Quoted 37 lines · Sairaj Kodilkar
Commit
c1f46999ef506("amd_iommu: Add support for pass though mode") introduces the support for "pt" flag by enabling nodma memory when "pt=off". This allowed VFIO devices to successfully register notifiers by using nodma region.But, This also broke things when guest is booted with the iommu=nopt because, devices bypass the IOMMU and use untranslated addresses (IOVA) to perform DMA reads/writes to the nodma memory region, ultimately resulting in a failure to setup the devices in the guest.
Fix the above issue by always enabling the
amdvi_dev_as->iommumemory region. But this will once again cause VFIO devices to fail while registering the notifiers with AMD IOMMU memory region.Fixes c1f46999ef506 ("amd_iommu: Add support for pass though mode")Signed-off-by Sairaj Kodilkar <[email protected]>Reviewed-by Vasant Hegde <[email protected]>--- hw/i386/amd_iommu.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)hw/i386/amd_iommu.c +0
-1@@ -1426,7 +1426,6 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)AMDVIState *s = opaque;AMDVIAddressSpace **iommu_as, *amdvi_dev_as;int bus_num =pci_bus_num (bus); -X86IOMMUState *x86_iommu =X86_IOMMU_DEVICE (s); iommu_as = s->address_spaces[bus_num];@@ -1486,15 +1485,8 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn)AMDVI_INT_ADDR_FIRST , &amdvi_dev_as->iommu_ir, 1);
hw/i386/amd_iommu.c static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) · line 1488
Quoted 10 lines
hw/i386/amd_iommu.c +1
-9-if (!x86_iommu->pt_supported) { -memory_region_set_enabled (&amdvi_dev_as->iommu_nodma, false); -memory_region_set_enabled (MEMORY_REGION (&amdvi_dev_as->iommu), - true); - }else { -memory_region_set_enabled (MEMORY_REGION (&amdvi_dev_as->iommu), - false); -memory_region_set_enabled (&amdvi_dev_as->iommu_nodma, true); - } +memory_region_set_enabled (&amdvi_dev_as->iommu_nodma, false);
I have no clue about this device but wonder what is the usefulness of iommu_nodma now, isn't it dead code?
Quoted 4 lines
hw/i386/amd_iommu.c +1
-0+memory_region_set_enabled (MEMORY_REGION (&amdvi_dev_as->iommu), true); }return &iommu_as[devfn]->as; }
Re: [PATCH v3 1/2] hw/i386/amd_iommu: Fix device setup failure when PT is on.
Quoted 45 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Sairaj Kodilkar
Commit
c1f46999ef506("amd_iommu: Add support for pass though mode") introduces the support for "pt" flag by enabling nodma memory when "pt=off". This allowed VFIO devices to successfully register notifiers by using nodma region.But, This also broke things when guest is booted with the iommu=nopt because, devices bypass the IOMMU and use untranslated addresses (IOVA) to perform DMA reads/writes to the nodma memory region, ultimately resulting in a failure to setup the devices in the guest.
Fix the above issue by always enabling the
amdvi_dev_as->iommumemory region. But this will once again cause VFIO devices to fail while registering the notifiers with AMD IOMMU memory region.Fixes c1f46999ef506 ("amd_iommu: Add support for pass though mode")Signed-off-by Sairaj Kodilkar <[email protected]>Reviewed-by Vasant Hegde <[email protected]>---
hw/i386/amd_iommu.c| 12 ++----------1 file changed, 2 insertions(+), 10 deletions(-)hw/i386/amd_iommu.c +0
-7@@ -1426,7 +1426,6 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) AMDVIState *s = opaque; AMDVIAddressSpace **iommu_as, *amdvi_dev_as; int bus_num = pci_bus_num(bus); - X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(s); iommu_as = s->address_spaces[bus_num];@@ -1486,15 +1485,8 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) AMDVI_INT_ADDR_FIRST, &amdvi_dev_as->iommu_ir, 1); - if (!x86_iommu->pt_supported) { - memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, false); - memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as- >iommu), - true); - } else { - memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as-
Quoted 9 lines
hw/i386/amd_iommu.c static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) · line 1488
Quoted 5 lines
hw/i386/amd_iommu.c +1
-3>iommu), - false); - memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, true); - } + memory_region_set_enabled(&amdvi_dev_as->iommu_nodma, false);I have no clue about this device but wonder what is the usefulness of
iommu_nodmanow, isn't it dead code?
Hi Philippe,
Indeed the iommu_nodma is dead. The reason I did not remove the iommu_nodma region completely is that, Alejandro's DMA remapping patches
[1] uses this region to dynamically switch the address space.
[1] https://lore.kernel.org/qemu-devel/[email protected]/
Thanks
Sairaj
Quoted 6 lines
Quoted 5 lines
hw/i386/amd_iommu.c +1
-0+ memory_region_set_enabled(MEMORY_REGION(&amdvi_dev_as-Quoted 1 line
iommu), true);
}
return &iommu_as[devfn]->as;
}
PATCH v3 2/2 hw/i386/amd_iommu: Fix xtsup when vcpus < 255
In reply to Sairaj KodilkarFrom: Vasant Hegde <[email protected]>
If vCPUs > 255 then x86 common code (x86_cpus_init()) call kvm_enable_x2apic(). But if vCPUs <= 255 then the common code won't calls kvm_enable_x2apic().
This is because commit 8c6619f3e692 ("hw/i386/amd_iommu: Simplify non-KVM checks on XTSup feature") removed the call to kvm_enable_x2apic when xtsup is "on", which break things when guest is booted with x2apic mode and there are <= 255 vCPUs.
Fix this by adding back kvm_enable_x2apic() call when xtsup=on.
--- hw/i386/amd_iommu.c | 8 ++++++++ 1 file changed, 8 insertions(+)
hw/i386/amd_iommu.c +8 -0
@@ -1649,6 +1649,14 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)exit (EXIT_FAILURE ); } +if (s->xtsup) { +if (kvm_irqchip_is_split () && !kvm_enable_x2apic ()) { +error_report ("AMD IOMMU xtsup=on requires x2APIC support on " +"the KVM side" ); +exit (EXIT_FAILURE ); + } + } +pci_setup_iommu (bus, &amdvi_iommu_ops, s);amdvi_init (s); }
Signature · 1 line
2.34.1
Re: [PATCH v3 2/2] hw/i386/amd_iommu: Fix xtsup when vcpus < 255
Hi,
Quoted 28 lines · Sairaj Kodilkar
From: Vasant Hegde <[email protected]>
If vCPUs > 255 then x86 common code (
x86_cpus_init()) callkvm_enable_x2apic(). But if vCPUs <= 255 then the common code won't callskvm_enable_x2apic().This is because commit
8c6619f3e692("hw/i386/amd_iommu: Simplify non-KVM checks on XTSup feature") removed the call tokvm_enable_x2apicwhen xtsup is "on", which break things when guest is booted with x2apic mode and there are <= 255 vCPUs.Fix this by adding back
kvm_enable_x2apic()call when xtsup=on.Fixes 8c6619f3e692 ("hw/i386/amd_iommu: Simplify non-KVM checks on XTSup feature")Reported-by Alejandro Jimenez <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Joao Martins <[email protected]>Signed-off-by Vasant Hegde <[email protected]>Signed-off-by Sairaj Kodilkar <[email protected]>--- hw/i386/amd_iommu.c | 8 ++++++++ 1 file changed, 8 insertions(+)hw/i386/amd_iommu.c +0
-0
hw/i386/amd_iommu.c static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) · line 1652
Quoted 4 lines
hw/i386/amd_iommu.c +1
-0@@ -1649,6 +1649,14 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp)exit (EXIT_FAILURE ); } +if (s->xtsup) {
I suppose we need:
if (s->xtsup && kvm_enabled()) {otherwise that will trigger back the problem I tried to fix. Did you try building QEMU with KVM disabled?
Quoted 10 lines
hw/i386/amd_iommu.c +7
-0+if (kvm_irqchip_is_split () && !kvm_enable_x2apic ()) { +error_report ("AMD IOMMU xtsup=on requires x2APIC support on " +"the KVM side" ); +exit (EXIT_FAILURE ); + } + } +pci_setup_iommu (bus, &amdvi_iommu_ops, s);amdvi_init (s); }
Re: [PATCH v3 2/2] hw/i386/amd_iommu: Fix xtsup when vcpus < 255
Hi Philippe,
Quoted 39 lines · Philippe Mathieu-Daudé
Hi,
Quoted 29 lines · Sairaj Kodilkar
From: Vasant Hegde <[email protected]>
If vCPUs > 255 then x86 common code (
x86_cpus_init()) callkvm_enable_x2apic(). But if vCPUs <= 255 then the common code won't callskvm_enable_x2apic().This is because commit
8c6619f3e692("hw/i386/amd_iommu: Simplify non-KVM checks on XTSup feature") removed the call tokvm_enable_x2apicwhen xtsup is "on", which break things when guest is booted with x2apic mode and there are <= 255 vCPUs.Fix this by adding back
kvm_enable_x2apic()call when xtsup=on.Fixes 8c6619f3e692 ("hw/i386/amd_iommu: Simplify non-KVM checks on XTSupfeature")
Reported-by Alejandro Jimenez <[email protected]>Cc Philippe Mathieu-Daudé <[email protected]>Cc Joao Martins <[email protected]>Signed-off-by Vasant Hegde <[email protected]>Signed-off-by Sairaj Kodilkar <[email protected]>---
hw/i386/amd_iommu.c| 8 ++++++++1 file changed, 8 insertions(+)hw/i386/amd_iommu.c +0
-0hw/i386/amd_iommu.c static void amdvi_sysbus_realize(DeviceState *dev, · line 1652
Quoted 4 lines
hw/i386/amd_iommu.c +0
-0@@ -1649,6 +1649,14 @@ static void amdvi_sysbus_realize(DeviceState *dev, Error **errp) exit(EXIT_FAILURE); } + if (s->xtsup) {I suppose we need:
Quoted 4 lines
if (
s->xtsup&&kvm_enabled()) {otherwise that will trigger back the problem I tried to fix. Did you try building QEMU with KVM disabled?
My understanding is if KVM is disabled then kvm_irqchip_is_split() will return false and we exit on below condition check.
Yes. I had tried configure --disable-kvm and it was built fine.
-Vasant
Quoted 12 lines
Quoted 11 lines
hw/i386/amd_iommu.c +7
-0+ if (kvm_irqchip_is_split() && !kvm_enable_x2apic()) { + error_report("AMD IOMMU xtsup=on requires x2APIC support on " + "the KVM side"); + exit(EXIT_FAILURE); + } + } + pci_setup_iommu(bus, &amdvi_iommu_ops, s); amdvi_init(s);}
Quoted 24 lines · Sairaj Kodilkar
Fix following two issues in the amd viommu
1. The guest fails to setup the passthrough device when for following setup because amd iommu enables the no DMA memory region even when guest is using DMA remapping mode.-device amd-iommu,intremap=on,xtsup=on,pt=on \
-device vfio-pci,host=<DEVID> \and guest forcing DMA remap mode e.g. 'iommu.passthrough=0'
which will cause failures from QEMU:
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address2. The guest fails to boot with xtsup=on and <= 255 vCPUs, because
amd_iommudoes not enable x2apic mode.base commit
56c6e249b6988c1b6edc2dd34ebb0f1e570a1365(v10.0.0-rc3)
Quoted 8 lines
Sairaj Kodilkar (1):
hw/i386/amd_iommu: Fix device setup failure when PT is on.Vasant Hegde (1):
hw/i386/amd_iommu: Fix xtsup when vcpus < 255hw/i386/amd_iommu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
changelog?
Quoted 2 lines
Signature · 1 line
2.34.1
Quoted 28 lines · Michael S. Tsirkin
Quoted 27 lines · Sairaj Kodilkar
Fix following two issues in the amd viommu
1. The guest fails to setup the passthrough device when for following setup because amd iommu enables the no DMA memory region even when guest is using DMA remapping mode.-device amd-iommu,intremap=on,xtsup=on,pt=on \
-device vfio-pci,host=<DEVID> \and guest forcing DMA remap mode e.g. 'iommu.passthrough=0'
which will cause failures from QEMU:
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address2. The guest fails to boot with xtsup=on and <= 255 vCPUs, because
amd_iommudoes not enable x2apic mode.base commit
56c6e249b6988c1b6edc2dd34ebb0f1e570a1365(v10.0.0-rc3)Sairaj Kodilkar (1):
hw/i386/amd_iommu: Fix device setup failure when PT is on.
Quoted 8 lines
Quoted 5 lines
Vasant Hegde (1):
hw/i386/amd_iommu: Fix xtsup when vcpus < 255hw/i386/amd_iommu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)changelog?
Sorry I forgot to update the cover-letter (Rookie mistake).
Changes Since v2:
Patch 1: Updated commit message [mst]
Patch 2: Updated commit message [mst]
v2: https://lore.kernel.org/qemu-devel/[email protected]/
Changes Since v1:
Patch 1: Updated commit message [Alejandro]
Patch 2: None
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Regards
Sairaj Kodilkar
Quoted 3 lines
Quoted 2 lines
Signature · 1 line
2.34.1
Quoted 22 lines · Sairaj Kodilkar
Fix following two issues in the amd viommu
1. The guest fails to setup the passthrough device when for following setup because amd iommu enables the no DMA memory region even when guest is using DMA remapping mode.-device amd-iommu,intremap=on,xtsup=on,pt=on \
-device vfio-pci,host=<DEVID> \and guest forcing DMA remap mode e.g. 'iommu.passthrough=0'
which will cause failures from QEMU:
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address2. The guest fails to boot with xtsup=on and <= 255 vCPUs, because
amd_iommudoes not enable x2apic mode.
Quoted 7 lines
base commit
56c6e249b6988c1b6edc2dd34ebb0f1e570a1365(v10.0.0-rc3)Sairaj Kodilkar (1):
hw/i386/amd_iommu: Fix device setup failure when PT is on.Vasant Hegde (1):
hw/i386/amd_iommu: Fix xtsup when vcpus < 255
Hi!
Is this a qemu-stable material (for 10.0.x)?
Thanks,
/mjt
Quoted 28 lines · Michael Tokarev
Quoted 27 lines · Sairaj Kodilkar
Fix following two issues in the amd viommu
1. The guest fails to setup the passthrough device when for following setup because amd iommu enables the no DMA memory region even when guest is using DMA remapping mode.-device amd-iommu,intremap=on,xtsup=on,pt=on \
-device vfio-pci,host=<DEVID> \and guest forcing DMA remap mode e.g. 'iommu.passthrough=0'
which will cause failures from QEMU:
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address
qemu-system-x86_64: AHCI: Failed to start FIS receive engine: bad FIS receive buffer address
qemu-system-x86_64: AHCI: Failed to start DMA engine: bad command list buffer address2. The guest fails to boot with xtsup=on and <= 255 vCPUs, because
amd_iommudoes not enable x2apic mode.base commit
56c6e249b6988c1b6edc2dd34ebb0f1e570a1365(v10.0.0-rc3)Sairaj Kodilkar (1):
hw/i386/amd_iommu: Fix device setup failure when PT is on.
Quoted 6 lines
Quoted 2 lines
Vasant Hegde (1):
hw/i386/amd_iommu: Fix xtsup when vcpus < 255Hi!
Is this a qemu-stable material (for 10.0.x)?
Yes it is
Thanks
Sairaj Kodilkar