On 02/08/2023 11.28, Thomas Huth wrote:
The code already tries to do some endianness handling here, but
currently fails badly:
- While it already swaps the data when logging errors / tracing, it fails
   to byteswap the value before e.g. accessing entry->irte.present
- entry->irte.source_id is swapped with le32_to_cpu(), though this is
   a 16-bit value
- The whole union is apparently supposed to be swapped via the 64-bit
   data[2] array, but the struct is a mixture between 32 bit values
   (the first 8 bytes) and 64 bit values (the second 8 bytes), so this
   cannot work as expected.

Fix it by converting the struct to two proper 64-bit bitfields, and
by swapping the values only once for everybody right after reading
the data from memory.

Signed-off-by: Thomas Huth <th...@redhat.com>
---
  Note: There are more endianness issues in the code, I haven't figured
        out all of them yet, Linux fails to boot in the guest when I use
        this device on a s390x host. But I wanted to publish this patch
        now already since this should also fix the "issue" with the Clang
        ms_struct packing that we recently discussed on the mailing list.

I just found the all remaining issues (I hope). I can now run a Linux guest with -device intel-iommu and it works without crashing now. I'll send out the patches shorty, after cleaning them up a little bit.

 Thomas



Reply via email to