virtio: force VIRTIO_F_IOMMU_PLATFORM

We allow vhost to clear VIRITO_F_IOMMU_PLATFORM which is wrong since
VIRTIO_F_IOMMU_PLATFORM is mandatory for security. Fixing this by
enforce it after vdc->get_features().

Signed-off-by: Jason Wang <jasowang@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
Jason Wang 2017-01-17 12:01:00 +08:00 committed by Michael S. Tsirkin
parent 6bdc21c050
commit 2943b53f68

View File

@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
VirtioBusState *bus = VIRTIO_BUS(qbus); VirtioBusState *bus = VIRTIO_BUS(qbus);
VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus); VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
bool has_iommu = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM);
DPRINTF("%s: plug device.\n", qbus->name); DPRINTF("%s: plug device.\n", qbus->name);
@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
klass->device_plugged(qbus->parent, errp); klass->device_plugged(qbus->parent, errp);
} }
if (klass->get_dma_as != NULL && if (klass->get_dma_as != NULL && has_iommu) {
virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) { virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM);
vdev->dma_as = klass->get_dma_as(qbus->parent); vdev->dma_as = klass->get_dma_as(qbus->parent);
} else { } else {
vdev->dma_as = &address_space_memory; vdev->dma_as = &address_space_memory;