OSDN Git Service

amd_iommu: Fix pte_override_page_mask()
authorJean-Philippe Brucker <jean-philippe@linaro.org>
Wed, 21 Apr 2021 08:40:08 +0000 (10:40 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 4 May 2021 11:27:37 +0000 (07:27 -0400)
commit5d31e1e59a21bafb57842313dd41f0b0ff11a4ff
treed9bf28e73e55b74bfeca019aefe3e21d700279d6
parent609d7596524ab204ccd71ef42c9eee4c7c338ea4
amd_iommu: Fix pte_override_page_mask()

AMD IOMMU PTEs have a special mode allowing to specify an arbitrary page
size. Quoting the AMD IOMMU specification: "When the Next Level bits [of
a pte] are 7h, the size of the page is determined by the first zero bit
in the page address, starting from bit 12."

So if the lowest bits of the page address is 0, the page is 8kB. If the
lowest bits are 011, the page is 32kB. Currently pte_override_page_mask()
doesn't compute the right value for this page size and amdvi_translate()
can return the wrong guest-physical address. With a Linux guest, DMA
from SATA devices accesses the wrong memory and causes probe failure:

qemu-system-x86_64 ... -device amd-iommu -drive id=hd1,file=foo.bin,if=none \
-device ahci,id=ahci -device ide-hd,drive=hd1,bus=ahci.0
[    6.613093] ata1.00: qc timeout (cmd 0xec)
[    6.615062] ata1.00: failed to IDENTIFY (I/O error, err_mask=0x4)

Fix the page mask.

Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Message-Id: <20210421084007.1190546-1-jean-philippe@linaro.org>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
hw/i386/amd_iommu.c