[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Please help me understand VIRTIO_F_IOMMU_PLATFORM

From: Jason Thorpe
Subject: Please help me understand VIRTIO_F_IOMMU_PLATFORM
Date: Sat, 31 Jul 2021 08:41:17 -0700

Hey folks —

I’d like to be able to use VirtIO with qemu-system-alpha but, at least on a 
NetBSD x86_64 host, it does not currently work.  This is because 
virtio_bus_device_plugged() in hw/virtio/virtio-bus.c ends up picking 
address_space_memory as the DMA address space for the VirtIODevice.  This does 
not work for alpha because the CPU and PCI have different views of system 
memory.  All that’s needed to fix it is for virtio_bus_device_plugged() to call 
klass->get_dma_as(qbus->parent), but the code only does that if:

        bool has_iommu = virtio_host_has_feature(vdev, 

So, obviously, VIRTIO_F_IOMMU_PLATFORM is not getting set for an emulated alpha 
system, despite the alpha platform having one[*].  But it’s not clear to me 
that it’s appropriate for alpha to use VIRTIO_F_IOMMU_PLATFORM, at least from 
my reading of how it’s used.

In any case, the following extremely simple change allows me to use VirtIO 
devices in qemu-system-alpha with a NetBSD/alpha guest (and I’m told this also 
fixes using VirtIO devices in qemu-system-sparc64 for a NetBSD/sparc64 guest):

diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c
index 859978d248..c083e8d737 100644
--- a/hw/virtio/virtio-bus.c
+++ b/hw/virtio/virtio-bus.c
@@ -85,6 +85,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error 
     if (klass->get_dma_as != NULL && has_iommu) {
         virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
         vdev->dma_as = klass->get_dma_as(qbus->parent);
+    } else if (klass->get_dma_as != NULL) {
+        vdev->dma_as = klass->get_dma_as(qbus->parent);
     } else {
         vdev->dma_as = &address_space_memory;

So, VirtIO experts, please weigh in on the correctness of this change… if it 
is, I’ll post the patch formally.

[*] The way the alpha platform works is that the IOMMU is used if the PCI 
device performs a memory access to a DMA window where SGMAPs are enabled.  If 
SGMAPs are not enabled in the DMA window the PCI device is accessing, the 
translation is performed directly by subtracting the address from the window’s 
Window Base and appending the result to the window’s Translated Base.  A 
typical alpha PCI platform has a 1GB DMA window at 1GB from the PCI’s 
perspective, which maps to 0-1GB in the system address map, and an alpha system 
with 1GB or less of RAM would thus not need to use the IOMMU, but the 
translation take place regardless.

-- thorpej

reply via email to

[Prev in Thread] Current Thread [Next in Thread]