It feels like things are finally starting to come together.
Infrastructure --------------
Server memory upgraded. We should now be able to handle more than one person cloning Spectrum's nixpkgs repo at once!
Documentation -------------
I added a much requested page[1] to the website with a few tasks a potential contributor might want to look into. More to come here, too!
[1]: https://spectrum-os.org/todo.html
virtio_wl ---------
I wrote a simple guest C program that connected to a host socket over virtio_wl, and sent some messages back and forth. In doing this, I've ended up with a nice set of generic functions for interacting with virtio_wl -- virtio_wl_connect(), virtio_wl_send(), etc. This is nice, because it allows me to treat virtio_wl inside a guest much like a regular socket (albeit one that can only be interacted with using a custom set of functions). Otherwise, I'd have to do ioctl operations every time (which seems to be what the various virtio_wl-using Chromium OS components do).
Having a simple test program (rather than integrating directly into wlroots) gives me a more simple environment with which to test the other end of this connection.
crosvm ------
I implemented a little Rust server that listens on a Unix stream socket. When it receives a message (consisting of an identifier {for debug purposes} and a size), it will allocate a memfd of the requested size, and then send that back to the socket, along with a status byte indicating success or failure.
I then integrated this program into crosvm, so it is started as part of the VM initialization, and exposed over virtio_wl as an additional socket. Integrating this into crosvm required some careful thought, because there's no precedent in crosvm for a virtio_wl server of this sort. It has almost nothing with the existing concept in crosvm of a "device", which is something that communicates with a guest kernel driver over PCI. So Spectrum's crosvm now has the concept of "servers". I can see us wanting to provide other VM services over virtio_wl in the future. It allows us to exchange various resources between host and guest (or between guests) without having to write a kernel driver specific to each task.
This all now works well enough that my program inside the VM can request a chunk of memory, and receive back something that looks a bit like a memfd, that can then be sent back to the host over a virtio_wl socket. It was great to see this working the first time!
One thing crosvm devices do that I would also like to apply to this type of server is sandboxing. The sandboxing mechanism used in crosvm is pretty generic (it's really just a thin wrapper around Minijail[2]), so it should be straightforward to reuse. I just have to understand a bit better how to use it.
The other crosvm change I still need to make is to put this functionality behind a command line flag. Most VMs should not be able to give themselves extra memory this way -- really only the Wayland compositor should be using it. I should also impose some upper bound on how much memory is allowed to be allocated this way. Such a limit will probably get harder to add (from a testing point of view) the longer I wait.
[2]: https://lwn.net/Articles/700557/
So, at lot of very focused progress this week. From here I plan to finish up the crosvm stuff, and then integrate this protocol into wlroots. Then, not too long from now, we'll finally be able to move the Wayland compositor into its own VM, separate from applications. Exciting!
There will also probably be a Chromium OS release next week, which will require some updates in Spectrum. If all goes well, I won't actually be the one doing that this time. ;)