From: Thomas Huth Date: Wed, 2 Aug 2023 13:57:18 +0000 (+0200) Subject: hw/i386/intel_iommu: Fix trivial endianness problems X-Git-Tag: qemu-xen-4.18.0-rc5~15 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bc5740e1783ceb14897548bbc5250e62ea0549d5;p=qemu-xen.git hw/i386/intel_iommu: Fix trivial endianness problems After reading the guest memory with dma_memory_read(), we have to make sure that we byteswap the little endian data to the host's byte order. Signed-off-by: Thomas Huth Message-Id: <20230802135723.178083-2-thuth@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Peter Xu (cherry picked from commit cc2a08480e19007c05be8fe5b6893e20448954dc) Signed-off-by: Michael Tokarev --- diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index a62896759c..255a881ad0 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -755,6 +755,8 @@ static int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, return -VTD_FR_PASID_TABLE_INV; } + pdire->val = le64_to_cpu(pdire->val); + return 0; } @@ -779,6 +781,9 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, pe, entry_size, MEMTXATTRS_UNSPECIFIED)) { return -VTD_FR_PASID_TABLE_INV; } + for (size_t i = 0; i < ARRAY_SIZE(pe->val); i++) { + pe->val[i] = le64_to_cpu(pe->val[i]); + } /* Do translation type check */ if (!vtd_pe_type_check(x86_iommu, pe)) {