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

driver/virtio/blk: Ensure request header stays in-page boundaries **AND** some minor sglist cleanup #1290

Merged

Conversation

mogasergiu
Copy link
Member

@mogasergiu mogasergiu commented Jan 29, 2024

Prerequisite checklist

  • Read the contribution guidelines regarding submitting new changes to the project;
  • Tested your changes against relevant architectures and platforms;
  • Ran the checkpatch.uk on your commit series before opening this PR;
  • Updated relevant documentation.

Base target

  • Architecture(s): N/A
  • Platform(s): kvm
  • Application(s): N/A

Additional configuration

Description of changes

Move some sglist stuff

  • netbuf appending to sglist method to lib/uknetdev/netbuf.c
  • some sglist definitions/macro's for saving/restoring to library header

The important addition of the PR:

The header (first descriptor) of the virtio-blk request must always
come in one piece! By aligning to its size (16), we ensure that
it will be contained entirely in one page only, i.e. the
scatter-gather list will not process it as two segments, which
would result in two descriptors.

E.g. If the address ends something like 0x...ff8 then the header
will span 0x...ff8 -> 0x...008 crossing the next page and resulting
in the scatter-gather list splitting it into two segments and
thus into two descriptors, which QEMU seems to not like.

To help with this, declare the request header at the beginning
of the virtio-blk request structure and make its allocation
16-byte aligned, guaranteeing its length will never cross the page
boundary.

@mogasergiu mogasergiu requested review from a team as code owners January 29, 2024 14:31
@github-actions github-actions bot added area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/uknetdev lib/uksglist labels Jan 29, 2024
@mogasergiu mogasergiu requested review from skuenzer and removed request for a team January 29, 2024 14:32
@razvand razvand added this to the v0.17.0 (Calypso) milestone Feb 1, 2024
@mogasergiu mogasergiu force-pushed the smoga/#1290/sglist_virtioblk_outhdr branch 2 times, most recently from 4fc766a to 020f7fa Compare March 15, 2024 15:16
Copy link
Contributor

@andreistan26 andreistan26 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good,

Reviewed-by: Andrei Stan andreistan2003@gmail.com

@mogasergiu mogasergiu force-pushed the smoga/#1290/sglist_virtioblk_outhdr branch from 020f7fa to fb3dbe3 Compare March 18, 2024 19:41
Copy link
Contributor

@razvanvirtan razvanvirtan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @mogasergiu!
Only one nitpick: I suggest having some consistency about the "scatter-gather" writing.
For instance, in this comment the two words are separated by a dash, while in this one they are not.

Reviewed-by: Razvan Virtan virtanrazvan@gmail.com

Copy link
Member

@skuenzer skuenzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mogasergiu, I have only some minor comments, otherwise, this PR looks good. 👍🏻

lib/uknetdev/include/uk/netbuf.h Outdated Show resolved Hide resolved
lib/uksglist/include/uk/sglist.h Outdated Show resolved Hide resolved
lib/uksglist/include/uk/sglist.h Outdated Show resolved Hide resolved
lib/uksglist/include/uk/sglist.h Outdated Show resolved Hide resolved
lib/uknetdev/include/uk/netbuf.h Outdated Show resolved Hide resolved
It may come in handy to do scatter-gather list save and restore
in places other than the scatter-gather library. Therefore, allow
others to see the corresponding definitions by placing them in
the header.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Rename `uk_sglist_append_netbuf` to `uk_netbuf_sglist_append`
and move it to the libuknetdev, since that is its only client.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
The header (first descriptor) of the virtio-blk request must always
come in one piece! By aligning to its size (16), we ensure that
it will be contained entirely in one page only, i.e. the
scatter-gather list will not process it as two segments, which
would result in two descriptors.

E.g. If the address ends something like 0x...ff8 then the header
will span 0x...ff8 -> 0x...008 crossing the next page and resulting
in the scatter-gather list splitting it into two segments and
thus into two descriptors, which QEMU seems to not like.

To help with this, declare the request header at the beginning
of the virtio-blk request structure and make its allocation
16-byte aligned, guaranteeing its length will never cross the page
boundary.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
@mogasergiu mogasergiu force-pushed the smoga/#1290/sglist_virtioblk_outhdr branch from fb3dbe3 to fb49749 Compare March 19, 2024 09:04
Copy link
Member

@skuenzer skuenzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates.

Approved-by: Simon Kuenzer simon@unikraft.io

@razvand razvand changed the base branch from staging to staging-1290 March 20, 2024 06:12
@razvand razvand merged commit 610d845 into unikraft:staging-1290 Mar 20, 2024
11 of 12 checks passed
razvand pushed a commit that referenced this pull request Mar 20, 2024
It may come in handy to do scatter-gather list save and restore
in places other than the scatter-gather library. Therefore, allow
others to see the corresponding definitions by placing them in
the header.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1290
razvand pushed a commit that referenced this pull request Mar 20, 2024
Rename `uk_sglist_append_netbuf` to `uk_netbuf_sglist_append`
and move it to the libuknetdev, since that is its only client.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1290
razvand pushed a commit that referenced this pull request Mar 20, 2024
The header (first descriptor) of the virtio-blk request must always
come in one piece! By aligning to its size (16), we ensure that
it will be contained entirely in one page only, i.e. the
scatter-gather list will not process it as two segments, which
would result in two descriptors.

E.g. If the address ends something like 0x...ff8 then the header
will span 0x...ff8 -> 0x...008 crossing the next page and resulting
in the scatter-gather list splitting it into two segments and
thus into two descriptors, which QEMU seems to not like.

To help with this, declare the request header at the beginning
of the virtio-blk request structure and make its allocation
16-byte aligned, guaranteeing its length will never cross the page
boundary.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: #1290
SerbanSo pushed a commit to SerbanSo/unikraft-ASLR that referenced this pull request Jun 16, 2024
It may come in handy to do scatter-gather list save and restore
in places other than the scatter-gather library. Therefore, allow
others to see the corresponding definitions by placing them in
the header.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: unikraft#1290
SerbanSo pushed a commit to SerbanSo/unikraft-ASLR that referenced this pull request Jun 16, 2024
Rename `uk_sglist_append_netbuf` to `uk_netbuf_sglist_append`
and move it to the libuknetdev, since that is its only client.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: unikraft#1290
SerbanSo pushed a commit to SerbanSo/unikraft-ASLR that referenced this pull request Jun 16, 2024
The header (first descriptor) of the virtio-blk request must always
come in one piece! By aligning to its size (16), we ensure that
it will be contained entirely in one page only, i.e. the
scatter-gather list will not process it as two segments, which
would result in two descriptors.

E.g. If the address ends something like 0x...ff8 then the header
will span 0x...ff8 -> 0x...008 crossing the next page and resulting
in the scatter-gather list splitting it into two segments and
thus into two descriptors, which QEMU seems to not like.

To help with this, declare the request header at the beginning
of the virtio-blk request structure and make its allocation
16-byte aligned, guaranteeing its length will never cross the page
boundary.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Razvan Virtan <virtanrazvan@gmail.com>
Approved-by: Simon Kuenzer <simon@unikraft.io>
GitHub-Closes: unikraft#1290
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/lib Internal Unikraft Microlibrary lang/c Issues or PRs to do with C/C++ lib/uknetdev lib/uksglist
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants