virtio: change config to guest endian.
A recent proposed feature addition to the virtio block driver revealed some flaws in the API, in particular how easy it is to break big endian machines. The virtio config space was originally chosen to be little-endian, because we thought the config might be part of the PCI config space for virtio_pci. It's actually a separate mmio region, so that argument holds little water; as only x86 is currently using the virtio mechanism, we can change this (but must do so now, before the impending s390 merge). API changes: - __virtio_config_val() just becomes a striaght vdev->config_get() call. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Родитель
5539ae9613
Коммит
72e61eb40b
|
@ -246,8 +246,8 @@ static int virtblk_probe(struct virtio_device *vdev)
|
||||||
blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL);
|
blk_queue_ordered(vblk->disk->queue, QUEUE_ORDERED_TAG, NULL);
|
||||||
|
|
||||||
/* Host must always specify the capacity. */
|
/* Host must always specify the capacity. */
|
||||||
__virtio_config_val(vdev, offsetof(struct virtio_blk_config, capacity),
|
vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
|
||||||
&cap);
|
&cap, sizeof(cap));
|
||||||
|
|
||||||
/* If capacity is too big, truncate with warning. */
|
/* If capacity is too big, truncate with warning. */
|
||||||
if ((sector_t)cap != cap) {
|
if ((sector_t)cap != cap) {
|
||||||
|
|
|
@ -155,9 +155,9 @@ static void virtballoon_changed(struct virtio_device *vdev)
|
||||||
static inline s64 towards_target(struct virtio_balloon *vb)
|
static inline s64 towards_target(struct virtio_balloon *vb)
|
||||||
{
|
{
|
||||||
u32 v;
|
u32 v;
|
||||||
__virtio_config_val(vb->vdev,
|
vb->vdev->config->get(vb->vdev,
|
||||||
offsetof(struct virtio_balloon_config, num_pages),
|
offsetof(struct virtio_balloon_config, num_pages),
|
||||||
&v);
|
&v, sizeof(v));
|
||||||
return v - vb->num_pages;
|
return v - vb->num_pages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#define VIRTIO_CONFIG_S_FAILED 0x80
|
#define VIRTIO_CONFIG_S_FAILED 0x80
|
||||||
|
|
||||||
#ifdef __KERNEL__
|
#ifdef __KERNEL__
|
||||||
struct virtio_device;
|
#include <linux/virtio.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virtio_config_ops - operations for configuring a virtio device
|
* virtio_config_ops - operations for configuring a virtio device
|
||||||
|
@ -30,13 +30,11 @@ struct virtio_device;
|
||||||
* offset: the offset of the configuration field
|
* offset: the offset of the configuration field
|
||||||
* buf: the buffer to write the field value into.
|
* buf: the buffer to write the field value into.
|
||||||
* len: the length of the buffer
|
* len: the length of the buffer
|
||||||
* Note that contents are conventionally little-endian.
|
|
||||||
* @set: write the value of a configuration field
|
* @set: write the value of a configuration field
|
||||||
* vdev: the virtio_device
|
* vdev: the virtio_device
|
||||||
* offset: the offset of the configuration field
|
* offset: the offset of the configuration field
|
||||||
* buf: the buffer to read the field value from.
|
* buf: the buffer to read the field value from.
|
||||||
* len: the length of the buffer
|
* len: the length of the buffer
|
||||||
* Note that contents are conventionally little-endian.
|
|
||||||
* @get_status: read the status byte
|
* @get_status: read the status byte
|
||||||
* vdev: the virtio_device
|
* vdev: the virtio_device
|
||||||
* Returns the status byte
|
* Returns the status byte
|
||||||
|
@ -70,40 +68,27 @@ struct virtio_config_ops
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virtio_config_val - look for a feature and get a single virtio config.
|
* virtio_config_val - look for a feature and get a virtio config entry.
|
||||||
* @vdev: the virtio device
|
* @vdev: the virtio device
|
||||||
* @fbit: the feature bit
|
* @fbit: the feature bit
|
||||||
* @offset: the type to search for.
|
* @offset: the type to search for.
|
||||||
* @val: a pointer to the value to fill in.
|
* @val: a pointer to the value to fill in.
|
||||||
*
|
*
|
||||||
* The return value is -ENOENT if the feature doesn't exist. Otherwise
|
* The return value is -ENOENT if the feature doesn't exist. Otherwise
|
||||||
* the value is endian-corrected and returned in v. */
|
* the config value is copied into whatever is pointed to by v. */
|
||||||
#define virtio_config_val(vdev, fbit, offset, v) ({ \
|
#define virtio_config_val(vdev, fbit, offset, v) \
|
||||||
int _err; \
|
virtio_config_buf((vdev), (fbit), (offset), (v), sizeof(v))
|
||||||
if ((vdev)->config->feature((vdev), (fbit))) { \
|
|
||||||
__virtio_config_val((vdev), (offset), (v)); \
|
|
||||||
_err = 0; \
|
|
||||||
} else \
|
|
||||||
_err = -ENOENT; \
|
|
||||||
_err; \
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
static inline int virtio_config_buf(struct virtio_device *vdev,
|
||||||
* __virtio_config_val - get a single virtio config without feature check.
|
unsigned int fbit,
|
||||||
* @vdev: the virtio device
|
unsigned int offset,
|
||||||
* @offset: the type to search for.
|
void *buf, unsigned len)
|
||||||
* @val: a pointer to the value to fill in.
|
{
|
||||||
*
|
if (!vdev->config->feature(vdev, fbit))
|
||||||
* The value is endian-corrected and returned in v. */
|
return -ENOENT;
|
||||||
#define __virtio_config_val(vdev, offset, v) do { \
|
|
||||||
BUILD_BUG_ON(sizeof(*(v)) != 1 && sizeof(*(v)) != 2 \
|
vdev->config->get(vdev, offset, buf, len);
|
||||||
&& sizeof(*(v)) != 4 && sizeof(*(v)) != 8); \
|
return 0;
|
||||||
(vdev)->config->get((vdev), (offset), (v), sizeof(*(v))); \
|
}
|
||||||
switch (sizeof(*(v))) { \
|
|
||||||
case 2: le16_to_cpus((__u16 *) v); break; \
|
|
||||||
case 4: le32_to_cpus((__u32 *) v); break; \
|
|
||||||
case 8: le64_to_cpus((__u64 *) v); break; \
|
|
||||||
} \
|
|
||||||
} while(0)
|
|
||||||
#endif /* __KERNEL__ */
|
#endif /* __KERNEL__ */
|
||||||
#endif /* _LINUX_VIRTIO_CONFIG_H */
|
#endif /* _LINUX_VIRTIO_CONFIG_H */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче