Skip to content

Add VIRTIO_NET_F_MRG_RXBUF to virtio-net #4658

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

Closed
wants to merge 13 commits into from

Conversation

ShadowCurse
Copy link
Contributor

@ShadowCurse ShadowCurse commented Jun 28, 2024

Changes

Add VIRTIO_NET_F_MRG_RXBUF to virtio-net.

Now virtio-net device can split incoming packets across multiple descriptor chains if VIRTIO_NET_F_MRG_RXBUF is enabled by the guest. The amount of descriptor chains (also known as heads) is written into the virtio_net_hdr_v1 structure which is located at the very begging of the packet. Virtio spec states that the number of heads used should always be correct:

  • 1 - if VIRTIO_NET_F_MRG_RXBUF is not negotiated
  • N - if VIRTIO_NET_F_MRG_RXBUF is negotiated
    Prior to this commit Firecracker never set the number of used heads to 1, but Linux was fine with it. Now we always set correct number of heads. Because of this some changes were introduced into the unit test code that was generating testing frames.

Fixes: #1314

Reason

Better performance and guest memory utilization.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this
    PR.
  • API changes follow the Runbook for Firecracker API changes.
  • User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • New TODOs link to an issue.
  • Commits meet
    contribution quality standards.

  • This functionality cannot be added in rust-vmm.

@ShadowCurse ShadowCurse self-assigned this Jun 28, 2024
@ShadowCurse ShadowCurse force-pushed the net_mrg_buf branch 5 times, most recently from b200d76 to ccda0b0 Compare July 5, 2024 18:15
@ShadowCurse ShadowCurse force-pushed the net_mrg_buf branch 6 times, most recently from cdc6f02 to fde7478 Compare July 16, 2024 08:36
@ShadowCurse ShadowCurse mentioned this pull request Jul 16, 2024
9 tasks
@ShadowCurse ShadowCurse force-pushed the net_mrg_buf branch 8 times, most recently from a4168d1 to 64616a4 Compare July 18, 2024 11:22
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

Attention: Patch coverage is 98.06094% with 7 lines in your changes missing coverage. Please review.

Project coverage is 84.50%. Comparing base (a364da8) to head (70bce30).
Report is 161 commits behind head on main.

Current head 70bce30 differs from pull request most recent head b61f394

Please upload reports for the commit b61f394 to get more accurate results.

Files with missing lines Patch % Lines
src/vmm/src/devices/virtio/net/device.rs 96.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4658      +/-   ##
==========================================
+ Coverage   84.37%   84.50%   +0.12%     
==========================================
  Files         249      250       +1     
  Lines       27433    27678     +245     
