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

virtq: use a struct with the actual layout rather than a struct of references #1150

Merged
merged 3 commits into from
May 7, 2024

Conversation

cagatay-y
Copy link
Contributor

The code is not ready as I haven't yet figured out how the existing code ensures that the whole allocation is on the same page. This PR needs to be modified to ensure that as well. It is also based on #1141.

@cagatay-y cagatay-y force-pushed the ref-to-dst branch 3 times, most recently from 721e4be to b79e219 Compare May 2, 2024 21:48
@cagatay-y cagatay-y marked this pull request as ready for review May 2, 2024 22:25
@cagatay-y
Copy link
Contributor Author

I am not sure if the use of Pin here is correct and I need to check it but I think the PR can be reviewed since any changes related to Pin should not have a big effect for the majority of the changes.

@mkroening mkroening self-requested a review May 3, 2024 08:07
@mkroening mkroening self-assigned this May 3, 2024
@cagatay-y cagatay-y force-pushed the ref-to-dst branch 3 times, most recently from f69e530 to 1366a92 Compare May 6, 2024 16:11
Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

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

Thanks!

Apart from one comment, this looks excellent! :)

src/drivers/virtio/virtqueue/split.rs Outdated Show resolved Hide resolved
cagatay-y added 2 commits May 7, 2024 15:37
…ferences

Using a struct of references for the ring structures of the split virtqueue adds an unnecessary level of indirection and complicates the initialization. Use dynamically sized structs with appropriate accessor methods instead.
Endianness-specified numbers from zerocopy, as opposed to the ones from virtio-def, do not guarantee appropriate alignment.
The fields are used to send data to and receive data from the host and Rust cannot reason about the changes done by the host and changes to the memory that are needed for their side effect. As such, we need to use volatile references for them.
@cagatay-y
Copy link
Contributor Author

FYI, in addition to the deprecation change, I also switched a ptr::from_mut call to ptr::from_ref and changed the mutability of the variable declaration accordingly. It is not easily visible because I amended the last commit, so I am noting it here.

vq_handler.set_ring_addr(paging::virt_to_phys(VirtAddr::from(
ptr::from_ref(descr_table_cell.as_ref()).expose_provenance(),
)));
// As usize is safe here, as the *mut EventSuppr raw pointer is a thin pointer of size usize
vq_handler.set_drv_ctrl_addr(paging::virt_to_phys(VirtAddr::from(
ptr::from_ref(avail_ring_cell.as_ref()).expose_provenance(),
)));
vq_handler.set_dev_ctrl_addr(paging::virt_to_phys(VirtAddr::from(
ptr::from_ref(used_ring_cell.as_ref()).expose_provenance(),

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

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

Thanks! :)

@mkroening mkroening added this pull request to the merge queue May 7, 2024
Merged via the queue into hermit-os:main with commit 5f08ef5 May 7, 2024
13 checks passed
@cagatay-y cagatay-y deleted the ref-to-dst branch May 7, 2024 18:38
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 this pull request may close these issues.

2 participants