Commit c5072037 authored by Greg Kurz's avatar Greg Kurz Committed by Michael S. Tsirkin

vhost: rename cross-endian helpers

The default use case for vhost is when the host and the vring have the
same endianness (default native endianness). But there are cases where
they differ and vhost should byteswap when accessing the vring.

The first case is when the host is big endian and the vring belongs to
a virtio 1.0 device, which is always little endian.

This is covered by the vq->is_le field. This field is initialized when
userspace calls the VHOST_SET_FEATURES ioctl. It is reset when the device
stops.

We already have a vhost_init_is_le() helper, but the reset operation is
opencoded as follows:

	vq->is_le = virtio_legacy_is_little_endian();

It isn't clear that we are resetting vq->is_le here.

This patch moves the code to a helper with a more explicit name.

The other case where we may have to byteswap is when the architecture can
switch endianness at runtime (bi-endian). If endianness differs in the host
and in the guest, then legacy devices need to be used in cross-endian mode.

This mode is available with CONFIG_VHOST_CROSS_ENDIAN_LEGACY=y, which
introduces a vq->user_be field. Userspace may enable cross-endian mode
by calling the SET_VRING_ENDIAN ioctl before the device is started. The
cross-endian mode is disabled when the device is stopped.

The current names of the helpers that manipulate vq->user_be are unclear.

This patch renames those helpers to clearly show that this is cross-endian
stuff and with explicit enable/disable semantics.

No behaviour change.
Signed-off-by: default avatarGreg Kurz <gkurz@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
parent 592002f5
...@@ -43,11 +43,21 @@ enum { ...@@ -43,11 +43,21 @@ enum {
#define vhost_avail_event(vq) ((__virtio16 __user *)&vq->used->ring[vq->num]) #define vhost_avail_event(vq) ((__virtio16 __user *)&vq->used->ring[vq->num])
#ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY #ifdef CONFIG_VHOST_CROSS_ENDIAN_LEGACY
static void vhost_vq_reset_user_be(struct vhost_virtqueue *vq) static void vhost_disable_cross_endian(struct vhost_virtqueue *vq)
{ {
vq->user_be = !virtio_legacy_is_little_endian(); vq->user_be = !virtio_legacy_is_little_endian();
} }
static void vhost_enable_cross_endian_big(struct vhost_virtqueue *vq)
{
vq->user_be = true;
}
static void vhost_enable_cross_endian_little(struct vhost_virtqueue *vq)
{
vq->user_be = false;
}
static long vhost_set_vring_endian(struct vhost_virtqueue *vq, int __user *argp) static long vhost_set_vring_endian(struct vhost_virtqueue *vq, int __user *argp)
{ {
struct vhost_vring_state s; struct vhost_vring_state s;
...@@ -62,7 +72,10 @@ static long vhost_set_vring_endian(struct vhost_virtqueue *vq, int __user *argp) ...@@ -62,7 +72,10 @@ static long vhost_set_vring_endian(struct vhost_virtqueue *vq, int __user *argp)
s.num != VHOST_VRING_BIG_ENDIAN) s.num != VHOST_VRING_BIG_ENDIAN)
return -EINVAL; return -EINVAL;
vq->user_be = s.num; if (s.num == VHOST_VRING_BIG_ENDIAN)
vhost_enable_cross_endian_big(vq);
else
vhost_enable_cross_endian_little(vq);
return 0; return 0;
} }
...@@ -91,7 +104,7 @@ static void vhost_init_is_le(struct vhost_virtqueue *vq) ...@@ -91,7 +104,7 @@ static void vhost_init_is_le(struct vhost_virtqueue *vq)
vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1) || !vq->user_be; vq->is_le = vhost_has_feature(vq, VIRTIO_F_VERSION_1) || !vq->user_be;
} }
#else #else
static void vhost_vq_reset_user_be(struct vhost_virtqueue *vq) static void vhost_disable_cross_endian(struct vhost_virtqueue *vq)
{ {
} }
...@@ -113,6 +126,11 @@ static void vhost_init_is_le(struct vhost_virtqueue *vq) ...@@ -113,6 +126,11 @@ static void vhost_init_is_le(struct vhost_virtqueue *vq)
} }
#endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */ #endif /* CONFIG_VHOST_CROSS_ENDIAN_LEGACY */
static void vhost_reset_is_le(struct vhost_virtqueue *vq)
{
vq->is_le = virtio_legacy_is_little_endian();
}
static void vhost_poll_func(struct file *file, wait_queue_head_t *wqh, static void vhost_poll_func(struct file *file, wait_queue_head_t *wqh,
poll_table *pt) poll_table *pt)
{ {
...@@ -276,8 +294,8 @@ static void vhost_vq_reset(struct vhost_dev *dev, ...@@ -276,8 +294,8 @@ static void vhost_vq_reset(struct vhost_dev *dev,
vq->call = NULL; vq->call = NULL;
vq->log_ctx = NULL; vq->log_ctx = NULL;
vq->memory = NULL; vq->memory = NULL;
vq->is_le = virtio_legacy_is_little_endian(); vhost_reset_is_le(vq);
vhost_vq_reset_user_be(vq); vhost_disable_cross_endian(vq);
} }
static int vhost_worker(void *data) static int vhost_worker(void *data)
...@@ -1159,7 +1177,7 @@ int vhost_init_used(struct vhost_virtqueue *vq) ...@@ -1159,7 +1177,7 @@ int vhost_init_used(struct vhost_virtqueue *vq)
bool is_le = vq->is_le; bool is_le = vq->is_le;
if (!vq->private_data) { if (!vq->private_data) {
vq->is_le = virtio_legacy_is_little_endian(); vhost_reset_is_le(vq);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment