Skip to contentSkip to conversation

virtio: force VIRTIO_F_IOMMU_PLATFORM

PATCH In review Jason Wang 2 participants 8 messages Jan 17, 2017 – Jan 20, 2017

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

PATCH 1/1 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().

---
 hw/virtio/virtio-bus.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +3 -2
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
     VirtioBusState *bus = VIRTIO_BUS(qbus);
     VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
     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);
 
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
         klass->device_plugged(qbus->parent, errp);
     }
 
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
         vdev->dma_as = &address_space_memory;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 22 lines · Jason Wang

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().

---
 hw/virtio/virtio-bus.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -0
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
     VirtioBusState *bus = VIRTIO_BUS(qbus);
     VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
     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);
 

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 71

Quoted 10 lines
hw/virtio/virtio-bus.c +2 -2
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
         klass->device_plugged(qbus->parent, errp);
     }
 
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
         vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Quoted 2 lines
Signature · 1 line
2.7.4
author
#2 lore raw
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · Jason Wang

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().

---
  hw/virtio/virtio-bus.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -0
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
      VirtioBusState *bus = VIRTIO_BUS(qbus);
      VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
      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);
 
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
          klass->device_plugged(qbus->parent, errp);
      }
 
Quoted 9 lines

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 71

Quoted 7 lines
hw/virtio/virtio-bus.c +2 -2
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
          vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Looks like with the patch, VIRTIO_F_IOMMU_PLATFORM will be passed to vhost_set_features(). So if vhost backend does not support it, it will fall back to userspace (This may not work for vhost-user, but it's a bug existed even before this patch).

Thanks

#3 lore raw
Quoted 36 lines · Jason Wang
Quoted 24 lines · Michael S. Tsirkin
Quoted 23 lines · Jason Wang

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().

---
  hw/virtio/virtio-bus.c | 5 +++--
  1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -1
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
      VirtioBusState *bus = VIRTIO_BUS(qbus);
      VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
      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);
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
          klass->device_plugged(qbus->parent, errp);
      }
-    if (klass->get_dma_as != NULL &&
Quoted 8 lines

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 71

Quoted 6 lines
hw/virtio/virtio-bus.c +2 -1
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
          vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Quoted 2 lines

Looks like with the patch, VIRTIO_F_IOMMU_PLATFORM will be passed to vhost_set_features().

Okay then. Could you please test on an old host kernel and confirm what happens? Pls mention this in commit log.

Quoted 5 lines

So if vhost backend does not support it, it will fall
back to userspace (This may not work for vhost-user, but it's a bug existed even before this patch).

Thanks

I guess this is true but this suddenly makes it important to fix this. So I prefer a patchset where patch 2 addresses the fallback bug. In which way? Do you think we should just fail if vhost doesn't work? Does this apply to both userspace and kernel?

Signature · 1 line
MST
author
#4 lore raw
Quoted 35 lines · Michael S. Tsirkin
Quoted 34 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Jason Wang

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().

---
   hw/virtio/virtio-bus.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -0
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
       VirtioBusState *bus = VIRTIO_BUS(qbus);
       VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
       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);

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 70

Quoted 9 lines
hw/virtio/virtio-bus.c +2 -2
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
           klass->device_plugged(qbus->parent, errp);
       }
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
           vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Quoted 4 lines
Quoted 2 lines

Looks like with the patch, VIRTIO_F_IOMMU_PLATFORM will be passed to vhost_set_features().

Okay then. Could you please test on an old host kernel and confirm what happens? Pls mention this in commit log.

Test were done before sending this patch :)

Vhost fallback to userspace since it lacks VIRTIO_F_IOMMU_PLATFORM.

Quoted 11 lines
Quoted 6 lines

So if vhost backend does not support it, it will fall
back to userspace (This may not work for vhost-user, but it's a bug existed even before this patch).

Thanks

I guess this is true but this suddenly makes it important to fix this. So I prefer a patchset where patch 2 addresses the fallback bug. In which way? Do you think we should just fail if vhost doesn't work? Does this apply to both userspace and kernel?

For 1.0 devices we could do this through NEEDS_RESET, but it doesn't work for legacy device. For kernel vhost, I'd prefer to keep the current fallback. For vhost-user, it seems not easy and we could not just terminate qemu in this case consider this kind of failure can only be detected during start not init.

Thanks

#5 lore raw
Quoted 59 lines · Jason Wang
Quoted 35 lines · Michael S. Tsirkin
Quoted 34 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Jason Wang

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().

---
   hw/virtio/virtio-bus.c | 5 +++--
   1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -0
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
       VirtioBusState *bus = VIRTIO_BUS(qbus);
       VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
       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);

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 70

Quoted 9 lines
hw/virtio/virtio-bus.c +2 -2
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
           klass->device_plugged(qbus->parent, errp);
       }
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
           vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Quoted 4 lines
Quoted 2 lines

Looks like with the patch, VIRTIO_F_IOMMU_PLATFORM will be passed to vhost_set_features().

Okay then. Could you please test on an old host kernel and confirm what happens? Pls mention this in commit log.

Test were done before sending this patch :)

Vhost fallback to userspace since it lacks VIRTIO_F_IOMMU_PLATFORM.

Quoted 11 lines
Quoted 6 lines

