Skip to content

Commit

Permalink
virtio: various cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan-Velickovic <[email protected]>
  • Loading branch information
Ivan-Velickovic committed Nov 7, 2024
1 parent 4a18c5b commit 9420943
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 0 additions & 2 deletions include/libvmm/virtio/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ struct virtio_blk_outhdr {
* virtio response from sddf response.
*/
typedef struct reqbk {
// /* For writing response byte in virtio descriptor */
// uint8_t *virtio_resp_byte;
/* Descriptor head of the virtio request */
uint16_t virtio_desc_head;
/* For enqueuing sddf req/resp */
Expand Down
25 changes: 13 additions & 12 deletions src/virtio/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ static bool virtio_blk_mmio_queue_notify(struct virtio_device *dev)
uint32_t curr_desc_bytes_read = 0;

/* There are three parts with each block request. The header, body (which
* contains the data) and reply. */
* contains the data) and footer. */

/* First read the header */
uint32_t header_bytes_read = 0;
struct virtio_blk_outhdr virtio_req_header;
for (; header_bytes_read < sizeof(struct virtio_blk_outhdr);
Expand All @@ -254,21 +256,20 @@ static bool virtio_blk_mmio_queue_notify(struct virtio_device *dev)
/* We can guarantee existence of next descriptor as footer is write only
*/
assert(virtq->desc[curr_desc].flags & VIRTQ_DESC_F_NEXT);
if (header_bytes_read + virtq->desc[curr_desc].len >
sizeof(struct virtio_blk_outhdr)) {
memcpy(&virtio_req_header, (void *)virtq->desc[curr_desc].addr,
sizeof(struct virtio_blk_outhdr) - header_bytes_read);
curr_desc_bytes_read =
sizeof(struct virtio_blk_outhdr) - header_bytes_read;
header_bytes_read +=
sizeof(struct virtio_blk_outhdr) - header_bytes_read;

void *desc_addr = (void *)virtq->desc[curr_desc].addr;
uint32_t desc_len = virtq->desc[curr_desc].len;

if (header_bytes_read + desc_len > sizeof(struct virtio_blk_outhdr)) {
memcpy(&virtio_req_header, desc_addr, sizeof(struct virtio_blk_outhdr) - header_bytes_read);
curr_desc_bytes_read = sizeof(struct virtio_blk_outhdr) - header_bytes_read;
header_bytes_read += sizeof(struct virtio_blk_outhdr) - header_bytes_read;
/* Don't go to the next descriptor yet, we're not done processing with
* current one */
break;
} else {
memcpy(&virtio_req_header, (void *)virtq->desc[curr_desc].addr,
virtq->desc[curr_desc].len);
header_bytes_read += virtq->desc[curr_desc].len;
memcpy(&virtio_req_header, desc_addr, desc_len);
header_bytes_read += desc_len;
}
}

Expand Down
14 changes: 7 additions & 7 deletions vmm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ CFLAGS += -I${LIBVMM_DIR}/include
endif

ARCH_INDEP_FILES := src/util/printf.c \
src/util/util.c \
src/virtio/block.c \
src/virtio/console.c \
src/virtio/mmio.c \
src/virtio/net.c \
src/virtio/sound.c \
src/guest.c \
src/util/util.c \
src/virtio/block.c \
src/virtio/console.c \
src/virtio/mmio.c \
src/virtio/net.c \
src/virtio/sound.c \
src/guest.c \
src/uio/uio.c \

CFILES := ${AARCH64_FILES} ${ARCH_INDEP_FILES}
Expand Down

0 comments on commit 9420943

Please sign in to comment.