aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2014-11-27 06:45:58 -0500
committerMichael S. Tsirkin <mst@redhat.com>2014-12-09 05:05:24 -0500
commit93d389f82078cf7197152fb10d21977da0883420 (patch)
treec168e5be2acd4e257212006a710af14df2185d80
parentd025477368792b272802146a86e41f81a54d8a19 (diff)
virtio: assert 32 bit features in transports
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>
-rw-r--r--drivers/lguest/lguest_device.c3
-rw-r--r--drivers/misc/mic/card/mic_virtio.c3
-rw-r--r--drivers/remoteproc/remoteproc_virtio.c3
-rw-r--r--drivers/s390/kvm/kvm_virtio.c3
-rw-r--r--drivers/s390/kvm/virtio_ccw.c3
-rw-r--r--drivers/virtio/virtio_mmio.c3
-rw-r--r--drivers/virtio/virtio_pci.c3
7 files changed, 21 insertions, 0 deletions
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index d81170a78a8d..9b77b6623ff8 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -136,6 +136,9 @@ static void lg_finalize_features(struct virtio_device *vdev)
136 /* Give virtio_ring a chance to accept features. */ 136 /* Give virtio_ring a chance to accept features. */
137 vring_transport_features(vdev); 137 vring_transport_features(vdev);
138 138
139 /* Make sure we don't have any features > 32 bits! */
140 BUG_ON((u32)vdev->features != vdev->features);
141
139 /* 142 /*
140 * Since lguest is currently x86-only, we're little-endian. That 143 * Since lguest is currently x86-only, we're little-endian. That
141 * means we could just memcpy. But it's not time critical, and in 144 * means we could just memcpy. But it's not time critical, and in
diff --git a/drivers/misc/mic/card/mic_virtio.c b/drivers/misc/mic/card/mic_virtio.c
index f5e756132bdb..d027d299602f 100644
--- a/drivers/misc/mic/card/mic_virtio.c
+++ b/drivers/misc/mic/card/mic_virtio.c
@@ -96,6 +96,9 @@ static void mic_finalize_features(struct virtio_device *vdev)
96 /* Give virtio_ring a chance to accept features. */ 96 /* Give virtio_ring a chance to accept features. */
97 vring_transport_features(vdev); 97 vring_transport_features(vdev);
98 98
99 /* Make sure we don't have any features > 32 bits! */
100 BUG_ON((u32)vdev->features != vdev->features);
101
99 memset_io(out_features, 0, feature_len); 102 memset_io(out_features, 0, feature_len);
100 bits = min_t(unsigned, feature_len, 103 bits = min_t(unsigned, feature_len,
101 sizeof(vdev->features)) * 8; 104 sizeof(vdev->features)) * 8;
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index 62897db1331e..627737ee7632 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -227,6 +227,9 @@ static void rproc_virtio_finalize_features(struct virtio_device *vdev)
227 /* Give virtio_ring a chance to accept features */ 227 /* Give virtio_ring a chance to accept features */
228 vring_transport_features(vdev); 228 vring_transport_features(vdev);
229 229
230 /* Make sure we don't have any features > 32 bits! */
231 BUG_ON((u32)vdev->features != vdev->features);
232
230 /* 233 /*
231 * Remember the finalized features of our vdev, and provide it 234 * Remember the finalized features of our vdev, and provide it
232 * to the remote processor once it is powered on. 235 * to the remote processor once it is powered on.
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 2336c7e3b0cf..f5575ccdbb65 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -103,6 +103,9 @@ static void kvm_finalize_features(struct virtio_device *vdev)
103 /* Give virtio_ring a chance to accept features. */ 103 /* Give virtio_ring a chance to accept features. */
104 vring_transport_features(vdev); 104 vring_transport_features(vdev);
105 105
106 /* Make sure we don't have any features > 32 bits! */
107 BUG_ON((u32)vdev->features != vdev->features);
108
106 memset(out_features, 0, desc->feature_len); 109 memset(out_features, 0, desc->feature_len);
107 bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8; 110 bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
108 for (i = 0; i < bits; i++) { 111 for (i = 0; i < bits; i++) {
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index 56d78956a8cb..244d611a0df2 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -714,6 +714,9 @@ static void virtio_ccw_finalize_features(struct virtio_device *vdev)
714 /* Give virtio_ring a chance to accept features. */ 714 /* Give virtio_ring a chance to accept features. */
715 vring_transport_features(vdev); 715 vring_transport_features(vdev);
716 716
717 /* Make sure we don't have any features > 32 bits! */
718 BUG_ON((u32)vdev->features != vdev->features);
719
717 features->index = 0; 720 features->index = 0;
718 features->features = cpu_to_le32(vdev->features); 721 features->features = cpu_to_le32(vdev->features);
719 /* Write the feature bits to the host. */ 722 /* Write the feature bits to the host. */
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index c63d0efa947b..aec1daee9ada 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -159,6 +159,9 @@ static void vm_finalize_features(struct virtio_device *vdev)
159 /* Give virtio_ring a chance to accept features. */ 159 /* Give virtio_ring a chance to accept features. */
160 vring_transport_features(vdev); 160 vring_transport_features(vdev);
161 161
162 /* Make sure we don't have any features > 32 bits! */
163 BUG_ON((u32)vdev->features != vdev->features);
164
162 writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL); 165 writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
163 writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES); 166 writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
164} 167}
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 7e0efa7fc384..dd6df979862b 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -119,6 +119,9 @@ static void vp_finalize_features(struct virtio_device *vdev)
119 /* Give virtio_ring a chance to accept features. */ 119 /* Give virtio_ring a chance to accept features. */
120 vring_transport_features(vdev); 120 vring_transport_features(vdev);
121 121
122 /* Make sure we don't have any features > 32 bits! */
123 BUG_ON((u32)vdev->features != vdev->features);
124
122 /* We only support 32 feature bits. */ 125 /* We only support 32 feature bits. */
123 iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES); 126 iowrite32(vdev->features, vp_dev->ioaddr + VIRTIO_PCI_GUEST_FEATURES);
124} 127}