Virtio: zero sized buffers are not allowed,cdrom kernel diff

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
fbkr
Posts: 14
Joined: Sun Dec 13, 2020 4:06 pm

Virtio: zero sized buffers are not allowed,cdrom kernel diff

Post by fbkr »

Hi all,

I'm trying to add virtio drivers (just block device at the moment) to my OS, however, I'm running into this issue. Once I set everything up and write 0xF (ACK | DRIVER | FEATURES_OK | DRIVERS_OK) to the status register, I get "qemu-system-x86_64: virtio: zero sized buffers are not allowed" in the terminal. If I don't set the virtual queue, I don't get this error, so I got it pinpointed there.

For the virtqueue setup, the device needs a 256 element queue, and I have the descriptors at 0x7000, available queue at 0x8000 (0x7000 + 256 * 16) and used queue at 0x9000 (aligned to 4096) and I write 0x7 to queue 0's address. All the memory here is zero initialized. I'm using the legacy interface since BAR0 for this device is an IO port.

Could someone assist me with this? Resources on virtio is much thinner than I expected. I checked out the examples at dumais.io and the managarm source, however I didn't notice anything.

Update: when I run the same kernel with `-kernel`, everything works. Running it with `-cdrom` causes this problem on linux and macos, but works on Windows.
Last edited by fbkr on Mon Feb 01, 2021 12:42 am, edited 1 time in total.
fbkr
Posts: 14
Joined: Sun Dec 13, 2020 4:06 pm

Re: Virtio error: "zero sized buffers are not allowed"

Post by fbkr »

I just tested this on qemu(v5.1.0-11824-g8699890d91-dirty) on Windows and it actually worked without a problem.

However, both with qemu v4.2.1 and v5.1.0 on linux have this problem.
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Virtio error: "zero sized buffers are not allowed"

Post by Octocontrabass »

fbkr wrote:I have the descriptors at 0x7000
Virtual or physical? How do you set up those descriptors? Did you set the buffer length to a nonzero value? (That's what QEMU is checking when it throws the error you're seeing.)
fbkr
Posts: 14
Joined: Sun Dec 13, 2020 4:06 pm

Re: Virtio error: "zero sized buffers are not allowed"

Post by fbkr »

Octocontrabass wrote:
fbkr wrote:I have the descriptors at 0x7000
Virtual or physical?


It's physical.
Octocontrabass wrote:How do you set up those descriptors? Did you set the buffer length to a nonzero value? (That's what QEMU is checking when it throws the error you're seeing.)
This is happening at initialization, the descriptors are empty, and the whole buffer is zero filled.
fbkr
Posts: 14
Joined: Sun Dec 13, 2020 4:06 pm

Re: Virtio error: "zero sized buffers are not allowed"

Post by fbkr »

I think I do finish setting up the descriptors. Neither the general initialization nor the block device initialization mention putting anything into the queues during initialization. So I'm just trying to initialize an empty queue. Am I missing something obvious?
fbkr
Posts: 14
Joined: Sun Dec 13, 2020 4:06 pm

Re: Virtio error: "zero sized buffers are not allowed"

Post by fbkr »

One thing I've noticed is that this works correctly even under linux if I boot with `-kernel ...`, but if I boot with `-cdrom ...`, it fails. But the same ELF/ISO works on windows either way.

Qemu 5.2.0 has the same behaviour on macos as well, works with -kernel, fails with -cdrom

The ISO is being generated with `grub-mkrescue` and the elf is a multiboot1 image.
fbkr
Posts: 14
Joined: Sun Dec 13, 2020 4:06 pm

Re: Virtio: zero sized buffers are not allowed,cdrom kernel

Post by fbkr »

I seem to have figured this out.

Even though the spec clearly says a device must initialize the status register with 0 (https://docs.oasis-open.org/virtio/virt ... #x1-120002), setting it to 0 before doing any initialization fixed the problem.
Post Reply