vhost_scsi: access VhostUsrMsg via packed struct

Fixes unaligned access to fields.

Change-Id: I43cff0c1cca7829da8f0d90774970e5feaa95515
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Signed-off-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com>
This commit is contained in:
Daniel Verkamp 2017-05-08 09:43:10 -07:00 committed by Jim Harris
parent 0cf6cc7b54
commit c2683a8e42

View File

@ -197,11 +197,11 @@ vhost_user_set_features(struct virtio_net *dev, uint64_t features)
*/ */
static int static int
vhost_user_set_vring_num(struct virtio_net *dev, vhost_user_set_vring_num(struct virtio_net *dev,
struct vhost_vring_state *state) VhostUserMsg *msg)
{ {
struct vhost_virtqueue *vq = dev->virtqueue[state->index]; struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
vq->size = state->num; vq->size = msg->payload.state.num;
if (dev->dequeue_zero_copy) { if (dev->dequeue_zero_copy) {
vq->nr_zmbuf = 0; vq->nr_zmbuf = 0;
@ -334,7 +334,7 @@ static int vhost_setup_mem_table(struct virtio_net *dev);
* This function then converts these to our address space. * This function then converts these to our address space.
*/ */
static int static int
vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr) vhost_user_set_vring_addr(struct virtio_net *dev, VhostUserMsg *msg)
{ {
struct vhost_virtqueue *vq; struct vhost_virtqueue *vq;
@ -348,11 +348,11 @@ vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr)
return -1; return -1;
/* addr->index refers to the queue index. The txq 1, rxq is 0. */ /* addr->index refers to the queue index. The txq 1, rxq is 0. */
vq = dev->virtqueue[addr->index]; vq = dev->virtqueue[msg->payload.addr.index];
/* The addresses are converted from QEMU virtual to Vhost virtual. */ /* The addresses are converted from QEMU virtual to Vhost virtual. */
vq->desc = (struct vring_desc *)(uintptr_t)qva_to_vva(dev, vq->desc = (struct vring_desc *)(uintptr_t)qva_to_vva(dev,
addr->desc_user_addr); msg->payload.addr.desc_user_addr);
if (vq->desc == 0) { if (vq->desc == 0) {
RTE_LOG(ERR, VHOST_CONFIG, RTE_LOG(ERR, VHOST_CONFIG,
"(%d) failed to find desc ring address.\n", "(%d) failed to find desc ring address.\n",
@ -360,11 +360,11 @@ vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr)
return -1; return -1;
} }
dev = numa_realloc(dev, addr->index); dev = numa_realloc(dev, msg->payload.addr.index);
vq = dev->virtqueue[addr->index]; vq = dev->virtqueue[msg->payload.addr.index];
vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev, vq->avail = (struct vring_avail *)(uintptr_t)qva_to_vva(dev,
addr->avail_user_addr); msg->payload.addr.avail_user_addr);
if (vq->avail == 0) { if (vq->avail == 0) {
RTE_LOG(ERR, VHOST_CONFIG, RTE_LOG(ERR, VHOST_CONFIG,
"(%d) failed to find avail ring address.\n", "(%d) failed to find avail ring address.\n",
@ -373,7 +373,7 @@ vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr)
} }
vq->used = (struct vring_used *)(uintptr_t)qva_to_vva(dev, vq->used = (struct vring_used *)(uintptr_t)qva_to_vva(dev,
addr->used_user_addr); msg->payload.addr.used_user_addr);
if (vq->used == 0) { if (vq->used == 0) {
RTE_LOG(ERR, VHOST_CONFIG, RTE_LOG(ERR, VHOST_CONFIG,
"(%d) failed to find used ring address.\n", "(%d) failed to find used ring address.\n",
@ -390,7 +390,7 @@ vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr)
vq->last_avail_idx = vq->used->idx; vq->last_avail_idx = vq->used->idx;
} }
vq->log_guest_addr = addr->log_guest_addr; vq->log_guest_addr = msg->payload.addr.log_guest_addr;
LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n", LOG_DEBUG(VHOST_CONFIG, "(%d) mapped address desc: %p\n",
dev->vid, vq->desc); dev->vid, vq->desc);
@ -409,7 +409,7 @@ vhost_user_set_vring_addr(struct virtio_net *dev, struct vhost_vring_addr *addr)
*/ */
static int static int
vhost_user_set_vring_base(struct virtio_net *dev, vhost_user_set_vring_base(struct virtio_net *dev,
struct vhost_vring_state *state) VhostUserMsg *msg)
{ {
/* Remove from the data plane. */ /* Remove from the data plane. */
if (dev->flags & VIRTIO_DEV_RUNNING) { if (dev->flags & VIRTIO_DEV_RUNNING) {
@ -417,8 +417,8 @@ vhost_user_set_vring_base(struct virtio_net *dev,
dev->notify_ops->destroy_device(dev->vid); dev->notify_ops->destroy_device(dev->vid);
} }
dev->virtqueue[state->index]->last_used_idx = state->num; dev->virtqueue[msg->payload.state.index]->last_used_idx = msg->payload.state.num;
dev->virtqueue[state->index]->last_avail_idx = state->num; dev->virtqueue[msg->payload.state.index]->last_avail_idx = msg->payload.state.num;
return 0; return 0;
} }
@ -744,9 +744,9 @@ free_zmbufs(struct vhost_virtqueue *vq)
*/ */
static int static int
vhost_user_get_vring_base(struct virtio_net *dev, vhost_user_get_vring_base(struct virtio_net *dev,
struct vhost_vring_state *state) VhostUserMsg *msg)
{ {
struct vhost_virtqueue *vq = dev->virtqueue[state->index]; struct vhost_virtqueue *vq = dev->virtqueue[msg->payload.state.index];
/* We have to stop the queue (virtio) if it is running. */ /* We have to stop the queue (virtio) if it is running. */
if (dev->flags & VIRTIO_DEV_RUNNING) { if (dev->flags & VIRTIO_DEV_RUNNING) {
@ -757,10 +757,10 @@ vhost_user_get_vring_base(struct virtio_net *dev,
dev->flags &= ~VIRTIO_DEV_READY; dev->flags &= ~VIRTIO_DEV_READY;
/* Here we are safe to get the last used index */ /* Here we are safe to get the last used index */
state->num = vq->last_used_idx; msg->payload.state.num = vq->last_used_idx;
RTE_LOG(INFO, VHOST_CONFIG, RTE_LOG(INFO, VHOST_CONFIG,
"vring base idx:%d file:%d\n", state->index, state->num); "vring base idx:%d file:%d\n", msg->payload.state.index, msg->payload.state.num);
/* /*
* Based on current qemu vhost-user implementation, this message is * Based on current qemu vhost-user implementation, this message is
* sent and only sent in vhost_vring_stop. * sent and only sent in vhost_vring_stop.
@ -790,18 +790,18 @@ vhost_user_get_vring_base(struct virtio_net *dev,
*/ */
static int static int
vhost_user_set_vring_enable(struct virtio_net *dev, vhost_user_set_vring_enable(struct virtio_net *dev,
struct vhost_vring_state *state) VhostUserMsg *msg)
{ {
int enable = (int)state->num; int enable = (int)msg->payload.state.num;
RTE_LOG(INFO, VHOST_CONFIG, RTE_LOG(INFO, VHOST_CONFIG,
"set queue enable: %d to qp idx: %d\n", "set queue enable: %d to qp idx: %d\n",
enable, state->index); enable, msg->payload.state.index);
if (dev->notify_ops->vring_state_changed) if (dev->notify_ops->vring_state_changed)
dev->notify_ops->vring_state_changed(dev->vid, state->index, enable); dev->notify_ops->vring_state_changed(dev->vid, msg->payload.state.index, enable);
dev->virtqueue[state->index]->enabled = enable; dev->virtqueue[msg->payload.state.index]->enabled = enable;
return 0; return 0;
} }
@ -1090,17 +1090,17 @@ vhost_user_msg_handler(int vid, int fd)
break; break;
case VHOST_USER_SET_VRING_NUM: case VHOST_USER_SET_VRING_NUM:
vhost_user_set_vring_num(dev, &msg.payload.state); vhost_user_set_vring_num(dev, &msg);
break; break;
case VHOST_USER_SET_VRING_ADDR: case VHOST_USER_SET_VRING_ADDR:
vhost_user_set_vring_addr(dev, &msg.payload.addr); vhost_user_set_vring_addr(dev, &msg);
break; break;
case VHOST_USER_SET_VRING_BASE: case VHOST_USER_SET_VRING_BASE:
vhost_user_set_vring_base(dev, &msg.payload.state); vhost_user_set_vring_base(dev, &msg);
break; break;
case VHOST_USER_GET_VRING_BASE: case VHOST_USER_GET_VRING_BASE:
vhost_user_get_vring_base(dev, &msg.payload.state); vhost_user_get_vring_base(dev, &msg);
msg.size = sizeof(msg.payload.state); msg.size = sizeof(msg.payload.state);
send_vhost_message(fd, &msg); send_vhost_message(fd, &msg);
break; break;
@ -1125,7 +1125,7 @@ vhost_user_msg_handler(int vid, int fd)
break; break;
case VHOST_USER_SET_VRING_ENABLE: case VHOST_USER_SET_VRING_ENABLE:
vhost_user_set_vring_enable(dev, &msg.payload.state); vhost_user_set_vring_enable(dev, &msg);
break; break;
case VHOST_USER_SEND_RARP: case VHOST_USER_SEND_RARP:
vhost_user_send_rarp(dev, &msg); vhost_user_send_rarp(dev, &msg);