Change the u32 to a u64, and make sure to use 1ULL everywhere!

Cc: Ohad Ben-Cohen <[email protected]>
Cc: Brian Swetland <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: Christian Borntraeger <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
Acked-by: Pawel Moll <[email protected]>
---
 drivers/char/virtio_console.c          |    2 +-
 drivers/lguest/lguest_device.c         |   10 +++++-----
 drivers/remoteproc/remoteproc_virtio.c |    6 +++++-
 drivers/s390/kvm/kvm_virtio.c          |   10 +++++-----
 drivers/s390/kvm/virtio_ccw.c          |   13 +++++++++++--
 drivers/virtio/virtio.c                |   12 ++++++------
 drivers/virtio/virtio_mmio.c           |   14 +++++++++-----
 drivers/virtio/virtio_pci.c            |    5 ++---
 drivers/virtio/virtio_ring.c           |    2 +-
 include/linux/virtio.h                 |    2 +-
 include/linux/virtio_config.h          |    8 ++++----
 tools/virtio/linux/virtio.h            |    2 +-
 tools/virtio/linux/virtio_config.h     |    2 +-
 13 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index 9d9f717..1a1e5da 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -351,7 +351,7 @@ static inline bool use_multiport(struct ports_device 
*portdev)
         */
        if (!portdev->vdev)
                return 0;
-       return portdev->vdev->features & (1 << VIRTIO_CONSOLE_F_MULTIPORT);
+       return portdev->vdev->features & (1ULL << VIRTIO_CONSOLE_F_MULTIPORT);
 }
 
 static DEFINE_SPINLOCK(dma_bufs_lock);
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 9528e64..61dd97c 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -94,17 +94,17 @@ static unsigned desc_size(const struct lguest_device_desc 
*desc)
 }
 
 /* This gets the device's feature bits. */
-static u32 lg_get_features(struct virtio_device *vdev)
+static u64 lg_get_features(struct virtio_device *vdev)
 {
        unsigned int i;
-       u32 features = 0;
+       u64 features = 0;
        struct lguest_device_desc *desc = to_lgdev(vdev)->desc;
        u8 *in_features = lg_features(desc);
 
        /* We do this the slow but generic way. */
-       for (i = 0; i < min(desc->feature_len * 8, 32); i++)
+       for (i = 0; i < min(desc->feature_len * 8, 64); i++)
                if (in_features[i / 8] & (1 << (i % 8)))
-                       features |= (1 << i);
+                       features |= (1ULL << i);
 
        return features;
 }
@@ -144,7 +144,7 @@ static void lg_finalize_features(struct virtio_device *vdev)
        memset(out_features, 0, desc->feature_len);
        bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
        for (i = 0; i < bits; i++) {
-               if (vdev->features & (1 << i))
+               if (vdev->features & (1ULL << i))
                        out_features[i / 8] |= (1 << (i % 8));
        }
 
diff --git a/drivers/remoteproc/remoteproc_virtio.c 
b/drivers/remoteproc/remoteproc_virtio.c
index fb8faee..aefbaae 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -196,7 +196,7 @@ static void rproc_virtio_reset(struct virtio_device *vdev)
 }
 
 /* provide the vdev features as retrieved from the firmware */
-static u32 rproc_virtio_get_features(struct virtio_device *vdev)
+static u64 rproc_virtio_get_features(struct virtio_device *vdev)
 {
        struct rproc_vdev *rvdev = vdev_to_rvdev(vdev);
 
@@ -210,6 +210,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.
@@ -220,6 +223,7 @@ static void rproc_virtio_finalize_features(struct 
virtio_device *vdev)
         * extension of the virtio resource entries.
         */
        rvdev->gfeatures = vdev->features;
+
 }
 
 static const struct virtio_config_ops rproc_virtio_config_ops = {
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 8779224..a023979 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -80,16 +80,16 @@ static unsigned desc_size(const struct kvm_device_desc 
*desc)
 }
 
 /* This gets the device's feature bits. */
