News for hackers. Stuff that matters.
Re:FreeBSD on Firecracker by packetlost on Thursday August 24, 2023 @06:00PM (#37255117)
I'm very surprised the standard isn't to build a microkernel that emulates Linux userspace (or *NIX userspace) and is tailored towards the subset of virtual hardware that Firecracker and QEMU provide. I don't get the impression that implementing a new target for a PL is all that difficult, so if you create a psuedo-OS like WASI/WASM and send PRs to the supported languages you could cut out most of the overhead.

The "hardest" part is probably sufficiently emulating Linux userspace accurately: it's a big surface area. That's why I think creating a pseudo-OS target is the best route.

Re:FreeBSD on Firecracker by tptacek on Thursday August 24, 2023 @06:29PM (#37255380)
You're describing gvisor.
Re:FreeBSD on Firecracker by packetlost on Thursday August 24, 2023 @06:55PM (#37255609)
No, I'm not. Gvisor is a security layer around Linux containers that emulates and constrains syscalls. It specifically runs on top of a container platform and kernel. What I'm suggesting is a stripped down Linux-like kernel that is really good at running exactly one process. I'm describing a microkernel.
Re:FreeBSD on Firecracker by tptacek on Thursday August 24, 2023 @07:03PM (#37255674)
gvisor emulates a big chunk of the Linux system call interface, and, remarkably, a further large chunk of Linux kernel state. It's architecturally similar to uml (though not as complete; like Firecracker, it's optimized to a specific set of workloads).

gvisor is not like a seccomp-bpf process sandbox that just ACLs system calls.

Re:FreeBSD on Firecracker by packetlost on Thursday August 24, 2023 @07:49PM (#37256040)
Ok, I oversimplified a bit. Regardless, I'm suggesting something that still runs in emulated hardware isolation and implements drivers for Firecracker/QEMU's subset of hardware.
Re:FreeBSD on Firecracker by tptacek on Thursday August 24, 2023 @07:56PM (#37256078)
gvisor does emulate some hardware. See, for instance, its network stack.

At any rate: why is this better than just using KVM and Firecracker? The big problem with gvisor is that the emulation you're talking about has pretty tough overhead.

Re:FreeBSD on Firecracker by packetlost on Thursday August 24, 2023 @09:21PM (#37256703)
Let's you get the best of both gvisor and Firecracker: efficient use of resources (ie. not running a full Linux kernel + scheduler, and most importantly, network stack for every lambda) while getting the isolation that comes from virtualization. You can achieve this in one of 2 ways: make a new kernel and add support for targeting it in the supported languages, or strip the Linux kernel down and reimplement the parts that aren't optimized for you short-lived VM lifecycle (scheduler, network stack, etc.).
Re:FreeBSD on Firecracker by tptacek on Thursday August 24, 2023 @09:25PM (#37256734)
Stripping the Linux kernel down is what people do with Firecracker. I'm curious what savings you see in the Linux networking stack. You could compile it out and just rely on vsocks, but now you're breaking everyone's code and you're not winning anything on performance.
Re:FreeBSD on Firecracker by packetlost on Thursday August 24, 2023 @10:06PM (#37257023)
Perhaps I'm off base (I'm not an expert in this area), but I recall reading that one of the major challenges with Lambda was the latency that initializing the network stack introduces. Perhaps that's been solved by now, but my naive idea is to have the guest not really run it's own network stack (at least the MAC/IP portion of it) and instead delegate the entire stack (IP and all) to the virtual device, which can be implemented by Firecracker/QEMU/whatever. I guess at that point, the amount of mangling you'd need to do to the kernel probably isn't worth it and you should just use Gvisor... ah oh well.

Regardless, I'm still surprised microkernels aren't more popular in this space, but perhaps the losing the ecosystem of Linux libs/applications is a non-starter.

Even if the idea wasn't fruitful, the conversation was fun. Thanks for engaging and challenging my bad ideas!

Edit: I've also realized I was thinking of Unikernels, not microkernels and I've been calling it the wrong thing all night. *sigh*

Re:FreeBSD on Firecracker by monocasa on Friday August 25, 2023 @12:22AM (#37258034)
FWIW, Linux itself has plenty of support for TCP offload engines. I don't think Firecracker uses that at the moment, but there's no reason why it has to be that way if that's a true bottleneck in the system.
Re:FreeBSD on Firecracker by caskstrength on Friday August 25, 2023 @05:42AM (#37259804)
> Linux itself has plenty of support for TCP offload engines

Could you link to any specific Linux kernel source that implements support for TCP offload? AFAIK networking subsystem maintainers were always opposed to accommodate TCP offload because it is A Bad Idea.

Re:FreeBSD on Firecracker by packetlost on Friday August 25, 2023 @10:23AM (#37262070)
I know there's a few userspace networking APIs such as DPDK [0]. Or maybe there's something in KVM code that implements it. If so, it's news to me!

[0]: https://www.linuxjournal.com/content/userspace-networking-dp...

Re:FreeBSD on Firecracker by yencabulator on Friday August 25, 2023 @03:20PM (#37265988)
At its simplest, TCP offload can be just letting the hardware chunk a large packet into smaller ones on the wire. I don't think anything trying to offload more than that has really seen much daylight outside of very proprietary "smart NICs".

https://www.kernel.org/doc/Documentation/networking/segmenta...

https://wiki.linuxfoundation.org/networking/tso

Re:FreeBSD on Firecracker by touisteur on Friday August 25, 2023 @05:52AM (#37259877)
I think the Firecracker team has stated that PCIe bypass wasn't something they wanted to do, so I don't see how they'd open up to other accelerators' bypass method. But seems like building a vmm from the rust-vmm toolbox is 'not that hard' and there are some PCIe bypass crates already, so... Have fun?
Re:FreeBSD on Firecracker by monocasa on Friday August 25, 2023 @11:37AM (#37262918)
I'm not saying an actual NIC with TCP offload, but instead something like adding TCP offload to the virtio nic if for some reason initialization of the network stack was a latency problem. If the VM is only running at layer 3, most init latency problems disappear.
Re:FreeBSD on Firecracker by packetlost on Friday August 25, 2023 @01:28PM (#37264510)
This is exactly what I'm referring to. You have a pool of virtual NICs on the host in user-space created by the VM runtime that get assigned to the guest on provision-time, which just passes through any commands/syscalls (bind/connect/etc.) via a funky driver interface. You'd have to mangle the guest kernel syscalls or libc though, it might be really ugly.
Re:FreeBSD on Firecracker by monocasa on Friday August 25, 2023 @01:41PM (#37264668)
> You'd have to mangle the guest kernel syscalls or libc though, it might be really ugly.

You wouldn't have to. There's patches for hardware TCP offload using the normal socket syscall ABI. The kernel net stack maintainer is pretty ideologically against them so they're not mainlined, but plenty of people have been running them in production for decades and they're quite mature.

Re:FreeBSD on Firecracker by packetlost on Friday August 25, 2023 @01:43PM (#37264690)
Oh neat!
Re:FreeBSD on Firecracker by talideon on Friday August 25, 2023 @05:31AM (#37259743)
That's not what a microkernel is. A microkernel is a kernel that pushes services traditionally included in the kernel, such as networking, out into userspace.

The closest things to what you're describing are unikernels and NetBSD rump kernels.

Re:FreeBSD on Firecracker by packetlost on Friday August 25, 2023 @01:37PM (#37264621)
Yeah, further down I realized I was crossing wires and was thinking of a Unikernel. My bad!
Re:FreeBSD on Firecracker by reachableceo on Friday August 25, 2023 @02:13PM (#37265171)
I believe the term you are looking for is unikernel, not micro kernel.
Re:FreeBSD on Firecracker by yencabulator on Friday August 25, 2023 @03:07PM (#37265868)
It's a unikernel really only if you rip out any security boundaries inside the VM and link the kernel into the app. If you still maintain a syscall boundary inside the VM, it's just another kernel.
Re:FreeBSD on Firecracker by yencabulator on Friday August 25, 2023 @03:16PM (#37265958)
Sort of. Let's say gVisor is three things:

1. Mechanism to capture syscalls (systrap)

2. Reimplementation of parts Linux kernel

3. Narrow set of calls to outside using Linux syscalls

This thing could be envisioned as

1. Linux syscall ABI as-is, same mechanism[a]

2. Reimplementation of parts Linux kernel

3. virt-io hardware drivers for calls to outside

So the middle part of the sandwich could look the same.

Also, I think it's worth saying that I think the work in maintaining #2 there is exactly why Google Cloud Run migrated away from gVisor. People just kept asking for more and more kernel features.

[a]: Alternatively, #1 could be replaced with unikernel like linking directly with #2.

Me personally, I think HTTP/3's move away from TCP could be really interesting for this sort of stuff. The responsibilities of the kernel could be hugely simplified if all you had were UDP/IP directly hardcoded to virtio (no need for routing, address configuration, ARP, etc), no paging etc, and the only filesystems were EROFS & tmpfs. Of course, Cloud Run's move away from gVisor shows that Enterprise clients would hate it.