From: Jack Lange Date: Thu, 8 Sep 2011 19:05:35 +0000 (-0400) Subject: updated virtio block device to partially handle non-aligned IO requests X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=7a59334f2c211cfe59b0cc83e52aabe26da98464 updated virtio block device to partially handle non-aligned IO requests --- diff --git a/palacios/include/devices/lnx_virtio_pci.h b/palacios/include/devices/lnx_virtio_pci.h index e48df2c..f0c5e3d 100644 --- a/palacios/include/devices/lnx_virtio_pci.h +++ b/palacios/include/devices/lnx_virtio_pci.h @@ -91,14 +91,19 @@ * */ struct virtio_config { - uint32_t host_features; - uint32_t guest_features; - uint32_t vring_page_num; - uint16_t vring_ring_size; - uint16_t vring_queue_selector; - uint16_t vring_queue_notifier; - uint8_t status; - uint8_t pci_isr; + union { + uint8_t buf[20]; + struct { + uint32_t host_features; + uint32_t guest_features; + uint32_t vring_page_num; + uint16_t vring_ring_size; + uint16_t vring_queue_selector; + uint16_t vring_queue_notifier; + uint8_t status; + uint8_t pci_isr; + } __attribute__((packed)); + } __attribute__((packed)); } __attribute__((packed)); diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index d47243a..fd9ec61 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -407,38 +407,44 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u PrintDebug("VIRTIO BLOCK Read for port %d (index =%d), length=%d\n", port, port_idx, length); + switch (port_idx) { case HOST_FEATURES_PORT: - if (length != 4) { - PrintError("Illegal read length for host features\n"); + case HOST_FEATURES_PORT + 1: + case HOST_FEATURES_PORT + 2: + case HOST_FEATURES_PORT + 3: + if (port_idx + length > HOST_FEATURES_PORT + 4) { + PrintError("Illegal read length for host features (len=%d)\n", length); return -1; } - *(uint32_t *)dst = blk_state->virtio_cfg.host_features; - + memcpy(dst, &(blk_state->virtio_cfg.host_features), length); break; case VRING_PG_NUM_PORT: - if (length != 4) { - PrintError("Illegal read length for page frame number\n"); + case VRING_PG_NUM_PORT + 1: + case VRING_PG_NUM_PORT + 2: + case VRING_PG_NUM_PORT + 3: + if (port_idx + length > VRING_PG_NUM_PORT + 4) { + PrintError("Illegal read length for vring pg num (len=%d)\n", length); return -1; } - *(uint32_t *)dst = blk_state->queue.pfn; - + memcpy(dst, &(blk_state->queue.pfn), length); break; case VRING_SIZE_PORT: - if (length != 2) { - PrintError("Illegal read length for vring size\n"); + case VRING_SIZE_PORT + 1: + if (length > 2) { + PrintError("Illegal read length for vring size (len=%d)\n", length); return -1; } - - *(uint16_t *)dst = blk_state->queue.queue_size; + + memcpy(dst, &(blk_state->queue.queue_size), length); break; case VIRTIO_STATUS_PORT: if (length != 1) { - PrintError("Illegal read length for status\n"); + PrintError("Illegal read length for status (len=%d)\n", length); return -1; }