-static u32 kvm_get_features(struct virtio_device *vdev)
+static u64 kvm_get_features(struct virtio_device *vdev)
 {
        unsigned int i;
-       u32 features = 0;
+       u64 features = 0;
        struct kvm_device_desc *desc = to_kvmdev(vdev)->desc;
        u8 *in_features = kvm_vq_features(desc);
 
-       for (i = 0; i < min(desc->feature_len * 8, 32); i++)
+       for (i = 0; i < min(desc->feature_len * 8, 64); i++)
                if (in_features[i / 8] & (1 << (i % 8)))
-                       features |= (1 << i);
+                       features |= (1ULL << i);
        return features;
 }
 
@@ -106,7 +106,7 @@ static void kvm_finalize_features(struct virtio_device 
*vdev)
        memset(out_features, 0, desc->feature_len);
        bits = min_t(unsigned, desc->feature_len, sizeof(vdev->features)) * 8;
        for (i = 0; i < bits; i++) {
-               if (vdev->features & (1 << i))
+               if (vdev->features & (1ULL << i))
                        out_features[i / 8] |= (1 << (i % 8));
        }
 }
diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c
index 8c564bf..bd67b26 100644
--- a/drivers/s390/kvm/virtio_ccw.c
+++ b/drivers/s390/kvm/virtio_ccw.c
@@ -454,8 +454,17 @@ static void virtio_ccw_finalize_features(struct 
virtio_device *vdev)
        vring_transport_features(vdev);
 
        features->index = 0;
-       features->features = cpu_to_le32(vdev->features);
-       /* Write the feature bits to the host. */
+       features->features = cpu_to_le32((u32)vdev->features);
+       /* Write the first half of the feature bits to the host. */
+       ccw->cmd_code = CCW_CMD_WRITE_FEAT;
+       ccw->flags = 0;
+       ccw->count = sizeof(*features);
+       ccw->cda = (__u32)(unsigned long)features;
+       ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT);
+
+       features->index = 1;
+       features->features = cpu_to_le32(vdev->features >> 32);
+       /* Write the second half of the feature bits to the host. */
        ccw->cmd_code = CCW_CMD_WRITE_FEAT;
        ccw->flags = 0;
        ccw->count = sizeof(*features);
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 8ebe913..6ffa542 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -111,7 +111,7 @@ static int virtio_dev_probe(struct device *_d)
        int err, i;
        struct virtio_device *dev = dev_to_virtio(_d);
        struct virtio_driver *drv = drv_to_virtio(dev->dev.driver);
-       u32 device_features;
+       u64 device_features;
 
        /* We have a driver! */
        add_status(dev, VIRTIO_CONFIG_S_DRIVER);
@@ -123,15 +123,15 @@ static int virtio_dev_probe(struct device *_d)
        dev->features = 0;
        for (i = 0; i < drv->feature_table_size; i++) {
                unsigned int f = drv->feature_table[i];
-               BUG_ON(f >= 32);
-               if (device_features & (1 << f))
-                       dev->features |= (1 << f);
+               BUG_ON(f >= 64);
+               if (device_features & (1ULL << f))
+                       dev->features |= (1ULL << f);
        }
 
        /* Transport features always preserved to pass to finalize_features. */
        for (i = VIRTIO_TRANSPORT_F_START; i < VIRTIO_TRANSPORT_F_END; i++)
-               if (device_features & (1 << i))
-                       dev->features |= (1 << i);
+               if (device_features & (1ULL << i))
+                       dev->features |= (1ULL << i);
 
        dev->config->finalize_features(dev);
 
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
index 24d583a..0f1995c 100644
--- a/drivers/virtio/virtio_mmio.c
+++ b/drivers/virtio/virtio_mmio.c
@@ -142,14 +142,16 @@ struct virtio_mmio_vq_info {
 
 /* Configuration interface */
 
-static u32 vm_get_features(struct virtio_device *vdev)
+static u64 vm_get_features(struct virtio_device *vdev)
 {
        struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
+       u64 features;
 
-       /* TODO: Features > 32 bits */
        writel(0, vm_dev->base + VIRTIO_MMIO_HOST_FEATURES_SEL);
-
-       return readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES);
+       features = readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES);
+       writel(1, vm_dev->base + VIRTIO_MMIO_HOST_FEATURES_SEL);
+       features |= ((u64)readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES) << 
32);
+       return features;
 }
 
 static void vm_finalize_features(struct virtio_device *vdev)
