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-blk storage via mmio using virtio-drivers [v3] #635

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

osteffenrh
Copy link
Contributor

@osteffenrh osteffenrh commented Mar 1, 2025

This PR adds support for virtio-blk storage devices using the virtio-mmio transport.
MMIO accesses are done via explicit vmgexits. Interrupts are not used (-> polling).

A minimized version of the rcore-os/virtio-drivers crate (MIT License) is added
to the codebase as a sub-crate. Most of the unused code was removed (PCI support, unused device types,
example programs,...), resulting in about 3800 lines of code, see osteffenrh/virtio-drivers#3

This PR requires a patched version of Qemu (coconut-svsm/qemu#13), which features virtio-mmio slots in the Q35 machine model (thanks @kraxel).

Qemu communicates the MMIO base address via the fw_cfg interface, making use of OVMF's
HardwareInfoLib. Work is already ongoing to add this to upstream Qemu.
Device information are stored in the etc/hardware-info fw_cfg file in a simple binary format.
Building on top of that, the PR introduces a new device type to store MMIO addresses for use by the SVSM.

How to test:

Fixes since V2 (#542):

  • pull virtio code into the repo + minimize it
  • device discovery via fw_cfg

Things for future PRs:

  • encryption layer
  • file system / partitioning

osteffenrh and others added 10 commits March 4, 2025 13:26
Use the latest version of the zerocopy crate, to match the one used by
the virtio-drivers crate.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Add mmio read and write functions.

ToDo: Improve read_buffer() to be similar to write_buffer().

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Import a minimized version of the rcore-os/virtio-drivers crate
into the codebase, as a sub-crate.

See https://github.com/osteffenrh/virtio-drivers/tree/minimize
for changes made to the upstream branch.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Implement a Hal for Coconut that uses the ghcb mmio functions
and manages bounce-buffers in host-shared memory.

The buffers use SharedBox and are currently limited to 1 page in size.
The SharedBoxes need to be kept around between the share() and unshare()
calls, thus a global manager was added that holds them.

ToDo: Allow arbitrary buffer sizes.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Add a simple block layer api trait.

Co-developed-by: Oliver Steffen <osteffen@redhat.com>
Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Add command line option to add a virtio-blk MMIO device to the CVM.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Make use of the fw_cfg file "etc/hardware-info" to obtain the
MMIO base addresses for virtio devices.
This mechanism was/is being added to OVMF [1] and Qemu [2] to
pass information about hardware devices to the firmware, which can not
be communicated in other ways. We introduce a new device type for SVSM
for use in that file which specifies a MMIO address.

[1] https://edk2.groups.io/g/devel/message/86051
[2] https://lists.nongnu.org/archive/html/qemu-devel/2025-02/msg03923.html

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Add a block device driver that uses the virito-blk via
mmio transport.

ToDo: Return proper error codes.

Co-developed-by: Oliver Steffen <osteffen@redhat.com>
Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Add simple write+readback tests for the VirtioBlkDriver.

Signed-off-by: Oliver Steffen <osteffen@redhat.com>
Add a virtio-blk device to the in-svsm test setup to allow
the VirtioBlkDriver tests to run.

Signed-off-by: Oliver Steffen <osteffen@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 this pull request may close these issues.

2 participants