Skip to content

Commit

Permalink
virtio: add support for 64 bit features.
Browse files Browse the repository at this point in the history
Change u32 to u64, and use BIT_ULL and 1ULL everywhere.

Note: transports are unchanged, and only set low 32 bit.
This guarantees that no transport sets e.g. VERSION_1
by mistake without proper support.

Based on patch by Rusty.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
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>
  • Loading branch information
Michael S. Tsirkin committed Dec 9, 2014
1 parent 0ffaead commit d025477
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion drivers/lguest/lguest_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ 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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/mic/card/mic_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static inline struct device *mic_dev(struct mic_vdev *mvdev)
}

/* This gets the device's feature bits. */
static u32 mic_get_features(struct virtio_device *vdev)
static u64 mic_get_features(struct virtio_device *vdev)
{
unsigned int i, bits;
u32 features = 0;
Expand Down
2 changes: 1 addition & 1 deletion drivers/remoteproc/remoteproc_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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);
struct fw_rsc_vdev *rsc;
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/kvm/kvm_virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ 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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/s390/kvm/virtio_ccw.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ static void virtio_ccw_reset(struct virtio_device *vdev)
kfree(ccw);
}

static u32 virtio_ccw_get_features(struct virtio_device *vdev)
static u64 virtio_ccw_get_features(struct virtio_device *vdev)
{
struct virtio_ccw_device *vcdev = to_vc_device(vdev);
struct virtio_feature_desc *features;
Expand Down
8 changes: 4 additions & 4 deletions drivers/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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);
Expand All @@ -171,14 +171,14 @@ 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))
BUG_ON(f >= 64);
if (device_features & (1ULL << f))
__virtio_set_bit(dev, 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))
if (device_features & (1ULL << i))
__virtio_set_bit(dev, i);

dev->config->finalize_features(dev);
Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ 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);

Expand Down
2 changes: 1 addition & 1 deletion drivers/virtio/virtio_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ 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);

Expand Down
2 changes: 1 addition & 1 deletion include/linux/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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;
};

Expand Down
20 changes: 10 additions & 10 deletions include/linux/virtio_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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);
Expand All @@ -88,11 +88,11 @@ static inline bool __virtio_test_bit(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);

return vdev->features & BIT(fbit);
return vdev->features & BIT_ULL(fbit);
}

/**
Expand All @@ -105,11 +105,11 @@ static inline void __virtio_set_bit(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);

vdev->features |= BIT(fbit);
vdev->features |= BIT_ULL(fbit);
}

/**
Expand All @@ -122,11 +122,11 @@ static inline void __virtio_clear_bit(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);

vdev->features &= ~BIT(fbit);
vdev->features &= ~BIT_ULL(fbit);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tools/virtio/linux/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

struct virtio_device {
void *dev;
u32 features;
u64 features;
};

struct virtqueue {
Expand Down

0 comments on commit d025477

Please sign in to comment.