@@ -160,7 +162,9 @@ static void vm_finalize_features(struct virtio_device *vdev)
        vring_transport_features(vdev);
 
        writel(0, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
-       writel(vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
+       writel((u32)vdev->features, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
+       writel(1, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SEL);
+       writel(vdev->features >> 32, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
 }
 
 static u8 vm_get8(struct virtio_device *vdev, unsigned offset)
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index aa85fdd..bfcce21 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -105,12 +105,11 @@ static struct virtio_pci_device *to_vp_device(struct 
virtio_device *vdev)
 }
 
 /* virtio config->get_features() implementation */
-static u32 vp_get_features(struct virtio_device *vdev)
+static u64 vp_get_features(struct virtio_device *vdev)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
 
-       /* When someone needs more than 32 feature bits, we'll need to
-        * steal a bit to indicate that the rest are somewhere else. */
+       /* We only support 32 feature bits. */
        return ioread32(vp_dev->ioaddr + VIRTIO_PCI_HOST_FEATURES);
 }
 
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 82afdd8..ba58e29 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -814,7 +814,7 @@ void vring_transport_features(struct virtio_device *vdev)
                        break;
                default:
                        /* We don't understand this bit. */
-                       vdev->features &= ~(1 << i);
+                       vdev->features &= ~(1ULL << i);
                }
        }
 }
diff --git a/include/linux/virtio.h b/include/linux/virtio.h
index 80f55a0..a05f7c7 100644
--- a/include/linux/virtio.h
+++ b/include/linux/virtio.h
@@ -100,7 +100,7 @@ struct virtio_device {
        const struct virtio_config_ops *config;
        const struct vringh_config_ops *vringh_config;
        struct list_head vqs;
-       u32 features;
+       u64 features;
        void *priv;
 };
 
diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
index 9a7f740..9a9aaa0 100644
--- a/include/linux/virtio_config.h
+++ b/include/linux/virtio_config.h
@@ -84,7 +84,7 @@ struct virtio_config_ops {
                        vq_callback_t *callbacks[],
                        const char *names[]);
        void (*del_vqs)(struct virtio_device *);
-       u32 (*get_features)(struct virtio_device *vdev);
+       u64 (*get_features)(struct virtio_device *vdev);
        void (*finalize_features)(struct virtio_device *vdev);
        const char *(*bus_name)(struct virtio_device *vdev);
        int (*set_vq_affinity)(struct virtqueue *vq, int cpu);
@@ -104,14 +104,14 @@ static inline bool virtio_has_feature(const struct 
virtio_device *vdev,
 {
        /* Did you forget to fix assumptions on max features? */
        if (__builtin_constant_p(fbit))
-               BUILD_BUG_ON(fbit >= 32);
+               BUILD_BUG_ON(fbit >= 64);
        else
-               BUG_ON(fbit >= 32);
+               BUG_ON(fbit >= 64);
 
        if (fbit < VIRTIO_TRANSPORT_F_START)
                virtio_check_driver_offered_feature(vdev, fbit);
 
-       return vdev->features & (1 << fbit);
+       return vdev->features & (1ULL << fbit);
 }
 
 static inline
diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h
index 02a38e8..358706d 100644
--- a/tools/virtio/linux/virtio.h
+++ b/tools/virtio/linux/virtio.h
@@ -10,7 +10,7 @@
 
 struct virtio_device {
        void *dev;
-       u32 features;
+       u64 features;
 };
 
 struct virtqueue {
diff --git a/tools/virtio/linux/virtio_config.h 
b/tools/virtio/linux/virtio_config.h
index 1f1636b..a254c2b 100644
--- a/tools/virtio/linux/virtio_config.h
+++ b/tools/virtio/linux/virtio_config.h
@@ -2,5 +2,5 @@
 #define VIRTIO_TRANSPORT_F_END         32
 
 #define virtio_has_feature(dev, feature) \
-       ((dev)->features & (1 << feature))
+       ((dev)->features & (1ULL << feature))
 
-- 
1.7.10.4

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Reply via email to