
When running on a 64kB page size host and protecting a VFIO device with the virtio-iommu, qemu crashes with this kind of message: qemu-kvm: virtio-iommu page mask 0xfffffffffffff000 is incompatible with mask 0x20010000 qemu: hardware error: vfio: DMA mapping failed, unable to continue This is due to the fact the IOMMU MR corresponding to the VFIO device is enabled very late on domain attach, after the machine init. The device reports a minimal 64kB page size but it is too late to be applied. virtio_iommu_set_page_size_mask() fails and this causes vfio_listener_region_add() to end up with hw_error(); To work around this issue, we transiently enable the IOMMU MR on machine init to collect the page size requirements and then restore the bypass state. Fixes: 90519b9053 ("virtio-iommu: Add bypass mode support to assigned device") Signed-off-by: Eric Auger <eric.auger@redhat.com> Message-Id: <20230705165118.28194-2-eric.auger@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Tested-by: Jean-Philippe Brucker <jean-philippe@linaro.org> Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
69 lines
2.0 KiB
C
69 lines
2.0 KiB
C
/*
|
|
* virtio-iommu device
|
|
*
|
|
* Copyright (c) 2020 Red Hat, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#ifndef QEMU_VIRTIO_IOMMU_H
|
|
#define QEMU_VIRTIO_IOMMU_H
|
|
|
|
#include "standard-headers/linux/virtio_iommu.h"
|
|
#include "hw/virtio/virtio.h"
|
|
#include "hw/pci/pci.h"
|
|
#include "qom/object.h"
|
|
|
|
#define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
|
|
#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci"
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOIOMMU, VIRTIO_IOMMU)
|
|
|
|
#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
|
|
|
|
typedef struct IOMMUDevice {
|
|
void *viommu;
|
|
PCIBus *bus;
|
|
int devfn;
|
|
IOMMUMemoryRegion iommu_mr;
|
|
AddressSpace as;
|
|
MemoryRegion root; /* The root container of the device */
|
|
MemoryRegion bypass_mr; /* The alias of shared memory MR */
|
|
} IOMMUDevice;
|
|
|
|
typedef struct IOMMUPciBus {
|
|
PCIBus *bus;
|
|
IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */
|
|
} IOMMUPciBus;
|
|
|
|
struct VirtIOIOMMU {
|
|
VirtIODevice parent_obj;
|
|
VirtQueue *req_vq;
|
|
VirtQueue *event_vq;
|
|
struct virtio_iommu_config config;
|
|
uint64_t features;
|
|
GHashTable *as_by_busptr;
|
|
IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
|
|
PCIBus *primary_bus;
|
|
ReservedRegion *reserved_regions;
|
|
uint32_t nb_reserved_regions;
|
|
GTree *domains;
|
|
QemuRecMutex mutex;
|
|
GTree *endpoints;
|
|
bool boot_bypass;
|
|
Notifier machine_done;
|
|
bool granule_frozen;
|
|
};
|
|
|
|
#endif
|