X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Flnx_virtio_blk.c;h=fd9ec6191842c5dd41e5cbf89262484a0fc73444;hb=8a3dbb70c29175bad79764a0b2f3961b98138bb2;hp=7e26b3081566e8d51d71a2cc4dedc4376d81f422;hpb=aac189310cca0f5f14543d91413d3b5b58250a3e;p=palacios.git diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index 7e26b30..fd9ec61 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -26,7 +26,7 @@ -#ifndef CONFIG_DEBUG_VIRTIO_BLK +#ifndef V3_CONFIG_DEBUG_VIRTIO_BLK #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -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; }