virtio: assert 32 bit features in transports
authorMichael S. Tsirkin <mst@redhat.com>
Thu, 27 Nov 2014 11:45:58 +0000 (13:45 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Tue, 9 Dec 2014 10:05:24 +0000 (12:05 +0200)
At this point, no transports set any of the high 32 feature bits.
Since transports generally can't (yet) cope with such bits, add BUG_ON
checks to make sure they are not set by mistake.

Based on rproc patch by Rusty.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: David Hildenbrand <dahi@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
drivers/lguest/lguest_device.c
drivers/misc/mic/card/mic_virtio.c
drivers/remoteproc/remoteproc_virtio.c
drivers/s390/kvm/kvm_virtio.c
drivers/s390/kvm/virtio_ccw.c
drivers/virtio/virtio_mmio.c
drivers/virtio/virtio_pci.c

index d81170a78a8dcd54a32200c90e79d45827522174..9b77b6623ff853990c9d5f44277c7dc16f58c530 100644 (file)
@@ -136,6 +136,9 @@ static void lg_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features. */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        /*
         * Since lguest is currently x86-only, we're little-endian.  That
         * means we could just memcpy.  But it's not time critical, and in
index f5e756132bdbfd5c38bc9b036fee0f87685529d9..d027d299602fa8903f2ad35851d34298e64c64a6 100644 (file)
@@ -96,6 +96,9 @@ static void mic_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features. */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        memset_io(out_features, 0, feature_len);
        bits = min_t(unsigned, feature_len,
                sizeof(vdev->features)) * 8;
index 62897db1331e04e73c84764f608f7ebec95f1034..627737ee76320f55c4240f80a4a8e263e042f581 100644 (file)
@@ -227,6 +227,9 @@ static void rproc_virtio_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        /*
         * Remember the finalized features of our vdev, and provide it
         * to the remote processor once it is powered on.
index 2336c7e3b0cf422a3e26d3f44c2a5fe21a654304..f5575ccdbb65bfe5c22ccaafa0fdd8497ff72531 100644 (file)
@@ -103,6 +103,9 @@ static void kvm_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features. */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        memset(out_features, 0, desc->feature_len);
        bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
        for (i = 0; i < bits; i++) {
index 56d78956a8cbf40ec0d29c3b259450c52e8e1e06..244d611a0df242f71030917e5018e635aa57c480 100644 (file)
@@ -714,6 +714,9 @@ static void virtio_ccw_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features. */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        features->index = 0;
        features->features = cpu_to_le32(vdev->features);
        /* Write the feature bits to the host. */
index c63d0efa947b8fb63e740f4cf92ff7facc5b032a..aec1daee9ada3c3de69911fecb1341923713acae 100644 (file)
@@ -159,6 +159,9 @@ static void vm_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features. */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
        writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
 }
index 7e0efa7fc384bf1fe883ffd939c4534e607e1580..dd6df979862b3be711e41b065992ee1a740868fb 100644 (file)
@@ -119,6 +119,9 @@ static void vp_finalize_features(struct virtio_device *vdev)
        /* Give virtio_ring a chance to accept features. */
        vring_transport_features(vdev);
 
+       /* Make sure we don't have any features > 32 bits! */
+       BUG_ON((u32)vdev->features != vdev->features);
+
        /* We only support 32 feature bits. */
        iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
 }