Skip to contentSkip to conversation

virtio: hide legacy features from modern guests

PATCH In review Michael S. Tsirkin 2 participants 3 messages Jul 22, 2015 – Jul 23, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: hide legacy features from modern guests

NOTIFY_ON_EMPTY, ANY_LAYOUT and BAD are only valid on the legacy interface.

Hide them from modern guests.

---
 include/hw/virtio/virtio.h | 4 ++++
 hw/virtio/virtio-pci.c     | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/virtio/virtio.h +4 -0
index fbb3c06..cbe3a5a 100644
@@ -25,6 +25,10 @@
 /* A guest should never accept this.  It implies negotiation is broken. */
 #define VIRTIO_F_BAD_FEATURE		30
 
+#define VIRTIO_LEGACY_FEATURES ((0x1ULL << VIRTIO_F_BAD_FEATURE) | \
+                                (0x1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \
+                                (0x1ULL << VIRTIO_F_ANY_LAYOUT))
+
 struct VirtQueue;
 
 static inline hwaddr vring_align(hwaddr addr,
hw/virtio/virtio-pci.c +2 -1
index 283401a..db8f27c 100644
@@ -1095,7 +1095,8 @@ static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
         break;
     case VIRTIO_PCI_COMMON_DF:
         if (proxy->dfselect <= 1) {
-            val = vdev->host_features >> (32 * proxy->dfselect);
+            val = (vdev->host_features & ~VIRTIO_LEGACY_FEATURES) >>
+                (32 * proxy->dfselect);
         }
         break;
     case VIRTIO_PCI_COMMON_GFSELECT:
Signature · 1 line
MST
#1 lore raw
Quoted 6 lines · Michael S. Tsirkin

NOTIFY_ON_EMPTY, ANY_LAYOUT and BAD are only valid on the legacy interface.

Hide them from modern guests.

Should we do the same for device specific legacy feature bits?

Quoted 34 lines
---
 include/hw/virtio/virtio.h | 4 ++++
 hw/virtio/virtio-pci.c     | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/virtio/virtio.h +4 -0
index fbb3c06..cbe3a5a 100644
@@ -25,6 +25,10 @@
 /* A guest should never accept this.  It implies negotiation is broken. */
 #define VIRTIO_F_BAD_FEATURE		30
 
+#define VIRTIO_LEGACY_FEATURES ((0x1ULL << VIRTIO_F_BAD_FEATURE) | \
+                                (0x1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \
+                                (0x1ULL << VIRTIO_F_ANY_LAYOUT))
+
 struct VirtQueue;
 
 static inline hwaddr vring_align(hwaddr addr,
hw/virtio/virtio-pci.c +2 -1
index 283401a..db8f27c 100644
@@ -1095,7 +1095,8 @@ static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
         break;
     case VIRTIO_PCI_COMMON_DF:
         if (proxy->dfselect <= 1) {
-            val = vdev->host_features >> (32 * proxy->dfselect);
+            val = (vdev->host_features & ~VIRTIO_LEGACY_FEATURES) >>
+                (32 * proxy->dfselect);
         }
         break;
     case VIRTIO_PCI_COMMON_GFSELECT:
#2 lore raw
Quoted 11 lines · Jason Wang
Quoted 6 lines · Michael S. Tsirkin

NOTIFY_ON_EMPTY, ANY_LAYOUT and BAD are only valid on the legacy interface.

Hide them from modern guests.

Should we do the same for device specific legacy feature bits?

Depends on what do you refer to.

Quoted 34 lines
Quoted 34 lines
---
 include/hw/virtio/virtio.h | 4 ++++
 hw/virtio/virtio-pci.c     | 3 ++-
 2 files changed, 6 insertions(+), 1 deletion(-)
include/hw/virtio/virtio.h +4 -0
index fbb3c06..cbe3a5a 100644
@@ -25,6 +25,10 @@
 /* A guest should never accept this.  It implies negotiation is broken. */
 #define VIRTIO_F_BAD_FEATURE		30
 
+#define VIRTIO_LEGACY_FEATURES ((0x1ULL << VIRTIO_F_BAD_FEATURE) | \
+                                (0x1ULL << VIRTIO_F_NOTIFY_ON_EMPTY) | \
+                                (0x1ULL << VIRTIO_F_ANY_LAYOUT))
+
 struct VirtQueue;
 
 static inline hwaddr vring_align(hwaddr addr,
hw/virtio/virtio-pci.c +2 -1
index 283401a..db8f27c 100644
@@ -1095,7 +1095,8 @@ static uint64_t virtio_pci_common_read(void *opaque, hwaddr addr,
         break;
     case VIRTIO_PCI_COMMON_DF:
         if (proxy->dfselect <= 1) {
-            val = vdev->host_features >> (32 * proxy->dfselect);
+            val = (vdev->host_features & ~VIRTIO_LEGACY_FEATURES) >>
+                (32 * proxy->dfselect);
         }
         break;
     case VIRTIO_PCI_COMMON_GFSELECT: