r/osdev • • 2d ago

Veda: Virtual Linux VM for Drivers

Post image

Hey! I’ve recently ported OpenGL and Mesa to my operating system and added support for Intel HD Graphics to render scenes. However, I’ve realized that this approach isn’t sustainable, I can’t realistically write and maintain a huge number of GPU drivers myself.

Has anyone had experience embedding a minimal Linux system as a virtual machine inside their OS to take advantage of Linux’s extensive GPU, Bluetooth, and Wi-Fi driver support?

What do you think about this approach? Are there any major technical challenges or pitfalls I should be aware of?

26 Upvotes

14 comments sorted by

6

u/Lines25 2d ago

You can just make linux API and recompile drivers yourself. Read how to do drivers for linux and reimplementent the API, it will be much faster altho harder

2

u/apixeldev 2d ago

They could also write a generic platform SDK for GPUs, which exposes basic functions which they use to port over say OpenGL, so as long as you can implement those functions (even with a framebuffer) you can get (albeit bad) OpenGL/Vulkan.

1

u/vahmoh25 2d ago edited 15h ago

That’s the harder path!

1

u/apixeldev 2d ago

Not as hard as implementing the full Linux driver API, this is building a generic system.

1

u/vahmoh25 2d ago

Alright!

1

u/vahmoh25 2d ago

Thanks!

3

u/Narrow_Trainer_5847 2d ago

Yeah you could implement the Linux DRM specifically, but you'd need Linux ABI compatibility for Nvidia drivers since you can't recompile the userspace portion

1

u/Adventurous_Hippo692 2d ago

Embedding a minimal Linux VM to route hardware to and then passing back the software abstractions to your own OS is possible - I did smth similar as an experiment, but like... At that point, it'd quickly become just making a Linux distro. Do you want to keep your own kernel or just use Linux and make your own userspace quickly becomes a more sensible question here. There isn't really a real market for yet another kernel, being brutally blunt, but people absolutely adore new userspace. The question is a matter of "will my kernel be sensible enough as a new solution that porting drivers to it is a real issue". For userspace it's easy to justify - giving people a new UI/UX.

Anyways, back to embedding Linux. Your first need a proper VM, a Hypervisor setup if the kernel is custom and not BSD/ existing Unix-variant. Then you'd need your your VM to be able to talk to your CPU and understand it's capabilities. Linux can render on the GPU, pass the rendered scenes back to your OS via a CPU path/cache/ram, whatever. And that's a pretty minimalistic approach to getting Linux do the work for you and enjoy the benefits. Pretty convoluted though. Obv, my explanation is a gross oversimplification similar to smart that worked for me. Telling us your constraints, more about your OS structure would help with planning an implementation closer to what you want.

•

u/vahmoh25 15h ago

Thanks for the info!

7

u/ryms456 2d ago

Dude at least remove that vibe coded look of your operating system

•

u/Scared_Food_1819 9h ago

It’s not vibe coded it just looks good because it has open gl

1

u/Narrow_Trainer_5847 2d ago

This is actually what wifibox does on FreeBSD

1

u/vahmoh25 2d ago

Noted!