==========================================
+ Hits        23147    23388     +241     
- Misses       4286     4290       +4     
Flag Coverage Δ
5.10-c5n.metal 84.73% <98.06%> (+0.13%) ⬆️
5.10-m5n.metal 84.72% <98.06%> (+0.13%) ⬆️
5.10-m6a.metal 84.02% <98.06%> (+0.13%) ⬆️
5.10-m6g.metal 81.09% <98.06%> (+0.17%) ⬆️
5.10-m6i.metal 84.72% <98.06%> (+0.13%) ⬆️
5.10-m7g.metal 81.09% <98.06%> (+0.17%) ⬆️
6.1-c5n.metal 84.73% <98.06%> (+0.13%) ⬆️
6.1-m5n.metal 84.72% <98.06%> (+0.13%) ⬆️
6.1-m6a.metal 84.02% <98.06%> (+0.13%) ⬆️
6.1-m6g.metal 81.08% <98.06%> (+0.17%) ⬆️
6.1-m6i.metal 84.72% <98.06%> (+0.14%) ⬆️
6.1-m7g.metal 81.09% <98.06%> (+0.17%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ShadowCurse ShadowCurse force-pushed the net_mrg_buf branch 4 times, most recently from 05923db to 7f94f6a Compare July 18, 2024 16:12
@ShadowCurse ShadowCurse marked this pull request as ready for review July 18, 2024 16:49
@ShadowCurse ShadowCurse added Status: Awaiting review Indicates that a pull request is ready to be reviewed Type: Enhancement Indicates new feature requests Type: Performance labels Jul 18, 2024
@ShadowCurse ShadowCurse mentioned this pull request Aug 12, 2024
9 tasks
@ShadowCurse ShadowCurse force-pushed the net_mrg_buf branch 5 times, most recently from c6ceb46 to 719dbdb Compare August 13, 2024 11:11
Now IoVecBufferMut can be reloaded from DescriptorChain
same way as IoVecBuffer does it.
This is helpful to avoid unnecessary allocations/deallocations
when reusing same buffer.

Signed-off-by: Egor Lazarchuk <[email protected]>
Replace numbers with more descriptive `size_of`
methods.

Signed-off-by: Egor Lazarchuk <[email protected]>
`Self::default()` is a bit more compact.

Signed-off-by: Egor Lazarchuk <[email protected]>
Move used ring update into a separate method. This
will help with preprocessing of descriptor chains in later
commits where we will advance used ring once after
processing multiple descriptors.

Signed-off-by: Egor Lazarchuk <[email protected]>
Now `write_used_ring` makes sure the index
is in correct bounds. This removes a need for the
caller to make sure the index is in bounds. It
will be used in the later commits to discard
used descriptors.

Signed-off-by: Egor Lazarchuk <[email protected]>
@ShadowCurse ShadowCurse force-pushed the net_mrg_buf branch 4 times, most recently from cd9e706 to 68db1b0 Compare August 15, 2024 11:14
Now we will know the index of the head descriptor
from which the IoVecBufferMut was build.

Signed-off-by: Egor Lazarchuk <[email protected]>
Add methods to obtain head index and pointer to the
first buffer from `IoVecBufferMut`. These methods
will be used in later commits.

Signed-off-by: Egor Lazarchuk <[email protected]>
Add `RingBuffer` data structure. It will be used
in later commits.

Signed-off-by: Egor Lazarchuk <[email protected]>
Add `read_used_ring` to read used element from a used ring.
This is needed for `discard_used`.

Add `discard_used` method to discard last
`n` used elements in the used ring by setting
their `len` to 0.

Signed-off-by: Egor Lazarchuk <[email protected]>
Make some structs/fields public as following
commits will need this.

Signed-off-by: Egor Lazarchuk <[email protected]>
Now virtio-net device can split incoming packets across
multiple descriptor chains if VIRTIO_NET_F_MRG_RXBUF is enabled
by the guest. The amount of descriptor chains (also known as heads)
is written into the `virtio_net_hdr_v1` structure which is located
at the very begging of the packet. Virtio spec states that the
number of heads used should always be correct:
- 1 - if VIRTIO_NET_F_MRG_RXBUF is not negotiated
- N - if VIRTIO_NET_F_MRG_RXBUF is negotiated
Prior to this commit Firecracker never set the number of
used heads to 1, but Linux was fine with it. Now Firecracker always
sets correct number of heads. Because of this, some changes
were introduced into the unit test code that was generating
testing frames.

Additionally, because processing of descriptors was taking a big chunk
of total time spend in the RX packet processing, move reading of
descriptors to the preprocessing step performed when guest notifies
Firecracker about new descriptors available for RX queue.

Signed-off-by: Egor Lazarchuk <[email protected]>
`read_obj` takes too much time and we don't need it's checks
as we do them before the actual reading happens.
To help with perpormance, replace it with either `get_slice`
or `get_host_address`.

Signed-off-by: Egor Lazarchuk <[email protected]>
@ShadowCurse ShadowCurse mentioned this pull request Aug 16, 2024
9 tasks
Signed-off-by: Egor Lazarchuk <[email protected]>
@ShadowCurse
Copy link
Contributor Author

Closing in favor of #4834

@ShadowCurse ShadowCurse closed this Oct 4, 2024
@ShadowCurse ShadowCurse deleted the net_mrg_buf branch October 29, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Indicates new feature requests Type: Performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Virtio-net: implement support of VIRTIO_NET_F_MRG_RXBUF
1 participant