Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio-vsock: spec violation about the number of descriptors per packet #204

Closed
stefano-garzarella opened this issue Nov 24, 2022 · 9 comments · Fixed by #207
Closed

virtio-vsock: spec violation about the number of descriptors per packet #204

stefano-garzarella opened this issue Nov 24, 2022 · 9 comments · Fixed by #207

Comments

@stefano-garzarella
Copy link
Member

In crates/devices/virtio-vsock/src/packet.rs for both the TX and RX queue, we assume that each packet always consists of 2 descriptors (returning DescriptorChainTooShort error otherwise), but this is not in the specification.

It was an implementation detail true until Linux 6.1, but now it's about to change.
Testing vhost-user-vsock (which uses this crate) with the proposed Linux patch, I noticed that it doesn't work, printing this error:

WARN  vhost_user_vsock::vhu_vsock_thread] vsock: RX queue error: DescriptorChainTooShort

In the vhost-vsock device available in Linux, we don't assume that, so I think we should do the same here to respect the virtio specification.

@stefano-garzarella
Copy link
Member Author

stefano-garzarella commented Nov 24, 2022

I would like to fix it before we release the new driver (not before Linux 6.2).
@lauralt can you take a look at it? If not, I'll try to look at it next week.

@lauralt
Copy link
Contributor

lauralt commented Nov 24, 2022

Yes, the implementation was Linux specific at that point, it is mentioned in a doc comment as well. I agree this should be fixed, but other things were prioritised.
Having a look again at the code, it won't be super straightforward to fix this, and it will probably be ugly since we don't have the Reader and Writer abstractions that crosvm for example uses (there is a PR open for this in vm-virtio as well #33 for quite some time already). I can take a better look early next week.

Out of curiosity, does it fail with the error you mentioned when having multiple descriptors for the data or?

@stefano-garzarella
Copy link
Member Author

Yes, the implementation was Linux specific at that point, it is mentioned in a doc comment as well.

I didn't know that, thanks for pointing it out!

I agree this should be fixed, but other things were prioritised. Having a look again at the code, it won't be super straightforward to fix this, and it will probably be ugly since we don't have the Reader and Writer abstractions that crosvm for example uses (there is a PR open for this in vm-virtio as well #33 for quite some time already). I can take a better look early next week.

Great! Thanks, let me know if I can help in some way.

Out of curiosity, does it fail with the error you mentioned when having multiple descriptors for the data or?

Nope, in this case we have a single descriptor for header and data (in RX)

@lauralt
Copy link
Contributor

lauralt commented Nov 24, 2022

Yes, the implementation was Linux specific at that point, it is mentioned in a doc comment as well.

I didn't know that, thanks for pointing it out!

I agree this should be fixed, but other things were prioritised. Having a look again at the code, it won't be super straightforward to fix this, and it will probably be ugly since we don't have the Reader and Writer abstractions that crosvm for example uses (there is a PR open for this in vm-virtio as well #33 for quite some time already). I can take a better look early next week.

Great! Thanks, let me know if I can help in some way.

Out of curiosity, does it fail with the error you mentioned when having multiple descriptors for the data or?

Nope, in this case we have a single descriptor for header and data (in RX)

Aaaah yes that is possible since for the vsock device the header and the data have the same type (device readable or writable), so you can keep them in a single descriptor, I forgot about that for a second. Thanks for the clarification.

@lauralt
Copy link
Contributor

lauralt commented Nov 30, 2022

@stefano-garzarella I had a better look at the code, it should be doable with the current abstraction (but didn't do any POC yet).
How I imagine the fix would look like: instead of a single VolatileSlice, we use an array of VolatileSlices for each of the header and data. Then, when we parse the RX and TX chains, we append each slice corresponding to a descriptor to either the header or the data depending on the number of bytes we consumed up until that point (less than the header size or more). For the particular situation you mentioned, we will start with one VolatileSlice on which we can use split_at to split into two VolatileSlices, one for the header and one for the data. I don't have bandwidth to take care of this in the near future, but I'm happy to help/review if you want to work on it.

This would probably be a good time to invest in reviewing/updating #33 since the Reader and Writer abstractions should simplify this problem (which we ultimately have in each device implementation).

@stefano-garzarella
Copy link
Member Author

@lauralt thank you for the helpful information!

I'll see if I can next week, but if we merge the patch into Linux, I think we should at least have a workaround right away and then maybe refine the implementation.

stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 19, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make the tests work with this change (mainly by always using
PKT_HEADER_SIZE for the header descriptor) and adding new tests to cover
the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
@stefano-garzarella
Copy link
Member Author

@lauralt I pushed #207.
For now I have not implemented the VolatileSlices array, both because I have limited time (I will be off the next 2 weeks) and because it requires an API change.

So I thought for now to just support the single descriptor case to run the device with Linux v6.2 without changing API (we might release virtio-vsock 0.2.1).

And then think better about your suggestion and change the API.

What do you think?

stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 19, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make the tests work with this change (mainly by always using
PKT_HEADER_SIZE for the header descriptor) and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
@lauralt
Copy link
Contributor

lauralt commented Dec 19, 2022

@lauralt I pushed #207. For now I have not implemented the VolatileSlices array, both because I have limited time (I will be off the next 2 weeks) and because it requires an API change.

So I thought for now to just support the single descriptor case to run the device with Linux v6.2 without changing API (we might release virtio-vsock 0.2.1).

And then think better about your suggestion and change the API.

What do you think?

@stefano-garzarella
Sounds good. Thanks for taking care of this! I will have time to review the PR this Wednesday at the earliest. Does that work for you?

@stefano-garzarella
Copy link
Member Author

@stefano-garzarella
Sounds good. Thanks for taking care of this! I will have time to review the PR this Wednesday at the earliest. Does that work for you?

@lauralt yep, sure!

stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 19, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make the tests work with this change (mainly by always using
PKT_HEADER_SIZE for the header descriptor) and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 20, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make the tests work with this change (mainly by always using
PKT_HEADER_SIZE for the header descriptor) and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 20, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make the tests work with this change (mainly by always using
PKT_HEADER_SIZE for the header descriptor) and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 21, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make the tests work with this change (mainly by always using
PKT_HEADER_SIZE for the header descriptor) and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 21, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make some tests working with this change and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
stefano-garzarella added a commit to stefano-garzarella/vm-virtio that referenced this issue Dec 21, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
rust-vmm#204 (comment)

Let's make some tests working with this change and adding new tests to
cover the single descriptor scenario.

Fixes: rust-vmm#204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
lauralt pushed a commit that referenced this issue Dec 21, 2022
Starting from Linux 6.2 the virtio-vsock driver can use a single
descriptor for both header and data:
https://lore.kernel.org/lkml/20221215043645.3545127-1-bobby.eshleman@bytedance.com/

So with this modification the virtio-vsock device can support header
and data on a single descriptor or on two. This is just a Linux
implementation detail though, for the spec it could be multiple
descriptors as well.

For now let's add only the single descriptor support, since it doesn't
involve an API change, but in the future we should change the API and
support an array of VolatileSlices as suggested by Laura here:
#204 (comment)

Let's make some tests working with this change and adding new tests to
cover the single descriptor scenario.

Fixes: #204

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants