[PATCH for-8.1 0/6] Fix endianness issues in the intel-iommu device

Thomas Huth posted 6 patches 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20230802135723.178083-1-thuth@redhat.com
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Peter Xu <peterx@redhat.com>, Jason Wang <jasowang@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Michael Tokarev <mjt@tls.msk.ru>, Laurent Vivier <laurent@vivier.eu>
hw/i386/intel_iommu_internal.h |  9 ++++++
include/hw/i386/intel_iommu.h  | 50 ++++++++++++++++++----------------
include/hw/i386/x86-iommu.h    | 50 ++++++++++++++++++----------------
hw/i386/intel_iommu.c          | 23 ++++++++++------
hw/i386/x86-iommu.c            |  2 +-
5 files changed, 76 insertions(+), 58 deletions(-)
[PATCH for-8.1 0/6] Fix endianness issues in the intel-iommu device
Posted by Thomas Huth 9 months ago
The intel-iommu device is currently unusable on big endian hosts.
When doing something like this on a s390x host:

 wget https://download.fedoraproject.org/pub/fedora/linux/releases/38/Server/x86_64/images/Fedora-Server-KVM-38-1.6.x86_64.qcow2
 ./qemu-system-x86_64 -M q35 -device intel-iommu -m 2G \
        -hda ~/Fedora-Server-KVM-38-1.6.x86_64.qcow2 -trace "vtd_*"

... the guest kernel crashes during boot, complaining about some
problems with the iommu, and you can see clearly in the traces that
some values are wrong when compared to running this on a x86 host.

After spending quite some time hunting down the problems one by one,
I think I now found them all - at least I can successfully boot the
above kernel after I applied these patches.

Thomas Huth (6):
  hw/i386/intel_iommu: Fix trivial endianness problems
  hw/i386/intel_iommu: Fix endianness problems related to
    VTD_IR_TableEntry
  hw/i386/intel_iommu: Fix struct VTDInvDescIEC on big endian hosts
  hw/i386/intel_iommu: Fix index calculation in
    vtd_interrupt_remap_msi()
  hw/i386/x86-iommu: Fix endianness issue in
    x86_iommu_irq_to_msi_message()
  include/hw/i386/x86-iommu: Fix struct X86IOMMU_MSIMessage for big
    endian hosts

 hw/i386/intel_iommu_internal.h |  9 ++++++
 include/hw/i386/intel_iommu.h  | 50 ++++++++++++++++++----------------
 include/hw/i386/x86-iommu.h    | 50 ++++++++++++++++++----------------
 hw/i386/intel_iommu.c          | 23 ++++++++++------
 hw/i386/x86-iommu.c            |  2 +-
 5 files changed, 76 insertions(+), 58 deletions(-)

-- 
2.39.3
Re: [PATCH for-8.1 0/6] Fix endianness issues in the intel-iommu device
Posted by Michael S. Tsirkin 9 months ago
On Wed, Aug 02, 2023 at 03:57:17PM +0200, Thomas Huth wrote:
> The intel-iommu device is currently unusable on big endian hosts.
> When doing something like this on a s390x host:
> 
>  wget https://download.fedoraproject.org/pub/fedora/linux/releases/38/Server/x86_64/images/Fedora-Server-KVM-38-1.6.x86_64.qcow2
>  ./qemu-system-x86_64 -M q35 -device intel-iommu -m 2G \
>         -hda ~/Fedora-Server-KVM-38-1.6.x86_64.qcow2 -trace "vtd_*"
> 
> ... the guest kernel crashes during boot, complaining about some
> problems with the iommu, and you can see clearly in the traces that
> some values are wrong when compared to running this on a x86 host.
> 
> After spending quite some time hunting down the problems one by one,
> I think I now found them all - at least I can successfully boot the
> above kernel after I applied these patches.
> 
> Thomas Huth (6):
>   hw/i386/intel_iommu: Fix trivial endianness problems
>   hw/i386/intel_iommu: Fix endianness problems related to
>     VTD_IR_TableEntry
>   hw/i386/intel_iommu: Fix struct VTDInvDescIEC on big endian hosts
>   hw/i386/intel_iommu: Fix index calculation in
>     vtd_interrupt_remap_msi()
>   hw/i386/x86-iommu: Fix endianness issue in
>     x86_iommu_irq_to_msi_message()
>   include/hw/i386/x86-iommu: Fix struct X86IOMMU_MSIMessage for big
>     endian hosts
> 
>  hw/i386/intel_iommu_internal.h |  9 ++++++
>  include/hw/i386/intel_iommu.h  | 50 ++++++++++++++++++----------------
>  include/hw/i386/x86-iommu.h    | 50 ++++++++++++++++++----------------
>  hw/i386/intel_iommu.c          | 23 ++++++++++------
>  hw/i386/x86-iommu.c            |  2 +-
>  5 files changed, 76 insertions(+), 58 deletions(-)

I guess it's ok as a hack for 8.1. But we really need better
APIs. Annotating field endianness with __bitwise would be
a start.


> -- 
> 2.39.3
Re: [PATCH for-8.1 0/6] Fix endianness issues in the intel-iommu device
Posted by Peter Xu 9 months ago
On Wed, Aug 02, 2023 at 03:57:17PM +0200, Thomas Huth wrote:
> The intel-iommu device is currently unusable on big endian hosts.
> When doing something like this on a s390x host:
> 
>  wget https://download.fedoraproject.org/pub/fedora/linux/releases/38/Server/x86_64/images/Fedora-Server-KVM-38-1.6.x86_64.qcow2
>  ./qemu-system-x86_64 -M q35 -device intel-iommu -m 2G \
>         -hda ~/Fedora-Server-KVM-38-1.6.x86_64.qcow2 -trace "vtd_*"
> 
> ... the guest kernel crashes during boot, complaining about some
> problems with the iommu, and you can see clearly in the traces that
> some values are wrong when compared to running this on a x86 host.
> 
> After spending quite some time hunting down the problems one by one,
> I think I now found them all - at least I can successfully boot the
> above kernel after I applied these patches.
> 
> Thomas Huth (6):
>   hw/i386/intel_iommu: Fix trivial endianness problems
>   hw/i386/intel_iommu: Fix endianness problems related to
>     VTD_IR_TableEntry
>   hw/i386/intel_iommu: Fix struct VTDInvDescIEC on big endian hosts
>   hw/i386/intel_iommu: Fix index calculation in
>     vtd_interrupt_remap_msi()
>   hw/i386/x86-iommu: Fix endianness issue in
>     x86_iommu_irq_to_msi_message()
>   include/hw/i386/x86-iommu: Fix struct X86IOMMU_MSIMessage for big
>     endian hosts

All look right here. This was the 1st project I did after I worked on QEMU,
thanks again for fixing the issues for years!

Reviewed-by: Peter Xu <peterx@redhat.com>

This will need to be 8.2 material though, am I right?

Thanks,

-- 
Peter Xu