So if vhost backend does not support it, it will fall
back to userspace (This may not work for vhost-user, but it's a bug existed even before this patch).

Thanks

I guess this is true but this suddenly makes it important to fix this. So I prefer a patchset where patch 2 addresses the fallback bug. In which way? Do you think we should just fail if vhost doesn't work? Does this apply to both userspace and kernel?

Quoted 3 lines

For 1.0 devices we could do this through NEEDS_RESET, but it doesn't work for legacy device. For kernel vhost, I'd prefer to keep the current fallback.

I'm not so sure. This has security implications, e.g. user might expect not to be affected by a bug in qemu if specifying vhost=on.

Quoted 5 lines

For vhost-user, it seems not easy and we could not just terminate qemu in this case consider this kind of failure can only be detected during start not init.

Thanks

I think we should at least deny connection.

Signature · 1 line
MST
author
#6 lore raw
Quoted 55 lines · Michael S. Tsirkin
Quoted 54 lines · Jason Wang
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Jason Wang

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().

---
    hw/virtio/virtio-bus.c | 5 +++--
    1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -0
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
        VirtioBusState *bus = VIRTIO_BUS(qbus);
        VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
        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);

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 70

Quoted 9 lines
hw/virtio/virtio-bus.c +2 -2
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
            klass->device_plugged(qbus->parent, errp);
        }
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
            vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Quoted 4 lines
Quoted 2 lines

Looks like with the patch, VIRTIO_F_IOMMU_PLATFORM will be passed to vhost_set_features().

Okay then. Could you please test on an old host kernel and confirm what happens? Pls mention this in commit log.

Test were done before sending this patch :)

Vhost fallback to userspace since it lacks VIRTIO_F_IOMMU_PLATFORM.

Quoted 10 lines
Quoted 5 lines

So if vhost backend does not support it, it will fall
back to userspace (This may not work for vhost-user, but it's a bug existed even before this patch).

Thanks

I guess this is true but this suddenly makes it important to fix this. So I prefer a patchset where patch 2 addresses the fallback bug. In which way? Do you think we should just fail if vhost doesn't work? Does this apply to both userspace and kernel?

Quoted 5 lines
Quoted 3 lines

For 1.0 devices we could do this through NEEDS_RESET, but it doesn't work for legacy device. For kernel vhost, I'd prefer to keep the current fallback.

I'm not so sure. This has security implications, e.g. user might expect not to be affected by a bug in qemu if specifying vhost=on.

Ok.

Quoted 7 lines
Quoted 6 lines

For vhost-user, it seems not easy and we could not just terminate qemu in this case consider this kind of failure can only be detected during start not init.

Thanks

I think we should at least deny connection.

Ok and we need do something after denying it, how about vdev->broken or others?

Thanks

#7 lore raw
Quoted 71 lines · Jason Wang
Quoted 55 lines · Michael S. Tsirkin
Quoted 54 lines · Jason Wang
Quoted 34 lines · Michael S. Tsirkin
Quoted 33 lines · Jason Wang
Quoted 32 lines · Michael S. Tsirkin
Quoted 20 lines · Jason Wang

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().

---
    hw/virtio/virtio-bus.c | 5 +++--
    1 file changed, 3 insertions(+), 2 deletions(-)
hw/virtio/virtio-bus.c +1 -0
index d31cc00..a886011 100644
@@ -47,6 +47,7 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
        VirtioBusState *bus = VIRTIO_BUS(qbus);
        VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
        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);

hw/virtio/virtio-bus.c void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) · line 70

Quoted 9 lines
hw/virtio/virtio-bus.c +2 -2
@@ -63,8 +64,8 @@ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp)
            klass->device_plugged(qbus->parent, errp);
        }
-    if (klass->get_dma_as != NULL &&
-        virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM)) {
+    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 {
            vdev->dma_as = &address_space_memory;

I suspect that's not enough, we must also fail or disable vhost (depending on the options), otherwise things won't work.

Quoted 4 lines
Quoted 2 lines

Looks like with the patch, VIRTIO_F_IOMMU_PLATFORM will be passed to vhost_set_features().

Okay then. Could you please test on an old host kernel and confirm what happens? Pls mention this in commit log.

Test were done before sending this patch :)

Vhost fallback to userspace since it lacks VIRTIO_F_IOMMU_PLATFORM.

Quoted 10 lines
Quoted 5 lines

So if vhost backend does not support it, it will fall
back to userspace (This may not work for vhost-user, but it's a bug existed even before this patch).

Thanks

I guess this is true but this suddenly makes it important to fix this. So I prefer a patchset where patch 2 addresses the fallback bug. In which way? Do you think we should just fail if vhost doesn't work? Does this apply to both userspace and kernel?

Quoted 5 lines
Quoted 3 lines

For 1.0 devices we could do this through NEEDS_RESET, but it doesn't work for legacy device. For kernel vhost, I'd prefer to keep the current fallback.

I'm not so sure. This has security implications, e.g. user might expect not to be affected by a bug in qemu if specifying vhost=on.

Ok.

Quoted 5 lines
Quoted 5 lines

For vhost-user, it seems not easy and we could not just terminate qemu in this case consider this kind of failure can only be detected during start not init.

Quoted 7 lines
Quoted 2 lines
Quoted 1 line

Thanks

I think we should at least deny connection.

Ok and we need do something after denying it, how about vdev->broken or others?

Thanks

For vhost-user qemu does not make progress until there's a valid connection.