Skip to contentSkip to conversation

virtqueue request size

Qemu-devel Vasile Catalin-B50542 1 participant 3 messages Feb 12, 2015 – Feb 13, 2015

lore
Share & tools
lore
#0 lore raw

I'm trying to work out virtqueue from the virtio API.
I've been able to send a message from guest to qemu, but there is something strange that I don't understand.
virtqueue_get_avail_bytes() returns 0 number of "in" bytes, but if I hard code iov_to_buf() to get 5 bytes, it actually gets my message.
What am I missing out?

Here is the essential code so far:
Guest:

    probe function:
        vq = virtio_find_single_vq(vdev, recv_done, "input");
    triggered send function:
        sg_init_one(&sg, buf, size);
        if (virtqueue_add_inbuf(vq, &sg, 1, buf, GFP_KERNEL) < 0)
            BUG();
        virtqueue_kick(vq);

Qemu:

    realize function:
        vcrypto->vq = virtio_add_queue(vdev, 8, handle_input);
    handle_input:
        virtqueue_pop(vcrypto->vq, &elem);
        eprintf("request size is %u", get_request_size(vcrypto->vq, 
100)); // prints size 0
        iov_to_buf(elem.in_sg, elem.in_num, 0, buffer, 5); // hardcoded 

to 5 bytes for now
get_request_size:
virtqueue_get_avail_bytes(vq, &in, &out, quota, quota); //
quota = 100

        return in;
#1 lore raw

I found what was the problem. virtqueue_get_avail_bytes() must be called before virtqueue_pop().

Quoted 30 lines · On 12.02.2015 15:52, Vasile Catalin-B50542 wrote:

I'm trying to work out virtqueue from the virtio API.
I've been able to send a message from guest to qemu, but there is something strange that I don't understand.
virtqueue_get_avail_bytes() returns 0 number of "in" bytes, but if I hard code iov_to_buf() to get 5 bytes, it actually gets my message.
What am I missing out?

Here is the essential code so far:
Guest:

    probe function:
        vq = virtio_find_single_vq(vdev, recv_done, "input");
    triggered send function:
        sg_init_one(&sg, buf, size);
        if (virtqueue_add_inbuf(vq, &sg, 1, buf, GFP_KERNEL) < 0)
            BUG();
        virtqueue_kick(vq);

Qemu:

    realize function:
        vcrypto->vq = virtio_add_queue(vdev, 8, handle_input);
    handle_input:
        virtqueue_pop(vcrypto->vq, &elem);
        eprintf("request size is %u", get_request_size(vcrypto->vq, 
100)); // prints size 0
        iov_to_buf(elem.in_sg, elem.in_num, 0, buffer, 5); // 

hardcoded to 5 bytes for now
get_request_size:
virtqueue_get_avail_bytes(vq, &in, &out, quota, quota); //
quota = 100

        return in;
#2 lore raw
In reply to Vasile Catalin-B50542

I found out what was the problem.
I was calling virtqueue_get_avail_bytes() after virtqueue_pop().

Quoted 30 lines · On 12.02.2015 15:52, Vasile Catalin-B50542 wrote:

I'm trying to work out virtqueue from the virtio API.
I've been able to send a message from guest to qemu, but there is something strange that I don't understand.
virtqueue_get_avail_bytes() returns 0 number of "in" bytes, but if I hard code iov_to_buf() to get 5 bytes, it actually gets my message.
What am I missing out?

Here is the essential code so far:
Guest:

    probe function:
        vq = virtio_find_single_vq(vdev, recv_done, "input");
    triggered send function:
        sg_init_one(&sg, buf, size);
        if (virtqueue_add_inbuf(vq, &sg, 1, buf, GFP_KERNEL) < 0)
            BUG();
        virtqueue_kick(vq);

Qemu:

    realize function:
        vcrypto->vq = virtio_add_queue(vdev, 8, handle_input);
    handle_input:
        virtqueue_pop(vcrypto->vq, &elem);
        eprintf("request size is %u", get_request_size(vcrypto->vq, 
100)); // prints size 0
        iov_to_buf(elem.in_sg, elem.in_num, 0, buffer, 5); // 

hardcoded to 5 bytes for now
get_request_size:
virtqueue_get_avail_bytes(vq, &in, &out, quota, quota); //
quota = 100

        return in;