[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/16] amd_iommu: Fix pte_override_page_mask()
From: |
Michael S. Tsirkin |
Subject: |
[PULL 01/16] amd_iommu: Fix pte_override_page_mask() |
Date: |
Fri, 14 May 2021 12:04:08 -0400 |
From: Jean-Philippe Brucker <jean-philippe@linaro.org>
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 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
index 74a93a5d93..43b6e9bf51 100644
--- a/hw/i386/amd_iommu.c
+++ b/hw/i386/amd_iommu.c
@@ -860,8 +860,8 @@ static inline uint8_t get_pte_translation_mode(uint64_t pte)
static inline uint64_t pte_override_page_mask(uint64_t pte)
{
- uint8_t page_mask = 12;
- uint64_t addr = (pte & AMDVI_DEV_PT_ROOT_MASK) ^ AMDVI_DEV_PT_ROOT_MASK;
+ uint8_t page_mask = 13;
+ uint64_t addr = (pte & AMDVI_DEV_PT_ROOT_MASK) >> 12;
/* find the first zero bit */
while (addr & 1) {
page_mask++;
--
MST
- [PULL 00/16] pc,pci,virtio: bugfixes, improvements, Michael S. Tsirkin, 2021/05/14
- [PULL 01/16] amd_iommu: Fix pte_override_page_mask(),
Michael S. Tsirkin <=
- [PULL 03/16] hw/virtio: Pass virtio_feature_get_config_size() a const argument, Michael S. Tsirkin, 2021/05/14
- [PULL 04/16] virtio-blk: Constify VirtIOFeature feature_sizes[], Michael S. Tsirkin, 2021/05/14
- [PULL 05/16] virtio-net: Constify VirtIOFeature feature_sizes[], Michael S. Tsirkin, 2021/05/14
- [PULL 07/16] pc-dimm: remove unnecessary get_vmstate_memory_region() method, Michael S. Tsirkin, 2021/05/14
- [PULL 08/16] virtio-blk: Fix rollback path in virtio_blk_data_plane_start(), Michael S. Tsirkin, 2021/05/14
- [PULL 09/16] virtio-blk: Configure all host notifiers in a single MR transaction, Michael S. Tsirkin, 2021/05/14
- [PULL 10/16] virtio-scsi: Set host notifiers and callbacks separately, Michael S. Tsirkin, 2021/05/14
- [PULL 11/16] virtio-scsi: Configure all host notifiers in a single MR transaction, Michael S. Tsirkin, 2021/05/14
- [PULL 12/16] checkpatch: Fix use of uninitialized value, Michael S. Tsirkin, 2021/05/14
- [PULL 15/16] vhost-vdpa: Make vhost_vdpa_get_device_id() static, Michael S. Tsirkin, 2021/05/14